m4b / goblin

An impish, cross-platform binary parsing crate, written in Rust
MIT License
1.2k stars 160 forks source link

Add PT_GNU_PROPERTY #346

Closed ETKNeil closed 1 year ago

ETKNeil commented 2 years ago

There is an extension to gABI that add this program header : see https://raw.githubusercontent.com/wiki/hjl-tools/linux-abi/linux-abi-draft.pdf

Would it be possible to consider adding it in?

The relevant sections :

3.1 Program header
The following Linux program header types are defined:
Table 3.1: Program Header Types
Name Value
PT_GNU_EH_FRAME 0x6474e550
PT_GNU_PROPERTY 0x6474e553
PT_GNU_EH_FRAME The segment contains .eh_frame_hdr section. See
Section 2.1.3 of this document.
PT_GNU_PROPERTY The segment contains .note.gnu.property sec-
tion. See Section 2.1.5 of this document.
2.1.5 .note.gnu.property section
.note.gnu.property section contains a program property note which de-
scribes special handling requirements for linker and run-time loader. It can be
merged with other SHT_NOTE sections.
Table 2.9: The Program Property Note Format
Field Length Contents
n_namsz 4 4
n_descsz 4 The note descriptor size
n_type 4 NT_GNU_PROPERTY_TYPE_0
n_name 4 GNU
n_desc n_descsz The program property array
n_namsz Size of the n_name field. A 4-byte integer in the format of the target
processor. It should be 4.
n_descsz Size of the n_desc field. A 4-byte integer in the format of the target
processor.
n_type Type of the note descriptor. A 4-byte integer in the format of the target
processor. It should be NT_GNU_PROPERTY_TYPE_0.
n_name Owner of the program property note. A null-terminated character string.
It should be GNU.
n_desc The note descriptor. The first n_descsz bytes in n_desc is the pro-
gram property array.
m4b commented 1 year ago

Seems like this should be possible, but it would have to be optional if i understand correctly. If it isn't too much work, it might be better to see what a PR implementing this looks like. Ideally the PR is backwards compatible (non-breaking change). Do you think you'd be interested in doing this? :)

x64k commented 1 year ago

Hey, is there still any interest in this, and is anyone working on it?

I have basic support for this implemented. It's actually pretty straightforward to keep it backwards compatible, since this is really just another NOTE type, so all that needs to happen to not have goblin shrug is add a bunch of boilerplate. You can see it on this branch: https://github.com/x64k/goblin/tree/ln-gnu-property .

FWIW it should be easy to add support for decoding the actual note contents, too. I haven't pushed any code for that because it's not supported for the other note types, either -- I suppose that's technically the application's realm, not goblin's?

Anyways, if there's still interest in this I'd be happy to open a pull request.

ETKNeil commented 1 year ago

Hey, is there still any interest in this, and is anyone working on it?

I have basic support for this implemented. It's actually pretty straightforward to keep it backwards compatible, since this is really just another NOTE type, so all that needs to happen to not have goblin shrug is add a bunch of boilerplate. You can see it on this branch: https://github.com/x64k/goblin/tree/ln-gnu-property .

FWIW it should be easy to add support for decoding the actual note contents, too. I haven't pushed any code for that because it's not supported for the other note types, either -- I suppose that's technically the application's realm, not goblin's?

Anyways, if there's still interest in this I'd be happy to open a pull request.

I would definetly be interested, I have yet to free some time to implement it myself but glancing at your commit, this seems like how it should be implemented

x64k commented 1 year ago

Cool, in that case, I got a PR open. I'm obviously open to any suggestions -- I'm currently using goblin to replace some old, homebrew, very clunky code that I wrote years ago so I'm not (yet) super familiar with its innards.

m4b commented 1 year ago

this is implemented, thanks @x64k !