xoofx / LibObjectFile

LibObjectFile is a .NET library to read, manipulate and write linker and executable object files (e.g ELF, PE, DWARF, ar...)
BSD 2-Clause "Simplified" License
159 stars 11 forks source link

Fails to load ELF files from Android #5

Closed bruno-garcia closed 4 years ago

bruno-garcia commented 4 years ago

Is it expected that the library can load ELF files from an Android emulator?

The files in question came from an Android emulator (x86) but I'm processing them via a .NET Core 3.1 console app. ELFSharp can successfully load the same files.

Example output:

Processing file: Files/libchrome.so
ELF diag Error LB0114: Unable to read program header table as the size of program header entry (e_phentsize) == 0 in the Elf Header
Error LB0118: Unable to read section header table as the size of section header entry (e_ehsize) == 0 in the Elf Header

Please note these are different errors than when the same code runs on Android. LibObjectFile in Android seem not to work for other reasons likely unrelated to the library itself.

One of such files is here. It's part of a repro I've made which includes a readme. It also includes more details relevant to Xamarin.Android that are not related to this issue.

xoofx commented 4 years ago

It's just that the test might be to restrictive for that field. PR welcome.

bruno-garcia commented 4 years ago

While investigating this, lead me to open #8 . ELFSharp chooses whether to use the DirectDecoder or the endianness flipping one based on the Class while LibObjectFIle does that based on the 5th bit (encoding).

I successfully parsed ELF files from Linux x86, ARM and Android using that library so I'm afraid the problem is here.

Also, the output of loading the same library when running on an Android emulator and on my desktop differs. If I force (with the debugger) to use Class to define endienness, the output matches in both.

bruno-garcia commented 4 years ago

After the bug fix released on 0.3.2 the behavior on Android and .NET Core 3 match.

In both cases it fails with:

image

Closing this issue now.

xoofx commented 4 years ago

Could you open an issue with attached the ELF file generating such errors?, I'm curious how this can happen.