Package ghidra.util
Class SourceFileUtils
java.lang.Object
ghidra.util.SourceFileUtils
A utility class for creating
SourceFile
s from native paths, e.g., windows paths.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final record
A record containing the minimum and maximum mapped line numbers -
Method Summary
Modifier and TypeMethodDescriptionstatic String
byteArrayToHexString
(byte[] bytes) Converts a byte array to aString
of hexadecimal digits.static long
byteArrayToLong
(byte[] bytes) Converts a byte array of length 8 to along
value.static String
fixDwarfRelativePath
(String path, String baseDir) Corrects potentially relative paths encountered in DWARF debug info.static SourceFile
static SourceFile
getSourceFileFromPathString
(String path, SourceFileIdType idType, byte[] identifier) Creates aSourceFile
frompath
with the provided id type and identifier.getSourceLineBounds
(Program program, SourceFile sourceFile) Returns aSourceFileUtils.SourceLineBounds
record containing the minimum and maximum mapped line forsourceFile
inprogram
.static byte[]
hexStringToByteArray
(String hexString) Converts aString
of hexadecimal character to an array of bytes.static byte[]
longToByteArray
(long l) Converts along
value to an byte array of length 8.
-
Method Details
-
getSourceFileFromPathString
Creates aSourceFile
frompath
with id typeSourceFileIdType.NONE
and empty identifier. The path will be transformed usingFSUtilities.normalizeNativePath(String)
and thenURI.normalize()
.- Parameters:
path
- path- Returns:
- source file
-
getSourceFileFromPathString
public static SourceFile getSourceFileFromPathString(String path, SourceFileIdType idType, byte[] identifier) Creates aSourceFile
frompath
with the provided id type and identifier. The path will be transformed usingFSUtilities.normalizeNativePath(String)
and thenURI.normalize()
.- Parameters:
path
- pathidType
- id typeidentifier
- identifier- Returns:
- source file
-
longToByteArray
public static byte[] longToByteArray(long l) Converts along
value to an byte array of length 8. The most significant byte of the long will be at position 0 of the resulting array.- Parameters:
l
- long- Returns:
- byte array
-
byteArrayToLong
public static long byteArrayToLong(byte[] bytes) Converts a byte array of length 8 to along
value. The byte at position 0 of the array will be the most significant byte of the resulting long.- Parameters:
bytes
- array to convert- Returns:
- long
- Throws:
IllegalArgumentException
- if bytes.length != 8
-
hexStringToByteArray
Converts aString
of hexadecimal character to an array of bytes. An initial "0x" or "0X" is ignored, as is the case of the digits a-f.- Parameters:
hexString
- String to convert- Returns:
- byte array
-
byteArrayToHexString
Converts a byte array to aString
of hexadecimal digits.- Parameters:
bytes
- array to convert- Returns:
- string
-
getSourceLineBounds
public static SourceFileUtils.SourceLineBounds getSourceLineBounds(Program program, SourceFile sourceFile) Returns aSourceFileUtils.SourceLineBounds
record containing the minimum and maximum mapped line forsourceFile
inprogram
.- Parameters:
program
- programsourceFile
- source file- Returns:
- source line bounds or null
-
fixDwarfRelativePath
Corrects potentially relative paths encountered in DWARF debug info. Relative paths are based at /baseDir
/. If normalization of "/../" subpaths results in a path "above" /baseDir
/, the returned path will be based at "baseDir_i" where i is the count of initial "/../" in the normalized path.- Parameters:
path
- path to normalizebaseDir
- name of artificial root directory- Returns:
- normalized path
- Throws:
IllegalArgumentException
- if the path is not valid or if baseDir contains a non-alphanumeric, non-underscore character
-