mirror of
https://github.com/NationalSecurityAgency/ghidra.git
synced 2026-06-02 00:08:02 +08:00
GP-3650 - Fixed GNU demangler parsing bug
This commit is contained in:
+8
-10
@@ -118,8 +118,7 @@ public class GnuDemanglerParser {
|
|||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
private static final Pattern ARRAY_POINTER_REFERENCE_PATTERN =
|
private static final Pattern ARRAY_POINTER_REFERENCE_PATTERN =
|
||||||
Pattern.compile(
|
Pattern.compile("\\s(?:const[\\[\\]\\d\\*&]{0,4}\\s)*\\(([&*])\\)\\s*((?:\\[.*?\\])+)");
|
||||||
"\\s(?:const[\\[\\]\\d\\*&]{0,4}\\s)*\\(([&*])\\)\\s*((?:\\[.*?\\])+)");
|
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Sample: bob(short (&)[7])
|
* Sample: bob(short (&)[7])
|
||||||
@@ -836,16 +835,15 @@ public class GnuDemanglerParser {
|
|||||||
if (hasPointerParens) {
|
if (hasPointerParens) {
|
||||||
Demangled namespace = dt.getNamespace();
|
Demangled namespace = dt.getNamespace();
|
||||||
DemangledFunctionPointer dfp = parseFunctionPointer(datatype);
|
DemangledFunctionPointer dfp = parseFunctionPointer(datatype);
|
||||||
int firstParenEnd = datatype.indexOf(')', i + 1);
|
int paramParenEnd = datatype.lastIndexOf(')');
|
||||||
int secondParenEnd = datatype.indexOf(')', firstParenEnd + 1);
|
if (paramParenEnd == -1) {
|
||||||
if (secondParenEnd == -1) {
|
|
||||||
throw new DemanglerParseException(
|
throw new DemanglerParseException(
|
||||||
"Did not find ending to closure: " + datatype);
|
"Did not find ending to closure: " + datatype);
|
||||||
}
|
}
|
||||||
|
|
||||||
dfp.getReturnType().setNamespace(namespace);
|
dfp.getReturnType().setNamespace(namespace);
|
||||||
dt = dfp;
|
dt = dfp;
|
||||||
i = secondParenEnd + 1; // two sets of parens (normal case)
|
i = paramParenEnd + 1; // two sets of parens (normal case)
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
|
|
||||||
@@ -970,8 +968,8 @@ public class GnuDemanglerParser {
|
|||||||
|
|
||||||
Demangled namespace = dt.getNamespace();
|
Demangled namespace = dt.getNamespace();
|
||||||
String name = leading;
|
String name = leading;
|
||||||
DemangledDataType newDt = parseArrayPointerOrReference(datatype, name, lambdaString,
|
DemangledDataType newDt =
|
||||||
matcher);
|
parseArrayPointerOrReference(datatype, name, lambdaString, matcher);
|
||||||
newDt.setNamespace(namespace);
|
newDt.setNamespace(namespace);
|
||||||
return newDt;
|
return newDt;
|
||||||
}
|
}
|
||||||
@@ -993,8 +991,8 @@ public class GnuDemanglerParser {
|
|||||||
|
|
||||||
Demangled namespace = dt.getNamespace();
|
Demangled namespace = dt.getNamespace();
|
||||||
String name = leading;
|
String name = leading;
|
||||||
DemangledDataType newDt = parseArrayPointerOrReference(datatype, name, templatedString,
|
DemangledDataType newDt =
|
||||||
matcher);
|
parseArrayPointerOrReference(datatype, name, templatedString, matcher);
|
||||||
newDt.setNamespace(namespace);
|
newDt.setNamespace(namespace);
|
||||||
return newDt;
|
return newDt;
|
||||||
}
|
}
|
||||||
|
|||||||
+4
-16
@@ -387,8 +387,7 @@ public class GnuDemanglerParserTest extends AbstractGenericTest {
|
|||||||
//
|
//
|
||||||
// The demangled string contains this string: {unnamed_type#1}
|
// The demangled string contains this string: {unnamed_type#1}
|
||||||
//
|
//
|
||||||
String mangled =
|
String mangled = "_ZN14GoalDefinitionUt_aSERKS0_";
|
||||||
"_ZN14GoalDefinitionUt_aSERKS0_";
|
|
||||||
|
|
||||||
String demangled = process.demangle(mangled);
|
String demangled = process.demangle(mangled);
|
||||||
|
|
||||||
@@ -397,16 +396,14 @@ public class GnuDemanglerParserTest extends AbstractGenericTest {
|
|||||||
assertType(object, DemangledFunction.class);
|
assertType(object, DemangledFunction.class);
|
||||||
|
|
||||||
String signature = object.getSignature(false);
|
String signature = object.getSignature(false);
|
||||||
assertEquals(
|
assertEquals("undefined GoalDefinition::{unnamed_type#1}::operator=({unnamed const &)",
|
||||||
"undefined GoalDefinition::{unnamed_type#1}::operator=({unnamed const &)",
|
|
||||||
signature);
|
signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParse_DecltypeAuto() throws Exception {
|
public void testParse_DecltypeAuto() throws Exception {
|
||||||
|
|
||||||
String mangled =
|
String mangled = "_Z9enum_castIN17FurnaceBlockActorUt_EEDcT_";
|
||||||
"_Z9enum_castIN17FurnaceBlockActorUt_EEDcT_";
|
|
||||||
|
|
||||||
String demangled = process.demangle(mangled);
|
String demangled = process.demangle(mangled);
|
||||||
|
|
||||||
@@ -1928,17 +1925,8 @@ public class GnuDemanglerParserTest extends AbstractGenericTest {
|
|||||||
|
|
||||||
String signature = object.getSignature(false);
|
String signature = object.getSignature(false);
|
||||||
|
|
||||||
// 20230719: Note that argument in the following function is not correctly parsed.
|
|
||||||
// The argument is a non-pointer/ref reference to a function that returns void and
|
|
||||||
// which takes the argument list shown. Parser looks for double closing parenthesis,
|
|
||||||
// but that is found on the last argument of the template parameter. It actually needed
|
|
||||||
// to find the last closing parethesis and know that there could be nested pairs.
|
|
||||||
// Modification on 20230719 has "(* &&)" emitted in place of "(*)" because of lref/rref
|
|
||||||
// work in GP-3649, but the "&&" was found due to the closing parenthesis issue, which
|
|
||||||
// already existed.
|
|
||||||
// TODO: needs fixed
|
|
||||||
assertEquals(
|
assertEquals(
|
||||||
"undefined WebCore::TextCodecICU::registerCodecs(void (* &&)(char const *,WTF::Function<std::__1::unique_ptr<WebCore::TextCodec,std::__1::default_delete<WebCore::TextCodec>> ()> &&))",
|
"undefined WebCore::TextCodecICU::registerCodecs(void (*)(char const *,WTF::Function<std::__1::unique_ptr<WebCore::TextCodec,std::__1::default_delete<WebCore::TextCodec>> ()> &&))",
|
||||||
signature);
|
signature);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user