From bddb5949a60943e11e1fc3a8105c3a08ad5b6762 Mon Sep 17 00:00:00 2001 From: Patryk Gensch <43010113+patryk025@users.noreply.github.com> Date: Sat, 24 Oct 2026 18:24:15 +0200 Subject: [PATCH] fix(extractor): read registration literals from raw bytes first Analyzer-typed string data can split short or overlapping literals; the operand points at the literal start, so trust the bytes and require a terminator within the bound. Co-Authored-By: Claude Opus 5.5 --- ghidra_scripts/extract_engine_surface.py | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/ghidra_scripts/extract_engine_surface.py b/ghidra_scripts/extract_engine_surface.py index 2a66aae..0206d66 100644 --- a/ghidra_scripts/extract_engine_surface.py +++ b/ghidra_scripts/extract_engine_surface.py @@ -96,21 +96,26 @@ def _read_cstring(program, addr, maxlen=64): except: # noqa: E722 - Java MemoryAccessException isn't a Python Exception under Jython return None if b == 0: - break + return "".join(chars) if chars else None if b < 0x20 or b > 0x7e: return None # not a clean type-name literal chars.append(chr(b)) i += 1 - return "".join(chars) if chars else None + return None # the bound was reached without a terminator def _string_at(program, addr): if addr is None or not addr.isMemoryAddress(): return None # skip stack/register/constant refs (e.g. inline CXString stack buffers) + # Registration operands point to literal bytes. Prefer them over an analyzer's + # typed string boundary (which can split short/overlapping literals). + raw = _read_cstring(program, addr) + if raw is not None: + return raw d = program.getListing().getDataAt(addr) if d is not None and d.hasStringValue(): return str(d.getValue()) - return _read_cstring(program, addr) # fall back to raw memory for undefined literals + return None def lookback_string(program, recent):