首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Python CreateFile找不到PhysicalMemory

Python CreateFile找不到PhysicalMemory
EN

Stack Overflow用户
提问于 2009-09-23 19:35:23
回答 1查看 1.7K关注 0票数 0

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

代码语言:javascript
复制
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和pywintype没有产生关于不同返回值的信息。

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

代码语言:javascript
复制
# 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()

谢谢你,卡特维

EN

回答 1

Stack Overflow用户

发布于 2009-09-23 22:09:01

我不相信在Windows中从用户模式访问物理内存对象是可能的。正如您的win32dd link所建议的,您需要在内核模式下执行此操作。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/1468130

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档