summaryrefslogtreecommitdiff
path: root/examples/print_syscalls
diff options
context:
space:
mode:
authorKyleMiles <krm504@nyu.edu>2022-01-27 22:43:28 -0500
committerKyleMiles <krm504@nyu.edu>2022-01-28 00:24:06 -0500
commit6812c973c9fa9b4ad642ab81856c05f87bd6fcc4 (patch)
treedace4156d03148bcaf02df138ab4e0d93e61bc6f /examples/print_syscalls
parent519c9db22367f2659d1a54599fab47e6313be06e (diff)
Format All Files
Diffstat (limited to 'examples/print_syscalls')
-rw-r--r--examples/print_syscalls/src/arm-syscall.cpp145
1 files changed, 73 insertions, 72 deletions
diff --git a/examples/print_syscalls/src/arm-syscall.cpp b/examples/print_syscalls/src/arm-syscall.cpp
index e291f30a..e74f8324 100644
--- a/examples/print_syscalls/src/arm-syscall.cpp
+++ b/examples/print_syscalls/src/arm-syscall.cpp
@@ -15,105 +15,106 @@ using namespace BinaryNinja;
using namespace std;
#ifndef _WIN32
-#include <libgen.h>
-#include <dlfcn.h>
+ #include <libgen.h>
+ #include <dlfcn.h>
string get_plugins_directory()
{
- Dl_info info;
- if (!dladdr((void *)BNGetBundledPluginDirectory, &info))
- return NULL;
+ Dl_info info;
+ if (!dladdr((void*)BNGetBundledPluginDirectory, &info))
+ return NULL;
- stringstream ss;
- ss << dirname((char *)info.dli_fname) << "/plugins/";
- return ss.str();
+ stringstream ss;
+ ss << dirname((char*)info.dli_fname) << "/plugins/";
+ return ss.str();
}
#else
string get_plugins_directory()
{
- return "C:\\Program Files\\Vector35\\BinaryNinja\\plugins\\";
+ return "C:\\Program Files\\Vector35\\BinaryNinja\\plugins\\";
}
#endif
-bool is_file(char *fname)
+bool is_file(char* fname)
{
- struct stat buf;
- if (stat(fname, &buf) == 0 && (buf.st_mode & S_IFREG) == S_IFREG)
- return true;
+ struct stat buf;
+ if (stat(fname, &buf) == 0 && (buf.st_mode & S_IFREG) == S_IFREG)
+ return true;
- return false;
+ return false;
}
-int main(int argc, char *argv[])
+int main(int argc, char* argv[])
{
- if (argc != 2) {
- cerr << "USAGE: " << argv[0] << " <file_name>" << endl;
- exit(-1);
- }
+ if (argc != 2)
+ {
+ cerr << "USAGE: " << argv[0] << " <file_name>" << endl;
+ exit(-1);
+ }
- char *fname = argv[1];
- if (!is_file(fname)) {
- cerr << "Error: " << fname << " is not a regular file" << endl;
- exit(-1);
- }
+ char* fname = argv[1];
+ if (!is_file(fname))
+ {
+ cerr << "Error: " << fname << " is not a regular file" << endl;
+ exit(-1);
+ }
- /* In order to initiate the bundled plugins properly, the location
- * of where bundled plugins directory is must be set. Since
- * libbinaryninjacore is in the path get the path to it and use it to
- * determine the plugins directory */
- SetBundledPluginDirectory(get_plugins_directory());
- InitPlugins();
+ /* In order to initiate the bundled plugins properly, the location
+ * of where bundled plugins directory is must be set. Since
+ * libbinaryninjacore is in the path get the path to it and use it to
+ * determine the plugins directory */
+ SetBundledPluginDirectory(get_plugins_directory());
+ InitPlugins();
- Ref<BinaryData> bd = new BinaryData(new FileMetadata(), argv[1]);
- Ref<BinaryView> bv;
- for (auto type : BinaryViewType::GetViewTypes())
- {
- if (type->IsTypeValidForData(bd) && type->GetName() != "Raw")
- {
- bv = type->Create(bd);
- break;
- }
- }
+ Ref<BinaryData> bd = new BinaryData(new FileMetadata(), argv[1]);
+ Ref<BinaryView> bv;
+ for (auto type : BinaryViewType::GetViewTypes())
+ {
+ if (type->IsTypeValidForData(bd) && type->GetName() != "Raw")
+ {
+ bv = type->Create(bd);
+ break;
+ }
+ }
- if (!bv || bv->GetTypeName() == "Raw")
- {
- fprintf(stderr, "Input file does not appear to be an exectuable\n");
- return -1;
- }
+ if (!bv || bv->GetTypeName() == "Raw")
+ {
+ fprintf(stderr, "Input file does not appear to be an exectuable\n");
+ return -1;
+ }
- bv->UpdateAnalysisAndWait();
+ bv->UpdateAnalysisAndWait();
- auto arch = bv->GetDefaultArchitecture();
- auto platform = bv->GetDefaultPlatform();
+ auto arch = bv->GetDefaultArchitecture();
+ auto platform = bv->GetDefaultPlatform();
- auto cc = platform->GetSystemCallConvention();
- if (!cc) {
- cerr << "Error: No system call conventions found for "
- << platform->GetName() << endl;
- exit(-1);
- }
+ auto cc = platform->GetSystemCallConvention();
+ if (!cc)
+ {
+ cerr << "Error: No system call conventions found for " << platform->GetName() << endl;
+ exit(-1);
+ }
- auto reg = cc->GetIntegerArgumentRegisters()[0];
+ auto reg = cc->GetIntegerArgumentRegisters()[0];
- for (Function *func : bv->GetAnalysisFunctionList()) {
- auto il_func = func->GetLowLevelIL();
+ for (Function* func : bv->GetAnalysisFunctionList())
+ {
+ auto il_func = func->GetLowLevelIL();
- for (size_t i = 0; i < il_func->GetInstructionCount(); i++) {
- auto instr = (*il_func)[il_func->GetIndexForInstruction(i)];
+ for (size_t i = 0; i < il_func->GetInstructionCount(); i++)
+ {
+ auto instr = (*il_func)[il_func->GetIndexForInstruction(i)];
- if (instr.operation == LLIL_SYSCALL) {
- auto reg_value = il_func->GetRegisterValueAtInstruction(reg, i);
+ if (instr.operation == LLIL_SYSCALL)
+ {
+ auto reg_value = il_func->GetRegisterValueAtInstruction(reg, i);
- cout << "System call address: 0x"
- << hex << instr.address
- << " - "
- << dec << reg_value.value
- << endl;
- }
- }
- }
+ cout << "System call address: 0x" << hex << instr.address << " - " << dec << reg_value.value << endl;
+ }
+ }
+ }
- // Shutting down is required to allow for clean exit of the core
- BNShutdown();
+ // Shutting down is required to allow for clean exit of the core
+ BNShutdown();
- return 0;
+ return 0;
}