-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.cpp
More file actions
48 lines (38 loc) · 1.31 KB
/
main.cpp
File metadata and controls
48 lines (38 loc) · 1.31 KB
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
#include "emulator.hpp"
#include <cstdio>
using namespace BinaryNinja;
int main(const int argc, char* argv[])
{
if (argc != 3) {
fprintf(stderr, "Usage: ./bnil-emulator <binary path> <starting function>\n");
return 1;
}
// In order to initiate the bundled plugins properly, the location
// of where bundled plugins directory is must be set.
SetBundledPluginDirectory(GetBundledPluginDirectory());
InitPlugins(true);
LogToStdout(InfoLog);
const Ref<BinaryView> bv = Load(argv[1], true);
bv->UpdateAnalysisAndWait();
const auto log = LogRegistry::CreateLogger(plugin_name);
if (!bv || bv->GetTypeName() == "Raw") {
log->LogError("Input file does not appear to be an executable\n");
return -1;
}
// Get `main` function
const Ref<Symbol> sym = bv->GetSymbolByRawName(argv[2]);
if (!sym) {
log->LogError("Unable to find \"%s\" in the binary", argv[2]);
}
const Ref<Function> func = bv->GetAnalysisFunction(bv->GetDefaultPlatform(), sym->GetAddress());
const Ref<LowLevelILFunction> llil_func = func->GetLowLevelIL();
const auto emu_state = new Emulator(bv);
if (!llil_func) {
log->LogError("[!] LLIL is not available for %s @ 0x%llx\n", sym->GetFullName().c_str(), sym->GetAddress());
delete emu_state;
return -1;
}
emu_state->emulate_llil(llil_func);
emu_state->dump_registers();
return 0;
}