Generic way to check the architecture of a file

1.5k Views Asked by At

Is there a general way to check the platform (32-bit/64-bit) and architecture (powerpc, arm, etc...) of a binary file (Which can be ELF, Dwarf, PE, etc...)?

I know that almost every file (elf or pe) has a header which says which architecture can execute it but is there a generic way to get this information from all of the binary files?

I tried using magic which returns all of this info but it returns it in a string -

ELF 64-bit LSB executable, x86-64,ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib/ld.so.0, stripped

Right now, I'm using a regex to extract the information out of it but I'm not sure if can always count on that because the string output of magic can be different.

0

There are 0 best solutions below