scientific-method-engine 19.10.1__tar.gz → 21.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.
Files changed (97) hide show
  1. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/PKG-INFO +6 -4
  2. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/README.md +3 -1
  3. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/pyproject.toml +2 -2
  4. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ExportFunctionInventory.java +176 -10
  5. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/image.py +1 -1
  6. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/inventory.py +17 -4
  7. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_inventory_check.py +14 -1
  8. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_x86.py +6 -4
  9. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/.gitignore +0 -0
  10. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/LICENSE +0 -0
  11. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/__init__.py +0 -0
  12. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/__main__.py +0 -0
  13. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/cli.py +0 -0
  14. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ClearNoReturnFunctions.java +0 -0
  15. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/CreateFunctions.java +0 -0
  16. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ExportBoundedFlow.java +0 -0
  17. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ExportCallEdges.java +0 -0
  18. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ExportFunctionFingerprints.java +0 -0
  19. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/MergeFallThroughFragment.java +0 -0
  20. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/RecoverCitedFunctions.java +0 -0
  21. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/RepairReturningCallers.java +0 -0
  22. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportCallArguments.java +0 -0
  23. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportCallPaths.java +0 -0
  24. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportCallSitesWithScalars.java +0 -0
  25. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportCallsToRange.java +0 -0
  26. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportConstantFirstArgumentCalls.java +0 -0
  27. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportDataBytes.java +0 -0
  28. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportDecompileMatches.java +0 -0
  29. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportDecompileWindow.java +0 -0
  30. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportFilePatternInMemory.java +0 -0
  31. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportFirstArgumentCallSummary.java +0 -0
  32. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportFunctionScalarConstants.java +0 -0
  33. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportFunctionSummary.java +0 -0
  34. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportInstructionContext.java +0 -0
  35. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportInstructionWindow.java +0 -0
  36. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportMemoryBlockForFileOffset.java +0 -0
  37. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportMemoryBlocks.java +0 -0
  38. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportRandomnessCandidates.java +0 -0
  39. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportRangeBoundaries.java +0 -0
  40. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportReferences.java +0 -0
  41. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportScalarConstants.java +0 -0
  42. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportStringReferences.java +0 -0
  43. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/ReportSymbolReferences.java +0 -0
  44. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/RunQueryPlan.java +0 -0
  45. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/scientificmethod/FirstArgumentLookBack.java +0 -0
  46. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/scientificmethod/InstructionStart.java +0 -0
  47. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/scientificmethod/OperandConstants.java +0 -0
  48. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/scientificmethod/QueryBatch.java +0 -0
  49. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/ghidra/scientificmethod/Xxh3.java +0 -0
  50. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/__init__.py +0 -0
  51. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/argument_frames.py +0 -0
  52. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/derived_counts.py +0 -0
  53. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/dispatch.py +0 -0
  54. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/effect_order.py +0 -0
  55. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/loops.py +0 -0
  56. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/machine.py +0 -0
  57. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/memory_scopes.py +0 -0
  58. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/pcode.py +0 -0
  59. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/pcode_backend.py +0 -0
  60. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/pe.py +0 -0
  61. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/ranges.py +0 -0
  62. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/reach.py +0 -0
  63. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/relational.py +0 -0
  64. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/reports.py +0 -0
  65. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/result_flow.py +0 -0
  66. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/scan_index.py +0 -0
  67. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/table_bounds.py +0 -0
  68. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/trace.py +0 -0
  69. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/src/scientific_method_engine/x86/values.py +0 -0
  70. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/java/QueryBatchHarness.java +0 -0
  71. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/oracle.py +0 -0
  72. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_config_encoding.py +0 -0
  73. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_continuation_budget.py +0 -0
  74. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_derived_counts.py +0 -0
  75. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_dispatch.py +0 -0
  76. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_effect_order.py +0 -0
  77. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_enter_frames.py +0 -0
  78. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_entry_frame.py +0 -0
  79. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_indirect_far_transfers.py +0 -0
  80. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_interrupt_models.py +0 -0
  81. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_join_terms.py +0 -0
  82. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_loops.py +0 -0
  83. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_memory_scopes.py +0 -0
  84. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_nested_frame_request.py +0 -0
  85. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_oracle.py +0 -0
  86. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_pe.py +0 -0
  87. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_ranges.py +0 -0
  88. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_reach.py +0 -0
  89. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_relational_controls.py +0 -0
  90. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_return_checks.py +0 -0
  91. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_scan_index.py +0 -0
  92. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_successor_rule.py +0 -0
  93. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_table_bounds.py +0 -0
  94. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_table_continuations.py +0 -0
  95. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_term_limit.py +0 -0
  96. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_upstream_gaps.py +0 -0
  97. {scientific_method_engine-19.10.1 → scientific_method_engine-21.0.0}/tests/test_volatile_memory.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: scientific-method-engine
