Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Is there something like this in windows ?

like image 284
becks Avatar asked Jan 28 '13 11:01

becks


People also ask

How can I tell if a DLL is 64-bit notepad?

After you open the binary file in Notepad, use the Find option to look for the 1st occurrence of the word PE . The letter that follows the PE header tells you if the file is 32-bit or 64-bit. 32-bit (x86) programs would have PE L as the header. 64-bit (x64) programs would have PE d† as the header.

How do I change a 32-bit DLL to 64-bit?

Solution 2 If possible create a separate 32 bits application that uses the 32 bit dll and call that using Process. Start()[^] from your 64 bits application. There are other ways like using named pipes for inter-process communincation, but they are quite complex to implement.

How can I tell if a file is 32-bit?

Press Ctrl + Shift + Esc to open up Task Manager. If you see the simple Task Manager interface, click on More details to see the full version. Once you see the full version of Task Manager, select the Detail tab from the horizontal menu at the top.


3 Answers

DUMPBIN is included with Visual C++ and can provide this information with the /HEADERS switch.

Example output from a 32-bit image:

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
like image 50
Jon Avatar answered Oct 13 '22 09:10

Jon


If you have installed 7zip :

"C:\Program Files\7-Zip\7z.exe" l "my-program.exe" | findstr CPU
like image 24
P. Debrabant Avatar answered Oct 13 '22 10:10

P. Debrabant


You can use the dbghelp library to obtain the image headers. Then you can read the information you need out of the 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++.

#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. To learn more about the details behind this, refer to the MSDN documentation for the various API calls that are used.

like image 21
David Heffernan Avatar answered Oct 13 '22 10:10

David Heffernan