我想用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的句柄值无效。(始终返回4。)
我不熟悉windows驱动程序,请问如何解决这个问题?谢谢
暂无答案!
目前还没有任何答案,快来回答吧!