erocarrera / pefile

pefile is a Python module to read and work with PE (Portable Executable) files

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Accept memoryview for data

rpm5099 opened this issue · comments

In the PE class could the __init__ function parameter data be changed to support accepting a memoryview? the function def b(x): right now will attempt to run codecs.encode on it as if it were a str. In many cases memoryview can be treated just like bytes. If you are working with executables in memoryview format converting them to bytes to analyze with pefile requires them to be copied it memory. Because pefile does not modify data AFAIK, making this change should not be an issue.

pefile will attempt to use mmap.mmap on the input file, which implements the buffer protocol, as memoryview does. I have done some experiments with memoryview but I see not difference in speed or memory consumption. However since the move to Python 3 the b(x) function is superfluous so I'll do away with it.
I am closing this for the time being but feel free to open if I've misunderstood your suggestion or overlooked something.