Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Better abstraction of addresses #721

Open
ZehMatt opened this issue Jun 14, 2022 · 2 comments
Open

Better abstraction of addresses #721

ZehMatt opened this issue Jun 14, 2022 · 2 comments

Comments

@ZehMatt
Copy link
Contributor

ZehMatt commented Jun 14, 2022

Is your feature request related to a problem? Please describe.
I've been using this project lately and one thing that bothers me a bit is the abstraction of most things that have just address(), for ELF this is the actual virtual address and for PE this is typically the RVA.

Describe the solution you'd like
It would be best to have either one address type or make them explicit via different types/function. For consistency it would be an alternative is to have all addresses on the PE also as virtual address instead of relative virtual address, if the rva is needed it can be done with the Binary interface.

Describe alternatives you've considered
I currently wrote my own wrapper above LIEF::Binary which makes the addresses consistent for each binary type, this resulted in writing multiple more wrappers as objects like Function, Symbol all result in different address types per binary type.

Additional context
I think the abstraction could be improved in general, if the PE would have Segments instead of Sections then it would be at least consistent with ELF, PE would not have sections anymore and ELF sections will always be optional. I don't know about all the other abstractions but I feel like the general LIEF::Binary interface could be better, rva_to_va/va_to_rva is something that I would expect there also, not necessarily specific to PE.

@romainthomas
Copy link
Member

Hi @ZehMatt

I understand the need and it perfectly makes sense. Actually the PE sections can live independently from the PE::Binary object which embeds the imagebase through the OptionalHeader.
To enable accessing the imagebase from a PE section, it would require to, somehow, bind the PE section with the PE binary object so that we can transform a RVA into a VA.

This raises the complexity of keeping the different structures consistent with the potential modifications of the user. Actually if the LIEF's objects were read-only it would be quite easy to implement but since users can change ,for instance, the base address, it's a bit more tricky to handle.

If you have a draft of design which handles these aspects, let me know and we could see how to integrate it in LIEF.

@ZehMatt
Copy link
Contributor Author

ZehMatt commented Jun 15, 2022

Well one of the ideas is to always use virtual address, in theory we could do that during serialization/deserialization, so when we deserialize sections in the PE file we would simply add the image base already and store that value as address instead of keeping it rva, when we save the file we need to remove imagebase, I think what you have in mind is doing that in the object internally which indeed would add complexity. This way it would be hidden from the end user and the address would be generalized to virtual address.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants