为了检查特定的Windows dll是32位还是64位,读取PE标头将产生所需的结果。 但是需要找出 linux 文件 (.so) 是 32 位还是 64 位。
搜索时,找到有助于查找此信息的 linux shell 脚本或命令。 但是我们需要从Windows环境中找到它。在Windows操作系统上运行的任何Windows命令或代码都应该能够提供此信息。
最简单的方法是安装 Cygwin 并使用 file
命令:
$ 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
能够以编程方式检查这一点,而不是依赖安装 Cygwin(因为如果您只需要检查文件状态,这可能会矫枉过正)。 您可以通过查找magic
表中的 ELF 部分来模拟 file
命令正在执行的操作(在 Cygwin 上/usr/share/misc/magic
):
# 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,
我不知道magic
格式规则的确切语法,但在我看来可能需要检查第 5 个字节,该字节为 1 位,2 表示 64 位