Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove c keywords when parsing function signatures #6462

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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