Package ghidra.framework.data
Class GhidraFile
java.lang.Object
ghidra.framework.data.GhidraFile
- All Implemented Interfaces:
DomainFile
,Comparable<DomainFile>
-
Field Summary
FieldsFields inherited from interface ghidra.framework.model.DomainFile
DEFAULT_VERSION, READ_ONLY_PROPERTY
-
Method Summary
Modifier and TypeMethodDescriptionvoid
addToVersionControl
(String comment, boolean keepCheckedOut, TaskMonitor monitor) Adds this private file to version control.boolean
Returns true if this private file may be added to the associated repository.boolean
Returns true if this file may be checked-in to the associated repository.boolean
Returns true if this file may be checked-out from the associated repository.boolean
canMerge()
Returns true if this file can be merged with the current versioned file.boolean
Prior to invoking getDomainObject, this method can be used to determine if unsaved changes can be recovered on the next open.boolean
canSave()
Return whether this domain object can be saved (i.e., updated/overwritten).void
checkin
(CheckinHandler checkinHandler, boolean okToUpgrade, TaskMonitor monitor) Performs check in to associated repository.boolean
checkout
(boolean exclusive, TaskMonitor monitor) Checkout this file for update.int
compareTo
(DomainFile df) copyTo
(DomainFolder newParent, TaskMonitor monitor) Copy this file into the newParent folder as a private file.copyVersionTo
(int version, DomainFolder destFolder, TaskMonitor monitor) Copy a specific version of this file to the specified destFolder.void
delete()
Delete the entire database for this file, including any version files.void
delete
(int version) Deletes a specific version of a file from the versioned filesystem.boolean
boolean
exists()
Check for existence of domain file.Returns changes made to versioned file by others since checkout was performed.Get a list of checkouts by all users for the associated versioned file.Get checkout status associated with a versioned file.ArrayList<?>
Get the list of consumers (Objects) for this domain file.Returns content-type stringgetDomainObject
(Object consumer, boolean okToUpgrade, boolean okToRecover, TaskMonitor monitor) Opens and returns the current domain object.Class<? extends DomainObject>
Returns the underlying Class for the domain object in this domain file.Returns a unique file-IDgetIcon
(boolean disabled) Get the state based Icon image for the domain file based upon its content class.getImmutableDomainObject
(Object consumer, int version, TaskMonitor monitor) Returns a new DomainObject that cannot be changed or saved to its original file.long
Get a long value representing the time when the data was last modified.int
Return the latest versionReturns an ordered map containing the metadata that has been associated with the corresponding domain object.getName()
Get the name of the StoredObj that is associated with the data.getOpenedDomainObject
(Object consumer) Returns the domainObject for this DomainFile only if it is already open.Get the parent domain folder for this domain file.Returns the path name to the domain object.Returns the local storage location for the project that this DomainFile belongs to.getReadOnlyDomainObject
(Object consumer, int version, TaskMonitor monitor) Returns a "read-only" version of the domain object.int
Return either the latest version if the file is not checked-out or the version that was checked-out or a specific version that was requested.Version[]
Returns list of all available versions.int
hashCode()
boolean
isBusy()
Returns true if the domain object in this domain file exists and has an open transaction.boolean
Return whether the domain object in this domain file has changed.boolean
Returns true if this is a checked-out file.boolean
Returns true if this a checked-out file with exclusive access.boolean
Returns true if the file is versioned but a private copy also exists.boolean
Returns true if this file is in a writable project.boolean
Returns true if this file represents the latest version of the associated domain object.boolean
isOpen()
Returns true if there is an open domainObject for this file.boolean
Returns whether the object is read-only.boolean
Returns true if the versioned filesystem can be used to store this files content type.boolean
Return true if this is a versioned database, else falselong
length()
Returns the length of this domain file.void
merge
(boolean okToUpgrade, TaskMonitor monitor) Performs merge from current version of versioned file into local checked-out file.boolean
Returns true if this is a checked-out file which has been modified since it was checked-out.moveTo
(DomainFolder newParent) Move this file into the newParent folder.void
packFile
(File file, TaskMonitor monitor) Pack domain file into specified file.void
save
(TaskMonitor monitor) Save theDomainObject
associated with this file.Set the name on this domain file.void
setReadOnly
(boolean state) Sets the object to read-only.boolean
If the file has an updatable domain object with unsaved changes, generate a recovery snapshot.void
terminateCheckout
(long checkoutId) Forcefully terminate a checkout for the associated versioned file.toString()
void
undoCheckout
(boolean keep) Undo "checked-out" file.void
undoCheckout
(boolean keep, boolean force) Undo "checked-out" file.
-
Field Details
-
fileManager
-
-
Method Details
-
getUserFileSystem
-
exists
public boolean exists()Description copied from interface:DomainFile
Check for existence of domain file.- Specified by:
exists
in interfaceDomainFile
- Returns:
- true if file exists. A proxy domain file will always return false.
-
getFileID
Description copied from interface:DomainFile
Returns a unique file-ID- Specified by:
getFileID
in interfaceDomainFile
- Returns:
- the ID
-
setName
Description copied from interface:DomainFile
Set the name on this domain file.- Specified by:
setName
in interfaceDomainFile
- Parameters:
newName
- domain file name- Returns:
- renamed domain file (the original DomainFile object becomes invalid since it is immutable)
- Throws:
InvalidNameException
- if newName contains illegal charactersDuplicateFileException
- if a file named newName already exists in this files domain folder.FileInUseException
- if this file is in-use / checked-out.IOException
- thrown if an IO or access error occurs.
-
getName
Description copied from interface:DomainFile
Get the name of the StoredObj that is associated with the data.- Specified by:
getName
in interfaceDomainFile
- Returns:
- the name
-
getPathname
Description copied from interface:DomainFile
Returns the path name to the domain object.- Specified by:
getPathname
in interfaceDomainFile
- Returns:
- the path name
-
getProjectLocator
Description copied from interface:DomainFile
Returns the local storage location for the project that this DomainFile belongs to.- Specified by:
getProjectLocator
in interfaceDomainFile
- Returns:
- the location
-
getContentType
Description copied from interface:DomainFile
Returns content-type string- Specified by:
getContentType
in interfaceDomainFile
- Returns:
- the content type
-
getDomainObjectClass
Description copied from interface:DomainFile
Returns the underlying Class for the domain object in this domain file.- Specified by:
getDomainObjectClass
in interfaceDomainFile
- Returns:
- the class
-
getParent
Description copied from interface:DomainFile
Get the parent domain folder for this domain file.- Specified by:
getParent
in interfaceDomainFile
- Returns:
- the parent
-
compareTo
- Specified by:
compareTo
in interfaceComparable<DomainFile>
-
getChangesByOthersSinceCheckout
Description copied from interface:DomainFile
Returns changes made to versioned file by others since checkout was performed.- Specified by:
getChangesByOthersSinceCheckout
in interfaceDomainFile
- Returns:
- change set or null
- Throws:
VersionException
- latest version was created with a newer version of softwareIOException
- if a folder item access error occurs or change set was produced by newer version of software and can not be read
-
getOpenedDomainObject
Description copied from interface:DomainFile
Returns the domainObject for this DomainFile only if it is already open.- Specified by:
getOpenedDomainObject
in interfaceDomainFile
- Parameters:
consumer
- the consumer that will use the object.- Returns:
- the already opened domainObject or null if it is not currently open.
-
getDomainObject
public DomainObject getDomainObject(Object consumer, boolean okToUpgrade, boolean okToRecover, TaskMonitor monitor) throws VersionException, IOException, CancelledException Description copied from interface:DomainFile
Opens and returns the current domain object. If the domain object is already opened, then the existing open domain object is returned.- Specified by:
getDomainObject
in interfaceDomainFile
- Parameters:
consumer
- consumer of the domain object which is responsible for releasing it after use. When all the consumers using the domain object release it, then the object is closed and its resources released.okToUpgrade
- if true, allows the system to upgrade out of data domain objects to be in compliance with the current version of Ghidra. A Version exception will be thrown if the domain object cannot be upgraded OR okToUpgrade is false and the domain object is out of date.okToRecover
- if true, allows the system to recover unsaved file changes which resulted from a crash. If false, any existing recovery data will be deleted. This flag is only relevant if project is open for update (isInProject) and the file can be opened for update.monitor
- permits monitoring of open progress.- Returns:
- an open domain object can be modified and saved. (Not read-only)
- Throws:
VersionException
- if the domain object could not be read due to a version format change. If okToUpgrade is true, then a VersionException indicates that the domain object cannot be upgraded to the current format. If okToUpgrade is false, then the VersionException only means the object is not in the current format - it may or may not be possible to upgrade.IOException
- thrown if an IO or access error occurs.CancelledException
- if monitor cancelled operation
-
getReadOnlyDomainObject
public DomainObject getReadOnlyDomainObject(Object consumer, int version, TaskMonitor monitor) throws VersionException, IOException, CancelledException Description copied from interface:DomainFile
Returns a "read-only" version of the domain object. "Read-only" means that the domain object cannot be saved back into its original domain object. It can still be modified and saved to a new domain file. The domain object will be assigned a temporary domain file that will not allow a "save" operation. The user must do a "save as" to a new filename.- Specified by:
getReadOnlyDomainObject
in interfaceDomainFile
- Parameters:
consumer
- consumer of the domain object which is responsible for releasing it after use.version
- the domain object version requested. DEFAULT_VERSION should be specified to open the current version.monitor
- permits monitoring of open progress.- Returns:
- a new domain object that is disassociated from its original domain file.
- Throws:
VersionException
- if the domain object could not be read due to a version format change.FileNotFoundException
- if the stored file/version was not found.IOException
- thrown if an IO or access error occurs.CancelledException
- if monitor cancelled operation
-
getImmutableDomainObject
public DomainObject getImmutableDomainObject(Object consumer, int version, TaskMonitor monitor) throws VersionException, IOException, CancelledException Description copied from interface:DomainFile
Returns a new DomainObject that cannot be changed or saved to its original file.- Specified by:
getImmutableDomainObject
in interfaceDomainFile
- Parameters:
consumer
- consumer of the domain object which is responsible for releasing it after use.version
- the domain object version requested. DEFAULT_VERSION should be specified to open the current version.monitor
- permits monitoring of open progress.- Returns:
- a new domain object that is disassociated from its original domain file and cannot be modified
- Throws:
VersionException
- if the domain object could not be read due to a version format change.FileNotFoundException
- if the stored file/version was not found.IOException
- thrown if an IO or access error occurs.CancelledException
- if monitor cancelled operation
-
save
Description copied from interface:DomainFile
Save theDomainObject
associated with this file.- Specified by:
save
in interfaceDomainFile
- Parameters:
monitor
- monitor for the task that is doing the save on the file- Throws:
FileInUseException
- if the file is open for update by someone else, or a transient-read is in progress.IOException
- thrown if an IO error occurs.CancelledException
- if monitor cancelled operation
-
canSave
public boolean canSave()Description copied from interface:DomainFile
Return whether this domain object can be saved (i.e., updated/overwritten).- Specified by:
canSave
in interfaceDomainFile
- Returns:
- true if the user is the owner AND the file is in the active project AND the file is not read-only.
-
canRecover
public boolean canRecover()Description copied from interface:DomainFile
Prior to invoking getDomainObject, this method can be used to determine if unsaved changes can be recovered on the next open.- Specified by:
canRecover
in interfaceDomainFile
- Returns:
- true if recovery data exists.
-
takeRecoverySnapshot
Description copied from interface:DomainFile
If the file has an updatable domain object with unsaved changes, generate a recovery snapshot.- Specified by:
takeRecoverySnapshot
in interfaceDomainFile
- Returns:
- true if snapshot successful or not needed, false if file is busy which prevents snapshot, or snapshot was cancelled.
- Throws:
IOException
- if there is an exception saving the snapshot
-
isInWritableProject
public boolean isInWritableProject()Description copied from interface:DomainFile
Returns true if this file is in a writable project.- Specified by:
isInWritableProject
in interfaceDomainFile
- Returns:
- true if writable
-
getLastModifiedTime
public long getLastModifiedTime()Description copied from interface:DomainFile
Get a long value representing the time when the data was last modified.- Specified by:
getLastModifiedTime
in interfaceDomainFile
- Returns:
- the time
-
getIcon
Description copied from interface:DomainFile
Get the state based Icon image for the domain file based upon its content class.- Specified by:
getIcon
in interfaceDomainFile
- Parameters:
disabled
- true if the icon return should be rendered as not enabled- Returns:
- image icon
-
isCheckedOut
public boolean isCheckedOut()Description copied from interface:DomainFile
Returns true if this is a checked-out file.- Specified by:
isCheckedOut
in interfaceDomainFile
- Returns:
- true if checked-out
-
isCheckedOutExclusive
public boolean isCheckedOutExclusive()Description copied from interface:DomainFile
Returns true if this a checked-out file with exclusive access.- Specified by:
isCheckedOutExclusive
in interfaceDomainFile
- Returns:
- true if checked-out exclusively
-
modifiedSinceCheckout
public boolean modifiedSinceCheckout()Description copied from interface:DomainFile
Returns true if this is a checked-out file which has been modified since it was checked-out.- Specified by:
modifiedSinceCheckout
in interfaceDomainFile
- Returns:
- true if modified since check-out
-
canCheckout
public boolean canCheckout()Description copied from interface:DomainFile
Returns true if this file may be checked-out from the associated repository. User's with read-only repository access will not have checkout ability.- Specified by:
canCheckout
in interfaceDomainFile
- Returns:
- true if can checkout
-
canCheckin
public boolean canCheckin()Description copied from interface:DomainFile
Returns true if this file may be checked-in to the associated repository.- Specified by:
canCheckin
in interfaceDomainFile
- Returns:
- true if can check-in
-
canMerge
public boolean canMerge()Description copied from interface:DomainFile
Returns true if this file can be merged with the current versioned file.- Specified by:
canMerge
in interfaceDomainFile
- Returns:
- true if can merge
-
canAddToRepository
public boolean canAddToRepository()Description copied from interface:DomainFile
Returns true if this private file may be added to the associated repository.- Specified by:
canAddToRepository
in interfaceDomainFile
- Returns:
- true if can add to the repository
-
setReadOnly
Description copied from interface:DomainFile
Sets the object to read-only. This method may only be invoked for private files (i.e., not versioned).- Specified by:
setReadOnly
in interfaceDomainFile
- Parameters:
state
- if true file will be read-only and may not be updated, if false the file may be updated.- Throws:
IOException
- thrown if an IO error occurs.
-
isReadOnly
public boolean isReadOnly()Description copied from interface:DomainFile
Returns whether the object is read-only. From a framework point of view a read-only object can never be changed.- Specified by:
isReadOnly
in interfaceDomainFile
- Returns:
- true if read-only
-
isVersionControlSupported
public boolean isVersionControlSupported()Description copied from interface:DomainFile
Returns true if the versioned filesystem can be used to store this files content type.- Specified by:
isVersionControlSupported
in interfaceDomainFile
- Returns:
- true if supports version control
-
isVersioned
public boolean isVersioned()Description copied from interface:DomainFile
Return true if this is a versioned database, else false- Specified by:
isVersioned
in interfaceDomainFile
- Returns:
- true if versioned
-
isHijacked
public boolean isHijacked()Description copied from interface:DomainFile
Returns true if the file is versioned but a private copy also exists.- Specified by:
isHijacked
in interfaceDomainFile
- Returns:
- true if hijacked
-
getLatestVersion
public int getLatestVersion()Description copied from interface:DomainFile
Return the latest version- Specified by:
getLatestVersion
in interfaceDomainFile
- Returns:
- the version
-
isLatestVersion
public boolean isLatestVersion()Description copied from interface:DomainFile
Returns true if this file represents the latest version of the associated domain object.- Specified by:
isLatestVersion
in interfaceDomainFile
- Returns:
- true if the latest version
-
getVersion
public int getVersion()Description copied from interface:DomainFile
Return either the latest version if the file is not checked-out or the version that was checked-out or a specific version that was requested.- Specified by:
getVersion
in interfaceDomainFile
- Returns:
- the version
-
getVersionHistory
Description copied from interface:DomainFile
Returns list of all available versions.- Specified by:
getVersionHistory
in interfaceDomainFile
- Returns:
- the versions
- Throws:
IOException
- if there is an exception getting the history
-
addToVersionControl
public void addToVersionControl(String comment, boolean keepCheckedOut, TaskMonitor monitor) throws IOException, CancelledException Description copied from interface:DomainFile
Adds this private file to version control.- Specified by:
addToVersionControl
in interfaceDomainFile
- Parameters:
comment
- new version commentkeepCheckedOut
- if true, the file will be initially checked-outmonitor
- progress monitor- Throws:
FileInUseException
- if this file is in-use.IOException
- thrown if an IO or access error occurs. Also thrown if file is not private.CancelledException
- if the monitor cancelled the operation
-
checkout
public boolean checkout(boolean exclusive, TaskMonitor monitor) throws IOException, CancelledException Description copied from interface:DomainFile
Checkout this file for update. If this file is already private, this method does nothing.- Specified by:
checkout
in interfaceDomainFile
- Parameters:
exclusive
- if true an exclusive checkout will be requestedmonitor
- progress monitor- Returns:
- true if checkout successful, false if an exclusive checkout was not possible due to other users having checkouts of this file. A request for a non-exclusive checkout will never return false.
- Throws:
IOException
- thrown if an IO or access error occurs.CancelledException
- if task monitor cancelled operation.
-
checkin
public void checkin(CheckinHandler checkinHandler, boolean okToUpgrade, TaskMonitor monitor) throws IOException, VersionException, CancelledException Description copied from interface:DomainFile
Performs check in to associated repository. File must be checked-out and modified since checkout.- Specified by:
checkin
in interfaceDomainFile
- Parameters:
checkinHandler
- provides user input data to complete checkin process.okToUpgrade
- if true an upgrade will be performed if neededmonitor
- the TaskMonitor.- Throws:
IOException
- if an IO or access error occursVersionException
- if unable to handle domain object version in versioned filesystem. If okToUpgrade was false, check exception to see if it can be upgraded sometime after doing a checkout.CancelledException
- if task monitor cancelled operation
-
merge
public void merge(boolean okToUpgrade, TaskMonitor monitor) throws IOException, VersionException, CancelledException Description copied from interface:DomainFile
Performs merge from current version of versioned file into local checked-out file.- Specified by:
merge
in interfaceDomainFile
- Parameters:
okToUpgrade
- if true an upgrade will be performed if neededmonitor
- task monitor- Throws:
IOException
- if an IO or access error occursVersionException
- if unable to handle domain object version in versioned filesystem. If okToUpgrade was false, check exception to see if it can be upgradedCancelledException
- if task monitor cancelled operation
-
undoCheckout
Description copied from interface:DomainFile
Undo "checked-out" file. The original repository file is restored.- Specified by:
undoCheckout
in interfaceDomainFile
- Parameters:
keep
- if true, the private database will be renamed with a .keep extension.- Throws:
NotConnectedException
- if shared project and not connected to repositoryFileInUseException
- if this file is in-use / checked-out.IOException
- thrown if file is not checked-out or an IO / access error occurs.
-
undoCheckout
Description copied from interface:DomainFile
Undo "checked-out" file. The original repository file is restored.- Specified by:
undoCheckout
in interfaceDomainFile
- Parameters:
keep
- if true, the private database will be renamed with a .keep extension.force
- if not connected to the repository the local checkout file will be removed. Warning: forcing undo checkout will leave a stale checkout in place for the associated repository if not connected.- Throws:
NotConnectedException
- if shared project and not connected to repository and force is falseFileInUseException
- if this file is in-use / checked-out.IOException
- thrown if file is not checked-out or an IO / access error occurs.
-
terminateCheckout
Description copied from interface:DomainFile
Forcefully terminate a checkout for the associated versioned file. The user must be the owner of the checkout or have administrator privilege on the versioned filesystem (i.e., repository).- Specified by:
terminateCheckout
in interfaceDomainFile
- Parameters:
checkoutId
- checkout ID- Throws:
IOException
- if an IO or access error occurs
-
getCheckouts
Description copied from interface:DomainFile
Get a list of checkouts by all users for the associated versioned file.- Specified by:
getCheckouts
in interfaceDomainFile
- Returns:
- list of checkouts
- Throws:
IOException
- if an IO or access error occurs
-
getCheckoutStatus
Description copied from interface:DomainFile
Get checkout status associated with a versioned file.- Specified by:
getCheckoutStatus
in interfaceDomainFile
- Returns:
- checkout status or null if not checked-out to current associated project.
- Throws:
IOException
- if an IO or access error occurs
-
delete
Description copied from interface:DomainFile
Delete the entire database for this file, including any version files.- Specified by:
delete
in interfaceDomainFile
- Throws:
FileInUseException
- if this file is in-use / checked-out.UserAccessException
- if the user does not have permission to delete the file.IOException
- thrown if an IO or access error occurs.
-
delete
Description copied from interface:DomainFile
Deletes a specific version of a file from the versioned filesystem.- Specified by:
delete
in interfaceDomainFile
- Parameters:
version
- specific version to be deleted. The version must either be the oldest or latest, or -1 which will attempt to remove all versions. When deleting the latest version, this method could take a long time to return since the previous version must be reconstructed within the versioned filesystem.- Throws:
IOException
- if an IO error occurs, including the inability to delete a version because this item is checked-out, the user does not have permission, or the specified version is not the oldest or latest.
-
moveTo
Description copied from interface:DomainFile
Move this file into the newParent folder.- Specified by:
moveTo
in interfaceDomainFile
- Parameters:
newParent
- new parent folder within the same project- Returns:
- the newly relocated domain file (the original DomainFile object becomes invalid since it is immutable)
- Throws:
DuplicateFileException
- if a file with the same name already exists in newParent folder.FileInUseException
- if this file is in-use / checked-out.IOException
- thrown if an IO or access error occurs.
-
copyTo
public DomainFile copyTo(DomainFolder newParent, TaskMonitor monitor) throws IOException, CancelledException Description copied from interface:DomainFile
Copy this file into the newParent folder as a private file.- Specified by:
copyTo
in interfaceDomainFile
- Parameters:
newParent
- new parent foldermonitor
- task monitor- Returns:
- newly created domain file
- Throws:
FileInUseException
- if this file is in-use / checked-out.IOException
- thrown if an IO or access error occurs.CancelledException
- if task monitor cancelled operation.
-
copyVersionTo
public DomainFile copyVersionTo(int version, DomainFolder destFolder, TaskMonitor monitor) throws IOException, CancelledException Description copied from interface:DomainFile
Copy a specific version of this file to the specified destFolder.- Specified by:
copyVersionTo
in interfaceDomainFile
- Parameters:
version
- version to copydestFolder
- destination parent foldermonitor
- task monitor- Returns:
- the copied file
- Throws:
IOException
- thrown if an IO or access error occurs.CancelledException
- if task monitor cancelled operation.
-
getConsumers
Description copied from interface:DomainFile
Get the list of consumers (Objects) for this domain file.- Specified by:
getConsumers
in interfaceDomainFile
- Returns:
- empty array list if there are no consumers
-
isChanged
public boolean isChanged()Description copied from interface:DomainFile
Return whether the domain object in this domain file has changed.- Specified by:
isChanged
in interfaceDomainFile
- Returns:
- true if changed
-
isOpen
public boolean isOpen()Description copied from interface:DomainFile
Returns true if there is an open domainObject for this file.- Specified by:
isOpen
in interfaceDomainFile
- Returns:
- true if open
-
isBusy
public boolean isBusy()Description copied from interface:DomainFile
Returns true if the domain object in this domain file exists and has an open transaction.- Specified by:
isBusy
in interfaceDomainFile
- Returns:
- true if busy
-
packFile
Description copied from interface:DomainFile
Pack domain file into specified file. Specified file will be overwritten if it already exists.- Specified by:
packFile
in interfaceDomainFile
- Parameters:
file
- destination filemonitor
- the task monitor- Throws:
IOException
- if there is an exception packing the fileCancelledException
- if monitor cancels operation
-
getMetadata
Description copied from interface:DomainFile
Returns an ordered map containing the metadata that has been associated with the corresponding domain object. The map contains key,value pairs and are ordered by their insertion order.- Specified by:
getMetadata
in interfaceDomainFile
- Returns:
- a map containing the metadata that has been associated with the corresponding domain object.
-
length
Description copied from interface:DomainFile
Returns the length of this domain file. This size is the minimum disk space used for storing this file, but does not account for additional storage space used to tracks changes, etc.- Specified by:
length
in interfaceDomainFile
- Returns:
- file length
- Throws:
IOException
- thrown if IO or access error occurs
-
equals
-
hashCode
public int hashCode() -
toString
-