MCPcopy Create free account
hub / github.com/Vector35/binaryninja-api / main

Function main

examples/llil_parser/src/llil_parser.cpp:282–391  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

280
281
282int main(int argc, char* argv[])
283{
284 if (argc != 2)
285 {
286 fprintf(stderr, "Expected input filename\n");
287 return 1;
288 }
289
290 // In order to initiate the bundled plugins properly, the location
291 // of where bundled plugins directory is must be set.
292 SetBundledPluginDirectory(GetBundledPluginDirectory());
293 InitPlugins();
294
295 Ref<BinaryView> bv = BinaryNinja::Load(argv[1]);
296 if (!bv || bv->GetTypeName() == "Raw")
297 {
298 fprintf(stderr, "Input file does not appear to be an executable\n");
299 return -1;
300 }
301
302 // Go through all functions in the binary
303 for (auto& func : bv->GetAnalysisFunctionList())
304 {
305 // Get the name of the function and display it
306 Ref<Symbol> sym = func->GetSymbol();
307 if (sym)
308 printf("Function %s:\n", sym->GetFullName().c_str());
309 else
310 printf("Function at 0x%" PRIx64 ":\n", func->GetStart());
311
312 // Fetch the low level IL for the function
313 Ref<LowLevelILFunction> il = func->GetLowLevelIL();
314 if (!il)
315 {
316 printf(" Does not have LLIL\n\n");
317 continue;
318 }
319
320 // Loop through all blocks in the function
321 for (auto& block : il->GetBasicBlocks())
322 {
323 // Loop though each instruction in the block
324 for (size_t instrIndex = block->GetStart(); instrIndex < block->GetEnd(); instrIndex++)
325 {
326 // Fetch IL instruction
327 LowLevelILInstruction instr = (*il)[instrIndex];
328
329 // Display core's intrepretation of the IL instruction
330 vector<InstructionTextToken> tokens;
331 il->GetInstructionText(func, func->GetArchitecture(), instrIndex, tokens);
332 printf(" %" PRIdPTR " @ 0x%" PRIx64 " ", instrIndex, instr.address);
333 for (auto& token : tokens)
334 printf("%s", token.text.c_str());
335 printf("\n");
336
337 // Generically parse the IL tree and display the parts
338 PrintILExpr(instr, 2);
339

Callers

nothing calls this directly

Calls 15

c_strMethod · 0.80
GetFullNameMethod · 0.80
PrintILExprFunction · 0.70
LoadFunction · 0.50
GetTypeNameMethod · 0.45
GetSymbolMethod · 0.45
GetStartMethod · 0.45
GetLowLevelILMethod · 0.45
GetBasicBlocksMethod · 0.45
GetEndMethod · 0.45
GetInstructionTextMethod · 0.45

Tested by

no test coverage detected