Package ghidra.app.util.cparser.C
Class CParserUtils
java.lang.Object
ghidra.app.util.cparser.C.CParserUtils
-
Nested Class Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic File
static String
handleParseProblem
(Throwable t, String functionString) Given a throwable, attempt pull out the significant error parts to generate a user-friendly error message.static CParserUtils.CParseResults
parseHeaderFiles
(DataTypeManager[] openDTMgrs, String[] filenames, String[] args, DataTypeManager existingDTMgr, String languageId, String compileSpecId, TaskMonitor monitor) Parse a set of C Header files and associated parsing arguments, data types are added to the provided DTMgr.static CParserUtils.CParseResults
parseHeaderFiles
(DataTypeManager[] openDTmanagers, String[] filenames, String[] includePaths, String[] args, DataTypeManager dtMgr, TaskMonitor monitor) Parse a set of C Header files and associated parsing arguments, data types are added to the provided DTMgr.static CParserUtils.CParseResults
parseHeaderFiles
(DataTypeManager[] openDTMgrs, String[] filenames, String[] includePaths, String[] args, DataTypeManager existingDTMgr, String languageId, String compileSpecId, TaskMonitor monitor) Parse a set of C Header files and associated parsing arguments, data types are added to the provided DTMgr.static FileDataTypeManager
parseHeaderFiles
(DataTypeManager[] openDTMgrs, String[] filenames, String[] includePaths, String[] args, String dataFileName, TaskMonitor monitor) Parse a set of C Header files and associated parsing arguments, returning a new File Data TypeManager with in the provided dataFileName.static FileDataTypeManager
parseHeaderFiles
(DataTypeManager[] openDTMgrs, String[] filenames, String[] includePaths, String[] args, String dataFileName, String languageId, String compileSpecId, TaskMonitor monitor) Parse a set of C Header files and associated parsing arguments, returning a new File Data TypeManager with in the provided dataFileName.static FileDataTypeManager
parseHeaderFiles
(DataTypeManager[] openDTMgrs, String[] filenames, String[] args, String dataFileName, TaskMonitor monitor) Parse a set of C Header files and associated parsing arguments, returning a new File Data TypeManager with in the provided dataFileName.static FunctionDefinitionDataType
parseSignature
(DataTypeManagerService service, Program program, String signatureText) Parse the given function signature text.static FunctionDefinitionDataType
parseSignature
(DataTypeManagerService service, Program program, String signatureText, boolean handleExceptions) Parse the given function signature text.static FunctionDefinitionDataType
parseSignature
(ServiceProvider serviceProvider, Program program, String signatureText) Parse the given function signature text.
-
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 DataTypeManagersprogram
- the program against which data types will be resolvedsignatureText
- 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 resolvedsignatureText
- 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 resolvedsignatureText
- the signature to parsehandleExceptions
- 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 typesfilenames
- names of files in order to parse, could include strings with "#" at start, which are ignored as commentsargs
- 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 parsingParseException
- for catastrophic errors in Preprocessor macro parsingIOException
- 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 typesfilenames
- names of files in order to parse, could include strings with "#" at start, which are ignored as commentsincludePaths
- paths to include files, instead of using-I<includepath>
in argsargs
- 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 parsingParseException
- for catastrophic errors in Preprocessor macro parsingIOException
- 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 typesfilenames
- names of files in order to parse, could include strings with "#" at start, which are ignored as commentsincludePaths
- 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 parsingmonitor
- used to cancel or provide results- Returns:
- the data types in the ghidra .gdt archive file
- Throws:
ParseException
- for catastrophic errors in C parsingParseException
- for catastrophic errors in Preprocessor macro parsingIOException
- 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 typesfilenames
- names of files in order to parse, could include strings with "#" at start, which are ignored as commentsargs
- 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 DTMgrlanguageId
- language identification to use for data type organization definitions (int, long, ptr size)compileSpecId
- compiler specification to use for parsingmonitor
- 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 parsingParseException
- for catastrophic errors in Preprocessor macro parsingIOException
- 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 typesfilenames
- names of files in order to parse, could include strings with "#" at start, which are ignored as commentsincludePaths
- paths to include files, instead of using-I<includepath>
in argsargs
- 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 DTMgrlanguageId
- language identification to use for data type organization definitions (int, long, ptr size)compileSpecId
- compiler specification to use for parsingmonitor
- 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 parsingParseException
- for catastrophic errors in Preprocessor macro parsingIOException
- 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 typesfilenames
- names of files in order to parse, could include strings with "#" at start, which are ignored as commentsincludePaths
- paths to include files, instead of using-I<includepath>
in argsargs
- 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 DTMgrmonitor
- 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 parsingParseException
- for catastrophic errors in Preprocessor macro parsing
-
handleParseProblem
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 theCParser
.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
-