3
- Version: 19.10.1
3
+ Version: 21.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
@@ -8,8 +8,8 @@ License-Expression: MIT
8
8
  License-File: LICENSE
9
9
  Requires-Python: >=3.12
10
10
  Requires-Dist: capstone==5.0.9
11
- Requires-Dist: pypcode==4.0.1
12
- Requires-Dist: xxhash==4.0.1
11
+ Requires-Dist: pypcode==4.1.0
12
+ Requires-Dist: xxhash==4.1.0
13
13
  Provides-Extra: test
14
14
  Requires-Dist: unicorn==2.1.4; extra == 'test'
15
15
  Description-Content-Type: text/markdown
@@ -20,6 +20,8 @@ Bounded instruction-derived x86 evidence reports for segmented 16-bit MZ/FBOV co
20
20
  PE32/i386 code. The engine decodes instructions with Capstone, takes their values, flags and
21
21
  branch conditions from Ghidra's SLEIGH specification through pypcode, follows bounded paths and
22
22
  emits `bounded-x86-v1` JSON. It never runs the original program. It needs Python 3.12 or later.
23
+ It pins `capstone==5.0.9`, `pypcode==4.1.0` and `xxhash==4.1.0`, because reports depend on the
24
+ decoder, and refuses to build a report under any other Capstone or pypcode.
23
25
 
24
26
  ```sh
25
27
  uv add --group research scientific-method-engine # or: pip install scientific-method-engine
@@ -96,7 +98,7 @@ Exporting for comparison (each writes one file and refuses to overwrite where no
96
98
  | Script | Arguments | Writes |
97
99
  |---|---|---|
98
100
  | `ExportBoundedFlow` | entry where an instruction starts, instruction limit (1..10000, the most instruction records exported), output path under `analysis/original/` | instruction metadata of one bounded flow as JSON, with `limitReached` (the walk stopped at the limit with flow left unread) and `noInstruction` (flow targets where no instruction starts). An entry where no instruction starts fails the script and writes nothing |
99
- | `ExportFunctionInventory` | output path `coverage/<build>/<file>.tsv` (must not exist, nor its `.provenance.tsv` and `.regions.tsv`), identifier of the database snapshot the export reads | the function inventory that `standard-coverage` and `inventory-check` read: each function's start in the Standard's notation, its body size and, for a body that is not one range from the start, its ranges; and beside it a `.provenance.tsv` with the imported file's `xxh3` and SHA-256, the Ghidra version, the snapshot and the SHA-256 of the script and of its Xxh3 helper; and a `.regions.tsv` that counts the instruction, defined-data and undefined bytes of each executable block, in all and outside every body, with rows for body bytes outside those blocks and for starts where no instruction starts. A body or executable block it cannot place in the notation fails the export, which then writes nothing ([Exporting a function inventory](https://github.com/kibertoad/refurbished-dinosaurs-toolkit/blob/main/docs/ghidra-workflow.md#exporting-a-function-inventory)) |
101
+ | `ExportFunctionInventory` | output path `coverage/<build>/<file>.tsv` (must not exist, nor its `.provenance.tsv` and `.regions.tsv`), identifier of the database snapshot the export reads, and optionally the previous inventory, moved aside, whose annotations it carries over | the function inventory that `standard-coverage` and `inventory-check` read, with the work protocol's seven columns: each function's start in the Standard's notation, its body size and, for a body that is not one range from the start, its ranges, with the name, out-of-scope reason and lift state the previous inventory gave its start (the lift state only where the body is unchanged, otherwise `none`); and beside it a `.provenance.tsv` with the imported file's `xxh3` and SHA-256, the Ghidra version, the snapshot and the SHA-256 of the script and of its Xxh3 helper; and a `.regions.tsv` that counts the instruction, defined-data and undefined bytes of each executable block, in all and outside every body, with rows for body bytes outside those blocks and for starts where no instruction starts. A body or executable block it cannot place in the notation fails the export, which then writes nothing ([Exporting a function inventory](https://github.com/kibertoad/refurbished-dinosaurs-toolkit/blob/main/docs/ghidra-workflow.md#exporting-a-function-inventory)) |
100
102
  | `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` |
101
103
  | `RunQueryPlan` | local v1 plan JSON, new ignored output directory | one required source/project audit and 1..31 bounded read-only target queries in one loaded program; source/import SHA-256 checks, script fingerprints, per-target completion/rejection controls and explicit failed/limited/cancelled/not-run dispositions; see [query plans](https://github.com/kibertoad/refurbished-dinosaurs-toolkit/blob/main/docs/query-plans.md) |
102
104
  | `ExportFunctionFingerprints` | output TSV path (replaced only when the export completes) | per-function and per-instruction fingerprints with addresses normalized, for matching functions across versions |
@@ -4,6 +4,8 @@ Bounded instruction-derived x86 evidence reports for segmented 16-bit MZ/FBOV co
4
4
  PE32/i386 code. The engine decodes instructions with Capstone, takes their values, flags and
5
5
  branch conditions from Ghidra's SLEIGH specification through pypcode, follows bounded paths and
6
6
  emits `bounded-x86-v1` JSON. It never runs the original program. It needs Python 3.12 or later.
7
+ It pins `capstone==5.0.9`, `pypcode==4.1.0` and `xxhash==4.1.0`, because reports depend on the
8
+ decoder, and refuses to build a report under any other Capstone or pypcode.
7
9
 
8
10
  ```sh
