summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--architecture.cpp67
-rw-r--r--binaryninjaapi.h18
-rw-r--r--type.cpp74
3 files changed, 83 insertions, 76 deletions
diff --git a/architecture.cpp b/architecture.cpp
index 14e5b780..98e53b5c 100644
--- a/architecture.cpp
+++ b/architecture.cpp
@@ -556,6 +556,73 @@ void Architecture::SetBinaryViewTypeConstant(const string& type, const string& n
}
+bool Architecture::ParseTypesFromSource(const string& source, const string& fileName,
+ map<string, Ref<Type>>& types, map<string, Ref<Type>>& variables,
+ map<string, Ref<Type>>& functions, string& errors,
+ const vector<string>& includeDirs)
+{
+ BNTypeParserResult result;
+ char* errorStr;
+ const char** includeDirList = new const char*[includeDirs.size()];
+
+ for (size_t i = 0; i < includeDirs.size(); i++)
+ includeDirList[i] = includeDirs[i].c_str();
+
+ types.clear();
+ variables.clear();
+ functions.clear();
+
+ bool ok = BNParseTypesFromSource(m_arch, source.c_str(), fileName.c_str(), &result,
+ &errorStr, includeDirList, includeDirs.size());
+ errors = errorStr;
+ BNFreeString(errorStr);
+ if (!ok)
+ return false;
+
+ for (size_t i = 0; i < result.typeCount; i++)
+ types[result.types[i].name] = new Type(BNNewTypeReference(result.types[i].type));
+ for (size_t i = 0; i < result.variableCount; i++)
+ types[result.variables[i].name] = new Type(BNNewTypeReference(result.variables[i].type));
+ for (size_t i = 0; i < result.functionCount; i++)
+ types[result.functions[i].name] = new Type(BNNewTypeReference(result.functions[i].type));
+ BNFreeTypeParserResult(&result);
+ return true;
+}
+
+
+bool Architecture::ParseTypesFromSourceFile(const string& fileName, map<string, Ref<Type>>& types,
+ map<string, Ref<Type>>& variables, map<string, Ref<Type>>& functions,
+ string& errors, const vector<string>& includeDirs)
+{
+ BNTypeParserResult result;
+ char* errorStr;
+ const char** includeDirList = new const char*[includeDirs.size()];
+
+ for (size_t i = 0; i < includeDirs.size(); i++)
+ includeDirList[i] = includeDirs[i].c_str();
+
+ types.clear();
+ variables.clear();
+ functions.clear();
+
+ bool ok = BNParseTypesFromSourceFile(m_arch, fileName.c_str(), &result, &errorStr,
+ includeDirList, includeDirs.size());
+ errors = errorStr;
+ BNFreeString(errorStr);
+ if (!ok)
+ return false;
+
+ for (size_t i = 0; i < result.typeCount; i++)
+ types[result.types[i].name] = new Type(BNNewTypeReference(result.types[i].type));
+ for (size_t i = 0; i < result.variableCount; i++)
+ variables[result.variables[i].name] = new Type(BNNewTypeReference(result.variables[i].type));
+ for (size_t i = 0; i < result.functionCount; i++)
+ functions[result.functions[i].name] = new Type(BNNewTypeReference(result.functions[i].type));
+ BNFreeTypeParserResult(&result);
+ return true;
+}
+
+
CoreArchitecture::CoreArchitecture(BNArchitecture* arch): Architecture(arch)
{
}
diff --git a/binaryninjaapi.h b/binaryninjaapi.h
index abf4cf2a..61622c5a 100644
--- a/binaryninjaapi.h
+++ b/binaryninjaapi.h
@@ -165,14 +165,6 @@ namespace BinaryNinja
bool PreprocessSource(const std::string& source, const std::string& fileName,
std::string& output, std::string& errors,
const std::vector<std::string>& includeDirs = std::vector<std::string>());
- bool ParseTypesFromSource(Architecture* arch, const std::string& source, const std::string& fileName,
- std::map<std::string, Ref<Type>>& types, std::map<std::string, Ref<Type>>& variables,
- std::map<std::string, Ref<Type>>& functions, std::string& errors,
- const std::vector<std::string>& includeDirs = std::vector<std::string>());
- bool ParseTypesFromSourceFile(Architecture* arch, const std::string& fileName,
- std::map<std::string, Ref<Type>>& types, std::map<std::string, Ref<Type>>& variables,
- std::map<std::string, Ref<Type>>& functions, std::string& errors,
- const std::vector<std::string>& includeDirs = std::vector<std::string>());
void InitCorePlugins();
void InitUserPlugins();
@@ -930,6 +922,15 @@ namespace BinaryNinja
uint64_t GetBinaryViewTypeConstant(const std::string& type, const std::string& name,
uint64_t defaultValue = 0);
void SetBinaryViewTypeConstant(const std::string& type, const std::string& name, uint64_t value);
+
+ bool ParseTypesFromSource(const std::string& source, const std::string& fileName,
+ std::map<std::string, Ref<Type>>& types, std::map<std::string, Ref<Type>>& variables,
+ std::map<std::string, Ref<Type>>& functions, std::string& errors,
+ const std::vector<std::string>& includeDirs = std::vector<std::string>());
+ bool ParseTypesFromSourceFile(const std::string& fileName, std::map<std::string, Ref<Type>>& types,
+ std::map<std::string, Ref<Type>>& variables,
+ std::map<std::string, Ref<Type>>& functions, std::string& errors,
+ const std::vector<std::string>& includeDirs = std::vector<std::string>());
};
class CoreArchitecture: public Architecture
@@ -993,6 +994,7 @@ namespace BinaryNinja
bool IsConst() const;
bool IsFloat() const;
Ref<Type> GetChildType() const;
+ BNCallingConvention GetCallingConvention() const;
std::vector<NameAndType> GetParameters() const;
bool HasVariableArguments() const;
bool CanReturn() const;
diff --git a/type.cpp b/type.cpp
index d1322c1b..45967c6c 100644
--- a/type.cpp
+++ b/type.cpp
@@ -60,6 +60,12 @@ Ref<Type> Type::GetChildType() const
}
+BNCallingConvention Type::GetCallingConvention() const
+{
+ return BNGetTypeCallingConvention(m_type);
+}
+
+
vector<NameAndType> Type::GetParameters() const
{
size_t count;
@@ -386,71 +392,3 @@ bool BinaryNinja::PreprocessSource(const string& source, const string& fileName,
delete[] includeDirList;
return result;
}
-
-
-bool BinaryNinja::ParseTypesFromSource(Architecture* arch, const string& source, const string& fileName,
- map<string, Ref<Type>>& types, map<string, Ref<Type>>& variables,
- map<string, Ref<Type>>& functions, string& errors,
- const vector<string>& includeDirs)
-{
- BNTypeParserResult result;
- char* errorStr;
- const char** includeDirList = new const char*[includeDirs.size()];
-
- for (size_t i = 0; i < includeDirs.size(); i++)
- includeDirList[i] = includeDirs[i].c_str();
-
- types.clear();
- variables.clear();
- functions.clear();
-
- bool ok = BNParseTypesFromSource(arch->GetArchitectureObject(), source.c_str(), fileName.c_str(), &result,
- &errorStr, includeDirList, includeDirs.size());
- errors = errorStr;
- BNFreeString(errorStr);
- if (!ok)
- return false;
-
- for (size_t i = 0; i < result.typeCount; i++)
- types[result.types[i].name] = new Type(BNNewTypeReference(result.types[i].type));
- for (size_t i = 0; i < result.variableCount; i++)
- types[result.variables[i].name] = new Type(BNNewTypeReference(result.variables[i].type));
- for (size_t i = 0; i < result.functionCount; i++)
- types[result.functions[i].name] = new Type(BNNewTypeReference(result.functions[i].type));
- BNFreeTypeParserResult(&result);
- return true;
-}
-
-
-bool BinaryNinja::ParseTypesFromSourceFile(Architecture* arch, const string& fileName,
- map<string, Ref<Type>>& types, map<string, Ref<Type>>& variables,
- map<string, Ref<Type>>& functions, string& errors,
- const vector<string>& includeDirs)
-{
- BNTypeParserResult result;
- char* errorStr;
- const char** includeDirList = new const char*[includeDirs.size()];
-
- for (size_t i = 0; i < includeDirs.size(); i++)
- includeDirList[i] = includeDirs[i].c_str();
-
- types.clear();
- variables.clear();
- functions.clear();
-
- bool ok = BNParseTypesFromSourceFile(arch->GetArchitectureObject(), fileName.c_str(), &result,
- &errorStr, includeDirList, includeDirs.size());
- errors = errorStr;
- BNFreeString(errorStr);
- if (!ok)
- return false;
-
- for (size_t i = 0; i < result.typeCount; i++)
- types[result.types[i].name] = new Type(BNNewTypeReference(result.types[i].type));
- for (size_t i = 0; i < result.variableCount; i++)
- variables[result.variables[i].name] = new Type(BNNewTypeReference(result.variables[i].type));
- for (size_t i = 0; i < result.functionCount; i++)
- functions[result.functions[i].name] = new Type(BNNewTypeReference(result.functions[i].type));
- BNFreeTypeParserResult(&result);
- return true;
-}