summaryrefslogtreecommitdiff
path: root/platform/efi/efi_resolver/src/Plugin.cpp
diff options
context:
space:
mode:
authorZichuan Li <34680029+river-li@users.noreply.github.com>2024-08-15 11:53:05 -0400
committerBrandon Miller <brandon@vector35.com>2025-05-08 07:23:08 -0400
commit7f08117cfeb48a8f48d08e14cb498ee028efcef2 (patch)
tree345eab220c00cfa098e94fa261dce092fc8d5182 /platform/efi/efi_resolver/src/Plugin.cpp
parent64de95854f9ad4da90b9cf2ee69a80f5dddd7a18 (diff)
Move EFI Resolver to API
Support all existing features in EFI Resolver, 1. Doesn't support running on existing BNDBs (though we tried to support this in python plugins, it doesn't work well) 2. Perform analysis on MLIL rather than HLIL, previous pattern matching on HLIL constains many false negatives
Diffstat (limited to 'platform/efi/efi_resolver/src/Plugin.cpp')
-rw-r--r--platform/efi/efi_resolver/src/Plugin.cpp64
1 files changed, 64 insertions, 0 deletions
diff --git a/platform/efi/efi_resolver/src/Plugin.cpp b/platform/efi/efi_resolver/src/Plugin.cpp
new file mode 100644
index 00000000..bfa19a7f
--- /dev/null
+++ b/platform/efi/efi_resolver/src/Plugin.cpp
@@ -0,0 +1,64 @@
+#include "DxeResolver.h"
+#include "PeiResolver.h"
+#include "binaryninjaapi.h"
+#include <thread>
+
+using namespace BinaryNinja;
+
+extern "C" {
+BN_DECLARE_CORE_ABI_VERSION
+
+BINARYNINJAPLUGIN void CorePluginDependencies()
+{
+ BinaryNinja::AddOptionalPluginDependency("arch_x86");
+ BinaryNinja::AddOptionalPluginDependency("arch_armv7");
+ BinaryNinja::AddOptionalPluginDependency("arch_arm64");
+ BinaryNinja::AddOptionalPluginDependency("platform_efi");
+}
+
+static Ref<BackgroundTask> efiBackgroundTask = nullptr;
+
+void Run(Ref<BinaryView> view)
+{
+ efiBackgroundTask = new BackgroundTask("Loading EFI protocol mappings!", true);
+ thread resolverThread([view]() {
+ LogInfo("Entering new thread");
+
+ LogInfo("Identifying module type");
+ EFIModuleType moduleType = identifyModuleType(view);
+
+#ifdef DEBUG
+ auto undo = view->BeginUndoActions();
+#endif
+ if (moduleType == PEI) {
+ efiBackgroundTask->SetProgressText("Resolving PEIM...");
+ auto resolver = PeiResolver(view, efiBackgroundTask);
+ resolver.resolvePei();
+ } else if (moduleType == DXE) {
+ efiBackgroundTask->SetProgressText("Resolving DXE protocols...");
+ auto resolver = DxeResolver(view, efiBackgroundTask);
+ resolver.resolveDxe();
+ efiBackgroundTask->SetProgressText("Resolving MM related protocols...");
+ resolver.resolveSmm();
+ }
+
+#ifdef DEBUG
+ resolver.m_view->CommitUndoActions(undo);
+#endif
+ efiBackgroundTask->Finish();
+ });
+ resolverThread.detach();
+}
+
+BINARYNINJAPLUGIN bool CorePluginInit()
+{
+ EfiGuidRenderer::Register();
+
+ PluginCommand::Register(
+ "EFI Resolver\\Resolve EFI Types And Protocols",
+ "Resolve EFI Protocols",
+ &Run);
+
+ return true;
+}
+}