Class ProgramMappingService
FSRL
).
As there is no current feature that allows you to quickly query the metadata of Programs/DomainFile objects in the current project, finding a Program by its MD5 or by a original source location string is not easily possible.
Threadsafe.
The current implementation searches current open Ghidra Programs and maintains a
short-lived, in-memory only mapping of FSRL->DomainFile paths
(manually updated by users of the ProgramMappingService when
they do an import or other operation that creates a Ghidra DomainFile by calling
createAssociation(FSRL, DomainFile)
and friends.)
[1] - best-effort (adverb): meaning a dirty hack.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
clear()
ClearsProgramMappingService
data.static void
createAssociation
(FSRL fsrl, DomainFile domainFile) Creates a short-lived association between aFSRL
and aDomainFile
.static void
createAssociation
(FSRL fsrl, Program program) static void
createAutoAssocation
(Program program) static Program
findMatchingOpenProgram
(FSRL fsrl, Object consumer) Returns a currently open GhidraProgram
that has metadata that links it to the specifiedfile
parameter.static Program
findMatchingProgramOpenIfNeeded
(FSRL fsrl, DomainFile domainFile, Object consumer, ProgramManager programManager, int openState) Returns an openProgram
instance that matches the specifiedFSRL
, either from the set of currently open programs, or by requesting the specifiedProgramManager
to open aDomainFile
that was found to match this GFile.static Program
findMatchingProgramOpenIfNeeded
(FSRL fsrl, Object consumer, ProgramManager programManager, int openState) Returns an openProgram
instance that matches the specifiedFSRL
, either from the set of currently open programs, or by requesting the specifiedProgramManager
to open aDomainFile
that was found to match this GFile.static DomainFile
getCachedDomainFileFor
(FSRL fsrl) static boolean
Returns true if the specifiedFSRL
has a matched GhidraDomainFile
in the current project.static boolean
isFileOpen
(FSRL fsrl) static Map<FSRL,
DomainFile> searchProjectForMatchingFiles
(List<FSRL> fsrls, TaskMonitor monitor) Recursively searches the current activeProject
forDomainFile
s that have metadata that matches aFSRL
in the specified list.
-
Field Details
-
PROGRAM_METADATA_MD5
- See Also:
-
PROGRAM_SOURCE_FSRL
- See Also:
-
-
Method Details
-
clear
public static void clear()ClearsProgramMappingService
data.This should be done whenever the project is opened/closed.
-
isFileOpen
Returns true if there is a current open GhidraProgram
that has metadata that links it to the specifiedFSRL
.(ie. an open program has a MD5 or FSRL metadata value that matches the fsrl param.)
- Parameters:
fsrl
-FSRL
to search for in open program info.- Returns:
- boolean true if found.
-
isFileImportedIntoProject
Returns true if the specifiedFSRL
has a matched GhidraDomainFile
in the current project.- Parameters:
fsrl
-FSRL
to search for- Returns:
- boolean true if file exists in project.
-
getCachedDomainFileFor
Returns a reference to aDomainFile
in the currentProject
that matches the specifiedFSRL
.This method only consults an internal fsrl-to-DomainFile mapping that is short-lived and not persisted.
- Parameters:
fsrl
-FSRL
to search for- Returns:
DomainFile
that was previously associated viacreateAssociation(FSRL, DomainFile)
and friends.
-
createAssociation
-
createAssociation
Creates a short-lived association between aFSRL
and aDomainFile
.- Parameters:
fsrl
-FSRL
of where the DomainFile was imported from.domainFile
-DomainFile
to associate with
-
createAutoAssocation
Attempts to create an association between the specified openprogram
and anyFSRL
metadata found in theProgram
s properties.Used by event handlers that get notified about a
Program
being opened to opportunistically link that program to its source FSRL if the metadata is present.- Parameters:
program
-Program
to rummage around in its metadata looking for FSRL info.
-
findMatchingProgramOpenIfNeeded
public static Program findMatchingProgramOpenIfNeeded(FSRL fsrl, Object consumer, ProgramManager programManager, int openState) Returns an openProgram
instance that matches the specifiedFSRL
, either from the set of currently open programs, or by requesting the specifiedProgramManager
to open aDomainFile
that was found to match this GFile.- Parameters:
fsrl
-FSRL
of program original location.consumer
- Object that will be used to pin the matching Program open. Caller must release the consumer when done.programManager
-ProgramManager
that will be used to open DomainFiles if necessary.openState
- one ofProgramManager.OPEN_VISIBLE
,ProgramManager.OPEN_HIDDEN
,ProgramManager.OPEN_VISIBLE
- Returns:
Program
which was imported from the specified FSRL, or null if not found.
-
findMatchingProgramOpenIfNeeded
public static Program findMatchingProgramOpenIfNeeded(FSRL fsrl, DomainFile domainFile, Object consumer, ProgramManager programManager, int openState) Returns an openProgram
instance that matches the specifiedFSRL
, either from the set of currently open programs, or by requesting the specifiedProgramManager
to open aDomainFile
that was found to match this GFile.- Parameters:
fsrl
-FSRL
of program original location.domainFile
- optionalDomainFile
that corresponds to the FSRL param.consumer
- Object that will be used to pin the matching Program open. Caller must release the consumer when done.programManager
-ProgramManager
that will be used to open DomainFiles if necessary.openState
- one ofProgramManager.OPEN_VISIBLE
,ProgramManager.OPEN_HIDDEN
,ProgramManager.OPEN_VISIBLE
- Returns:
Program
which was imported from the specified FSRL, or null if not found.
-
findMatchingOpenProgram
Returns a currently open GhidraProgram
that has metadata that links it to the specifiedfile
parameter.(ie. an open program has a MD5 or FSRL metadata value that matches the file)
See also
isFileOpen(FSRL)
. -
searchProjectForMatchingFiles
public static Map<FSRL,DomainFile> searchProjectForMatchingFiles(List<FSRL> fsrls, TaskMonitor monitor) Recursively searches the current activeProject
forDomainFile
s that have metadata that matches aFSRL
in the specified list.Warning, this operation is expensive and should only be done in a Task thread.
- Parameters:
fsrls
- List ofFSRL
to match against the metadata of each DomainFile in Project.monitor
-TaskMonitor
to watch for cancel and update with progress.- Returns:
- Map of FSRLs to
DomainFile
s of the found files, never null.
-