Closed ghost closed 8 years ago
It seems good for the files I've tested with the new requirement https://github.com/mlaferrera/python3-pefile
But after a debug, the implementation is still strange :
The class ImportData
inherits of DataContainer
.
class DataContainer(object):
"""Generic data container."""
def __init__(self, **args):
bare_setattr = super(DataContainer, self).__setattr__
for key, value in list(args.items()):
bare_setattr(key, value)
In python3 the order of the list returned by args.items() is undefined, here is a simple example :
def test(**args):
for key, value in list(args.items()):
print(key)
test(arg1=1, arg2=1, arg3=1)
Result:
arg3
arg1
arg2
Then in the function ImportData.__setattr__
, some attributes may not be defined (for example self.struct_table
not defined when the current attribute is ordinal
).
If the problem persists, the solution should be to set all attributes first then call the loop like this :
for key, value in args.items():
self.__dict__[key] = value
for key, value in list(args.items()):
bare_setattr(key, value)
In python2, the above example gives always :
arg1
arg2
arg3
It uses the official pefile now https://github.com/erocarrera/pefile
The pefile library seems to be bugged. Sometimes the function pe.load_import_symbols fails because the internal function of pefile, parse_data_directories, throw an exception.