Crusader_Decomp/tmp_build_regret_debugger20_stub.py

73 lines
2.4 KiB
Python
Raw Normal View History

2026-04-10 18:14:55 +02:00
from collections import OrderedDict
origin = 0x2040
pos = origin
parts = []
def emit(name, hex_bytes):
global pos
data = bytes.fromhex(hex_bytes)
parts.append((pos, name, data))
pos += len(data)
def emit_nops(name, count):
emit(name, '90 ' * count)
# Outer wrapper at 13f8:2040. Existing relocation operand at 0x204E requires CALLF starting at 0x204D.
emit('outer_push_bp', '55')
emit('outer_mov_bp_sp', '8B EC')
emit_nops('outer_padding', 10)
emit('outer_call_helper', '9A FF FF 00 00')
emit('outer_pop_bp', '5D')
emit('outer_retf', 'CB')
# Helper body at 13f8:2054. Existing relocation operands at 0x20BB and 0x20CF stay as CALLF sites.
emit('helper_push_bp', '55')
emit('helper_mov_bp_sp', '8B EC')
emit('helper_push_bx', '53')
emit('helper_push_es', '06')
emit('helper_mov_ax_dbg_off', 'A1 2C 71')
emit('helper_or_ax_dbg_seg', '0B 06 2E 71')
emit('helper_jz_skip_seed', '74 60')
emit('helper_les_bx_arg1', 'C4 5E 0C')
emit('helper_sub_bx_36', '83 EB 36')
emit('helper_mov_ax_process_index', '26 8B 47 02')
emit('helper_shl_ax_1a', 'D1 E0')
emit('helper_shl_ax_1b', 'D1 E0')
emit('helper_les_bx_name_table', 'C4 1E 30 44')
emit('helper_add_bx_ax', '03 D8')
emit('helper_mov_cx_name_off', '26 8B 0F')
emit('helper_mov_dx_name_seg', '26 8B 57 02')
emit('helper_les_bx_arg1_again', 'C4 5E 0C')
emit('helper_sub_bx_36_again', '83 EB 36')
emit('helper_push_third_seg', '26 FF B7 E3 00')
emit('helper_push_third_off', '26 FF B7 E1 00')
emit('helper_push_frame_seg', '26 FF B7 DC 00')
emit('helper_push_frame_off', '26 FF B7 DA 00')
emit('helper_push_cursor_seg', '26 FF B7 D8 00')
emit('helper_push_cursor_off', '26 FF B7 D6 00')
emit('helper_push_name_seg', '52')
emit('helper_push_name_off', '51')
emit('helper_push_dbg_seg', 'FF 36 2E 71')
emit('helper_push_dbg_off', 'FF 36 2C 71')
emit_nops('helper_align_to_call1', 15)
emit('helper_call_push_current_entry', '9A FF FF 00 00')
emit('helper_add_sp_14', '83 C4 14')
emit('helper_push_arg2_seg', 'FF 76 12')
emit('helper_push_arg2_off', 'FF 76 10')
emit('helper_push_arg1_seg', 'FF 76 0E')
emit('helper_push_arg1_off', 'FF 76 0C')
emit('helper_call_original_hook', '9A FF FF 00 00')
emit('helper_add_sp_08', '83 C4 08')
emit('helper_pop_es', '07')
emit('helper_pop_bx', '5B')
emit('helper_pop_bp', '5D')
emit('helper_retf', 'CB')
emit_nops('tail_padding', 3)
for offset, name, data in parts:
print(f'{offset:04X} {name:<32} {data.hex(" ")}')
print(f'final_end={pos:04X}')