feat: map Piklib 6.1 types through constructor-created runners

Piklib 6.1 predates CMC_RunnerFactory; each class constructor creates its
own runner. The extractor records class -> runner from those call sites
(runner_map.by_class) and the tracker walks the snapshot's constructor
chain from a type's class to the nearest one creating a runner, so 6.1
variable and condition types no longer fall into pseudo-types either.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Patryk Gensch
2026-10-24 18:59:58 +02:00
co-authored by Claude Opus 5.5
parent edae0929d7
commit 11f4b6fc37
4 changed files with 71 additions and 4 deletions
+31 -3
View File
@@ -1263,6 +1263,34 @@ def _runner_from_global(name):
return "CMC_%s_Runner" % name[1:-len("Runner")]
def extract_class_runners(program):
"""{"by_class": [{class, runner}]} for engines without CMC_RunnerFactory (Piklib 6.1),
where every class constructor creates its own runner: CMC_Variable's constructor makes
CMC_Variable_Runner and CMC_Integer inherits it through that base constructor."""
fm = program.getFunctionManager()
refs = program.getReferenceManager()
pairs = set()
it = fm.getFunctions(True)
while it.hasNext():
f = it.next()
ns = f.getParentNamespace()
runner = ns.getName() if ns is not None else ""
if f.getName() != runner or not runner.endswith("_Runner") or runner == "CMC_Runner":
continue
for ref in refs.getReferencesTo(f.getEntryPoint()):
if not ref.getReferenceType().isCall():
continue
caller = fm.getFunctionContaining(ref.getFromAddress())
if caller is None:
continue
for cls, name in _labels(program, caller.getEntryPoint()):
if cls == name and cls.startswith(CMC_PREFIX) and not cls.endswith("_Runner"):
pairs.add((cls, runner))
if not pairs:
return None
return {"by_class": [{"class": c, "runner": r} for c, r in sorted(pairs)]}
def extract_runner_map(program, types):
"""Which runner executes each script type, from CMC_RunnerFactory (Piklib 7.1+, BlooMoo).
@@ -1804,13 +1832,13 @@ def run():
engine, compiler = detect_engine(factory) # namespace lives on the symbol/stub
factory = resolve_thunk(factory) # MSVC8 exposes the symbol as a JMP stub
types = extract_types(program, factory)
runner_map = extract_runner_map(program, types)
runner_map = extract_runner_map(program, types) or extract_class_runners(program)
methods, method_inheritance = extract_methods(program, runner_map)
events = extract_events(program)
fields = extract_script_fields(program)
struct_layout, field_inheritance = extract_struct_layout(program)
method_dispatch, run_addrs = extract_method_dispatch(program, runner_map)
if runner_map:
if runner_map and "by_type_id" in runner_map:
annotate_method_facts(program, method_dispatch, run_addrs, runner_map, types)
annotate_type_vftables(program, types, method_dispatch)
@@ -1845,7 +1873,7 @@ def run():
print("[+] %s [%s/%s]: %d types, %d methods, %d events, %d fields (%d layout, %d dispatch, %d runners) -> %s" % (
program.getName(), engine, compiler, len(types), len(methods),
len(events), len(fields), len(struct_layout), len(method_dispatch),
len(runner_map["runners"]) if runner_map else 0, out_path))
len((runner_map or {}).get("runners", [])), out_path))
run()