scientific-method-engine 5.0.0__tar.gz → 6.1.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/PKG-INFO +1 -1
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/pyproject.toml +1 -1
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/cli.py +2 -1
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/reports.py +52 -19
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_pe.py +51 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_x86.py +78 -6
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/.gitignore +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/LICENSE +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/README.md +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/__init__.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/__main__.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ClearNoReturnFunctions.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/CreateFunctions.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ExportBoundedFlow.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ExportCallEdges.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ExportFunctionFingerprints.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ExportFunctionInventory.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/MergeFallThroughFragment.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/RecoverCitedFunctions.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/RepairReturningCallers.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportCallArguments.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportCallPaths.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportCallSitesWithScalars.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportCallsToRange.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportConstantFirstArgumentCalls.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportDataBytes.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportDecompileMatches.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportDecompileWindow.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportFilePatternInMemory.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportFirstArgumentCallSummary.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportFunctionScalarConstants.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportFunctionSummary.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportInstructionContext.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportInstructionWindow.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportMemoryBlockForFileOffset.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportMemoryBlocks.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportRandomnessCandidates.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportReferences.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportScalarConstants.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportStringReferences.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/ReportSymbolReferences.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/ghidra/scientificmethod/FirstArgumentLookBack.java +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/__init__.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/argument_frames.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/dispatch.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/effect_order.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/image.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/loops.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/machine.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/memory_scopes.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/pcode.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/pcode_backend.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/pe.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/relational.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/result_flow.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/trace.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/src/scientific_method_engine/x86/values.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/oracle.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_continuation_budget.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_dispatch.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_effect_order.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_loops.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_memory_scopes.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_nested_frame_request.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_oracle.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_relational_controls.py +0 -0
- {scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_table_continuations.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: scientific-method-engine
|
|
3
|
-
Version:
|
|
3
|
+
Version: 6.1.0
|
|
4
4
|
Summary: Bounded instruction-derived x86 evidence reports for segmented MZ/FBOV and PE32/i386 code.
|
|
5
5
|
Project-URL: Source, https://github.com/kibertoad/refurbished-dinosaurs-toolkit/tree/main/packages/scientific-method-engine
|
|
6
6
|
Author: kibertoad
|
|
@@ -5,7 +5,7 @@ build-backend = "hatchling.build"
|
|
|
5
5
|
[project]
|
|
6
6
|
name = "scientific-method-engine"
|
|
7
7
|
# The release workflow writes the published version from the package's release tag.
|
|
8
|
-
version = "
|
|
8
|
+
version = "6.1.0"
|
|
9
9
|
description = "Bounded instruction-derived x86 evidence reports for segmented MZ/FBOV and PE32/i386 code."
|
|
10
10
|
readme = "README.md"
|
|
11
11
|
requires-python = ">=3.12"
|
|
@@ -16,7 +16,8 @@ INSTRUCTION_SEMANTICS = f"pypcode {pypcode.__version__} (Ghidra SLEIGH x86)"
|
|
|
16
16
|
USAGE = ("Usage: scientific-method-engine <operand|operand-candidates|target|bounds|owner|callees|trace|uses|arguments|"
|
|
17
17
|
"effects|returns|memory|incoming|call-order|guards|allocation|dispatch> <config.json|->\n"
|
|
18
18
|
"effects includes ordered path writes/calls and local restoration witnesses; transactionality remains unestablished.\n"
|
|
19
|
-
"callees compares its edges with an ExportCallEdges.java export given as ghidraCallEdges
|
|
19
|
+
"callees compares its edges with an ExportCallEdges.java export given as ghidraCallEdges;\n"
|
|
20
|
+
"agreed is false where Ghidra ends the function at a call, conditional jump or interrupt the engine reads past (ghidraEndsFunction).\n"
|
|
20
21
|
"trace, arguments, effects, returns, guards, memory and allocation check relationalControls:\n"
|
|
21
22
|
"a violated control fails the report; an undecided one is reported and never counts as held.\n"
|
|
22
23
|
"Declared table continuations are separate conditional paths that spend continuationBudget\n"
|
|
@@ -31,12 +31,16 @@ def memory_width(ins, operand):
|
|
|
31
31
|
X87_MEMORY_STORES = {"fst", "fstp", "fist", "fistp", "fisttp", "fbstp", "fnstcw", "fstcw", "fnstsw", "fstsw",
|
|
32
32
|
"fnstenv", "fstenv", "fnsave", "fsave"}
|
|
33
33
|
X87_MEMORY_LOADS = {"fldcw", "fldenv", "frstor"}
|
|
34
|
+
# Capstone gives the memory operand of INS and OUTS no access flags: INS writes ES:[(E)DI], OUTS reads [(E)SI].
|
|
35
|
+
PORT_MEMORY_STORES = {"insb", "insw", "insd"}
|
|
36
|
+
PORT_MEMORY_LOADS = {"outsb", "outsw", "outsd"}
|
|
34
37
|
|
|
35
38
|
|
|
36
39
|
def memory_access(ins, operand):
|
|
37
|
-
|
|
40
|
+
m = base_mnemonic(ins)
|
|
41
|
+
if m in X87_MEMORY_STORES or m in PORT_MEMORY_STORES:
|
|
38
42
|
return ["write"]
|
|
39
|
-
if
|
|
43
|
+
if m in X87_MEMORY_LOADS or m in PORT_MEMORY_LOADS:
|
|
40
44
|
return ["read"]
|
|
41
45
|
return [name for flag, name in ((CS_AC_READ, "read"), (CS_AC_WRITE, "write")) if operand.access & flag]
|
|
42
46
|
|
|
@@ -195,6 +199,11 @@ def incoming(image, config):
|
|
|
195
199
|
"scope": "All bytes of declared search regions; verified calls are reachable from accepted starts. Never proves universal absence."}
|
|
196
200
|
|
|
197
201
|
|
|
202
|
+
# Classifications of a conditionalAccesses row in ``uses``.
|
|
203
|
+
CFG_OPERAND = "entry-CFG operand past a stop; values and callee effects unresolved"
|
|
204
|
+
PORT_OPERAND = "operand past a PE32 port access; values and continuation unresolved"
|
|
205
|
+
|
|
206
|
+
|
|
198
207
|
def uses(image, config):
|
|
199
208
|
query = config.get("query", {})
|
|
200
209
|
offset = integer(query.get("offset"), 0, image.mask, "query offset")
|
|
@@ -283,6 +292,14 @@ def uses(image, config):
|
|
|
283
292
|
after_stop, stop_gaps, _, _, _ = (walk(image, list(stops), instruction_limit, follow_flat_ports=True)
|
|
284
293
|
if stops else ({}, [], None, None, None))
|
|
285
294
|
gaps.extend(g for g in stop_gaps if g["reason"] == "instruction limit")
|
|
295
|
+
# In PE32 a site the stops reach only by continuing past a port access is named as such, even when
|
|
296
|
+
# it also depends on an unread call. The walk that ends at port accesses must finish within the
|
|
297
|
+
# limit for that claim; otherwise every row keeps the shared value.
|
|
298
|
+
port_only = set()
|
|
299
|
+
if image.flat and any(base_mnemonic(ins) in PORTS for ins in after_stop.values()):
|
|
300
|
+
before_ports, port_gaps, _, _, _ = walk(image, list(stops), instruction_limit)
|
|
301
|
+
if not any(g["reason"] == "instruction limit" for g in port_gaps):
|
|
302
|
+
port_only = set(after_stop) - set(before_ports)
|
|
286
303
|
# A call past a stop was never traced either, so code after it also depends on it returning.
|
|
287
304
|
starts = [(root, root, reason) for root, reason in stops.items()]
|
|
288
305
|
starts += [(at, at + ins.size, "call past a stop; assumed to return")
|
|
@@ -305,8 +322,7 @@ def uses(image, config):
|
|
|
305
322
|
for operand in ins.operands:
|
|
306
323
|
if operand.type != X86_OP_MEM:
|
|
307
324
|
continue
|
|
308
|
-
kinds = [kind for
|
|
309
|
-
if operand.access & flag and mode in ("both", kind) and (at, kind) not in reported]
|
|
325
|
+
kinds = [kind for kind in memory_access(ins, operand) if mode in ("both", kind) and (at, kind) not in reported]
|
|
310
326
|
if not kinds:
|
|
311
327
|
continue
|
|
312
328
|
if state is None:
|
|
@@ -332,7 +348,7 @@ def uses(image, config):
|
|
|
332
348
|
"effectiveSegmentRegister": segment_name,
|
|
333
349
|
"address": "overlaps query" if overlaps and segment is None else "possible alias",
|
|
334
350
|
"classification": ("unverified overlapping instruction path" if at in unverified else
|
|
335
|
-
|
|
351
|
+
PORT_OPERAND if at in port_only else CFG_OPERAND),
|
|
336
352
|
"dependsOn": depends.get(at, []),
|
|
337
353
|
"reachability": "conditional on encoded branch outcomes and on execution continuing past every named stop"})
|
|
338
354
|
# A control proves the search reaches a known use, which an operand found past a stop still shows.
|
|
@@ -1105,6 +1121,17 @@ def _ghidra_key(g):
|
|
|
1105
1121
|
return g["site"], g["target"]
|
|
1106
1122
|
|
|
1107
1123
|
|
|
1124
|
+
def _ghidra_falls_through(g):
|
|
1125
|
+
"""Whether Ghidra continues to the next instruction at an exported edge's site, and what that was read from.
|
|
1126
|
+
|
|
1127
|
+
The export's fallsThrough also reflects a user's fall-through override. Copies of the script that leave it out
|
|
1128
|
+
are read by the flow type's name, which misses such an override.
|
|
1129
|
+
"""
|
|
1130
|
+
exported = g["fallsThrough"] is not None
|
|
1131
|
+
return {"ghidraFallsThrough": g["fallsThrough"] if exported else "TERMINATOR" not in g["flow"],
|
|
1132
|
+
"ghidraFallsThroughBasis": "fallsThrough" if exported else "flowName"}
|
|
1133
|
+
|
|
1134
|
+
|
|
1108
1135
|
def _ghidra_cross_check(export, nodes, outgoing, omitted):
|
|
1109
1136
|
"""Compare the engine's edges with Ghidra's for each caller both read; a Ghidra-only edge stays unchecked."""
|
|
1110
1137
|
callers = export["callers"]
|
|
@@ -1115,12 +1142,18 @@ def _ghidra_cross_check(export, nodes, outgoing, omitted):
|
|
|
1115
1142
|
theirs = callers[caller]
|
|
1116
1143
|
instructions = nodes[caller]["body"]["instructions"]
|
|
1117
1144
|
# A call neither analysis resolved matches on its site with no target.
|
|
1118
|
-
|
|
1145
|
+
matches = {_ghidra_key(g): g for g in theirs if g["site"] is not None}
|
|
1119
1146
|
read = {(e["site"], e["target"]) for e in ours}
|
|
1120
1147
|
for e in ours:
|
|
1121
|
-
|
|
1122
|
-
|
|
1123
|
-
|
|
1148
|
+
g = matches.get((e["site"], e["target"]))
|
|
1149
|
+
row = {"caller": caller, "site": e["site"], "target": e["target"], "engineEdge": e["id"],
|
|
1150
|
+
"result": "engineOnly" if g is None else "agreement", "ghidraFlow": g["flow"] if g else None}
|
|
1151
|
+
# The engine reads on past every call and every conditional tail transfer, and stops at a jmp or ljmp.
|
|
1152
|
+
# Ghidra ends the function at a call to a callee it treats as non-returning (CALL_TERMINATOR) or at an
|
|
1153
|
+
# instruction whose fall-through a user cleared.
|
|
1154
|
+
if g is not None and (e["kind"] != "tail transfer" or base_mnemonic(instructions[e["site"]]) not in ("jmp", "ljmp")):
|
|
1155
|
+
row |= _ghidra_falls_through(g)
|
|
1156
|
+
rows.append(row)
|
|
1124
1157
|
for g in theirs:
|
|
1125
1158
|
if g["site"] is not None and _ghidra_key(g) in read:
|
|
1126
1159
|
continue
|
|
@@ -1128,34 +1161,34 @@ def _ghidra_cross_check(export, nodes, outgoing, omitted):
|
|
|
1128
1161
|
if ins is not None and base_mnemonic(ins) in INTERRUPTS and _ghidra_key(g)[1] is None:
|
|
1129
1162
|
# SLEIGH lifts INT, INT1, INT3 and INTO to a computed call with no target, while the engine assumes the
|
|
1130
1163
|
# interrupt returns to the next instruction and records no edge. At INT1 and INT3 Ghidra's flow is a
|
|
1131
|
-
# terminator that ends the function there.
|
|
1132
|
-
# export without it is read by the flow type's name.
|
|
1133
|
-
exported = g["fallsThrough"] is not None
|
|
1164
|
+
# terminator that ends the function there.
|
|
1134
1165
|
rows.append({"caller": caller, "site": g["site"], "target": None, "siteAddress": g["siteAddress"],
|
|
1135
1166
|
"targetAddress": None, "ghidraFlow": g["flow"], "result": "interrupt", "engineEdge": None,
|
|
1136
|
-
|
|
1137
|
-
"ghidraFallsThroughBasis": "fallsThrough" if exported else "flowName"})
|
|
1167
|
+
**_ghidra_falls_through(g)})
|
|
1138
1168
|
continue
|
|
1139
1169
|
# Ghidra's edge is evidence the engine did not check; it never becomes an engine edge.
|
|
1140
1170
|
rows.append({"caller": caller, "site": g["site"], "target": g["target"], "siteAddress": g["siteAddress"],
|
|
1141
1171
|
"targetAddress": g["targetAddress"], "ghidraFlow": g["flow"], "result": "ghidraOnly", "checked": False,
|
|
1142
1172
|
"engineEdge": next((e["id"] for e in ours if g["site"] is not None and e["site"] == g["site"]), None)})
|
|
1143
1173
|
counts = {kind: sum(r["result"] == kind for r in rows) for kind in ("agreement", "engineOnly", "ghidraOnly", "interrupt")}
|
|
1174
|
+
counts["ghidraEndsFunction"] = sum(r.get("ghidraFallsThrough") is False for r in rows)
|
|
1144
1175
|
not_compared = {"engineCallers": sorted(nodes.keys() - callers.keys()), "ghidraCallers": sorted(callers.keys() - nodes.keys()),
|
|
1145
1176
|
"unmappedGhidraFunctions": export["unmappedFunctions"], "missingGhidraEntries": export["missingEntries"],
|
|
1146
1177
|
"unreadGhidraFunctions": export["unreadFunctions"],
|
|
1147
1178
|
"omittedEngineRoutes": [o["id"] for o in omitted if o["entry"] in callers]}
|
|
1148
|
-
# A site agrees only when every edge either analysis read there agrees.
|
|
1149
|
-
disputed = {r["site"] for r in rows if r["result"] != "agreement"}
|
|
1179
|
+
# A site agrees only when every edge either analysis read there agrees and Ghidra continues past it as the engine does.
|
|
1180
|
+
disputed = {r["site"] for r in rows if r["result"] != "agreement" or r.get("ghidraFallsThrough") is False}
|
|
1150
1181
|
return {"comparedCallers": compared, "edges": rows, "counts": counts, "notCompared": not_compared,
|
|
1151
1182
|
"agreed": (not counts["engineOnly"] and not counts["ghidraOnly"] and not any(not_compared.values())
|
|
1152
|
-
and
|
|
1183
|
+
and not counts["ghidraEndsFunction"]),
|
|
1153
1184
|
"agreementSites": {r["site"] for r in rows if r["result"] == "agreement"} - disputed,
|
|
1154
1185
|
"interpretation": "Edges of each caller that both the engine and the Ghidra export read, matched by site and target "
|
|
1155
1186
|
"file offset; an unresolved call matches an unresolved call at its site, and a Ghidra target without a file offset "
|
|
1156
1187
|
"matches no engine edge. An interrupt row is Ghidra's targetless call at an instruction the engine read as an "
|
|
1157
|
-
"interrupt and assumed to return
|
|
1158
|
-
"
|
|
1188
|
+
"interrupt and assumed to return. The engine reads on past every call, conditional jump and interrupt, so an "
|
|
1189
|
+
"interrupt row or an agreement at a call or conditional tail transfer counts against agreed when Ghidra "
|
|
1190
|
+
"ends the function there (ghidraFallsThrough false, counted in ghidraEndsFunction), read from the export's "
|
|
1191
|
+
"fallsThrough or, in an export without it, from the flow name (ghidraFallsThroughBasis). "
|
|
1159
1192
|
"A ghidraOnly edge is Ghidra's claim: the engine did not check it and never adds it to its graph. Agreement "
|
|
1160
1193
|
"means both analyses read the edge, not that it executes."}
|
|
1161
1194
|
|
|
@@ -120,6 +120,7 @@ class PEReporterTests(unittest.TestCase):
|
|
|
120
120
|
self.assertEqual(r['matches'], [])
|
|
121
121
|
row, = r['conditionalAccesses']
|
|
122
122
|
self.assertEqual((row['site'], row['dependsOn']), (store, [{'site': out, 'reason': gap['reason']}]))
|
|
123
|
+
self.assertEqual(row['classification'], 'operand past a PE32 port access; values and continuation unresolved')
|
|
123
124
|
# The inventoried store is not reported a second time as a raw candidate.
|
|
124
125
|
self.assertEqual(r['rawCandidates'], [])
|
|
125
126
|
self.assertIn(gap, r['gaps'])
|
|
@@ -143,6 +144,56 @@ class PEReporterTests(unittest.TestCase):
|
|
|
143
144
|
self.assertEqual([d['site'] for d in row['dependsOn']], [CODE_RAW + 4, CODE_RAW + 5])
|
|
144
145
|
self.assertEqual(row['dependsOn'][1]['reason'], 'port access past a stop; assumed to continue')
|
|
145
146
|
|
|
147
|
+
def test_uses_classifies_an_operand_reached_only_past_a_port_access(self):
|
|
148
|
+
cfg = 'entry-CFG operand past a stop; values and callee effects unresolved'
|
|
149
|
+
port = 'operand past a PE32 port access; values and continuation unresolved'
|
|
150
|
+
def row(code):
|
|
151
|
+
r = report(code, 'uses', query={'offset': DATA_VA, 'width': 4})
|
|
152
|
+
found, = r['conditionalAccesses']
|
|
153
|
+
return found['site'] - CODE_RAW, found['classification'], [d['site'] - CODE_RAW for d in found['dependsOn']]
|
|
154
|
+
# call eax; mov [DATA_VA], eax; ret: past an unread call only.
|
|
155
|
+
self.assertEqual(row('ff d0 a3 00 20 40 00 c3'), (2, cfg, [0]))
|
|
156
|
+
# mov dx, 0x3c8; out dx, al; mov [DATA_VA], eax; ret: past a port access only.
|
|
157
|
+
self.assertEqual(row('66 ba c8 03 ee a3 00 20 40 00 c3'), (5, port, [4]))
|
|
158
|
+
# call eax; mov dx, 0x3c8; out dx, al; mov [DATA_VA], eax; ret: every route from the unread call
|
|
159
|
+
# crosses the port access, so the row is outside the entry CFG and dependsOn names both.
|
|
160
|
+
self.assertEqual(row('ff d0 66 ba c8 03 ee a3 00 20 40 00 c3'), (7, port, [0, 6]))
|
|
161
|
+
# call eax; test eax, eax; jz store; mov dx, 0x3c8; out dx, al; store: mov [DATA_VA], eax; ret
|
|
162
|
+
# One route from the unread call skips the port access, so the row keeps the shared value.
|
|
163
|
+
c = Code().emit('ff d0 85 c0').branch('74', 'store').emit('66 ba c8 03 ee').label('store').emit('a3 00 20 40 00 c3')
|
|
164
|
+
self.assertEqual(row(c), (c.labels['store'], cfg, [0, c.labels['store'] - 1]))
|
|
165
|
+
|
|
166
|
+
def test_uses_claims_no_port_access_route_when_the_walk_reaches_its_limit(self):
|
|
167
|
+
# call eax; jz far; mov dx, 0x3c8; out dx, al; store: mov [DATA_VA], eax; ret; far: nop; nop; nop; ret
|
|
168
|
+
c = Code().emit('ff d0').branch('74', 'far').emit('66 ba c8 03 ee').label('store').emit('a3 00 20 40 00 c3')
|
|
169
|
+
c.label('far').emit('90 90 90 c3')
|
|
170
|
+
store = c.labels['store']
|
|
171
|
+
for limit, classification in ((100, 'operand past a PE32 port access; values and continuation unresolved'),
|
|
172
|
+
(5, 'entry-CFG operand past a stop; values and callee effects unresolved')):
|
|
173
|
+
with self.subTest(limit=limit):
|
|
174
|
+
r = report(c, 'uses', query={'offset': DATA_VA, 'width': 4}, instructionLimit=limit)
|
|
175
|
+
found, = r['conditionalAccesses']
|
|
176
|
+
self.assertEqual((found['site'] - CODE_RAW, found['classification']), (store, classification))
|
|
177
|
+
self.assertEqual(any(g.get('reason') == 'instruction limit' for g in r['gaps']), limit == 5)
|
|
178
|
+
self.assertFalse(r['negativeUsable'])
|
|
179
|
+
|
|
180
|
+
def test_uses_takes_the_access_direction_of_a_string_port_or_x87_operand_from_its_mnemonic(self):
|
|
181
|
+
# Capstone flags no access on an INS or OUTS memory operand and reports FSTP's store as a read.
|
|
182
|
+
cfg = 'entry-CFG operand past a stop; values and callee effects unresolved'
|
|
183
|
+
port = 'operand past a PE32 port access; values and continuation unresolved'
|
|
184
|
+
for name, code, expected in (('call eax; rep insb', 'ff d0 f3 6c c3', [(2, 'write', cfg)]),
|
|
185
|
+
('call eax; outsd', 'ff d0 6f c3', [(2, 'read', cfg)]),
|
|
186
|
+
('call eax; fstp dword [DATA_VA]', 'ff d0 d9 1d 00 20 40 00 c3', [(2, 'write', cfg)]),
|
|
187
|
+
('mov dx, 0x3c8; out dx, al; insb', '66 ba c8 03 ee 6c c3', [(5, 'write', port)])):
|
|
188
|
+
with self.subTest(name):
|
|
189
|
+
r = report(code, 'uses', query={'offset': DATA_VA, 'width': 4})
|
|
190
|
+
self.assertEqual([(e['site'] - CODE_RAW, e['kind'], e['classification']) for e in r['conditionalAccesses']],
|
|
191
|
+
expected)
|
|
192
|
+
self.assertFalse(r['negativeUsable'])
|
|
193
|
+
# A read query no longer lists the FSTP store.
|
|
194
|
+
r = report('ff d0 d9 1d 00 20 40 00 c3', 'uses', query={'offset': DATA_VA, 'width': 4, 'access': 'read'})
|
|
195
|
+
self.assertEqual(r['conditionalAccesses'], [])
|
|
196
|
+
|
|
146
197
|
def test_pop_addresses_its_destination_after_the_stack_pointer_moves(self):
|
|
147
198
|
# push 1; push 2; push 3; pop dword [esp+4]; pop eax; pop ebx; ret
|
|
148
199
|
regs = report('6a 01 6a 02 6a 03 8f 44 24 04 58 5b c3')['paths'][0]['registers']
|
|
@@ -615,7 +615,7 @@ class GhidraCrossCheckTests(unittest.TestCase):
|
|
|
615
615
|
# Ghidra's computed target never becomes an engine edge.
|
|
616
616
|
self.assertIsNone(r["edges"][2]["target"])
|
|
617
617
|
self.assertEqual(r["edges"][2]["classification"], "unresolved")
|
|
618
|
-
self.assertEqual(check["counts"], {"agreement": 1, "engineOnly": 2, "ghidraOnly": 1, "interrupt": 0})
|
|
618
|
+
self.assertEqual(check["counts"], {"agreement": 1, "engineOnly": 2, "ghidraOnly": 1, "interrupt": 0, "ghidraEndsFunction": 0})
|
|
619
619
|
self.assertEqual(check["comparedCallers"], [0, b])
|
|
620
620
|
self.assertEqual(check["notCompared"]["engineCallers"], [a])
|
|
621
621
|
self.assertFalse(check["agreed"])
|
|
@@ -629,7 +629,7 @@ class GhidraCrossCheckTests(unittest.TestCase):
|
|
|
629
629
|
r = run_report(data, cfg, "callees")
|
|
630
630
|
check = r["ghidraCrossCheck"]
|
|
631
631
|
self.assertTrue(check["agreed"])
|
|
632
|
-
self.assertEqual(check["counts"], {"agreement": 2, "engineOnly": 0, "ghidraOnly": 0, "interrupt": 0})
|
|
632
|
+
self.assertEqual(check["counts"], {"agreement": 2, "engineOnly": 0, "ghidraOnly": 0, "interrupt": 0, "ghidraEndsFunction": 0})
|
|
633
633
|
# Agreement on an unresolved call leaves the engine's edge unresolved.
|
|
634
634
|
self.assertEqual(r["edges"][1]["classification"], "unresolved")
|
|
635
635
|
|
|
@@ -641,7 +641,7 @@ class GhidraCrossCheckTests(unittest.TestCase):
|
|
|
641
641
|
cfg = configuration(data, ghidraCallEdges=export)
|
|
642
642
|
cfg["regions"][0]["entries"] = [0, 6]
|
|
643
643
|
check = run_report(data, cfg, "callees")["ghidraCrossCheck"]
|
|
644
|
-
self.assertEqual(check["counts"], {"agreement": 1, "engineOnly": 1, "ghidraOnly": 1, "interrupt": 0})
|
|
644
|
+
self.assertEqual(check["counts"], {"agreement": 1, "engineOnly": 1, "ghidraOnly": 1, "interrupt": 0, "ghidraEndsFunction": 0})
|
|
645
645
|
self.assertFalse(check["agreed"])
|
|
646
646
|
cfg["controls"] = {"ghidraAgreementSites": [3]}
|
|
647
647
|
with self.assertRaisesRegex(ValueError, "positive control missed: ghidraAgreementSites"):
|
|
@@ -657,7 +657,7 @@ class GhidraCrossCheckTests(unittest.TestCase):
|
|
|
657
657
|
r = run_report(data, cfg, "callees")
|
|
658
658
|
check = r["ghidraCrossCheck"]
|
|
659
659
|
self.assertTrue(check["agreed"])
|
|
660
|
-
self.assertEqual(check["counts"], {"agreement": 1, "engineOnly": 0, "ghidraOnly": 0, "interrupt": 2})
|
|
660
|
+
self.assertEqual(check["counts"], {"agreement": 1, "engineOnly": 0, "ghidraOnly": 0, "interrupt": 2, "ghidraEndsFunction": 0})
|
|
661
661
|
rows = [e for e in check["edges"] if e["result"] == "interrupt"]
|
|
662
662
|
self.assertEqual([(e["site"], e["ghidraFallsThrough"]) for e in rows], [(0, True), (2, True)])
|
|
663
663
|
self.assertEqual([e["site"] for e in r["edges"]], [3])
|
|
@@ -682,7 +682,7 @@ class GhidraCrossCheckTests(unittest.TestCase):
|
|
|
682
682
|
data = bytes.fromhex("cc c3")
|
|
683
683
|
cfg = configuration(data, ghidraCallEdges=ghidra_export(data, {0: [(0, None, "COMPUTED_CALL_TERMINATOR")]}))
|
|
684
684
|
check = run_report(data, cfg, "callees")["ghidraCrossCheck"]
|
|
685
|
-
self.assertEqual(check["counts"], {"agreement": 0, "engineOnly": 0, "ghidraOnly": 0, "interrupt": 1})
|
|
685
|
+
self.assertEqual(check["counts"], {"agreement": 0, "engineOnly": 0, "ghidraOnly": 0, "interrupt": 1, "ghidraEndsFunction": 1})
|
|
686
686
|
self.assertFalse(check["agreed"])
|
|
687
687
|
|
|
688
688
|
def test_the_exported_falls_through_decides_an_interrupt_over_the_flow_name(self):
|
|
@@ -710,6 +710,78 @@ class GhidraCrossCheckTests(unittest.TestCase):
|
|
|
710
710
|
self.assertEqual(rows, [(0, True, "flowName"), (2, False, "flowName")])
|
|
711
711
|
self.assertFalse(check["agreed"])
|
|
712
712
|
|
|
713
|
+
def test_a_call_ghidra_ends_the_function_at_counts_against_agreed(self):
|
|
714
|
+
# call 4; ret; ret. Both analyses have the call. The engine reads on to the ret after it, while Ghidra ends
|
|
715
|
+
# the function at the call when it treats the callee as non-returning or a user cleared the fall-through.
|
|
716
|
+
data = bytes.fromhex("e8 01 00 c3 c3")
|
|
717
|
+
for flow, falls_through, agreed in (("UNCONDITIONAL_CALL", True, True), ("UNCONDITIONAL_CALL", False, False),
|
|
718
|
+
("CALL_TERMINATOR", False, False), ("CALL_TERMINATOR", True, True)):
|
|
719
|
+
with self.subTest(flow=flow, fallsThrough=falls_through):
|
|
720
|
+
cfg = configuration(data, ghidraCallEdges=ghidra_export(data, {0: [(0, 4, flow, falls_through)], 4: []}))
|
|
721
|
+
cfg["regions"][0]["entries"] = [0, 4]
|
|
722
|
+
check = run_report(data, cfg, "callees")["ghidraCrossCheck"]
|
|
723
|
+
[row] = check["edges"]
|
|
724
|
+
self.assertEqual(row["result"], "agreement")
|
|
725
|
+
self.assertEqual((row["ghidraFallsThrough"], row["ghidraFallsThroughBasis"]), (falls_through, "fallsThrough"))
|
|
726
|
+
self.assertEqual(check["counts"], {"agreement": 1, "engineOnly": 0, "ghidraOnly": 0, "interrupt": 0,
|
|
727
|
+
"ghidraEndsFunction": 0 if falls_through else 1})
|
|
728
|
+
self.assertEqual(check["agreed"], agreed)
|
|
729
|
+
# A call Ghidra ends the function at is no agreement site.
|
|
730
|
+
cfg["controls"] = {"ghidraAgreementSites": [0]}
|
|
731
|
+
if agreed:
|
|
732
|
+
run_report(data, cfg, "callees")
|
|
733
|
+
else:
|
|
734
|
+
with self.assertRaisesRegex(ValueError, "positive control missed: ghidraAgreementSites"):
|
|
735
|
+
run_report(data, cfg, "callees")
|
|
736
|
+
|
|
737
|
+
def test_a_call_in_an_export_without_falls_through_reads_the_flow_name(self):
|
|
738
|
+
# Copies of ExportCallEdges.java written before fallsThrough was added: CALL_TERMINATOR ends the function, and a
|
|
739
|
+
# cleared fall-through on an UNCONDITIONAL_CALL goes unseen. The row names the flow name as its basis.
|
|
740
|
+
data = bytes.fromhex("e8 01 00 c3 c3")
|
|
741
|
+
for flow, falls_through in (("UNCONDITIONAL_CALL", True), ("CALL_TERMINATOR", False)):
|
|
742
|
+
with self.subTest(flow=flow):
|
|
743
|
+
cfg = configuration(data, ghidraCallEdges=ghidra_export(data, {0: [(0, 4, flow)], 4: []}))
|
|
744
|
+
cfg["regions"][0]["entries"] = [0, 4]
|
|
745
|
+
check = run_report(data, cfg, "callees")["ghidraCrossCheck"]
|
|
746
|
+
[row] = check["edges"]
|
|
747
|
+
self.assertEqual((row["ghidraFallsThrough"], row["ghidraFallsThroughBasis"]), (falls_through, "flowName"))
|
|
748
|
+
self.assertEqual(check["counts"]["ghidraEndsFunction"], 0 if falls_through else 1)
|
|
749
|
+
self.assertEqual(check["agreed"], falls_through)
|
|
750
|
+
|
|
751
|
+
def test_an_agreed_tail_transfer_keeps_agreed_without_a_falls_through(self):
|
|
752
|
+
# jmp 3; ret; ret. Neither analysis continues past an unconditional jump into another function.
|
|
753
|
+
data = bytes.fromhex("eb 01 c3 c3")
|
|
754
|
+
cfg = configuration(data, ghidraCallEdges=ghidra_export(data, {0: [(0, 3, "UNCONDITIONAL_JUMP", False)], 3: []}),
|
|
755
|
+
controls={"ghidraAgreementSites": [0]})
|
|
756
|
+
cfg["regions"][0]["entries"] = [0, 3]
|
|
757
|
+
check = run_report(data, cfg, "callees")["ghidraCrossCheck"]
|
|
758
|
+
[row] = check["edges"]
|
|
759
|
+
self.assertEqual(row["result"], "agreement")
|
|
760
|
+
self.assertNotIn("ghidraFallsThrough", row)
|
|
761
|
+
self.assertEqual(check["counts"]["ghidraEndsFunction"], 0)
|
|
762
|
+
self.assertTrue(check["agreed"])
|
|
763
|
+
|
|
764
|
+
def test_a_conditional_tail_transfer_ghidra_ends_the_function_at_counts_against_agreed(self):
|
|
765
|
+
# je 3; ret; ret. The engine reads on past the conditional jump into the entry at 3; Ghidra ends the function
|
|
766
|
+
# there when a user cleared the jump's fall-through.
|
|
767
|
+
data = bytes.fromhex("74 01 c3 c3")
|
|
768
|
+
for falls_through in (True, False):
|
|
769
|
+
with self.subTest(fallsThrough=falls_through):
|
|
770
|
+
cfg = configuration(data, ghidraCallEdges=ghidra_export(data, {0: [(0, 3, "CONDITIONAL_JUMP", falls_through)], 3: []}))
|
|
771
|
+
cfg["regions"][0]["entries"] = [0, 3]
|
|
772
|
+
check = run_report(data, cfg, "callees")["ghidraCrossCheck"]
|
|
773
|
+
[row] = check["edges"]
|
|
774
|
+
self.assertEqual(row["result"], "agreement")
|
|
775
|
+
self.assertEqual(row["ghidraFallsThrough"], falls_through)
|
|
776
|
+
self.assertEqual(check["counts"]["ghidraEndsFunction"], 0 if falls_through else 1)
|
|
777
|
+
self.assertEqual(check["agreed"], falls_through)
|
|
778
|
+
cfg["controls"] = {"ghidraAgreementSites": [0]}
|
|
779
|
+
if falls_through:
|
|
780
|
+
run_report(data, cfg, "callees")
|
|
781
|
+
else:
|
|
782
|
+
with self.assertRaisesRegex(ValueError, "positive control missed: ghidraAgreementSites"):
|
|
783
|
+
run_report(data, cfg, "callees")
|
|
784
|
+
|
|
713
785
|
def test_a_ghidra_target_at_an_interrupt_or_a_targetless_call_elsewhere_stays_ghidra_only(self):
|
|
714
786
|
# int 21h; int 10h; nop; call 8; ret. Ghidra resolves the first interrupt to a file offset and the second to an
|
|
715
787
|
# address without file bytes, and claims a call at the nop.
|
|
@@ -731,7 +803,7 @@ class GhidraCrossCheckTests(unittest.TestCase):
|
|
|
731
803
|
cfg["regions"][0]["entries"] = [0, 6]
|
|
732
804
|
r = run_report(data, cfg, "callees")
|
|
733
805
|
check = r["ghidraCrossCheck"]
|
|
734
|
-
self.assertEqual(check["counts"], {"agreement": 1, "engineOnly": 0, "ghidraOnly": 0, "interrupt": 0})
|
|
806
|
+
self.assertEqual(check["counts"], {"agreement": 1, "engineOnly": 0, "ghidraOnly": 0, "interrupt": 0, "ghidraEndsFunction": 0})
|
|
735
807
|
self.assertEqual(check["notCompared"]["omittedEngineRoutes"], [r["omittedRoutes"][0]["id"]])
|
|
736
808
|
self.assertFalse(check["agreed"])
|
|
737
809
|
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_continuation_budget.py
RENAMED
|
File without changes
|
|
File without changes
|
{scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_effect_order.py
RENAMED
|
File without changes
|
|
File without changes
|
{scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_memory_scopes.py
RENAMED
|
File without changes
|
{scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_nested_frame_request.py
RENAMED
|
File without changes
|
|
File without changes
|
{scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_relational_controls.py
RENAMED
|
File without changes
|
{scientific_method_engine-5.0.0 → scientific_method_engine-6.1.0}/tests/test_table_continuations.py
RENAMED
|
File without changes
|