def debug(self): import pygamehack as gh with open('MarkerAddress-64.txt') as f: marker_addr = int(f.read()) self.hack = gh.Hack() self.root_address = gh.Address(self.hack, marker_addr) self.struct = TestProgram(self.root_address) self.struct.address.name = "TestProgram"
def test_hack_cheat_engine_save_pointer_scan_file_compressed( pointer_scan_file_write, pointer_scan_file_offsets): hack = gh.Hack() addresses = [] for offset in pointer_scan_file_offsets: addresses.append(gh.Address(hack, 'TestProgram-64.exe', offset)) settings = gh.CheatEnginePointerScanSettings() hack.cheat_engine_save_pointer_scan_file(pointer_scan_file_write, addresses, settings, True)
def test_hack_cheat_engine_load_pointer_scan_file_compressed( pointer_scan_file_read, pointer_scan_file_offsets): hack = gh.Hack() addresses, settings = hack.cheat_engine_load_pointer_scan_file( pointer_scan_file_read, True) for i, a in enumerate(addresses): assert a.type == gh.Address.Type.Static assert a.module_name == 'TestProgram-64.exe' assert a.module_offset == pointer_scan_file_offsets[i] assert settings.max_level == 7 assert settings.max_offset == 4095 assert settings.is_compressed == True assert settings.is_aligned == True assert settings.ends_with_offsets == []
def test_hack_cheat_engine_load_pointer_scan_file_uncompressed( pointer_scan_file_read_uncompressed, pointer_scan_file_offsets_uncompressed): hack = gh.Hack() addresses, settings = hack.cheat_engine_load_pointer_scan_file( pointer_scan_file_read_uncompressed, True) for i, a in enumerate(addresses): assert a.type == gh.Address.Type.Static assert a.module_name == 'TestProgram-64.exe' assert a.module_offset == pointer_scan_file_offsets_uncompressed[i] assert settings.max_level == 3 assert settings.max_offset == ((1 << 32) - 1) # UINT32_MAX assert settings.is_compressed == False assert settings.is_aligned == False assert settings.ends_with_offsets == []
def test_buffer_create_incorrect(): hack = gh.Hack() buf1 = gh.Buffer(hack, 32) # Buffer with size=0 with pytest.raises(RuntimeError): buf2 = gh.Buffer(hack, 0) # View with size=0 with pytest.raises(RuntimeError): buf2 = gh.Buffer(buf1, 16, 0) # View that exceeds memory range of parent with pytest.raises(RuntimeError): buf2 = gh.Buffer(buf1, 32, 16) with pytest.raises(RuntimeError): buf2 = gh.Buffer(buf1, 16, 32)
def test_gdb(program_name, app_addresses, gdb_path): hack = gh.Hack() hack.attach(program_name) gdb = GDB(gdb_path) gdb.attach(hack.process.pid) previous, updated = 0, 1 def assert_watch(watch, prev, upd, data): nonlocal previous, updated assert int(prev) == previous assert int(upd) == updated previous = (previous + 1) % 4 updated = (updated + 1) % 4 for i, addr in enumerate(app_addresses.roots): w = Watch('w' + str(i), addr + 8, assert_watch) w.c_type = 'unsigned int' gdb.add_watch(w) with gdb.continue_wait(): hack.write_u32(addr + 8, 1) # with gdb.continue_wait(): # hack.write_u32(addr + 8, 1) # # with gdb.continue_wait(): # hack.write_u32(addr + 8, 1) # # with gdb.continue_wait(): # hack.write_u32(addr + 8, 1) gdb.remove_watch(w) gdb.detach()
def test_hack_attach_detach(app): hack = gh.Hack() # Unattached assert not hack.process.attached # Attach different ways for arg in [app.pid, app.program_name]: for read_only in [False, True]: hack.detach() hack.attach(arg, read_only=read_only) assert hack.process.attached assert hack.process.read_only == read_only assert hack.process.pid == app.pid # Attach/detach repeatedly hack.detach() for i in range(10): assert not hack.process.attached hack.attach(app.pid) assert hack.process.attached hack.detach() assert not hack.process.attached
def test_buffer_create(): hack = gh.Hack() # Owning buf1 = gh.Buffer(hack, 32) assert 32 == buf1.size assert 0 == buf1.read_u32(16) buf1.write_u32(16, 10) assert 10 == buf1.read_u32(16) # View buf2 = gh.Buffer(buf1, 16, 16) assert 16 == buf2.size assert 10 == buf2.read_u32(0) buf2.write_u32(0, 4) assert 4 == buf1.read_u32(16) assert 4 == buf2.read_u32(0) # Clear buf1.clear() assert 0 == buf1.read_u32(16) assert 0 == buf2.read_u32(0)
def hack(app): hack = gh.Hack() hack.attach(app.pid) yield hack hack.detach()