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

Function main

examples/mlil_parser/src/mlil_parser.cpp:233–335  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

231
232
233int main(int argc, char* argv[])
234{
235 if (argc != 2)
236 {
237 fprintf(stderr, "Expected input filename\n");
238 return 1;
239 }
240
241 // In order to initiate the bundled plugins properly, the location
242 // of where bundled plugins directory must be set
243 SetBundledPluginDirectory(GetBundledPluginDirectory());
244 InitPlugins();
245
246 Ref<BinaryView> bv = BinaryNinja::Load(argv[1]);
247 if (!bv || bv->GetTypeName() == "Raw")
248 {
249 fprintf(stderr, "Input file does not appear to be an executable\n");
250 return -1;
251 }
252
253 // Go through all functions in the binary
254 for (auto& func : bv->GetAnalysisFunctionList())
255 {
256 // Get the name of the function and display it
257 Ref<Symbol> sym = func->GetSymbol();
258 if (sym)
259 printf("Function %s:\n", sym->GetFullName().c_str());
260 else
261 printf("Function at 0x%" PRIx64 ":\n", func->GetStart());
262
263 // Fetch the medium level IL for the function
264 Ref<MediumLevelILFunction> il = func->GetMediumLevelIL();
265 if (!il)
266 {
267 printf(" Does not have MLIL\n\n");
268 continue;
269 }
270
271 // Loop through all blocks in the function
272 for (auto& block : il->GetBasicBlocks())
273 {
274 // Loop though each instruction in the block
275 for (size_t instrIndex = block->GetStart(); instrIndex < block->GetEnd(); instrIndex++)
276 {
277 // Fetch IL instruction
278 MediumLevelILInstruction instr = (*il)[instrIndex];
279
280 // Display core's intrepretation of the IL instruction
281 vector<InstructionTextToken> tokens;
282 il->GetInstructionText(func, func->GetArchitecture(), instrIndex, tokens);
283 printf(" %" PRIdPTR " @ 0x%" PRIx64 " ", instrIndex, instr.address);
284 for (auto& token : tokens)
285 printf("%s", token.text.c_str());
286 printf("\n");
287
288 // Generically parse the IL tree and display the parts
289 PrintILExpr(instr, 2);
290

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
GetMediumLevelILMethod · 0.45
GetBasicBlocksMethod · 0.45
GetEndMethod · 0.45
GetInstructionTextMethod · 0.45

Tested by

no test coverage detected