Reputation: 85
I am wondering if there is a simple way in Linux, or maybe an existing open source project that will allow me to provide it a binary or firmware image and it will return both the architecture (aarch64, armv7-eabihf, armv7m, etc.) and the libc type (glibc, musl, uclibc) used?
My hope is to be able to script a way to automatically grab the correct qemu-system-* image (e.g. https://azeria-labs.com/emulate-raspberry-pi-with-qemu/) for device emulation as well as the correct cross-compile toolchain (https://toolchains.bootlin.com/) based on either a single binary to emulate (ideal), or a full firmware image (less ideal).
Current understanding - Full architecture may be able to be "mapped" to toolchains.bootlin.com and qemu-system-* architectures based on output of the file
command, maybe? Also, I know there are lots of answers here on SO that show similar answers for this question, but assume you have some kind of system access and can run commands like "ldd". I'm looking for a solution that is based purely on static analysis of either a binary or if necessary a firmware image of an unknown device.
Upvotes: 1
Views: 144
Reputation: 985
For standalone binaries you can run utilities like objdump
and grep for some header members. For architecture it should be e_machine member of ELF header.
I dont know how to get libc type from a binary, but would suggest to make a test on some small program building it with all libc types and then analyzing
the differences in headers of all built binaries.
The task gets complicated for firmware images, since there can be entire filesystems. I would suggest to use projects like https://github.com/cruise-automation/fwanalyzer to analyze them.
Upvotes: 1