diff --git a/ams/api/static/tracker.js b/ams/api/static/tracker.js index 232cc6c..831b7f5 100644 --- a/ams/api/static/tracker.js +++ b/ams/api/static/tracker.js @@ -31,9 +31,9 @@ function detail(t,m){$('detail-title').textContent=`${typeName(t.name)} · ${m.n const section=(title,text)=>{body.append(el('h3',title));if(text !== undefined)body.append(el('pre',text));}; section('Implementacja emulatora',m.source?`${m.source.path}:${m.source.line}\nWłaściciel: ${m.source.owner || '—'}\nHash treści: ${m.source.body_sha256 || '—'}`:'Nie znaleziono rejestracji w emulatorze.'); section('Dowody z oryginału');const entries=original(m);if(!entries.length)body.append(el('p','Nieustalone — ekstrakcja nie dostarcza dopasowania w wybranym zakresie.')); - for(const o of entries){const b=data.binaries.find(b=>b.id===o.binary_id);const a=el('article');a.append(el('strong',b?binaryName(b):o.binary_id));const dl=el('dl');for(const [key,value] of [['SHA-256',b?.sha256],['Silnik',typeof b?.engine==='object'?JSON.stringify(b.engine):b?.engine],['Właściciel',o.owner],['Id metody',o.method_id],['Implementacja',o.impl_addr],['Gałąź dispatchera',o.case_addr],['Funkcja rejestrująca',o.registration_addr],['Wywołanie rejestracji',o.registration_call_addr],['Przekazanie ID',o.id_push_addr],['Napis',o.string_addr],['Id dowodów',(o.evidence_ids||[]).join(', ')||'—'],['Dopasowanie',MAPPING[o.mapping]||o.mapping],['Dziedziczenie',o.inherited?'Tak':'Nie']]){dl.append(el('dt',key),el('dd',value===null || value===undefined?'—':String(value)));}a.append(dl);if(o.registration_addr || o.evidence_ids?.length)a.append(el('p','Dowód rejestracji ASM potwierdza rozpoznanie API; nie stanowi weryfikacji zachowania implementacji.','muted'));if(b?.limitations?.length){a.append(el('strong','Ograniczenia ekstrakcji'));a.append(el('pre',b.limitations.map(item=>typeof item==='string'?item:JSON.stringify(item,null,2)).join('\n')));}if(b?.coverage !== undefined)a.append(el('pre','Zakres ekstrakcji: '+(typeof b.coverage==='string'?b.coverage:JSON.stringify(b.coverage,null,2))));body.append(a);} + for(const o of entries){const b=data.binaries.find(b=>b.id===o.binary_id);const a=el('article');a.append(el('strong',b?binaryName(b):o.binary_id));const dl=el('dl');for(const [key,value] of [['SHA-256',b?.sha256],['Silnik',typeof b?.engine==='object'?JSON.stringify(b.engine):b?.engine],['Właściciel',o.owner],['Id metody',o.method_id],['Sygnatura',o.signature],['Dla tego typu',o.per_type],['Implementacja',o.impl_addr],['Gałąź dispatchera',o.case_addr],['Funkcja rejestrująca',o.registration_addr],['Wywołanie rejestracji',o.registration_call_addr],['Przekazanie ID',o.id_push_addr],['Napis',o.string_addr],['Id dowodów',(o.evidence_ids||[]).join(', ')||'—'],['Dopasowanie',MAPPING[o.mapping]||o.mapping],['Dziedziczenie',o.inherited?'Tak':'Nie']]){dl.append(el('dt',key),el('dd',value===null || value===undefined?'—':String(value)));}a.append(dl);if(o.registration_addr || o.evidence_ids?.length)a.append(el('p','Dowód rejestracji ASM potwierdza rozpoznanie API; nie stanowi weryfikacji zachowania implementacji.','muted'));if(b?.limitations?.length){a.append(el('strong','Ograniczenia ekstrakcji'));a.append(el('pre',b.limitations.map(item=>typeof item==='string'?item:JSON.stringify(item,null,2)).join('\n')));}if(b?.coverage !== undefined)a.append(el('pre','Zakres ekstrakcji: '+(typeof b.coverage==='string'?b.coverage:JSON.stringify(b.coverage,null,2))));body.append(a);} section('Przeglądy i testy');body.append(el('p','Poniżej wszystkie zapisane przeglądy metody. Zbiorczy status weryfikacji nie oznacza potwierdzenia każdego wariantu; zakres dowodu określają jego dane.'));if(!(m.reviews||[]).length)body.append(el('p','Brak zapisanych dowodów weryfikacji zachowania.'));for(const review of m.reviews||[])body.append(el('pre',typeof review==='string'?review:JSON.stringify(review,null,2))); - const notes=[...(t.mapping_notes||[]),...(m.notes||[])];if(notes.length)section('Uwagi',notes.map(n=>typeof n==='string'?n:JSON.stringify(n,null,2)).join('\n')); + if(m.signatures?.length)section('Sygnatura w oryginale',m.signatures.join('\n'));const notes=[...(t.mapping_notes||[]),...(m.notes||[])];if(notes.length)section('Uwagi',notes.map(n=>typeof n==='string'?n:JSON.stringify(n,null,2)).join('\n')); $('details').showModal(); } $('close').onclick=()=>$('details').close();$('all-types').onclick=()=>{selected=null;render();};for(const id of ['search','family','binary','status','gaps'])$(id).addEventListener(id==='search'?'input':'change',()=>{if(data){if(id==='family')variants();render();}}); diff --git a/ams/tracker.py b/ams/tracker.py index 6a763fb..dd9db82 100644 --- a/ams/tracker.py +++ b/ams/tracker.py @@ -165,6 +165,18 @@ def owner_name(owner: str) -> str: return canonical(owner.removeprefix("CMC_")) +def signature(dispatch_row: dict) -> str | None: + """`(int, string/int, …) → double` from the argument getters and result allocator the + extractor saw in the method body; None when the body was not analysed.""" + if "params" not in dispatch_row: + return None + args = ["/".join(p["types"]) for p in dispatch_row["params"]] + if dispatch_row.get("variadic"): + args.append("…") + returns = "/".join(dispatch_row["returns"]) or "—" + return f"({', '.join(args)}) → {returns}" + + BASE_SCOPE = "*" # getRunner(0) is the runner behind `@IF`, `@LOOP`, ... statements, not an object type. BUILTIN_SCOPE, BUILTIN_TYPE_ID = "@", 0 @@ -218,6 +230,7 @@ def build_tracker(snapshots: list[Snapshot], emulator: dict, reviews: list[dict] "source": None, "original": [], "reviews": [], "notes": [], }) + excluded = defaultdict(set) # (type, method) -> binaries whose code skips it for that type seen = set() for snap in snapshots: sha = snap.binary.get("sha256") @@ -279,6 +292,11 @@ def build_tracker(snapshots: list[Snapshot], emulator: dict, reviews: list[dict] type_row(name).setdefault("inherits", []).append(BASE_SCOPE) return for m in owners[current]: + d = dispatch.get((current, m.get("id")), {}) if m.get("id") is not None else {} + verdict = {canonical(k): v for k, v in (d.get("per_type") or {}).items()}.get(name) + if verdict == "excluded_by_type_check": + excluded[(name, m["name"].upper())].add(bid) + continue row = method_row(name, m["name"].upper()) if len(name_ids[(current, m["name"].upper())]) > 1: note = "Oryginał rejestruje tę nazwę z różnymi ID; skuteczny wybór wymaga sprawdzenia hashtable/dispatchera." @@ -291,9 +309,13 @@ def build_tracker(snapshots: list[Snapshot], emulator: dict, reviews: list[dict] # Child declarations override names from ancestors for this binary. if any(o["binary_id"] == bid and o["owner"] != current for o in row["original"]): continue - d = dispatch.get((current, m.get("id")), {}) if m.get("id") is not None else {} + if verdict == "trivial_virtual": + note = "W oryginale bez efektu dla tego typu: jego vftable zostawia wywoływane metody wirtualne puste." + if note not in row["notes"]: + row["notes"].append(note) row["original"].append({"binary_id": bid, "owner": current, "method_id": m.get("id"), "impl_addr": d.get("impl_addr"), "case_addr": d.get("case_addr"), + "signature": signature(d), "per_type": verdict, "mapping": mapping, "inherited": inherited, "registration_addr": m.get("registration_addr"), "string_addr": m.get("string_addr"), "registration_call_addr": m.get("registration_call_addr"), @@ -318,6 +340,11 @@ def build_tracker(snapshots: list[Snapshot], emulator: dict, reviews: list[dict] if row["source"] is None and method in globals_: row.update(globals_[method]) row["notes"] = row["notes"] + ["Obsługa przez globalny fallback Variable."] + for (name, method), binaries_ in excluded.items(): + row = rows.get(name, {}).get("methods", {}).get(method) + if row is not None: + row["notes"].append(f"Oryginał ({len(binaries_)} binarek) pomija tę metodę dla tego typu: " + "warunek obj.getType() we wspólnym runnerze.") base_verbs = {m for m, row in rows.get(BASE_SCOPE, {}).get("methods", {}).items() if row["original"]} for name, t in rows.items(): for method, row in t["methods"].items(): @@ -350,6 +377,8 @@ def build_tracker(snapshots: list[Snapshot], emulator: dict, reviews: list[dict] row["status"] = "partial" elif row["reviews"] and not current: row["verification"] = "stale" + for row in t["methods"].values(): + row["signatures"] = sorted({o["signature"] for o in row["original"] if o.get("signature")}) t["methods"] = sorted(t["methods"].values(), key=lambda m: m["name"]) t["mapping_notes"] = sorted(set(t["mapping_notes"])) if "inherits" in t: diff --git a/tests/test_tracker.py b/tests/test_tracker.py index 2d328b8..84dc4b7 100644 --- a/tests/test_tracker.py +++ b/tests/test_tracker.py @@ -86,12 +86,18 @@ def factory_snapshot(): {"script_name": "STRING", "cpp_class": "CMC_String", "type_id": 2}, {"script_name": "VECTOR", "cpp_class": None, "type_id": 0x7e0}], "methods": [{"owner": "CMC_Variable", "runner": "CMC_Variable_Runner", "name": "ADD", "id": 6}, + {"owner": "CMC_Variable", "runner": "CMC_Variable_Runner", "name": "UPPER", "id": 30}, {"owner": "CMC_Vector", "runner": "CMC_Vector_Runner", "name": "NORMALIZE", "id": 8}, {"owner": "CMC_Dummy", "runner": "CMC_Dummy_Runner", "name": "IF", "id": 1}, {"owner": "CMC_Dummy", "runner": "CMC_Dummy_Runner", "name": "MSGBOX", "id": 6}, {"owner": "CMC", "runner": "CMC_Runner", "name": "CLONE", "id": 100}], "method_inheritance": [{"runner": "CMC_Variable_Runner", "base_runner": "CMC_Runner"}, {"runner": "CMC_Vector_Runner", "base_runner": "CMC_Runner"}], + "method_dispatch": [ + {"owner": "CMC_Variable", "runner": "CMC_Variable_Runner", "id": 6, "params": [{"index": 0, "types": ["int"]}], + "variadic": False, "returns": ["copy"], "per_type": {"INTEGER": "trivial_virtual", "STRING": "applies"}}, + {"owner": "CMC_Variable", "runner": "CMC_Variable_Runner", "id": 30, "params": [], "variadic": False, + "returns": [], "per_type": {"INTEGER": "excluded_by_type_check", "STRING": "applies"}}], "runner_map": {"by_type_id": [{"type_id": 0, "runner": "CMC_Dummy_Runner"}, {"type_id": 1, "runner": "CMC_Variable_Runner"}, {"type_id": 2, "runner": "CMC_Variable_Runner"}, @@ -243,3 +249,16 @@ def test_api_configuration_and_download(tmp_path, monkeypatch): assert "attachment" in response.headers["content-disposition"] assert response.json()["schema"] == "tracker/1" assert client.get("/ui/tracker.html").status_code == 200 + + +def test_shared_runner_methods_follow_per_type_verdicts(tmp_path): + emu = emulator(tmp_path) + emu["types"]["INTEGER"] = {"mapping_notes": [], "methods": { + "UPPER": {"status": "registered", "notes": [], "source": {"owner": "INTEGER"}}}} + result = build_tracker([factory_snapshot()], emu) + assert row(result, "STRING", "UPPER")["original"] + upper = row(result, "INTEGER", "UPPER") # registered by the emulator, skipped by the original + assert upper["original"] == [] and any("obj.getType()" in n for n in upper["notes"]) + assert row(result, "STRING", "ADD")["signatures"] == ["(int) → copy"] + assert any("bez efektu" in n for n in row(result, "INTEGER", "ADD")["notes"]) + assert row(result, "INTEGER", "ADD")["original"][0]["per_type"] == "trivial_virtual"