From 64de95854f9ad4da90b9cf2ee69a80f5dddd7a18 Mon Sep 17 00:00:00 2001 From: Zichuan Li <34680029+river-li@users.noreply.github.com> Date: Tue, 6 Aug 2024 18:05:53 -0400 Subject: Change type for TPIDR_EL0 and run the plugin automatically --- platform/efi/platform_efi.cpp | 107 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 107 insertions(+) diff --git a/platform/efi/platform_efi.cpp b/platform/efi/platform_efi.cpp index 4f30cc35..9f9840b2 100644 --- a/platform/efi/platform_efi.cpp +++ b/platform/efi/platform_efi.cpp @@ -60,6 +60,17 @@ public: { if (!m_idtrtype) m_idtrtype = Type::NamedType(QualifiedName("IDTR32"), GetTypeByName(QualifiedName("IDTR32"))); + + auto ctx = PluginCommandContext(); + ctx.binaryView = view; + auto commandList = PluginCommand::GetValidList(ctx); + for (auto command : commandList) + { + if (command.GetName() == "EFI Resolver\\Resolve EFI Types And Protocols") + { + command.Execute(ctx); + } + } } virtual Ref GetGlobalRegisterType(uint32_t reg) override @@ -124,6 +135,17 @@ public: { if (!m_idtrtype) m_idtrtype = Type::NamedType(QualifiedName("IDTR32"), GetTypeByName(QualifiedName("IDTR32"))); + + auto ctx = PluginCommandContext(); + ctx.binaryView = view; + auto commandList = PluginCommand::GetValidList(ctx); + for (auto command : commandList) + { + if (command.GetName() == "EFI Resolver\\Resolve EFI Types And Protocols") + { + command.Execute(ctx); + } + } } virtual Ref GetGlobalRegisterType(uint32_t reg) override @@ -171,6 +193,17 @@ public: { if (!m_idtrtype) m_idtrtype = Type::NamedType(QualifiedName("IDTR64"), GetTypeByName(QualifiedName("IDTR64"))); + + auto ctx = PluginCommandContext(); + ctx.binaryView = view; + auto commandList = PluginCommand::GetValidList(ctx); + for (auto command : commandList) + { + if (command.GetName() == "EFI Resolver\\Resolve EFI Types And Protocols") + { + command.Execute(ctx); + } + } } virtual Ref GetGlobalRegisterType(uint32_t reg) override @@ -218,6 +251,17 @@ public: { if (!m_idtrtype) m_idtrtype = Type::NamedType(QualifiedName("IDTR64"), GetTypeByName(QualifiedName("IDTR64"))); + + auto ctx = PluginCommandContext(); + ctx.binaryView = view; + auto commandList = PluginCommand::GetValidList(ctx); + for (auto command : commandList) + { + if (command.GetName() == "EFI Resolver\\Resolve EFI Types And Protocols") + { + command.Execute(ctx); + } + } } virtual Ref GetGlobalRegisterType(uint32_t reg) override @@ -261,11 +305,15 @@ public: class EFIArm64Platform : public Platform { + uint32_t m_tpidrel0; + Ref m_tpidrel0type; + public: EFIArm64Platform(Architecture* arch) : Platform(arch, "efi-aarch64") { Ref cc; + m_tpidrel0 = arch->GetRegisterByName("tpidr_el0"); cc = arch->GetCallingConventionByName("cdecl"); if (cc) { @@ -276,6 +324,26 @@ public: } } + virtual void BinaryViewInit(BinaryView* view) override + { + if (!m_tpidrel0type) + m_tpidrel0type = Type::NamedType(QualifiedName("EFI_PEI_SERVICES"), + Type::PointerType(view->GetDefaultArchitecture(), + Type::PointerType( + view->GetDefaultArchitecture(), GetTypeByName(QualifiedName("EFI_PEI_SERVICES"))))); + + auto ctx = PluginCommandContext(); + ctx.binaryView = view; + auto commandList = PluginCommand::GetValidList(ctx); + for (auto command : commandList) + { + if (command.GetName() == "EFI Resolver\\Resolve EFI Types And Protocols") + { + command.Execute(ctx); + } + } + } + static Ref Recognize(BinaryView* view, Metadata* metadata) { Ref subsystem = metadata->Get("Subsystem"); @@ -285,16 +353,27 @@ public: return g_efiArm64; return nullptr; } + + virtual Ref GetGlobalRegisterType(uint32_t reg) override + { + if (reg == m_tpidrel0) + return m_tpidrel0type; + + return nullptr; + } }; class EFIArm64WindowsPlatform : public Platform { + uint32_t m_tpidrel0; + Ref m_tpidrel0type; public: EFIArm64WindowsPlatform(Architecture* arch) : Platform(arch, "efi-windows-aarch64") { Ref cc; + m_tpidrel0 = arch->GetRegisterByName("tpidr_el0"); cc = arch->GetCallingConventionByName("cdecl"); if (cc) { @@ -305,6 +384,26 @@ public: } } + virtual void BinaryViewInit(BinaryView* view) override + { + if (!m_tpidrel0type) + m_tpidrel0type = Type::NamedType(QualifiedName("EFI_PEI_SERVICES"), + Type::PointerType(view->GetDefaultArchitecture(), + Type::PointerType( + view->GetDefaultArchitecture(), GetTypeByName(QualifiedName("EFI_PEI_SERVICES"))))); + + auto ctx = PluginCommandContext(); + ctx.binaryView = view; + auto commandList = PluginCommand::GetValidList(ctx); + for (auto command : commandList) + { + if (command.GetName() == "EFI Resolver\\Resolve EFI Types And Protocols") + { + command.Execute(ctx); + } + } + } + static Ref Recognize(BinaryView* view, Metadata* metadata) { Ref subsystem = metadata->Get("Subsystem"); @@ -314,6 +413,14 @@ public: return g_efiArm64Windows; return nullptr; } + + virtual Ref GetGlobalRegisterType(uint32_t reg) override + { + if (reg == m_tpidrel0) + return m_tpidrel0type; + + return nullptr; + } }; extern "C" -- cgit v1.3.1