scientific-method-engine 7.2.0__tar.gz → 7.3.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-7.2.0 → scientific_method_engine-7.3.0}/PKG-INFO +8 -6
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/README.md +7 -5
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/pyproject.toml +1 -1
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/cli.py +3 -1
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ExportCallEdges.java +9 -4
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/machine.py +6 -2
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/memory_scopes.py +38 -21
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/reports.py +85 -73
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/trace.py +79 -43
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/tests/test_memory_scopes.py +149 -3
- scientific_method_engine-7.3.0/tests/test_successor_rule.py +103 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/tests/test_x86.py +196 -14
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/.gitignore +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/LICENSE +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/__init__.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/__main__.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ClearNoReturnFunctions.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/CreateFunctions.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ExportBoundedFlow.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ExportFunctionFingerprints.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ExportFunctionInventory.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/MergeFallThroughFragment.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/RecoverCitedFunctions.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/RepairReturningCallers.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportCallArguments.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportCallPaths.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportCallSitesWithScalars.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportCallsToRange.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportConstantFirstArgumentCalls.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportDataBytes.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportDecompileMatches.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportDecompileWindow.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportFilePatternInMemory.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportFirstArgumentCallSummary.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportFunctionScalarConstants.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportFunctionSummary.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportInstructionContext.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportInstructionWindow.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportMemoryBlockForFileOffset.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportMemoryBlocks.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportRandomnessCandidates.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportReferences.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportScalarConstants.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportStringReferences.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/ReportSymbolReferences.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/ghidra/scientificmethod/FirstArgumentLookBack.java +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/__init__.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/argument_frames.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/dispatch.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/effect_order.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/image.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/loops.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/pcode.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/pcode_backend.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/pe.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/relational.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/result_flow.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/src/scientific_method_engine/x86/values.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/tests/oracle.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/tests/test_continuation_budget.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/tests/test_dispatch.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/tests/test_effect_order.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/tests/test_entry_frame.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/tests/test_loops.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/tests/test_nested_frame_request.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/tests/test_oracle.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/tests/test_pe.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.0}/tests/test_relational_controls.py +0 -0
- {scientific_method_engine-7.2.0 → scientific_method_engine-7.3.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: 7.
|
|
3
|
+
Version: 7.3.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
|
|
@@ -92,7 +92,7 @@ Exporting for comparison (each writes one file and refuses to overwrite where no
|
|
|
92
92
|
|---|---|---|
|
|
93
93
|
| `ExportBoundedFlow` | entry, instruction limit (1..10000), output path under `analysis/original/` | instruction metadata of one bounded flow as JSON |
|
|
94
94
|
| `ExportFunctionInventory` | output TSV path (must not exist) | every function's start and body size |
|
|
95
|
-
| `ExportCallEdges` | output JSON path (must not exist), function limit (1..128), one or more function entries | the call and tail-jump edges of the functions Ghidra reaches breadth-first from the entries, with file offsets, Ghidra's flow type (after any flow override)
|
|
95
|
+
| `ExportCallEdges` | output JSON path (must not exist), function limit (1..128), one or more function entries | the call and tail-jump edges of the functions Ghidra reaches breadth-first from the entries, with file offsets, Ghidra's flow type (after any flow override), `fallsThrough` (whether Ghidra continues to the next instruction at the site, after any fall-through override) and `fallsThroughTo`/`fallsThroughToAddress` (where a fall-through override sends Ghidra instead, or null), as the `ghidraCallEdges` input of `callees` |
|
|
96
96
|
| `ExportFunctionFingerprints` | output TSV path (replaced only when the export completes) | per-function and per-instruction fingerprints with addresses normalized, for matching functions across versions |
|
|
97
97
|
|
|
98
98
|
Repairing the analysis (these change the Ghidra program, so run them before reports and keep the
|
|
@@ -148,10 +148,12 @@ partial evidence, never complete dispatch or native-reachability claims. See the
|
|
|
148
148
|
A call model may declare `preservesMemory`: up to 32 scopes (4,096 bytes in total), each naming a
|
|
149
149
|
segment register, an address-width base register, an optional displacement, a byte count and the
|
|
150
150
|
evidence for assuming the service leaves those bytes alone. Scopes resolve against the pre-call
|
|
151
|
-
registers.
|
|
152
|
-
|
|
153
|
-
|
|
154
|
-
|
|
151
|
+
registers. The base may be symbolic, such as BP in an `entryFrame` query, and then keeps the bytes
|
|
152
|
+
at those offsets from its value. An unknown segment, a concrete interval that crosses the end of
|
|
153
|
+
the address space, or two scopes that may share a byte stop the path. Only the scoped bytes survive
|
|
154
|
+
the model's memory invalidation, and each scope is reported with the model, the modeled return and
|
|
155
|
+
the effect summary. Everything else the service may do stays unknown. This input needs prepared
|
|
156
|
+
protocol 3, so upgrade the reader and the engine together. See the
|
|
155
157
|
[call model contract](https://github.com/kibertoad/refurbished-dinosaurs-toolkit/blob/main/docs/bounded-evidence-reporters.md#limits-and-assumptions).
|
|
156
158
|
|
|
157
159
|
The trace-family commands (`trace`, `arguments`, `effects`, `returns`, `guards`, `memory`,
|
|
@@ -76,7 +76,7 @@ Exporting for comparison (each writes one file and refuses to overwrite where no
|
|
|
76
76
|
|---|---|---|
|
|
77
77
|
| `ExportBoundedFlow` | entry, instruction limit (1..10000), output path under `analysis/original/` | instruction metadata of one bounded flow as JSON |
|
|
78
78
|
| `ExportFunctionInventory` | output TSV path (must not exist) | every function's start and body size |
|
|
79
|
-
| `ExportCallEdges` | output JSON path (must not exist), function limit (1..128), one or more function entries | the call and tail-jump edges of the functions Ghidra reaches breadth-first from the entries, with file offsets, Ghidra's flow type (after any flow override)
|
|
79
|
+
| `ExportCallEdges` | output JSON path (must not exist), function limit (1..128), one or more function entries | the call and tail-jump edges of the functions Ghidra reaches breadth-first from the entries, with file offsets, Ghidra's flow type (after any flow override), `fallsThrough` (whether Ghidra continues to the next instruction at the site, after any fall-through override) and `fallsThroughTo`/`fallsThroughToAddress` (where a fall-through override sends Ghidra instead, or null), as the `ghidraCallEdges` input of `callees` |
|
|
80
80
|
| `ExportFunctionFingerprints` | output TSV path (replaced only when the export completes) | per-function and per-instruction fingerprints with addresses normalized, for matching functions across versions |
|
|
81
81
|
|
|
82
82
|
Repairing the analysis (these change the Ghidra program, so run them before reports and keep the
|
|
@@ -132,10 +132,12 @@ partial evidence, never complete dispatch or native-reachability claims. See the
|
|
|
132
132
|
A call model may declare `preservesMemory`: up to 32 scopes (4,096 bytes in total), each naming a
|
|
133
133
|
segment register, an address-width base register, an optional displacement, a byte count and the
|
|
134
134
|
evidence for assuming the service leaves those bytes alone. Scopes resolve against the pre-call
|
|
135
|
-
registers.
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
135
|
+
registers. The base may be symbolic, such as BP in an `entryFrame` query, and then keeps the bytes
|
|
136
|
+
at those offsets from its value. An unknown segment, a concrete interval that crosses the end of
|
|
137
|
+
the address space, or two scopes that may share a byte stop the path. Only the scoped bytes survive
|
|
138
|
+
the model's memory invalidation, and each scope is reported with the model, the modeled return and
|
|
139
|
+
the effect summary. Everything else the service may do stays unknown. This input needs prepared
|
|
140
|
+
protocol 3, so upgrade the reader and the engine together. See the
|
|
139
141
|
[call model contract](https://github.com/kibertoad/refurbished-dinosaurs-toolkit/blob/main/docs/bounded-evidence-reporters.md#limits-and-assumptions).
|
|
140
142
|
|
|
141
143
|
The trace-family commands (`trace`, `arguments`, `effects`, `returns`, `guards`, `memory`,
|
|
@@ -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 = "7.
|
|
8
|
+
version = "7.3.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"
|
|
@@ -18,7 +18,8 @@ USAGE = ("Usage: scientific-method-engine <operand|operand-candidates|target|bou
|
|
|
18
18
|
"effects includes ordered path writes/calls and local restoration witnesses; transactionality remains unestablished.\n"
|
|
19
19
|
"callees compares its edges with an ExportCallEdges.java export given as ghidraCallEdges;\n"
|
|
20
20
|
"agreed is false where Ghidra ends the function at a call, conditional jump or interrupt the engine reads past (ghidraEndsFunction),\n"
|
|
21
|
-
"
|
|
21
|
+
"continues past a jmp, ljmp, return or hlt the engine stops at (ghidraContinues),\n"
|
|
22
|
+
"or continues at another address than the next instruction (ghidraFallsThroughElsewhere).\n"
|
|
22
23
|
"trace, arguments, effects, returns, guards, memory and allocation check relationalControls:\n"
|
|
23
24
|
"a violated control fails the report; an undecided one is reported and never counts as held.\n"
|
|
24
25
|
"entryFrame {from} starts an entry inside the function at from, in the frame a trace from there observed.\n"
|
|
@@ -26,6 +27,7 @@ USAGE = ("Usage: scientific-method-engine <operand|operand-candidates|target|bou
|
|
|
26
27
|
"(paths, totalSteps, maxSteps, visitLimit, stringIterations); ordinary computed transfers remain stopped.\n"
|
|
27
28
|
"Port accesses and interrupts are hardware-boundary events; portInputs supplies port reads as assumptions.\n"
|
|
28
29
|
"callModels[].preservesMemory keeps explicit, bounded pre-call byte scopes across a modeled call; other memory stays unknown.\n"
|
|
30
|
+
"A scope needs a concrete segment; its base may be symbolic, such as BP in an entryFrame query.\n"
|
|
29
31
|
"Each traced path's loops record lists restart edges and what changed between iterations (loopIterationLimit).\n"
|
|
30
32
|
" scientific-method-engine ghidra-scripts")
|
|
31
33
|
|
|
@@ -106,17 +106,22 @@ public class ExportCallEdges extends GhidraScript {
|
|
|
106
106
|
|
|
107
107
|
// The flow is Ghidra's flow type after any flow override. fallsThrough is true when Ghidra continues to
|
|
108
108
|
// the next instruction at the site. getFallThrough() reflects a fall-through override, which can clear it
|
|
109
|
-
// or send it to another address; hasFallthrough() stays true for the second, so it is not used.
|
|
109
|
+
// or send it to another address; hasFallthrough() stays true for the second, so it is not used. When the
|
|
110
|
+
// override sends it to another address, fallsThroughTo and fallsThroughToAddress name that address and
|
|
111
|
+
// fallsThrough is false; otherwise both are null.
|
|
110
112
|
private String edge(Instruction instruction, Address target, FlowType flow) {
|
|
111
113
|
Address fallThrough = instruction.getFallThrough();
|
|
112
|
-
|
|
113
|
-
|
|
114
|
+
Address next = instruction.getAddress().addWrap(instruction.getDefaultFallThroughOffset());
|
|
115
|
+
boolean fallsThrough = fallThrough != null && fallThrough.equals(next);
|
|
116
|
+
Address elsewhere = fallThrough == null || fallsThrough ? null : fallThrough;
|
|
114
117
|
return "{\"site\": " + offset(instruction.getAddress())
|
|
115
118
|
+ ", \"siteAddress\": " + quote(instruction.getAddress().toString())
|
|
116
119
|
+ ", \"target\": " + (target == null ? "null" : offset(target))
|
|
117
120
|
+ ", \"targetAddress\": " + (target == null ? "null" : quote(target.toString()))
|
|
118
121
|
+ ", \"flow\": " + quote(flow.toString())
|
|
119
|
-
+ ", \"fallsThrough\": " + fallsThrough
|
|
122
|
+
+ ", \"fallsThrough\": " + fallsThrough
|
|
123
|
+
+ ", \"fallsThroughTo\": " + (elsewhere == null ? "null" : offset(elsewhere))
|
|
124
|
+
+ ", \"fallsThroughToAddress\": " + (elsewhere == null ? "null" : quote(elsewhere.toString())) + "}";
|
|
120
125
|
}
|
|
121
126
|
|
|
122
127
|
// The file offset the engine uses for an address, or null when the address has no file bytes.
|
|
@@ -553,8 +553,12 @@ def may_alias(key, written, bits, flat):
|
|
|
553
553
|
|
|
554
554
|
Different symbolic segments or bases may alias. Concrete linear locations do not.
|
|
555
555
|
"""
|
|
556
|
-
|
|
557
|
-
|
|
556
|
+
return domains_may_overlap(key_domain(key, bits, flat), written)
|
|
557
|
+
|
|
558
|
+
|
|
559
|
+
def domains_may_overlap(a, b):
|
|
560
|
+
"""Whether two linear byte domains may share a byte; an unknown (None) domain may share any."""
|
|
561
|
+
return a is None or b is None or not (a[1] <= b[0] or b[1] <= a[0])
|
|
558
562
|
|
|
559
563
|
|
|
560
564
|
def string_width(ins, flat):
|
|
@@ -4,8 +4,8 @@ A scope is a query hypothesis that a modeled service leaves a named byte range a
|
|
|
4
4
|
call. It is evidence-layer bookkeeping: it reads and writes no memory on the path, adds no read or
|
|
5
5
|
write event and computes no instruction value or flag (ADR 0003).
|
|
6
6
|
"""
|
|
7
|
-
from .machine import ALIASES, StopPath
|
|
8
|
-
from .values import const
|
|
7
|
+
from .machine import ALIASES, StopPath, domains_may_overlap, written_domain
|
|
8
|
+
from .values import const, op
|
|
9
9
|
|
|
10
10
|
|
|
11
11
|
SEGMENTS = ("cs", "ds", "es", "ss", "fs", "gs")
|
|
@@ -60,25 +60,39 @@ def capture_scopes(state, model):
|
|
|
60
60
|
"""Resolve each scope against the pre-call state and snapshot its bytes.
|
|
61
61
|
|
|
62
62
|
Returns ``(values, unread, descriptions)``: the cached bytes, the unknown term names of bytes
|
|
63
|
-
the model had no value for, and one report entry per scope.
|
|
64
|
-
|
|
65
|
-
|
|
63
|
+
the model had no value for, and one report entry per scope. The segment must be concrete. The
|
|
64
|
+
base may be concrete, or a symbolic value such as SP or BP at an offset from an unknown entry SP
|
|
65
|
+
(ADR 0013): the scope's bytes are then keyed by that value, as reads and writes through it are.
|
|
66
|
+
Raises ``StopPath`` when the segment is not concrete, a concrete interval leaves the address
|
|
67
|
+
space, two scopes on one base value share a byte, or two scopes on different base values may
|
|
68
|
+
share a linear byte (segment aliases included). A symbolic base may address any byte of its
|
|
69
|
+
segment, so it may alias every scope whose segment range overlaps that segment. An uncached
|
|
70
|
+
byte stays uncached after the call.
|
|
66
71
|
"""
|
|
67
|
-
values, unread, descriptions,
|
|
72
|
+
values, unread, descriptions, resolved = {}, {}, [], []
|
|
68
73
|
for scope in model.get("preservesMemory", []):
|
|
69
74
|
segment, base = state.segment(scope["segment"]), state.reg(scope["base"])
|
|
70
|
-
if segment.number is None
|
|
71
|
-
raise StopPath("preservesMemory address unresolved: segment
|
|
75
|
+
if segment.number is None:
|
|
76
|
+
raise StopPath("preservesMemory address unresolved: the segment must be concrete before the call")
|
|
72
77
|
displacement = scope.get("displacement", 0)
|
|
73
|
-
offset = base.number + displacement
|
|
74
78
|
size = scope["bytes"]
|
|
75
|
-
if
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
79
|
+
if base.number is not None:
|
|
80
|
+
if not 0 <= base.number + displacement <= (1 << state.bits) - size:
|
|
81
|
+
raise StopPath("preservesMemory interval crosses the address boundary")
|
|
82
|
+
offset = const(base.number + displacement, state.bits)
|
|
83
|
+
else:
|
|
84
|
+
offset = op("add", base, const(displacement, state.bits))
|
|
85
|
+
seg, group_base, start, keys = state.keys(segment, offset, size)
|
|
86
|
+
domain = written_domain(seg, group_base, start, size, state.bits, state.flat)
|
|
87
|
+
for group, prior_keys, prior_domain in resolved:
|
|
88
|
+
if group == (seg, group_base):
|
|
89
|
+
shared = not prior_keys.isdisjoint(keys)
|
|
90
|
+
else:
|
|
91
|
+
shared = domains_may_overlap(prior_domain, domain)
|
|
92
|
+
if shared:
|
|
93
|
+
raise StopPath("preservesMemory intervals overlap or alias")
|
|
94
|
+
resolved.append(((seg, group_base), set(keys), domain))
|
|
95
|
+
linear = seg == ("linear",)
|
|
82
96
|
cached = 0
|
|
83
97
|
for key in keys:
|
|
84
98
|
if key in state.memory:
|
|
@@ -89,7 +103,9 @@ def capture_scopes(state, model):
|
|
|
89
103
|
descriptions.append({
|
|
90
104
|
"segmentRegister": scope["segment"], "segment": segment.report(),
|
|
91
105
|
"baseRegister": scope["base"], "base": base.report(), "displacement": displacement,
|
|
92
|
-
"offset": offset,
|
|
106
|
+
"offset": offset.number,
|
|
107
|
+
"interval": {"segment": seg, "base": group_base, "start": start, "end": start + size},
|
|
108
|
+
"linearStart": start if linear else None, "linearEnd": start + size if linear else None, "bytes": size,
|
|
93
109
|
"cachedBytes": cached, "uncachedBytes": size - cached, "evidence": scope["evidence"],
|
|
94
110
|
"meaning": "explicit pre-call memory-preservation hypothesis; memory outside every scope is unknown"})
|
|
95
111
|
return values, unread, descriptions
|
|
@@ -104,15 +120,16 @@ def scope_history(state, values, unread):
|
|
|
104
120
|
def retain_scopes(state, values, unread, history):
|
|
105
121
|
"""Put the captured bytes back after the model invalidated memory. Later writes still apply.
|
|
106
122
|
|
|
107
|
-
|
|
108
|
-
|
|
123
|
+
Each byte rejoins the alias group of its own segment and base, so a later write that may alias
|
|
124
|
+
it drops it as it drops any other byte. ``history`` from ``scope_history`` keeps each byte's
|
|
125
|
+
reported writer, or its reason for having no value.
|
|
109
126
|
"""
|
|
110
127
|
state.memory.update(values)
|
|
111
128
|
state.unread_memory.update(unread)
|
|
112
129
|
state.memory_writers.update(history[0])
|
|
113
130
|
state.lost_memory.update(history[1])
|
|
114
|
-
|
|
115
|
-
state.memory_groups.setdefault(
|
|
131
|
+
for key in [*values, *unread]:
|
|
132
|
+
state.memory_groups.setdefault(key[:2], set()).add(key)
|
|
116
133
|
|
|
117
134
|
|
|
118
135
|
def model_scopes(models, event):
|
|
@@ -12,7 +12,7 @@ from .argument_frames import WINDOW_BYTES, argument_frames, stack_cleanup
|
|
|
12
12
|
from .memory_scopes import model_scopes
|
|
13
13
|
from .result_flow import return_flows
|
|
14
14
|
from .image import Image, integer
|
|
15
|
-
from .trace import (trace, walk, call_target, unsupported_transfer, uncovered, base_mnemonic, OVERLAP_REASON, CONTESTED_REASON,
|
|
15
|
+
from .trace import (trace, walk, cfg_step, call_target, unsupported_transfer, uncovered, base_mnemonic, OVERLAP_REASON, CONTESTED_REASON,
|
|
16
16
|
RETURNS, INTERRUPTS, PORTS, PORT_INPUTS, port_width, budget_input)
|
|
17
17
|
from .pcode_backend import interrupt_vector
|
|
18
18
|
|
|
@@ -233,24 +233,12 @@ def _function_exit(image, start, limit, follow_flat_ports, cache):
|
|
|
233
233
|
if ins is None:
|
|
234
234
|
continue
|
|
235
235
|
seen[at] = ins
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
elif m in RETURNS:
|
|
243
|
-
if not (image.flat and m in ("iret", "iretd")):
|
|
244
|
-
exits.append(at)
|
|
245
|
-
else:
|
|
246
|
-
if m == "ljmp" or m.startswith(("j", "loop")):
|
|
247
|
-
target, _ = call_target(image, at, ins)
|
|
248
|
-
if target is not None:
|
|
249
|
-
following.append(target)
|
|
250
|
-
if not (m in ("jmp", "ljmp") or m in INTERRUPTS or m == "hlt"
|
|
251
|
-
or (m in PORTS and image.flat and not follow_flat_ports)):
|
|
252
|
-
following.append(at + ins.size)
|
|
253
|
-
pending.extend(following)
|
|
236
|
+
# The same successor rule as walk(), except that a call continues only at its return site.
|
|
237
|
+
step = cfg_step(image, at, ins, follow_flat_ports, step_over_calls=True)
|
|
238
|
+
successors[at] = step.successors
|
|
239
|
+
if step.returns and not (image.flat and base_mnemonic(ins) in ("iret", "iretd")):
|
|
240
|
+
exits.append(at)
|
|
241
|
+
pending.extend(step.successors)
|
|
254
242
|
# Only the sites a return is reachable from lie on the way to it; a branch that never returns is left out.
|
|
255
243
|
callers = {}
|
|
256
244
|
for at, following in successors.items():
|
|
@@ -925,11 +913,17 @@ def body(image, entry, limit=10000):
|
|
|
925
913
|
continuation is listed as an assumption. Interrupts and port accesses are also listed as
|
|
926
914
|
hardware boundaries. A direct jump or conditional branch to another established entry or
|
|
927
915
|
another region, and every far jump, is a tail transfer.
|
|
916
|
+
|
|
917
|
+
flow records, for each instruction read, what the reading did after it. readsOn is whether it queued the
|
|
918
|
+
following instruction as the fall-through, or None at a transfer outside the frame model, where it stopped
|
|
919
|
+
with a gap and decided nothing. targets lists the jump or branch targets the instruction names (None for
|
|
920
|
+
one it could not resolve), including targets that leave the body. Reports that need where the body goes
|
|
921
|
+
from an instruction read flow instead of restating these rules.
|
|
928
922
|
"""
|
|
929
923
|
integer(limit, 1, 100000, "instruction limit")
|
|
930
924
|
established = set(entries(image))
|
|
931
925
|
pending, seen, exits, calls, gaps, assumed, shared = [entry], {}, [], [], [], [], set()
|
|
932
|
-
hardware = []
|
|
926
|
+
hardware, flow = [], {}
|
|
933
927
|
|
|
934
928
|
def leaves(at, target):
|
|
935
929
|
return (target in established and target != entry) or image.region(target) is not image.region(at)
|
|
@@ -948,7 +942,9 @@ def body(image, entry, limit=10000):
|
|
|
948
942
|
if at != entry and at in established:
|
|
949
943
|
shared.add(at)
|
|
950
944
|
m, following = base_mnemonic(ins), at + ins.size
|
|
945
|
+
step = flow[at] = {"readsOn": False, "targets": []}
|
|
951
946
|
if unsupported_transfer(image, ins):
|
|
947
|
+
step["readsOn"] = None
|
|
952
948
|
gaps.append({"site": at, "reason": "unsupported control-transfer frame encoding"})
|
|
953
949
|
continue
|
|
954
950
|
if m in RETURNS:
|
|
@@ -961,12 +957,13 @@ def body(image, entry, limit=10000):
|
|
|
961
957
|
hardware.append(hardware_boundary(image, at, ins))
|
|
962
958
|
assumed.append({"site": at, "assumption": ("the interrupt returns to the next instruction" if m in INTERRUPTS
|
|
963
959
|
else "the port access continues to the next instruction")})
|
|
960
|
+
step["readsOn"] = True
|
|
964
961
|
pending.append(following)
|
|
965
962
|
continue
|
|
966
963
|
if m in ("jmp", "ljmp"):
|
|
967
964
|
declaration = image.indirect_jumps.get(at)
|
|
968
965
|
if declaration is not None:
|
|
969
|
-
targets = sorted(set(row["target"] for row in declaration["rows"]))
|
|
966
|
+
targets = step["targets"] = sorted(set(row["target"] for row in declaration["rows"]))
|
|
970
967
|
# The full declaration is reported once, in indirectJumpDeclarations.
|
|
971
968
|
assumed.append({"site": at, "assumption": "indirect jump consumes the declared source table",
|
|
972
969
|
"targets": targets, "exhaustive": declaration["exhaustive"]})
|
|
@@ -982,6 +979,7 @@ def body(image, entry, limit=10000):
|
|
|
982
979
|
gaps.append({"site": at, "reason": "indirect jump table is not declared exhaustive"})
|
|
983
980
|
continue
|
|
984
981
|
target, provenance = call_target(image, at, ins)
|
|
982
|
+
step["targets"] = [target]
|
|
985
983
|
if target is None:
|
|
986
984
|
exits.append({"site": at, "kind": "unresolved jump", "reason": provenance.get("reason")})
|
|
987
985
|
gaps.append({"site": at, "reason": "jump target unresolved; the body may continue elsewhere"})
|
|
@@ -995,16 +993,19 @@ def body(image, entry, limit=10000):
|
|
|
995
993
|
calls.append({"site": at, "target": target, "encoding": m,
|
|
996
994
|
**({} if target is not None else {"reason": provenance.get("reason")})})
|
|
997
995
|
assumed.append({"site": at, "assumption": "the callee returns to the next instruction"})
|
|
996
|
+
step["readsOn"] = True
|
|
998
997
|
pending.append(following)
|
|
999
998
|
continue
|
|
1000
999
|
if m.startswith("j") or m.startswith("loop"):
|
|
1001
1000
|
target, provenance = call_target(image, at, ins)
|
|
1001
|
+
step["targets"] = [target]
|
|
1002
1002
|
if target is None:
|
|
1003
1003
|
gaps.append({"site": at, "reason": provenance.get("reason", "branch target outside declared regions")})
|
|
1004
1004
|
elif leaves(at, target):
|
|
1005
1005
|
exits.append({"site": at, "kind": "tail transfer", "target": target, "conditional": True})
|
|
1006
1006
|
else:
|
|
1007
1007
|
pending.append(target)
|
|
1008
|
+
step["readsOn"] = True
|
|
1008
1009
|
pending.append(following)
|
|
1009
1010
|
intervals = sorted((at, at + ins.size) for at, ins in seen.items())
|
|
1010
1011
|
runs, overlaps = [], []
|
|
@@ -1023,7 +1024,7 @@ def body(image, entry, limit=10000):
|
|
|
1023
1024
|
"span": {"start": runs[0][0], "end": runs[-1][1]} if runs else None, "coveredBytes": covered,
|
|
1024
1025
|
"exits": sorted(exits, key=lambda e: e["site"]), "calls": sorted(calls, key=lambda c: c["site"]),
|
|
1025
1026
|
"assumedContinuations": sorted(assumed, key=lambda a: a["site"]), "sharedEntries": sorted(shared),
|
|
1026
|
-
"hardwareBoundaries": sorted(hardware, key=lambda h: h["site"]),
|
|
1027
|
+
"hardwareBoundaries": sorted(hardware, key=lambda h: h["site"]), "flow": flow,
|
|
1027
1028
|
"gaps": gaps, "complete": bool(exits) and not gaps}
|
|
1028
1029
|
|
|
1029
1030
|
|
|
@@ -1222,9 +1223,19 @@ def _ghidra_call_edges(image, export):
|
|
|
1222
1223
|
or not isinstance(edge.get("fallsThrough", False), bool)):
|
|
1223
1224
|
raise ValueError("Invalid ghidraCallEdges edge")
|
|
1224
1225
|
# Copies of the script before fallsThrough was added leave it out; the cross-check then reads the flow name.
|
|
1225
|
-
|
|
1226
|
-
|
|
1227
|
-
|
|
1226
|
+
row = {"site": offset(edge["site"], "site"), "siteAddress": edge["siteAddress"],
|
|
1227
|
+
"target": offset(edge["target"], "target"), "targetAddress": edge["targetAddress"], "flow": edge["flow"],
|
|
1228
|
+
"fallsThrough": edge.get("fallsThrough")}
|
|
1229
|
+
# Copies of the script before fallsThroughTo was added leave out both keys; the script writes both with
|
|
1230
|
+
# fallsThrough, null unless a fall-through override sends Ghidra to another address, where fallsThrough is false.
|
|
1231
|
+
redirect = {"fallsThroughTo", "fallsThroughToAddress"} & edge.keys()
|
|
1232
|
+
if redirect:
|
|
1233
|
+
to, address = edge.get("fallsThroughTo"), edge.get("fallsThroughToAddress")
|
|
1234
|
+
if (len(redirect) != 2 or "fallsThrough" not in edge or not (address is None or isinstance(address, str))
|
|
1235
|
+
or (address is None and to is not None) or (address is not None and edge.get("fallsThrough") is not False)):
|
|
1236
|
+
raise ValueError("Invalid ghidraCallEdges edge")
|
|
1237
|
+
row["fallsThroughTo"] = None if address is None else {"target": offset(to, "fall-through"), "targetAddress": address}
|
|
1238
|
+
rows.append(row)
|
|
1228
1239
|
entry = offset(function["entry"], "entry")
|
|
1229
1240
|
if entry is None:
|
|
1230
1241
|
unmapped.append(function["address"])
|
|
@@ -1261,24 +1272,18 @@ def _ghidra_falls_through(g):
|
|
|
1261
1272
|
The export's fallsThrough also reflects a user's fall-through override. Copies of the script that leave it out
|
|
1262
1273
|
are read by the flow type's name, which misses such an override: a flow type Ghidra gives a fall-through
|
|
1263
1274
|
(GHIDRA_FALL_THROUGH_FLOWS) continues, and every other one ends the function.
|
|
1275
|
+
|
|
1276
|
+
Where a fall-through override sends Ghidra to another address, the export's fallsThroughTo names it and
|
|
1277
|
+
fallsThrough is false. Copies of the script that leave out fallsThroughTo give null with basis notExported, and
|
|
1278
|
+
such a redirect reads as a fall-through Ghidra does not take.
|
|
1264
1279
|
"""
|
|
1265
1280
|
exported = g["fallsThrough"] is not None
|
|
1266
1281
|
named = g["flow"] in GHIDRA_FALL_THROUGH_FLOWS
|
|
1282
|
+
redirect = "fallsThroughTo" in g
|
|
1267
1283
|
return {"ghidraFallsThrough": g["fallsThrough"] if exported else named,
|
|
1268
|
-
"ghidraFallsThroughBasis": "fallsThrough" if exported else "flowName"
|
|
1269
|
-
|
|
1270
|
-
|
|
1271
|
-
def _engine_reads_on(image, ins):
|
|
1272
|
-
"""Whether the engine's body reading continues to the instruction after ins.
|
|
1273
|
-
|
|
1274
|
-
It stops at a jmp, ljmp, return or hlt, and reads on past every other instruction, including a call, a conditional
|
|
1275
|
-
jump and an interrupt. At a transfer outside the frame model it stops with a gap, so the result is None: the engine
|
|
1276
|
-
decided nothing there. It is None too when the engine did not read ins.
|
|
1277
|
-
"""
|
|
1278
|
-
if ins is None or unsupported_transfer(image, ins):
|
|
1279
|
-
return None
|
|
1280
|
-
m = base_mnemonic(ins)
|
|
1281
|
-
return not (m in RETURNS or m in ("hlt", "jmp", "ljmp"))
|
|
1284
|
+
"ghidraFallsThroughBasis": "fallsThrough" if exported else "flowName",
|
|
1285
|
+
"ghidraFallsThroughTo": g["fallsThroughTo"] if redirect else None,
|
|
1286
|
+
"ghidraFallsThroughToBasis": "fallsThroughTo" if redirect else "notExported"}
|
|
1282
1287
|
|
|
1283
1288
|
|
|
1284
1289
|
def _ghidra_cross_check(image, export, nodes, outgoing, omitted):
|
|
@@ -1286,16 +1291,22 @@ def _ghidra_cross_check(image, export, nodes, outgoing, omitted):
|
|
|
1286
1291
|
callers = export["callers"]
|
|
1287
1292
|
compared = sorted(nodes.keys() & callers.keys())
|
|
1288
1293
|
rows = []
|
|
1289
|
-
# Rows where Ghidra ends the function at an instruction the engine reads past,
|
|
1290
|
-
# an instruction the engine stops at
|
|
1291
|
-
|
|
1292
|
-
|
|
1293
|
-
|
|
1294
|
-
|
|
1294
|
+
# Rows where Ghidra ends the function at an instruction the engine reads past, rows where Ghidra continues past
|
|
1295
|
+
# an instruction the engine stops at, and rows where Ghidra continues at another address than the next instruction.
|
|
1296
|
+
# Each way the two analyses disagree on the function's extent.
|
|
1297
|
+
ends, continues, elsewhere = [], [], []
|
|
1298
|
+
|
|
1299
|
+
def compare_extent(row, g, flow):
|
|
1300
|
+
# body() recorded whether it read on past the site: None where it stopped with a gap, and no record where it
|
|
1301
|
+
# did not read the site. Either way the engine decided nothing to compare.
|
|
1302
|
+
reads_on = flow.get(g["site"], {}).get("readsOn")
|
|
1295
1303
|
if reads_on is None:
|
|
1296
1304
|
return row
|
|
1297
1305
|
row |= _ghidra_falls_through(g)
|
|
1298
|
-
if
|
|
1306
|
+
if row["ghidraFallsThroughTo"] is not None:
|
|
1307
|
+
# Ghidra neither ends the function here nor reads on to the next instruction, whatever the engine does.
|
|
1308
|
+
elsewhere.append(row)
|
|
1309
|
+
elif reads_on and row["ghidraFallsThrough"] is False:
|
|
1299
1310
|
ends.append(row)
|
|
1300
1311
|
elif not reads_on and row["ghidraFallsThrough"] is True:
|
|
1301
1312
|
continues.append(row)
|
|
@@ -1304,7 +1315,8 @@ def _ghidra_cross_check(image, export, nodes, outgoing, omitted):
|
|
|
1304
1315
|
for caller in compared:
|
|
1305
1316
|
ours = outgoing.get(caller, [])
|
|
1306
1317
|
theirs = callers[caller]
|
|
1307
|
-
|
|
1318
|
+
flow = nodes[caller]["body"]["flow"]
|
|
1319
|
+
interrupts = {h["site"] for h in nodes[caller]["body"]["hardwareBoundaries"] if h["boundary"] == "interrupt"}
|
|
1308
1320
|
# A call neither analysis resolved matches on its site with no target.
|
|
1309
1321
|
matches = {_ghidra_key(g): g for g in theirs if g["site"] is not None}
|
|
1310
1322
|
read = {(e["site"], e["target"]) for e in ours}
|
|
@@ -1314,49 +1326,53 @@ def _ghidra_cross_check(image, export, nodes, outgoing, omitted):
|
|
|
1314
1326
|
"result": "engineOnly" if g is None else "agreement", "ghidraFlow": g["flow"] if g else None}
|
|
1315
1327
|
# Ghidra ends the function at a call to a callee it treats as non-returning (CALL_TERMINATOR) or at an
|
|
1316
1328
|
# instruction whose fall-through a user cleared, and continues past a jmp a user gave a fall-through.
|
|
1317
|
-
rows.append(row if g is None else compare_extent(row, g,
|
|
1329
|
+
rows.append(row if g is None else compare_extent(row, g, flow))
|
|
1318
1330
|
for g in theirs:
|
|
1319
1331
|
if g["site"] is not None and _ghidra_key(g) in read:
|
|
1320
1332
|
continue
|
|
1321
|
-
|
|
1322
|
-
if ins is not None and base_mnemonic(ins) in INTERRUPTS and _ghidra_key(g)[1] is None:
|
|
1333
|
+
if g["site"] in interrupts and _ghidra_key(g)[1] is None:
|
|
1323
1334
|
# SLEIGH lifts INT, INT1, INT3 and INTO to a computed call with no target, while the engine assumes the
|
|
1324
1335
|
# interrupt returns to the next instruction and records no edge. At INT1 and INT3 Ghidra's flow is a
|
|
1325
1336
|
# terminator that ends the function there.
|
|
1326
1337
|
rows.append(compare_extent({"caller": caller, "site": g["site"], "target": None, "siteAddress": g["siteAddress"],
|
|
1327
1338
|
"targetAddress": None, "ghidraFlow": g["flow"], "result": "interrupt",
|
|
1328
|
-
"engineEdge": None}, g,
|
|
1339
|
+
"engineEdge": None}, g, flow))
|
|
1329
1340
|
continue
|
|
1330
1341
|
# Ghidra's edge is evidence the engine did not check; it never becomes an engine edge. Its fall-through is
|
|
1331
1342
|
# still compared where the engine read the instruction at its site.
|
|
1332
1343
|
engine_edge = next((e["id"] for e in ours if g["site"] is not None and e["site"] == g["site"]), None)
|
|
1333
1344
|
rows.append(compare_extent({"caller": caller, "site": g["site"], "target": g["target"], "siteAddress": g["siteAddress"],
|
|
1334
1345
|
"targetAddress": g["targetAddress"], "ghidraFlow": g["flow"], "result": "ghidraOnly",
|
|
1335
|
-
"checked": False, "engineEdge": engine_edge}, g,
|
|
1346
|
+
"checked": False, "engineEdge": engine_edge}, g, flow))
|
|
1336
1347
|
counts = {kind: sum(r["result"] == kind for r in rows) for kind in ("agreement", "engineOnly", "ghidraOnly", "interrupt")}
|
|
1337
1348
|
counts["ghidraEndsFunction"] = len(ends)
|
|
1338
1349
|
counts["ghidraContinues"] = len(continues)
|
|
1350
|
+
counts["ghidraFallsThroughElsewhere"] = len(elsewhere)
|
|
1339
1351
|
not_compared = {"engineCallers": sorted(nodes.keys() - callers.keys()), "ghidraCallers": sorted(callers.keys() - nodes.keys()),
|
|
1340
1352
|
"unmappedGhidraFunctions": export["unmappedFunctions"], "missingGhidraEntries": export["missingEntries"],
|
|
1341
1353
|
"unreadGhidraFunctions": export["unreadFunctions"],
|
|
1342
1354
|
"omittedEngineRoutes": [o["id"] for o in omitted if o["entry"] in callers]}
|
|
1343
|
-
# A site agrees only when every edge either analysis read there agrees and Ghidra continues past it
|
|
1344
|
-
# engine does.
|
|
1345
|
-
disputed = {r["site"] for r in rows if r["result"] != "agreement"} | {r["site"] for r in ends + continues}
|
|
1355
|
+
# A site agrees only when every edge either analysis read there agrees and Ghidra continues past it to the next
|
|
1356
|
+
# instruction exactly when the engine does.
|
|
1357
|
+
disputed = {r["site"] for r in rows if r["result"] != "agreement"} | {r["site"] for r in ends + continues + elsewhere}
|
|
1346
1358
|
return {"comparedCallers": compared, "edges": rows, "counts": counts, "notCompared": not_compared,
|
|
1347
1359
|
"agreed": (not counts["engineOnly"] and not counts["ghidraOnly"] and not any(not_compared.values())
|
|
1348
|
-
and not counts["ghidraEndsFunction"] and not counts["ghidraContinues"]
|
|
1360
|
+
and not counts["ghidraEndsFunction"] and not counts["ghidraContinues"]
|
|
1361
|
+
and not counts["ghidraFallsThroughElsewhere"]),
|
|
1349
1362
|
"agreementSites": {r["site"] for r in rows if r["result"] == "agreement"} - disputed,
|
|
1350
1363
|
"interpretation": "Edges of each caller that both the engine and the Ghidra export read, matched by site and target "
|
|
1351
1364
|
"file offset; an unresolved call matches an unresolved call at its site, and a Ghidra target without a file offset "
|
|
1352
1365
|
"matches no engine edge. An interrupt row is Ghidra's targetless call at an instruction the engine read as an "
|
|
1353
1366
|
"interrupt and assumed to return. A row at an instruction the engine read carries whether Ghidra continues "
|
|
1354
1367
|
"to the next instruction there (ghidraFallsThrough), read from the export's fallsThrough or, in an export "
|
|
1355
|
-
"without it, from the flow name (ghidraFallsThroughBasis)
|
|
1368
|
+
"without it, from the flow name (ghidraFallsThroughBasis), and where a fall-through override sends Ghidra to "
|
|
1369
|
+
"another address (ghidraFallsThroughTo), read from the export's fallsThroughTo, or null with "
|
|
1370
|
+
"ghidraFallsThroughToBasis notExported for an export without it. The engine reads on past every call, conditional jump "
|
|
1356
1371
|
"and interrupt and stops at a jmp, ljmp, return or hlt. A row where Ghidra ends the function at an instruction "
|
|
1357
|
-
"the engine reads past (ghidraEndsFunction)
|
|
1358
|
-
"counts against agreed. A ghidraOnly edge
|
|
1359
|
-
"
|
|
1372
|
+
"the engine reads past (ghidraEndsFunction), continues past one the engine stops at (ghidraContinues) "
|
|
1373
|
+
"or continues at another address (ghidraFallsThroughElsewhere) counts against agreed. A ghidraOnly edge "
|
|
1374
|
+
"is Ghidra's claim: the engine did not check it and never adds it to its graph. Agreement means both "
|
|
1375
|
+
"analyses read the edge, not that it executes."}
|
|
1360
1376
|
|
|
1361
1377
|
|
|
1362
1378
|
# These branches test CX/ECX (LOOPE/LOOPNE also ZF), so an adjacent CMP/TEST never describes their predicate.
|
|
@@ -1397,17 +1413,15 @@ def call_order(image, config):
|
|
|
1397
1413
|
for at, ins in instructions.items():
|
|
1398
1414
|
ending.setdefault(at + ins.size, []).append(at)
|
|
1399
1415
|
for at, ins in instructions.items():
|
|
1400
|
-
|
|
1401
|
-
targets
|
|
1402
|
-
|
|
1403
|
-
|
|
1404
|
-
|
|
1405
|
-
|
|
1406
|
-
|
|
1407
|
-
elif m.startswith("j") or m.startswith("loop"):
|
|
1408
|
-
target = call_target(image, at, ins)[0]
|
|
1409
|
-
targets = [target, following]
|
|
1416
|
+
following = at + ins.size
|
|
1417
|
+
# body() recorded each instruction's jump or branch targets and whether it read on to the next instruction.
|
|
1418
|
+
step = b["flow"][at]
|
|
1419
|
+
targets = step["targets"] + ([following] if step["readsOn"] else [])
|
|
1420
|
+
if step["readsOn"] and step["targets"]:
|
|
1421
|
+
# A conditional branch: a named target and the fall-through.
|
|
1422
|
+
target = step["targets"][0]
|
|
1410
1423
|
if target != following:
|
|
1424
|
+
m = base_mnemonic(ins)
|
|
1411
1425
|
producer = ending.get(at, []) if m not in COUNT_BRANCHES and at != entry else []
|
|
1412
1426
|
comparison = instructions[producer[0]] if len(producer) == 1 else None
|
|
1413
1427
|
context = ({"site": producer[0], "mnemonic": comparison.mnemonic,
|
|
@@ -1417,8 +1431,6 @@ def call_order(image, config):
|
|
|
1417
1431
|
if to is not None:
|
|
1418
1432
|
branches.append({"site": at, "to": to, "taken": taken, "predicate": m,
|
|
1419
1433
|
"comparison": context, "interpretation": "necessary caller CFG edge, not a runtime value or preserved guard"})
|
|
1420
|
-
else:
|
|
1421
|
-
targets = [following]
|
|
1422
1434
|
successors[at] = sorted(set(t for t in targets if t in instructions))
|
|
1423
1435
|
# Returns, halts, unsupported frames and transfers out of the body leave the caller CFG.
|
|
1424
1436
|
if not targets or any(t not in instructions for t in targets):
|
|
@@ -1544,7 +1556,7 @@ def call_order(image, config):
|
|
|
1544
1556
|
|
|
1545
1557
|
|
|
1546
1558
|
def _body_report(b):
|
|
1547
|
-
return {k: v for k, v in b.items() if k
|
|
1559
|
+
return {k: v for k, v in b.items() if k not in ("instructions", "flow")} | {"instructionCount": len(b["instructions"])}
|
|
1548
1560
|
|
|
1549
1561
|
|
|
1550
1562
|
def _analyzer_function(config):
|