MCPcopy Create free account
hub / github.com/lief-project/LIEF / main

Function main

examples/cpp/disassembler.cpp:5–37  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

3using namespace LIEF::logging;
4
5int main(int argc, const char** argv) {
6 if (!LIEF::is_extended()) {
7 err("This example requires the extended version of LIEF");
8 return EXIT_FAILURE;
9 }
10
11 if (argc != 3) {
12 err("Usage: {} <binary> <address>", argv[0]);
13 return EXIT_FAILURE;
14 }
15
16 std::unique_ptr<LIEF::Binary> target = LIEF::Parser::parse(argv[1]);
17
18 if (target == nullptr) {
19 err("Can't parse: {}", argv[1]);
20 return EXIT_FAILURE;
21 }
22
23 std::string add_str = argv[2];
24 uint64_t addr = 0;
25
26 if (add_str.size() > 2 && add_str[0] == '0' && add_str[1] == 'x') {
27 addr = std::strtoull(add_str.c_str() + 2, /*__endptr=*/nullptr, 16);
28 } else {
29 addr = std::strtoull(add_str.c_str(), /*__endptr=*/nullptr, 10);
30 }
31
32 for (std::unique_ptr<LIEF::assembly::Instruction> inst : target->disassemble(addr)) {
33 info("{}", inst->to_string());
34 }
35
36 return EXIT_SUCCESS;
37}

Callers

nothing calls this directly

Calls 8

errFunction · 0.85
c_strMethod · 0.80
is_extendedFunction · 0.50
parseFunction · 0.50
infoFunction · 0.50
sizeMethod · 0.45
disassembleMethod · 0.45
to_stringMethod · 0.45

Tested by

no test coverage detected