Class CParserUtils

java.lang.Object
ghidra.app.util.cparser.C.CParserUtils

public class CParserUtils extends Object
  • Method Details

    • parseSignature

      public static FunctionDefinitionDataType parseSignature(ServiceProvider serviceProvider, Program program, String signatureText)
      Parse the given function signature text. Any exceptions will be handled herein by showing an error dialog (null is returned in that case).
      Parameters:
      serviceProvider - the service provider used to access DataTypeManagers
      program - the program against which data types will be resolved
      signatureText - the signature to parse
      Returns:
      the data type that is created as a result of parsing; null if there was a problem
      See Also:
    • parseSignature

      public static FunctionDefinitionDataType parseSignature(DataTypeManagerService service, Program program, String signatureText)
      Parse the given function signature text. Any exceptions will be handled herein by showing an error dialog (null is returned in that case).
      Parameters:
      service - the service used to access DataTypeManagers or null to use only the program's data type manager.
      program - the program against which data types will be resolved
      signatureText - the signature to parse
      Returns:
      the data type that is created as a result of parsing; null if there was a problem
      See Also:
    • parseSignature

      public static FunctionDefinitionDataType parseSignature(DataTypeManagerService service, Program program, String signatureText, boolean handleExceptions) throws ParseException
      Parse the given function signature text. Any exceptions will be handled herein by showing an error dialog (null is returned in that case).
      Parameters:
      service - the service used to access DataTypeManagers or null to use only the program's data type manager.
      program - the program against which data types will be resolved
      signatureText - the signature to parse
      handleExceptions - true signals that this method should deal with exceptions, showing error messages as necessary; false signals to throw any encountered parsing exceptions. This allows clients to perform exception handling that better matches their workflow.
      Returns:
      the data type that is created as a result of parsing; null if there was a problem
      Throws:
      ParseException - for catastrophic errors in C parsing
    • parseHeaderFiles

      public static FileDataTypeManager parseHeaderFiles(DataTypeManager[] openDTMgrs, String[] filenames, String[] args, String dataFileName, TaskMonitor monitor) throws ParseException, ParseException, IOException
      Parse a set of C Header files and associated parsing arguments, returning a new File Data TypeManager with in the provided dataFileName. Note: Using another open archive while parsing will cause: - a dependence on the other archive - any missing data types while parsing are supplied if present from an openDTMgr - after parsing all data types parsed with an equivalent data type in any openDTMgr replaced by the data type from the openDTMgr NOTE: This will only occur if the data type from the openDTMgr's is equivalent.
      Parameters:
      openDTMgrs - array of datatypes managers to use for undefined data types
      filenames - names of files in order to parse, could include strings with "#" at start, which are ignored as comments
      args - arguments for parsing, -D<defn>=, -I<includepath>
      dataFileName - name of data type archive file (include the .gdt extension)
      monitor - used to cancel or provide results
      Returns:
      the data types in the ghidra .gdt archive file
      Throws:
      ParseException - for catastrophic errors in C parsing
      ParseException - for catastrophic errors in Preprocessor macro parsing
      IOException - if there io are errors saving the archive
    • parseHeaderFiles

      public static FileDataTypeManager parseHeaderFiles(DataTypeManager[] openDTMgrs, String[] filenames, String[] includePaths, String[] args, String dataFileName, TaskMonitor monitor) throws ParseException, ParseException, IOException
      Parse a set of C Header files and associated parsing arguments, returning a new File Data TypeManager with in the provided dataFileName. Note: Using another open archive while parsing will cause: - a dependence on the other archive - any missing data types while parsing are supplied if present from an openDTMgr - after parsing all data types parsed with an equivalent data type in any openDTMgr replaced by the data type from the openDTMgr NOTE: This will only occur if the data type from the openDTMgr's is equivalent.
      Parameters:
      openDTMgrs - array of datatypes managers to use for undefined data types
      filenames - names of files in order to parse, could include strings with "#" at start, which are ignored as comments
      includePaths - paths to include files, instead of using -I<includepath> in args
      args - arguments for parsing, -D<defn>=, ( -I<includepath> use includePaths parm instead)
      dataFileName - name of data type archive file (include the .gdt extension)
      monitor - used to cancel or provide results
      Returns:
      the data types in the ghidra .gdt archive file
      Throws:
      ParseException - for catastrophic errors in C parsing
      ParseException - for catastrophic errors in Preprocessor macro parsing
      IOException - if there io are errors saving the archive
    • parseHeaderFiles

      public static FileDataTypeManager parseHeaderFiles(DataTypeManager[] openDTMgrs, String[] filenames, String[] includePaths, String[] args, String dataFileName, String languageId, String compileSpecId, TaskMonitor monitor) throws ParseException, ParseException, IOException
      Parse a set of C Header files and associated parsing arguments, returning a new File Data TypeManager with in the provided dataFileName. Note: Using another open archive while parsing will cause: - a dependence on the other archive - any missing data types while parsing are supplied if present from an openDTMgr - after parsing all data types parsed with an equivalent data type in any openDTMgr replaced by the data type from the openDTMgr NOTE: This will only occur if the data type from the openDTMgr's is equivalent. NOTE: Providing the correct languageID and compilerSpec is very important for header files that might use sizeof()
      Parameters:
      openDTMgrs - array of datatypes managers to use for undefined data types
      filenames - names of files in order to parse, could include strings with "#" at start, which are ignored as comments
      includePaths - path to include files, could also be in args with -I<includepath>
      args - arguments for parsing, -D<defn>=, -I<includepath>
      dataFileName - name of data type archive file (include the .gdt extension)
      languageId - language identication to use for data type organization definitions (int, long, ptr size)
      compileSpecId - compiler specification to use for parsing
      monitor - used to cancel or provide results
      Returns:
      the data types in the ghidra .gdt archive file
      Throws:
      ParseException - for catastrophic errors in C parsing
      ParseException - for catastrophic errors in Preprocessor macro parsing
      IOException - if there io are errors saving the archive
    • parseHeaderFiles

      public static CParserUtils.CParseResults parseHeaderFiles(DataTypeManager[] openDTMgrs, String[] filenames, String[] args, DataTypeManager existingDTMgr, String languageId, String compileSpecId, TaskMonitor monitor) throws ParseException, ParseException, IOException
      Parse a set of C Header files and associated parsing arguments, data types are added to the provided DTMgr. Note: Using another open archive while parsing will cause: - a dependence on the other archive - any missing data types while parsing are supplied if present from an openDTMgr - after parsing all data types parsed with an equivalent data type in any openDTMgr replaced by the data type from the openDTMgr NOTE: This will only occur if the data type from the openDTMgr's is equivalent. NOTE: Providing the correct languageID and compilerSpec is very important for header files that might use sizeof()
      Parameters:
      openDTMgrs - array of datatypes managers to use for undefined data types
      filenames - names of files in order to parse, could include strings with "#" at start, which are ignored as comments
      args - arguments for parsing, -D<defn>=, (-I<includepath> use includePaths parm instead)
      existingDTMgr - datatypes will be populated into this provided DTMgr, can pass Program or File DTMgr
      languageId - language identification to use for data type organization definitions (int, long, ptr size)
      compileSpecId - compiler specification to use for parsing
      monitor - used to cancel or provide results
      Returns:
      a formatted string of any output from pre processor parsing or C parsing
      Throws:
      ParseException - for catastrophic errors in C parsing
      ParseException - for catastrophic errors in Preprocessor macro parsing
      IOException - if there io are errors saving the archive
    • parseHeaderFiles

      public static CParserUtils.CParseResults parseHeaderFiles(DataTypeManager[] openDTMgrs, String[] filenames, String[] includePaths, String[] args, DataTypeManager existingDTMgr, String languageId, String compileSpecId, TaskMonitor monitor) throws ParseException, ParseException, IOException
      Parse a set of C Header files and associated parsing arguments, data types are added to the provided DTMgr. Note: Using another open archive while parsing will cause: - a dependence on the other archive - any missing data types while parsing are supplied if present from an openDTMgr - after parsing all data types parsed with an equivalent data type in any openDTMgr replaced by the data type from the openDTMgr NOTE: This will only occur if the data type from the openDTMgr's is equivalent. NOTE: Providing the correct languageID and compilerSpec is very important for header files that might use sizeof()
      Parameters:
      openDTMgrs - array of datatypes managers to use for undefined data types
      filenames - names of files in order to parse, could include strings with "#" at start, which are ignored as comments
      includePaths - paths to include files, instead of using -I<includepath> in args
      args - arguments for parsing, -D<defn>=, ( -I<includepath> use includePaths parm instead)
      existingDTMgr - datatypes will be populated into this provided DTMgr, can pass Program or File DTMgr
      languageId - language identification to use for data type organization definitions (int, long, ptr size)
      compileSpecId - compiler specification to use for parsing
      monitor - used to cancel or provide results
      Returns:
      a formatted string of any output from pre processor parsing or C parsing
      Throws:
      ParseException - for catastrophic errors in C parsing
      ParseException - for catastrophic errors in Preprocessor macro parsing
      IOException - if there io are errors saving the archive
    • parseHeaderFiles

      public static CParserUtils.CParseResults parseHeaderFiles(DataTypeManager[] openDTmanagers, String[] filenames, String[] includePaths, String[] args, DataTypeManager dtMgr, TaskMonitor monitor) throws ParseException, ParseException
      Parse a set of C Header files and associated parsing arguments, data types are added to the provided DTMgr. Note: Using another open archive while parsing will cause: - a dependence on the other archive - any missing data types while parsing are supplied if present from an openDTMgr - after parsing all data types parsed with an equivalent data type in any openDTMgr replaced by the data type from the openDTMgr NOTE: This will only occur if the data type from the openDTMgr's is equivalent. NOTE: The DTMgr should have been created with the correct data type organization from a language/compilerspec if there could be variants in datatype defintions when using the generic data type manager data organization for example in a generic FileDataTypeManager int and long are size 4. This will change in the future, but with the current implementation, beware!
      Parameters:
      openDTmanagers - array of datatypes managers to use for undefined data types
      filenames - names of files in order to parse, could include strings with "#" at start, which are ignored as comments
      includePaths - paths to include files, instead of using -I<includepath> in args
      args - arguments for parsing, -D<defn>=, ( -I<includepath> use includePaths parm instead)
      dtMgr - datatypes will be populated into this provided DTMgr, can pass Program or File DTMgr
      monitor - used to cancel or provide results
      Returns:
      a formatted string of any output from pre processor parsing or C parsing
      Throws:
      ParseException - for catastrophic errors in C parsing
      ParseException - for catastrophic errors in Preprocessor macro parsing
    • handleParseProblem

      public static String handleParseProblem(Throwable t, String functionString)
      Given a throwable, attempt pull out the significant error parts to generate a user-friendly error message.
      Parameters:
      t - the throwable to examine, originating from the CParser.
      functionString - the full function signature text that was parsed by the parser.
      Returns:
      a user-friendly error message, or null if this class did not know how to handle the given exception.
    • getFile

      public static File getFile(String parent, String filename)