Class NativeSignatureDBManager
java.lang.Object
com.pnfsoftware.jeb.core.units.code.asm.sig.NativeSignatureDBManager
- All Implemented Interfaces:
IEventListener
Manage a set of
INativeSignaturePackage, such that a native item (routine, basic block,
instruction or data) can be matched against the INativeSignature contained in these
packages. The manager is a singleton handling all analysis.
Conflicts resolution, i.e. when several signature match, and processing of signatures' attributes are the client's responsibility.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptionvoidActivate automatic native signature creation for an analyzer.voidAdd a new folder to search for native signature packages.createUserPackage(ProcessorType procType, String packageName, String packageDescription, String packageAuthor) Create new signature package in user folder (seegetUserCreatedPackageFolder().voidDeactivate automatic native signature creation for an analyzer.Provides the list of available signature packages entries.static NativeSignatureDBManagergetInstance(IEnginesContext enginesContext) Get the singleton native signature database manager.Provides the list of signature packages entries for which the corresponding signatures are loaded in memory.intCount loaded signatures across registered analyzers.Get the signature generator used by this manager.Get the path for the user-created signature package folder, if any, whose name is set toSIGLIB_USER_PACKAGE_FOLDER.Provides the list of active signature packages entries that were created by a user.getUserCreatedPackages(ProcessorType procType) Provides the list of active signature packages entries that were created by a user with a given processor type.Get the user-selected signature package for an analyzer.booleanisActive()Determine whether native signature matching is enabled.booleanDetermine whether automatic native signature creation is active for an analyzer.voidLoads in memory the available packages suitable for the given analysis.booleanLoads a specific package for the given analysis.booleanloadPackage(NativeSignaturePackageEntry entry, boolean doMatching) Loads a specific package entry for all analyzers known to the manager.match(INativeCodeAnalyzer<? extends IInstruction> _gca, Collection<INativeMethodDataItem> routines, boolean uniqueMatchOnly, boolean maximumConfidenceLevel, boolean includeAlreadyMatched) Match a list of native routines against the currently loaded signatures packages for this analysis.voidHandle project save events by flushing pending user-created package updates.voidRegister an analyzer to be handled by this manager.voidEmpties the list of scanned foldersvoidEmpties the list of available packages.voidremoveFolder(File folder, boolean doRescan) Remove a folder from the list of folders to search for native signature packages.voidrescan()Rescan registered folders to register/unregister native signature packages.voidrescan(boolean deleteOldEntries) Rescan registered folders to register/unregister native signature packages.voidsetActive(boolean isActive) Enable or disable native signature matching.voidsetUserSelectedPackage(INativeCodeAnalyzer<IInstruction> analyzer, NativeSignaturePackageEntry userSelectedPackage) Set the user-selected signature package for an analyzer.voidUnregister an analyzer handled by this manager.voidupdateOnDiskPackages(boolean updateExistingSignatures) Write new signatures into the on disk packages.
-
Field Details
-
SIGLIB_EXTENSION
Extension of native signature package files.- See Also:
-
SIGLIB_USER_PACKAGE_FOLDER
Default folder name for user-created signature packages.- See Also:
-
-
Method Details
-
getInstance
Get the singleton native signature database manager.- Parameters:
enginesContext- engines context used by the manager- Returns:
- singleton manager
-
addFolder
Add a new folder to search for native signature packages.- Parameters:
folder- folder to adddoRescan- if true all registered folders are scanned for signature packages after the addition
-
removeFolder
Remove a folder from the list of folders to search for native signature packages.- Parameters:
folder- folder to removedoRescan- if true all registered folders are scanned for signature packages after the removal
-
removeAllFolders
public void removeAllFolders()Empties the list of scanned folders -
rescan
public void rescan()Rescan registered folders to register/unregister native signature packages. Such package names end withSIGLIB_EXTENSION. -
rescan
public void rescan(boolean deleteOldEntries) Rescan registered folders to register/unregister native signature packages.- Parameters:
deleteOldEntries- true to remove entries for packages that were not found again
-
getAvailablePackages
Provides the list of available signature packages entries. The corresponding packages are not necessarily loaded.- Returns:
- available package entries
-
removeAllPackages
public void removeAllPackages()Empties the list of available packages. -
getLoadedPackages
Provides the list of signature packages entries for which the corresponding signatures are loaded in memory.- Returns:
- loaded package entries
-
getUserCreatedPackages
Provides the list of active signature packages entries that were created by a user with a given processor type.- Parameters:
procType- target processor type- Returns:
- list of packages, never null
-
getUserCreatedPackages
Provides the list of active signature packages entries that were created by a user.- Returns:
- list of packages, never null
-
updateOnDiskPackages
public void updateOnDiskPackages(boolean updateExistingSignatures) Write new signatures into the on disk packages. These signatures are initially stored in memory into the corresponding entry (seeNativeSignaturePackageEntry.addSignatureToWrite(INativeSignature)). This allows to delay the actual write on disk of the new signatures.Note: only user-created signature packages can be written into through this method.
- Parameters:
updateExistingSignatures- if true, matching existing signatures are replaced
-
createUserPackage
public NativeSignaturePackageEntry createUserPackage(ProcessorType procType, String packageName, String packageDescription, String packageAuthor) Create new signature package in user folder (seegetUserCreatedPackageFolder(). If there is already a package with same name, it will fail.- Parameters:
procType- target processor typepackageName- package namepackageDescription- package descriptionpackageAuthor- package author- Returns:
- the entry representing the new package, null if the creation failed
-
loadDefaultPackages
Loads in memory the available packages suitable for the given analysis. The determination of the suitable packages is based on:- the processor type of the analysis
- the detected compiler, if any
- Parameters:
gca- analyzer for which packages should be loaded
-
loadPackage
Loads a specific package entry for all analyzers known to the manager.Note: analyzer have to be for the same architecture as the package for the loading to happen.
- Parameters:
entry- package entry to loaddoMatching- if true, after the package has been loaded, analyzers will re-match all routines- Returns:
- true if the package was loaded for at least one analysis, false otherwise
-
loadPackage
public boolean loadPackage(INativeCodeAnalyzer<IInstruction> gca, NativeSignaturePackageEntry entry) Loads a specific package for the given analysis.- Parameters:
gca- analyzer for which to load the packageentry- package entry to load- Returns:
- true if the package was loaded
-
activateAutoSigningMode
Activate automatic native signature creation for an analyzer.- Parameters:
gca- analyzer for which auto signing should be activated
-
deactivateAutoSigningMode
Deactivate automatic native signature creation for an analyzer.- Parameters:
gca- analyzer for which auto signing should be deactivated
-
isAutoSigningModeActivated
Determine whether automatic native signature creation is active for an analyzer.- Parameters:
gca- analyzer to query- Returns:
- true if auto signing is active
-
registerAnalyzer
Register an analyzer to be handled by this manager.- Parameters:
gca- analyzer to register
-
unregisterAnalyzer
Unregister an analyzer handled by this manager.Note that this method unloads from memory the signatures packages used by the given analysis. Only the signatures storage specific to this analysis will be removed, i.e. if another analysis uses the same package it will stay loaded.
- Parameters:
gca- analyzer to unregister
-
getNumberLoadedSigs
public int getNumberLoadedSigs()Count loaded signatures across registered analyzers.- Returns:
- number of loaded signatures
-
setActive
public void setActive(boolean isActive) Enable or disable native signature matching.- Parameters:
isActive- true to enable matching
-
isActive
public boolean isActive()Determine whether native signature matching is enabled.- Returns:
- true if matching is enabled
-
match
public List<NativeSignatureMatchResult> match(INativeCodeAnalyzer<? extends IInstruction> _gca, Collection<INativeMethodDataItem> routines, boolean uniqueMatchOnly, boolean maximumConfidenceLevel, boolean includeAlreadyMatched) Match a list of native routines against the currently loaded signatures packages for this analysis. For each routine the algorithm searches for signatures whose allINativeFeaturematch the routine.The result can be incomplete: if a unique match was asked we stop the search as soon as we found two matches and report an incomplete result, see
NativeSignatureMatchResult.isComplete().- Parameters:
_gca- analyzer owning the routinesroutines- routines to matchuniqueMatchOnly- if true the complete results are the ones for which there is only one matching signaturemaximumConfidenceLevel- if true the matching signatures -- if any -- will all be of the maximum possible level of confidence. For example, if two matching signatures haveINativeSignature.ConfidenceLevel.MEDIUMand one hasINativeSignature.ConfidenceLevel.LOW, only the first two will be kept in the results. Otherwise, all matching signatures are kept.includeAlreadyMatched- if true routines already matched will be re-matched, otherwise they will be ignored- Returns:
- list of results, empty if none
-
getSignatureGenerator
Get the signature generator used by this manager.- Returns:
- signature generator
-
getUserCreatedPackageFolder
Get the path for the user-created signature package folder, if any, whose name is set toSIGLIB_USER_PACKAGE_FOLDER.- Returns:
- user-created package folder, possibly null
-
getUserSelectedPackage
public NativeSignaturePackageEntry getUserSelectedPackage(INativeCodeAnalyzer<IInstruction> analyzer) Get the user-selected signature package for an analyzer.- Parameters:
analyzer- analyzer to query- Returns:
- selected package entry, possibly null
-
setUserSelectedPackage
public void setUserSelectedPackage(INativeCodeAnalyzer<IInstruction> analyzer, NativeSignaturePackageEntry userSelectedPackage) Set the user-selected signature package for an analyzer.- Parameters:
analyzer- analyzer to updateuserSelectedPackage- selected package entry
-
onEvent
Handle project save events by flushing pending user-created package updates.- Specified by:
onEventin interfaceIEventListener- Parameters:
e- event to handle
-