summaryrefslogtreecommitdiff
path: root/platform.cpp
diff options
context:
space:
mode:
authorRusty Wagner <rusty@vector35.com>2016-01-25 15:16:43 -0500
committerRusty Wagner <rusty.wagner@gmail.com>2016-01-25 23:13:23 -0500
commitad05dd2072917e2487dcd34dbc249b2a0efac589 (patch)
tree0392cd11853a91cbde36c0a8939116a5659fa1d3 /platform.cpp
parentc2b2e11c009fa9b9c6c4a0fbba9210cb997e38ce (diff)
Initial implementation of platform ABI classes
Diffstat (limited to 'platform.cpp')
-rw-r--r--platform.cpp216
1 files changed, 216 insertions, 0 deletions
diff --git a/platform.cpp b/platform.cpp
new file mode 100644
index 00000000..26d3b945
--- /dev/null
+++ b/platform.cpp
@@ -0,0 +1,216 @@
+#include "binaryninjaapi.h"
+
+using namespace std;
+using namespace BinaryNinja;
+
+
+Platform::Platform(BNPlatform* platform): m_platform(platform)
+{
+}
+
+
+Platform::Platform(Architecture* arch, const string& name)
+{
+ m_platform = BNCreatePlatform(arch->GetArchitectureObject(), name.c_str());
+}
+
+
+Platform::~Platform()
+{
+ BNFreePlatform(m_platform);
+}
+
+
+Ref<Architecture> Platform::GetArchitecture() const
+{
+ return new CoreArchitecture(BNGetPlatformArchitecture(m_platform));
+}
+
+
+string Platform::GetName() const
+{
+ char* str = BNGetPlatformName(m_platform);
+ string result = str;
+ BNFreeString(str);
+ return result;
+}
+
+
+void Platform::Register(const string& os, Platform* platform)
+{
+ BNRegisterPlatform(os.c_str(), platform->GetPlatformObject());
+}
+
+
+Ref<Platform> Platform::GetByName(const string& name)
+{
+ BNPlatform* platform = BNGetPlatformByName(name.c_str());
+ if (!platform)
+ return nullptr;
+ return new Platform(platform);
+}
+
+
+vector<Ref<Platform>> Platform::GetList()
+{
+ size_t count;
+ BNPlatform** list = BNGetPlatformList(&count);
+
+ vector<Ref<Platform>> result;
+ for (size_t i = 0; i < count; i++)
+ result.push_back(new Platform(BNNewPlatformReference(list[i])));
+
+ BNFreePlatformList(list, count);
+ return result;
+}
+
+
+vector<Ref<Platform>> Platform::GetList(Architecture* arch)
+{
+ size_t count;
+ BNPlatform** list = BNGetPlatformListByArchitecture(arch->GetArchitectureObject(), &count);
+
+ vector<Ref<Platform>> result;
+ for (size_t i = 0; i < count; i++)
+ result.push_back(new Platform(BNNewPlatformReference(list[i])));
+
+ BNFreePlatformList(list, count);
+ return result;
+}
+
+
+vector<Ref<Platform>> Platform::GetList(const string& os)
+{
+ size_t count;
+ BNPlatform** list = BNGetPlatformListByOS(os.c_str(), &count);
+
+ vector<Ref<Platform>> result;
+ for (size_t i = 0; i < count; i++)
+ result.push_back(new Platform(BNNewPlatformReference(list[i])));
+
+ BNFreePlatformList(list, count);
+ return result;
+}
+
+
+vector<Ref<Platform>> Platform::GetList(const string& os, Architecture* arch)
+{
+ size_t count;
+ BNPlatform** list = BNGetPlatformListByOSAndArchitecture(os.c_str(), arch->GetArchitectureObject(), &count);
+
+ vector<Ref<Platform>> result;
+ for (size_t i = 0; i < count; i++)
+ result.push_back(new Platform(BNNewPlatformReference(list[i])));
+
+ BNFreePlatformList(list, count);
+ return result;
+}
+
+
+vector<std::string> Platform::GetOSList()
+{
+ size_t count;
+ char** list = BNGetPlatformOSList(&count);
+
+ vector<string> result;
+ for (size_t i = 0; i < count; i++)
+ result.push_back(list[i]);
+
+ BNFreePlatformOSList(list, count);
+ return result;
+}
+
+
+Ref<CallingConvention> Platform::GetDefaultCallingConvention() const
+{
+ BNCallingConvention* cc = BNGetPlatformDefaultCallingConvention(m_platform);
+ if (!cc)
+ return nullptr;
+ return new CoreCallingConvention(cc);
+}
+
+
+Ref<CallingConvention> Platform::GetCdeclCallingConvention() const
+{
+ BNCallingConvention* cc = BNGetPlatformCdeclCallingConvention(m_platform);
+ if (!cc)
+ return nullptr;
+ return new CoreCallingConvention(cc);
+}
+
+
+Ref<CallingConvention> Platform::GetStdcallCallingConvention() const
+{
+ BNCallingConvention* cc = BNGetPlatformStdcallCallingConvention(m_platform);
+ if (!cc)
+ return nullptr;
+ return new CoreCallingConvention(cc);
+}
+
+
+Ref<CallingConvention> Platform::GetFastcallCallingConvention() const
+{
+ BNCallingConvention* cc = BNGetPlatformFastcallCallingConvention(m_platform);
+ if (!cc)
+ return nullptr;
+ return new CoreCallingConvention(cc);
+}
+
+
+vector<Ref<CallingConvention>> Platform::GetCallingConventions() const
+{
+ size_t count;
+ BNCallingConvention** list = BNGetPlatformCallingConventions(m_platform, &count);
+
+ vector<Ref<CallingConvention>> result;
+ for (size_t i = 0; i < count; i++)
+ result.push_back(new CoreCallingConvention(BNNewCallingConventionReference(list[i])));
+
+ BNFreeCallingConventionList(list, count);
+ return result;
+}
+
+
+void Platform::RegisterCallingConvention(CallingConvention* cc)
+{
+ BNRegisterPlatformCallingConvention(m_platform, cc->GetCallingConventionObject());
+}
+
+
+void Platform::RegisterDefaultCallingConvention(CallingConvention* cc)
+{
+ BNRegisterPlatformDefaultCallingConvention(m_platform, cc->GetCallingConventionObject());
+}
+
+
+void Platform::RegisterCdeclCallingConvention(CallingConvention* cc)
+{
+ BNRegisterPlatformCdeclCallingConvention(m_platform, cc->GetCallingConventionObject());
+}
+
+
+void Platform::RegisterStdcallCallingConvention(CallingConvention* cc)
+{
+ BNRegisterPlatformStdcallCallingConvention(m_platform, cc->GetCallingConventionObject());
+}
+
+
+void Platform::RegisterFastcallCallingConvention(CallingConvention* cc)
+{
+ BNRegisterPlatformFastcallCallingConvention(m_platform, cc->GetCallingConventionObject());
+}
+
+
+Ref<Platform> Platform::GetRelatedPlatform(Architecture* arch)
+{
+ BNPlatform* platform = BNGetRelatedPlatform(m_platform, arch->GetArchitectureObject());
+ if (!platform)
+ return nullptr;
+ return new Platform(platform);
+}
+
+
+void Platform::AddRelatedPlatform(Architecture* arch, Platform* platform)
+{
+ BNAddRelatedPlatform(m_platform, arch->GetArchitectureObject(), platform->GetPlatformObject());
+}