1

为了检查特定的 windows dll 是 32 位还是 64 位,读取 PE 标头将产生所需的结果。但是需要确定一个 linux 文件 (.so) 是 32 位还是 64 位。

搜索时,发现有助于查找此信息的 linux shell 脚本或命令。但是我们需要从windows环境中找到这个。在 Windows 操作系统上运行的任何 Windows 命令或代码都应该能够提供此信息。

4

2 回答 2

5

听起来您希望能够以编程方式进行检查,而不是依赖于安装 Cygwin(因为如果您只需要检查文件状态,这可能是矫枉过正)。file您可以通过查找magic表中的 ELF 部分(在/usr/share/misc/magicCygwin 中)来模仿命令正在执行的操作:

# 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 表示 32 位,2 表示 64 位

于 2013-10-18T08:39:24.993 回答
5

最简单的方法是安装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
于 2013-10-18T08:33:08.760 回答