feat(extractor): properties per script type along the constructor chain

type_fields walks each type's factory constructor through its base
constructors, base first, so unnamed classes get their properties
(VECTOR VALUE/SIZE, FILTER ACTION, PATH NODES, MOVIE FILENAME/POSITION)
and INTEGER/STRING inherit CMC_Variable's TOINI/NETNOTIFY. Property
names come only from pushed or register-loaded literals: a vftable store
whose bytes look printable produced BlooMoo's X5/Gs field names. Schema 7.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Patryk Gensch
2026-10-24 20:30:36 +02:00
co-authored by Claude Opus 5.5
parent 6217fde83c
commit 9d5a600d6b
+93 -25
View File
@@ -839,15 +839,48 @@ def _prop_type(getter):
return "string" # plain getPropertyValue return "string" # plain getPropertyValue
def extract_script_fields(program): def _property_getter(program, addr):
"""The script-visible named fields each type exposes (FILENAME, FPS, PRELOAD, VISIBLE, ...). """The CMElement::getProperty<T>Value called at `addr` (any folded alias), or None."""
for _, name in _labels(program, addr):
if name.startswith("getProperty"):
return name
return None
The CMC_* constructor reads them from the element: it builds the property-name literal and
calls CMElement::getProperty<T>Value(...). We anchor on that getter call, take the preceding def _string_operand(program, instr):
string literal as the field name, and derive the field type from the getter. Returns a flat """A name literal an instruction pushes or loads into a register. A store into memory is
list deduped per (owner, name).""" never one: installing a vftable writes an address whose bytes may happen to be printable
(BlooMoo read "X5"/"vN" instead of VALUE that way)."""
if instr.getMnemonicString() == "MOV" and "[" in instr.getDefaultOperandRepresentation(0):
return None
s = _imm_string(program, instr)
return s if s is not None and _is_method_name(s) else None
def _fields_read(program, func):
"""[(property, value type)] a constructor body reads, in order: the literal pushed or
loaded right before each CMElement::getProperty<T>Value call names the property."""
out = []
last = None
ins = program.getListing().getInstructions(resolve_thunk(func).getBody(), True)
while ins.hasNext():
instr = ins.next()
s = _string_operand(program, instr)
if s is not None:
last = s
if instr.getMnemonicString() == "CALL" and len(instr.getFlows()) == 1 and last is not None:
getter = _property_getter(program, instr.getFlows()[0])
if getter is not None:
out.append((last, _prop_type(getter)))
last = None
return out
def extract_script_fields(program):
"""The script-visible named fields each named CMC_* constructor reads (FILENAME, FPS,
PRELOAD, VISIBLE, ...), typed by the CMElement getter. Flat list deduped per (owner, name);
`type_fields` covers unnamed classes and inheritance per script type."""
fm = program.getFunctionManager() fm = program.getFunctionManager()
listing = program.getListing()
by_key = {} # (owner, name) -> record by_key = {} # (owner, name) -> record
next_order = {} # owner -> next order index next_order = {} # owner -> next order index
it = fm.getFunctions(True) it = fm.getFunctions(True)
@@ -856,27 +889,60 @@ def extract_script_fields(program):
if not _is_cmc_ctor(f): if not _is_cmc_ctor(f):
continue continue
owner = f.getParentNamespace().getName() owner = f.getParentNamespace().getName()
last_string = None for name, ty in _fields_read(program, f):
ins = listing.getInstructions(resolve_thunk(f).getBody(), True) key = (owner, name)
while ins.hasNext():
instr = ins.next()
s = _imm_string(program, instr)
if s is not None and _is_method_name(s):
last_string = s
if instr.getMnemonicString() == "CALL":
cf = call_target(program, instr)
cname = cf.getName() if cf is not None else None
if cname is not None and cname.startswith("getProperty") and last_string is not None:
key = (owner, last_string)
if key not in by_key: if key not in by_key:
o = next_order.get(owner, 0) o = next_order.get(owner, 0)
by_key[key] = {"owner": owner, "name": last_string, by_key[key] = {"owner": owner, "name": name, "type": ty, "order": o}
"type": _prop_type(cname), "order": o}
next_order[owner] = o + 1 next_order[owner] = o + 1
last_string = None
return sorted(by_key.values(), key=lambda r: (r["owner"], r["order"])) return sorted(by_key.values(), key=lambda r: (r["owner"], r["order"]))
def _constructor_chain(program, ctor, limit=6):
"""`ctor` and the base constructors it delegates to, most-derived first."""
chain = []
func = ctor
while func is not None and len(chain) < limit:
chain.append(func)
nxt = None
it = program.getListing().getInstructions(resolve_thunk(func).getBody(), True)
while it.hasNext():
instr = it.next()
flows = instr.getFlows() if instr.getMnemonicString() == "CALL" else []
if len(flows) == 1 and _is_base_ctor_call(program, flows[0]):
nxt = program.getFunctionManager().getFunctionAt(flows[0])
break
func = nxt
return chain
def extract_type_fields(program, types):
"""Per script type, the properties its constructor chain reads, base first: reaches
unnamed classes (VECTOR's VALUE/SIZE, FILTER's ACTION, PATH's NODES) and inherited ones
(INTEGER gets CMC_Variable's TOINI/NETNOTIFY). A property read through several getters
lists every value type."""
out = []
seen = set()
for t in types:
ctor = _function_at(program, t.get("ctor_addr"))
if ctor is None or t["script_name"] in seen:
continue
seen.add(t["script_name"])
records = {}
for func in reversed(_constructor_chain(program, ctor)):
classes = sorted(ns for ns, name in _labels(program, func.getEntryPoint()) if ns == name)
for name, ty in _fields_read(program, func):
rec = records.get(name)
if rec is None:
rec = records[name] = {"type": t["script_name"], "name": name, "value_types": [],
"order": len(records),
"declared_in": classes[0] if classes else None}
if ty not in rec["value_types"]:
rec["value_types"].append(ty)
out.extend(sorted(records.values(), key=lambda r: r["order"]))
return out
def extract_struct_layout(program): def extract_struct_layout(program):
"""Bonus/fuzzy axis: per CMC_* constructor, recover the this-relative C++ field stores """Bonus/fuzzy axis: per CMC_* constructor, recover the this-relative C++ field stores
(offset, size, is_vtable) and the base-class link. Offsets come from decompiler P-code, so (offset, size, is_vtable) and the base-class link. Offsets come from decompiler P-code, so
@@ -1896,9 +1962,10 @@ def run():
annotate_method_facts(program, method_dispatch, run_addrs, runner_map, types) annotate_method_facts(program, method_dispatch, run_addrs, runner_map, types)
annotate_type_vftables(program, types, method_dispatch) annotate_type_vftables(program, types, method_dispatch)
type_events = extract_type_events(program, types) type_events = extract_type_events(program, types)
type_fields = extract_type_fields(program, types)
snapshot = { snapshot = {
"schema_version": 6, "schema_version": 7,
"binary": { "binary": {
"name": program.getName(), "name": program.getName(),
"sha256": sha256_of(program), "sha256": sha256_of(program),
@@ -1916,6 +1983,7 @@ def run():
"method_dispatch": method_dispatch, "method_dispatch": method_dispatch,
"runner_map": runner_map, "runner_map": runner_map,
"type_events": type_events, "type_events": type_events,
"type_fields": type_fields,
} }
args = getScriptArgs() args = getScriptArgs()
@@ -1926,9 +1994,9 @@ def run():
finally: finally:
fh.close() fh.close()
print("[+] %s [%s/%s]: %d types, %d methods, %d events (%d per type), %d fields (%d layout, %d dispatch, %d runners) -> %s" % ( print("[+] %s [%s/%s]: %d types, %d methods, %d events (%d per type), %d fields (%d per type, %d layout, %d dispatch, %d runners) -> %s" % (
program.getName(), engine, compiler, len(types), len(methods), program.getName(), engine, compiler, len(types), len(methods),
len(events), len(type_events), len(fields), len(struct_layout), len(method_dispatch), len(events), len(type_events), len(fields), len(type_fields), len(struct_layout), len(method_dispatch),
len((runner_map or {}).get("runners", [])), out_path)) len((runner_map or {}).get("runners", [])), out_path))