CasualX / pelite

Lightweight, memory-safe, zero-allocation library for reading and navigating PE binaries.
MIT License
280 stars 42 forks source link

Enabling the ability to implement a lazily evaluated PeView #233

Closed ko1N closed 3 years ago

ko1N commented 4 years ago

Instead of calling the get() function on the image slice directly this commit adds a small convenience function which will just get a slice of the underlying image buffer at a specific offset. This will enable users to build their own lazy version of a PeView by intercepting all the calls to the Pe trait.

CasualX commented 4 years ago

I like this, if you don't mind I'll add it to other places as well.

ko1N commented 4 years ago

I like this, if you don't mind I'll add it to other places as well.

I only really found one other spot where it could potentially be changed: https://github.com/CasualX/pelite/blob/master/src/rich_structure.rs#L38

CasualX commented 4 years ago

The Rich header is part of the PE header and shouldn't be subject to this function I think. I need to think about how to enforce this better.

I was thinking about read, slice and get_section_bytes and making it hard to make this mistake of directly accessing the image.

ko1N commented 4 years ago

The Rich header is part of the PE header and shouldn't be subject to this function I think. I need to think about how to enforce this better.

I was thinking about read, slice and get_section_bytes and making it hard to make this mistake of directly accessing the image.

That would also work. It's kinda odd to have a "slice" and "read" and "image_slice" function in there. The scanner currently accesses the entire image slice as well (and also fetches it), which makes a lazy implementation for it kinda pointless but I commited that change as well as i initially overlooked it.