@Test public void testDemangleTypeInfo() throws Exception { String mangled = "_ZTIN6AP_HAL3HAL9CallbacksE"; program.startTransaction("markup..."); program.getMemory().setInt(addr("01001000"), 0x1001010); SymbolTable symbolTable = program.getSymbolTable(); symbolTable.createLabel(addr("01001000"), mangled, SourceType.IMPORTED); GnuDemangler demangler = new GnuDemangler(); DemangledObject obj = demangler.demangle(mangled, true); assertNotNull(obj); assertTrue( obj.applyTo(program, addr("01001000"), new DemanglerOptions(), TaskMonitor.DUMMY)); Symbol s = symbolTable.getPrimarySymbol(addr("01001000")); assertNotNull(s); assertEquals("typeinfo", s.getName()); assertEquals("AP_HAL::HAL::Callbacks", s.getParentNamespace().getName(true)); assertEquals("typeinfo for AP_HAL::HAL::Callbacks", program.getListing().getComment(CodeUnit.PLATE_COMMENT, addr("01001000"))); Data d = program.getListing().getDefinedDataAt(addr("01001000")); assertNotNull(d); assertTrue(d.isPointer()); }
@Override public DemangledObject demangle(String mangled, boolean demangleOnlyKnownPatterns) throws DemangledException { if (skip(mangled, demangleOnlyKnownPatterns)) { return null; } String originalMangled = mangled; String globalPrefix = null; if (mangled.startsWith(GLOBAL_PREFIX)) { int index = mangled.indexOf("_Z"); if (index > 0) { globalPrefix = mangled.substring(0, index); mangled = mangled.substring(index); } } else if (mangled.startsWith("__Z")) { mangled = mangled.substring(1); } boolean isDwarf = false; if (mangled.startsWith(DWARF_REF)) { int len = DWARF_REF.length(); mangled = mangled.substring(len); isDwarf = true; } try { GnuDemanglerNativeProcess process = GnuDemanglerNativeProcess.getDemanglerNativeProcess(); String demangled = process.demangle(mangled).trim(); if (mangled.equals(demangled) || demangled.length() == 0) { throw new DemangledException(true); } DemangledObject demangledObject = parse(mangled, process, demangled, demangleOnlyKnownPatterns); if (demangledObject == null) { return demangledObject; } if (globalPrefix != null) { DemangledFunction dfunc = new DemangledFunction(globalPrefix + demangledObject.getName()); dfunc.setNamespace(demangledObject.getNamespace()); demangledObject = dfunc; } else { demangledObject.setSignature(demangled); } demangledObject.setOriginalMangled(originalMangled); if (isDwarf) { DemangledAddressTable dat = new DemangledAddressTable((String) null, 1); dat.setSpecialPrefix("DWARF Debug "); dat.setName(demangledObject.getName()); dat.setNamespace(demangledObject.getNamespace()); dat.setOriginalMangled(originalMangled); return dat; } return demangledObject; } catch (IOException e) { if (e.getMessage().endsWith("14001")) { ResourceFile installationDir = Application.getInstallationDirectory(); throw new DemangledException("Missing runtime libraries. " + "Please install " + installationDir + File.separatorChar + "support" + File.separatorChar + "install_windows_runtime_libraries.exe."); } throw new DemangledException(e); } }
GnuDemangler implements Demangler { @Override public DemangledObject demangle(String mangled, boolean demangleOnlyKnownPatterns) throws DemangledException { if (skip(mangled, demangleOnlyKnownPatterns)) { return null; } String originalMangled = mangled; String globalPrefix = null; if (mangled.startsWith(GLOBAL_PREFIX)) { int index = mangled.indexOf("_Z"); if (index > 0) { globalPrefix = mangled.substring(0, index); mangled = mangled.substring(index); } } else if (mangled.startsWith("__Z")) { mangled = mangled.substring(1); } boolean isDwarf = false; if (mangled.startsWith(DWARF_REF)) { int len = DWARF_REF.length(); mangled = mangled.substring(len); isDwarf = true; } try { GnuDemanglerNativeProcess process = GnuDemanglerNativeProcess.getDemanglerNativeProcess(); String demangled = process.demangle(mangled).trim(); if (mangled.equals(demangled) || demangled.length() == 0) { throw new DemangledException(true); } DemangledObject demangledObject = parse(mangled, process, demangled, demangleOnlyKnownPatterns); if (demangledObject == null) { return demangledObject; } if (globalPrefix != null) { DemangledFunction dfunc = new DemangledFunction(globalPrefix + demangledObject.getName()); dfunc.setNamespace(demangledObject.getNamespace()); demangledObject = dfunc; } else { demangledObject.setSignature(demangled); } demangledObject.setOriginalMangled(originalMangled); if (isDwarf) { DemangledAddressTable dat = new DemangledAddressTable((String) null, 1); dat.setSpecialPrefix("DWARF Debug "); dat.setName(demangledObject.getName()); dat.setNamespace(demangledObject.getNamespace()); dat.setOriginalMangled(originalMangled); return dat; } return demangledObject; } catch (IOException e) { if (e.getMessage().endsWith("14001")) { ResourceFile installationDir = Application.getInstallationDirectory(); throw new DemangledException("Missing runtime libraries. " + "Please install " + installationDir + File.separatorChar + "support" + File.separatorChar + "install_windows_runtime_libraries.exe."); } throw new DemangledException(e); } } }
GnuDemangler implements Demangler { @Override public DemangledObject demangle(String mangled, boolean demangleOnlyKnownPatterns) throws DemangledException { if (skip(mangled, demangleOnlyKnownPatterns)) { return null; } String originalMangled = mangled; String globalPrefix = null; if (mangled.startsWith(GLOBAL_PREFIX)) { int index = mangled.indexOf("_Z"); if (index > 0) { globalPrefix = mangled.substring(0, index); mangled = mangled.substring(index); } } else if (mangled.startsWith("__Z")) { mangled = mangled.substring(1); } boolean isDwarf = false; if (mangled.startsWith(DWARF_REF)) { int len = DWARF_REF.length(); mangled = mangled.substring(len); isDwarf = true; } try { GnuDemanglerNativeProcess process = GnuDemanglerNativeProcess.getDemanglerNativeProcess(); String demangled = process.demangle(mangled).trim(); if (mangled.equals(demangled) || demangled.length() == 0) { throw new DemangledException(true); } DemangledObject demangledObject = parse(mangled, process, demangled, demangleOnlyKnownPatterns); if (demangledObject == null) { return demangledObject; } if (globalPrefix != null) { DemangledFunction dfunc = new DemangledFunction(globalPrefix + demangledObject.getName()); dfunc.setNamespace(demangledObject.getNamespace()); demangledObject = dfunc; } else { demangledObject.setSignature(demangled); } demangledObject.setOriginalMangled(originalMangled); if (isDwarf) { DemangledAddressTable dat = new DemangledAddressTable((String) null, 1); dat.setSpecialPrefix("DWARF Debug "); dat.setName(demangledObject.getName()); dat.setNamespace(demangledObject.getNamespace()); dat.setOriginalMangled(originalMangled); return dat; } return demangledObject; } catch (IOException e) { if (e.getMessage().endsWith("14001")) { ResourceFile installationDir = Application.getInstallationDirectory(); throw new DemangledException("Missing runtime libraries. " + "Please install " + installationDir + File.separatorChar + "support" + File.separatorChar + "install_windows_runtime_libraries.exe."); } throw new DemangledException(e); } } GnuDemangler(); }
GnuDemangler implements Demangler { @Override public DemangledObject demangle(String mangled, boolean demangleOnlyKnownPatterns) throws DemangledException { if (skip(mangled, demangleOnlyKnownPatterns)) { return null; } String originalMangled = mangled; String globalPrefix = null; if (mangled.startsWith(GLOBAL_PREFIX)) { int index = mangled.indexOf("_Z"); if (index > 0) { globalPrefix = mangled.substring(0, index); mangled = mangled.substring(index); } } else if (mangled.startsWith("__Z")) { mangled = mangled.substring(1); } boolean isDwarf = false; if (mangled.startsWith(DWARF_REF)) { int len = DWARF_REF.length(); mangled = mangled.substring(len); isDwarf = true; } try { GnuDemanglerNativeProcess process = GnuDemanglerNativeProcess.getDemanglerNativeProcess(); String demangled = process.demangle(mangled).trim(); if (mangled.equals(demangled) || demangled.length() == 0) { throw new DemangledException(true); } DemangledObject demangledObject = parse(mangled, process, demangled, demangleOnlyKnownPatterns); if (demangledObject == null) { return demangledObject; } if (globalPrefix != null) { DemangledFunction dfunc = new DemangledFunction(globalPrefix + demangledObject.getName()); dfunc.setNamespace(demangledObject.getNamespace()); demangledObject = dfunc; } else { demangledObject.setSignature(demangled); } demangledObject.setOriginalMangled(originalMangled); if (isDwarf) { DemangledAddressTable dat = new DemangledAddressTable((String) null, 1); dat.setSpecialPrefix("DWARF Debug "); dat.setName(demangledObject.getName()); dat.setNamespace(demangledObject.getNamespace()); dat.setOriginalMangled(originalMangled); return dat; } return demangledObject; } catch (IOException e) { if (e.getMessage().endsWith("14001")) { ResourceFile installationDir = Application.getInstallationDirectory(); throw new DemangledException("Missing runtime libraries. " + "Please install " + installationDir + File.separatorChar + "support" + File.separatorChar + "install_windows_runtime_libraries.exe."); } throw new DemangledException(e); } } GnuDemangler(); @Override boolean canDemangle(Program program); @Override DemangledObject demangle(String mangled, boolean demangleOnlyKnownPatterns); }
GnuDemangler implements Demangler { @Override public DemangledObject demangle(String mangled, boolean demangleOnlyKnownPatterns) throws DemangledException { if (skip(mangled, demangleOnlyKnownPatterns)) { return null; } String originalMangled = mangled; String globalPrefix = null; if (mangled.startsWith(GLOBAL_PREFIX)) { int index = mangled.indexOf("_Z"); if (index > 0) { globalPrefix = mangled.substring(0, index); mangled = mangled.substring(index); } } else if (mangled.startsWith("__Z")) { mangled = mangled.substring(1); } boolean isDwarf = false; if (mangled.startsWith(DWARF_REF)) { int len = DWARF_REF.length(); mangled = mangled.substring(len); isDwarf = true; } try { GnuDemanglerNativeProcess process = GnuDemanglerNativeProcess.getDemanglerNativeProcess(); String demangled = process.demangle(mangled).trim(); if (mangled.equals(demangled) || demangled.length() == 0) { throw new DemangledException(true); } DemangledObject demangledObject = parse(mangled, process, demangled, demangleOnlyKnownPatterns); if (demangledObject == null) { return demangledObject; } if (globalPrefix != null) { DemangledFunction dfunc = new DemangledFunction(globalPrefix + demangledObject.getName()); dfunc.setNamespace(demangledObject.getNamespace()); demangledObject = dfunc; } else { demangledObject.setSignature(demangled); } demangledObject.setOriginalMangled(originalMangled); if (isDwarf) { DemangledAddressTable dat = new DemangledAddressTable((String) null, 1); dat.setSpecialPrefix("DWARF Debug "); dat.setName(demangledObject.getName()); dat.setNamespace(demangledObject.getNamespace()); dat.setOriginalMangled(originalMangled); return dat; } return demangledObject; } catch (IOException e) { if (e.getMessage().endsWith("14001")) { ResourceFile installationDir = Application.getInstallationDirectory(); throw new DemangledException("Missing runtime libraries. " + "Please install " + installationDir + File.separatorChar + "support" + File.separatorChar + "install_windows_runtime_libraries.exe."); } throw new DemangledException(e); } } GnuDemangler(); @Override boolean canDemangle(Program program); @Override DemangledObject demangle(String mangled, boolean demangleOnlyKnownPatterns);  }