From 89eafe1c31488e0824be07e9150162636ad404ab Mon Sep 17 00:00:00 2001 From: Alberto Garcia Illera Date: Tue, 9 May 2023 00:03:01 +1000 Subject: [PATCH] use new error handling on Tritons instruction processing --- src/actions.cpp | 6 +++--- src/snapshot.cpp | 2 +- src/triton_logic.cpp | 29 ++++++++++++++++------------- src/utils.cpp | 6 +++--- src/utils.hpp | 4 ++-- 5 files changed, 25 insertions(+), 22 deletions(-) diff --git a/src/actions.cpp b/src/actions.cpp index 8a9c5bfa..dfdfbee8 100644 --- a/src/actions.cpp +++ b/src/actions.cpp @@ -341,12 +341,12 @@ struct ah_negate_and_inject_t : public action_handler_t for (const auto& pc : tritonCtx.getPathConstraints()) { for (auto const& [taken, srcAddr, dstAddr, pc] : pc.getBranchConstraints()) { if (ctx->cur_ea == srcAddr && !taken) { - char tooltip[256]; + char tooltip[20]; //We need the path constraint index during the action activate qsnprintf(tooltip, 255, "Index: %u", path_constraint_index); update_action_tooltip(ctx->action, tooltip); - char label[100] = { 0 }; + char label[50] = { 0 }; qsnprintf(label, sizeof(label), "Negate and Inject to reach " MEM_FORMAT, dstAddr); update_action_label(ctx->action, label); return AST_ENABLE; @@ -444,7 +444,7 @@ struct ah_create_snapshot_t : public action_handler_t return 0; } - ponce_set_cmt(xip, "Snapshot taken here", false, true); + ponce_set_cmt(xip, "Snapshot taken here", false, true, false); ponce_set_item_color(xip, 0x00FFFF); snapshot.takeSnapshot(); diff --git a/src/snapshot.cpp b/src/snapshot.cpp index d330f1e9..a0c1728a 100644 --- a/src/snapshot.cpp +++ b/src/snapshot.cpp @@ -172,7 +172,7 @@ void Snapshot::resetEngine(void) { this->snapshotTaken = false; //We delete the comment and color that we created - ponce_set_cmt(this->address, "", false); + ponce_set_cmt(this->address, "", false, false, false); del_item_color(this->address); this->address = 0; } diff --git a/src/triton_logic.cpp b/src/triton_logic.cpp index 742f449e..293b5780 100644 --- a/src/triton_logic.cpp +++ b/src/triton_logic.cpp @@ -59,20 +59,23 @@ int tritonize(ea_t pc, thid_t threadID) tritonInst->setAddress(pc); tritonInst->setThreadId(threadID); - try { - if (!tritonCtx.processing(*tritonInst)) { - msg("[!] Instruction at " MEM_FORMAT " not supported by Triton: %s (Thread id: %d)\n", pc, tritonInst->getDisassembly().c_str(), threadID); - return 2; + + switch (tritonCtx.processing(*tritonInst)) + { + case triton::arch::NO_FAULT: + if (cmdOptions.showExtraDebugInfo) { + msg("[+] Triton at " MEM_FORMAT " : %s (Thread id: %d)\n", pc, tritonInst->getDisassembly().c_str(), threadID); } - } - catch (const triton::exceptions::Exception& e) { + break; + case triton::arch::FAULT_UD: msg("[!] Instruction at " MEM_FORMAT " not supported by Triton: %s (Thread id: %d)\n", pc, tritonInst->getDisassembly().c_str(), threadID); return 2; - } - - if (cmdOptions.showExtraDebugInfo) { - msg("[+] Triton at " MEM_FORMAT " : %s (Thread id: %d)\n", pc, tritonInst->getDisassembly().c_str(), threadID); - } + case triton::arch::FAULT_DE: + case triton::arch::FAULT_BP: + case triton::arch::FAULT_GP: + msg("[!] Some error happend at " MEM_FORMAT " processing instruction: %s (Thread id: %d)\n", pc, tritonInst->getDisassembly().c_str(), threadID); + return 2; + } /*In the case that the snapshot engine is in use we should track every memory write access*/ if (snapshot.exists()) { @@ -92,13 +95,13 @@ int tritonize(ea_t pc, thid_t threadID) } } - /* Don't write nothing on symbolic/tainted branch instructions instructions because I'll do it later*/ + /* Don't write anything on symbolic/tainted branch instructions because I'll do it later*/ if (cmdOptions.addCommentsControlledOperands && !tritonInst->isBranch()){ comment_controlled_operands(tritonInst, pc); } if (cmdOptions.addCommentsSymbolicExpresions) - add_symbolic_expressions(tritonInst, pc); + comment_symbolic_expressions(tritonInst, pc); //We only paint the executed instructions if they don't have a previous color if (get_item_color(pc) == DEFCOLOR && cmdOptions.color_executed_instruction != DEFCOLOR) { diff --git a/src/utils.cpp b/src/utils.cpp index 553dbaae..12419fc6 100644 --- a/src/utils.cpp +++ b/src/utils.cpp @@ -241,7 +241,7 @@ void rename_tainted_function(ea_t address) } } -void add_symbolic_expressions(triton::arch::Instruction* tritonInst, ea_t address) +void comment_symbolic_expressions(triton::arch::Instruction* tritonInst, ea_t address) { std::ostringstream oss; for (const auto& expr : tritonInst->symbolicExpressions) { @@ -515,10 +515,10 @@ void ponce_set_item_color(ea_t ea, bgcolor_t color) { } /* Wrapper to keep track of added comments so we can delete them after*/ -bool ponce_set_cmt(ea_t ea, const char* comm, bool rptble, bool snapshot) { +bool ponce_set_cmt(ea_t ea, const char* comm, bool rptble, bool snapshot, bool increment_index) { qstring buf; qstring new_comment; - if (get_cmt(&buf, ea, rptble) != -1) { + if (increment_index && get_cmt(&buf, ea, rptble) != -1) { auto first_space = strchr(buf.c_str(), ' '); // there is a previous comment. Let's try to get the hit count if (first_space){ diff --git a/src/utils.hpp b/src/utils.hpp index 6d8e8e36..64f6ee31 100644 --- a/src/utils.hpp +++ b/src/utils.hpp @@ -22,7 +22,7 @@ ea_t get_args_pointer(int argument_number, bool skip_ret); char read_char_from_ida(ea_t address); ea_t read_regSize_from_ida(ea_t address); void rename_tainted_function(ea_t address); -void add_symbolic_expressions(triton::arch::Instruction* tritonInst, ea_t address); +void comment_symbolic_expressions(triton::arch::Instruction* tritonInst, ea_t address); std::string notification_code_to_string(int notification_code); bool load_options(struct cmdOptionStruct* cmdOptions); bool save_options(struct cmdOptionStruct* cmdOptions); @@ -36,6 +36,6 @@ void concretizeAndUntaintVolatileRegisters(); short read_unicode_char_from_ida(ea_t address); ea_t current_instruction(); void delete_ponce_comments(); -bool ponce_set_cmt(ea_t ea, const char* comm, bool rptble, bool snapshot = false); +bool ponce_set_cmt(ea_t ea, const char* comm, bool rptble, bool snapshot = false, bool increment_index = true); void ponce_set_item_color(ea_t ea, bgcolor_t color); void comment_controlled_operands(triton::arch::Instruction* tritonInst, ea_t pc); \ No newline at end of file