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:
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?