gdb_video_state.py 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. # State of WE's video texture player on a live WE (wallpaper64.exe 2.8.42): the player thread's play gate
  2. # (sub_1400F3930 at 0x1400f3a34: +0x90 play requested, +0x60 frame counter of the last transfer vs the scene counter,
  3. # +0x91 engine playing, +0x92 dirty), the OnVideoStreamTick result (0x1400f3aeb), every entry of the transfer
  4. # (sub_1400F3480 at 0x1400f3496, +0xc9 needs transfer) and the TransferVideoFrame arguments (0x1400f353f).
  5. # Only lines that differ from the previous one of the same kind are written.
  6. # OUT=state.txt SECONDS=20 gdb -q -batch -p <wallpaper64.exe pid> -x gdb_video_state.py
  7. import gdb, os, struct, time
  8. gdb.execute('set pagination off')
  9. gdb.execute('set confirm off')
  10. out = open(os.environ.get('OUT', 'video_state.txt'), 'w')
  11. inf = gdb.selected_inferior()
  12. end = time.time() + float(os.environ.get('SECONDS', 20))
  13. last = {}
  14. def reg(n):
  15. return int(gdb.selected_frame().read_register(n)) & 0xffffffffffffffff
  16. def mem(addr, fmt):
  17. return struct.unpack(fmt, bytes(inf.read_memory(addr, struct.calcsize(fmt))))
  18. def player(rbx):
  19. counter = mem(mem(rbx + 0x50, 'Q')[0] + 0x144, 'I')[0]
  20. req, playing, dirty = mem(rbx + 0x90, 'BBB')
  21. w, h, fps = mem(rbx + 0x68, 'iif')
  22. return 'player %#x req %d playing %d dirty %d last %d counter %d needs %d info %dx%d %.2f' % (
  23. rbx, req, playing, dirty, mem(rbx + 0x60, 'I')[0], counter, mem(rbx + 0xc9, 'B')[0], w, h, fps)
  24. def log(kind, text):
  25. if last.get(kind) != text:
  26. last[kind] = text
  27. out.write('%.3f %s %s\n' % (time.time(), kind, text))
  28. out.flush()
  29. if time.time() > end:
  30. gdb.execute('delete')
  31. out.close()
  32. gdb.post_event(lambda: gdb.execute('detach'))
  33. class B(gdb.Breakpoint):
  34. def __init__(self, addr, kind, fn):
  35. super().__init__('*' + hex(addr), internal=False)
  36. self.kind, self.fn = kind, fn
  37. def stop(self):
  38. log(self.kind, self.fn())
  39. return False
  40. B(0x1400f3a34, 'gate', lambda: 'want %d ' % (reg('rdi') & 0xff) + player(reg('rbx')))
  41. B(0x1400f3aeb, 'tick', lambda: 'hr=0x%08x' % (reg('rax') & 0xffffffff))
  42. B(0x1400f3496, 'bind', lambda: player(reg('rbx')))
  43. B(0x1400f353f, 'transfer', lambda: 'dst tex %#x src %s dst %s' % (reg('rdx'), mem(reg('r8'), '4f'), mem(reg('r9'), '4i')))
  44. gdb.execute('continue')