Package ghidra.util
Class SourceFileUtils
java.lang.Object
ghidra.util.SourceFileUtils
A utility class for creating
SourceFiles from native paths, e.g., windows paths.-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic final recordA record containing the minimum and maximum mapped line numbers -
Method Summary
Modifier and TypeMethodDescriptionstatic StringbyteArrayToHexString(byte[] bytes) Converts a byte array to aStringof hexadecimal digits.static longbyteArrayToLong(byte[] bytes) Converts a byte array of length 8 to alongvalue.static SourceFilestatic SourceFilegetSourceFileFromPathString(String path, SourceFileIdType idType, byte[] identifier) Creates aSourceFilefrompathwith the provided id type and identifier.getSourceLineBounds(Program program, SourceFile sourceFile) Returns aSourceFileUtils.SourceLineBoundsrecord containing the minimum and maximum mapped line forsourceFileinprogram.static byte[]hexStringToByteArray(String hexString) Converts aStringof hexadecimal character to an array of bytes.static byte[]longToByteArray(long l) Converts alongvalue to an byte array of length 8.static StringnormalizeDwarfPath(String path, String baseDir) Normalizes paths encountered in DWARF debug info.
-
Method Details
-
getSourceFileFromPathString
Creates aSourceFilefrompathwith id typeSourceFileIdType.NONEand 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 aSourceFilefrompathwith 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 alongvalue 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 alongvalue. 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 aStringof 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 aStringof hexadecimal digits.- Parameters:
bytes- array to convert- Returns:
- string
-
getSourceLineBounds
public static SourceFileUtils.SourceLineBounds getSourceLineBounds(Program program, SourceFile sourceFile) Returns aSourceFileUtils.SourceLineBoundsrecord containing the minimum and maximum mapped line forsourceFileinprogram.- Parameters:
program- programsourceFile- source file- Returns:
- source line bounds or null
-
normalizeDwarfPath
Normalizes paths encountered in DWARF debug info. Relative paths are made absolute with base /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. Additionally, any backslashes are converted to forward slashes (backslashes can occur in files produced by MinGW).- 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
-