简体   繁体   中英

How to check if a object code is 16/32 bit?

Is there any way by which we can identify that a .obj file and .exe file is 16/32 bit?

Basically I want to create a smart linker, that will automatically identify which linker do the given file names need to be passed to.

Preferred Language: C (it can be different, if needed)

I am looking for some solution that can read the bytes of an .exe /the code of an .obj file and then determine if it's 16/32 bit. Even an algorithm would too do.

Note: I know both object code and a executable are two different entities.

All of this information is encoded in the binary object according to the relevant Application Binary Interface (ABI).

The current Linux ABI is the Executable and Linkable Format (ELF), and you can query a specific binary file using a tool such as readelf or objdump.

The current Windows ABI is the Portable Executable (PE) format. I'm not familiar with the toolset here but a quick google search suggests there are programs that function the same as readelf:

http://www.pe-explorer.com/peexplorer-tour.htm

Here's the Microsoft specification of the PE format:

https://docs.microsoft.com/en-us/windows/win32/debug/pe-format

However, neither of those formats support 16-bit binaries anymore. The older ABI format is called "a.out" for Linux, which can be read and queried with objdump (I'm not sure about readelf). The older Windows/DOS formats are called MZ and NE. Again, I'm not familiar with the tool support for these older Windows formats.

Wikipedia has a pretty comprehensive list of all the popular executable file formats that have been used, with links to more info:

https://en.wikipedia.org/wiki/Comparison_of_executable_file_formats

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM