Skip to content

Commit

Permalink
remove c keywords when parsing function signatures
Browse files Browse the repository at this point in the history
  • Loading branch information
astrelsky committed Apr 27, 2024
1 parent e6c8f5b commit 943b7b0
Showing 1 changed file with 9 additions and 0 deletions.
Expand Up @@ -161,6 +161,9 @@ private ParameterDefinition[] extractArguments(String newSignatureText)
throw new ParseException("Can't parse function arguments");
}
String trailingText = newSignatureText.substring(endIndex + 1);

// remove any trailing whitespace and semicolon
trailingText = trailingText.replaceAll("\\s*;?\\s*$", "");
if (trailingText.trim().length() > 0) {
throw new ParseException(
"Unexpected trailing text at end of function: " + trailingText);
Expand Down Expand Up @@ -192,6 +195,9 @@ private void addParameter(List<ParameterDefinition> parameterList, String arg)
throw new ParseException("Missing parameter");
}

// remove c keywords that Ghidra doesn't support
arg = arg.replaceAll("\\b((const)|(volatile)|(restrict)|(struct)|(union))\\b", "");

// Attempt to resolve parameter assuming only a datatype is specified
DataType dt = resolveDataType(arg);
if (dt != null) {
Expand Down Expand Up @@ -260,6 +266,9 @@ DataType extractReturnType(String signatureText) throws ParseException, Cancelle
throw new ParseException("Can't find return type");
}
String returnTypeName = StringUtils.join(split, " ", 0, split.length - 1);

// remove any c keywords from the return type name
returnTypeName = returnTypeName.replaceAll("\\b((static)|(inline)|(const)|(volatile)|(restrict)|(struct)|(union))\\b", "");

DataType dt = resolveDataType(returnTypeName);
if (dt == null) {
Expand Down

0 comments on commit 943b7b0

Please sign in to comment.