how to check a linux file(.so) is of 32 or

2019-08-14 01:30发布

For Checking whether a particular windows dll is of 32 or 64 bit, reading PE header will yield the needed result. But there is a need to find whether a linux file (.so) is of 32 or 64 bit.

When searched, found linux shell scripts or commands which help to find this information. But we need to find this from a windows environment. Any windows commands or code which runs on Windows OS should be able to provide this info.

标签: linux windows
2条回答
甜甜的少女心
2楼-- · 2019-08-14 02:05

It sounds like you want to be able to check this programmatically, rather than rely on installing Cygwin (as that may be overkill if you just need to check the file status). You can mimic what the file command is doing by looking up the ELF section in the magic table (in /usr/share/misc/magic on Cygwin):

# elf:  file(1) magic for ELF executables
#
# We have to check the byte order flag to see what byte order all the
# other stuff in the header is in.
#
0       string          \177ELF         ELF
>4      byte            0               invalid class
>4      byte            1               32-bit
>4      byte            2               64-bit
>5      byte            0               invalid byte order
>5      byte            1               LSB
>>16    leshort         0               no file type,
!:strength *2
!:mime  application/octet-stream
>>16    leshort         1               relocatable,
!:mime  application/x-object
>>16    leshort         2               executable,
!:mime  application/x-executable
>>16    leshort         3               shared object,

I don't know the exact syntax of the magic format rules, but it looks to me like might need to check the 5th byte which will be 1 for 32-bit and 2 for 64-bit

查看更多
爱情/是我丢掉的垃圾
3楼-- · 2019-08-14 02:05

The easiest way would be to install Cygwin and use the file command:

$ file libc.so
libc.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked (uses shared lib
s), BuildID[sha1]=0xdf6c83b270f1e32ea0482d61ae16933aa090870b, for GNU/Linux 2.6.24, stripped
查看更多
登录 后发表回答