Class ProgramMappingService
- java.lang.Object
-
- ghidra.plugin.importer.ProgramMappingService
-
public class ProgramMappingService extends java.lang.ObjectProvides 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(FSLR, DomainFile)and friends.)[1] - best-effort (adverb): meaning a dirty hack.
-
-
Field Summary
Fields Modifier and Type Field Description static java.lang.StringPROGRAM_METADATA_MD5static java.lang.StringPROGRAM_SOURCE_FSRL
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static voidclear()ClearsProgramMappingServicedata.static voidcreateAssociation(FSRL fsrl, DomainFile domainFile)Creates a short-lived association between aFSRLand aDomainFile.static voidcreateAssociation(FSRL fsrl, Program program)static voidcreateAutoAssocation(Program program)static ProgramfindMatchingOpenProgram(FSRL fsrl, java.lang.Object consumer)Returns a currently open GhidraProgramthat has metadata that links it to the specifiedfileparameter.static ProgramfindMatchingProgramOpenIfNeeded(FSRL fsrl, DomainFile domainFile, java.lang.Object consumer, ProgramManager programManager, int openState)Returns an openPrograminstance that matches the specifiedFSRL, either from the set of currently open programs, or by requesting the specifiedProgramManagerto open aDomainFilethat was found to match this GFile.static ProgramfindMatchingProgramOpenIfNeeded(FSRL fsrl, java.lang.Object consumer, ProgramManager programManager, int openState)Returns an openPrograminstance that matches the specifiedFSRL, either from the set of currently open programs, or by requesting the specifiedProgramManagerto open aDomainFilethat was found to match this GFile.static DomainFilegetCachedDomainFileFor(FSRL fsrl)static booleanisFileImportedIntoProject(FSRL fsrl)Returns true if the specifiedFSRLhas a matched GhidraDomainFilein the current project.static booleanisFileOpen(FSRL fsrl)static java.util.Map<FSRL,DomainFile>searchProjectForMatchingFiles(java.util.List<FSRL> fsrls, TaskMonitor monitor)Recursively searches the current activeProjectforDomainFiles that have metadata that matches aFSRLin 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()
ClearsProgramMappingServicedata.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 GhidraProgramthat 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-FSRLto search for in open program info.- Returns:
- boolean true if found.
-
isFileImportedIntoProject
public static boolean isFileImportedIntoProject(FSRL fsrl)
Returns true if the specifiedFSRLhas a matched GhidraDomainFilein the current project.- Parameters:
fsrl-FSRLto search for- Returns:
- boolean true if file exists in project.
-
getCachedDomainFileFor
public static DomainFile getCachedDomainFileFor(FSRL fsrl)
Returns a reference to aDomainFilein the currentProjectthat matches the specifiedFSRL.This method only consults an internal fsrl-to-DomainFile mapping that is short-lived and not persisted.
- Parameters:
fsrl-FSRLto search for- Returns:
DomainFilethat was previously associated viacreateAssociation(FSRL, DomainFile)and friends.
-
createAssociation
public static void createAssociation(FSRL fsrl, DomainFile domainFile)
Creates a short-lived association between aFSRLand aDomainFile.- Parameters:
fsrl-FSRLof where the DomainFile was imported from.domainFile-DomainFileto associate with
-
createAutoAssocation
public static void createAutoAssocation(Program program)
Attempts to create an association between the specified openprogramand anyFSRLmetadata found in thePrograms properties.Used by event handlers that get notified about a
Programbeing opened to opportunistically link that program to its source FSRL if the metadata is present.- Parameters:
program-Programto 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 openPrograminstance that matches the specifiedFSRL, either from the set of currently open programs, or by requesting the specifiedProgramManagerto open aDomainFilethat was found to match this GFile.- Parameters:
fsrl-FSRLof program original location.consumer- Object that will be used to pin the matching Program open. Caller must release the consumer when done.programManager-ProgramManagerthat will be used to open DomainFiles if necessary.openState- one ofProgramManager.OPEN_VISIBLE,ProgramManager.OPEN_HIDDEN,ProgramManager.OPEN_VISIBLE- Returns:
Programwhich 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 openPrograminstance that matches the specifiedFSRL, either from the set of currently open programs, or by requesting the specifiedProgramManagerto open aDomainFilethat was found to match this GFile.- Parameters:
fsrl-FSRLof program original location.domainFile- optionalDomainFilethat 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-ProgramManagerthat will be used to open DomainFiles if necessary.openState- one ofProgramManager.OPEN_VISIBLE,ProgramManager.OPEN_HIDDEN,ProgramManager.OPEN_VISIBLE- Returns:
Programwhich 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 GhidraProgramthat has metadata that links it to the specifiedfileparameter.(ie. an open program has a MD5 or FSRL metadata value that matches the file)
See also
#isFileOpen(GFile).
-
searchProjectForMatchingFiles
public static java.util.Map<FSRL,DomainFile> searchProjectForMatchingFiles(java.util.List<FSRL> fsrls, TaskMonitor monitor)
Recursively searches the current activeProjectforDomainFiles that have metadata that matches aFSRLin the specified list.Warning, this operation is expensive and should only be done in a Task thread.
- Parameters:
fsrls- List ofFSRLto match against the metadata of each DomainFile in Project.monitor-TaskMonitorto watch for cancel and update with progress.- Returns:
- Map of FSRLs to
DomainFiles of the found files, never null.
-
-