0

我正在尝试访问 Windows 2000 系统的物理内存(尝试在没有内存转储工具的情况下执行此操作)。我的理解是我需要使用 CreateFile 函数来创建句柄。我使用了旧版本的win32dd来帮助我解决这个问题。网络上的其他文档指向我使用“\Device\PhysicalMemory”或“\\.\PhysicalMemory”。不幸的是,我得到了相同的错误。

Traceback (most recent call last):
   File "testHandles.py", line 101, in (module)
   File "testHandles.py", line 72, in createFileHandle
pywintypes.error: (3, 'CreateFile', 'The system cannot find the path specified.')

实际上,每次运行返回的错误号都不同 \\.\PhysicalMemory == 3 和 \Device\PhysicalMemory == 2。对 pywin32、win32file、createfile、pyhandle 和 pywintypes 的审查没有产生关于不同返回值的信息.

这是我的代码。我正在使用 py2exe 让它在 Windows 2000 上运行(是的,它编译成功)。我意识到我可能对 DeviceIoControl 也有问题,但现在我专注于 CreateFile。

# testHandles.py

import ctypes
import socket
import struct
import sys
import win32file
import pywintypes

def createFileHandle():

    outLoc = pywintypes.Unicode("C:\\Documents and Settings\\Administrator\\My Documents\\pymemdump_dotPM.dd")
    handleLoc = pywintypes.Unicode("\\\\.\\PhysicalMemory")
    #handleLoc = pywintypes.Unicode("\\Device\\PhysicalMemory")
    placeHolder = 0
    BytesReturned = 0


    # Device =                                              CreateFile(L"\\\\.\\win32dd", GENERIC_ALL, FILE_SHARE_READ | FILE_SHARE_WRITE, NULL, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, NULL);
    #                                                           CreateFile(fileName,                        desiredAccess ,          shareMode ,    attributes , creationDisposition ,      flagsAndAttributes ,                    hTemplateFile )
    #hMemHandle = win32file.CreateFile(handleLoc, GENERIC_ALL, SHARE_READ, None, OPEN_EXISTING, FILE_ATTRIBUTE_NORMAL, None)
    hMemHandle = win32file.CreateFile(handleLoc, win32file.GENERIC_READ, win32file.FILE_SHARE_READ, None, win32file.OPEN_EXISTING, win32file.FILE_ATTRIBUTE_NORMAL, None)
    print "hMemHandle: %s" % hMemHandle
    if (hMemHandle == NO_ERROR):
        print "Could not build hMemHandle"
        sys.exit()

    # We send destination path to the driver.
    #if (!DeviceIoControl(hMemHandle, 0x19880922, outLoc, (ULONG)(wcslen(outLoc) + 1) * sizeof(TCHAR), NULL, 0, &BytesReturned, NULL))
    if (ctypes.windll.Kernel32.DeviceIoControl(hMemHandle, 0x19880922, outLoc, 5, NULL, 0, BytesReturned, NULL)):
        print "Error: DeviceIoControl(), Cannot send IOCTL.\n"
    else:
        print "[win32dd] Physical memory dumped. You can now check %s.\n" % outLoc

# Dump memory
createFileHandle()

谢谢,切图

4

1 回答 1

0

我不相信可以从 Windows 中的用户模式访问物理内存对象。正如您的win32dd 链接所建议的那样,您需要从内核模式执行此操作。

于 2009-09-23T22:09:01.097 回答