konrad-kruczynski / elfsharp

Pure managed C# library for reading ELF, UImage, Mach-O binaries.
https://elfsharp.it
Other
159 stars 57 forks source link

Fixed Section.GetContents trying to read NoBits section #81

Closed dedmen closed 2 years ago

dedmen commented 2 years ago

https://man7.org/linux/man-pages/man5/elf.5.html

Search for SHT_NOBITS

sh_offset This member's value holds the byte offset from the beginning of the file to the first byte in the section. One section type, SHT_NOBITS, occupies no space in the file, and its sh_offset member locates the conceptual placement in the file.

The old code tried to happily read a section from file, that simply isn't present in the file, which causes this to return bogus data. I'm not sure if this is the correct approach to fix this, but the section isn't present in the file thus you cannot really return its contents.

If you need a repro,

objcopy --only-keep-debug sourceBinary sourceBinary.debug turns .eh_frame into NoBits

konrad-kruczynski commented 2 years ago

Thanks for the PR. Indeed there was a bug, actually it's quite funny that this didn't show up until now. Anyway I'll review it in a moment.

konrad-kruczynski commented 2 years ago

Finished, just one small remark to consider.

konrad-kruczynski commented 2 years ago

I'm merging it with my remark now.

konrad-kruczynski commented 2 years ago

Released in 2.13.2.