From ad05dd2072917e2487dcd34dbc249b2a0efac589 Mon Sep 17 00:00:00 2001 From: Rusty Wagner Date: Mon, 25 Jan 2016 15:16:43 -0500 Subject: Initial implementation of platform ABI classes --- platform.cpp | 216 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 216 insertions(+) create mode 100644 platform.cpp (limited to 'platform.cpp') 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 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::GetByName(const string& name) +{ + BNPlatform* platform = BNGetPlatformByName(name.c_str()); + if (!platform) + return nullptr; + return new Platform(platform); +} + + +vector> Platform::GetList() +{ + size_t count; + BNPlatform** list = BNGetPlatformList(&count); + + vector> result; + for (size_t i = 0; i < count; i++) + result.push_back(new Platform(BNNewPlatformReference(list[i]))); + + BNFreePlatformList(list, count); + return result; +} + + +vector> Platform::GetList(Architecture* arch) +{ + size_t count; + BNPlatform** list = BNGetPlatformListByArchitecture(arch->GetArchitectureObject(), &count); + + vector> result; + for (size_t i = 0; i < count; i++) + result.push_back(new Platform(BNNewPlatformReference(list[i]))); + + BNFreePlatformList(list, count); + return result; +} + + +vector> Platform::GetList(const string& os) +{ + size_t count; + BNPlatform** list = BNGetPlatformListByOS(os.c_str(), &count); + + vector> result; + for (size_t i = 0; i < count; i++) + result.push_back(new Platform(BNNewPlatformReference(list[i]))); + + BNFreePlatformList(list, count); + return result; +} + + +vector> Platform::GetList(const string& os, Architecture* arch) +{ + size_t count; + BNPlatform** list = BNGetPlatformListByOSAndArchitecture(os.c_str(), arch->GetArchitectureObject(), &count); + + vector> result; + for (size_t i = 0; i < count; i++) + result.push_back(new Platform(BNNewPlatformReference(list[i]))); + + BNFreePlatformList(list, count); + return result; +} + + +vector Platform::GetOSList() +{ + size_t count; + char** list = BNGetPlatformOSList(&count); + + vector result; + for (size_t i = 0; i < count; i++) + result.push_back(list[i]); + + BNFreePlatformOSList(list, count); + return result; +} + + +Ref Platform::GetDefaultCallingConvention() const +{ + BNCallingConvention* cc = BNGetPlatformDefaultCallingConvention(m_platform); + if (!cc) + return nullptr; + return new CoreCallingConvention(cc); +} + + +Ref Platform::GetCdeclCallingConvention() const +{ + BNCallingConvention* cc = BNGetPlatformCdeclCallingConvention(m_platform); + if (!cc) + return nullptr; + return new CoreCallingConvention(cc); +} + + +Ref Platform::GetStdcallCallingConvention() const +{ + BNCallingConvention* cc = BNGetPlatformStdcallCallingConvention(m_platform); + if (!cc) + return nullptr; + return new CoreCallingConvention(cc); +} + + +Ref Platform::GetFastcallCallingConvention() const +{ + BNCallingConvention* cc = BNGetPlatformFastcallCallingConvention(m_platform); + if (!cc) + return nullptr; + return new CoreCallingConvention(cc); +} + + +vector> Platform::GetCallingConventions() const +{ + size_t count; + BNCallingConvention** list = BNGetPlatformCallingConventions(m_platform, &count); + + vector> 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::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()); +} -- cgit v1.3.1