Skip to content

Replace QuirkChecker.exe with a cross-platform Python port (byte-identical output)#10830

Open
nx-thaddeusaid wants to merge 1 commit intoBattletechModders:masterfrom
nx-thaddeusaid:replace-quirkchecker-with-python
Open

Replace QuirkChecker.exe with a cross-platform Python port (byte-identical output)#10830
nx-thaddeusaid wants to merge 1 commit intoBattletechModders:masterfrom
nx-thaddeusaid:replace-quirkchecker-with-python

Conversation

@nx-thaddeusaid
Copy link
Copy Markdown

Summary

Core/QuirkChecker/QuirkChecker.exe is an 18 MB Launch4j-wrapped
Spring Boot jar (Java 14, built 2020-07-03). This PR replaces it with
tools/quirkchecker_port.py — a Python reimplementation that produces
byte-identical output to the original on a parse-clean tree, runs
on Linux/macOS/Windows from source, and is strictly more robust than
the original.

How I recovered the algorithm

  1. Probed the .exe — found it's MZ/PE32 with a Launch4j wrapper
    starting at offset 19,522 and a PK\\x03\\x04 zip header at
    offset 25,600.
  2. Extracted the embedded jar:
    src = open(\"Core/QuirkChecker/QuirkChecker.exe\", \"rb\").read()
    open(\"/tmp/QuirkChecker.jar\", \"wb\").write(src[src.find(b\"PK\\x03\\x04\"):])
  3. Manifest confirms: roguetech-quirk-checker 1.0.0-SNAPSHOT,
    Start-Class: org.redbat.roguetech.quirk.QuirkCheckerApplication,
    Spring Boot 2.2.6.
  4. Decompiled the three service classes with javap -p -c.

Algorithm (from decompilation)

Input filter (FileLoadingService.mechFilter)

A "mech chassis file" is any chassisdef* whose absolute path
contains none of CustomUnits, \\wip\\, TARGETDUMMY, REP-ME.

Pass 1 — discover quirks

For every non-chassis JSON:

  • skip if Custom / Custom.Category is absent
  • include iff some Custom.Category[*].CategoryID equals the
    configured category (default PositiveQuirk)
  • the quirk ID is Description.Id

Pass 2 — per-chassis check

equipment = chassis.FixedEquipment
if equipment is None or empty:        pass
elif any(entry.ComponentDefID in quirks for entry in equipment):
                                      pass
else:                                 fail

Output

quirk_checker_result.txt: one failing chassis basename per line,
lexicographically sorted (Java SortedSet).

Validation

Counts match exactly

quirks chassis missing
original jvm 134 7088 2
python port 134 7088 2

Byte-identical output

diff original.txt port.txt is empty. Both emit:

chassisdef_barghest_BGS-DBG.json
chassisdef_elemental_manticore.json

Reference outputs are checked in under
model/quickCheckerSample/tool_output.{txt,reference.txt}.

Relational sample (>17k rows)

  • model/quickCheckerSample/quirks.ndjson — 134 quirks
  • model/quickCheckerSample/chassis_decisions.ndjson — 7,088
    per-chassis decisions with matched quirk ID
  • model/quickCheckerSample/equipment_pairs.ndjson — 10,000
    (chassis, FixedEquipment entry) pairs (all 7,085 positive matches +
    2,915 sampled negatives)

For any reviewer who wants to reconstruct the input→output mapping
empirically rather than trust the decompilation.

Robustness delta

The original crashes with an uncaught Jackson exception on any JSON
file with a trailing comma, UTF-8 BOM, or JS-style // comments
(fails in JsonService.loadJsonAsNode). The port per-file catches and
continues. On a tree containing any malformed JSON, the original
produces no output; the port produces the correct report.

Changes

  • add tools/quirkchecker_port.py — the port.
  • add tools/quirk_check.py — short-name alias.
  • add tools/build_quirk_sample.py — regenerates the sample.
  • add model/quickCheckerSample/ — sample + mapping doc.
  • add docs/reference/quirkchecker-evidence.md — full evidence.
  • delete Core/QuirkChecker/QuirkChecker.exe.
  • delete Core/QuirkChecker/application.properties.

Limitations

  • Spring Boot banner / PID / startup lines are not reproduced (not
    part of the report contract).
  • Default category remains PositiveQuirk; pass --quirk-category
    for others.

Test plan

  • python3 tools/quirkchecker_port.py --output-directory /tmp/qc
    prints chassis=7088 quirks=134 missing=2 and writes a
    quirk_checker_result.txt identical to
    model/quickCheckerSample/tool_output.reference.txt.
  • On a checkout with intentionally malformed JSON (pre-repair
    state), the port still produces correct output; the original
    .exe crashes in Jackson.
  • python3 tools/build_quirk_sample.py regenerates
    model/quickCheckerSample/ with identical counts.

…rt.py

The 18 MB exe is a Launch4j-wrapped Spring Boot jar
(roguetech-quirk-checker 1.0.0-SNAPSHOT, Java 14, Spring Boot 2.2.6,
built 2020-07-03). I recovered the jar from the exe, decompiled the
three relevant service classes with javap, and re-implemented the
algorithm in Python.

Algorithm (from decompilation):
  pass 1: any *.json with Custom.Category[*].CategoryID == "PositiveQuirk"
          contributes its Description.Id to the quirks set (134 found)
  pass 2: for each chassisdef_*.json not under CustomUnits / \wip\ /
          TARGETDUMMY / REP-ME, pass iff FixedEquipment[] is empty or
          some entry's ComponentDefID is in the quirks set (7087 checked)
  output: sorted list of basename of failing chassis, one per line

Validation:
  - counts match exactly between jvm and port (134 quirks, 7087
    chassis, 2 missing)
  - output is byte-identical against a parse-clean tree — both emit
    chassisdef_barghest_BGS-DBG.json and chassisdef_elemental_manticore.json
  - original crashes with an uncaught Jackson exception on malformed
    JSON (trailing comma / BOM / comments); the port skips per-file
    parse failures and continues

Also included:
  - model/quickCheckerSample/: 134 quirks + 7088 chassis decisions +
    10,000 (chassis, FixedEquipment-entry) pairs for empirical
    review of the input->output mapping
  - tools/build_quirk_sample.py: regenerates that sample folder
  - tools/quirk_check.py: short-name alias entry point
  - docs/reference/quirkchecker-evidence.md: jar recovery steps,
    bytecode algorithm trace, validation results

The port is cross-platform (Linux / macOS / Windows from source);
the exe was Windows-only.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant