diff --git a/ghidra/ghidra_scripts/MSVC7Mangle.java b/ghidra/ghidra_scripts/MSVC7Mangle.java index 84d197c..718ca2b 100644 --- a/ghidra/ghidra_scripts/MSVC7Mangle.java +++ b/ghidra/ghidra_scripts/MSVC7Mangle.java @@ -264,24 +264,29 @@ public class MSVC7Mangle extends GhidraScript{ } private boolean isVirtual(final Function f) { - /* Attempt to determine whether a method is virtual - We essentially try to figure out if any references are from a vtable - by checking if they lie in non-executable memory, or from a scalar - deleting destructor. + /* Determine whether a method is virtual + We essentially check whether any references are from a vtable or a + scalar deleting destructor. */ final Reference[] refs = getReferencesTo(f.getEntryPoint()); for (int i = 0; i < refs.length; i++) { - final Address addr = refs[i].getFromAddress(); - final Optional caller = Optional.ofNullable(getFunctionContaining(addr)) - .map(x -> x.getName(false)); + final Data data = getDataContaining (refs[i].getFromAddress()); + final Function func = getFunctionContaining(refs[i].getFromAddress()); - if ( - !getMemoryBlock(addr).isExecute() || - caller.map(x -> x.equals("`scalar_deleting_destructor'")) - .orElse(false) || - caller.map(x -> x.startsWith("??_G")) // From mangled name - .orElse(false) - ) return true; + if (data != null) { + final String name = getSymbolAt(data.getRoot() + .getAddress()).getName(false); + if ( + name.equals("`vftable'") || + name.startsWith("??_7") + ) return true; + } else if (func != null) { + final String name = func.getName(false); + if ( + name.equals("`scalar_deleting_destructor'") || + name.startsWith("??_G") + ) return true; + } } return false;