Class FSRL
- java.lang.Object
-
- ghidra.formats.gfilesystem.FSRL
-
- Direct Known Subclasses:
FSRLRoot
public class FSRL extends java.lang.ObjectA _F_ile _S_ystem _R_esource _L_ocator, (name and string format patterned after URLs)Used to locate a resource (by name) on a "filesystem", in a recursively nested fashion.
The string format of FSRLs is
fstype+ "://" +path+optional_MD5[ + "|" pipe +FSRL]*See
fromPartString(FSRL, String)for more format info.Read the string format from right-to-left for easiest understanding... ie. "file://z|y://x" reads as "file x inside a filesystem y inside a container file z".
FSRL instances are immutable and thread-safe.
Examples (pipes shown in red since they are hard to see):
- file://dir/subdir -- simplest example, locates a file on local computer filesystem.
- file://dir/subdir/example.zip|zip://readme.txt -- points to a file named "readme.txt" in a zip file.
- file://dir/subdir/example.zip|zip://dir/nested.tar|tar://file.txt -- points to a file inside a TAR archive, which is inside a ZIP archive, which is on the local filesystem.
- file://dir/subdir/example.zip?MD5=1234567|zip://readme.txt?MD5=987654 -- points to a file named "readme.txt" (with a MD5 hash) in a zip file (that has another MD5 hash).
See
FSRLRootfor examples of how FSRL and FSRLRoot's are related.FSRL's can be created either piecemeal, from the bottom up, starting with a root filesystem FSRL and calling
appendPath(String)orFSRLRoot.nestedFS(FSRL, String)methods to create deeper and deeper nested FSRLs,or
FSRL's can be created from strings using
fromString(String).FSRLs that have a MD5 value are
"fully qualified".
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedFSRL(FSRL parent, java.lang.String path)Protected constructor called by static factory methods such asfromString(String)or methods that return a new instance such aswithPath(String).protectedFSRL(FSRL parent, java.lang.String path, java.lang.String md5)Protected constructor called by static factory methods such asfromString(String)or methods that return a new instance such aswithPath(String).
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description FSRLappendPath(java.lang.String relPath)protected voidappendToStringBuilder(java.lang.StringBuilder sb, boolean recurse, boolean includeParams, boolean includeFSRoot)booleanequals(java.lang.Object obj)static FSRLfromString(FSRL parent, java.lang.String fsrlStr)Creates aFSRLfrom a raw string.static FSRLfromString(java.lang.String fsrlStr)Creates aFSRLfrom a raw string.FSRLRootgetFS()Returns theFSRLRootobject that represents the entirefilesystemfor this FSRL.java.lang.StringgetMD5()Returns the MD5 string associated with this file.java.lang.StringgetName()Returns the name portion of this FSRL's path, everything after the last '/'java.lang.StringgetName(int nestedDepth)Returns the name portion of the FSRL part at parent depthnestedDepth, where 0 is ourself (equiv to just callinggetName(), 1 is the parent container's name, etc.intgetNestingDepth()java.lang.StringgetPath()Returns the full path/filename of this FSRL.inthashCode()booleanisDescendantOf(FSRL potentialParent)Returnstrueif this object is a child or descendant of the specifiedpotentialParentparameter.booleanisEquivalent(FSRL other)Returns true if the twoFSRLs are the same, excluding any MD5 values.booleanisEquivalent(java.lang.String fsrlStr)Returns true if the two FSRLs are the same, excluding any MD5 values.FSRLRootmakeNested(java.lang.String fstype)Creates a newFSRLRootinstance that is a child of this FSRL.java.util.List<FSRL>split()Splits aFSRLinto aList, with each element pointing to each level of the full FSRL.java.lang.StringtoPrettyFullpathString()Returns a string containing the full FSRL, without FS "fstype://" portionsjava.lang.StringtoPrettyString()Returns a string containing the full FSRL, excluding MD5 portions.java.lang.StringtoString()Returns a string containing the full FSRL.java.lang.StringtoStringPart()Returns a string containing just the currentFSRLprotocol and path.FSRLwithMD5(java.lang.String newMD5)FSRLwithPath(FSRL copyPath)Creates a newFSRLinstance using the same path and other metadata present in thecopyPathinstance.FSRLwithPath(java.lang.String newpath)
-
-
-
Field Detail
-
PARAM_MD5
public static final java.lang.String PARAM_MD5
- See Also:
- Constant Field Values
-
parent
protected final FSRL parent
-
path
protected final java.lang.String path
-
-
Constructor Detail
-
FSRL
protected FSRL(FSRL parent, java.lang.String path)
Protected constructor called by static factory methods such asfromString(String)or methods that return a new instance such aswithPath(String).- Parameters:
parent- FSRL parent, null if this instance is root FSRLRootpath- String path, meaning dependent on context
-
FSRL
protected FSRL(FSRL parent, java.lang.String path, java.lang.String md5)
Protected constructor called by static factory methods such asfromString(String)or methods that return a new instance such aswithPath(String).- Parameters:
parent- FSRL parent, null if this instance is root FSRLRootpath- String path, meaning dependent on contextmd5- hex string with the md5 hash of the file this FSRL points to, null ok.
-
-
Method Detail
-
fromString
public static FSRL fromString(java.lang.String fsrlStr) throws java.net.MalformedURLException
Creates aFSRLfrom a raw string. The parent portions of the FSRL are not intern()'d so will not be shared with other FSRL instances.See
fromPartString(FSRL, String)for details of character encoding fixups.- Parameters:
fsrlStr- something like "fstype://path/path|fs2type://path2/path2|etc://etc/etc"- Returns:
- new
FSRLinstance, never null - Throws:
java.net.MalformedURLException- if empty string or bad format
-
fromString
public static FSRL fromString(FSRL parent, java.lang.String fsrlStr) throws java.net.MalformedURLException
Creates aFSRLfrom a raw string.See
fromPartString(FSRL, String)for details of character encoding fixups.
-
getFS
public FSRLRoot getFS()
Returns theFSRLRootobject that represents the entirefilesystemfor this FSRL.Never returns NULL, and calling getFS() on a
FSRLRootobject returns itself.
-
getNestingDepth
public int getNestingDepth()
Returns the number ofFSRLRoots there are in thisFSRL.A single level FSRL such as "file://path" will return 1.
A two level FSRL such as "file://path|subfs://path2" will return 2.
etc.- Returns:
- number of levels in this FSRL, min value returned is 1.
-
getPath
public java.lang.String getPath()
Returns the full path/filename of this FSRL. Does not include parent filesystem path or info."file://path|subfs://subpath/blah" returns "/subpath/blah"
May return null if this instance is a
FSRLRoot.
-
getName
public java.lang.String getName()
Returns the name portion of this FSRL's path, everything after the last '/'"file://path/name.ext" returns "name.ext"
- Returns:
- name portion of this FSRL path, or null if path is null also.
-
getName
public java.lang.String getName(int nestedDepth) throws java.io.IOExceptionReturns the name portion of the FSRL part at parent depthnestedDepth, where 0 is ourself (equiv to just callinggetName(), 1 is the parent container's name, etc.- Parameters:
nestedDepth- relative parent index of FSRL part to query, 0 == this instance.- Returns:
- name portion of the path of the specified FSRL part.
- Throws:
java.io.IOException- if nestedDepth is larger than number of FSRL parent parts.
-
getMD5
public java.lang.String getMD5()
Returns the MD5 string associated with this file.NULL if no MD5 value present.
- Returns:
- md5 string associated with this file object, or null if not present.
-
withMD5
public FSRL withMD5(java.lang.String newMD5)
- Parameters:
newMD5- string md5- Returns:
- new
FSRLinstance with the same path and the specified md5 value.
-
withPath
public FSRL withPath(java.lang.String newpath)
Creates a newFSRLinstance, using the sameFSRLRootas this instance, but with a new path.See also
appendPath(String).- Parameters:
newpath- string path- Returns:
- new
FSRLinstance with the specified path.
-
withPath
public FSRL withPath(FSRL copyPath)
Creates a newFSRLinstance using the same path and other metadata present in thecopyPathinstance.Used when re-root'ing a FSRL path onto another parent object (usually during intern()'ing)
- Parameters:
copyPath-- Returns:
- new FSRL instance
-
appendPath
public FSRL appendPath(java.lang.String relPath)
Creates a newFSRLinstance, using the sameFSRLRootas this instance, combining the currentpathwith therelPathvalue.- Parameters:
relPath-- Returns:
- new
FSRLinstance with additional path appended.
-
makeNested
public FSRLRoot makeNested(java.lang.String fstype)
Creates a newFSRLRootinstance that is a child of this FSRL.See
FSRLRoot.nestedFS(FSRL, FSRLRoot)andFSRLRoot.nestedFS(FSRL, String).- Parameters:
fstype- file system type string.- Returns:
- new
FSRLRootinstance
-
toString
public java.lang.String toString()
Returns a string containing the full FSRL.Example: "file://path|subfs://blah?MD5=1234567"
- Overrides:
toStringin classjava.lang.Object- Returns:
- string with full FSRL
-
toPrettyString
public java.lang.String toPrettyString()
Returns a string containing the full FSRL, excluding MD5 portions.- Returns:
- string with full FSRL, excluding MD5 portions.
-
toPrettyFullpathString
public java.lang.String toPrettyFullpathString()
Returns a string containing the full FSRL, without FS "fstype://" portionsExample:
"fsrl://path/filename?MD5=1234|subfsrl://subpath/subfile"will result in
"path/filename|subpath/subfile".- Returns:
- formatted string such as: "path/filename|subpath/subfile"
-
appendToStringBuilder
protected void appendToStringBuilder(java.lang.StringBuilder sb, boolean recurse, boolean includeParams, boolean includeFSRoot)
-
toStringPart
public java.lang.String toStringPart()
Returns a string containing just the currentFSRLprotocol and path.Example: "file://path|subfs://blah?MD5=123456" returns "subfs://blah?MD5=123456"
- Returns:
- string containing just the current
FSRLprotocol and path.
-
split
public java.util.List<FSRL> split()
Splits aFSRLinto aList, with each element pointing to each level of the full FSRL.Example: "file://path|subfs://blah|subfs2://blah2"
Produces a list of 3 elements:
"file://path"
"file://path|subfs://blah"
"file://path|subfs://blah|subfs2://blah2"- Returns:
ListofFSRLelements pointing to each level of this FSRL.
-
isEquivalent
public boolean isEquivalent(java.lang.String fsrlStr)
Returns true if the two FSRLs are the same, excluding any MD5 values.- Parameters:
fsrlStr- string-ifiedFSRL- Returns:
- boolean true if this instance is the same as the specified string-ified fsrl, ignoring any md5 values.
-
isEquivalent
public boolean isEquivalent(FSRL other)
Returns true if the twoFSRLs are the same, excluding any MD5 values.- Parameters:
other-FSRLto compare with- Returns:
- boolean true if this instance is the same as the specified FSRL, ignoring any md5 values.
-
isDescendantOf
public boolean isDescendantOf(FSRL potentialParent)
Returnstrueif this object is a child or descendant of the specifiedpotentialParentparameter.
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
equals
public boolean equals(java.lang.Object obj)
- Overrides:
equalsin classjava.lang.Object
-
-