Skip to content

Commit b6a812a

Browse files
authored
Merge pull request #135 from illera88/fix_134
use new error handling on Tritons instruction processing
2 parents 5eaef2b + 89eafe1 commit b6a812a

File tree

5 files changed

+25
-22
lines changed

5 files changed

+25
-22
lines changed

src/actions.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -341,12 +341,12 @@ struct ah_negate_and_inject_t : public action_handler_t
341341
for (const auto& pc : tritonCtx.getPathConstraints()) {
342342
for (auto const& [taken, srcAddr, dstAddr, pc] : pc.getBranchConstraints()) {
343343
if (ctx->cur_ea == srcAddr && !taken) {
344-
char tooltip[256];
344+
char tooltip[20];
345345
//We need the path constraint index during the action activate
346346
qsnprintf(tooltip, 255, "Index: %u", path_constraint_index);
347347
update_action_tooltip(ctx->action, tooltip);
348348

349-
char label[100] = { 0 };
349+
char label[50] = { 0 };
350350
qsnprintf(label, sizeof(label), "Negate and Inject to reach " MEM_FORMAT, dstAddr);
351351
update_action_label(ctx->action, label);
352352
return AST_ENABLE;
@@ -444,7 +444,7 @@ struct ah_create_snapshot_t : public action_handler_t
444444
return 0;
445445
}
446446

447-
ponce_set_cmt(xip, "Snapshot taken here", false, true);
447+
ponce_set_cmt(xip, "Snapshot taken here", false, true, false);
448448
ponce_set_item_color(xip, 0x00FFFF);
449449

450450
snapshot.takeSnapshot();

src/snapshot.cpp

+1-1
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ void Snapshot::resetEngine(void) {
172172
this->snapshotTaken = false;
173173

174174
//We delete the comment and color that we created
175-
ponce_set_cmt(this->address, "", false);
175+
ponce_set_cmt(this->address, "", false, false, false);
176176
del_item_color(this->address);
177177
this->address = 0;
178178
}

src/triton_logic.cpp

+16-13
Original file line numberDiff line numberDiff line change
@@ -59,20 +59,23 @@ int tritonize(ea_t pc, thid_t threadID)
5959
tritonInst->setAddress(pc);
6060
tritonInst->setThreadId(threadID);
6161

62-
try {
63-
if (!tritonCtx.processing(*tritonInst)) {
64-
msg("[!] Instruction at " MEM_FORMAT " not supported by Triton: %s (Thread id: %d)\n", pc, tritonInst->getDisassembly().c_str(), threadID);
65-
return 2;
62+
63+
switch (tritonCtx.processing(*tritonInst))
64+
{
65+
case triton::arch::NO_FAULT:
66+
if (cmdOptions.showExtraDebugInfo) {
67+
msg("[+] Triton at " MEM_FORMAT " : %s (Thread id: %d)\n", pc, tritonInst->getDisassembly().c_str(), threadID);
6668
}
67-
}
68-
catch (const triton::exceptions::Exception& e) {
69+
break;
70+
case triton::arch::FAULT_UD:
6971
msg("[!] Instruction at " MEM_FORMAT " not supported by Triton: %s (Thread id: %d)\n", pc, tritonInst->getDisassembly().c_str(), threadID);
7072
return 2;
71-
}
72-
73-
if (cmdOptions.showExtraDebugInfo) {
74-
msg("[+] Triton at " MEM_FORMAT " : %s (Thread id: %d)\n", pc, tritonInst->getDisassembly().c_str(), threadID);
75-
}
73+
case triton::arch::FAULT_DE:
74+
case triton::arch::FAULT_BP:
75+
case triton::arch::FAULT_GP:
76+
msg("[!] Some error happend at " MEM_FORMAT " processing instruction: %s (Thread id: %d)\n", pc, tritonInst->getDisassembly().c_str(), threadID);
77+
return 2;
78+
}
7679

7780
/*In the case that the snapshot engine is in use we should track every memory write access*/
7881
if (snapshot.exists()) {
@@ -92,13 +95,13 @@ int tritonize(ea_t pc, thid_t threadID)
9295
}
9396
}
9497

95-
/* Don't write nothing on symbolic/tainted branch instructions instructions because I'll do it later*/
98+
/* Don't write anything on symbolic/tainted branch instructions because I'll do it later*/
9699
if (cmdOptions.addCommentsControlledOperands && !tritonInst->isBranch()){
97100
comment_controlled_operands(tritonInst, pc);
98101
}
99102

100103
if (cmdOptions.addCommentsSymbolicExpresions)
101-
add_symbolic_expressions(tritonInst, pc);
104+
comment_symbolic_expressions(tritonInst, pc);
102105

103106
//We only paint the executed instructions if they don't have a previous color
104107
if (get_item_color(pc) == DEFCOLOR && cmdOptions.color_executed_instruction != DEFCOLOR) {

src/utils.cpp

+3-3
Original file line numberDiff line numberDiff line change
@@ -241,7 +241,7 @@ void rename_tainted_function(ea_t address)
241241
}
242242
}
243243

244-
void add_symbolic_expressions(triton::arch::Instruction* tritonInst, ea_t address)
244+
void comment_symbolic_expressions(triton::arch::Instruction* tritonInst, ea_t address)
245245
{
246246
std::ostringstream oss;
247247
for (const auto& expr : tritonInst->symbolicExpressions) {
@@ -515,10 +515,10 @@ void ponce_set_item_color(ea_t ea, bgcolor_t color) {
515515
}
516516

517517
/* Wrapper to keep track of added comments so we can delete them after*/
518-
bool ponce_set_cmt(ea_t ea, const char* comm, bool rptble, bool snapshot) {
518+
bool ponce_set_cmt(ea_t ea, const char* comm, bool rptble, bool snapshot, bool increment_index) {
519519
qstring buf;
520520
qstring new_comment;
521-
if (get_cmt(&buf, ea, rptble) != -1) {
521+
if (increment_index && get_cmt(&buf, ea, rptble) != -1) {
522522
auto first_space = strchr(buf.c_str(), ' ');
523523
// there is a previous comment. Let's try to get the hit count
524524
if (first_space){

src/utils.hpp

+2-2
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ ea_t get_args_pointer(int argument_number, bool skip_ret);
2222
char read_char_from_ida(ea_t address);
2323
ea_t read_regSize_from_ida(ea_t address);
2424
void rename_tainted_function(ea_t address);
25-
void add_symbolic_expressions(triton::arch::Instruction* tritonInst, ea_t address);
25+
void comment_symbolic_expressions(triton::arch::Instruction* tritonInst, ea_t address);
2626
std::string notification_code_to_string(int notification_code);
2727
bool load_options(struct cmdOptionStruct* cmdOptions);
2828
bool save_options(struct cmdOptionStruct* cmdOptions);
@@ -36,6 +36,6 @@ void concretizeAndUntaintVolatileRegisters();
3636
short read_unicode_char_from_ida(ea_t address);
3737
ea_t current_instruction();
3838
void delete_ponce_comments();
39-
bool ponce_set_cmt(ea_t ea, const char* comm, bool rptble, bool snapshot = false);
39+
bool ponce_set_cmt(ea_t ea, const char* comm, bool rptble, bool snapshot = false, bool increment_index = true);
4040
void ponce_set_item_color(ea_t ea, bgcolor_t color);
4141
void comment_controlled_operands(triton::arch::Instruction* tritonInst, ea_t pc);

0 commit comments

Comments
 (0)