【问题标题】:how to check a linux file(.so) is of 32 or 64 bit from windows machine如何从 Windows 机器检查 linux 文件(.so)是 32 位还是 64 位
【发布时间】:2013-10-18 16:39:24
【问题描述】:

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

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

【问题讨论】:

  • 为什么不直接解析elf头呢?
  • .so 不只是 ELF 文件吗? (我不知道,不是进入 linux)如果是这样,在偏移量 4 处有一个字节,32 位为 1,64 位为 2
  • 你不能只通过 ssh 来做,例如ssh remote-machine file my_file ?

标签: linux windows


【解决方案1】:

最简单的方法是安装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

【讨论】:

    【解决方案2】:

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

    # 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 位

    【讨论】:

      猜你喜欢
      • 2011-02-10
      • 2011-01-24
      • 2012-07-29
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-09-11
      • 1970-01-01
      • 2014-08-04
      相关资源
      最近更新 更多