2

我有一个名为 BGB 和 Pokemon Red/Blue 游戏的 Game Boy 模拟器。在模拟器中,我可以打开一个调试窗口。在窗口中,我可以在十六进制表(memmap)中看到游戏的整个内存:

我需要的窗口部分位于左下角: 在此处输入图像描述

我试图通过 pywin32 库访问这些数据:

import win32gui
import win32con
 
 
def _windowEnumerationHandler(hwnd, resultlist):
    """Pass to win32gui.EnumWindows() to generate list of window handle,
    window text, window class tuples."""
    resultlist.append((hwnd,
                       win32gui.GetWindowText(hwnd),
                       win32gui.GetClassName(hwnd)))
 
 
def enumChild(hwnd):
    previous = None
    while True:
        cur = win32gui.FindWindowEx(hwnd, previous, None, None)
        if not cur:
            return
        yield cur
        previous = cur
 
 
def main():
    hWnd = win32gui.FindWindow(None, 'bgb debugger - R:\Games\BGB\ROMs\Pokemon - Red Version (UE) [S][!].gb')
    print(win32gui.GetWindowText(hWnd))
    windows = []
    win32gui.EnumChildWindows(hWnd, _windowEnumerationHandler, windows)
    hTpl = windows[19]
    hFrm = hTpl[0]
    print('Handle Window = {hWnd}\nHandle Tuple = {hTpl}\nHandle Frame = {hFrm}'
          .format(hWnd=hWnd,
                  hTpl=hTpl,
                  hFrm=hFrm))
    print(windows)
    lWindowTexts = [win32gui.GetWindowText(item) for item in enumChild(hWnd)]
    print(lWindowTexts)
    print('--------------')
    FrameChilds = []
    win32gui.EnumChildWindows(hFrm, _windowEnumerationHandler, FrameChilds)
    print(FrameChilds)
    hCtrl = FrameChilds[0][0]
    print('Handle Control = {0}'.format(hCtrl))
    lChildTexts = [win32gui.GetWindowText(item) for item in enumChild(hFrm)]
    print(lChildTexts)
    buffer = win32gui.PyMakeBuffer(300000)
    print('Text:', win32gui.SendMessage(hCtrl, win32con.WM_GETTEXT, len(buffer), buffer))
 
 
if __name__ == '__main__':
    main()

但是没有任何效果......我得到的只是:

[Console out]
bgb debugger - R:\Games\BGB\ROMs\Pokemon - Red Version (UE) [S][!].gb
Handle Window = 2033576
Handle Tuple = (1574836, '', 'tscrollermemmap')
Handle Frame = 1574836
[(395264, '', 'Tdrawcontrol'), (460850, 'c', 'TPanel'), (395250, '', 'TCheckBox'), (395266, 'h', 'TPanel'), (395212, '', 'TCheckBox'), (460824, 'n', 'TPanel'), (460720, '', 'TCheckBox'), (395204, 'z', 'TPanel'), (460686, '', 'TCheckBox'), (395232, '', 'tcpumetercontrol'), (395202, '', 'Tdrawcontrol'), (395254, '', 'tscrollerasm'), (395260, '', 'Tdrawcontrol'), (395284, '', 'TScrollBar'), (395210, '', 'tscrollerstack'), (395286, '', 'Tdrawcontrol'), (395292, '', 'TScrollBar'), (591780, '', 'tscrollerregs'), (395256, '', 'Tdrawcontrol'), (1574836, '', 'tscrollermemmap'), (395270, '', 'Tdrawcontrol'), (395272, '', 'TScrollBar'), (395274, '', 'TStatusBar')]
['', '', '', '', '', '', '']
--------------
[(395270, '', 'Tdrawcontrol'), (395272, '', 'TScrollBar')]
Handle Control = 395270
['', '']
Text: 0

正如我们所看到的,没有任何结果。所以问题是,我可以从程序的内存中抓取几个字节的数据还是从窗口中复制它?

4

0 回答 0