scientific-method-engine 12.0.0__tar.gz → 13.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-12.0.0 → scientific_method_engine-13.0.0}/PKG-INFO +5 -5
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/README.md +4 -4
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/pyproject.toml +1 -1
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportFunctionScalarConstants.java +13 -8
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportReferences.java +7 -1
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportScalarConstants.java +14 -11
- scientific_method_engine-13.0.0/src/scientific_method_engine/ghidra/scientificmethod/OperandConstants.java +29 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/.gitignore +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/LICENSE +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/__init__.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/__main__.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/cli.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ClearNoReturnFunctions.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/CreateFunctions.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ExportBoundedFlow.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ExportCallEdges.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ExportFunctionFingerprints.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ExportFunctionInventory.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/MergeFallThroughFragment.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/RecoverCitedFunctions.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/RepairReturningCallers.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportCallArguments.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportCallPaths.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportCallSitesWithScalars.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportCallsToRange.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportConstantFirstArgumentCalls.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportDataBytes.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportDecompileMatches.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportDecompileWindow.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportFilePatternInMemory.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportFirstArgumentCallSummary.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportFunctionSummary.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportInstructionContext.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportInstructionWindow.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportMemoryBlockForFileOffset.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportMemoryBlocks.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportRandomnessCandidates.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportStringReferences.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/ReportSymbolReferences.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/scientificmethod/FirstArgumentLookBack.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/ghidra/scientificmethod/InstructionStart.java +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/__init__.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/argument_frames.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/dispatch.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/effect_order.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/image.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/loops.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/machine.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/memory_scopes.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/pcode.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/pcode_backend.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/pe.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/relational.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/reports.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/result_flow.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/trace.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/src/scientific_method_engine/x86/values.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/oracle.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_continuation_budget.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_dispatch.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_effect_order.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_enter_frames.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_entry_frame.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_indirect_far_transfers.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_interrupt_models.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_loops.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_memory_scopes.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_nested_frame_request.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_oracle.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_pe.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_relational_controls.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_return_checks.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_successor_rule.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_table_continuations.py +0 -0
- {scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_x86.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: scientific-method-engine
|
|
3
|
-
Version:
|
|
3
|
+
Version: 13.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
|
|
@@ -51,8 +51,8 @@ for the other report scripts, a result count equal to the cap means the same.
|
|
|
51
51
|
`analyzeHeadless` can exit with code 0 after a script failed to load, so check the log for the
|
|
52
52
|
script's own result lines ([the Ghidra workflow](https://github.com/kibertoad/refurbished-dinosaurs-toolkit/blob/main/docs/ghidra-workflow.md)
|
|
53
53
|
says what a run must show). The scripts compile against Ghidra 12.1. `ReportConstantFirstArgumentCalls`,
|
|
54
|
-
`ReportFirstArgumentCallSummary`, `ReportCallSitesWithScalars`, `
|
|
55
|
-
`ExportBoundedFlow` load shared helpers from the `scientificmethod/` directory beside them, so pass the directory the command prints as `-scriptPath`,
|
|
54
|
+
`ReportFirstArgumentCallSummary`, `ReportCallSitesWithScalars`, `ReportScalarConstants`,
|
|
55
|
+
`ReportFunctionScalarConstants`, `ReportInstructionWindow` and `ExportBoundedFlow` load shared helpers from the `scientificmethod/` directory beside them, so pass the directory the command prints as `-scriptPath`,
|
|
56
56
|
or copy that subdirectory along with the scripts.
|
|
57
57
|
|
|
58
58
|
Reading code and data:
|
|
@@ -73,11 +73,11 @@ Finding references and calls:
|
|
|
73
73
|
|
|
74
74
|
| Script | Arguments | Prints |
|
|
75
75
|
|---|---|---|
|
|
76
|
-
| `ReportReferences` | one or more addresses | references to each, with the referring instruction and
|
|
76
|
+
| `ReportReferences` | one or more addresses | references to each, with the referring instruction, function and Ghidra reference type. The type is not the access: `DATA` covers indexed reads and writes and address formation, and a memory operand Ghidra gave no reference is not listed |
|
|
77
77
|
| `ReportStringReferences` | one or more literal string fragments | strings containing a fragment and their references |
|
|
78
78
|
| `ReportSymbolReferences` | one or more symbol-name fragments, matched as case-insensitive substrings of the full name | matching symbols, default labels included, and their references. Default labels end in their address, so an address fragment such as `0089d4a4` finds the `PTR_<name>_0089d4a4` import slot there |
|
|
79
79
|
| `ReportScalarConstants` | optional operand kind (`immediate` or `memory`), one or more scalar values | instructions using any of them, unsigned or signed, as an immediate or inside a memory operand (a displacement such as `[ECX + 0x44]`, an absolute address such as `[0x41c000]`, or an index scale), with the kind on each line |
|
|
80
|
-
| `ReportFunctionScalarConstants` | function address, one or more scalar values | instructions inside one function using any of them, compared unsigned |
|
|
80
|
+
| `ReportFunctionScalarConstants` | function address, one or more scalar values | instructions inside one function using any of them, compared unsigned, as an immediate or inside a memory operand (a displacement, an absolute address or an index scale) |
|
|
81
81
|
| `ReportCallArguments` | callee address | the three nearest pushed arguments at every call Ghidra references to the callee |
|
|
82
82
|
| `ReportCallSitesWithScalars` | callee address, one or more scalar values | calls whose argument setup contains a requested value as an immediate, never as a memory-operand displacement or address. The setup is up to 12 instructions that fall through to the call, ending after a function entry or a jump or call target, and before an earlier call. Then the counts or the cap |
|
|
83
83
|
| `ReportConstantFirstArgumentCalls` | callee address, constant | cdecl calls whose first argument is the constant: the nearest `PUSH` before the call, past instructions that fall through, are no function entry or jump or call target, and write neither the stack pointer nor memory addressed through it. Only calls Ghidra references to the callee are read |
|
|
@@ -35,8 +35,8 @@ for the other report scripts, a result count equal to the cap means the same.
|
|
|
35
35
|
`analyzeHeadless` can exit with code 0 after a script failed to load, so check the log for the
|
|
36
36
|
script's own result lines ([the Ghidra workflow](https://github.com/kibertoad/refurbished-dinosaurs-toolkit/blob/main/docs/ghidra-workflow.md)
|
|
37
37
|
says what a run must show). The scripts compile against Ghidra 12.1. `ReportConstantFirstArgumentCalls`,
|
|
38
|
-
`ReportFirstArgumentCallSummary`, `ReportCallSitesWithScalars`, `
|
|
39
|
-
`ExportBoundedFlow` load shared helpers from the `scientificmethod/` directory beside them, so pass the directory the command prints as `-scriptPath`,
|
|
38
|
+
`ReportFirstArgumentCallSummary`, `ReportCallSitesWithScalars`, `ReportScalarConstants`,
|
|
39
|
+
`ReportFunctionScalarConstants`, `ReportInstructionWindow` and `ExportBoundedFlow` load shared helpers from the `scientificmethod/` directory beside them, so pass the directory the command prints as `-scriptPath`,
|
|
40
40
|
or copy that subdirectory along with the scripts.
|
|
41
41
|
|
|
42
42
|
Reading code and data:
|
|
@@ -57,11 +57,11 @@ Finding references and calls:
|
|
|
57
57
|
|
|
58
58
|
| Script | Arguments | Prints |
|
|
59
59
|
|---|---|---|
|
|
60
|
-
| `ReportReferences` | one or more addresses | references to each, with the referring instruction and
|
|
60
|
+
| `ReportReferences` | one or more addresses | references to each, with the referring instruction, function and Ghidra reference type. The type is not the access: `DATA` covers indexed reads and writes and address formation, and a memory operand Ghidra gave no reference is not listed |
|
|
61
61
|
| `ReportStringReferences` | one or more literal string fragments | strings containing a fragment and their references |
|
|
62
62
|
| `ReportSymbolReferences` | one or more symbol-name fragments, matched as case-insensitive substrings of the full name | matching symbols, default labels included, and their references. Default labels end in their address, so an address fragment such as `0089d4a4` finds the `PTR_<name>_0089d4a4` import slot there |
|
|
63
63
|
| `ReportScalarConstants` | optional operand kind (`immediate` or `memory`), one or more scalar values | instructions using any of them, unsigned or signed, as an immediate or inside a memory operand (a displacement such as `[ECX + 0x44]`, an absolute address such as `[0x41c000]`, or an index scale), with the kind on each line |
|
|
64
|
-
| `ReportFunctionScalarConstants` | function address, one or more scalar values | instructions inside one function using any of them, compared unsigned |
|
|
64
|
+
| `ReportFunctionScalarConstants` | function address, one or more scalar values | instructions inside one function using any of them, compared unsigned, as an immediate or inside a memory operand (a displacement, an absolute address or an index scale) |
|
|
65
65
|
| `ReportCallArguments` | callee address | the three nearest pushed arguments at every call Ghidra references to the callee |
|
|
66
66
|
| `ReportCallSitesWithScalars` | callee address, one or more scalar values | calls whose argument setup contains a requested value as an immediate, never as a memory-operand displacement or address. The setup is up to 12 instructions that fall through to the call, ending after a function entry or a jump or call target, and before an earlier call. Then the counts or the cap |
|
|
67
67
|
| `ReportConstantFirstArgumentCalls` | callee address, constant | cdecl calls whose first argument is the constant: the nearest `PUSH` before the call, past instructions that fall through, are no function entry or jump or call target, and write neither the stack pointer nor memory addressed through it. Only calls Ghidra references to the callee are read |
|
|
@@ -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 = "13.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"
|
|
@@ -1,15 +1,19 @@
|
|
|
1
|
-
// Reports instruction references to selected scalar values within one function
|
|
1
|
+
// Reports instruction references to selected scalar values within one function: immediates and
|
|
2
|
+
// memory-operand displacements, absolute addresses such as [0x41c000] and index scales.
|
|
2
3
|
// @category Restoration
|
|
3
4
|
|
|
4
5
|
import ghidra.app.script.GhidraScript;
|
|
5
6
|
import ghidra.program.model.address.Address;
|
|
6
7
|
import ghidra.program.model.listing.Function;
|
|
7
8
|
import ghidra.program.model.listing.Instruction;
|
|
9
|
+
import ghidra.program.model.listing.InstructionIterator;
|
|
8
10
|
import ghidra.program.model.scalar.Scalar;
|
|
9
11
|
|
|
10
12
|
import java.util.HashSet;
|
|
11
13
|
import java.util.Set;
|
|
12
14
|
|
|
15
|
+
import scientificmethod.OperandConstants;
|
|
16
|
+
|
|
13
17
|
public class ReportFunctionScalarConstants extends GhidraScript {
|
|
14
18
|
private static final int MAX_MATCHES = 200;
|
|
15
19
|
|
|
@@ -33,14 +37,16 @@ public class ReportFunctionScalarConstants extends GhidraScript {
|
|
|
33
37
|
requested.add(Long.decode(arguments[index]));
|
|
34
38
|
|
|
35
39
|
int matches = 0;
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
while (
|
|
39
|
-
|
|
40
|
+
// The whole body, so a chunk before the entry or past another function's code is read too.
|
|
41
|
+
InstructionIterator instructions = currentProgram.getListing().getInstructions(function.getBody(), true);
|
|
42
|
+
while (instructions.hasNext()) {
|
|
43
|
+
monitor.checkCancelled();
|
|
44
|
+
Instruction instruction = instructions.next();
|
|
40
45
|
for (int operand = 0; operand < instruction.getNumOperands(); operand++) {
|
|
46
|
+
int operandType = instruction.getOperandType(operand);
|
|
41
47
|
for (Object object : instruction.getOpObjects(operand)) {
|
|
42
|
-
|
|
43
|
-
|
|
48
|
+
Scalar scalar = OperandConstants.value(object, operandType);
|
|
49
|
+
if (scalar == null || !requested.contains(scalar.getUnsignedValue())) continue;
|
|
44
50
|
println(scalar.getUnsignedValue() + " at " + instruction.getAddress()
|
|
45
51
|
+ ": " + instruction);
|
|
46
52
|
if (++matches >= MAX_MATCHES) {
|
|
@@ -49,7 +55,6 @@ public class ReportFunctionScalarConstants extends GhidraScript {
|
|
|
49
55
|
}
|
|
50
56
|
}
|
|
51
57
|
}
|
|
52
|
-
instruction = instruction.getNext();
|
|
53
58
|
}
|
|
54
59
|
if (matches == 0) println("No requested scalar constants matched.");
|
|
55
60
|
}
|
|
@@ -24,7 +24,8 @@ public class ReportReferences extends GhidraScript {
|
|
|
24
24
|
println("===== references to " + target + " =====");
|
|
25
25
|
ReferenceIterator references = currentProgram.getReferenceManager().getReferencesTo(target);
|
|
26
26
|
int count = 0;
|
|
27
|
-
while (references.hasNext() && count < MAX_REFERENCES
|
|
27
|
+
while (references.hasNext() && count < MAX_REFERENCES) {
|
|
28
|
+
monitor.checkCancelled();
|
|
28
29
|
Reference reference = references.next();
|
|
29
30
|
Instruction instruction = currentProgram.getListing().getInstructionContaining(reference.getFromAddress());
|
|
30
31
|
Function function = currentProgram.getFunctionManager().getFunctionContaining(reference.getFromAddress());
|
|
@@ -38,5 +39,10 @@ public class ReportReferences extends GhidraScript {
|
|
|
38
39
|
if (count == 0) println("No references found.");
|
|
39
40
|
else if (count == MAX_REFERENCES && references.hasNext()) println("Output capped at " + MAX_REFERENCES + " references.");
|
|
40
41
|
}
|
|
42
|
+
|
|
43
|
+
// Ghidra types an indexed store such as MOV [EAX*4+table],ECX as DATA, and gives an indexed
|
|
44
|
+
// read-modify-write no reference at all, so the type column cannot answer "who writes this".
|
|
45
|
+
println("Types are Ghidra's reference types, not the access an instruction makes: DATA covers"
|
|
46
|
+
+ " indexed reads and writes and address formation. An operand Ghidra gave no reference is not listed.");
|
|
41
47
|
}
|
|
42
48
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
// Reports bounded instruction references to explicitly supplied scalar values, as immediates or
|
|
2
|
-
// inside memory operands (a displacement,
|
|
2
|
+
// inside memory operands (a displacement, an absolute address such as [0x41c000], or the scale of an
|
|
3
|
+
// index such as the 4 in [EBX + ECX*4]).
|
|
3
4
|
// @category Restoration
|
|
4
5
|
|
|
5
6
|
import ghidra.app.script.GhidraScript;
|
|
6
|
-
import ghidra.program.model.lang.OperandType;
|
|
7
7
|
import ghidra.program.model.listing.Function;
|
|
8
8
|
import ghidra.program.model.listing.Instruction;
|
|
9
9
|
import ghidra.program.model.listing.InstructionIterator;
|
|
@@ -12,6 +12,8 @@ import ghidra.program.model.scalar.Scalar;
|
|
|
12
12
|
import java.util.HashSet;
|
|
13
13
|
import java.util.Set;
|
|
14
14
|
|
|
15
|
+
import scientificmethod.OperandConstants;
|
|
16
|
+
|
|
15
17
|
public class ReportScalarConstants extends GhidraScript {
|
|
16
18
|
private static final int MAX_MATCHES = 300;
|
|
17
19
|
|
|
@@ -36,11 +38,12 @@ public class ReportScalarConstants extends GhidraScript {
|
|
|
36
38
|
monitor.checkCancelled();
|
|
37
39
|
Instruction instruction = instructions.next();
|
|
38
40
|
for (int operand = 0; operand < instruction.getNumOperands(); operand++) {
|
|
41
|
+
int operandType = instruction.getOperandType(operand);
|
|
39
42
|
String operandKind = null;
|
|
40
43
|
for (Object object : instruction.getOpObjects(operand)) {
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
if (operandKind == null) operandKind = operandKind(instruction
|
|
44
|
+
Scalar scalar = OperandConstants.value(object, operandType);
|
|
45
|
+
if (scalar == null || !matchesRequested(scalar, requested)) continue;
|
|
46
|
+
if (operandKind == null) operandKind = operandKind(instruction, operand);
|
|
44
47
|
if (kind != null && !kind.equals(operandKind)) break;
|
|
45
48
|
if (matches == MAX_MATCHES) {
|
|
46
49
|
println("Output capped at " + MAX_MATCHES + " matches; the search did not finish. "
|
|
@@ -61,12 +64,12 @@ public class ReportScalarConstants extends GhidraScript {
|
|
|
61
64
|
else println("Matched " + matches + " operands; the search covered every disassembled instruction.");
|
|
62
65
|
}
|
|
63
66
|
|
|
64
|
-
// Ghidra types
|
|
65
|
-
//
|
|
66
|
-
//
|
|
67
|
-
// [0x41c000]
|
|
68
|
-
private static String operandKind(int
|
|
69
|
-
return
|
|
67
|
+
// Ghidra's operand types do not tell the two kinds apart: LEA EAX,[0x41c000] and the 16-bit
|
|
68
|
+
// CALLF [0x1234] are SCALAR like an immediate, and the far direct target in CALLF 0x12:0x12345678
|
|
69
|
+
// is ADDRESS and CODE like an absolute memory operand. Ghidra writes every memory operand in
|
|
70
|
+
// brackets ([0x41c000], [ECX + 0x44], FS:[0x0]) and no immediate.
|
|
71
|
+
private static String operandKind(Instruction instruction, int operand) {
|
|
72
|
+
return instruction.getDefaultOperandRepresentation(operand).contains("[") ? "memory" : "immediate";
|
|
70
73
|
}
|
|
71
74
|
|
|
72
75
|
// Arguments are decoded as signed longs while operands are reported unsigned, so a request
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
package scientificmethod;
|
|
2
|
+
|
|
3
|
+
import ghidra.program.model.address.Address;
|
|
4
|
+
import ghidra.program.model.lang.OperandType;
|
|
5
|
+
import ghidra.program.model.scalar.Scalar;
|
|
6
|
+
|
|
7
|
+
/**
|
|
8
|
+
* The operand constant reading that ReportScalarConstants and ReportFunctionScalarConstants share, so
|
|
9
|
+
* both match the same operands. It lives in a package directory beside the scripts so that Ghidra
|
|
10
|
+
* compiles it with them and the Script Manager does not list it as a script.
|
|
11
|
+
*/
|
|
12
|
+
public final class OperandConstants {
|
|
13
|
+
private OperandConstants() {
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
/**
|
|
17
|
+
* The constant that one of an operand's objects encodes, or null when it encodes none. A
|
|
18
|
+
* displacement, scale or immediate is a Scalar, and so is each part of a far direct target such
|
|
19
|
+
* as CALLF 0x12:0x12345678. An absolute memory operand such as [0x41c000] holds its address as an
|
|
20
|
+
* Address. A near direct branch target is an Address too, but in a CODE operand: Ghidra computes
|
|
21
|
+
* it from a relative displacement, so it never matches.
|
|
22
|
+
*/
|
|
23
|
+
public static Scalar value(Object object, int operandType) {
|
|
24
|
+
if (object instanceof Scalar scalar) return scalar;
|
|
25
|
+
if (object instanceof Address address && !OperandType.isCodeReference(operandType))
|
|
26
|
+
return new Scalar(address.getSize(), address.getOffset(), false);
|
|
27
|
+
return null;
|
|
28
|
+
}
|
|
29
|
+
}
|
|
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-12.0.0 → scientific_method_engine-13.0.0}/tests/test_effect_order.py
RENAMED
|
File without changes
|
{scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_enter_frames.py
RENAMED
|
File without changes
|
{scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_entry_frame.py
RENAMED
|
File without changes
|
|
File without changes
|
{scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_interrupt_models.py
RENAMED
|
File without changes
|
|
File without changes
|
{scientific_method_engine-12.0.0 → scientific_method_engine-13.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-12.0.0 → scientific_method_engine-13.0.0}/tests/test_return_checks.py
RENAMED
|
File without changes
|
{scientific_method_engine-12.0.0 → scientific_method_engine-13.0.0}/tests/test_successor_rule.py
RENAMED
|
File without changes
|
|
File without changes
|
|
File without changes
|