How to use WinIo with Python?

300 Views Asked by At

I want to write a MMIO tool with Python to get some chipset register value under Win10 64.

Below is the sample code I write to read a register which MMIO address is 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)) 

It is always return false when execute winio.InitializeWinIo(). I try to debug WinIo64.dll and rebuild it with below modification.

//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;
}

I find InstallWinIoDriver() and StartWinIoDriver() is successful but hDriver is INVALID_HANDLE_VALUE.(Always return 4.)

I am not familiar with Windows driver, may I know how to solve this issue? Thanks!!

0

There are 0 best solutions below