-
Notifications
You must be signed in to change notification settings - Fork 5.6k
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
elf: Refactoring to enable creation of ELF files from scratch #4938
Conversation
See comments made to #5010 |
Your patches don't apply/work after 0133090. Can you please check and rebase your branch on current master? I will include it then again on ghidra-staging. |
This branch/PR by itself offers no changes in functionality to Ghidra. Following upstream's rejection of my changes, I've stopped maintaining my PR branches and instead piled up all of my work on this branch: https://github.com/boricj/ghidra/tree/feature/elfrelocatebleobjectexporter. If you want my relocation table rebuilder analyzer, you can cherry-pick the last 6 commits or so (boricj/ghidra@b85ae37...7fbca35). However, I'm afraid that the rest of my development branch is very painful to rebase on top of upstream due to the extensive modifications in the ELF support code. In particular, 0133090 looks especially awful to rebase on top of. Unfortunately I don't have a solution to get out of this mess, so for the time being I'm not going to rebase my development branch any further. |
This is a bunch of fixes that I've encountered as part of my ongoing attempt to unlink programs back into relocatable object files (#4922). Since I don't know what changes I've made are acceptable or not for upstreaming, in this PR I've tried to keep them at the absolute bare minimum that my own code can live with.
The changes are intended to support generating ELF files from scratch instead of just parsing an existing ELF file on disk:
BinaryReader
as a class variable ofElfHeader
. We can no longer assume that we can arbitrarily seek and read bytes from an ELF file except when actually parsing one, so every piece of data we need must be read upfront in the constructor and associated methods.ElfFileSection
from an interface that the various ELF table classes to an interface thatElfSectionHeader
andElfProgramHeader
implements. As above, table classes must work within a single ELF section or segment, they can't arbitrarily seek and read bytes around.ByteArrayMutableByteProvider
as an in-memory backing store for the string table data).The existing ELF serialization code is not used in-tree as far as I can tell, but can be tested with https://github.com/boricj/ghidra/tree/feature/elfrelocatebleobjectexporter, by:
Selection only
checked) to create an ELF file.Note that the exporter is alpha-quality, buggy and incomplete, but the generated ELF file should be valid as far as the ELF specification is concerned. The ELF support code in this PR for generating files is not fully-featured (no support for extended numbers of sections, no attempt to accommodate segments...) but so far works well enough for my purposes.
I did not notice any regressions when importing ELF files as part of my normal Ghidra usage with these changes. Hopefully I haven't introduced new bugs in that area.