summaryrefslogtreecommitdiff
path: root/platform/efi/efi_resolver/src/Plugin.cpp
blob: bfa19a7f7a266ab0f876d18524ccd9df1e754511 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
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;
}
}