MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / DemangleNameGNU3

Method DemangleNameGNU3

plugins/rtti/rtti.cpp:17–48  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

15
16
17std::optional<std::string> RTTI::DemangleNameGNU3(BinaryView* view, bool allowMangled, const std::string &mangledName)
18{
19 QualifiedName demangledName = {};
20 Ref<Type> outType = {};
21
22 std::string adjustedMangledName = mangledName;
23 // For some reason some of the names that start with ZN are not prefixed by `_`.
24 if (adjustedMangledName.rfind("ZN", 0) == 0)
25 adjustedMangledName = "_" + adjustedMangledName;
26 // GCC emits a leading * to indicate that the type info is internal and its
27 // name can be compared via pointer equality. It is not part of the type name.
28 if (adjustedMangledName.rfind("*", 0) == 0)
29 adjustedMangledName = adjustedMangledName.substr(1);
30 // All types at this point should have a _Z prefix, if not, we likely need to just call the demangler directly, as this
31 // function is specific to dealing with mangled _type_ names.
32 if (adjustedMangledName.rfind("_Z", 0) != 0)
33 adjustedMangledName = "_Z" + adjustedMangledName;
34
35 if (!DemangleGNU3(view->GetDefaultArchitecture(), adjustedMangledName, outType, demangledName, true))
36 return allowMangled ? std::optional(mangledName) : std::nullopt;
37
38 // Because we might have a generic name such as "PackageListGui::PackageListGui" returned, we must attempt to
39 // stringify the returned type IF its function type and then append that to the end of the demangled name.
40 // REAL: PackageListGui::PackageListGui(Filesystem::Path&&, PackageListGui::UnderSubheader, bool)::$_1[0x0]
41 // MANGLED: ZN14PackageListGuiC1EON10Filesystem4PathENS_14UnderSubheaderEbE3$_1
42 // GENERIC DEMANGLED: PackageListGui::PackageListGui
43 // UPDATED DEMANGLED: PackageListGui::PackageListGui(Filesystem::Path&&, PackageListGui::UnderSubheader, bool)
44 if (outType && outType->IsFunction())
45 demangledName.push_back(outType->GetStringAfterName(view->GetDefaultPlatform()));
46
47 return demangledName.GetString();
48}
49
50
51std::string RemoveItaniumPrefix(std::string &name)

Callers

nothing calls this directly

Calls 7

push_backMethod · 0.80
GetStringAfterNameMethod · 0.80
GetDefaultPlatformMethod · 0.80
DemangleGNU3Function · 0.50
IsFunctionMethod · 0.45
GetStringMethod · 0.45

Tested by

no test coverage detected