erocarrera / pefile

pefile is a Python module to read and work with PE (Portable Executable) files
MIT License
1.83k stars 516 forks source link

Accept memoryview for data #380

Closed rpm5099 closed 10 months ago

rpm5099 commented 11 months ago

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.

erocarrera commented 10 months ago

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.