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

TryRead throws when not an ELF file #4

Closed bruno-garcia closed 4 years ago

bruno-garcia commented 4 years ago

Firstly let me thank you for deciding to open source this.

Is it intentionally that ElfObjectFile.TryRead throws? I'm enumerating a whole directory and calling that hoping that it'll just return false to non ELF files. But instead I got:

Invalid ELF object file while trying to decode Elf Header Error LB0007: Invalid ELF Magic found

Is this the expected behavior?

xoofx commented 4 years ago

No, that's weird because the code doing this should go through that:

https://github.com/xoofx/LibObjectFile/blob/8323364388bf3769da9a3ae61921ff1eaedc646c/src/LibObjectFile/Elf/ElfObjectFile.cs#L645-L656

bruno-garcia commented 4 years ago

I see. It might be due to my setup. The repro is here: https://github.com/getsentry/symbol-collector/pull/7

Basically it's an Xamarin Android app which I expect to run on devices as low as Android 5 (API 21). But to use your library I need to target API 29 (Android 10 aka Q). I'm running this on an Android 5 emulator, although Xamarin Android 10 support netstandard2.1 maybe that's the reason.

xoofx commented 4 years ago

I don't know, have you tried on desktop already? PR welcome!

bruno-garcia commented 4 years ago

If I'm able to use netstandard2.1 I plan to move from ELFSharp over which means writing Mach-O support and a less hacky impl for Fat Mach-O which I hacked in-repo so far to get things moving.

xoofx commented 4 years ago

Closing as TryRead doesn't throw an exception when an invalid file is passed (as per commit dc6a604)

bruno-garcia commented 4 years ago

Just to update you on this one.

I've copied the file out the Android (emulator) ran the same code against the same file on a .NET Core 3.1 console app and it works as expected.

So as suspected, the problem only happens when running on an Xamarin.Android 10 (API 29). It's supposed to support netstandard2.1 though so maybe I'll investigate further and perhaps raise this to the Xamarin team.

filipnavara commented 4 years ago

@bruno-garcia It would make sense to test it on regular Mono on desktop since that's easier to debug than Xamarin and it uses the same code base for class libraries.

bruno-garcia commented 4 years ago

~I have mono but it won't help Tests do process.start on stuff I don't have on a Mac.~

Sorry I thought it was about another issue. I believe the problem is other. Didn't finish investigating but there's a PR #8