简体   繁体   English

判断 .dll 文件是 32 位还是 64 位的 Windows 命令?

[英]Windows command to tell whether a .dll file is 32 bit or 64 bit?

I'm looking for a command in windows cmd to tell me if a certain dll file is 32 bit or 64 bit我正在 windows cmd 中寻找一个命令来告诉我某个 dll 文件是 32 位还是 64 位

Is there something like this in windows ? Windows 中有类似的东西吗?

DUMPBIN is included with Visual C++ and can provide this information with the /HEADERS switch. DUMPBIN包含在 Visual C++ 中,可以通过/HEADERS开关提供此信息。

Example output from a 32-bit image:来自 32 位图像的示例输出:

FILE HEADER VALUES
     14C machine (i386)
       6 number of sections
306F7A22 time date stamp Sun Oct 01 22:35:30 1995
       0 file pointer to symbol table
     1D1 number of symbols
      E0 size of optional header
     302 characteristics
            Executable
            32 bit word machine
            Debug information stripped

You can use the dbghelp library to obtain the image headers.您可以使用 dbghelp 库来获取图像标题。 Then you can read the information you need out of the FileHeader .然后您可以从FileHeader读取您需要的信息。

Here's some sample code.这是一些示例代码。 Please forgive the rather lame error handling.请原谅相当蹩脚的错误处理。 I just knocked it up quickly to illustrate, and I'm not even remotely fluent in C++.我只是快速地将它敲起来以进行说明,而且我什至不精通 C++。

#include <Windows.h>
#include <Dbghelp.h>

#include <string>
#include <iostream>

using namespace std;

bool GetImageFileHeaders(wstring fileName, IMAGE_NT_HEADERS &headers)
{
    HANDLE fileHandle = CreateFile(
        fileName.c_str(),
        GENERIC_READ,
        FILE_SHARE_READ,
        nullptr,
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL,
        0
    );
    if (fileHandle == INVALID_HANDLE_VALUE)
        return false;

    HANDLE imageHandle = CreateFileMapping(
        fileHandle,
        nullptr,
        PAGE_READONLY,
        0,
        0,
        nullptr
    );
    if (imageHandle == 0)
    {
        CloseHandle(fileHandle);
        return false;
    }

    void *imagePtr = MapViewOfFile(
        imageHandle,
        FILE_MAP_READ,
        0, 
        0,
        0
    );
    if (imagePtr == nullptr)
    {
        CloseHandle(imageHandle);
        CloseHandle(fileHandle);
        return false;
    }

    PIMAGE_NT_HEADERS headersPtr = ImageNtHeader(imagePtr);
    if (headersPtr == nullptr)
    {
        UnmapViewOfFile(imagePtr);
        CloseHandle(imageHandle);
        CloseHandle(fileHandle);
        return false;
    }

    headers = *headersPtr;

    UnmapViewOfFile(imagePtr);
    CloseHandle(imageHandle);
    CloseHandle(fileHandle);

    return true;
}

int main(int argc, char* argv[])
{
    IMAGE_NT_HEADERS headers;
    if (GetImageFileHeaders(L"C:\\windows\\system32\\user32.dll", headers))
    {
        if (headers.FileHeader.Machine == IMAGE_FILE_MACHINE_I386)
            cout << "x86";
        else if (headers.FileHeader.Machine == IMAGE_FILE_MACHINE_IA64)
            cout << "IA64";
        else if (headers.FileHeader.Machine == IMAGE_FILE_MACHINE_AMD64)
            cout << "x64";
        else
            cout << "Machine not recognised";
    }
    return 0;
}

To link this you need to add dbghelp.lib to the additional dependencies of your project.要链接它,您需要将dbghelp.lib添加到项目的其他依赖项中。 To learn more about the details behind this, refer to the MSDN documentation for the various API calls that are used.要了解有关这背后的详细信息的更多信息,请参阅 MSDN 文档以了解所使用的各种 API 调用。

如果您已安装 7zip :

"C:\Program Files\7-Zip\7z.exe" l "my-program.exe" | findstr CPU

The capability you are looking for is available natively on UNIX systems;您正在寻找的功能可在 UNIX 系统本机上使用; use the 'file' command.使用“文件”命令。 You can use 'file' on Windows systems if you install Cygwin or one of the other UNIX emulators.如果您安装 Cygwin 或其他 UNIX 模拟器之一,则可以在 Windows 系统上使用“文件”。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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