Package ghidra.util

Class SourceFileUtils

java.lang.Object
ghidra.util.SourceFileUtils

public class SourceFileUtils extends Object
A utility class for creating SourceFiles from native paths, e.g., windows paths.
  • Method Details

    • getSourceFileFromPathString

      public static SourceFile getSourceFileFromPathString(String path)
      Creates a SourceFile from path with id type SourceFileIdType.NONE and empty identifier. The path will be transformed using FSUtilities.normalizeNativePath(String) and then URI.normalize().
      Parameters:
      path - path
      Returns:
      source file
    • getSourceFileFromPathString

      public static SourceFile getSourceFileFromPathString(String path, SourceFileIdType idType, byte[] identifier)
      Creates a SourceFile from path with the provided id type and identifier. The path will be transformed usingFSUtilities.normalizeNativePath(String) and then URI.normalize().
      Parameters:
      path - path
      idType - id type
      identifier - identifier
      Returns:
      source file
    • longToByteArray

      public static byte[] longToByteArray(long l)
      Converts a long 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 a long 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

      public static byte[] hexStringToByteArray(String hexString)
      Converts a String 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

      public static String byteArrayToHexString(byte[] bytes)
      Converts a byte array to a String of hexadecimal digits.
      Parameters:
      bytes - array to convert
      Returns:
      string
    • getSourceLineBounds

      public static SourceFileUtils.SourceLineBounds getSourceLineBounds(Program program, SourceFile sourceFile)
      Returns a SourceFileUtils.SourceLineBounds record containing the minimum and maximum mapped line for sourceFile in program.
      Parameters:
      program - program
      sourceFile - source file
      Returns:
      source line bounds or null
    • fixDwarfRelativePath

      public static String fixDwarfRelativePath(String path, String baseDir)
      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 normalize
      baseDir - 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