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
Fields -
Method Summary
Modifier and TypeMethodDescriptionstatic 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, Object consumer) Returns a currently open GhidraProgramthat has metadata that links it to the specifiedfileparameter.static ProgramfindMatchingProgramOpenIfNeeded(FSRL fsrl, DomainFile domainFile, 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, 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 booleanReturns true if the specifiedFSRLhas a matched GhidraDomainFilein the current project.static booleanisFileOpen(FSRL fsrl) static Map<FSRL,DomainFile> searchProjectForMatchingFiles(List<FSRL> fsrls, TaskMonitor monitor) Recursively searches the current activeProjectforDomainFiles that have metadata that matches aFSRLin the specified list.
-
Field Details
-
PROGRAM_METADATA_MD5
- See Also:
-
PROGRAM_SOURCE_FSRL
- See Also:
-
-
Method Details
-
clear
public static void clear()ClearsProgramMappingServicedata.This should be done whenever the project is opened/closed.
-
isFileOpen
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
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
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
-
createAssociation
Creates a short-lived association between aFSRLand aDomainFile.- Parameters:
fsrl-FSRLof where the DomainFile was imported from.domainFile-DomainFileto associate with
-
createAutoAssocation
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, 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, 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
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(FSRL). -
searchProjectForMatchingFiles
public static Map<FSRL,DomainFile> searchProjectForMatchingFiles(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.
-