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

Some raw types for your elf pattern. #34

Closed
arizvisa opened this issue Mar 21, 2022 · 3 comments
Closed

Some raw types for your elf pattern. #34

arizvisa opened this issue Mar 21, 2022 · 3 comments

Comments

@arizvisa
Copy link

Here's that raw data for your elf pattern that I promised.

First of all, some apologies for not making this into a proper PR as since I don't actually use ImHex I don't have it forked or anything (ui allergies, but I'm still an admirer). Plus, I didn't want to smash up the original elf pattern since I haven't tested this data with your parser. Hence it still being raw.

Also an apology for not doing the conditionals that glue the fields together, or that switch between types based on the values in the headers. As you can imagine that requires parsing logic out of my definitions, and rigging things with Python's ast library would definitely be more time consuming than just a simple type conversion.

In my definitions, I have the header split out, and then based on the header I use either the Elf32 or the Elf64 types.

Some of the bitfields might be wrong because they're in "microsoft-order" which is high-bit first, and it's a little bit clumsy because the byteorder can change based on E_DATA. So those bitfields should be little-endian.

for-werwolv.txt

If there's something you think I can fix, or that would make it easier for you to fit within your syntax, let me know as I can generate these again.

@WerWolv
Copy link
Owner

WerWolv commented Sep 4, 2022

Finally got around to implement those into a pattern that basically has feature-parity with the 010 template
Thanks a lot :)

@WerWolv WerWolv closed this as completed Sep 4, 2022
@arizvisa
Copy link
Author

arizvisa commented Sep 6, 2022

Super-awesome. I'm glad it worked out and we can slowly dethrone 010 with opensource. ;-)
Was there anything in particular that sucked other than having to add the logic for resolving types dynamically?

I think this is a small thing, but it seems that the Elf32_Phdr and Elf32_Shdr fields were missed. I noticed it because of the '@' pointer syntax.

if (e_ident.EI_CLASS == EI_CLASS::ELFCLASS32) {
Elf32_Ehdr header;
} else if (e_ident.EI_CLASS == EI_CLASS::ELFCLASS64) {
Elf64_Ehdr ehdr;
Elf64_Phdr phdr[ehdr.e_phnum] @ ehdr.e_phoff;
Elf64_Shdr shdr[ehdr.e_shnum] @ ehdr.e_shoff;

With your example on choosing the type for the section contents (ElfXX_Shdr), it seems that I might be able to add the definitions for the section header types and copy the logic for the program header types too.. which'd get it pretty close to PT_DYNAMIC and verdef/verneed/versym. I'll try to work on a PR for those.

@WerWolv
Copy link
Owner

WerWolv commented Sep 6, 2022

You're right I forgot to add those, thank you!

The most annoying thing was really just to write the whole pattern twice basically, once for 32 bit and once for 64 bit. There's currently no way to conditionally define types which made it harder. Other than that, the types you gave me were great and didn't need many changes

If you'd like to make PRs for anything, please absolutely feel free :)

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

No branches or pull requests

2 participants