summaryrefslogtreecommitdiff
path: root/demangle.cpp
diff options
context:
space:
mode:
authorRusty Wagner <rusty.wagner@gmail.com>2023-01-24 18:38:13 -0700
committerRusty Wagner <rusty.wagner@gmail.com>2023-01-30 11:57:43 -0500
commita3939bdec15f9299ae9a681255fa93c47113870a (patch)
tree2b4bb5643ac3cd25a618a99a542968fe81c66bcc /demangle.cpp
parentcf4220570c2d1b7105fb29719383f64026d46837 (diff)
Fix UAF on C++ BinaryView plugin init, improve demangler and BinaryView APIs
Diffstat (limited to 'demangle.cpp')
-rw-r--r--demangle.cpp26
1 files changed, 14 insertions, 12 deletions
diff --git a/demangle.cpp b/demangle.cpp
index 17879f4f..9239da6d 100644
--- a/demangle.cpp
+++ b/demangle.cpp
@@ -3,14 +3,14 @@
using namespace std;
namespace BinaryNinja {
- bool DemangleMS(Architecture* arch, const std::string& mangledName, Type** outType, QualifiedName& outVarName,
- const Ref<BinaryView>& view)
+ bool DemangleMS(Architecture* arch, const std::string& mangledName, Ref<Type>& outType, QualifiedName& outVarName,
+ BinaryView* view)
{
const bool simplify = Settings::Instance()->Get<bool>("analysis.types.templateSimplifier", view);
return DemangleMS(arch, mangledName, outType, outVarName, simplify);
}
- bool DemangleMS(Architecture* arch, const std::string& mangledName, Type** outType, QualifiedName& outVarName,
+ bool DemangleMS(Architecture* arch, const std::string& mangledName, Ref<Type>& outType, QualifiedName& outVarName,
const bool simplify)
{
BNType* localType = nullptr;
@@ -18,9 +18,7 @@ namespace BinaryNinja {
size_t localSize = 0;
if (!BNDemangleMS(arch->GetObject(), mangledName.c_str(), &localType, &localVarName, &localSize, simplify))
return false;
- if (!localType)
- return false;
- *outType = new Type(BNNewTypeReference(localType));
+ outType = localType ? new Type(BNNewTypeReference(localType)) : nullptr;
for (size_t i = 0; i < localSize; i++)
{
outVarName.push_back(localVarName[i]);
@@ -30,14 +28,14 @@ namespace BinaryNinja {
return true;
}
- bool DemangleGNU3(Ref<Architecture> arch, const std::string& mangledName, Type** outType, QualifiedName& outVarName,
- const Ref<BinaryView>& view)
+ bool DemangleGNU3(Ref<Architecture> arch, const std::string& mangledName, Ref<Type>& outType, QualifiedName& outVarName,
+ BinaryView* view)
{
const bool simplify = Settings::Instance()->Get<bool>("analysis.types.templateSimplifier", view);
return DemangleGNU3(arch, mangledName, outType, outVarName, simplify);
}
- bool DemangleGNU3(Ref<Architecture> arch, const std::string& mangledName, Type** outType, QualifiedName& outVarName,
+ bool DemangleGNU3(Ref<Architecture> arch, const std::string& mangledName, Ref<Type>& outType, QualifiedName& outVarName,
const bool simplify)
{
BNType* localType;
@@ -45,9 +43,7 @@ namespace BinaryNinja {
size_t localSize = 0;
if (!BNDemangleGNU3(arch->GetObject(), mangledName.c_str(), &localType, &localVarName, &localSize, simplify))
return false;
- if (!localType)
- return false;
- *outType = new Type(BNNewTypeReference(localType));
+ outType = localType ? new Type(BNNewTypeReference(localType)) : nullptr;
for (size_t i = 0; i < localSize; i++)
{
outVarName.push_back(localVarName[i]);
@@ -58,6 +54,12 @@ namespace BinaryNinja {
}
+ bool IsGNU3MangledString(const std::string& mangledName)
+ {
+ return BNIsGNU3MangledString(mangledName.c_str());
+ }
+
+
string SimplifyName::to_string(const string& input)
{
return (string)SimplifyName(input, SimplifierDest::str, true);