Selective parsing

16 views
Skip to first unread message

TarasCo

unread,
Feb 15, 2011, 6:20:43 AM2/15/11
to pefile
Is it possible to do something like this pseudocode:

pe = pefile.PE( filename, fast_load=True)
pe.load( pefile.IMAGE_DIRECTORY_ENTRY_EXPORT )

for exp in pe.DIRECTORY_ENTRY_EXPORT.symbols: doSomeThing( exp )

?

Ero Carrera

unread,
Feb 15, 2011, 7:42:35 AM2/15/11
to pefile

Indeed it is possible:

After setting fast_load to True you can then make pefile selectively
load what you need as follows:

---------------------------
pe = pefile.PE(control_file, fast_load=True)

# the following is a list of directory indices, one can use the
dictionary
# pefile.DIRECTORY_ENTRY to refer to the directories by name or
simply
# specify a list such as: [1,2,6,7]

directories_to_load =
[ pefile.DIRECTORY_ENTRY['IMAGE_DIRECTORY_ENTRY_RESOURCE'] ]
pe.parse_data_directories( directories = directories_to_load )
---------------------------

To load all 16 directories (same as fast_load=False)

---------------------------
pe.parse_data_directories( directories= range(0x10) )
---------------------------

regards,
--
ero

TarasCo

unread,
Feb 15, 2011, 10:48:45 AM2/15/11
to pefile
Great! It works )))
Thank you!
Reply all
Reply to author
Forward
0 new messages