From 9c1cc9c741d14380fe6d39fc7645e87c0707ee78 Mon Sep 17 00:00:00 2001 From: shweet Date: Fri, 30 Oct 2026 17:09:29 -0400 Subject: [PATCH 1/2] decompile.sh --case: decompile single switch cases of functions Ghidra times out on (Entity_Effect::Update 0x5d4380): DecompileCase.java patches the switch JMP at 0x5d47cc to jump straight to the case in a -readOnly copy and re-flows the body; all 139 cases decompile in ~90 s Co-Authored-By: Claude Opus 5.5 --- decompile.sh | 11 +++++- scripts/DecompileCase.java | 68 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 78 insertions(+), 1 deletion(-) create mode 100644 scripts/DecompileCase.java diff --git a/decompile.sh b/decompile.sh index 9e7c053..0e0a2fa 100755 --- a/decompile.sh +++ b/decompile.sh @@ -1,13 +1,22 @@ #!/bin/bash -# Usage: decompile.sh [--live|--asm] QUERY [MAX] +# Usage: decompile.sh [--live|--asm] QUERY [MAX] | decompile.sh --case CASEADDR... # QUERY = entry/inner address (0x6c0f30 / 006c0f30) or a regex on the qualified name (grep -E). # Default reads the pre-dumped corpus dump/all.c (instant, concurrency-safe). # --asm ADDR [N] prints N (default 20) instructions from ADDR (for functions the decompiler times out on). +# --case decompiles single switch cases of a function the decompiler times out on (Entity_Effect::Update): each +# CASEADDR is a jump-table target; the switch is patched to jump straight there in a throwaway copy (DecompileCase.java). # --live runs the Ghidra decompiler on a copy of the saved project (~25s; env DECOMP_TIMEOUT=secs, default 180). D="$(cd "$(dirname "$0")" && pwd)" LIVE=0; SCRIPT=Decompile.java [ "$1" = --live ] && { LIVE=1; shift; } [ "$1" = --asm ] && { LIVE=1; SCRIPT=Disasm.java; shift; } +if [ "$1" = --case ]; then + shift; TMP=$(mktemp -d); export JAVA_HOME="$D/jdk" + cp -r "$D/project" "$TMP/project"; rm -f "$TMP"/project/*.lock* + "$D/ghidra_12.2_PUBLIC/support/analyzeHeadless" "$TMP/project" isaac -process isaac-ng.exe -noanalysis -readOnly \ + -scriptPath "$D/scripts" -postScript DecompileCase.java "$TMP/out.c" "$@" >/dev/null 2>&1 + cat "$TMP/out.c"; rm -rf "$TMP"; exit +fi Q="$1"; MAX="${2:-20}" [ -z "$Q" ] && { sed -n '2,7p' "$0"; exit 1; } if [[ "$Q" =~ ^(0x)?[0-9a-fA-F]{6,8}$ ]]; then diff --git a/scripts/DecompileCase.java b/scripts/DecompileCase.java new file mode 100644 index 0000000..66bc187 --- /dev/null +++ b/scripts/DecompileCase.java @@ -0,0 +1,68 @@ +// Decompile single switch cases of a function too big for the decompiler (Entity_Effect::Update 0x5d4380 times out). +// Args: outfile [label=]caseAddr... Only ever run on a -readOnly project copy (decompile.sh --case): for each case it finds +// the switch's indirect JMP that lists the case among its flows, patches it into a direct JMP to the case, re-flows the +// function body (prologue + that case + whatever it shares, e.g. the common tail) and decompiles that. +import ghidra.app.script.GhidraScript; +import ghidra.app.decompiler.*; +import ghidra.app.cmd.function.CreateFunctionCmd; +import ghidra.program.model.address.*; +import ghidra.program.model.listing.*; +import java.io.*; +import java.util.*; + +public class DecompileCase extends GhidraScript { + public void run() throws Exception { + String[] a = getScriptArgs(); + DecompInterface di = new DecompInterface(); + DecompileOptions opts = new DecompileOptions(); + opts.setMaxPayloadMBytes(1024); + di.setOptions(opts); + di.openProgram(currentProgram); + int timeout = Integer.parseInt(System.getenv().getOrDefault("DECOMP_TIMEOUT", "600")); + Map switches = new HashMap<>(); + try (PrintStream o = new PrintStream(new FileOutputStream(a[0]))) { + for (int i = 1; i < a.length; i++) { + Address target = toAddr(Long.parseLong(a[i].replaceAll(".*=|0x", ""), 16)); + Function f = getFunctionContaining(target); + if (f == null) f = getFunctionBefore(target); // Ghidra's body for Update stops short of its cases + Instruction sw = switches.get(f); + if (sw == null) + for (Instruction in : currentProgram.getListing().getInstructions(f.getBody(), true)) + if (in.getFlowType().isJump() && in.getFlowType().isComputed() && lists(in, target)) { sw = in; break; } + if (sw == null) { o.println("//@@ case " + target + ": no switch jump in " + f.getName(true) + " lists it"); continue; } + switches.put(f, sw); + Address jmp = sw.getAddress(); + int size = sw.getLength(); + byte[] b = new byte[size]; + Arrays.fill(b, (byte) 0x90); + b[0] = (byte) 0xe9; + int rel = (int) (target.getOffset() - (jmp.getOffset() + 5)); + for (int k = 0; k < 4; k++) b[1 + k] = (byte) (rel >> (8 * k)); + clearListing(jmp, jmp.add(size - 1)); + setBytes(jmp, b); + disassemble(jmp); + CreateFunctionCmd.fixupFunctionBody(currentProgram, f, monitor); + di.flushCache(); + DecompileResults r = di.decompileFunction(f, timeout, monitor); + String label = a[i].contains("=") ? a[i].split("=")[0] : "0x" + target; + o.println("//@@ " + f.getEntryPoint() + " " + f.getName(true) + "/case_" + label + " (case at " + target + ": switch " + jmp + " patched to jump there)"); + o.println(r.decompileCompleted() ? r.getDecompiledFunction().getC() : "/* failed: " + r.getErrorMessage() + " */"); + o.flush(); + } + } + di.dispose(); + } + + // does this `JMP [reg*4 + table]` list target, by its recovered flows or else by reading the table itself + boolean lists(Instruction in, Address target) throws Exception { + if (Arrays.asList(in.getFlows()).contains(target)) return true; + for (Object op : in.getOpObjects(0)) + if (op instanceof ghidra.program.model.scalar.Scalar && currentProgram.getMemory().contains(toAddr(((ghidra.program.model.scalar.Scalar) op).getUnsignedValue()))) + for (int k = 0; k < 1024; k++) { + Address t = toAddr(getInt(toAddr(((ghidra.program.model.scalar.Scalar) op).getUnsignedValue() + 4L * k)) & 0xffffffffL); + if (t.equals(target)) return true; + if (getFunctionBefore(t) != getFunctionBefore(in.getAddress()) && getFunctionContaining(t) != getFunctionContaining(in.getAddress())) break; + } + return false; + } +} From e640efa18ff11799fe39756c9bfe2a08879989f5 Mon Sep 17 00:00:00 2001 From: shweet Date: Fri, 30 Oct 2026 17:16:16 -0400 Subject: [PATCH 2/2] notes: Entity_Effect::Update item cases transcribed via decompile.sh --case + asm: Salvation halo (case 123 @0x6064cc; its beams are Entity_NPC::Update's 1000.19.3), Trinity Shield (47 @0x5f2add), Luna moonlight (39.1 @0x5f2246 + timer callback 0x6073f0), Spear of Destiny (83 @0x5fea2f), Linger Bean cloud (105 @0x600dfc), Death Skull (109 @0x6029b5), Larynx/Mega Bean shockwave (127/202 @0x5fa30d) with Larynx's use from asm (pitch (n-8)*0.2+1.1, SetCollisionDamage(n*28+20), fade from n>=6), Mega Blast's laser damage (hit damage x5, x2 deathmatch), Meat Cleaver slash (176 @0x5df80d -> Entity_NPC::split 0x6d97e0), Vade Retro ghosts (144 @0x5d78ee), Ocular Rift (180 @0x5e1225), Jacob's Ladder chain lightning (167 @0x5e038f); names for 9 helpers Co-Authored-By: Claude Opus 5.5 --- db/names.tsv | 11 +- notes/items/effect_update.md | 262 +++++++++++++++++++++++++++++++++++ 2 files changed, 272 insertions(+), 1 deletion(-) create mode 100644 notes/items/effect_update.md diff --git a/db/names.tsv b/db/names.tsv index bbf9d61..e814a4b 100644 --- a/db/names.tsv +++ b/db/names.tsv @@ -1300,7 +1300,7 @@ # # Corrections found by the tier-3 pass (checked: strings/callers). Short REPENTOGON sigs and ICF put these names on the wrong function. 00782af0 Entity_Player::Update 34 KB vtable slot 3; "Controller %d has disconnected", status-effect anims; ZHL had put the name on 006d97e0 -006d97e0 Entity_NPC::zhl_misfit_006d97e0 ? tests boss types (0x47..0x4c, 0xdf), Morph/BloodExplode; ZHL prefix20/55 called it Entity_Player::Update +006d97e0 Entity_NPC::split splits an NPC into two 0.66-scale halves (40% max HP / HP each, score x0.5; unsplittable types/bosses excluded; arg 3 = play sound 0x4d); Meat Cleaver's 1000.176 slash calls it (Entity_Effect::Update case 176 @0x5df80d) with its spawner as source, no sound (notes/items/effect_update.md); ZHL prefix20/55 called it Entity_Player::Update 00779b40 Entity_Player::update_body_animations ? Head*/Walk*/Blink/Shimmer anims, only caller Entity_Player::Update; ZHL called it RoomTransition::Update 00830950 RoomTransition::ChangeRoom uses _roomIndex/_direction, Game::ChangeRoom, boss intro; ZHL had put the name on 006414c0 006414c0 Entity_Familiar::zhl_misfit_006414c0 ? only caller Entity_Familiar::Update; +0x184=5, Random()%3; ZHL called it RoomTransition::ChangeRoom @@ -3481,3 +3481,12 @@ 007515c0 Level::enter_dark_closet Death Certificate use (UseActiveItem case 0x5c3433): outside dimension 2 lays it once, keeps the current room/dimension/leave door, StartRoomTransition(0x50, -1, 0x14, 0, 2) 009b1910 LevelGenerator::block_cell sets the generator +0x2b8 byte for (x, y) (13x13); generate_dark_closet blocks (1,6), (2,5), (2,7) 009b1a90 LevelGenerator::queue_push_front deque push_front on generate_rooms local queue +0041d510 Math::abs ANDPS xmm0 with 0x7fffffff mask (0xbacb40); Trinity Shield's |rotation| in Entity_Effect::Update case 47 +00429550 DeathmatchManager::is_active returns *this > 1, called on &g_game->_deathmatchManager (Game::GetField26614); Mega Blast/Larynx/brown cloud deathmatch branches +00435da0 Entity::is_slot returns type == 6 (ENTITY_SLOT); shockwave case 127/202 pushes and damages slots +005cd660 Room::is_deaths_list_done returns room+0x1bbc (Death's List done flag, Room::update_deaths_list 0x8020d0); Death Skull 1000.109 dies when set +005cd670 Room::has_exorcist returns room+0x7768, set each tick by Entity_NPC::PreUpdate 0x6c4ac0 while an 832.0 Exorcist lives; enemy ghost 1000.144 stays in a cleared room while set +005cd950 Entity_Effect::rift_attract_filter returns a != b: Ocular Rift's Game::AttractEntities filter excluding its owner player (case 180 @0x5e1b91) +006073f0 Entity_Effect::moonlight_timer_callback Luna moonlight 1000.39.1 touch: 30-tick CreateTimer callback (case 39 @0x5f2433): sound 0x84, colour flash, null item 74 (luna secondary), AnimateCollectible(0x24d), AddSoulHearts(1) +007cbcb0 Entity_Player::resolve_tainted_soul returns +0x1e68 (the Forgotten body) when the player type is 0x28 (Tainted Soul) and it is set, else the player itself +007d4340 Entity_Player::get_salvation_scale clamp(GetCollectibleEffect(0x2b8).count * 0.1 + 1, 1, 2) (asm; returns in XMM0); x1.2 is the halo's _scale (Entity_Player::Update, update_effects 0x799548) diff --git a/notes/items/effect_update.md b/notes/items/effect_update.md new file mode 100644 index 0000000..4bbc55d --- /dev/null +++ b/notes/items/effect_update.md @@ -0,0 +1,262 @@ +# Entity_Effect::Update per-variant cases (items) + +`Entity_Effect::Update` 0x5d4380 (~200 KB, a 0x7500-byte frame) never decompiles whole. Its switch is +`JMP [EDX*4 + 0x606f8c]` at 0x5d47cc on `variant - 1` (0..0xcb; anything else -> 0x606e88, the shared tail). +Read here: the item-related cases, transcribed from per-case decompiles checked against the asm. + +## How to read a case (decompile.sh --case, scripts/DecompileCase.java) + +- `./decompile.sh --case 0x6064cc [0x5f2add ...]` decompiles single cases (~4 s each after a ~5 s Ghidra start; all + 139 distinct targets take ~90 s in one call). It copies project/ to a temp dir, opens it `-readOnly`, finds the + computed JMP whose flows (or jump table, read from memory) contain the case address, patches that JMP into a direct + `JMP case` (E9 rel32 + NOPs), re-flows the function body with `CreateFunctionCmd.fixupFunctionBody` (prologue + + that case + whatever it jumps into, e.g. the shared tail) and decompiles that. Changes are discarded; the shared + project is never written. Arguments may be labelled `label=addr`; the header then reads + `//@@ 005d4380 Entity_Effect::Update/case_