Crusader_Decomp/docs/jp-remorse-hidden-debugger-investigation.md
Marco 1225a3e737 Refactor and enhance documentation and tooling for Crusader USECODE
- Updated retail-debugger-entry-options.md to clarify the status of the debugger in No Remorse and No Regret, including findings from recent investigations.
- Revised usecode-format-specification.md to improve clarity on opcode behavior and historical naming conventions, with added references to Japanese executable analysis.
- Introduced usecode-jp-dispatch-analysis.md to document findings from the Japanese No Remorse executable, detailing opcode dispatch and search object behavior.
- Added ghidra_to_dosbox_memory.py, a new tool for translating Ghidra segment:offset addresses to DOSBox physical memory offsets, including comprehensive address validation.
- Created test_ghidra_to_dosbox_memory.py to ensure the correctness of address translation logic and selector base loading, with unit tests covering various scenarios.
2026-10-08 17:40:59 +02:00

14 KiB

Japanese No Remorse Hidden Debugger Investigation

Scope

This note records the debugger-focused investigation of the Win32 Japanese build /ja/CRUSADER.EXE, including the initial string scan and the follow-up live-Ghidra function pass.

Question for this pass:

  • did the JP build keep the old hidden usecode debugger itself,
  • or did it only keep the broader cheat/debug framework (-laurie, JASSICA16, immortality, -debug, -u, and related launch/key features)?

Short Answer

Current best read after a deeper live-Ghidra pass: the JP Win32 build preserves broad cheat/debug machinery and ordinary usecode execution, but no classic hidden usecode-debugger bootstrap, break-state object, UI, or event subsystem has been recovered. The function-side checks strengthen the original string-based negative result without proving absolute absence.

The strongest current reason is simple and specific: the live JP image does not contain the classic debugger-only English UI string bundle seen in the DOS-side hidden debugger, while the same live byte-search method does recover known surviving JP cheat/debug strings such as JASSICA16, Immortality enabled., and Cheats are now active.

That makes the current comparison result asymmetrical:

  • REGRET.EXE still shows the hidden debugger subsystem and a recovered write-side bootstrap
  • JP /ja/CRUSADER.EXE still shows broad cheat/debug support, but the deeper function-side pass also did not recover the classic hidden debugger surface

Verified Findings From This Pass

1. The byte-search method is valid on the live JP target

Live search_bytes against the active JP program recovered known strings that earlier JP notes already proved were real.

Positive-control hits from this pass:

  • JASSICA16 -> hit at 0047b1cc
  • Immortality enabled. -> hit at 004192b6
  • Cheats are now active. -> hit at 004192cb

This matters because it rules out the simplest failure mode. The JP image is searchable with the current tool flow, and ordinary internal English cheat/debug strings are still present as raw bytes.

2. The classic hidden-debugger string bundle does not appear in the JP image

Live search_bytes against the active JP program returned no hits for the following classic hidden-debugger UI strings:

  • Goto Line
  • Watch what?
  • Inspect what?
  • Global name
  • Search for
  • FILE NOT FOUND
  • Unable to open this file
  • Nothing to find
  • Not found
  • Done

This is the main result of the pass.

Those strings are not generic cheat/debug text. They are the most characteristic UI vocabulary of the hidden usecode debugger's file-open, goto-line, watch, inspect, global-edit, and search flows.

3. That absence is stronger than a simple localization explanation

The JP build still retains multiple English internal cheat/debug strings, including the positive-control strings above. That means the absence of the debugger-only English UI bundle is not well explained by a blanket everything was translated or removed from string form theory.

The current safest read is therefore not merely the strings were probably renamed; it is:

if the classic hidden usecode debugger survived in JP, it did not survive with the usual recognizable English UI string bundle that identifies the DOS-side debugger in Remorse and Regret.

4. This pass does not overturn the earlier JP cheat/debug findings

Nothing in this pass weakens the earlier JP Win32 cheat/debug note.

Those earlier closures still stand:

  • -laurie still survives
  • JASSICA16 still survives
  • the option-key cheat handler still contains the immortality path
  • -debug still survives
  • -u still survives as a usecode startup override

What changed here is narrower: the first debugger-specific comparison did not find a recognizable hidden usecode-debugger UI signature. The follow-up below also found no debugger/bootstrap function family in the usecode runtime and classified the surviving -debug and DebugBreak paths as general diagnostics or invariant handling.

Deeper Live-Ghidra Pass (2026-10-08)

The active Ghidra program was confirmed as /ja/CRUSADER.EXE. This pass started at the likely bootstrap boundary, then followed command-line debug handling, usecode-process creation/execution, and the executable's DebugBreak references. Program bytes were not changed.

Bootstrap And Process Creation

No functions named debugger or bootstrap exist in the JP program. Searches for break, watch, inspect, trace, step, source, symbol, and global likewise found no corresponding debugger-function family. Searching usecode functions finds only the general runtime entries UsecodeProcess_Create, UsecodeProcess_NextOpcode, UsecodeProcess_Run, Usecode_FreeList, and Usecode_FreeVal.

The closest bootstrap-looking function is the ordinary process factory:

  • 004671b0 UsecodeProcess_Create creates a runtime process, installs g_usecodeProcessFnPtrs, initializes its normal execution/context fields, and invokes the process initializer. Its recovered callers are generic event/process creation and interpreter paths; it does not allocate or publish a debugger break-state object.
  • 00467304 UsecodeProcess_Run marks a process active, calls UsecodeProcess_NextOpcode, and returns completion through the normal scheduler callback. It has no breakpoint callback or UI dispatch.
  • 0042ddc8 UsecodeProcess_NextOpcode is the large opcode engine (body ends at 00431024). The recovered DebugBreak call inside it is at 00430796, through 00467d64; the callsite reads an indexed usecode reference before updating the current runtime context.

The reference helper is now named in Ghidra as usecode_reference_table_decrement_refcount at 00467d64. It looks up a table entry, decrements the selected reference count, and calls the Windows DebugBreak API only after a failed lookup. This is an invariant/error trap in the usecode value/reference path, not a user-facing usecode debugger stop. Other DebugBreak xrefs are in non-debugger error/validation code, including a cluster in 00453c64 and one callsite without a recovered function owner at 00453985.

No recovered function in this chain stores a debugger-global pointer, pushes a source-line/callstack record, or dispatches a debugger UI callback. The process factory is therefore not the missing JP equivalent of Regret's usecode_debugger_bootstrap_init.

Indirect Process Table And Bytecode Metadata

The indirect process-registration check also found no debugger callback lane:

  • g_usecodeProcessFnPtrs at 004803d4 is installed by UsecodeProcess_Create at 00467238; its first entry is the ordinary UsecodeProcess_Run callback at 00467304.
  • The table has one recovered static use, from process creation. No separate debugger process table, UI callback registration, or break-state global was recovered.
  • UsecodeProcess_NextOpcode dispatches through its opcode table at 0042dbe0. The two metadata opcodes that resemble the DOS debugger path do not perform the same work:
    • 0x5b at 0042dfaa advances the source cursor by two bytes and returns to dispatch. It does not store a current line or test a breakpoint.
    • 0x5c at 0042dfbd skips a two-byte symbol-info offset and a following nine-byte inline name record. If DAT_00482ad0 is nonzero, it passes that name to shared helper 00445520 with the format "<%s>\n", then skips the record. This is symbol/debug metadata output, not a live current-entry push. The helper is also called from process-termination and other non-debugger paths.
  • DAT_00482ad0 has two recovered reads in the interpreter and no recovered writer. Its exact ownership and the purpose of the conditional output remain unresolved; it is not evidence of debugger state.

The opcode numbers alone are misleading here. The DOS builds use 0x5b to update debugger line state and 0x5c to push a live unit/source/frame record. JP retains metadata opcodes with those numbers, but its handlers discard the line operand and consume symbol information without creating or updating a debugger object.

Command-Line Debug Mode

handle_commandline_args_jp at 00466774 is already named in Ghidra. The option string table maps -debug to the branch at 004668b4; that branch prints Debugging mode ON and sets bytes at 004957d9 and 004957eb. The latter is now labeled g_debug_mode_enabled; its only recovered reader at 00455bac gates 00455eac, now named debug_mode_update_timeline_buffer.

That helper builds a 512-byte timeline-like marker buffer from context counters and copies it into an associated buffer. Its exact visible destination remains unresolved, but this is general engine instrumentation, not a usecode break-state or debugger UI path. The -laurie special case is separate and only sets the existing cheat flags g_wasLaurieSet and g_cheatsActive. The auxiliary byte at 004957d9 has a recovered -debug write but no recovered read, so it remains unnamed.

String And Function-Surface Recheck

The positive control JASSICA16 still resolves at 0047b1cc. The classic prompts Watch what?, Goto Line, and User code again produced no byte hits; the previous pass's broader list of debugger-only English strings remains negative. Ghidra's decoded string filters also returned no results for Japanese terms デバッグ, ウォッチ, ブレーク, or ソース.

