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):