2

I have an emulator of Game Boy called BGB and Pokemon Red/Blue game. In the emulator, I can open a debug window. And in the window I can see the entire memory of the game in a hex-table (memmap):

The part of the window which I need is located in the bottom-left corner: enter image description here

I have tried to take access to this data through the pywin32 library:

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()

But nothing worked... All I got was:

[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

As we can see nothing worked out. So the question is, can I grab a few bytes of data from the memory of the program or copy it from the window or not?

Dharman
  • 30,962
  • 25
  • 85
  • 135
  • Есть StackOverflow на русском: https://ru.stackoverflow.com – ForceBru Nov 08 '20 at 15:07
  • @ForceBru да, спасибо, я знаю. Просто тут, я надеюсь, вероятность получить ответ будет больше :) А то я уже спрашивал на киберфоруме и там, за пять дней, так никто и не ответил... – ForgottenGhost Nov 08 '20 at 15:25
  • The return value of `WM_GETTEXT` is 0. You can use spy++ to check whether the text content of the corresponding window is obtained, and use `GetLastError` to check the specific error information. Of course, I recommend that you get the data by reading the program memory. – Zeus Nov 09 '20 at 03:02
  • 1
    To get to the underlying data displayed in a window you need the cooperation of the window in question. Since there is no standard control that implements a hex view, it's a fair bet to assume that you are dealing with a custom implementation. Unless that custom implementation exposes UI Automation interfaces, there's virtually nothing you can do to get the data. You'll have to contact the author and have them implement the functionality. – IInspectable Nov 09 '20 at 13:00

0 Answers0