Patch for pefile 1.2.9.1 - big performance boost for large files

16 views
Skip to first unread message

barnabas79

unread,
Oct 23, 2008, 11:38:57 AM10/23/08
to pefile
Hey all - I made a patch for pefile that realizes some pretty
significant performance gains when reading in pefiles with a lot of
small entries - in the ~6MB dll I was testing, consisting mostly of
images embedded as resources, I was getting speed gains of 6x-10x.
(Unfortunately, I can't upload the dll, as it's copyrighted...)

Anyway, the gains are mostly realized b/c it seems pefile makes a lot
of calls to get_data with no length argument - which means it just
reads until the end of the section EVERY time. For a big section,
this obviously means a lot of wasted time. Instead, added a
get_struct function to the PE class, which acts sort of like get_data
and __unpack_data__ rolled into one, with the added bonus that it
automatically calculates a length for set_data.

Also, to help avoid making the same mistake again, I modified get_data
so that the length arg is no longer optional; the same behavior (ie,
reading to the end of the section) may still be had by passing in
None, but given how potentially expensive this is, it must now be done
explicitly, if that is what is desired.

Thanks for the great module!

- Paul

PS - I'm going to post both a diff, and my (complete) modified
pefile.py in the files section here...
Reply all
Reply to author
Forward
0 new messages