diff options
| author | KyleMiles <krm504@nyu.edu> | 2022-01-27 22:43:28 -0500 |
|---|---|---|
| committer | KyleMiles <krm504@nyu.edu> | 2022-01-28 00:24:06 -0500 |
| commit | 6812c973c9fa9b4ad642ab81856c05f87bd6fcc4 (patch) | |
| tree | dace4156d03148bcaf02df138ab4e0d93e61bc6f /examples | |
| parent | 519c9db22367f2659d1a54599fab47e6313be06e (diff) | |
Format All Files
Diffstat (limited to 'examples')
31 files changed, 788 insertions, 772 deletions
diff --git a/examples/bin-info/src/bin-info.cpp b/examples/bin-info/src/bin-info.cpp index 33f84f7d..9503c734 100644 --- a/examples/bin-info/src/bin-info.cpp +++ b/examples/bin-info/src/bin-info.cpp @@ -16,107 +16,109 @@ 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(); - cout << "Target: " << fname << endl << endl; - cout << "TYPE: " << bv->GetTypeName() << endl; - cout << "START: 0x" << hex << bv->GetStart() << endl; - cout << "ENTRY: 0x" << hex << bv->GetEntryPoint() << endl; - cout << "PLATFORM: " << bv->GetDefaultPlatform()->GetName() << endl; - cout << endl; + cout << "Target: " << fname << endl << endl; + cout << "TYPE: " << bv->GetTypeName() << endl; + cout << "START: 0x" << hex << bv->GetStart() << endl; + cout << "ENTRY: 0x" << hex << bv->GetEntryPoint() << endl; + cout << "PLATFORM: " << bv->GetDefaultPlatform()->GetName() << endl; + cout << endl; - cout << "---------- 10 Functions ----------" << endl; - int x = 0; - for (auto func : bv->GetAnalysisFunctionList()) { - cout << hex << func->GetStart() << " " << func->GetSymbol()->GetFullName() << endl; - if (++x >= 10) - break; - } - cout << endl; + cout << "---------- 10 Functions ----------" << endl; + int x = 0; + for (auto func : bv->GetAnalysisFunctionList()) + { + cout << hex << func->GetStart() << " " << func->GetSymbol()->GetFullName() << endl; + if (++x >= 10) + break; + } + cout << endl; - cout << "---------- 10 Strings ----------" << endl; - x = 0; - for (auto str_ref : bv->GetStrings()) { - char *str = (char *)malloc(str_ref.length+1); - bv->Read(str, str_ref.start, str_ref.length); - str[str_ref.length] = 0; + cout << "---------- 10 Strings ----------" << endl; + x = 0; + for (auto str_ref : bv->GetStrings()) + { + char* str = (char*)malloc(str_ref.length + 1); + bv->Read(str, str_ref.start, str_ref.length); + str[str_ref.length] = 0; - cout << hex << str_ref.start << " (" - << dec << str_ref.length << ") " - << str << endl; - free(str); + cout << hex << str_ref.start << " (" << dec << str_ref.length << ") " << str << endl; + free(str); - if (++x >= 10) - break; - } + if (++x >= 10) + break; + } - // 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; } diff --git a/examples/breakpoint/src/breakpoint.cpp b/examples/breakpoint/src/breakpoint.cpp index 65c8d018..75156e1d 100644 --- a/examples/breakpoint/src/breakpoint.cpp +++ b/examples/breakpoint/src/breakpoint.cpp @@ -4,35 +4,37 @@ using namespace BinaryNinja; using namespace std; -void write_breakpoint(BinaryNinja::BinaryView *view, uint64_t start, uint64_t length) +void write_breakpoint(BinaryNinja::BinaryView* view, uint64_t start, uint64_t length) { - // Sample function to show registering a plugin menu item for a range of bytes. - // Also possible: - // register - // register_for_address - // register_for_function + // Sample function to show registering a plugin menu item for a range of bytes. + // Also possible: + // register + // register_for_address + // register_for_function - Ref<Architecture> arch = view->GetDefaultArchitecture(); - string arch_name = arch->GetName(); + Ref<Architecture> arch = view->GetDefaultArchitecture(); + string arch_name = arch->GetName(); - if (arch_name.compare(0, 3, "x86") == 0) { - string int3s = string(length, '\xcc'); - view->Write(start, int3s.c_str(), length); - } else { - LogError("No support for breakpoint on %s", arch_name.c_str()); - } + if (arch_name.compare(0, 3, "x86") == 0) + { + string int3s = string(length, '\xcc'); + view->Write(start, int3s.c_str(), length); + } + else + { + LogError("No support for breakpoint on %s", arch_name.c_str()); + } } extern "C" { - BN_DECLARE_CORE_ABI_VERSION + BN_DECLARE_CORE_ABI_VERSION - BINARYNINJAPLUGIN bool CorePluginInit() - { - // Register the plugin with Binary Ninja - PluginCommand::RegisterForRange("Convert to breakpoint", - "Fill region with breakpoint instructions.", - &write_breakpoint); - return true; - } + BINARYNINJAPLUGIN bool CorePluginInit() + { + // Register the plugin with Binary Ninja + PluginCommand::RegisterForRange( + "Convert to breakpoint", "Fill region with breakpoint instructions.", &write_breakpoint); + return true; + } }
\ No newline at end of file diff --git a/examples/cmdline_disasm/src/disasm.cpp b/examples/cmdline_disasm/src/disasm.cpp index 6d350526..49d4d650 100644 --- a/examples/cmdline_disasm/src/disasm.cpp +++ b/examples/cmdline_disasm/src/disasm.cpp @@ -12,14 +12,14 @@ using namespace BinaryNinja; /* forward declarations */ -int parse_nib(const char *str, uint8_t *val); -int parse_uint8_hex(const char *str, uint8_t *result); +int parse_nib(const char* str, uint8_t* val); +int parse_uint8_hex(const char* str, uint8_t* result); /****************************************************************************** MAIN ******************************************************************************/ -void usage(int ac, char **av) +void usage(int ac, char** av) { (void)ac; printf(" syntax: %s <arch+mode> <byte0> <byte1> ...\n", av[0]); @@ -36,23 +36,23 @@ void usage(int ac, char **av) printf(" %s mipsel32 f0 ff bd 27\n", av[0]); } -int main(int ac, char **av) +int main(int ac, char** av) { int rc = -1; unsigned int i; - char *archmode; - BNArchitecture *arch; + char* archmode; + BNArchitecture* arch; - size_t nBytesDisasm; + size_t nBytesDisasm; - uint8_t input[64]; - unsigned int input_n; + uint8_t input[64]; + unsigned int input_n; - BNInstructionTextToken *ttResult = NULL; - size_t ttCount; + BNInstructionTextToken* ttResult = NULL; + size_t ttCount; - char *path_bundled_plugins; + char* path_bundled_plugins; /* plugin path */ path_bundled_plugins = BNGetBundledPluginDirectory(); @@ -61,13 +61,17 @@ int main(int ac, char **av) BNInitPlugins(true); /* parse architecture argument */ - if(ac < 2) - { usage(ac, av); goto cleanup; } + if (ac < 2) + { + usage(ac, av); + goto cleanup; + } archmode = av[1]; printf("looking up architecture \"%s\"\n", archmode); arch = BNGetArchitectureByName(archmode); - if(!arch) { + if (!arch) + { printf("ERROR: BNGetArchitectureByName() (is \"%s\" valid?)\n", archmode); usage(ac, av); goto cleanup; @@ -75,32 +79,33 @@ int main(int ac, char **av) /* parse bytes argument */ input_n = ac - 2; - for(i=0; i<input_n && i<sizeof(input); ++i) { - if(parse_uint8_hex(av[i+2], input+i)) { - printf("ERROR: can't parse byte: %s\n", av[i+2]); + for (i = 0; i < input_n && i < sizeof(input); ++i) + { + if (parse_uint8_hex(av[i + 2], input + i)) + { + printf("ERROR: can't parse byte: %s\n", av[i + 2]); goto cleanup; } } printf("parsed bytes: "); - for(i=0; i<input_n; ++i) + for (i = 0; i < input_n; ++i) printf("%02X ", input[i]); printf("\n"); /* actually disassemble now */ nBytesDisasm = input_n; - BNGetInstructionText(arch, (const uint8_t *)input, 0, &nBytesDisasm, - &ttResult, &ttCount); + BNGetInstructionText(arch, (const uint8_t*)input, 0, &nBytesDisasm, &ttResult, &ttCount); - //printf("%zu text tokens\n", ttCount); + // printf("%zu text tokens\n", ttCount); - for(i=0; i<ttCount; ++i) + for (i = 0; i < ttCount; ++i) printf("%s", ttResult[i].text); printf("\n"); - /* done! */ - cleanup: - if(ttResult) +/* done! */ +cleanup: + if (ttResult) BNFreeInstructionText(ttResult, ttCount); // Shutting down is required to allow for clean exit of the core @@ -113,44 +118,47 @@ int main(int ac, char **av) PARSING ******************************************************************************/ -int parse_nib(const char *str, uint8_t *val) +int parse_nib(const char* str, uint8_t* val) { int rc = -1; char c = *str; - if(c>='0' && c<='9') { - *val = c-'0'; + if (c >= '0' && c <= '9') + { + *val = c - '0'; rc = 0; } - else if(c>='a' && c<='f') { - *val = 10 + (c-'a'); + else if (c >= 'a' && c <= 'f') + { + *val = 10 + (c - 'a'); rc = 0; } - else if(c>='A' && c<='F') { - *val = 10 + (c-'A'); + else if (c >= 'A' && c <= 'F') + { + *val = 10 + (c - 'A'); rc = 0; } - else { + else + { printf("ERROR: %s('%c', ...)\n", __func__, c); } return rc; } -int parse_uint8_hex(const char *str, uint8_t *result) +int parse_uint8_hex(const char* str, uint8_t* result) { - int rc=-1; + int rc = -1; uint8_t v1, v2; - if(parse_nib(str, &v1)) + if (parse_nib(str, &v1)) goto cleanup; - if(parse_nib(str+1, &v2)) + if (parse_nib(str + 1, &v2)) goto cleanup; *result = (v1 << 4) | v2; rc = 0; - cleanup: +cleanup: return rc; } - diff --git a/examples/llil_parser/src/llil_parser.cpp b/examples/llil_parser/src/llil_parser.cpp index b7c96c22..d700e7ce 100644 --- a/examples/llil_parser/src/llil_parser.cpp +++ b/examples/llil_parser/src/llil_parser.cpp @@ -9,16 +9,16 @@ using namespace std; #ifndef _WIN32 -#include <libgen.h> -#include <dlfcn.h> + #include <libgen.h> + #include <dlfcn.h> static string GetPluginsDirectory() { Dl_info info; - if (!dladdr((void *)BNGetBundledPluginDirectory, &info)) + if (!dladdr((void*)BNGetBundledPluginDirectory, &info)) return NULL; stringstream ss; - ss << dirname((char *)info.dli_fname) << "/plugins/"; + ss << dirname((char*)info.dli_fname) << "/plugins/"; return ss.str(); } #else @@ -45,99 +45,99 @@ static void PrintOperation(BNLowLevelILOperation operation) switch (operation) { - ENUM_PRINTER(LLIL_NOP) - ENUM_PRINTER(LLIL_SET_REG) - ENUM_PRINTER(LLIL_SET_REG_SPLIT) - ENUM_PRINTER(LLIL_SET_FLAG) - ENUM_PRINTER(LLIL_LOAD) - ENUM_PRINTER(LLIL_STORE) - ENUM_PRINTER(LLIL_PUSH) - ENUM_PRINTER(LLIL_POP) - ENUM_PRINTER(LLIL_REG) - ENUM_PRINTER(LLIL_CONST) - ENUM_PRINTER(LLIL_CONST_PTR) - ENUM_PRINTER(LLIL_EXTERN_PTR) - ENUM_PRINTER(LLIL_FLAG) - ENUM_PRINTER(LLIL_FLAG_BIT) - ENUM_PRINTER(LLIL_ADD) - ENUM_PRINTER(LLIL_ADC) - ENUM_PRINTER(LLIL_SUB) - ENUM_PRINTER(LLIL_SBB) - ENUM_PRINTER(LLIL_AND) - ENUM_PRINTER(LLIL_OR) - ENUM_PRINTER(LLIL_XOR) - ENUM_PRINTER(LLIL_LSL) - ENUM_PRINTER(LLIL_LSR) - ENUM_PRINTER(LLIL_ASR) - ENUM_PRINTER(LLIL_ROL) - ENUM_PRINTER(LLIL_RLC) - ENUM_PRINTER(LLIL_ROR) - ENUM_PRINTER(LLIL_RRC) - ENUM_PRINTER(LLIL_MUL) - ENUM_PRINTER(LLIL_MULU_DP) - ENUM_PRINTER(LLIL_MULS_DP) - ENUM_PRINTER(LLIL_DIVU) - ENUM_PRINTER(LLIL_DIVU_DP) - ENUM_PRINTER(LLIL_DIVS) - ENUM_PRINTER(LLIL_DIVS_DP) - ENUM_PRINTER(LLIL_MODU) - ENUM_PRINTER(LLIL_MODU_DP) - ENUM_PRINTER(LLIL_MODS) - ENUM_PRINTER(LLIL_MODS_DP) - ENUM_PRINTER(LLIL_NEG) - ENUM_PRINTER(LLIL_NOT) - ENUM_PRINTER(LLIL_SX) - ENUM_PRINTER(LLIL_ZX) - ENUM_PRINTER(LLIL_LOW_PART) - ENUM_PRINTER(LLIL_JUMP) - ENUM_PRINTER(LLIL_JUMP_TO) - ENUM_PRINTER(LLIL_CALL) - ENUM_PRINTER(LLIL_CALL_STACK_ADJUST) - ENUM_PRINTER(LLIL_TAILCALL) - ENUM_PRINTER(LLIL_RET) - ENUM_PRINTER(LLIL_NORET) - ENUM_PRINTER(LLIL_IF) - ENUM_PRINTER(LLIL_GOTO) - ENUM_PRINTER(LLIL_FLAG_COND) - ENUM_PRINTER(LLIL_CMP_E) - ENUM_PRINTER(LLIL_CMP_NE) - ENUM_PRINTER(LLIL_CMP_SLT) - ENUM_PRINTER(LLIL_CMP_ULT) - ENUM_PRINTER(LLIL_CMP_SLE) - ENUM_PRINTER(LLIL_CMP_ULE) - ENUM_PRINTER(LLIL_CMP_SGE) - ENUM_PRINTER(LLIL_CMP_UGE) - ENUM_PRINTER(LLIL_CMP_SGT) - ENUM_PRINTER(LLIL_CMP_UGT) - ENUM_PRINTER(LLIL_TEST_BIT) - ENUM_PRINTER(LLIL_BOOL_TO_INT) - ENUM_PRINTER(LLIL_ADD_OVERFLOW) - ENUM_PRINTER(LLIL_SYSCALL) - ENUM_PRINTER(LLIL_BP) - ENUM_PRINTER(LLIL_TRAP) - ENUM_PRINTER(LLIL_UNDEF) - ENUM_PRINTER(LLIL_UNIMPL) - ENUM_PRINTER(LLIL_UNIMPL_MEM) - ENUM_PRINTER(LLIL_SET_REG_SSA) - ENUM_PRINTER(LLIL_SET_REG_SSA_PARTIAL) - ENUM_PRINTER(LLIL_SET_REG_SPLIT_SSA) - ENUM_PRINTER(LLIL_REG_SPLIT_DEST_SSA) - ENUM_PRINTER(LLIL_REG_SSA) - ENUM_PRINTER(LLIL_REG_SSA_PARTIAL) - ENUM_PRINTER(LLIL_SET_FLAG_SSA) - ENUM_PRINTER(LLIL_FLAG_SSA) - ENUM_PRINTER(LLIL_FLAG_BIT_SSA) - ENUM_PRINTER(LLIL_CALL_SSA) - ENUM_PRINTER(LLIL_SYSCALL_SSA) - ENUM_PRINTER(LLIL_TAILCALL_SSA) - ENUM_PRINTER(LLIL_CALL_PARAM) - ENUM_PRINTER(LLIL_CALL_STACK_SSA) - ENUM_PRINTER(LLIL_CALL_OUTPUT_SSA) - ENUM_PRINTER(LLIL_LOAD_SSA) - ENUM_PRINTER(LLIL_STORE_SSA) - ENUM_PRINTER(LLIL_REG_PHI) - ENUM_PRINTER(LLIL_FLAG_PHI) - ENUM_PRINTER(LLIL_MEM_PHI) + ENUM_PRINTER(LLIL_NOP) + ENUM_PRINTER(LLIL_SET_REG) + ENUM_PRINTER(LLIL_SET_REG_SPLIT) + ENUM_PRINTER(LLIL_SET_FLAG) + ENUM_PRINTER(LLIL_LOAD) + ENUM_PRINTER(LLIL_STORE) + ENUM_PRINTER(LLIL_PUSH) + ENUM_PRINTER(LLIL_POP) + ENUM_PRINTER(LLIL_REG) + ENUM_PRINTER(LLIL_CONST) + ENUM_PRINTER(LLIL_CONST_PTR) + ENUM_PRINTER(LLIL_EXTERN_PTR) + ENUM_PRINTER(LLIL_FLAG) + ENUM_PRINTER(LLIL_FLAG_BIT) + ENUM_PRINTER(LLIL_ADD) + ENUM_PRINTER(LLIL_ADC) + ENUM_PRINTER(LLIL_SUB) + ENUM_PRINTER(LLIL_SBB) + ENUM_PRINTER(LLIL_AND) + ENUM_PRINTER(LLIL_OR) + ENUM_PRINTER(LLIL_XOR) + ENUM_PRINTER(LLIL_LSL) + ENUM_PRINTER(LLIL_LSR) + ENUM_PRINTER(LLIL_ASR) + ENUM_PRINTER(LLIL_ROL) + ENUM_PRINTER(LLIL_RLC) + ENUM_PRINTER(LLIL_ROR) + ENUM_PRINTER(LLIL_RRC) + ENUM_PRINTER(LLIL_MUL) + ENUM_PRINTER(LLIL_MULU_DP) + ENUM_PRINTER(LLIL_MULS_DP) + ENUM_PRINTER(LLIL_DIVU) + ENUM_PRINTER(LLIL_DIVU_DP) + ENUM_PRINTER(LLIL_DIVS) + ENUM_PRINTER(LLIL_DIVS_DP) + ENUM_PRINTER(LLIL_MODU) + ENUM_PRINTER(LLIL_MODU_DP) + ENUM_PRINTER(LLIL_MODS) + ENUM_PRINTER(LLIL_MODS_DP) + ENUM_PRINTER(LLIL_NEG) + ENUM_PRINTER(LLIL_NOT) + ENUM_PRINTER(LLIL_SX) + ENUM_PRINTER(LLIL_ZX) + ENUM_PRINTER(LLIL_LOW_PART) + ENUM_PRINTER(LLIL_JUMP) + ENUM_PRINTER(LLIL_JUMP_TO) + ENUM_PRINTER(LLIL_CALL) + ENUM_PRINTER(LLIL_CALL_STACK_ADJUST) + ENUM_PRINTER(LLIL_TAILCALL) + ENUM_PRINTER(LLIL_RET) + ENUM_PRINTER(LLIL_NORET) + ENUM_PRINTER(LLIL_IF) + ENUM_PRINTER(LLIL_GOTO) + ENUM_PRINTER(LLIL_FLAG_COND) + ENUM_PRINTER(LLIL_CMP_E) + ENUM_PRINTER(LLIL_CMP_NE) + ENUM_PRINTER(LLIL_CMP_SLT) + ENUM_PRINTER(LLIL_CMP_ULT) + ENUM_PRINTER(LLIL_CMP_SLE) + ENUM_PRINTER(LLIL_CMP_ULE) + ENUM_PRINTER(LLIL_CMP_SGE) + ENUM_PRINTER(LLIL_CMP_UGE) + ENUM_PRINTER(LLIL_CMP_SGT) + ENUM_PRINTER(LLIL_CMP_UGT) + ENUM_PRINTER(LLIL_TEST_BIT) + ENUM_PRINTER(LLIL_BOOL_TO_INT) + ENUM_PRINTER(LLIL_ADD_OVERFLOW) + ENUM_PRINTER(LLIL_SYSCALL) + ENUM_PRINTER(LLIL_BP) + ENUM_PRINTER(LLIL_TRAP) + ENUM_PRINTER(LLIL_UNDEF) + ENUM_PRINTER(LLIL_UNIMPL) + ENUM_PRINTER(LLIL_UNIMPL_MEM) + ENUM_PRINTER(LLIL_SET_REG_SSA) + ENUM_PRINTER(LLIL_SET_REG_SSA_PARTIAL) + ENUM_PRINTER(LLIL_SET_REG_SPLIT_SSA) + ENUM_PRINTER(LLIL_REG_SPLIT_DEST_SSA) + ENUM_PRINTER(LLIL_REG_SSA) + ENUM_PRINTER(LLIL_REG_SSA_PARTIAL) + ENUM_PRINTER(LLIL_SET_FLAG_SSA) + ENUM_PRINTER(LLIL_FLAG_SSA) + ENUM_PRINTER(LLIL_FLAG_BIT_SSA) + ENUM_PRINTER(LLIL_CALL_SSA) + ENUM_PRINTER(LLIL_SYSCALL_SSA) + ENUM_PRINTER(LLIL_TAILCALL_SSA) + ENUM_PRINTER(LLIL_CALL_PARAM) + ENUM_PRINTER(LLIL_CALL_STACK_SSA) + ENUM_PRINTER(LLIL_CALL_OUTPUT_SSA) + ENUM_PRINTER(LLIL_LOAD_SSA) + ENUM_PRINTER(LLIL_STORE_SSA) + ENUM_PRINTER(LLIL_REG_PHI) + ENUM_PRINTER(LLIL_FLAG_PHI) + ENUM_PRINTER(LLIL_MEM_PHI) default: printf("<invalid operation %" PRId32 ">", operation); break; @@ -149,20 +149,20 @@ static void PrintFlagCondition(BNLowLevelILFlagCondition cond) { switch (cond) { - ENUM_PRINTER(LLFC_E) - ENUM_PRINTER(LLFC_NE) - ENUM_PRINTER(LLFC_SLT) - ENUM_PRINTER(LLFC_ULT) - ENUM_PRINTER(LLFC_SLE) - ENUM_PRINTER(LLFC_ULE) - ENUM_PRINTER(LLFC_SGE) - ENUM_PRINTER(LLFC_UGE) - ENUM_PRINTER(LLFC_SGT) - ENUM_PRINTER(LLFC_UGT) - ENUM_PRINTER(LLFC_NEG) - ENUM_PRINTER(LLFC_POS) - ENUM_PRINTER(LLFC_O) - ENUM_PRINTER(LLFC_NO) + ENUM_PRINTER(LLFC_E) + ENUM_PRINTER(LLFC_NE) + ENUM_PRINTER(LLFC_SLT) + ENUM_PRINTER(LLFC_ULT) + ENUM_PRINTER(LLFC_SLE) + ENUM_PRINTER(LLFC_ULE) + ENUM_PRINTER(LLFC_SGE) + ENUM_PRINTER(LLFC_UGE) + ENUM_PRINTER(LLFC_SGT) + ENUM_PRINTER(LLFC_UGT) + ENUM_PRINTER(LLFC_NEG) + ENUM_PRINTER(LLFC_POS) + ENUM_PRINTER(LLFC_O) + ENUM_PRINTER(LLFC_NO) default: printf("<invalid condition>"); break; @@ -300,7 +300,7 @@ static void PrintILExpr(const LowLevelILInstruction& instr, size_t indent) } -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc != 2) { @@ -365,7 +365,7 @@ int main(int argc, char *argv[]) vector<InstructionTextToken> tokens; il->GetInstructionText(func, func->GetArchitecture(), instrIndex, tokens); printf(" %" PRIdPTR " @ 0x%" PRIx64 " ", instrIndex, instr.address); - for (auto& token: tokens) + for (auto& token : tokens) printf("%s", token.text.c_str()); printf("\n"); @@ -380,11 +380,11 @@ int main(int argc, char *argv[]) case LLIL_CONST_PTR: case LLIL_EXTERN_PTR: printf(" Found constant 0x%" PRIx64 "\n", expr.GetConstant()); - return false; // Done parsing this + return false; // Done parsing this default: break; } - return true; // Parse any subexpressions + return true; // Parse any subexpressions }); // Example of using the templated accessors for efficiently parsing load instructions @@ -395,20 +395,20 @@ int main(int argc, char *argv[]) if (expr.GetSourceExpr<LLIL_LOAD>().operation == LLIL_CONST_PTR) { printf(" Loading from address 0x%" PRIx64 "\n", - expr.GetSourceExpr<LLIL_LOAD>().GetConstant<LLIL_CONST_PTR>()); - return false; // Done parsing this + expr.GetSourceExpr<LLIL_LOAD>().GetConstant<LLIL_CONST_PTR>()); + return false; // Done parsing this } else if (expr.GetSourceExpr<LLIL_LOAD>().operation == LLIL_EXTERN_PTR) { printf(" Loading from address 0x%" PRIx64 "\n", - expr.GetSourceExpr<LLIL_LOAD>().GetConstant<LLIL_EXTERN_PTR>()); - return false; // Done parsing this + expr.GetSourceExpr<LLIL_LOAD>().GetConstant<LLIL_EXTERN_PTR>()); + return false; // Done parsing this } break; default: break; } - return true; // Parse any subexpressions + return true; // Parse any subexpressions }); } } diff --git a/examples/mlil_parser/src/mlil_parser.cpp b/examples/mlil_parser/src/mlil_parser.cpp index e14c9317..c31ec035 100644 --- a/examples/mlil_parser/src/mlil_parser.cpp +++ b/examples/mlil_parser/src/mlil_parser.cpp @@ -9,16 +9,16 @@ using namespace std; #ifndef _WIN32 -#include <libgen.h> -#include <dlfcn.h> + #include <libgen.h> + #include <dlfcn.h> static string GetPluginsDirectory() { Dl_info info; - if (!dladdr((void *)BNGetBundledPluginDirectory, &info)) + if (!dladdr((void*)BNGetBundledPluginDirectory, &info)) return NULL; stringstream ss; - ss << dirname((char *)info.dli_fname) << "/plugins/"; + ss << dirname((char*)info.dli_fname) << "/plugins/"; return ss.str(); } #else @@ -45,106 +45,106 @@ static void PrintOperation(BNMediumLevelILOperation operation) switch (operation) { - ENUM_PRINTER(MLIL_NOP) - ENUM_PRINTER(MLIL_SET_VAR) - ENUM_PRINTER(MLIL_SET_VAR_FIELD) - ENUM_PRINTER(MLIL_SET_VAR_SPLIT) - ENUM_PRINTER(MLIL_LOAD) - ENUM_PRINTER(MLIL_LOAD_STRUCT) - ENUM_PRINTER(MLIL_STORE) - ENUM_PRINTER(MLIL_STORE_STRUCT) - ENUM_PRINTER(MLIL_VAR) - ENUM_PRINTER(MLIL_VAR_FIELD) - ENUM_PRINTER(MLIL_ADDRESS_OF) - ENUM_PRINTER(MLIL_ADDRESS_OF_FIELD) - ENUM_PRINTER(MLIL_CONST) - ENUM_PRINTER(MLIL_CONST_PTR) - ENUM_PRINTER(MLIL_EXTERN_PTR) - ENUM_PRINTER(MLIL_ADD) - ENUM_PRINTER(MLIL_ADC) - ENUM_PRINTER(MLIL_SUB) - ENUM_PRINTER(MLIL_SBB) - ENUM_PRINTER(MLIL_AND) - ENUM_PRINTER(MLIL_OR) - ENUM_PRINTER(MLIL_XOR) - ENUM_PRINTER(MLIL_LSL) - ENUM_PRINTER(MLIL_LSR) - ENUM_PRINTER(MLIL_ASR) - ENUM_PRINTER(MLIL_ROL) - ENUM_PRINTER(MLIL_RLC) - ENUM_PRINTER(MLIL_ROR) - ENUM_PRINTER(MLIL_RRC) - ENUM_PRINTER(MLIL_MUL) - ENUM_PRINTER(MLIL_MULU_DP) - ENUM_PRINTER(MLIL_MULS_DP) - ENUM_PRINTER(MLIL_DIVU) - ENUM_PRINTER(MLIL_DIVU_DP) - ENUM_PRINTER(MLIL_DIVS) - ENUM_PRINTER(MLIL_DIVS_DP) - ENUM_PRINTER(MLIL_MODU) - ENUM_PRINTER(MLIL_MODU_DP) - ENUM_PRINTER(MLIL_MODS) - ENUM_PRINTER(MLIL_MODS_DP) - ENUM_PRINTER(MLIL_NEG) - ENUM_PRINTER(MLIL_NOT) - ENUM_PRINTER(MLIL_SX) - ENUM_PRINTER(MLIL_ZX) - ENUM_PRINTER(MLIL_LOW_PART) - ENUM_PRINTER(MLIL_JUMP) - ENUM_PRINTER(MLIL_JUMP_TO) - ENUM_PRINTER(MLIL_CALL) - ENUM_PRINTER(MLIL_CALL_UNTYPED) - ENUM_PRINTER(MLIL_CALL_OUTPUT) - ENUM_PRINTER(MLIL_CALL_PARAM) - ENUM_PRINTER(MLIL_RET) - ENUM_PRINTER(MLIL_NORET) - ENUM_PRINTER(MLIL_IF) - ENUM_PRINTER(MLIL_GOTO) - ENUM_PRINTER(MLIL_CMP_E) - ENUM_PRINTER(MLIL_CMP_NE) - ENUM_PRINTER(MLIL_CMP_SLT) - ENUM_PRINTER(MLIL_CMP_ULT) - ENUM_PRINTER(MLIL_CMP_SLE) - ENUM_PRINTER(MLIL_CMP_ULE) - ENUM_PRINTER(MLIL_CMP_SGE) - ENUM_PRINTER(MLIL_CMP_UGE) - ENUM_PRINTER(MLIL_CMP_SGT) - ENUM_PRINTER(MLIL_CMP_UGT) - ENUM_PRINTER(MLIL_TEST_BIT) - ENUM_PRINTER(MLIL_BOOL_TO_INT) - ENUM_PRINTER(MLIL_ADD_OVERFLOW) - ENUM_PRINTER(MLIL_SYSCALL) - ENUM_PRINTER(MLIL_SYSCALL_UNTYPED) - ENUM_PRINTER(MLIL_TAILCALL) - ENUM_PRINTER(MLIL_TAILCALL_UNTYPED) - ENUM_PRINTER(MLIL_BP) - ENUM_PRINTER(MLIL_TRAP) - ENUM_PRINTER(MLIL_UNDEF) - ENUM_PRINTER(MLIL_UNIMPL) - ENUM_PRINTER(MLIL_UNIMPL_MEM) - ENUM_PRINTER(MLIL_SET_VAR_SSA) - ENUM_PRINTER(MLIL_SET_VAR_SSA_FIELD) - ENUM_PRINTER(MLIL_SET_VAR_SPLIT_SSA) - ENUM_PRINTER(MLIL_SET_VAR_ALIASED) - ENUM_PRINTER(MLIL_SET_VAR_ALIASED_FIELD) - ENUM_PRINTER(MLIL_VAR_SSA) - ENUM_PRINTER(MLIL_VAR_SSA_FIELD) - ENUM_PRINTER(MLIL_VAR_ALIASED) - ENUM_PRINTER(MLIL_VAR_ALIASED_FIELD) - ENUM_PRINTER(MLIL_CALL_SSA) - ENUM_PRINTER(MLIL_CALL_UNTYPED_SSA) - ENUM_PRINTER(MLIL_SYSCALL_SSA) - ENUM_PRINTER(MLIL_SYSCALL_UNTYPED_SSA) - ENUM_PRINTER(MLIL_TAILCALL_SSA) - ENUM_PRINTER(MLIL_TAILCALL_UNTYPED_SSA) - ENUM_PRINTER(MLIL_CALL_PARAM_SSA) - ENUM_PRINTER(MLIL_CALL_OUTPUT_SSA) - ENUM_PRINTER(MLIL_LOAD_SSA) - ENUM_PRINTER(MLIL_LOAD_STRUCT_SSA) - ENUM_PRINTER(MLIL_STORE_SSA) - ENUM_PRINTER(MLIL_STORE_STRUCT_SSA) - ENUM_PRINTER(MLIL_VAR_PHI) - ENUM_PRINTER(MLIL_MEM_PHI) + ENUM_PRINTER(MLIL_NOP) + ENUM_PRINTER(MLIL_SET_VAR) + ENUM_PRINTER(MLIL_SET_VAR_FIELD) + ENUM_PRINTER(MLIL_SET_VAR_SPLIT) + ENUM_PRINTER(MLIL_LOAD) + ENUM_PRINTER(MLIL_LOAD_STRUCT) + ENUM_PRINTER(MLIL_STORE) + ENUM_PRINTER(MLIL_STORE_STRUCT) + ENUM_PRINTER(MLIL_VAR) + ENUM_PRINTER(MLIL_VAR_FIELD) + ENUM_PRINTER(MLIL_ADDRESS_OF) + ENUM_PRINTER(MLIL_ADDRESS_OF_FIELD) + ENUM_PRINTER(MLIL_CONST) + ENUM_PRINTER(MLIL_CONST_PTR) + ENUM_PRINTER(MLIL_EXTERN_PTR) + ENUM_PRINTER(MLIL_ADD) + ENUM_PRINTER(MLIL_ADC) + ENUM_PRINTER(MLIL_SUB) + ENUM_PRINTER(MLIL_SBB) + ENUM_PRINTER(MLIL_AND) + ENUM_PRINTER(MLIL_OR) + ENUM_PRINTER(MLIL_XOR) + ENUM_PRINTER(MLIL_LSL) + ENUM_PRINTER(MLIL_LSR) + ENUM_PRINTER(MLIL_ASR) + ENUM_PRINTER(MLIL_ROL) + ENUM_PRINTER(MLIL_RLC) + ENUM_PRINTER(MLIL_ROR) + ENUM_PRINTER(MLIL_RRC) + ENUM_PRINTER(MLIL_MUL) + ENUM_PRINTER(MLIL_MULU_DP) + ENUM_PRINTER(MLIL_MULS_DP) + ENUM_PRINTER(MLIL_DIVU) + ENUM_PRINTER(MLIL_DIVU_DP) + ENUM_PRINTER(MLIL_DIVS) + ENUM_PRINTER(MLIL_DIVS_DP) + ENUM_PRINTER(MLIL_MODU) + ENUM_PRINTER(MLIL_MODU_DP) + ENUM_PRINTER(MLIL_MODS) + ENUM_PRINTER(MLIL_MODS_DP) + ENUM_PRINTER(MLIL_NEG) + ENUM_PRINTER(MLIL_NOT) + ENUM_PRINTER(MLIL_SX) + ENUM_PRINTER(MLIL_ZX) + ENUM_PRINTER(MLIL_LOW_PART) + ENUM_PRINTER(MLIL_JUMP) + ENUM_PRINTER(MLIL_JUMP_TO) + ENUM_PRINTER(MLIL_CALL) + ENUM_PRINTER(MLIL_CALL_UNTYPED) + ENUM_PRINTER(MLIL_CALL_OUTPUT) + ENUM_PRINTER(MLIL_CALL_PARAM) + ENUM_PRINTER(MLIL_RET) + ENUM_PRINTER(MLIL_NORET) + ENUM_PRINTER(MLIL_IF) + ENUM_PRINTER(MLIL_GOTO) + ENUM_PRINTER(MLIL_CMP_E) + ENUM_PRINTER(MLIL_CMP_NE) + ENUM_PRINTER(MLIL_CMP_SLT) + ENUM_PRINTER(MLIL_CMP_ULT) + ENUM_PRINTER(MLIL_CMP_SLE) + ENUM_PRINTER(MLIL_CMP_ULE) + ENUM_PRINTER(MLIL_CMP_SGE) + ENUM_PRINTER(MLIL_CMP_UGE) + ENUM_PRINTER(MLIL_CMP_SGT) + ENUM_PRINTER(MLIL_CMP_UGT) + ENUM_PRINTER(MLIL_TEST_BIT) + ENUM_PRINTER(MLIL_BOOL_TO_INT) + ENUM_PRINTER(MLIL_ADD_OVERFLOW) + ENUM_PRINTER(MLIL_SYSCALL) + ENUM_PRINTER(MLIL_SYSCALL_UNTYPED) + ENUM_PRINTER(MLIL_TAILCALL) + ENUM_PRINTER(MLIL_TAILCALL_UNTYPED) + ENUM_PRINTER(MLIL_BP) + ENUM_PRINTER(MLIL_TRAP) + ENUM_PRINTER(MLIL_UNDEF) + ENUM_PRINTER(MLIL_UNIMPL) + ENUM_PRINTER(MLIL_UNIMPL_MEM) + ENUM_PRINTER(MLIL_SET_VAR_SSA) + ENUM_PRINTER(MLIL_SET_VAR_SSA_FIELD) + ENUM_PRINTER(MLIL_SET_VAR_SPLIT_SSA) + ENUM_PRINTER(MLIL_SET_VAR_ALIASED) + ENUM_PRINTER(MLIL_SET_VAR_ALIASED_FIELD) + ENUM_PRINTER(MLIL_VAR_SSA) + ENUM_PRINTER(MLIL_VAR_SSA_FIELD) + ENUM_PRINTER(MLIL_VAR_ALIASED) + ENUM_PRINTER(MLIL_VAR_ALIASED_FIELD) + ENUM_PRINTER(MLIL_CALL_SSA) + ENUM_PRINTER(MLIL_CALL_UNTYPED_SSA) + ENUM_PRINTER(MLIL_SYSCALL_SSA) + ENUM_PRINTER(MLIL_SYSCALL_UNTYPED_SSA) + ENUM_PRINTER(MLIL_TAILCALL_SSA) + ENUM_PRINTER(MLIL_TAILCALL_UNTYPED_SSA) + ENUM_PRINTER(MLIL_CALL_PARAM_SSA) + ENUM_PRINTER(MLIL_CALL_OUTPUT_SSA) + ENUM_PRINTER(MLIL_LOAD_SSA) + ENUM_PRINTER(MLIL_LOAD_STRUCT_SSA) + ENUM_PRINTER(MLIL_STORE_SSA) + ENUM_PRINTER(MLIL_STORE_STRUCT_SSA) + ENUM_PRINTER(MLIL_VAR_PHI) + ENUM_PRINTER(MLIL_MEM_PHI) default: printf("<invalid operation %" PRId32 ">", operation); break; @@ -248,7 +248,7 @@ static void PrintILExpr(const MediumLevelILInstruction& instr, size_t indent) } -int main(int argc, char *argv[]) +int main(int argc, char* argv[]) { if (argc != 2) { @@ -313,7 +313,7 @@ int main(int argc, char *argv[]) vector<InstructionTextToken> tokens; il->GetInstructionText(func, func->GetArchitecture(), instrIndex, tokens); printf(" %" PRIdPTR " @ 0x%" PRIx64 " ", instrIndex, instr.address); - for (auto& token: tokens) + for (auto& token : tokens) printf("%s", token.text.c_str()); printf("\n"); @@ -336,20 +336,20 @@ int main(int argc, char *argv[]) if (expr.GetSourceExpr<MLIL_LOAD>().operation == MLIL_CONST_PTR) { printf(" Loading from address 0x%" PRIx64 "\n", - expr.GetSourceExpr<MLIL_LOAD>().GetConstant<MLIL_CONST_PTR>()); - return false; // Done parsing this + expr.GetSourceExpr<MLIL_LOAD>().GetConstant<MLIL_CONST_PTR>()); + return false; // Done parsing this } else if (expr.GetSourceExpr<MLIL_LOAD>().operation == MLIL_EXTERN_PTR) { printf(" Loading from address 0x%" PRIx64 "\n", - expr.GetSourceExpr<MLIL_LOAD>().GetConstant<MLIL_EXTERN_PTR>()); - return false; // Done parsing this + expr.GetSourceExpr<MLIL_LOAD>().GetConstant<MLIL_EXTERN_PTR>()); + return false; // Done parsing this } break; default: break; } - return true; // Parse any subexpressions + return true; // Parse any subexpressions }); } } 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; } diff --git a/examples/triage/byte.cpp b/examples/triage/byte.cpp index be25368a..b6318d1e 100644 --- a/examples/triage/byte.cpp +++ b/examples/triage/byte.cpp @@ -5,28 +5,21 @@ #include "theme.h" -static const char* g_byteMapping[] = -{ - " ", "☺", "☻", "♥", "♦", "♣", "♠", "•", "◘", "○", "◙", "♂", "♀", "♪", "♫", "☼", - "▸", "◂", "↕", "‼", "¶", "§", "▬", "↨", "↑", "↓", "→", "←", "∟", "↔", "▴", "▾", - " ", "!", "\"", "#", "$", "%", "&", "'", "(", ")", "*", "+", ",", "-", ".", "/", - "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", ">", "?", - "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", - "P", "Q", "R", "S", "T", "U", "V", "W", "X", "Y", "Z", "[", "\\", "]", "^", "_", - "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", "l", "m", "n", "o", - "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~", "⌂", - "Ç", "ü", "é", "â", "ä", "à", "å", "ç", "ê", "ë", "è", "ï", "î", "ì", "Ä", "Å", - "É", "æ", "Æ", "ô", "ö", "ò", "û", "ù", "ÿ", "Ö", "Ü", "¢", "£", "¥", "₧", "ƒ", - "á", "í", "ó", "ú", "ñ", "Ñ", "ª", "º", "¿", "⌐", "¬", "½", "¼", "¡", "«", "»", - "░", "▒", "▓", "│", "┤", "╡", "╢", "╖", "╕", "╣", "║", "╗", "╝", "╜", "╛", "┐", - "└", "┴", "┬", "├", "─", "┼", "╞", "╟", "╚", "╔", "╩", "╦", "╠", "═", "╬", "╧", - "╨", "╤", "╥", "╙", "╘", "╒", "╓", "╫", "╪", "┘", "┌", "█", "▄", "▌", "▐", "▀", - "α", "ß", "Γ", "π", "Σ", "σ", "µ", "τ", "Φ", "Θ", "Ω", "δ", "∞", "φ", "ε", "∩", - "≡", "±", "≥", "≤", "⌠", "⌡", "÷", "≈", "°", "∙", "·", "√", "ⁿ", "²", "■", " " -}; +static const char* g_byteMapping[] = {" ", "☺", "☻", "♥", "♦", "♣", "♠", "•", "◘", "○", "◙", "♂", "♀", "♪", "♫", "☼", + "▸", "◂", "↕", "‼", "¶", "§", "▬", "↨", "↑", "↓", "→", "←", "∟", "↔", "▴", "▾", " ", "!", "\"", "#", "$", "%", "&", + "'", "(", ")", "*", "+", ",", "-", ".", "/", "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", ":", ";", "<", "=", + ">", "?", "@", "A", "B", "C", "D", "E", "F", "G", "H", "I", "J", "K", "L", "M", "N", "O", "P", "Q", "R", "S", "T", + "U", "V", "W", "X", "Y", "Z", "[", "\\", "]", "^", "_", "`", "a", "b", "c", "d", "e", "f", "g", "h", "i", "j", "k", + "l", "m", "n", "o", "p", "q", "r", "s", "t", "u", "v", "w", "x", "y", "z", "{", "|", "}", "~", "⌂", "Ç", "ü", "é", + "â", "ä", "à", "å", "ç", "ê", "ë", "è", "ï", "î", "ì", "Ä", "Å", "É", "æ", "Æ", "ô", "ö", "ò", "û", "ù", "ÿ", "Ö", + "Ü", "¢", "£", "¥", "₧", "ƒ", "á", "í", "ó", "ú", "ñ", "Ñ", "ª", "º", "¿", "⌐", "¬", "½", "¼", "¡", "«", "»", "░", + "▒", "▓", "│", "┤", "╡", "╢", "╖", "╕", "╣", "║", "╗", "╝", "╜", "╛", "┐", "└", "┴", "┬", "├", "─", "┼", "╞", "╟", + "╚", "╔", "╩", "╦", "╠", "═", "╬", "╧", "╨", "╤", "╥", "╙", "╘", "╒", "╓", "╫", "╪", "┘", "┌", "█", "▄", "▌", "▐", + "▀", "α", "ß", "Γ", "π", "Σ", "σ", "µ", "τ", "Φ", "Θ", "Ω", "δ", "∞", "φ", "ε", "∩", "≡", "±", "≥", "≤", "⌠", "⌡", + "÷", "≈", "°", "∙", "·", "√", "ⁿ", "²", "■", " "}; -ByteView::ByteView(QWidget* parent, BinaryViewRef data): QAbstractScrollArea(parent), m_render(this) +ByteView::ByteView(QWidget* parent, BinaryViewRef data) : QAbstractScrollArea(parent), m_render(this) { setBinaryDataNavigable(true); setupView(this); @@ -72,7 +65,7 @@ ByteView::ByteView(QWidget* parent, BinaryViewRef data): QAbstractScrollArea(par m_updateTimer = new QTimer(this); m_updateTimer->setInterval(200); m_updateTimer->setSingleShot(false); - //connect(m_updateTimer, &QTimer::timeout, this, &ByteView::updateTimerEvent); + // connect(m_updateTimer, &QTimer::timeout, this, &ByteView::updateTimerEvent); actionHandler()->bindAction("Move Cursor Up", UIAction([=]() { up(false); })); actionHandler()->bindAction("Move Cursor Down", UIAction([=]() { down(false); })); @@ -155,7 +148,7 @@ BNAddressRange ByteView::getSelectionOffsets() start = end; end = t; } - return { start, end }; + return {start, end}; } void ByteView::setSelectionOffsets(BNAddressRange range) @@ -169,11 +162,11 @@ void ByteView::updateRanges() { m_ranges = m_data->GetAllocatedRanges(); // Remove regions not backed by the file - for (auto& i: m_data->GetSegments()) + for (auto& i : m_data->GetSegments()) if (i->GetDataLength() < i->GetLength()) removeRange(i->GetStart() + i->GetDataLength(), i->GetEnd()); m_allocatedLength = 0; - for (auto& i: m_ranges) + for (auto& i : m_ranges) m_allocatedLength += i.end - i.start; } @@ -181,7 +174,7 @@ void ByteView::updateRanges() void ByteView::removeRange(uint64_t begin, uint64_t end) { std::vector<BNAddressRange> newRanges; - for (auto& i: m_ranges) + for (auto& i : m_ranges) { if ((end <= i.start) || (begin >= i.end)) { @@ -193,16 +186,16 @@ void ByteView::removeRange(uint64_t begin, uint64_t end) } else if ((begin <= i.start) && (end < i.end)) { - newRanges.push_back(BNAddressRange { end, i.end }); + newRanges.push_back(BNAddressRange {end, i.end}); } else if ((begin > i.start) && (end >= i.end)) { - newRanges.push_back(BNAddressRange { i.start, begin }); + newRanges.push_back(BNAddressRange {i.start, begin}); } else { - newRanges.push_back(BNAddressRange { i.start, begin }); - newRanges.push_back(BNAddressRange { end, i.end }); + newRanges.push_back(BNAddressRange {i.start, begin}); + newRanges.push_back(BNAddressRange {end, i.end}); } } m_ranges = newRanges; @@ -211,7 +204,7 @@ void ByteView::removeRange(uint64_t begin, uint64_t end) void ByteView::setTopToAddress(uint64_t addr) { - for (auto& i: m_ranges) + for (auto& i : m_ranges) { if ((addr >= i.start) && (addr <= i.end)) { @@ -237,7 +230,7 @@ bool ByteView::navigate(uint64_t addr) if (addr > getEnd()) return false; m_cursorAddr = getStart(); - for (auto& i: m_ranges) + for (auto& i : m_ranges) { if (i.start > addr) break; @@ -293,7 +286,7 @@ void ByteView::adjustSize(int width, int height) uint64_t ByteView::getContiguousOffsetForAddress(uint64_t addr) { uint64_t offset = 0; - for (auto& i: m_ranges) + for (auto& i : m_ranges) { if ((addr >= i.start) && (addr <= i.end)) { @@ -309,7 +302,7 @@ uint64_t ByteView::getContiguousOffsetForAddress(uint64_t addr) uint64_t ByteView::getAddressForContiguousOffset(uint64_t offset) { uint64_t cur = 0; - for (auto& i: m_ranges) + for (auto& i : m_ranges) { if (offset < (cur + (i.end - i.start))) return i.start + (offset - cur); @@ -352,7 +345,7 @@ ByteViewLine ByteView::createLine(uint64_t addr, size_t length, bool separator) { if (separator) { - return ByteViewLine { addr, length, "", true }; + return ByteViewLine {addr, length, "", true}; } else { @@ -360,7 +353,7 @@ ByteViewLine ByteView::createLine(uint64_t addr, size_t length, bool separator) QString line; for (size_t i = 0; i < data.GetLength(); i++) line.append(QString(g_byteMapping[data[i]])); - return ByteViewLine { addr, length, line, false }; + return ByteViewLine {addr, length, line, false}; } } @@ -369,7 +362,7 @@ bool ByteView::cachePreviousLines() { bool prevEndValid = false; uint64_t prevEnd = 0; - for (auto& i: m_ranges) + for (auto& i : m_ranges) { if ((m_topAddr > i.start) && (m_topAddr <= i.end)) { @@ -410,7 +403,7 @@ bool ByteView::cachePreviousLines() bool ByteView::cacheNextLines() { uint64_t lastAddr = m_data->GetStart(); - for (auto& i: m_ranges) + for (auto& i : m_ranges) { if ((m_bottomAddr >= i.start) && (m_bottomAddr < i.end)) { @@ -519,8 +512,8 @@ void ByteView::repositionCaret() bool found = false; for (size_t i = 0; i < m_lines.size(); i++) { - if (((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr < (m_lines[i].address + m_lines[i].length))) || - (((i + 1) == m_lines.size()) && (m_cursorAddr == (m_lines[i].address + m_lines[i].length)))) + if (((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr < (m_lines[i].address + m_lines[i].length))) + || (((i + 1) == m_lines.size()) && (m_cursorAddr == (m_lines[i].address + m_lines[i].length)))) { if (i < m_topLine) m_topLine = i; @@ -557,11 +550,11 @@ void ByteView::updateCaret() // Rerender both the old caret position and the new caret position for (size_t i = m_topLine; (i < m_lines.size()) && (i < (m_topLine + m_visibleRows)); i++) { - if (((m_prevCursorAddr >= m_lines[i].address) && (m_prevCursorAddr <= (m_lines[i].address + m_lines[i].length))) || - ((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr <= (m_lines[i].address + m_lines[i].length)))) + if (((m_prevCursorAddr >= m_lines[i].address) && (m_prevCursorAddr <= (m_lines[i].address + m_lines[i].length))) + || ((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr <= (m_lines[i].address + m_lines[i].length)))) { - viewport()->update(0, (int)(i - m_topLine) * m_render.getFontHeight(), - viewport()->size().width(), m_render.getFontHeight() + 3); + viewport()->update(0, (int)(i - m_topLine) * m_render.getFontHeight(), viewport()->size().width(), + m_render.getFontHeight() + 3); } } } @@ -628,22 +621,22 @@ void ByteView::paintEvent(QPaintEvent* event) if (startY == endY) { p.drawRect(2 + ((int)m_addrWidth + 2 + startX) * charWidth, 2 + startY * charHeight, - (endX - startX) * charWidth, charHeight + 1); + (endX - startX) * charWidth, charHeight + 1); } else { p.drawRect(2 + ((int)m_addrWidth + 2 + startX) * charWidth, 2 + startY * charHeight, - ((int)m_cols - startX) * charWidth, charHeight + 1); + ((int)m_cols - startX) * charWidth, charHeight + 1); if (endX > 0) { - p.drawRect(2 + ((int)m_addrWidth + 2) * charWidth, 2 + endY * charHeight, - endX * charWidth, charHeight + 1); + p.drawRect(2 + ((int)m_addrWidth + 2) * charWidth, 2 + endY * charHeight, endX * charWidth, + charHeight + 1); } } if ((endY - startY) > 1) { p.drawRect(2 + ((int)m_addrWidth + 2) * charWidth, 2 + (startY + 1) * charHeight, - (int)m_cols * charWidth, ((endY - startY) - 1) * charHeight + 1); + (int)m_cols * charWidth, ((endY - startY) - 1) * charHeight + 1); } } } @@ -658,8 +651,8 @@ void ByteView::paintEvent(QPaintEvent* event) break; if (m_lines[y + m_topLine].separator) { - m_render.drawLinearDisassemblyLineBackground(p, NonContiguousSeparatorLineType, - QRect(0, 2 + y * charHeight, event->rect().width(), charHeight), 0); + m_render.drawLinearDisassemblyLineBackground( + p, NonContiguousSeparatorLineType, QRect(0, 2 + y * charHeight, event->rect().width(), charHeight), 0); continue; } @@ -670,8 +663,8 @@ void ByteView::paintEvent(QPaintEvent* event) bool hasCursor = false; int cursorCol = 0; - if (((m_cursorAddr >= lineStartAddr) && (m_cursorAddr < (lineStartAddr + length))) || - (((y + (int)m_topLine + 1) >= (int)m_lines.size()) && (m_cursorAddr == (lineStartAddr + length)))) + if (((m_cursorAddr >= lineStartAddr) && (m_cursorAddr < (lineStartAddr + length))) + || (((y + (int)m_topLine + 1) >= (int)m_lines.size()) && (m_cursorAddr == (lineStartAddr + length)))) { cursorCol = (int)(m_cursorAddr - lineStartAddr); hasCursor = true; @@ -684,13 +677,15 @@ void ByteView::paintEvent(QPaintEvent* event) { p.setPen(Qt::NoPen); p.setBrush(palette().color(QPalette::WindowText)); - p.drawRect(2 + ((int)m_addrWidth + 2 + cursorCol) * charWidth, 2 + y * charHeight, charWidth, charHeight + 1); + p.drawRect( + 2 + ((int)m_addrWidth + 2 + cursorCol) * charWidth, 2 + y * charHeight, charWidth, charHeight + 1); QColor caretTextColor = palette().color(QPalette::Base); BinaryNinja::DataBuffer byteValue = m_data->ReadBuffer(lineStartAddr + cursorCol, 1); if (byteValue.GetLength() == 1) { QString byteStr = g_byteMapping[byteValue[0]]; - m_render.drawText(p, 2 + ((int)m_addrWidth + 2 + cursorCol) * charWidth, 2 + y * charHeight, caretTextColor, byteStr); + m_render.drawText( + p, 2 + ((int)m_addrWidth + 2 + cursorCol) * charWidth, 2 + y * charHeight, caretTextColor, byteStr); } } } @@ -699,7 +694,7 @@ void ByteView::paintEvent(QPaintEvent* event) void ByteView::wheelEvent(QWheelEvent* event) { - if (event->angleDelta().x()) // ignore horizontal scrolling + if (event->angleDelta().x()) // ignore horizontal scrolling return; m_wheelDelta -= event->angleDelta().y(); @@ -796,7 +791,7 @@ void ByteView::focusOutEvent(QFocusEvent*) void ByteView::selectNone() { - for (auto& i: m_lines) + for (auto& i : m_lines) { if ((m_cursorAddr >= i.address) && (m_cursorAddr < (i.address + i.length)) && i.separator) { @@ -825,7 +820,7 @@ void ByteView::selectAll() void ByteView::adjustAddressAfterBackwardMovement() { uint64_t lastAddr = getStart(); - for (auto& i: m_ranges) + for (auto& i : m_ranges) { if ((m_cursorAddr >= i.start) && (m_cursorAddr < i.end)) break; @@ -841,7 +836,7 @@ void ByteView::adjustAddressAfterBackwardMovement() void ByteView::adjustAddressAfterForwardMovement() { - for (auto& i: m_ranges) + for (auto& i : m_ranges) { if ((m_cursorAddr >= i.start) && (m_cursorAddr < i.end)) break; @@ -900,8 +895,8 @@ void ByteView::pageUp(bool selecting) { for (size_t i = 0; i < m_lines.size(); i++) { - if (((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr < (m_lines[i].address + m_lines[i].length))) || - (((i + 1) == m_lines.size()) && (m_cursorAddr == (m_lines[i].address + m_lines[i].length)))) + if (((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr < (m_lines[i].address + m_lines[i].length))) + || (((i + 1) == m_lines.size()) && (m_cursorAddr == (m_lines[i].address + m_lines[i].length)))) { if (i < m_visibleRows) { @@ -942,8 +937,8 @@ void ByteView::pageDown(bool selecting) { for (size_t i = 0; i < m_lines.size(); i++) { - if (((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr < (m_lines[i].address + m_lines[i].length))) || - (((i + 1) == m_lines.size()) && (m_cursorAddr == (m_lines[i].address + m_lines[i].length)))) + if (((m_cursorAddr >= m_lines[i].address) && (m_cursorAddr < (m_lines[i].address + m_lines[i].length))) + || (((i + 1) == m_lines.size()) && (m_cursorAddr == (m_lines[i].address + m_lines[i].length)))) { if (i >= (m_lines.size() - m_visibleRows)) { @@ -982,7 +977,7 @@ void ByteView::pageDown(bool selecting) void ByteView::moveToStartOfLine(bool selecting) { - for (auto& i: m_lines) + for (auto& i : m_lines) { if ((m_cursorAddr >= i.address) && (m_cursorAddr < (i.address + i.length))) { @@ -1000,7 +995,7 @@ void ByteView::moveToStartOfLine(bool selecting) void ByteView::moveToEndOfLine(bool selecting) { - for (auto& i: m_lines) + for (auto& i : m_lines) { if ((m_cursorAddr >= i.address) && (m_cursorAddr < (i.address + i.length))) { @@ -1095,9 +1090,7 @@ void ByteView::mouseMoveEvent(QMouseEvent* event) } -ByteViewType::ByteViewType(): ViewType("Bytes", "Byte Overview") -{ -} +ByteViewType::ByteViewType() : ViewType("Bytes", "Byte Overview") {} int ByteViewType::getPriority(BinaryViewRef, const QString&) diff --git a/examples/triage/byte.h b/examples/triage/byte.h index 61cb51a4..1c8c20f8 100644 --- a/examples/triage/byte.h +++ b/examples/triage/byte.h @@ -14,7 +14,7 @@ struct ByteViewLine }; -class ByteView: public QAbstractScrollArea, public View +class ByteView : public QAbstractScrollArea, public View { BinaryViewRef m_data; RenderContext m_render; @@ -76,7 +76,7 @@ class ByteView: public QAbstractScrollArea, public View uint64_t addressFromLocation(int x, int y); -public: + public: ByteView(QWidget* parent, BinaryViewRef data); virtual BinaryViewRef getData() override; @@ -93,7 +93,7 @@ public: uint64_t getEnd(); uint64_t getLength(); -protected: + protected: virtual void resizeEvent(QResizeEvent* event) override; virtual void paintEvent(QPaintEvent* event) override; virtual void wheelEvent(QWheelEvent* event) override; @@ -102,16 +102,16 @@ protected: virtual void mousePressEvent(QMouseEvent* event) override; virtual void mouseMoveEvent(QMouseEvent* event) override; -private Q_SLOTS: + private Q_SLOTS: void scrollBarMoved(int value); void scrollBarAction(int action); void cursorTimerEvent(); }; -class ByteViewType: public ViewType +class ByteViewType : public ViewType { -public: + public: ByteViewType(); virtual int getPriority(BinaryViewRef data, const QString& filename) override; virtual QWidget* create(BinaryViewRef data, ViewFrame* frame) override; diff --git a/examples/triage/entropy.cpp b/examples/triage/entropy.cpp index 72ca0a92..b43350cd 100644 --- a/examples/triage/entropy.cpp +++ b/examples/triage/entropy.cpp @@ -30,7 +30,8 @@ void EntropyThread::Run() { if (!m_running) break; - std::vector<float> entropy = m_data->GetEntropy(m_data->GetStart() + ((uint64_t)i * m_blockSize), m_blockSize, m_blockSize); + std::vector<float> entropy = + m_data->GetEntropy(m_data->GetStart() + ((uint64_t)i * m_blockSize), m_blockSize, m_blockSize); int v; if (entropy.size() == 0) v = 0; @@ -53,7 +54,7 @@ void EntropyThread::Run() } -EntropyWidget::EntropyWidget(QWidget* parent, TriageView* view, BinaryViewRef data): QWidget(parent) +EntropyWidget::EntropyWidget(QWidget* parent, TriageView* view, BinaryViewRef data) : QWidget(parent) { m_view = view; m_data = data; diff --git a/examples/triage/entropy.h b/examples/triage/entropy.h index eb75cfee..a48097c4 100644 --- a/examples/triage/entropy.h +++ b/examples/triage/entropy.h @@ -14,7 +14,7 @@ class EntropyThread bool m_updated, m_running; std::thread m_thread; -public: + public: EntropyThread(BinaryViewRef data, size_t blockSize, QImage* image); ~EntropyThread(); @@ -26,7 +26,7 @@ public: class TriageView; -class EntropyWidget: public QWidget +class EntropyWidget : public QWidget { TriageView* m_view; BinaryViewRef m_data, m_rawData; @@ -35,16 +35,16 @@ class EntropyWidget: public QWidget QImage m_image; EntropyThread* m_thread; -public: + public: EntropyWidget(QWidget* parent, TriageView* view, BinaryViewRef data); virtual ~EntropyWidget(); virtual QSize sizeHint() const override; -protected: + protected: virtual void paintEvent(QPaintEvent* event) override; virtual void mousePressEvent(QMouseEvent* event) override; -private Q_SLOTS: + private Q_SLOTS: void timerExpired(); }; diff --git a/examples/triage/exports.cpp b/examples/triage/exports.cpp index bc5b970e..5ad63613 100644 --- a/examples/triage/exports.cpp +++ b/examples/triage/exports.cpp @@ -12,12 +12,12 @@ GenericExportsModel::GenericExportsModel(BinaryViewRef data) m_totalCols = 2; m_sortCol = 0; m_sortOrder = Qt::AscendingOrder; - for (auto& sym: data->GetSymbolsOfType(FunctionSymbol)) + for (auto& sym : data->GetSymbolsOfType(FunctionSymbol)) { if ((sym->GetBinding() == GlobalBinding) || (sym->GetBinding() == WeakBinding)) m_allEntries.push_back(sym); } - for (auto& sym: data->GetSymbolsOfType(DataSymbol)) + for (auto& sym : data->GetSymbolsOfType(DataSymbol)) { if ((sym->GetBinding() == GlobalBinding) || (sym->GetBinding() == WeakBinding)) m_allEntries.push_back(sym); @@ -148,7 +148,7 @@ void GenericExportsModel::setFilter(const std::string& filterText) { beginResetModel(); m_entries.clear(); - for (auto& entry: m_allEntries) + for (auto& entry : m_allEntries) { if (FilteredView::match(entry->GetFullName(), filterText)) m_entries.push_back(entry); @@ -158,7 +158,7 @@ void GenericExportsModel::setFilter(const std::string& filterText) } -ExportsTreeView::ExportsTreeView(ExportsWidget* parent, TriageView* view, BinaryViewRef data): QTreeView(parent) +ExportsTreeView::ExportsTreeView(ExportsWidget* parent, TriageView* view, BinaryViewRef data) : QTreeView(parent) { m_data = data; m_parent = parent; @@ -262,7 +262,7 @@ void ExportsTreeView::keyPressEvent(QKeyEvent* event) } -ExportsWidget::ExportsWidget(QWidget* parent, TriageView* view, BinaryViewRef data): QWidget(parent) +ExportsWidget::ExportsWidget(QWidget* parent, TriageView* view, BinaryViewRef data) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(); layout->setContentsMargins(0, 0, 0, 0); diff --git a/examples/triage/exports.h b/examples/triage/exports.h index e79fe7eb..bb0c4411 100644 --- a/examples/triage/exports.h +++ b/examples/triage/exports.h @@ -5,7 +5,7 @@ #include "filter.h" -class GenericExportsModel: public QAbstractItemModel +class GenericExportsModel : public QAbstractItemModel { std::vector<SymbolRef> m_allEntries, m_entries; int m_addrCol, m_nameCol, m_ordinalCol; @@ -14,7 +14,7 @@ class GenericExportsModel: public QAbstractItemModel void performSort(int col, Qt::SortOrder order); -public: + public: GenericExportsModel(BinaryViewRef data); virtual int columnCount(const QModelIndex& parent) const override; @@ -36,7 +36,7 @@ public: class TriageView; class ExportsWidget; -class ExportsTreeView: public QTreeView, public FilterTarget +class ExportsTreeView : public QTreeView, public FilterTarget { BinaryViewRef m_data; ExportsWidget* m_parent; @@ -44,7 +44,7 @@ class ExportsTreeView: public QTreeView, public FilterTarget UIActionHandler m_actionHandler; GenericExportsModel* m_model; -public: + public: ExportsTreeView(ExportsWidget* parent, TriageView* view, BinaryViewRef data); virtual void setFilter(const std::string& filterText) override; @@ -54,20 +54,20 @@ public: virtual void activateFirstItem() override; virtual void closeFilter() override; -protected: + protected: virtual void keyPressEvent(QKeyEvent* event) override; -private Q_SLOTS: + private Q_SLOTS: void exportSelected(const QModelIndex& cur, const QModelIndex& prev); void exportDoubleClicked(const QModelIndex& cur); }; -class ExportsWidget: public QWidget +class ExportsWidget : public QWidget { FilteredView* m_filter; -public: + public: ExportsWidget(QWidget* parent, TriageView* view, BinaryViewRef data); void showFilter(const QString& filter); }; diff --git a/examples/triage/fileinfo.cpp b/examples/triage/fileinfo.cpp index 2ff7cf38..ddb94897 100644 --- a/examples/triage/fileinfo.cpp +++ b/examples/triage/fileinfo.cpp @@ -6,94 +6,92 @@ #include <QToolTip> #include <QPainter> -class CopyableLabel: public QLabel +class CopyableLabel : public QLabel { - QColor m_desiredColor{}; + QColor m_desiredColor {}; -public: - CopyableLabel(const QString& text, const QColor& color) - : QLabel(text), m_desiredColor(color) - { - this->setMouseTracking(true); - auto style = QPalette(palette()); - style.setColor(QPalette::WindowText, m_desiredColor); - setPalette(style); - this->setToolTip("Copy"); - } + public: + CopyableLabel(const QString& text, const QColor& color) : QLabel(text), m_desiredColor(color) + { + this->setMouseTracking(true); + auto style = QPalette(palette()); + style.setColor(QPalette::WindowText, m_desiredColor); + setPalette(style); + this->setToolTip("Copy"); + } - void enterEvent(QEnterEvent* event) override - { - auto font = this->font(); - font.setBold(true); - this->setFont(font); - QToolTip::showText(event->globalPosition().toPoint(), this->toolTip()); - } + void enterEvent(QEnterEvent* event) override + { + auto font = this->font(); + font.setBold(true); + this->setFont(font); + QToolTip::showText(event->globalPosition().toPoint(), this->toolTip()); + } - void leaveEvent(QEvent* event) override - { - auto font = this->font(); - font.setBold(false); - this->setFont(font); - QToolTip::hideText(); - } + void leaveEvent(QEvent* event) override + { + auto font = this->font(); + font.setBold(false); + this->setFont(font); + QToolTip::hideText(); + } - void mousePressEvent(QMouseEvent* event) override - { - if (event->button() == Qt::LeftButton) - QApplication::clipboard()->setText(this->text()); - } + void mousePressEvent(QMouseEvent* event) override + { + if (event->button() == Qt::LeftButton) + QApplication::clipboard()->setText(this->text()); + } }; void FileInfoWidget::addField(const QString& name, const QVariant& value) { - auto& [row, column] = this->m_fieldPosition; + auto& [row, column] = this->m_fieldPosition; - const auto valueLabel = new QLabel(value.toString()); - valueLabel->setFont(getMonospaceFont(this)); + const auto valueLabel = new QLabel(value.toString()); + valueLabel->setFont(getMonospaceFont(this)); - this->m_layout->addWidget(new QLabel(name), row, column); - this->m_layout->addWidget(valueLabel, row++, column + 1); + this->m_layout->addWidget(new QLabel(name), row, column); + this->m_layout->addWidget(valueLabel, row++, column + 1); } -void FileInfoWidget::addHashField(const QString& hashName, - const QCryptographicHash::Algorithm& algorithm, - const QByteArray& data) +void FileInfoWidget::addHashField( + const QString& hashName, const QCryptographicHash::Algorithm& algorithm, const QByteArray& data) { - auto& [row, column] = this->m_fieldPosition; + auto& [row, column] = this->m_fieldPosition; - const auto hashFieldColor = getThemeColor(AlphanumericHighlightColor); - const auto crypto = QCryptographicHash::hash(data, algorithm); - const auto hashLabel = new CopyableLabel(crypto.toHex(), hashFieldColor); - hashLabel->setFont(getMonospaceFont(this)); + const auto hashFieldColor = getThemeColor(AlphanumericHighlightColor); + const auto crypto = QCryptographicHash::hash(data, algorithm); + const auto hashLabel = new CopyableLabel(crypto.toHex(), hashFieldColor); + hashLabel->setFont(getMonospaceFont(this)); - this->m_layout->addWidget(new QLabel(hashName), row, column); - this->m_layout->addWidget(hashLabel, row++, column + 1); + this->m_layout->addWidget(new QLabel(hashName), row, column); + this->m_layout->addWidget(hashLabel, row++, column + 1); } FileInfoWidget::FileInfoWidget(QWidget* parent, BinaryViewRef bv) { - this->m_layout = new QGridLayout(); - this->m_layout->setContentsMargins(0, 0, 0, 0); - this->m_layout->setVerticalSpacing(1); + this->m_layout = new QGridLayout(); + this->m_layout->setContentsMargins(0, 0, 0, 0); + this->m_layout->setVerticalSpacing(1); - const auto view = bv->GetParentView() ? bv->GetParentView() : bv; - const auto filePath = bv->GetFile()->GetOriginalFilename(); - this->addField("Path: ", filePath.c_str()); + const auto view = bv->GetParentView() ? bv->GetParentView() : bv; + const auto filePath = bv->GetFile()->GetOriginalFilename(); + this->addField("Path: ", filePath.c_str()); - const auto fileSize = QString::number(view->GetLength(), 16).prepend("0x"); - this->addField("Size: ", fileSize); + const auto fileSize = QString::number(view->GetLength(), 16).prepend("0x"); + this->addField("Size: ", fileSize); - const auto bufferSize = fileSize.toUInt(nullptr, 16); - const auto fileBuffer = std::make_unique<char[]>(bufferSize); - view->Read(fileBuffer.get(), 0, bufferSize); + const auto bufferSize = fileSize.toUInt(nullptr, 16); + const auto fileBuffer = std::make_unique<char[]>(bufferSize); + view->Read(fileBuffer.get(), 0, bufferSize); - const auto fileBytes = QByteArray(fileBuffer.get(), bufferSize); - this->addHashField("MD5: ", QCryptographicHash::Md5, fileBytes); - this->addHashField("SHA-1: ", QCryptographicHash::Sha1, fileBytes); - this->addHashField("SHA-256: ", QCryptographicHash::Sha256, fileBytes); + const auto fileBytes = QByteArray(fileBuffer.get(), bufferSize); + this->addHashField("MD5: ", QCryptographicHash::Md5, fileBytes); + this->addHashField("SHA-1: ", QCryptographicHash::Sha1, fileBytes); + this->addHashField("SHA-256: ", QCryptographicHash::Sha256, fileBytes); - const auto scaledWidth = UIContext::getScaledWindowSize(20, 20).width(); - this->m_layout->setColumnMinimumWidth(FileInfoWidget::m_maxColumns * 3 - 1, scaledWidth); - this->m_layout->setColumnStretch(FileInfoWidget::m_maxColumns * 3 - 1, 1); - setLayout(this->m_layout); + const auto scaledWidth = UIContext::getScaledWindowSize(20, 20).width(); + this->m_layout->setColumnMinimumWidth(FileInfoWidget::m_maxColumns * 3 - 1, scaledWidth); + this->m_layout->setColumnStretch(FileInfoWidget::m_maxColumns * 3 - 1, 1); + setLayout(this->m_layout); }
\ No newline at end of file diff --git a/examples/triage/fileinfo.h b/examples/triage/fileinfo.h index 02cc154d..14a7ec3c 100644 --- a/examples/triage/fileinfo.h +++ b/examples/triage/fileinfo.h @@ -5,17 +5,15 @@ #include "uitypes.h" #include "viewframe.h" -class FileInfoWidget: public QWidget +class FileInfoWidget : public QWidget { - static constexpr std::int32_t m_maxColumns{2}; - std::pair<std::int32_t, std::int32_t> m_fieldPosition{}; // row, column - QGridLayout* m_layout{}; + static constexpr std::int32_t m_maxColumns {2}; + std::pair<std::int32_t, std::int32_t> m_fieldPosition {}; // row, column + QGridLayout* m_layout {}; - void addField(const QString& name, const QVariant& value); - void addHashField(const QString& hashName, - const QCryptographicHash::Algorithm& algorithm, - const QByteArray& data); + void addField(const QString& name, const QVariant& value); + void addHashField(const QString& hashName, const QCryptographicHash::Algorithm& algorithm, const QByteArray& data); -public: - FileInfoWidget(QWidget* parent, BinaryViewRef bv); + public: + FileInfoWidget(QWidget* parent, BinaryViewRef bv); }; diff --git a/examples/triage/files.cpp b/examples/triage/files.cpp index fcb71cd0..d70b61cd 100644 --- a/examples/triage/files.cpp +++ b/examples/triage/files.cpp @@ -18,7 +18,7 @@ TriageFilePicker::TriageFilePicker(UIContext* context) m_model = new QFileSystemModel(); m_model->setRootPath(""); if (hiddenFiles) - m_model->setFilter(QDir::Hidden | QDir::AllEntries | QDir::System ); + m_model->setFilter(QDir::Hidden | QDir::AllEntries | QDir::System); m_tree = new QTreeView(this); m_tree->setModel(m_model); m_tree->setSelectionMode(QAbstractItemView::ExtendedSelection); @@ -45,9 +45,8 @@ TriageFilePicker::TriageFilePicker(UIContext* context) recentFile = parentDir; } - m_actionHandler.bindAction("Open Selected Files", UIAction( - [=]() { openSelectedFiles(); }, - [=]() { return areFilesSelected(); })); + m_actionHandler.bindAction( + "Open Selected Files", UIAction([=]() { openSelectedFiles(); }, [=]() { return areFilesSelected(); })); m_contextMenu.addAction("Open Selected Files", "Open"); } @@ -70,11 +69,11 @@ void TriageFilePicker::openSelectedFiles() std::set<QString> files; SettingsRef settings = BinaryNinja::Settings::Instance(); - for (auto& index: m_tree->selectionModel()->selectedIndexes()) + for (auto& index : m_tree->selectionModel()->selectedIndexes()) if (m_model->fileInfo(index).isFile()) files.insert(m_model->fileInfo(index).absoluteFilePath()); - for (auto& filename: files) + for (auto& filename : files) { QSettings().setValue("triage/recentFile", filename); @@ -85,7 +84,7 @@ void TriageFilePicker::openSelectedFiles() continue; } - for (auto data: f->getAllDataViews()) + for (auto data : f->getAllDataViews()) { settings->Set("analysis.mode", settings->Get<std::string>("triage.analysisMode"), data); settings->Set("triage.preferSummaryView", true, data); @@ -118,7 +117,7 @@ void TriageFilePicker::openSelectedFiles() if (failedToOpen.size() > 0) { QString message = "Unable to open:\n"; - for (auto& name: failedToOpen) + for (auto& name : failedToOpen) message += name + "\n"; QMessageBox::critical(this, "Error", message); } diff --git a/examples/triage/files.h b/examples/triage/files.h index e371d869..01d8e75e 100644 --- a/examples/triage/files.h +++ b/examples/triage/files.h @@ -3,15 +3,15 @@ #include <QtWidgets/QWidget> #include <QtWidgets/QTreeView> #if QT_VERSION < QT_VERSION_CHECK(6, 0, 0) -#include <QtWidgets/QFileSystemModel> + #include <QtWidgets/QFileSystemModel> #else -#include <QtGui/QFileSystemModel> + #include <QtGui/QFileSystemModel> #endif #include "action.h" #include "menus.h" -class TriageFilePicker: public QWidget +class TriageFilePicker : public QWidget { UIContext* m_context; UIActionHandler m_actionHandler; @@ -24,12 +24,12 @@ class TriageFilePicker: public QWidget void openSelectedFiles(); bool areFilesSelected(); -public: + public: TriageFilePicker(UIContext* context); -protected: + protected: virtual void contextMenuEvent(QContextMenuEvent*) override; -private Q_SLOTS: + private Q_SLOTS: void onDoubleClick(const QModelIndex& idx); }; diff --git a/examples/triage/headers.cpp b/examples/triage/headers.cpp index 7b8de78e..e327153e 100644 --- a/examples/triage/headers.cpp +++ b/examples/triage/headers.cpp @@ -6,8 +6,8 @@ #include "viewframe.h" -NavigationLabel::NavigationLabel(const QString& text, QColor color, const std::function<void()>& func): - QLabel(text), m_func(func) +NavigationLabel::NavigationLabel(const QString& text, QColor color, const std::function<void()>& func) : + QLabel(text), m_func(func) { QPalette style(palette()); style.setColor(QPalette::WindowText, color); @@ -22,8 +22,8 @@ void NavigationLabel::mousePressEvent(QMouseEvent*) } -NavigationAddressLabel::NavigationAddressLabel(const QString& text): - NavigationLabel(text, getThemeColor(AddressColor), [this]() { clickEvent(); }) +NavigationAddressLabel::NavigationAddressLabel(const QString& text) : + NavigationLabel(text, getThemeColor(AddressColor), [this]() { clickEvent(); }) { m_address = text.toULongLong(nullptr, 0); } @@ -37,8 +37,8 @@ void NavigationAddressLabel::clickEvent() } -NavigationCodeLabel::NavigationCodeLabel(const QString& text): - NavigationLabel(text, getThemeColor(CodeSymbolColor), [this]() { clickEvent(); }) +NavigationCodeLabel::NavigationCodeLabel(const QString& text) : + NavigationLabel(text, getThemeColor(CodeSymbolColor), [this]() { clickEvent(); }) { m_address = text.toULongLong(nullptr, 0); } @@ -52,20 +52,18 @@ void NavigationCodeLabel::clickEvent() } -Headers::Headers(): m_columns(1), m_rowsPerColumn(8) -{ -} +Headers::Headers() : m_columns(1), m_rowsPerColumn(8) {} void Headers::AddField(const QString& title, const QString& value, HeaderFieldType type) { - m_fields.push_back(HeaderField { title, {value}, type }); + m_fields.push_back(HeaderField {title, {value}, type}); } void Headers::AddField(const QString& title, const std::vector<QString>& values, HeaderFieldType type) { - m_fields.push_back(HeaderField { title, values, type }); + m_fields.push_back(HeaderField {title, values, type}); } @@ -174,40 +172,39 @@ PEHeaders::PEHeaders(BinaryViewRef data) uint64_t stackCommit = GetValueOfStructMember(data, optHeaderName, optHeaderStart, "sizeOfStackCommit"); uint64_t stackReserve = GetValueOfStructMember(data, optHeaderName, optHeaderStart, "sizeOfStackReserve"); - AddField("Stack Size", QString("0x") + QString::number(stackCommit, 16) + QString(" / 0x") + - QString::number(stackReserve, 16)); + AddField("Stack Size", + QString("0x") + QString::number(stackCommit, 16) + QString(" / 0x") + QString::number(stackReserve, 16)); uint64_t heapCommit = GetValueOfStructMember(data, optHeaderName, optHeaderStart, "sizeOfHeapCommit"); uint64_t heapReserve = GetValueOfStructMember(data, optHeaderName, optHeaderStart, "sizeOfHeapReserve"); - AddField("Heap Size", QString("0x") + QString::number(heapCommit, 16) + QString(" / 0x") + - QString::number(heapReserve, 16)); + AddField("Heap Size", + QString("0x") + QString::number(heapCommit, 16) + QString(" / 0x") + QString::number(heapReserve, 16)); uint64_t linkerMajor = GetValueOfStructMember(data, optHeaderName, optHeaderStart, "majorLinkerVersion"); uint64_t linkerMinor = GetValueOfStructMember(data, optHeaderName, optHeaderStart, "minorLinkerVersion"); - AddField("Linker Version", QString::number(linkerMajor) + QString(".") + - QString::number(linkerMinor).rightJustified(2, '0')); + AddField("Linker Version", + QString::number(linkerMajor) + QString(".") + QString::number(linkerMinor).rightJustified(2, '0')); uint64_t imageMajor = GetValueOfStructMember(data, optHeaderName, optHeaderStart, "majorImageVersion"); uint64_t imageMinor = GetValueOfStructMember(data, optHeaderName, optHeaderStart, "minorImageVersion"); - AddField("Image Version", QString::number(imageMajor) + QString(".") + - QString::number(imageMinor).rightJustified(2, '0')); + AddField("Image Version", + QString::number(imageMajor) + QString(".") + QString::number(imageMinor).rightJustified(2, '0')); uint64_t osMajor = GetValueOfStructMember(data, optHeaderName, optHeaderStart, "majorOperatingSystemVersion"); uint64_t osMinor = GetValueOfStructMember(data, optHeaderName, optHeaderStart, "minorOperatingSystemVersion"); - AddField("OS Version", QString::number(osMajor) + QString(".") + - QString::number(osMinor).rightJustified(2, '0')); + AddField("OS Version", QString::number(osMajor) + QString(".") + QString::number(osMinor).rightJustified(2, '0')); uint64_t subMajor = GetValueOfStructMember(data, optHeaderName, optHeaderStart, "majorSubsystemVersion"); uint64_t subMinor = GetValueOfStructMember(data, optHeaderName, optHeaderStart, "minorSubsystemVersion"); - AddField("Subsystem Version", QString::number(subMajor) + QString(".") + - QString::number(subMinor).rightJustified(2, '0')); + AddField("Subsystem Version", + QString::number(subMajor) + QString(".") + QString::number(subMinor).rightJustified(2, '0')); uint64_t coffCharValue = GetValueOfStructMember(data, "COFF_Header", peOffset, "characteristics"); TypeRef coffCharEnum = data->GetTypeByName(BinaryNinja::QualifiedName("coff_characteristics")); if (coffCharEnum && (coffCharEnum->GetClass() == EnumerationTypeClass)) { std::vector<QString> coffCharValues; - for (auto& member: coffCharEnum->GetEnumeration()->GetMembers()) + for (auto& member : coffCharEnum->GetEnumeration()->GetMembers()) { if (coffCharValue & member.value) { @@ -226,12 +223,13 @@ PEHeaders::PEHeaders(BinaryViewRef data) if (dllCharEnum && (dllCharEnum->GetClass() == EnumerationTypeClass)) { std::vector<QString> dllCharValues; - for (auto& member: dllCharEnum->GetEnumeration()->GetMembers()) + for (auto& member : dllCharEnum->GetEnumeration()->GetMembers()) { if (dllCharValue & member.value) { if (QString::fromStdString(member.name).startsWith("IMAGE_DLLCHARACTERISTICS_")) - dllCharValues.push_back(QString::fromStdString(member.name).mid((int)strlen("IMAGE_DLLCHARACTERISTICS_"))); + dllCharValues.push_back( + QString::fromStdString(member.name).mid((int)strlen("IMAGE_DLLCHARACTERISTICS_"))); else dllCharValues.push_back(QString::fromStdString(member.name)); } @@ -245,8 +243,8 @@ PEHeaders::PEHeaders(BinaryViewRef data) } -uint64_t PEHeaders::GetValueOfStructMember(BinaryViewRef data, const std::string& structName, uint64_t structStart, - const std::string& fieldName) +uint64_t PEHeaders::GetValueOfStructMember( + BinaryViewRef data, const std::string& structName, uint64_t structStart, const std::string& fieldName) { TypeRef type = data->GetTypeByName(structName); if (!type) @@ -254,7 +252,7 @@ uint64_t PEHeaders::GetValueOfStructMember(BinaryViewRef data, const std::string if (type->GetClass() != StructureTypeClass) return 0; StructureRef s = type->GetStructure(); - for (auto& member: s->GetMembers()) + for (auto& member : s->GetMembers()) { if (member.name == fieldName) { @@ -285,7 +283,7 @@ QString PEHeaders::GetNameOfEnumerationMember(BinaryViewRef data, const std::str TypeRef type = data->GetTypeByName(enumName); if (type && (type->GetClass() == EnumerationTypeClass)) { - for (auto& member: type->GetEnumeration()->GetMembers()) + for (auto& member : type->GetEnumeration()->GetMembers()) { if (member.value == value) return QString::fromStdString(member.name); @@ -295,17 +293,17 @@ QString PEHeaders::GetNameOfEnumerationMember(BinaryViewRef data, const std::str } -HeaderWidget::HeaderWidget(QWidget* parent, const Headers& header): QWidget(parent) +HeaderWidget::HeaderWidget(QWidget* parent, const Headers& header) : QWidget(parent) { QGridLayout* layout = new QGridLayout(); layout->setContentsMargins(0, 0, 0, 0); layout->setVerticalSpacing(1); int row = 0; int col = 0; - for (auto& field: header.GetFields()) + for (auto& field : header.GetFields()) { layout->addWidget(new QLabel(field.title + ": "), row, col * 3); - for (auto& value: field.values) + for (auto& value : field.values) { QWidget* label; if (field.type == AddressHeaderField) @@ -324,7 +322,8 @@ HeaderWidget::HeaderWidget(QWidget* parent, const Headers& header): QWidget(pare layout->addWidget(label, row, col * 3 + 1); row++; } - if ((header.GetColumns() > 1) && (row >= (int)header.GetRowsPerColumn()) && ((col + 1) < (int)header.GetColumns())) + if ((header.GetColumns() > 1) && (row >= (int)header.GetRowsPerColumn()) + && ((col + 1) < (int)header.GetColumns())) { row = 0; col++; diff --git a/examples/triage/headers.h b/examples/triage/headers.h index 0a9af5ff..a8348401 100644 --- a/examples/triage/headers.h +++ b/examples/triage/headers.h @@ -6,36 +6,36 @@ #include "uitypes.h" -class NavigationLabel: public QLabel +class NavigationLabel : public QLabel { std::function<void()> m_func; -public: + public: NavigationLabel(const QString& text, QColor color, const std::function<void()>& func); -protected: + protected: virtual void mousePressEvent(QMouseEvent* event) override; }; -class NavigationAddressLabel: public NavigationLabel +class NavigationAddressLabel : public NavigationLabel { uint64_t m_address; void clickEvent(); -public: + public: NavigationAddressLabel(const QString& text); }; -class NavigationCodeLabel: public NavigationLabel +class NavigationCodeLabel : public NavigationLabel { uint64_t m_address; void clickEvent(); -public: + public: NavigationCodeLabel(const QString& text); }; @@ -61,7 +61,7 @@ class Headers std::vector<HeaderField> m_fields; size_t m_columns, m_rowsPerColumn; -public: + public: Headers(); void AddField(const QString& title, const QString& value, HeaderFieldType type = TextHeaderField); void AddField(const QString& title, const std::vector<QString>& values, HeaderFieldType type = TextHeaderField); @@ -73,27 +73,27 @@ public: }; -class GenericHeaders: public Headers +class GenericHeaders : public Headers { -public: + public: GenericHeaders(BinaryViewRef data); }; -class PEHeaders: public Headers +class PEHeaders : public Headers { - uint64_t GetValueOfStructMember(BinaryViewRef data, const std::string& structName, uint64_t structStart, - const std::string& fieldName); + uint64_t GetValueOfStructMember( + BinaryViewRef data, const std::string& structName, uint64_t structStart, const std::string& fieldName); uint64_t GetAddressAfterStruct(BinaryViewRef data, const std::string& structName, uint64_t structStart); QString GetNameOfEnumerationMember(BinaryViewRef data, const std::string& enumName, uint64_t value); -public: + public: PEHeaders(BinaryViewRef data); }; -class HeaderWidget: public QWidget +class HeaderWidget : public QWidget { -public: + public: HeaderWidget(QWidget* parent, const Headers& headers); }; diff --git a/examples/triage/imports.cpp b/examples/triage/imports.cpp index 7a0c0d2a..79c1f35e 100644 --- a/examples/triage/imports.cpp +++ b/examples/triage/imports.cpp @@ -14,7 +14,7 @@ GenericImportsModel::GenericImportsModel(BinaryViewRef data) m_sortCol = 0; m_sortOrder = Qt::AscendingOrder; m_allEntries = data->GetSymbolsOfType(ImportAddressSymbol); - for (auto& sym: m_allEntries) + for (auto& sym : m_allEntries) { if ((sym->GetNameSpace().size() != 1) || (sym->GetNameSpace()[0] != "BNINTERNALNAMESPACE")) { @@ -168,7 +168,7 @@ void GenericImportsModel::setFilter(const std::string& filterText) { beginResetModel(); m_entries.clear(); - for (auto& entry: m_allEntries) + for (auto& entry : m_allEntries) { if (FilteredView::match(entry->GetFullName(), filterText)) m_entries.push_back(entry); @@ -180,7 +180,7 @@ void GenericImportsModel::setFilter(const std::string& filterText) } -ImportsTreeView::ImportsTreeView(ImportsWidget* parent, TriageView* view, BinaryViewRef data): QTreeView(parent) +ImportsTreeView::ImportsTreeView(ImportsWidget* parent, TriageView* view, BinaryViewRef data) : QTreeView(parent) { m_data = data; m_parent = parent; @@ -279,7 +279,7 @@ void ImportsTreeView::keyPressEvent(QKeyEvent* event) } -ImportsWidget::ImportsWidget(QWidget* parent, TriageView* view, BinaryViewRef data): QWidget(parent) +ImportsWidget::ImportsWidget(QWidget* parent, TriageView* view, BinaryViewRef data) : QWidget(parent) { QVBoxLayout* layout = new QVBoxLayout(); layout->setContentsMargins(0, 0, 0, 0); diff --git a/examples/triage/imports.h b/examples/triage/imports.h index cacda087..2199aa47 100644 --- a/examples/triage/imports.h +++ b/examples/triage/imports.h @@ -5,7 +5,7 @@ #include "filter.h" -class GenericImportsModel: public QAbstractItemModel +class GenericImportsModel : public QAbstractItemModel { std::vector<SymbolRef> m_allEntries, m_entries; bool m_hasModules; @@ -16,7 +16,7 @@ class GenericImportsModel: public QAbstractItemModel QString getNamespace(SymbolRef sym) const; void performSort(int col, Qt::SortOrder order); -public: + public: GenericImportsModel(BinaryViewRef data); virtual int columnCount(const QModelIndex& parent) const override; @@ -38,7 +38,7 @@ public: class TriageView; class ImportsWidget; -class ImportsTreeView: public QTreeView, public FilterTarget +class ImportsTreeView : public QTreeView, public FilterTarget { BinaryViewRef m_data; ImportsWidget* m_parent; @@ -46,7 +46,7 @@ class ImportsTreeView: public QTreeView, public FilterTarget UIActionHandler m_actionHandler; GenericImportsModel* m_model; -public: + public: ImportsTreeView(ImportsWidget* parent, TriageView* view, BinaryViewRef data); virtual void setFilter(const std::string& filterText) override; @@ -56,20 +56,20 @@ public: virtual void activateFirstItem() override; virtual void closeFilter() override; -protected: + protected: virtual void keyPressEvent(QKeyEvent* event) override; -private Q_SLOTS: + private Q_SLOTS: void importSelected(const QModelIndex& cur, const QModelIndex& prev); void importDoubleClicked(const QModelIndex& cur); }; -class ImportsWidget: public QWidget +class ImportsWidget : public QWidget { FilteredView* m_filter; -public: + public: ImportsWidget(QWidget* parent, TriageView* view, BinaryViewRef data); void showFilter(const QString& filter); }; diff --git a/examples/triage/sections.cpp b/examples/triage/sections.cpp index 026b3d7b..95993031 100644 --- a/examples/triage/sections.cpp +++ b/examples/triage/sections.cpp @@ -7,22 +7,21 @@ #include "fontsettings.h" -SegmentsWidget::SegmentsWidget(QWidget* parent, BinaryViewRef data): QWidget(parent) +SegmentsWidget::SegmentsWidget(QWidget* parent, BinaryViewRef data) : QWidget(parent) { QGridLayout* layout = new QGridLayout(); layout->setContentsMargins(0, 0, 0, 0); layout->setVerticalSpacing(1); layout->setHorizontalSpacing(UIContext::getScaledWindowSize(16, 16).width()); - for (auto& segment: data->GetSegments()) + for (auto& segment : data->GetSegments()) if ((segment->GetFlags() & (SegmentReadable | SegmentWritable | SegmentExecutable)) != 0) m_segments.push_back(segment); - sort(m_segments.begin(), m_segments.end(), [&](SegmentRef a, SegmentRef b) { - return a->GetStart() < b->GetStart(); - }); + sort(m_segments.begin(), m_segments.end(), + [&](SegmentRef a, SegmentRef b) { return a->GetStart() < b->GetStart(); }); int row = 0; - for (auto& segment: m_segments) + for (auto& segment : m_segments) { QString begin = QString("0x") + QString::number(segment->GetStart(), 16); QString end = QString("0x") + QString::number(segment->GetEnd(), 16); @@ -64,7 +63,7 @@ SegmentsWidget::SegmentsWidget(QWidget* parent, BinaryViewRef data): QWidget(par } -SectionsWidget::SectionsWidget(QWidget* parent, BinaryViewRef data): QWidget(parent) +SectionsWidget::SectionsWidget(QWidget* parent, BinaryViewRef data) : QWidget(parent) { QGridLayout* layout = new QGridLayout(); layout->setContentsMargins(0, 0, 0, 0); @@ -72,21 +71,20 @@ SectionsWidget::SectionsWidget(QWidget* parent, BinaryViewRef data): QWidget(par layout->setHorizontalSpacing(UIContext::getScaledWindowSize(16, 16).width()); size_t maxNameLen = 0; - for (auto& section: data->GetSections()) + for (auto& section : data->GetSections()) if (section->GetName().size() > maxNameLen) maxNameLen = section->GetName().size(); if (maxNameLen > 32) maxNameLen = 32; - for (auto& section: data->GetSections()) + for (auto& section : data->GetSections()) if (section->GetSemantics() != ExternalSectionSemantics) m_sections.push_back(section); - sort(m_sections.begin(), m_sections.end(), [&](SectionRef a, SectionRef b) { - return a->GetStart() < b->GetStart(); - }); + sort(m_sections.begin(), m_sections.end(), + [&](SectionRef a, SectionRef b) { return a->GetStart() < b->GetStart(); }); int row = 0; - for (auto& section: m_sections) + for (auto& section : m_sections) { std::string name = section->GetName(); if (name.size() > maxNameLen) diff --git a/examples/triage/sections.h b/examples/triage/sections.h index 09c9ea63..00285df8 100644 --- a/examples/triage/sections.h +++ b/examples/triage/sections.h @@ -4,21 +4,21 @@ #include "uitypes.h" -class SegmentsWidget: public QWidget +class SegmentsWidget : public QWidget { std::vector<SegmentRef> m_segments; -public: + public: SegmentsWidget(QWidget* parent, BinaryViewRef data); const std::vector<SegmentRef>& GetSegments() const { return m_segments; } }; -class SectionsWidget: public QWidget +class SectionsWidget : public QWidget { std::vector<SectionRef> m_sections; -public: + public: SectionsWidget(QWidget* parent, BinaryViewRef data); const std::vector<SectionRef>& GetSections() const { return m_sections; } }; diff --git a/examples/triage/triage.cpp b/examples/triage/triage.cpp index 5d0dc1d5..b268f069 100644 --- a/examples/triage/triage.cpp +++ b/examples/triage/triage.cpp @@ -17,7 +17,7 @@ extern "C" SettingsRef settings = BinaryNinja::Settings::Instance(); settings->RegisterGroup("triage", "Triage"); settings->RegisterSetting("triage.preferSummaryView", - R"({ + R"({ "title" : "Always Prefer Triage Summary View", "type" : "boolean", "default" : false, @@ -25,7 +25,7 @@ extern "C" })"); settings->RegisterSetting("triage.preferSummaryViewForRaw", - R"({ + R"({ "title" : "Prefer Triage Summary View for Raw Files", "type" : "boolean", "default" : false, @@ -35,7 +35,7 @@ extern "C" ViewType::registerViewType(new TriageViewType()); settings->RegisterSetting("triage.analysisMode", - R"({ + R"({ "title" : "Triage Analysis Mode", "type" : "string", "default" : "basic", @@ -48,7 +48,7 @@ extern "C" })"); settings->RegisterSetting("triage.linearSweep", - R"({ + R"({ "title" : "Triage Linear Sweep Mode", "type" : "string", "default" : "partial", @@ -61,7 +61,7 @@ extern "C" })"); settings->RegisterSetting("triage.hiddenFiles", - R"({ + R"({ "title" : "Triage Shows Hidden Files", "type" : "boolean", "default" : false, @@ -85,7 +85,8 @@ extern "C" Menu::mainMenu("File")->addAction("Open for Triage...", "Open"); - UIContext::registerFileOpenMode("Triage...", "Open file(s) for quick analysis in the Triage Summary view.", "Open for Triage..."); + UIContext::registerFileOpenMode( + "Triage...", "Open file(s) for quick analysis in the Triage Summary view.", "Open for Triage..."); ViewType::registerViewType(new ByteViewType()); return true; diff --git a/examples/triage/view.cpp b/examples/triage/view.cpp index 2c5f7b9b..8a85ba26 100644 --- a/examples/triage/view.cpp +++ b/examples/triage/view.cpp @@ -11,7 +11,7 @@ #include "fontsettings.h" #include <binaryninjacore.h> -TriageView::TriageView(QWidget* parent, BinaryViewRef data): QScrollArea(parent) +TriageView::TriageView(QWidget* parent, BinaryViewRef data) : QScrollArea(parent) { setBinaryDataNavigable(true); setupView(this); @@ -26,11 +26,11 @@ TriageView::TriageView(QWidget* parent, BinaryViewRef data): QScrollArea(parent) entropyGroup->setLayout(entropyLayout); layout->addWidget(entropyGroup); - QGroupBox* fileInfoGroup = new QGroupBox("File Info", container); - QVBoxLayout* fileInfoLayout = new QVBoxLayout(); - fileInfoLayout->addWidget(new FileInfoWidget(fileInfoGroup, m_data)); - fileInfoGroup->setLayout(fileInfoLayout); - layout->addWidget(fileInfoGroup); + QGroupBox* fileInfoGroup = new QGroupBox("File Info", container); + QVBoxLayout* fileInfoLayout = new QVBoxLayout(); + fileInfoLayout->addWidget(new FileInfoWidget(fileInfoGroup, m_data)); + fileInfoGroup->setLayout(fileInfoLayout); + layout->addWidget(fileInfoGroup); Headers* hdr = nullptr; if (m_data->GetTypeName() == "PE") @@ -129,7 +129,7 @@ BNAddressRange TriageView::getSelectionOffsets() { if (m_byteView) return m_byteView->getSelectionOffsets(); - return { m_currentOffset, m_currentOffset }; + return {m_currentOffset, m_currentOffset}; } void TriageView::setSelectionOffsets(BNAddressRange range) @@ -164,7 +164,7 @@ bool TriageView::navigate(uint64_t addr) void TriageView::startFullAnalysis() { BinaryNinja::Settings::Instance()->Set("analysis.mode", "full", m_data); - for (auto& f: m_data->GetAnalysisFunctionList()) + for (auto& f : m_data->GetAnalysisFunctionList()) { if (f->IsAnalysisSkipped()) f->Reanalyze(); @@ -223,9 +223,7 @@ void TriageView::focusInEvent(QFocusEvent*) } -TriageViewType::TriageViewType(): ViewType("Triage", "Triage Summary") -{ -} +TriageViewType::TriageViewType() : ViewType("Triage", "Triage Summary") {} int TriageViewType::getPriority(BinaryViewRef data, const QString&) diff --git a/examples/triage/view.h b/examples/triage/view.h index 37e53e7c..354091fb 100644 --- a/examples/triage/view.h +++ b/examples/triage/view.h @@ -6,14 +6,14 @@ #include "byte.h" -class TriageView: public QScrollArea, public View +class TriageView : public QScrollArea, public View { BinaryViewRef m_data; uint64_t m_currentOffset = 0; ByteView* m_byteView = nullptr; QPushButton* m_fullAnalysisButton = nullptr; -public: + public: TriageView(QWidget* parent, BinaryViewRef data); virtual BinaryViewRef getData() override; @@ -26,17 +26,17 @@ public: void setCurrentOffset(uint64_t offset); void navigateToFileOffset(uint64_t offset); -protected: + protected: virtual void focusInEvent(QFocusEvent* event) override; -private Q_SLOTS: + private Q_SLOTS: void startFullAnalysis(); }; -class TriageViewType: public ViewType +class TriageViewType : public ViewType { -public: + public: TriageViewType(); virtual int getPriority(BinaryViewRef data, const QString& filename) override; virtual QWidget* create(BinaryViewRef data, ViewFrame* frame) override; diff --git a/examples/uinotification/uinotification.cpp b/examples/uinotification/uinotification.cpp index d9eada8e..5072d98a 100644 --- a/examples/uinotification/uinotification.cpp +++ b/examples/uinotification/uinotification.cpp @@ -31,21 +31,24 @@ void NotificationListener::OnContextClose(UIContext* context) bool NotificationListener::OnBeforeOpenDatabase(UIContext* context, FileMetadataRef metadata) { LogInfo("OnBeforeOpenDatabase"); - return QMessageBox::question(context->mainWindow(), "OnBeforeOpenDatabase", "OnBeforeOpenDatabase") == QMessageBox::StandardButton::Yes; + return QMessageBox::question(context->mainWindow(), "OnBeforeOpenDatabase", "OnBeforeOpenDatabase") + == QMessageBox::StandardButton::Yes; } bool NotificationListener::OnAfterOpenDatabase(UIContext* context, FileMetadataRef metadata, BinaryViewRef data) { LogInfo("OnAfterOpenDatabase"); - return QMessageBox::question(context->mainWindow(), "OnAfterOpenDatabase", "OnAfterOpenDatabase") == QMessageBox::StandardButton::Yes; + return QMessageBox::question(context->mainWindow(), "OnAfterOpenDatabase", "OnAfterOpenDatabase") + == QMessageBox::StandardButton::Yes; } bool NotificationListener::OnBeforeOpenFile(UIContext* context, FileContext* file) { LogInfo("OnBeforeOpenFile"); - return QMessageBox::question(context->mainWindow(), "OnBeforeOpenFile", "OnBeforeOpenFile") == QMessageBox::StandardButton::Yes; + return QMessageBox::question(context->mainWindow(), "OnBeforeOpenFile", "OnBeforeOpenFile") + == QMessageBox::StandardButton::Yes; } @@ -58,7 +61,8 @@ void NotificationListener::OnAfterOpenFile(UIContext* context, FileContext* file bool NotificationListener::OnBeforeSaveFile(UIContext* context, FileContext* file, ViewFrame* frame) { LogInfo("OnBeforeSaveFile"); - return QMessageBox::question(context->mainWindow(), "OnBeforeSaveFile", "OnBeforeSaveFile") == QMessageBox::StandardButton::Yes; + return QMessageBox::question(context->mainWindow(), "OnBeforeSaveFile", "OnBeforeSaveFile") + == QMessageBox::StandardButton::Yes; } @@ -71,7 +75,8 @@ void NotificationListener::OnAfterSaveFile(UIContext* context, FileContext* file bool NotificationListener::OnBeforeCloseFile(UIContext* context, FileContext* file, ViewFrame* frame) { LogInfo("OnBeforeCloseFile"); - return QMessageBox::question(context->mainWindow(), "OnBeforeCloseFile", "OnBeforeCloseFile") == QMessageBox::StandardButton::Yes; + return QMessageBox::question(context->mainWindow(), "OnBeforeCloseFile", "OnBeforeCloseFile") + == QMessageBox::StandardButton::Yes; } @@ -87,7 +92,8 @@ void NotificationListener::OnViewChange(UIContext* context, ViewFrame* frame, co } -void NotificationListener::OnAddressChange(UIContext* context, ViewFrame* frame, View* view, const ViewLocation& location) +void NotificationListener::OnAddressChange( + UIContext* context, ViewFrame* frame, View* view, const ViewLocation& location) { LogInfo("OnAddressChange: 0x%" PRIx64, location.getOffset()); } diff --git a/examples/uinotification/uinotification.h b/examples/uinotification/uinotification.h index 31ffbc34..a359a35a 100644 --- a/examples/uinotification/uinotification.h +++ b/examples/uinotification/uinotification.h @@ -2,10 +2,11 @@ #include "uicontext.h" -class NotificationListener: UIContextNotification +class NotificationListener : UIContextNotification { static NotificationListener* m_instance; -public: + + public: virtual void OnContextOpen(UIContext* context) override; virtual void OnContextClose(UIContext* context) override; virtual bool OnBeforeOpenDatabase(UIContext* context, FileMetadataRef metadata) override; @@ -17,7 +18,8 @@ public: virtual bool OnBeforeCloseFile(UIContext* context, FileContext* file, ViewFrame* frame) override; virtual void OnAfterCloseFile(UIContext* context, FileContext* file, ViewFrame* frame) override; virtual void OnViewChange(UIContext* context, ViewFrame* frame, const QString& type) override; - virtual void OnAddressChange(UIContext* context, ViewFrame* frame, View* view, const ViewLocation& location) override; + virtual void OnAddressChange( + UIContext* context, ViewFrame* frame, View* view, const ViewLocation& location) override; virtual bool GetNameForFile(UIContext* context, FileContext* file, QString& name) override; virtual bool GetNameForPath(UIContext* context, const QString& path, QString& name) override; diff --git a/examples/workflows/inliner/inliner.cpp b/examples/workflows/inliner/inliner.cpp index 4ce05a31..da54fbc2 100644 --- a/examples/workflows/inliner/inliner.cpp +++ b/examples/workflows/inliner/inliner.cpp @@ -18,7 +18,7 @@ using namespace BinaryNinja; using namespace std; #if defined(_MSC_VER) -#define snprintf _snprintf + #define snprintf _snprintf #endif @@ -68,7 +68,8 @@ extern "C" if (instr.operation != LLIL_CALL) { - LogWarn("Failed to inline function at: 0x%" PRIx64 ". Mapping to LLIL_CALL Failed!", instr.address); + LogWarn( + "Failed to inline function at: 0x%" PRIx64 ". Mapping to LLIL_CALL Failed!", instr.address); continue; } @@ -79,14 +80,17 @@ extern "C" platformAddr = target.value; else { - LogWarn("Failed to inline function at: 0x%" PRIx64 ". Destination not Constant!", instr.address); + LogWarn( + "Failed to inline function at: 0x%" PRIx64 ". Destination not Constant!", instr.address); continue; } size_t opLen = data->Read(opcode, instr.address, arch->GetMaxInstructionLength()); if (!opLen || !arch->GetInstructionInfo(opcode, instr.address, opLen, iInfo)) continue; - Ref<Platform> platform = iInfo.archTransitionByTargetAddr ? function->GetPlatform()->GetAssociatedPlatformByAddress(platformAddr) : function->GetPlatform(); + Ref<Platform> platform = iInfo.archTransitionByTargetAddr ? + function->GetPlatform()->GetAssociatedPlatformByAddress(platformAddr) : + function->GetPlatform(); if (platform) { Ref<Function> targetFunc = data->GetAnalysisFunction(platform, platformAddr); @@ -145,21 +149,21 @@ extern "C" // }, inlinerIsValid); PluginCommand::RegisterForFunction( - "Optimizer\\Inline Function at Current Call Site", - "Inline function call at current call site.", - [](BinaryView* view, Function* func) { - // TODO func->Inform("inlinedCallSites") - // TODO resolve multiple embedded inlines - std::lock_guard<std::mutex> lock(g_mutex); - g_callSiteInlines[view->GetObject()][func->GetStart()].insert(view->GetCurrentOffset()); - func->Reanalyze(); - }, inlinerIsValid); + "Optimizer\\Inline Function at Current Call Site", "Inline function call at current call site.", + [](BinaryView* view, Function* func) { + // TODO func->Inform("inlinedCallSites") + // TODO resolve multiple embedded inlines + std::lock_guard<std::mutex> lock(g_mutex); + g_callSiteInlines[view->GetObject()][func->GetStart()].insert(view->GetCurrentOffset()); + func->Reanalyze(); + }, + inlinerIsValid); Ref<Workflow> inlinerWorkflow = Workflow::Instance()->Clone("InlinerWorkflow"); inlinerWorkflow->RegisterActivity(new Activity("extension.functionInliner", &FunctionInliner)); inlinerWorkflow->Insert("core.function.translateTailCalls", "extension.functionInliner"); Workflow::RegisterWorkflow(inlinerWorkflow, - R"#({ + R"#({ "title" : "Function Inliner (Example)", "description" : "This analysis stands in as an example to demonstrate Binary Ninja's extensible analysis APIs. ***Note** this feature is under active development and subject to change without notice.", "capabilities" : [] diff --git a/examples/workflows/objectivec/objectivec.cpp b/examples/workflows/objectivec/objectivec.cpp index b3272f94..b5ce26c1 100644 --- a/examples/workflows/objectivec/objectivec.cpp +++ b/examples/workflows/objectivec/objectivec.cpp @@ -17,7 +17,7 @@ using namespace BinaryNinja; using namespace std; #if defined(_MSC_VER) -#define snprintf _snprintf + #define snprintf _snprintf #endif @@ -46,7 +46,7 @@ extern "C" return; BinaryReader reader(data); - reader.SetEndianness(data->GetDefaultEndianness()); // TODO fix GetDefaultEndianness for non-elf formats + reader.SetEndianness(data->GetDefaultEndianness()); // TODO fix GetDefaultEndianness for non-elf formats reader.Seek(constSection->GetStart()); reader.Read32(); @@ -62,13 +62,13 @@ extern "C" reader.Read64(); uint32_t methodListFlags = reader.Read32(); uint32_t methodListCount = reader.Read32(); - for (uint32_t i = 0; i < methodListCount; i++) // section end/symbol validation + for (uint32_t i = 0; i < methodListCount; i++) // section end/symbol validation { uint64_t selector = reader.Read64(); uint64_t typePtr = reader.Read64(); uint64_t impPtr = reader.Read64(); - //string methodName = reader.ReadCString(selector); - string typeEncoding = "";//reader.ReadCString(typePtr); + // string methodName = reader.ReadCString(selector); + string typeEncoding = ""; // reader.ReadCString(typePtr); g_classData[data->GetObject()].insert_or_assign(selector, std::forward_as_tuple(typeEncoding, impPtr)); } @@ -118,11 +118,13 @@ extern "C" if (msgSendAddr == (uint64_t)destExpr.GetValue().value) { auto params = instr.GetParameterExprs<LLIL_CALL_SSA>(); - if ((params.size() >= 2) && (params[0].operation == LLIL_REG_SSA) && (params[1].operation == LLIL_REG_SSA)) + if ((params.size() >= 2) && (params[0].operation == LLIL_REG_SSA) + && (params[1].operation == LLIL_REG_SSA)) { auto selfSSAReg = params[0].GetSourceSSARegister<LLIL_REG_SSA>(); auto selSSAReg = params[1].GetSourceSSARegister<LLIL_REG_SSA>(); - if (auto itr = classData.find(ssa->GetSSARegisterValue(selSSAReg).value); itr != classData.end()) + if (auto itr = classData.find(ssa->GetSSARegisterValue(selSSAReg).value); + itr != classData.end()) { size_t llilIndex = ssa->GetNonSSAInstructionIndex(instrIndex); LowLevelILInstruction llilInstr = llilFunc->GetInstruction(llilIndex); @@ -130,12 +132,13 @@ extern "C" const auto& [typeEncoding, impPtr] = itr->second; destExpr.Replace(llilFunc->ConstPointer(destExpr.size, impPtr, destExpr)); llilInstr.Replace(llilFunc->Call(destExpr.exprIndex, llilInstr)); - analysisContext->Inform("directRefs", "insert", impPtr, i->GetArchitecture(), instr.address); + analysisContext->Inform( + "directRefs", "insert", impPtr, i->GetArchitecture(), instr.address); updated = true; } // else - // LogError("ObjectiveC Workflow: missing classData for __objc_methname entry: 0x%" PRIx64 " at: 0x%" PRIx64, - // ssa->GetSSARegisterValue(selSSAReg).value, instr.address); + // LogError("ObjectiveC Workflow: missing classData for __objc_methname entry: 0x%" PRIx64 " + // at: 0x%" PRIx64, ssa->GetSSARegisterValue(selSSAReg).value, instr.address); } // else // LogError("Unhandled _objc_msgSend: 0x%" PRIx64, instr.address); @@ -157,7 +160,7 @@ extern "C" objectiveCWorkflow->RegisterActivity(new Activity("extension.objectiveC", &ObjectiveCAnalysis)); objectiveCWorkflow->Insert("core.function.translateTailCalls", "extension.objectiveC"); Workflow::RegisterWorkflow(objectiveCWorkflow, - R"#({ + R"#({ "title" : "Objective C Meta-Analysis (Example)", "description" : "This analysis stands in as an example to demonstrate Binary Ninja's extensible analysis APIs. ***Note** this feature is under active development and subject to change without notice.", "capabilities" : [] diff --git a/examples/workflows/tailcall/tailcall.cpp b/examples/workflows/tailcall/tailcall.cpp index 3d8613c4..01190987 100644 --- a/examples/workflows/tailcall/tailcall.cpp +++ b/examples/workflows/tailcall/tailcall.cpp @@ -17,7 +17,7 @@ using namespace BinaryNinja; using namespace std; #if defined(_MSC_VER) -#define snprintf _snprintf + #define snprintf _snprintf #endif @@ -52,7 +52,8 @@ extern "C" RegisterValue target = destExpr.GetValue(); if (target.IsConstant()) platformAddr = target.value; - else if (target.state == ImportedAddressValue) // Call to imported function, look up type from import symbol + else if (target.state + == ImportedAddressValue) // Call to imported function, look up type from import symbol platformAddr = target.value; else if (target.state == ExternalPointerValue && target.offset == 0) platformAddr = target.value; @@ -62,7 +63,9 @@ extern "C" size_t opLen = data->Read(opcode, instr.address, arch->GetMaxInstructionLength()); if (!opLen || !arch->GetInstructionInfo(opcode, instr.address, opLen, iInfo)) continue; - Ref<Platform> platform = iInfo.archTransitionByTargetAddr ? function->GetPlatform()->GetAssociatedPlatformByAddress(platformAddr) : function->GetPlatform(); + Ref<Platform> platform = iInfo.archTransitionByTargetAddr ? + function->GetPlatform()->GetAssociatedPlatformByAddress(platformAddr) : + function->GetPlatform(); if (platform) { bool canReturn = true; @@ -72,7 +75,8 @@ extern "C" DataVariable var; if (data->GetDataVariableAtAddress(target.value, var)) { - if (var.type && (var.type->GetClass() == PointerTypeClass) && (var.type->GetChildType()->GetClass() == FunctionTypeClass)) + if (var.type && (var.type->GetClass() == PointerTypeClass) + && (var.type->GetChildType()->GetClass() == FunctionTypeClass)) canReturn = var.type->GetChildType()->CanReturn().GetValue(); } } @@ -119,7 +123,7 @@ extern "C" customTailCallWorkflow->Replace("core.function.translateTailCalls", "extension.translateTailCalls"); customTailCallWorkflow->Remove("core.function.translateTailCalls"); Workflow::RegisterWorkflow(customTailCallWorkflow, - R"#({ + R"#({ "title" : "Tail Call Translation (Example)", "description" : "This analysis stands in as an example to demonstrate Binary Ninja's extensible analysis APIs. ***Note** this feature is under active development and subject to change without notice.", "capabilities" : [] diff --git a/examples/x86_extension/src/x86_extension.cpp b/examples/x86_extension/src/x86_extension.cpp index ada7c801..80043287 100644 --- a/examples/x86_extension/src/x86_extension.cpp +++ b/examples/x86_extension/src/x86_extension.cpp @@ -12,14 +12,13 @@ using namespace asmx86; // This is a wrapper for the x86 architecture. Its useful for extending and improving // the existing core x86 architecture. -class x86ArchitectureExtension: public ArchitectureHook +class x86ArchitectureExtension : public ArchitectureHook { -public: - x86ArchitectureExtension(Architecture* x86) : ArchitectureHook(x86) - { - } + public: + x86ArchitectureExtension(Architecture* x86) : ArchitectureHook(x86) {} - virtual bool GetInstructionLowLevelIL(const uint8_t* data, uint64_t addr, size_t& len, LowLevelILFunction& il) override + virtual bool GetInstructionLowLevelIL( + const uint8_t* data, uint64_t addr, size_t& len, LowLevelILFunction& il) override { Instruction instr; if (asmx86::Disassemble32(data, addr, len, &instr)) @@ -29,7 +28,7 @@ public: case CPUID: // The default implementation of CPUID doesn't set registers to constant values // Here we'll emulate a Intel(R) Core(TM) i5-6267U CPU @ 2.90GHz with _eax set to 1 - il.AddInstruction(il.Register(4, REG_EAX)); // Reference the register so we know it is read + il.AddInstruction(il.Register(4, REG_EAX)); // Reference the register so we know it is read il.AddInstruction(il.SetRegister(4, REG_EAX, il.Const(4, 0x000406e3))); il.AddInstruction(il.SetRegister(4, REG_EBX, il.Const(4, 0x03100800))); il.AddInstruction(il.SetRegister(4, REG_ECX, il.Const(4, 0x7ffafbbf))); |
