Closed kiddinn closed 9 years ago
Error lies here:
section_name = u'{0:s}'.format(section_name.encode(u'unicode_escape'))
In one of the examples the culprit is:
(Pdb) section_name
'.xdata\x00\x90'
FYI using string_escape is not going to fly as a long term fix, since it is not supported by Python 3. Maybe:
codecs.getdecoder('unicode_escape')(b'as\x00\x90')[0]
(Pdb) !section_name.encode(u'unicode_escape') *\ UnicodeDecodeError: 'ascii' codec can't decode byte 0x90 in position 7: ordinal not in range(128)
another "solution" is just to catch the unicode decode error and use repr() on the string instead. That will get the text in full, escaped... like:
(Pdb) !repr(section_name)
"'.xdata\\x00\\x90'"
and the unicode_escape is not a fix, this is the part of the code that causes the error to be raised.
The bug is most likely inside the pe library itself:
In [1]: import pefile
In [2]: fh = open('/tmp/pefile', 'rb')
In [3]: data = fh.read()
In [4]: p = pefile.PE(data=data, fast_load=True)
In [5]: p.is_dll()
Out[5]: True
In [6]: sections = p.sections
In [7]: [getattr(s, u'Name', b'') for s in sections]
Out[7]:
['.data\x00j\x08',
'.xdata\x00\x90',
'.text\x00\x8b\x06',
'.extrel\x00',
'.reloc\x00\x90']
All the section names have data after it... will split the string on \x00
Know that section names can be fully binary data as well. They don't need to be ASCII strings.
CL is in, and tested again, bug is fixed.
Parsing the nfury SANS disk image:
Seeing tracebacks like this: