Class ProgramMappingService
- java.lang.Object
-
- ghidra.plugin.importer.ProgramMappingService
-
public class ProgramMappingService extends java.lang.Object
Provides a best-effort[1] mapping / association between Ghidra Program/DomainFile objects and GFilesystem files (identified by theirFSRL
).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
Fields Modifier and Type Field Description static java.lang.String
PROGRAM_METADATA_MD5
static java.lang.String
PROGRAM_SOURCE_FSRL
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static 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, java.lang.Object consumer)
Returns a currently open GhidraProgram
that has metadata that links it to the specifiedfile
parameter.static Program
findMatchingProgramOpenIfNeeded(FSRL fsrl, DomainFile domainFile, java.lang.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, java.lang.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
isFileImportedIntoProject(FSRL fsrl)
Returns true if the specifiedFSRL
has a matched GhidraDomainFile
in the current project.static boolean
isFileOpen(FSRL fsrl)
static java.util.Map<FSRL,DomainFile>
searchProjectForMatchingFiles(java.util.List<FSRL> fsrls, TaskMonitor monitor)
Recursively searches the current activeProject
forDomainFile
s that have metadata that matches aFSRL
in the specified list.
-
-
-
Field Detail
-
PROGRAM_METADATA_MD5
public static final java.lang.String PROGRAM_METADATA_MD5
- See Also:
- Constant Field Values
-
PROGRAM_SOURCE_FSRL
public static final java.lang.String PROGRAM_SOURCE_FSRL
- See Also:
- Constant Field Values
-
-
Method Detail
-
clear
public static void clear()
ClearsProgramMappingService
data.This should be done whenever the project is opened/closed.
-
isFileOpen
public static boolean isFileOpen(FSRL fsrl)
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
public static boolean isFileImportedIntoProject(FSRL fsrl)
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
public static DomainFile getCachedDomainFileFor(FSRL fsrl)
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
public static void createAssociation(FSRL fsrl, DomainFile domainFile)
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
public static void createAutoAssocation(Program program)
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, java.lang.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, java.lang.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
public static Program findMatchingOpenProgram(FSRL fsrl, java.lang.Object consumer)
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 java.util.Map<FSRL,DomainFile> searchProjectForMatchingFiles(java.util.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.
-
-