1

我想用 Python 写一个 MMIO 工具来获取 Win10 64 下的一些芯片组寄存器值。

下面是我为读取 MMIO 地址为 0xFD6E0604 的寄存器而编写的示例代码。

from ctypes import *

winio = windll.LoadLibrary("WinIo64.dll")
winio.InitializeWinIo()
print(winio.InitializeWinIo())
DWxData = c_ulong(4)
winio.GetPhysLong(0xFD6E0604, byref(DWxData))
print(hex(DWxData.value)) 

执行 winio.InitializeWinIo() 时总是返回 false。我尝试调试 WinIo64.dll 并通过以下修改重建它。

//DBG- bool __stdcall InitializeWinIo()
int __stdcall InitializeWinIo()
{
    bool bResult;
    int status = 0;
    DWORD dwBytesReturned;

    g_Is64BitOS = Is64BitOS();

    hDriver = CreateFile(L"\\\\.\\WINIO",
        GENERIC_READ | GENERIC_WRITE,
        0,
        NULL,
        OPEN_EXISTING,
        FILE_ATTRIBUTE_NORMAL,
        NULL);

    // If the driver is not running, install it

    if (hDriver == INVALID_HANDLE_VALUE)
    {       
        GetDriverPath();

        bResult = InstallWinIoDriver(szWinIoDriverPath, true);

        if (!bResult)
            status = 2;
//DBG-          return false;

        bResult = StartWinIoDriver();

        if (!bResult)
            status = 3;
//DBG-          return false;

        hDriver = CreateFile(L"\\\\.\\WINIO",
            GENERIC_READ | GENERIC_WRITE,
            FILE_SHARE_READ | FILE_SHARE_WRITE,
            NULL,
            OPEN_EXISTING,
            FILE_ATTRIBUTE_NORMAL,
            NULL);

        if (hDriver == INVALID_HANDLE_VALUE)
            status = 4;
//DBG-          return false;
    }

    // Enable I/O port access for this process if running on a 32 bit OS

    if (!g_Is64BitOS)
    {
        if (!DeviceIoControl(hDriver, IOCTL_WINIO_ENABLEDIRECTIO, NULL,
            0, NULL, 0, &dwBytesReturned, NULL))
        {
            status = 5;
//DBG-          return false;
        }
    }

    IsWinIoInitialized = true;

//DBG-  return true;
    return status;
}

我发现 InstallWinIoDriver() 和 StartWinIoDriver() 是成功的,但 hDriver 是 INVALID_HANDLE_VALUE。(总是返回 4。)

我不熟悉Windows驱动程序,我可以知道如何解决这个问题吗?谢谢!!

4

0 回答 0