Bug relating to autosort in PayloadGenerator
There's a mistake in the autosorting logic inside PayloadGenerator, as a consequence payload generation will often fail, raising a ValueError: Unknown error. Missing bytes on line 166 or an IndexError: list index out of range on line 180 of core.py.
A proof of concept crash:
from libformatstr import *
f = FormatStr()
f[0xdddddd05] = 0xcccccccc
payload = f.payload(6)
This is as a result of the if statement on line 145 of core.py being the wrong way round. At the moment the default value of autosort is True, and the if statement is:
if autosort:
self.addrs = list(mem.keys()) # addresses of each byte to set
else:
self.addrs = list(sorted(mem.keys()))
Which means the keys aren't sorted by default, causing various problems. To rectify this the lines can simply be switched around like so:
if autosort:
self.addrs = list(sorted(mem.keys())) # addresses of each byte to set
else:
self.addrs = list(mem.keys())
This only appears to be a problem in this git repository. The versions in pip don't have the autosort property so keys are always sorted and this problem doesn't exist.
Well, maybe there is an error. But I cannot reproduce your crash. I'm late because I don't get the notification...:( Sorry.
Don't worry about it! Make sure you're testing the version in this repository, not the version in PyPI (because that appears to be a different version, without the autosort property). I've just cloned this repository again and reproduced the error. See the following screenshot.
Well, actually this feature was committed by me....I wrote it because it is useful in some CTF challenges.
In my machine your code work just fine, but I use my submitted version.

Later I will check the version in this repo.
Did you test the code in this repository?