| 25 | } |
| 26 | |
| 27 | int main(int argc, char* argv[]) |
| 28 | { |
| 29 | if (argc != 2) |
| 30 | { |
| 31 | cerr << "USAGE: " << argv[0] << " <file_name>" << endl; |
| 32 | exit(-1); |
| 33 | } |
| 34 | |
| 35 | char* fname = argv[1]; |
| 36 | if (!is_file(fname)) |
| 37 | { |
| 38 | cerr << "Error: " << fname << " is not a regular file" << endl; |
| 39 | exit(-1); |
| 40 | } |
| 41 | |
| 42 | /* In order to initiate the bundled plugins properly, the location |
| 43 | * of where bundled plugins directory is must be set.*/ |
| 44 | SetBundledPluginDirectory(GetBundledPluginDirectory()); |
| 45 | InitPlugins(); |
| 46 | |
| 47 | Ref<BinaryView> bv = BinaryNinja::Load(fname); |
| 48 | if (!bv || bv->GetTypeName() == "Raw") |
| 49 | { |
| 50 | fprintf(stderr, "Input file does not appear to be an executable\n"); |
| 51 | return -1; |
| 52 | } |
| 53 | |
| 54 | auto arch = bv->GetDefaultArchitecture(); |
| 55 | auto platform = bv->GetDefaultPlatform(); |
| 56 | |
| 57 | auto cc = platform->GetSystemCallConvention(); |
| 58 | if (!cc) |
| 59 | { |
| 60 | cerr << "Error: No system call conventions found for " << platform->GetName() << endl; |
| 61 | exit(-1); |
| 62 | } |
| 63 | |
| 64 | auto reg = cc->GetIntegerArgumentRegisters()[0]; |
| 65 | |
| 66 | for (Function* func : bv->GetAnalysisFunctionList()) |
| 67 | { |
| 68 | auto il_func = func->GetLowLevelIL(); |
| 69 | |
| 70 | for (size_t i = 0; i < il_func->GetInstructionCount(); i++) |
| 71 | { |
| 72 | auto instr = (*il_func)[il_func->GetIndexForInstruction(i)]; |
| 73 | |
| 74 | if (instr.operation == LLIL_SYSCALL) |
| 75 | { |
| 76 | auto reg_value = il_func->GetRegisterValueAtInstruction(reg, i); |
| 77 | |
| 78 | cout << "System call address: 0x" << hex << instr.address << " - " << dec << reg_value.value << endl; |
| 79 | } |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | // Close the file so that the resources can be freed |
| 84 | bv->GetFile()->Close(); |
nothing calls this directly
no test coverage detected