diff --git a/Ghidra/Features/MicrosoftDmang/src/main/java/mdemangler/MDMang.java b/Ghidra/Features/MicrosoftDmang/src/main/java/mdemangler/MDMang.java index d4b1c7e1e1..51bc11287e 100644 --- a/Ghidra/Features/MicrosoftDmang/src/main/java/mdemangler/MDMang.java +++ b/Ghidra/Features/MicrosoftDmang/src/main/java/mdemangler/MDMang.java @@ -70,13 +70,15 @@ public class MDMang { } /** - * Demangles the string passed in. + * Demangles the string passed in and returns a parsed item. * * @param mangledIn * the string to be demangled. * @param errorOnRemainingChars * boolean flag indicating whether remaining characters causes an * error. + * @return the item that has been parsed. + * @throws MDException upon parsing error */ public MDParsableItem demangle(String mangledIn, boolean errorOnRemainingChars) throws MDException { @@ -88,7 +90,7 @@ public class MDMang { } /** - * Demangles the string passed in. + * Demangles the string already stored and returns a parsed item. * * @param errorOnRemainingChars * boolean flag indicating whether remaining characters causes an diff --git a/Ghidra/Features/MicrosoftDmang/src/main/java/mdemangler/object/MDObjectCPP.java b/Ghidra/Features/MicrosoftDmang/src/main/java/mdemangler/object/MDObjectCPP.java index 1daa04a36a..39132b0ad9 100644 --- a/Ghidra/Features/MicrosoftDmang/src/main/java/mdemangler/object/MDObjectCPP.java +++ b/Ghidra/Features/MicrosoftDmang/src/main/java/mdemangler/object/MDObjectCPP.java @@ -257,7 +257,7 @@ public class MDObjectCPP extends MDObject { break; } builder.append(ch); - dmang.next(); + dmang.increment(); } int end = dmang.getIndex(); if ((end - start) != 32 || ch != '@') { diff --git a/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDBaseTestConfiguration.java b/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDBaseTestConfiguration.java index 83c04ab181..d0ae855f55 100644 --- a/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDBaseTestConfiguration.java +++ b/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDBaseTestConfiguration.java @@ -15,8 +15,7 @@ */ package mdemangler; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; +import static org.junit.Assert.*; import org.junit.rules.TestName; @@ -87,7 +86,8 @@ public class MDBaseTestConfiguration { } // Meant to be overridden, as needed by extended classes - doDemangleSymbol(); + demangItem = doDemangleSymbol(mdm, mangled); + demangled = (demangItem == null) ? "" : demangItem.toString(); doBasicTestsAndOutput(); @@ -192,15 +192,12 @@ public class MDBaseTestConfiguration { } // Meant to be overridden, as needed by extended classes - protected void doDemangleSymbol() throws Exception { + protected MDParsableItem doDemangleSymbol(MDMang mdmIn, String mangledIn) throws Exception { try { - demangItem = mdm.demangle(mangled, true); - demangled = demangItem.toString(); + return mdmIn.demangle(mangledIn, true); } catch (MDException e) { - Msg.info(this, "Could not demangle: " + mangled, e); - demangItem = null; - demangled = ""; + return null; } } diff --git a/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDGenericizeTestConfiguration.java b/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDGenericizeTestConfiguration.java index 8b39b0fd96..1c77020f58 100644 --- a/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDGenericizeTestConfiguration.java +++ b/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDGenericizeTestConfiguration.java @@ -41,13 +41,10 @@ public class MDGenericizeTestConfiguration extends MDBaseTestConfiguration { outputInfo.append(mangledGeneric); outputInfo.append("\n"); MDMang mdmGeneric = new MDMang(); - MDParsableItem demangItemGeneric = mdmGeneric.demangle(mangledGeneric, false); - String demangledGeneric; + MDParsableItem demangItemGeneric = doDemangleSymbol(mdmGeneric, mangledGeneric); + String demangledGeneric = (demangItemGeneric == null) ? "" : demangItemGeneric.toString(); if (demangItemGeneric == null) { - demangledGeneric = ""; - } - else { - demangledGeneric = demangItemGeneric.toString(); + demangled = ""; // Make sure test value is set properly when failure } outputInfo.append("GDemang: "); outputInfo.append(demangledGeneric); diff --git a/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDGhidraTestConfiguration.java b/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDGhidraTestConfiguration.java index 0f23514d98..04fab3f7c4 100644 --- a/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDGhidraTestConfiguration.java +++ b/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDGhidraTestConfiguration.java @@ -46,17 +46,17 @@ public class MDGhidraTestConfiguration extends MDBaseTestConfiguration { } @Override - protected void doDemangleSymbol() throws Exception { + protected MDParsableItem doDemangleSymbol(MDMang mdmIn, String mangledIn) throws Exception { + MDParsableItem returnItem; try { //Set true in operational mode. - demangItem = ((MDMangGhidra) mdm).demangle(mangled, false); // "false" is different - demangled = demangItem.toString(); - demangledObject = ((MDMangGhidra) mdm).getObject(); + returnItem = ((MDMangGhidra) mdmIn).demangle(mangledIn, false); // "false" is different + demangledObject = ((MDMangGhidra) mdmIn).getObject(); } catch (MDException e) { - demangItem = null; - demangled = ""; + returnItem = null; } + return returnItem; } @Override diff --git a/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDVS2013TestConfiguration.java b/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDVS2013TestConfiguration.java index fec56a6430..a8e0143158 100644 --- a/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDVS2013TestConfiguration.java +++ b/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDVS2013TestConfiguration.java @@ -40,14 +40,12 @@ public class MDVS2013TestConfiguration extends MDBaseTestConfiguration { } @Override - protected void doDemangleSymbol() throws Exception { + protected MDParsableItem doDemangleSymbol(MDMang mdmIn, String mangledIn) throws Exception { try { - demangItem = mdm.demangle(mangled, false); // "false" is different - demangled = demangItem.toString(); + return mdmIn.demangle(mangledIn, false); // "false" is different } catch (MDException e) { - demangItem = null; - demangled = ""; + return null; } } } diff --git a/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDVS2015TestConfiguration.java b/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDVS2015TestConfiguration.java index 91bcacc150..2ab8e3c80b 100644 --- a/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDVS2015TestConfiguration.java +++ b/Ghidra/Features/MicrosoftDmang/src/test/java/mdemangler/MDVS2015TestConfiguration.java @@ -35,14 +35,12 @@ public class MDVS2015TestConfiguration extends MDBaseTestConfiguration { } @Override - protected void doDemangleSymbol() throws Exception { + protected MDParsableItem doDemangleSymbol(MDMang mdmIn, String mangledIn) throws Exception { try { - demangItem = mdm.demangle(mangled, false); // "false" is different - demangled = demangItem.toString(); + return mdmIn.demangle(mangledIn, false); // "false" is different } catch (MDException e) { - demangItem = null; - demangled = ""; + return null; } } }