9
11
  uv add --group research scientific-method-engine # or: pip install scientific-method-engine
@@ -80,7 +82,7 @@ Exporting for comparison (each writes one file and refuses to overwrite where no
80
82
  | Script | Arguments | Writes |
81
83
  |---|---|---|
82
84
  | `ExportBoundedFlow` | entry where an instruction starts, instruction limit (1..10000, the most instruction records exported), output path under `analysis/original/` | instruction metadata of one bounded flow as JSON, with `limitReached` (the walk stopped at the limit with flow left unread) and `noInstruction` (flow targets where no instruction starts). An entry where no instruction starts fails the script and writes nothing |
83
- | `ExportFunctionInventory` | output path `coverage/<build>/<file>.tsv` (must not exist, nor its `.provenance.tsv` and `.regions.tsv`), identifier of the database snapshot the export reads | the function inventory that `standard-coverage` and `inventory-check` read: each function's start in the Standard's notation, its body size and, for a body that is not one range from the start, its ranges; and beside it a `.provenance.tsv` with the imported file's `xxh3` and SHA-256, the Ghidra version, the snapshot and the SHA-256 of the script and of its Xxh3 helper; and a `.regions.tsv` that counts the instruction, defined-data and undefined bytes of each executable block, in all and outside every body, with rows for body bytes outside those blocks and for starts where no instruction starts. A body or executable block it cannot place in the notation fails the export, which then writes nothing ([Exporting a function inventory](https://github.com/kibertoad/refurbished-dinosaurs-toolkit/blob/main/docs/ghidra-workflow.md#exporting-a-function-inventory)) |
85
+ | `ExportFunctionInventory` | output path `coverage/<build>/<file>.tsv` (must not exist, nor its `.provenance.tsv` and `.regions.tsv`), identifier of the database snapshot the export reads, and optionally the previous inventory, moved aside, whose annotations it carries over | the function inventory that `standard-coverage` and `inventory-check` read, with the work protocol's seven columns: each function's start in the Standard's notation, its body size and, for a body that is not one range from the start, its ranges, with the name, out-of-scope reason and lift state the previous inventory gave its start (the lift state only where the body is unchanged, otherwise `none`); and beside it a `.provenance.tsv` with the imported file's `xxh3` and SHA-256, the Ghidra version, the snapshot and the SHA-256 of the script and of its Xxh3 helper; and a `.regions.tsv` that counts the instruction, defined-data and undefined bytes of each executable block, in all and outside every body, with rows for body bytes outside those blocks and for starts where no instruction starts. A body or executable block it cannot place in the notation fails the export, which then writes nothing ([Exporting a function inventory](https://github.com/kibertoad/refurbished-dinosaurs-toolkit/blob/main/docs/ghidra-workflow.md#exporting-a-function-inventory)) |
84
86
  | `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` |
85
87
  | `RunQueryPlan` | local v1 plan JSON, new ignored output directory | one required source/project audit and 1..31 bounded read-only target queries in one loaded program; source/import SHA-256 checks, script fingerprints, per-target completion/rejection controls and explicit failed/limited/cancelled/not-run dispositions; see [query plans](https://github.com/kibertoad/refurbished-dinosaurs-toolkit/blob/main/docs/query-plans.md) |
86
88
  | `ExportFunctionFingerprints` | output TSV path (replaced only when the export completes) | per-function and per-instruction fingerprints with addresses normalized, for matching functions across versions |
@@ -5,13 +5,13 @@ 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 = "19.10.1"
8
+ version = "21.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"
12
12
  license = "MIT"
13
13
  authors = [{ name = "kibertoad" }]
14
- dependencies = ["capstone==5.0.9", "pypcode==4.0.1", "xxhash==4.0.1"]
14
+ dependencies = ["capstone==5.0.9", "pypcode==4.1.0", "xxhash==4.1.0"]
15
15
 
16
16
  [project.optional-dependencies]
17
17
  # Unicorn is the tests' concrete oracle (ADR 0003, decision 4). Its core is GPLv2, so it never
@@ -1,4 +1,4 @@
1
- // Exports every function's start, size and body ranges in the Standard's notation, with provenance and regions files.
1
+ // Exports every function's start, size and body ranges in the Standard's notation, with provenance and regions files, carrying over a previous inventory's annotations.
2
2
  // @category Restoration
3
3
 
4
4
  import java.io.BufferedWriter;
@@ -56,10 +56,12 @@ public class ExportFunctionInventory extends GhidraScript {
56
56
  @Override
57
57
  protected void run() throws Exception {
58
58
  String[] arguments = getScriptArgs();
59
- if (arguments.length != 2) {
59
+ if (arguments.length != 2 && arguments.length != 3) {
60
60
  throw new IllegalArgumentException(
61
- "Supply the output inventory path, ending in .tsv, and the identifier of the database snapshot it reads.");
61
+ "Supply the output inventory path, ending in .tsv, the identifier of the database snapshot it reads,"
62
+ + " and optionally the previous inventory whose annotations it carries over.");
62
63
  }
64
+ PreviousInventory previous = arguments.length == 3 ? readPrevious(Path.of(arguments[2])) : null;
63
65
  Path output = Path.of(arguments[0]).toAbsolutePath().normalize();
64
66
  String name = output.getFileName().toString();
65
67
  if (!name.endsWith(".tsv") || name.endsWith(".provenance.tsv") || name.endsWith(".regions.tsv")) {
@@ -87,11 +89,16 @@ public class ExportFunctionInventory extends GhidraScript {
87
89
 
88
90
  notation = notation();
89
91
  Map<String, String> source = provenance(snapshot);
92
+ if (previous != null) {
93
+ // The lift revisions say which generator, checker and harness the lift states were checked
94
+ // with, so they go with the states that are carried over.
95
+ source.putAll(previous.liftProvenance());
96
+ }
90
97
 
91
98
  // Every row is built before anything is written, so a function that cannot be placed refuses
92
99
  // the whole export and no inventory with a smaller denominator appears.
93
100
  Memory memory = currentProgram.getMemory();
94
- List<String> rows = new ArrayList<>();
101
+ List<Row> rows = new ArrayList<>();
95
102
  Map<String, Address> starts = new LinkedHashMap<>();
96
103
  AddressSet bodies = new AddressSet();
97
104
  List<Address> entries = new ArrayList<>();
@@ -144,10 +151,11 @@ public class ExportFunctionInventory extends GhidraScript {
144
151
  ranges = String.join(" ", written);
145
152
  withRanges++;
146
153
  }
147
- rows.add(first.startText() + "\t" + size + "\t" + ranges);
154
+ rows.add(new Row(first.startText(), size, ranges));
148
155
  bytes += size;
149
156
  }
150
157
 
158
+ List<String> lines = annotate(rows, previous);
151
159
  List<String> regionRows = regionRows(memory, bodies, entries);
152
160
 
153
161
  if (!problems.isEmpty()) {
@@ -158,7 +166,7 @@ public class ExportFunctionInventory extends GhidraScript {
158
166
  printerr("Output stopped after " + MAX_PROBLEM_LINES + " of " + problems.size() + " problems.");
159
167
  }
160
168
  throw new IllegalStateException((problems.size() == 1 ? "1 problem keeps" : problems.size() + " problems keep")
161
- + " the inventory and its regions from being written in the Standard's notation. Nothing was written.");
169
+ + " the inventory and its regions from being written. Nothing was written.");
162
170
  }
163
171
 
164
172
  Files.createDirectories(output.getParent());
@@ -170,9 +178,9 @@ public class ExportFunctionInventory extends GhidraScript {
170
178
  provenancePart = Files.createTempFile(output.getParent(), "provenance-", ".partial");
171
179
  regionsPart = Files.createTempFile(output.getParent(), "regions-", ".partial");
172
180
  try (BufferedWriter writer = Files.newBufferedWriter(inventoryPart, StandardCharsets.UTF_8)) {
173
- writer.write("start\tsize\tranges\n");
174
- for (String row : rows) {
175
- writer.write(row);
181
+ writer.write(String.join("\t", COLUMNS) + "\n");
182
+ for (String line : lines) {
183
+ writer.write(line);
176
184
  writer.write('\n');
177
185
  }
178
186
  }
@@ -218,7 +226,165 @@ public class ExportFunctionInventory extends GhidraScript {
218
226
  }
219
227
  println("Exported " + rows.size() + " functions with " + bytes + " body bytes, " + withRanges
220
228
  + " of them with a ranges column, to " + output + ", their provenance to " + provenance + ", and "
221
- + regionRows.size() + " region and anomaly rows to " + regions);
229
+ + regionRows.size() + " region and anomaly rows to " + regions
230
+ + (previous == null ? "" : ". From " + previous.path() + " it carried over the annotations of "
231
+ + carried + " functions and reset the lift state of " + reset + " whose body changed"));
232
+ }
233
+
234
+ /** The inventory's columns, in the order the work protocol gives them. */
235
+ private static final List<String> COLUMNS =
236
+ List.of("start", "size", "name", "out_of_scope", "ranges", "lift", "lift_reason");
237
+
238
+ /** The lift states a previous inventory may give. */
239
+ private static final List<String> LIFT_STATES = List.of("none", "lifted", "verified", "stuck", "excluded");
240
+
241
+ /** The lift states whose row gives a reason in lift_reason. */
242
+ private static final List<String> LIFT_STATES_WITH_REASON = List.of("stuck", "excluded");
243
+
244
+ /** One exported function before its annotations are added. */
245
+ private record Row(String start, long size, String ranges) {
246
+ }
247
+
248
+ /** One row of a previous inventory: its body as written, and the annotations a researcher gave it. */
249
+ private record Annotation(String size, String ranges, String name, String outOfScope, String lift,
250
+ String liftReason) {
251
+ /** Whether a researcher wrote anything into the row. */
252
+ boolean annotated() {
253
+ return !name.isEmpty() || !outOfScope.isEmpty() || !lift.equals("none");
254
+ }
255
+ }
256
+
257
+ /** A previous inventory: its path, its rows by start, and the lift lines of its provenance file. */
258
+ private record PreviousInventory(Path path, Map<String, Annotation> rows, Map<String, String> liftProvenance) {
259
+ }
260
+
261
+ private long carried;
262
+ private long reset;
263
+
264
+ /**
265
+ * Reads the inventory a new export replaces. Its first line names its columns, start and size first,
266
+ * then any of name, out_of_scope, ranges, lift and lift_reason. A row without a lift column has the
267
+ * state none. The provenance file beside it, if there is one, gives the lift_ lines the new provenance
268
+ * keeps.
269
+ */
270
+ private PreviousInventory readPrevious(Path path) throws Exception {
271
+ Path file = path.toAbsolutePath().normalize();
272
+ if (!Files.isRegularFile(file) || Files.size(file) > MAX_FILE) {
273
+ throw new IllegalArgumentException("The previous inventory must be a regular file of at most 256 MiB: " + file);
274
+ }
275
+ List<String> text = Files.readAllLines(file, StandardCharsets.UTF_8);
276
+ while (!text.isEmpty() && text.get(text.size() - 1).isEmpty()) {
277
+ text.remove(text.size() - 1);
278
+ }
279
+ if (text.isEmpty()) {
280
+ throw new IllegalArgumentException("The previous inventory has no header line: " + file);
281
+ }
282
+ List<String> columns = List.of(text.get(0).replace("\uFEFF", "").split("\t", -1));
283
+ if (columns.size() < 2 || !columns.get(0).equals("start") || !columns.get(1).equals("size")
284
+ || !COLUMNS.containsAll(columns) || columns.stream().distinct().count() != columns.size()) {
285
+ throw new IllegalArgumentException("The previous inventory's columns are not start and size, then any of"
286
+ + " name, out_of_scope, ranges, lift and lift_reason, each once: " + file);
287
+ }
288
+ if (columns.contains("lift_reason") && !columns.contains("lift")) {
289
+ throw new IllegalArgumentException("The previous inventory has a lift_reason column without a lift column: "
290
+ + file);
291
+ }
292
+ Map<String, Annotation> rows = new LinkedHashMap<>();
293
+ for (int k = 1; k < text.size(); k++) {
294
+ String[] cells = text.get(k).split("\t", -1);
295
+ if (cells.length != columns.size()) {
296
+ throw new IllegalArgumentException("Line " + (k + 1) + " of the previous inventory has " + cells.length
297
+ + " cells, not " + columns.size() + ": " + file);
298
+ }
299
+ Map<String, String> cell = new LinkedHashMap<>();
300
+ for (int c = 0; c < cells.length; c++) {
301
+ cell.put(columns.get(c), cells[c].trim());
302
+ }
303
+ String lift = cell.getOrDefault("lift", "none");
304
+ if (!LIFT_STATES.contains(lift)) {
305
+ throw new IllegalArgumentException("Line " + (k + 1) + " of the previous inventory gives the lift state "
306
+ + (lift.isEmpty() ? "(empty)" : lift) + ", which is not one of " + String.join(", ", LIFT_STATES) + ": " + file);
307
+ }
308
+ // The checkers refuse a state with a reason it does not take, or without one it needs, so such a
309
+ // row is refused here rather than carried into an inventory they cannot read.
310
+ boolean needsReason = LIFT_STATES_WITH_REASON.contains(lift);
311
+ if (needsReason == cell.getOrDefault("lift_reason", "").isEmpty()) {
312
+ throw new IllegalArgumentException("Line " + (k + 1) + " of the previous inventory gives the lift state "
313
+ + lift + (needsReason ? " with no reason in lift_reason" : " with a reason in lift_reason, which only"
314
+ + " stuck and excluded take") + ": " + file);
315
+ }
316
+ if (!cell.get("size").matches("[1-9][0-9]*")) {
317
+ throw new IllegalArgumentException("Line " + (k + 1) + " of the previous inventory gives the size "
318
+ + cell.get("size") + ", which is not a positive number of bytes: " + file);
319
+ }
320
+ Annotation row = new Annotation(cell.get("size"), cell.getOrDefault("ranges", ""), cell.getOrDefault("name", ""),
321
+ cell.getOrDefault("out_of_scope", ""), lift, cell.getOrDefault("lift_reason", ""));
322
+ if (rows.putIfAbsent(cell.get("start"), row) != null) {
323
+ throw new IllegalArgumentException("The previous inventory lists " + cell.get("start") + " twice: " + file);
324
+ }
325
+ }
326
+ Map<String, String> liftProvenance = new LinkedHashMap<>();
327
+ String name = file.getFileName().toString();
328
+ Path side = name.endsWith(".tsv")
329
+ ? file.resolveSibling(name.substring(0, name.length() - 4) + ".provenance.tsv") : null;
330
+ if (side != null && Files.isRegularFile(side)) {
331
+ for (String line : Files.readAllLines(side, StandardCharsets.UTF_8)) {
332
+ String[] pair = line.split("\t", 2);
333
+ if (pair.length == 2 && pair[0].startsWith("lift_")) {
334
+ liftProvenance.put(pair[0], pair[1]);
335
+ }
336
+ }
337
+ } else if (rows.values().stream().anyMatch(row -> !row.lift().equals("none"))) {
338
+ // The lift states are carried over, but the revisions they were checked with are not.
339
+ printerr("The previous inventory gives lift states, but no provenance file "
340
+ + (side == null ? "beside it, since its name does not end in .tsv" : side.toString())
341
+ + " gives the lift_ lines the states were checked with, so the new provenance has none.");
342
+ }
343
+ return new PreviousInventory(file, rows, liftProvenance);
344
+ }
345
+
346
+ /**
347
+ * The inventory's lines with the previous inventory's annotations. A row keeps the name and the reason
348
+ * it is out of scope that the previous inventory gives its start. It keeps the lift state and reason
349
+ * only where its size and ranges are as before, since a lifted function translated other code where
350
+ * the body changed, and otherwise has the state none. A previous row with an annotation and a start
351
+ * no exported function has is a problem: the work protocol asks for it to be reconciled before the
352
+ * new inventory replaces the old.
353
+ */
354
+ private List<String> annotate(List<Row> rows, PreviousInventory previous) {
355
+ List<String> lines = new ArrayList<>();
356
+ Map<String, Annotation> unmatched = new LinkedHashMap<>(previous == null ? Map.of() : previous.rows());
357
+ for (Row row : rows) {
358
+ Annotation before = unmatched.remove(row.start());
359
+ String name = "";
360
+ String outOfScope = "";
361
+ String lift = "none";
362
+ String liftReason = "";
363
+ if (before != null) {
364
+ name = before.name();
365
+ outOfScope = before.outOfScope();
366
+ if (before.size().equals(Long.toString(row.size())) && before.ranges().equals(row.ranges())) {
367
+ lift = before.lift();
368
+ liftReason = before.liftReason();
369
+ } else if (!before.lift().equals("none")) {
370
+ reset++;
371
+ }
372
+ // A row whose only annotation was a lift state that was reset carried nothing over.
373
+ if (!name.isEmpty() || !outOfScope.isEmpty() || !lift.equals("none")) {
374
+ carried++;
375
+ }
376
+ }
377
+ lines.add(String.join("\t", row.start(), Long.toString(row.size()), name, outOfScope, row.ranges(), lift,
378
+ liftReason));
379
+ }
380
+ for (Map.Entry<String, Annotation> gone : unmatched.entrySet()) {
381
+ if (gone.getValue().annotated()) {
382
+ problems.add("The previous inventory annotates the function at " + gone.getKey()
383
+ + ", which no function starts at now. Reconcile its name, out-of-scope reason or lift state in"
384
+ + " the previous inventory, as the work protocol asks, and export again.");
385
+ }
386
+ }
387
+ return lines;
222
388
  }
223
389
 
224
390
  /** The Standard's address notation for this program, or an exception naming why it has none here. */
@@ -24,7 +24,7 @@ REQUIRED_CAPSTONE = "5.0.9"
24
24
  # The engine's rules for which flags to keep are checked against this SLEIGH specification, such as
25
25
  # the OF of SHR, which pypcode 4.0.0 writes as 0 where 4.0.1 writes the CPU's value.
26
26
  PYPCODE_VERSION = pypcode.__version__
27
- REQUIRED_PYPCODE = "4.0.1"
27
+ REQUIRED_PYPCODE = "4.1.0"
28
28
  MAX_SOURCE = 256 * 1024 * 1024
29
29
  XXH3_FORM = re.compile("[0-9a-f]{32}")
30
30
 
@@ -8,7 +8,10 @@ from .dispatch import indirect_call_declarations, call_ends, never_runs, indirec
8
8
 
9
9
  MAX_INVENTORY = 16 * 1024 * 1024
10
10
  MAX_ROWS = 200000
11
- COLUMNS = ("start", "size", "name", "out_of_scope", "ranges")
11
+ COLUMNS = ("start", "size", "name", "out_of_scope", "ranges", "lift", "lift_reason")
12
+ # The work protocol's lift states, and those whose row gives a reason in lift_reason.
13
+ LIFT_STATES = ("none", "lifted", "verified", "stuck", "excluded")
14
+ LIFT_STATES_WITH_REASON = ("stuck", "excluded")
12
15
  SEGMENTED = re.compile(r"[0-9A-F]{4}:[0-9A-F]{4}")
13
16
  FLAT = re.compile(r"0x[0-9A-F]{8}")
14
17
  OFFSET = re.compile(r"0x[0-9A-F]{2,}")
@@ -37,8 +40,8 @@ def _place(value, image):
37
40
 
38
41
 
39
42
  def read_inventory(path, image):
40
- """The rows of a function inventory TSV (``start``, ``size``, then optionally ``name``, ``out_of_scope``
41
- and ``ranges``), each with its ``space``, ``at`` and half-open ``body`` ranges. Raises ``ValueError``
43
+ """The rows of a function inventory TSV (``start``, ``size``, then optionally ``name``, ``out_of_scope``,
44
+ ``ranges``, ``lift`` and ``lift_reason``), each with its ``space``, ``at`` and half-open ``body`` ranges. Raises ``ValueError``
42
45
  naming the line of the first row that does not parse. ``path`` must be absolute: the CLI resolves a
43
46
  config's relative ``inventory`` against the config file's directory, and a library caller resolves
44
47
  it the same way, so no path is read against the process's working directory."""
@@ -53,7 +56,10 @@ def read_inventory(path, image):
53
56
  lines = re.split(r"\r?\n", text)
54
57
  columns = lines[0].split("\t")
55
58
  if columns[:2] != ["start", "size"] or len(set(columns)) != len(columns) or not set(columns) <= set(COLUMNS):
56
- raise ValueError("inventory columns are start and size, then optionally name, out_of_scope and ranges, each once")
59
+ raise ValueError("inventory columns are start and size, then optionally name, out_of_scope, ranges, lift and "
60
+ "lift_reason, each once")
61
+ if "lift_reason" in columns and "lift" not in columns:
62
+ raise ValueError("inventory has a lift_reason column without a lift column")
57
63
  if len(lines) - 1 > MAX_ROWS:
58
64
  raise ValueError(f"inventory holds more than {MAX_ROWS} rows")
59
65
  rows, starts = [], set()
@@ -67,6 +73,13 @@ def read_inventory(path, image):
67
73
  if not re.fullmatch(r"[1-9][0-9]*", cell["size"]):
68
74
  raise bad(f"size {cell['size']} is not a positive number of bytes")
69
75
  size = int(cell["size"])
76
+ if "lift" in cell:
77
+ reason = cell.get("lift_reason", "")
78
+ if cell["lift"] not in LIFT_STATES:
79
+ raise bad(f"lift {cell['lift'] or '(empty)'} is not one of {', '.join(LIFT_STATES)}")
80
+ if (cell["lift"] in LIFT_STATES_WITH_REASON) != bool(reason):
81
+ raise bad(f"lift {cell['lift']} gives no reason in lift_reason" if not reason else
82
+ f"lift {cell['lift']} gives a reason in lift_reason, which only stuck and excluded take")
70
83
  place = _place(cell["start"], image)
71
84
  if place is None:
72
85
  raise bad(f"start {cell['start']} is not an address in the notation of a "
@@ -596,6 +596,14 @@ class InventoryCheckTests(unittest.TestCase):
596
596
  self.assertEqual(ended["assumptions"][0], "each reached call returns to its next instruction, except an "
597
597
  "indirect call declared never to run")
598
598
 
599
+ def test_the_lift_columns_are_read_and_change_no_target(self):
600
+ text = ("start\tsize\tname\tout_of_scope\tranges\tlift\tlift_reason\n"
601
+ "1000:0000\t6\t\t\t\tverified\t\n"
602
+ "1000:0006\t1\t\t\t\tstuck\twrites code it then runs\n"
603
+ "1000:000B\t1\t\t\t\tnone\t\n")
604
+ plain = "start\tsize\n1000:0000\t6\n1000:0006\t1\n1000:000B\t1\n"
605
+ self.assertEqual(self.check(text)["targets"], self.check(plain)["targets"])
606
+
599
607
  def test_a_missed_control_and_a_malformed_inventory_are_refused(self):
600
608
  with self.assertRaisesRegex(ValueError, "Positive control 12 missed"):
601
609
  self.check("start\tsize\n1000:0000\t6\n", data=RAW, controls=[12])
@@ -604,7 +612,12 @@ class InventoryCheckTests(unittest.TestCase):
604
612
  ("start\tsize\n1000:0000\t6\n1000:0000\t2\n", "line 3: start 1000:0000 is listed twice"),
605
613
  ("start\tsize\nmain\t6\n", "line 2: start main is not an address"),
606
614
  ("start\tsize\tranges\n1000:0000\t5\t1000:0000..1000:0006\n", "line 2: size 5 is not the total"),
607
- ("start\tsize\n1000:0000\n", "line 2: has 1 cells")):
615
+ ("start\tsize\n1000:0000\n", "line 2: has 1 cells"),
616
+ ("start\tsize\tlift_reason\n1000:0000\t6\t\n", "lift_reason column without a lift column"),
617
+ ("start\tsize\tlift\n1000:0000\t6\tdone\n", "line 2: lift done is not one of"),
618
+ ("start\tsize\tlift\tlift_reason\n1000:0000\t6\tstuck\t\n", "line 2: lift stuck gives no reason"),
619
+ ("start\tsize\tlift\tlift_reason\n1000:0000\t6\tverified\tchecked\n",
620
+ "line 2: lift verified gives a reason")):
608
621
  with self.subTest(text=text):
609
622
  with self.assertRaisesRegex(ValueError, message):
610
623
  self.check(text)
@@ -4,6 +4,7 @@ import itertools
4
4
  import json
5
5
  import os
6
6
  from pathlib import Path
7
+ import re
7
8
  import subprocess
8
9
  import sys
9
10
  import tempfile
@@ -2992,13 +2993,14 @@ class ReporterTests(unittest.TestCase):
2992
2993
  self.assertIsNone(image_module.installed("capstone"))
2993
2994
 
2994
2995
  def test_pypcode_guard_refuses_another_sleigh_specification(self):
2995
- # Which flags the engine keeps after a shift is checked against pypcode 4.0.1's SLEIGH files;
2996
+ # Which flags the engine keeps after a shift is checked against pypcode 4.1.0's SLEIGH files;
2996
2997
  # pypcode 4.0.0 writes the OF of SHR by one as 0.
2997
2998
  self.assertEqual(image_module.PYPCODE_VERSION, image_module.REQUIRED_PYPCODE)
2998
2999
  data = bytes.fromhex("c3")
2999
- with mock.patch.object(image_module, "PYPCODE_VERSION", "4.0.0"):
3000
- with self.assertRaisesRegex(ValueError, r"requires pypcode==4\.0\.1; pypcode 4\.0\.0 is installed"):
3001
- Image(data, configuration(data))
3000
+ for other in ("4.0.0", "4.0.1"):
3001
+ with self.subTest(pypcode=other), mock.patch.object(image_module, "PYPCODE_VERSION", other):
3002
+ with self.assertRaisesRegex(ValueError, rf"requires pypcode==4\.1\.0; pypcode {re.escape(other)} is installed"):
3003
+ Image(data, configuration(data))
3002
3004
 
3003
3005
  def test_cli_identity_and_errors(self):
3004
3006
  with tempfile.TemporaryDirectory() as folder: