CasualX / pelite

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

[HELP] Example: getting RVA ? #271

Closed WHots closed 1 year ago

WHots commented 1 year ago

Hey, I'm new to Rust so this may be the issue since im not familiar with it's wild syntax sugary appeal yet..

So i use this crate very well, other than getting an RVA.. I've tried like a dozen different ways and haven't saved them to show all possible examples of my issue, so ill show you what I have now that doesn't give a compilation error..

for sect in image.section_headers() { let va: Va = sect.VirtualAddress.into(); let rva = image.va_to_rva(va.into()); println!("Section Name: {:?} -- VirtualAddress {:#x} -- Size {} Bytes -- RVA: {:#?}", sect.name().unwrap(), sect.VirtualAddress, sect.VirtualSize, rva) }

Example output: Section Name: ".text" -- VirtualAddress 0x1000 -- Size 584160 Bytes -- RVA: Err(Bounds,)

Not really sure where to go, tried searching this repo for usage and couldn't find anything along the same context of what im trying to accomplish.

CasualX commented 1 year ago

section VirtualAddress is a misnomer, it is already an RVA not a VA, so va_to_rva is most likely going to fail. Just work with the sect.VirtualAddress as if it's an RVA. You can tell because VA are typically much higher numbers than 0x1000.

Va is also just a typedef for either u64/u32 (depending on whether you're working with 32 or 64 bit PE files) so the .into() would not be necessary.

WHots commented 1 year ago

@CasualX Would this also apply to strings VirtualAddress? because they return small as well.

WHots commented 1 year ago

I was able to get it all together, thanks.