This supports the conclusion that the classic DOS debugger front end is not present as an ordinary string-backed UI. It does not rule out code using encoded resources, unrecognized Japanese text encodings, or stripped internal diagnostics.

Ghidra Naming And Comments Added

  • 004957eb -> g_debug_mode_enabled
  • 00467d64 -> usecode_reference_table_decrement_refcount
  • 00455eac -> debug_mode_update_timeline_buffer
  • Disassembly comments at 0042dfaa and 0042dfbd record the JP 0x5b and 0x5c metadata behavior and distinguish it from Regret's line update and current-entry producer.
  • Decompiler comment at 004668b4 records that -debug enables general debug mode, not the usecode debugger.
  • Decompiler comment at 00430796 records the reference-count operation and clarifies that DebugBreak is only the failed-entry invariant trap.

No debugger-specific function was renamed because none was identified. The general reference-count and timeline-buffer helpers were named from their verified behavior instead.

Current Interpretation

The debugger comparison is now more specific than a string-presence result:

Build Recovered usecode-debugger surface Break-state activation
JP No Remorse (/ja/CRUSADER.EXE) No classic debugger object, UI/event family, bootstrap, or current-entry stack recovered. 0x5b discards its line operand; 0x5c consumes symbol-info metadata. -debug gates a separate timeline-like buffer update. No debugger-state global writer or open-on-break route recovered.
Western retail No Remorse (CRUSADER.EXE) The hidden UI, event dispatcher, break-state object, and interpreter record lifecycle survive. Opcode 0x5b updates the line/checks break conditions; 0x5c pushes the live unit/source/frame record, with child-copy and return/unwind handling. The global at 1478:659c/659e still has no recovered writer; the base break-state vtable's slot 0 is inert.
No Regret (REGRET.EXE) The debugger UI and interpreter lifecycle survive, with a different auxiliary source-line control in place of retail Remorse's watch pane. Its 0x5b/0x5c handlers update line state and push live current-entry records. usecode_debugger_bootstrap_init writes 1480:712c/712e and promotes the object to a vtable whose slot 0 opens the current-unit debugger. The bootstrap still lacks a recovered static caller, and runtime checks found the global null in the tested ordinary session.

Thus JP is not a weaker bootstrap variant of the classic debugger: the recovered JP opcodes are metadata handlers, not the DOS debugger's state producers. Western retail No Remorse has the debugger subsystem but lacks the recovered state writer and live break callback; No Regret preserves both pieces statically, although ordinary-session bootstrap reachability remains unproven. No Regret remains the strongest sibling build for explaining the retail activation gap.

Practical Consequence

For the minimum-modification retail debugger-entry problem, the completed static comparison remains:

  • retail No Remorse versus No Regret bootstrap/state-hook paths,

not:

  • retail No Remorse versus JP generic cheat/debug preservation.

JP remains useful as evidence that the Windows port retained cheat/debug behavior broadly, but it does not provide the debugger-bootstrap leverage found in No Regret. Runtime reachability in Regret remains a separate open question documented in the Regret note.

Remaining Uncertainty

This pass is still not an absolute negative proof.

The following possibilities remain open:

  1. debugger-related code could survive under unrecognized symbols, encoded resources, or Japanese text not decoded by Ghidra's string view
  2. the Win32 port could retain a lower-level inspection/break helper without the classic DOS UI
  3. ordinary runtime execution could register a callback or state object dynamically, though no static registration path was recovered

But none of those are currently evidenced by this pass.

No Regret remains the strongest sibling-build reference for the hidden debugger. The JP static pass is now bounded enough that the next work should discriminate the remaining runtime and encoding questions:

  1. Identify the visible consumer or destination of the timeline-like buffer produced by debug_mode_update_timeline_buffer.
  2. Resolve the unowned DebugBreak callsite at 00453985 and classify the 00453c64 call cluster as ordinary assertions or another diagnostic path.
  3. Check for dynamically constructed or encoded process callbacks not represented by the recovered static g_usecodeProcessFnPtrs reference.
  4. Compare JP 0x5b/0x5c emission and symbol-info records against representative compiled-usecode corpora to determine how often those metadata lanes occur.
  5. Search process/runtime data tables and constructor writes for an unlabelled break-state object or current-entry stack, not just a named global.
  6. If runtime access is available, observe -debug and ordinary usecode execution separately and check for a pause/UI transition; do not treat a Windows DebugBreak assertion as proof of debugger support.
  7. Revisit Japanese resources with a Shift-JIS-aware string/resource extraction pass if the localized-resource hypothesis remains important.