From e1dddb3ec0dd9a387dfa23169389ec9c688e7eb4 Mon Sep 17 00:00:00 2001
From: d-millar <33498836+d-millar@users.noreply.github.com>
Date: Wed, 3 Jun 2026 15:10:39 +0000
Subject: [PATCH] GP-6921: from GP-X
GP-6921: stashed changes
GP-6921: basic plugin
GP-6921: viable plugin
GP-6921: tags
GP-6921: bug fix
GP-6921: NPE
GP-6921: minor mods
GP-6921: aisle 9
GP-6921: working the bugs...
GP-6921: close to previous script results
GP-6921: intermediate stuff
GP-6921: mostly working
GP-6921: building struct
GP-6921: better action names
GP-6921: suggestions
GP-6921: better messaging
GP-6921: start on docs
GP-6921: docs
GP-6921: doc edits
GP-6921: one more suggestion pass
GP-6921: better conflict resolution
GP-6921: shrink
GP-6921: matching
GP-6921: more options; include offset equals
GP-6921: more options; include offset equals
GP-6921: from review (ongoing)
GP-6921: one more...
GP-6921: actions
GP-6921: from review...
GP-6921: temp
GP-6921: bookmarks?
GP-6921: tag -> bkmk
GP-6921: tag -> bkmk (pt2)
GP-6921: merge?
GP-6921: pinning mod
GP-6921: revert
GP-6921: revert
GP-6921: post-review
GP-6921: skip merge
GP-6921: finally
GP-6921: and release
GP-6921: mo' betta
GP-6921: mo' betta
GP-6921: mo' betta
GP-6921: typo
GP-6921: help oops
GP-6921: help oops
---
Ghidra/Features/BSim/certification.manifest | 1 +
.../BSim/src/main/help/help/TOC_Source.xml | 22 +
.../StructureRecovery/StructureRecovery.html | 203 ++++++
.../bsim/gui/structs/ComparePinningsTask.java | 400 ++++++++++
.../bsim/gui/structs/MatchFunctionsTask.java | 320 ++++++++
.../bsim/gui/structs/RetrieveUsesTask.java | 115 +++
.../gui/structs/StructureRecoveryPlugin.java | 686 ++++++++++++++++++
.../app/services/DataTypeReferenceFinder.java | 5 +-
.../codecompare/graphanalysis/DataVertex.java | 34 +-
.../codecompare/graphanalysis/Pinning.java | 4 +
10 files changed, 1786 insertions(+), 4 deletions(-)
create mode 100644 Ghidra/Features/BSim/src/main/help/help/topics/StructureRecovery/StructureRecovery.html
create mode 100644 Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/gui/structs/ComparePinningsTask.java
create mode 100644 Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/gui/structs/MatchFunctionsTask.java
create mode 100644 Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/gui/structs/RetrieveUsesTask.java
create mode 100644 Ghidra/Features/BSim/src/main/java/ghidra/features/bsim/gui/structs/StructureRecoveryPlugin.java
diff --git a/Ghidra/Features/BSim/certification.manifest b/Ghidra/Features/BSim/certification.manifest
index 951b1874fb..480af25ac1 100755
--- a/Ghidra/Features/BSim/certification.manifest
+++ b/Ghidra/Features/BSim/certification.manifest
@@ -41,6 +41,7 @@ src/main/help/help/topics/BSimSearchPlugin/images/BSimOverviewResults.png||GHIDR
src/main/help/help/topics/BSimSearchPlugin/images/BSimResultsProvider.png||GHIDRA||||END|
src/main/help/help/topics/BSimSearchPlugin/images/BSimSearchDialog.png||GHIDRA||||END|
src/main/help/help/topics/BSimSearchPlugin/images/ManageServersDialog.png||GHIDRA||||END|
+src/main/help/help/topics/StructureRecovery/StructureRecovery.html||GHIDRA||||END|
src/main/resources/bsim.log4j.xml||GHIDRA||||END|
src/main/resources/images/checkmark_yellow.gif||GHIDRA||||END|
src/main/resources/images/connected.png||GHIDRA||||END|
diff --git a/Ghidra/Features/BSim/src/main/help/help/TOC_Source.xml b/Ghidra/Features/BSim/src/main/help/help/TOC_Source.xml
index ba54898ec6..9f8be0f64d 100755
--- a/Ghidra/Features/BSim/src/main/help/help/TOC_Source.xml
+++ b/Ghidra/Features/BSim/src/main/help/help/TOC_Source.xml
@@ -170,6 +170,28 @@
text="BSim Command (bsim)"
target="help/topics/BSim/CommandLineReference.html#BSimCommand"/>
+
+
+ The StructureRecovery plugin allows users to build a structure in a target program based on the + field uses in a source program. The process involves three steps. First, a source program is + mined for field references from a known version of the structure to recover the use addresses + and offsets. Second, functions in the source program bookmarked by field use are matched to + functions in the target program using the local variation of BSim, which does not require a database. + Third, BSim is used to create 'pinnings' between the data-flow graphs for each pair of functions + which identify vertex-vertex correspondences using the decoompiler's diffing algorithm. + Vertices with addresses from the first step are examined to identify offset information, which + then becomes input to the construction of a new structure in the target program. +
++ The success of this process depends on a number of factors. There are cases, for instance, in + which nested structures may be missed by the structure use task, and, of course, certain fields + may not be referenced at all. BSim, here as elsewhere, depends on a number of parameters that + determine what constitutes a match, which are exposed as options. Unmatched functions will + potentially result in gaps in the structure. Finally, the pinning comparison attempts to reconcile + disparate pcode representations, but may fail in more complicated scenarios. When successful, + the resulting structure will be stored in the target program's DataTypeManager as "RECOVERED_structure_name". +
++ Each of the three tasks is relatively expensive. It may be necessary to save results from each + across sessions. This is done using bookmarks (viewable from the listing or the Bookmarks viewer), which + capture the structure use and function-to-function matches. The former are represented as + "USES_structure_name_offset:address"; the latter as "source function id→target function id". + The function-match bookmarks will be present in both the source and target programs. +
++ ALL tasks should run with the source program active. +
+ ++ Locates all non-zero field uses within a program for a specified structure. +
++ Uses BSim to match functions with structure use in the source program to similar functions + in a target program. +
++ Converts (persistent) bookmarks containing structure-use information, typically generated + by the 'Tag Structure Use' action, to a (non-persistent) map and vice-versa. +
++ Converts (persistent) bookmarks containing function-function matches, typically generated + by the 'Match Functions' action, to a (non-persistent) map and vice-versa. +
+ ++ Options governing various aspects of the structure recovery. +
+ + ++ The full path to the data type to be replicated ('Tag Structure Use' will query if empty). +
++ Should bookmarks by generated by 'Tag Structure Use'. +
++ Used by 'Match Functions' (see BSim documentation for details). +
++ Used by 'Match Functions' (see BSim documentation for details). +
++ Used by 'Match Functions' (see BSim documentation for details). +
++ The largest offset considered valid by 'Generate structure' (prevents confusion + between offsets and addresses). +
++ Comma-separated hex values to be ignored by 'Generate structure'. Principally used when + analyzing a randomized structure that amalgamates randomized fields in a common block, + e.g. 0x40 for the Linux task_struct randomized with symbols. +
+