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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14560866/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-09 10:13:43  来源:igfitidea点击:

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

windowsdllcmd32bit-64bit

提问by becks

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 中有类似的东西吗?

回答by Jon

DUMPBINis included with Visual C++ and can provide this information with the /HEADERSswitch.

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

回答by David Heffernan

You can use the dbghelp library to obtain the image headers. Then you can read the information you need out of the FileHeader.

您可以使用 dbghelp 库来获取图像标题。然后,您可以从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.libto the additional dependencies of your project. To learn more about the details behind this, refer to the MSDN documentation for the various API calls that are used.

要链接它,您需要添加dbghelp.lib到项目的其他依赖项中。要了解有关这背后的详细信息的更多信息,请参阅 MSDN 文档以了解所使用的各种 API 调用。

回答by Chris Golledge

The capability you are looking for is available natively on UNIX systems; use the 'file' command. You can use 'file' on Windows systems if you install Cygwin or one of the other UNIX emulators.

您正在寻找的功能可在 UNIX 系统本机上使用;使用“文件”命令。如果您安装 Cygwin 或其他 UNIX 模拟器之一,则可以在 Windows 系统上使用“文件”。