m4b / goblin

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

Fix `is_lib` detection for PIE and static PIE Elf objects. #366

Closed m-hilgendorf closed 1 year ago

m-hilgendorf commented 1 year ago

PIE executables (either static or dynamically linked) erroneously report is_lib == true, due to the fact that they have e_type == ET_DYN in their elf headers.

To distinguish you have to check if the DT_FLAGS_1 was set in the dynamics section.

The part that I'm not sure about is lazy_parse, which can't detect if something is a library or not.

m4b commented 1 year ago

non-breaking

m-hilgendorf commented 1 year ago

I think right now what you do is check the e_type of the Elf header for ET_DYN. However, ET_DYN only implies the object is dynamic, not if it is a library. The field name is a bit misleading in that sense, it might make more to expose the type directly through an enum (including the other variants of e_type).

m4b commented 1 year ago

released in 0.7.0, thank you so much for your patience!