scientific-method-engine 15.3.0__tar.gz → 16.0.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-15.3.0 → scientific_method_engine-16.0.0}/PKG-INFO +1 -1
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/pyproject.toml +1 -1
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/pcode_backend.py +5 -3
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/relational.py +21 -4
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/values.py +49 -12
- scientific_method_engine-16.0.0/tests/test_join_terms.py +81 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_relational_controls.py +34 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_term_limit.py +5 -5
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_x86.py +1 -1
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/.gitignore +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/LICENSE +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/README.md +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/__init__.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/__main__.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/cli.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ClearNoReturnFunctions.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/CreateFunctions.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ExportBoundedFlow.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ExportCallEdges.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ExportFunctionFingerprints.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ExportFunctionInventory.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/MergeFallThroughFragment.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/RecoverCitedFunctions.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/RepairReturningCallers.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportCallArguments.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportCallPaths.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportCallSitesWithScalars.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportCallsToRange.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportConstantFirstArgumentCalls.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportDataBytes.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportDecompileMatches.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportDecompileWindow.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportFilePatternInMemory.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportFirstArgumentCallSummary.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportFunctionScalarConstants.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportFunctionSummary.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportInstructionContext.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportInstructionWindow.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportMemoryBlockForFileOffset.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportMemoryBlocks.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportRandomnessCandidates.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportRangeBoundaries.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportReferences.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportScalarConstants.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportStringReferences.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/ReportSymbolReferences.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/scientificmethod/FirstArgumentLookBack.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/scientificmethod/InstructionStart.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/scientificmethod/OperandConstants.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/ghidra/scientificmethod/Xxh3.java +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/__init__.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/argument_frames.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/dispatch.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/effect_order.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/image.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/inventory.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/loops.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/machine.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/memory_scopes.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/pcode.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/pe.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/reach.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/reports.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/result_flow.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/src/scientific_method_engine/x86/trace.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/oracle.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_continuation_budget.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_dispatch.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_effect_order.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_enter_frames.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_entry_frame.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_indirect_far_transfers.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_interrupt_models.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_inventory_check.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_loops.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_memory_scopes.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_nested_frame_request.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_oracle.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_pe.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_reach.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_return_checks.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_successor_rule.py +0 -0
- {scientific_method_engine-15.3.0 → scientific_method_engine-16.0.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: 16.0.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 = "16.0.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"
|
|
@@ -23,7 +23,7 @@ from capstone.x86 import X86_OP_REG, X86_OP_IMM, X86_OP_MEM
|
|
|
23
23
|
|
|
24
24
|
from .machine import ALIASES, StopPath, FLAT_PORT_REASON
|
|
25
25
|
from .pcode import LIFTER, Address, Run, FLAGS, SEGMENT_BASES, segment_base
|
|
26
|
-
from .values import Value, const, unknown, op, extract, join, resize, sources
|
|
26
|
+
from .values import Value, const, unknown, op, extract, join, join_offsets, resize, sources
|
|
27
27
|
|
|
28
28
|
# Conditional branches by the condition code SLEIGH decodes from 0x70 + code.
|
|
29
29
|
CONDITION_CODES = {}
|
|
@@ -210,8 +210,10 @@ def known_bit(term, position, width):
|
|
|
210
210
|
if head == "extract":
|
|
211
211
|
return known_bit(term[1], term[2] + position, term[4]) if position < term[3] else None
|
|
212
212
|
if head == "join":
|
|
213
|
-
|
|
214
|
-
|
|
213
|
+
for part, bits, offset in join_offsets(term):
|
|
214
|
+
if offset <= position < offset + bits:
|
|
215
|
+
return known_bit(part, position - offset, bits)
|
|
216
|
+
return None
|
|
215
217
|
if head in ("or", "and"):
|
|
216
218
|
bits = [known_bit(t, position, width) for t in term[1:]]
|
|
217
219
|
decisive, other = (1, 0) if head == "or" else (0, 1)
|
|
@@ -9,7 +9,7 @@ from math import inf
|
|
|
9
9
|
from .image import integer
|
|
10
10
|
from .machine import ALIASES, NO_WRITE, State, StopPath
|
|
11
11
|
from .memory_scopes import SEGMENTS
|
|
12
|
-
from .values import const, op, TermLimit
|
|
12
|
+
from .values import const, join_offsets, op, TermLimit
|
|
13
13
|
|
|
14
14
|
KINDS = ("reach", "order", "lastWriter", "containment", "relation", "origin")
|
|
15
15
|
OPERATORS = ("eq", "ne", "lt", "le", "gt", "ge")
|
|
@@ -308,8 +308,8 @@ def _unsigned(term, bits, ranges):
|
|
|
308
308
|
"""Bounds on the term's unsigned value at its width, read from bitwise structure and assumptions.
|
|
309
309
|
|
|
310
310
|
An assumed range, a constant, ``and``, ``or``, ``xor``, a shift right or division by a constant
|
|
311
|
-
(an arithmetic shift only when its operand's sign bit is clear), a remainder by a constant, a zero extension
|
|
312
|
-
range; any other term keeps it.
|
|
311
|
+
(an arithmetic shift only when its operand's sign bit is clear), a remainder by a constant, a zero extension, an extracted field
|
|
312
|
+
or a join of parts narrows the width's full range; any other term keeps it.
|
|
313
313
|
"""
|
|
314
314
|
if (term, bits) in ranges:
|
|
315
315
|
return ranges[(term, bits)]
|
|
@@ -344,6 +344,13 @@ def _unsigned(term, bits, ranges):
|
|
|
344
344
|
low = term[2]
|
|
345
345
|
if hi >> low <= top:
|
|
346
346
|
return lo >> low, hi >> low
|
|
347
|
+
if tag == "join" and sum(term[2]) == bits:
|
|
348
|
+
# The parts hold disjoint bits, so the value is the sum of each part shifted to its offset.
|
|
349
|
+
lo = hi = 0
|
|
350
|
+
for part, width, offset in join_offsets(term):
|
|
351
|
+
plo, phi = _unsigned(part, width, ranges)
|
|
352
|
+
lo, hi = lo + (plo << offset), hi + (phi << offset)
|
|
353
|
+
return lo, hi
|
|
347
354
|
return 0, top
|
|
348
355
|
|
|
349
356
|
|
|
@@ -386,6 +393,13 @@ def _modular(term, bits, ranges):
|
|
|
386
393
|
return _scaled(_modular(x, bits, ranges), y[1] if tag == "mul" else 1 << y[1])
|
|
387
394
|
if tag in ("zeroExtend", "signExtend") and term[3] == bits:
|
|
388
395
|
return _integer(term[1], term[2], tag == "signExtend", ranges)
|
|
396
|
+
if tag == "join" and sum(term[2]) == bits and (term, bits) not in ranges:
|
|
397
|
+
# The parts hold disjoint bits, so the join is the sum of each part's value shifted to its
|
|
398
|
+
# offset, and a part compared with the join it sits in cancels.
|
|
399
|
+
form = 0, {}
|
|
400
|
+
for part, width, offset in join_offsets(term):
|
|
401
|
+
form = _combine(form, _scaled(_integer(part, width, False, ranges), 1 << offset))
|
|
402
|
+
return form
|
|
389
403
|
return 0, {(term, bits): 1}
|
|
390
404
|
|
|
391
405
|
|
|
@@ -562,7 +576,10 @@ def _ranges(control, path, anchor):
|
|
|
562
576
|
ranges = {}
|
|
563
577
|
for a in control.get("assume", []):
|
|
564
578
|
value = path.value(a["value"], anchor)
|
|
565
|
-
|
|
579
|
+
expression, bits = value["expression"], value["bits"]
|
|
580
|
+
# An assumed join is its own atom, which _modular then keeps whole instead of splitting it
|
|
581
|
+
# into its parts.
|
|
582
|
+
form = (0, {(expression, bits): 1}) if expression[0] == "join" else _modular(expression, bits, {})
|
|
566
583
|
if not form[1]:
|
|
567
584
|
if not a["min"] <= form[0] <= a["max"]:
|
|
568
585
|
raise _Unresolved(f"the assumed value is {form[0]} here, outside the assumed range {a['min']}..{a['max']}")
|
|
@@ -1,7 +1,8 @@
|
|
|
1
1
|
"""Small bit-vector expressions; unknown values retain their producers."""
|
|
2
2
|
from dataclasses import dataclass
|
|
3
3
|
|
|
4
|
-
# The most terms one value's expression may hold, counting every tuple node at any depth
|
|
4
|
+
# The most terms one value's expression may hold, counting every tuple node at any depth except
|
|
5
|
+
# the part widths of a join.
|
|
5
6
|
TERM_LIMIT = 1024
|
|
6
7
|
|
|
7
8
|
|
|
@@ -33,7 +34,9 @@ class Value:
|
|
|
33
34
|
if count > TERM_LIMIT:
|
|
34
35
|
raise TermLimit()
|
|
35
36
|
if isinstance(term, tuple):
|
|
36
|
-
|
|
37
|
+
# A join's part widths are numbers about its parts, not a term of their own.
|
|
38
|
+
items = term[:2] if term and term[0] == "join" else term
|
|
39
|
+
pending.extend(item for item in items if isinstance(item, tuple))
|
|
37
40
|
|
|
38
41
|
@property
|
|
39
42
|
def number(self):
|
|
@@ -94,10 +97,13 @@ def extract(v, low, bits):
|
|
|
94
97
|
if low == 0 and bits == v.bits:
|
|
95
98
|
return v
|
|
96
99
|
if v.term[0] == "join":
|
|
97
|
-
parts
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
100
|
+
# A field of a join is the join of the fields of the parts it covers.
|
|
101
|
+
pieces = []
|
|
102
|
+
for term, width, offset in join_offsets(v.term):
|
|
103
|
+
start, end = max(low, offset), min(low + bits, offset + width)
|
|
104
|
+
if start < end:
|
|
105
|
+
pieces.append(extract(Value(width, term, v.sources), start - offset, end - start))
|
|
106
|
+
return join(pieces)
|
|
101
107
|
if v.term[0] == "extract":
|
|
102
108
|
original, previous_low, _, original_bits = v.term[1:]
|
|
103
109
|
return Value(bits, ("extract", original, previous_low + low, bits, original_bits), v.sources)
|
|
@@ -105,6 +111,14 @@ def extract(v, low, bits):
|
|
|
105
111
|
|
|
106
112
|
|
|
107
113
|
def join(parts):
|
|
114
|
+
"""The value whose bits are ``parts`` laid end to end, the first part lowest.
|
|
115
|
+
|
|
116
|
+
A ``join`` term is ``("join", terms, widths)``: the parts' terms and their widths in bits,
|
|
117
|
+
lowest first. A part that is itself a join contributes its own parts. Adjacent constant parts
|
|
118
|
+
become one constant, and adjacent fields of one value become one field, or that value when they
|
|
119
|
+
cover all of it. So a join never nests, and a partial write that stores a register's own bits
|
|
120
|
+
back leaves its term as it was.
|
|
121
|
+
"""
|
|
108
122
|
bits = sum(v.bits for v in parts)
|
|
109
123
|
if len(parts) == 1:
|
|
110
124
|
# A single part is already its own value; wrapping it would nest on every partial register write.
|
|
@@ -115,12 +129,35 @@ def join(parts):
|
|
|
115
129
|
n |= v.number << shift
|
|
116
130
|
shift += v.bits
|
|
117
131
|
return Value(bits, const(n, bits).term, sources(*parts))
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
132
|
+
terms, widths = [], []
|
|
133
|
+
for v in parts:
|
|
134
|
+
for term, width in zip(*(v.term[1:] if v.term[0] == "join" else ((v.term,), (v.bits,)))):
|
|
135
|
+
previous = terms[-1] if terms else None
|
|
136
|
+
if previous and previous[0] == term[0] == "constant":
|
|
137
|
+
terms[-1] = ("constant", previous[1] | term[1] << widths[-1])
|
|
138
|
+
elif (previous and previous[0] == term[0] == "extract" and term[1] == previous[1]
|
|
139
|
+
and term[2] == previous[2] + previous[3]):
|
|
140
|
+
original, start, original_bits = previous[1], previous[2], previous[4]
|
|
141
|
+
merged = widths[-1] + width
|
|
142
|
+
terms[-1] = original if start == 0 and merged == original_bits else (
|
|
143
|
+
"extract", original, start, merged, original_bits)
|
|
144
|
+
else:
|
|
145
|
+
terms.append(term)
|
|
146
|
+
widths.append(width)
|
|
147
|
+
continue
|
|
148
|
+
widths[-1] += width
|
|
149
|
+
if len(terms) == 1:
|
|
150
|
+
return Value(bits, terms[0], sources(*parts))
|
|
151
|
+
return Value(bits, ("join", tuple(terms), tuple(widths)), sources(*parts))
|
|
152
|
+
|
|
153
|
+
|
|
154
|
+
def join_offsets(term):
|
|
155
|
+
"""A ``join`` term's parts as ``(term, width, offset)``, lowest first, each offset in bits."""
|
|
156
|
+
result, offset = [], 0
|
|
157
|
+
for part, width in zip(term[1], term[2]):
|
|
158
|
+
result.append((part, width, offset))
|
|
159
|
+
offset += width
|
|
160
|
+
return result
|
|
124
161
|
|
|
125
162
|
|
|
126
163
|
def resize(v, bits, signed=False):
|
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
"""Join terms record their parts' widths; readers find each part at its own offset. Synthetic values only."""
|
|
2
|
+
import unittest
|
|
3
|
+
import test_x86 # noqa: F401 (puts the engine source on the path)
|
|
4
|
+
from scientific_method_engine.x86.pcode_backend import known_bit
|
|
5
|
+
from scientific_method_engine.x86.relational import _unsigned
|
|
6
|
+
from scientific_method_engine.x86.values import Value, const, extract, join, unknown
|
|
7
|
+
|
|
8
|
+
|
|
9
|
+
def word(name):
|
|
10
|
+
return unknown(name, 16)
|
|
11
|
+
|
|
12
|
+
|
|
13
|
+
class JoinTermTests(unittest.TestCase):
|
|
14
|
+
def test_a_join_lists_its_parts_and_their_widths(self):
|
|
15
|
+
low, high = word("low"), word("high")
|
|
16
|
+
self.assertEqual(join([low, high]).term, ("join", (low.term, high.term), (16, 16)))
|
|
17
|
+
|
|
18
|
+
def test_a_nested_join_contributes_its_own_parts(self):
|
|
19
|
+
a, b, c = unknown("a", 8), unknown("b", 8), word("c")
|
|
20
|
+
self.assertEqual(join([join([a, b]), c]).term, ("join", (a.term, b.term, c.term), (8, 8, 16)))
|
|
21
|
+
|
|
22
|
+
def test_consecutive_fields_of_one_value_are_that_value(self):
|
|
23
|
+
whole = unknown("whole", 32)
|
|
24
|
+
self.assertEqual(join([extract(whole, 0, 16), extract(whole, 16, 8), extract(whole, 24, 8)]).term, whole.term)
|
|
25
|
+
self.assertEqual(join([extract(whole, 0, 8), extract(whole, 8, 16)]).term, ("extract", whole.term, 0, 24, 32))
|
|
26
|
+
|
|
27
|
+
def test_a_field_on_part_boundaries_selects_the_parts(self):
|
|
28
|
+
# A join of 16-bit parts, as PIECE and the zero-extended halves idiom build: the high word
|
|
29
|
+
# is the second part, not a byte offset into the part list.
|
|
30
|
+
low, high = word("low"), word("high")
|
|
31
|
+
joined = join([low, high])
|
|
32
|
+
self.assertEqual(extract(joined, 16, 16).term, high.term)
|
|
33
|
+
self.assertEqual(extract(joined, 0, 16).term, low.term)
|
|
34
|
+
# A field across a boundary joins the fields of the parts it covers.
|
|
35
|
+
self.assertEqual(extract(joined, 8, 16).term, ("join", (("extract", low.term, 8, 8, 16),
|
|
36
|
+
("extract", high.term, 0, 8, 16)), (8, 8)))
|
|
37
|
+
|
|
38
|
+
def test_a_field_inside_a_part_is_a_field_of_that_part(self):
|
|
39
|
+
# AH of (high << 16 | 1234h) is the constant 12h, and a field of an unknown part names that part.
|
|
40
|
+
joined = join([const(0x1234, 16), word("high")])
|
|
41
|
+
self.assertEqual(extract(joined, 8, 8).number, 0x12)
|
|
42
|
+
self.assertEqual(extract(joined, 20, 8).term, ("extract", ("unknown", "high"), 4, 8, 16))
|
|
43
|
+
|
|
44
|
+
def test_adjacent_parts_of_one_value_or_constants_merge(self):
|
|
45
|
+
whole, byte = unknown("whole", 32), unknown("byte", 8)
|
|
46
|
+
self.assertEqual(join([byte, extract(whole, 8, 8), extract(whole, 16, 8), extract(whole, 24, 8)]).term,
|
|
47
|
+
("join", (byte.term, ("extract", whole.term, 8, 24, 32)), (8, 24)))
|
|
48
|
+
self.assertEqual(join([const(0x34, 8), const(0x12, 8), word("high")]).term,
|
|
49
|
+
("join", (("constant", 0x1234), ("unknown", "high")), (16, 16)))
|
|
50
|
+
|
|
51
|
+
def test_writing_a_register_its_own_bytes_keeps_its_term(self):
|
|
52
|
+
# A partial write splits the old value into bytes and puts them back; the join it builds
|
|
53
|
+
# is the term the register held, for parts of any width.
|
|
54
|
+
for joined in (join([const(0x1234, 16), word("high")]), join([word("low"), word("high")])):
|
|
55
|
+
self.assertEqual(join([extract(joined, n, 8) for n in range(0, 32, 8)]).term, joined.term)
|
|
56
|
+
|
|
57
|
+
def test_a_known_bit_comes_from_the_part_that_holds_it(self):
|
|
58
|
+
# Bit 12 of (high << 16 | 0010h) is bit 12 of the constant low word, clear; bit 20 is high's.
|
|
59
|
+
joined = join([const(0x0010, 16), word("high")])
|
|
60
|
+
self.assertEqual(known_bit(joined.term, 4, 32), 1)
|
|
61
|
+
self.assertEqual(known_bit(joined.term, 12, 32), 0)
|
|
62
|
+
self.assertIsNone(known_bit(joined.term, 20, 32))
|
|
63
|
+
swapped = join([word("low"), const(0x0010, 16)])
|
|
64
|
+
self.assertIsNone(known_bit(swapped.term, 12, 32))
|
|
65
|
+
self.assertEqual(known_bit(swapped.term, 20, 32), 1)
|
|
66
|
+
|
|
67
|
+
def test_a_join_is_bounded_by_its_parts_at_their_offsets(self):
|
|
68
|
+
byte = unknown("byte", 8)
|
|
69
|
+
self.assertEqual(_unsigned(join([byte, const(0, 8)]).term, 16, {}), (0, 0xff))
|
|
70
|
+
self.assertEqual(_unsigned(join([byte, const(0x12, 8)]).term, 16, {}), (0x1200, 0x12ff))
|
|
71
|
+
# Parts that are not bytes: a 4-bit field below a 12-bit constant.
|
|
72
|
+
nibble = Value(4, ("unknown", "nibble"))
|
|
73
|
+
self.assertEqual(_unsigned(join([nibble, const(0x123, 12)]).term, 16, {}), (0x1230, 0x123f))
|
|
74
|
+
self.assertEqual(_unsigned(join([word("low"), const(0, 16)]).term, 32, {}), (0, 0xffff))
|
|
75
|
+
# An assumed range on a part narrows the join.
|
|
76
|
+
assumed = {(byte.term, 8): (0, 7)}
|
|
77
|
+
self.assertEqual(_unsigned(join([byte, const(0, 8)]).term, 16, assumed), (0, 7))
|
|
78
|
+
|
|
79
|
+
|
|
80
|
+
if __name__ == "__main__":
|
|
81
|
+
unittest.main()
|
|
@@ -704,6 +704,40 @@ class BitwiseBoundTests(unittest.TestCase):
|
|
|
704
704
|
self.assertEqual(self.check("0f b6 1e 00 02 83 cb 10", "le", 0xff)["verdict"], "held")
|
|
705
705
|
self.assertEqual(self.check("0f b6 1e 00 02 83 cb 10", "le", 0xfe)["verdict"], "undecided")
|
|
706
706
|
|
|
707
|
+
def test_a_partial_register_write_bounds_the_register_by_its_parts(self):
|
|
708
|
+
# mov bl,[0200h]; xor bh,bh: the zero-extension idiom leaves BX at most 0FFh, like movzx.
|
|
709
|
+
held = self.check("8a 1e 00 02 30 ff", "le", 0xff)
|
|
710
|
+
self.assertEqual(held["verdict"], "held")
|
|
711
|
+
self.assertEqual(held["paths"][0]["occurrences"][0]["leftMinusRight"], {"min": -0xff, "max": 0})
|
|
712
|
+
self.assertEqual(self.check("8a 1e 00 02 30 ff", "le", 0xfe)["verdict"], "undecided")
|
|
713
|
+
# mov bl,[0200h]; mov bh,12h: a constant high byte puts BX in 1200h..12FFh.
|
|
714
|
+
self.assertEqual(self.check("8a 1e 00 02 b7 12", "ge", 0x1200)["verdict"], "held")
|
|
715
|
+
self.assertEqual(self.check("8a 1e 00 02 b7 12", "le", 0x12ff)["verdict"], "held")
|
|
716
|
+
self.assertEqual(self.check("8a 1e 00 02 b7 12", "le", 0x12fe)["verdict"], "undecided")
|
|
717
|
+
with self.assertRaisesRegex(ValueError, "bound violated"):
|
|
718
|
+
self.check("8a 1e 00 02 b7 12", "lt", 0x1200)
|
|
719
|
+
# A loaded word is a join of two unknown bytes and keeps its whole range.
|
|
720
|
+
self.assertEqual(self.check("8b 1e 00 02", "le", 0xfffe)["verdict"], "undecided")
|
|
721
|
+
|
|
722
|
+
def test_a_register_compared_with_its_own_part_cancels(self):
|
|
723
|
+
# mov bl,[0200h]; xor bh,bh: BX is BL. With mov bh,12h in place of the xor, BX is BL + 1200h.
|
|
724
|
+
held = self.check("8a 1e 00 02 30 ff", "eq", {"field": "registers.bl"})
|
|
725
|
+
self.assertEqual(held["verdict"], "held")
|
|
726
|
+
self.assertEqual(held["paths"][0]["occurrences"][0]["leftMinusRight"], {"min": 0, "max": 0})
|
|
727
|
+
self.assertEqual(self.check("8a 1e 00 02 b7 12", "gt", {"field": "registers.bl"})["verdict"], "held")
|
|
728
|
+
with self.assertRaisesRegex(ValueError, "bound violated"):
|
|
729
|
+
self.check("8a 1e 00 02 b7 12", "eq", {"field": "registers.bl"})
|
|
730
|
+
# Two unknown bytes: BX is not BL unless BH is zero.
|
|
731
|
+
self.assertEqual(self.check("8b 1e 00 02", "eq", {"field": "registers.bl"})["verdict"], "undecided")
|
|
732
|
+
|
|
733
|
+
def test_an_assumption_on_a_loaded_word_bounds_the_word(self):
|
|
734
|
+
# mov bx,[0200h] joins two unknown bytes; an assumed range on BX applies to the whole join.
|
|
735
|
+
c = Code().emit("8b 1e 00 02").label("return").emit("c3")
|
|
736
|
+
rule = control("bound", "relation", at={"site": c.labels["return"], "event": "checkpoint"}, op="le",
|
|
737
|
+
left={"field": "registers.bx"}, right=10,
|
|
738
|
+
assume=[{"value": {"field": "registers.bx"}, "min": 0, "max": 10, "evidence": "synthetic range"}])
|
|
739
|
+
self.assertEqual(verdict(run(c, [rule], registers=FRAME), "bound")["verdict"], "held")
|
|
740
|
+
|
|
707
741
|
def test_an_assumed_range_bounds_the_masked_operand(self):
|
|
708
742
|
# mov bx,cx; and bx,0FFh, with CX assumed at most 7.
|
|
709
743
|
c = Code().emit("89 cb 81 e3 ff 00").label("return").emit("c3")
|
{scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_term_limit.py
RENAMED
|
@@ -160,9 +160,9 @@ class TermLimitTests(unittest.TestCase):
|
|
|
160
160
|
self.assertIn("was not formed: " + STOP, occurrence["reason"])
|
|
161
161
|
|
|
162
162
|
def test_an_entry_frame_whose_sp_cannot_be_formed_is_not_established(self):
|
|
163
|
-
# The entry SP's root starts at
|
|
163
|
+
# The entry SP's root starts at six terms, so 509 NOTs of ESP leave it at the limit; SP
|
|
164
164
|
# at the arrival is past it, and no offset is claimed.
|
|
165
|
-
c = Code().emit("66 f7 d4" *
|
|
165
|
+
c = Code().emit("66 f7 d4" * 509).label("entry").emit("c3")
|
|
166
166
|
data = c.bytes()
|
|
167
167
|
regions = [{"name": "synthetic", "start": 0, "end": len(data), "ip": 0, "segment": 0x1000, "resident": True,
|
|
168
168
|
"entries": [0, c.labels["entry"]], "evidence": "synthetic declared code extent"}]
|
|
@@ -174,7 +174,7 @@ class TermLimitTests(unittest.TestCase):
|
|
|
174
174
|
self.assertEqual(frame["reasons"], ["SP at an arrival could not be formed: " + STOP])
|
|
175
175
|
|
|
176
176
|
def test_an_entry_frame_whose_bp_cannot_be_formed_names_the_limit(self):
|
|
177
|
-
# BP copies the entry SP's
|
|
177
|
+
# BP copies the entry SP's six terms, so 509 NOTs of EBP leave it at the limit; BP at the
|
|
178
178
|
# arrival is past it. SP is unaffected, so the frame is still established.
|
|
179
179
|
def frame(count):
|
|
180
180
|
c = Code().emit("66 89 e5" + " 66 f7 d5" * count).label("entry").emit("c3")
|
|
@@ -185,11 +185,11 @@ class TermLimitTests(unittest.TestCase):
|
|
|
185
185
|
entryFrame={"from": 0}, maxSteps=520)["entryFrame"]
|
|
186
186
|
|
|
187
187
|
# The positive control: one NOT fewer forms BP, which is just not an offset.
|
|
188
|
-
formed = frame(
|
|
188
|
+
formed = frame(508)
|
|
189
189
|
self.assertTrue(formed["established"])
|
|
190
190
|
self.assertIsNone(formed["bp"])
|
|
191
191
|
self.assertNotIn("bpUnresolved", formed)
|
|
192
|
-
unformed = frame(
|
|
192
|
+
unformed = frame(509)
|
|
193
193
|
self.assertTrue(unformed["established"])
|
|
194
194
|
self.assertIsNone(unformed["bp"])
|
|
195
195
|
self.assertEqual(unformed["reasons"], [])
|
|
@@ -2524,7 +2524,7 @@ class ReporterTests(unittest.TestCase):
|
|
|
2524
2524
|
|
|
2525
2525
|
def test_symbolic_growth_is_bounded(self):
|
|
2526
2526
|
# test_term_limit.py covers the stop beside other paths.
|
|
2527
|
-
path = report("01 d8 " *
|
|
2527
|
+
path = report("01 d8 " * 400 + "c3")["paths"][0]
|
|
2528
2528
|
self.assertFalse(path["returned"])
|
|
2529
2529
|
self.assertTrue(path["stop"].startswith("expression term limit"))
|
|
2530
2530
|
|
|
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
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_effect_order.py
RENAMED
|
File without changes
|
{scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_enter_frames.py
RENAMED
|
File without changes
|
{scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_entry_frame.py
RENAMED
|
File without changes
|
|
File without changes
|
{scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_interrupt_models.py
RENAMED
|
File without changes
|
{scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_inventory_check.py
RENAMED
|
File without changes
|
|
File without changes
|
{scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_memory_scopes.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
{scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_return_checks.py
RENAMED
|
File without changes
|
{scientific_method_engine-15.3.0 → scientific_method_engine-16.0.0}/tests/test_successor_rule.py
RENAMED
|
File without changes
|
|
File without changes
|