From 56115aecf186bc720dae9a20cc4c6aef248ba07f Mon Sep 17 00:00:00 2001 From: Ryan Snyder Date: Fri, 24 May 2024 14:47:15 -0400 Subject: platform: initial BNCustomPlatform support --- platform/windows/platform_windows.cpp | 42 +++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) (limited to 'platform') diff --git a/platform/windows/platform_windows.cpp b/platform/windows/platform_windows.cpp index 2b0a427f..cb256660 100644 --- a/platform/windows/platform_windows.cpp +++ b/platform/windows/platform_windows.cpp @@ -7,11 +7,16 @@ using namespace std; class WindowsX86Platform: public Platform { + uint32_t m_fsbase; + Ref m_teb; + public: WindowsX86Platform(Architecture* arch): Platform(arch, "windows-x86") { Ref cc; + m_fsbase = arch->GetRegisterByName("fsbase"); + cc = arch->GetCallingConventionByName("cdecl"); if (cc) { @@ -36,14 +41,35 @@ public: if (cc) RegisterCallingConvention(cc); } + + + virtual void BinaryViewInit(BinaryView* view) override + { + if (!m_teb) + m_teb = Type::PointerType(GetArchitecture()->GetAddressSize(), Type::NamedType(QualifiedName("TEB"), GetTypeByName(QualifiedName("TEB")))); + } + + + virtual Ref GetGlobalRegisterType(uint32_t reg) override + { + if (reg == m_fsbase) + return m_teb; + + return nullptr; + } }; class WindowsX64Platform: public Platform { + uint32_t m_gsbase; + Ref m_teb; + public: WindowsX64Platform(Architecture* arch): Platform(arch, "windows-x86_64") { + m_gsbase = arch->GetRegisterByName("gsbase"); + Ref cc; cc = arch->GetCallingConventionByName("win64"); @@ -55,6 +81,22 @@ public: RegisterStdcallCallingConvention(cc); } } + + + virtual void BinaryViewInit(BinaryView* view) override + { + if (!m_teb) + m_teb = Type::PointerType(GetArchitecture()->GetAddressSize(), Type::NamedType(QualifiedName("TEB"), GetTypeByName(QualifiedName("TEB")))); + } + + + virtual Ref GetGlobalRegisterType(uint32_t reg) override + { + if (reg == m_gsbase) + return m_teb; + + return nullptr; + } }; -- cgit v1.3.1