Skip to content

Commit

Permalink
Merge pull request #135 from illera88/fix_134
Browse files Browse the repository at this point in the history
use new error handling on Tritons instruction processing
  • Loading branch information
illera88 authored May 11, 2023
2 parents 5eaef2b + 89eafe1 commit b6a812a
Show file tree
Hide file tree
Showing 5 changed files with 25 additions and 22 deletions.
6 changes: 3 additions & 3 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
Expand Down
2 changes: 1 addition & 1 deletion src/snapshot.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
29 changes: 16 additions & 13 deletions src/triton_logic.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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()) {
Expand All @@ -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) {
Expand Down
6 changes: 3 additions & 3 deletions src/utils.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down Expand Up @@ -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){
Expand Down
4 changes: 2 additions & 2 deletions src/utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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);

0 comments on commit b6a812a

Please sign in to comment.