Skip to content

Commit

Permalink
update to latest Triton version
Browse files Browse the repository at this point in the history
  • Loading branch information
illera88 committed Dec 1, 2022
1 parent 38d5665 commit eab235c
Show file tree
Hide file tree
Showing 18 changed files with 126 additions and 128 deletions.
30 changes: 15 additions & 15 deletions src/actions.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,14 @@
#include "triton_logic.hpp"

//Triton
#include "triton/api.hpp"
#include <triton/context.hpp>
#include "triton/x86Specifications.hpp"

int taint_symbolize_register(const qstring& selected, action_activation_ctx_t* action_activation_ctx) {
auto reg_id_to_symbolize = str_to_register(selected);

if (reg_id_to_symbolize != triton::arch::register_e::ID_REG_INVALID) {
auto register_to_symbolize = api.getRegister(reg_id_to_symbolize);
auto register_to_symbolize = tritonCtx.getRegister(reg_id_to_symbolize);
/*When the user symbolize something for the first time we should enable step_tracing*/
start_tainting_or_symbolic_analysis();

Expand All @@ -50,13 +50,13 @@ int taint_symbolize_register(const qstring& selected, action_activation_ctx_t* a
qsnprintf(comment, 256, "Reg %s at address: " MEM_FORMAT, selected.c_str(), pc);

// Before symbolizing register we should set his concrete value
needConcreteRegisterValue_cb(api, register_to_symbolize);
needConcreteRegisterValue_cb(tritonCtx, register_to_symbolize);

if (cmdOptions.use_tainting_engine) {
api.taintRegister(register_to_symbolize);
tritonCtx.taintRegister(register_to_symbolize);
}
else{ // Symbolize register
api.symbolizeRegister(register_to_symbolize, std::string(comment));
tritonCtx.symbolizeRegister(register_to_symbolize, std::string(comment));
}

tritonize(pc);
Expand All @@ -73,13 +73,13 @@ struct ah_taint_symbolize_register_t : public action_handler_t
{
// Get the address range selected, or return false if there was no selection
qstring selected;
if (ctx->widget_type == BWN_DISASM) {
if (ctx->widget_type == BWN_DISASM) {
uint32 flags;
get_highlight(&selected, get_current_viewer(), &flags);
}
#if IDA_SDK_VERSION >= 740
else if (ctx->widget_type == BWN_CPUREGS) {
selected = ctx->regname;
selected = ctx->regname;
}
#endif

Expand Down Expand Up @@ -205,20 +205,20 @@ struct ah_taint_symbolize_memory_t : public action_handler_t

// Before symbolizing the memory we should set its concrete value
for (unsigned int i = 0; i < selection_length; i++) {
needConcreteMemoryValue_cb(api, triton::arch::MemoryAccess(selection_starts + i, 1));
needConcreteMemoryValue_cb(tritonCtx, triton::arch::MemoryAccess(selection_starts + i, 1));
}

if (cmdOptions.use_tainting_engine) {
for (unsigned int i = 0; i < selection_length; i++) {
auto taintVar = api.taintMemory(triton::arch::MemoryAccess(selection_starts + i, 1));
auto taintVar = tritonCtx.taintMemory(triton::arch::MemoryAccess(selection_starts + i, 1));
if (taintVar) {
ponce_set_cmt(selection_starts + i, "Tainted memory", true);
}
}
}
else{ // Symbolizing all the selected memory
for (unsigned int i = 0; i < selection_length; i++) {
auto symVar = api.symbolizeMemory(triton::arch::MemoryAccess(selection_starts + i, 1));
auto symVar = tritonCtx.symbolizeMemory(triton::arch::MemoryAccess(selection_starts + i, 1));
auto var_name = symVar->getName();
ponce_set_cmt(selection_starts + i, var_name.c_str(), true);
}
Expand Down Expand Up @@ -338,7 +338,7 @@ struct ah_negate_and_inject_t : public action_handler_t
ponce_runtime_status.last_triton_instruction->isSymbolized()) {

unsigned int path_constraint_index = 0;
for (const auto& pc : api.getPathConstraints()) {
for (const auto& pc : tritonCtx.getPathConstraints()) {
for (auto const& [taken, srcAddr, dstAddr, pc] : pc.getBranchConstraints()) {
if (ctx->cur_ea == srcAddr && !taken) {
char tooltip[256];
Expand Down Expand Up @@ -407,7 +407,7 @@ struct ah_negate_inject_and_restore_t : public action_handler_t
ponce_runtime_status.last_triton_instruction->isSymbolized()) {


for (const auto& pc : api.getPathConstraints()) {
for (const auto& pc : tritonCtx.getPathConstraints()) {
for (auto const& [taken, srcAddr, dstAddr, pc] : pc.getBranchConstraints()) {
if (ctx->cur_ea == srcAddr) {
char label[100] = { 0 };
Expand Down Expand Up @@ -637,7 +637,7 @@ struct ah_action_chooser_add_constrain_t : public action_handler_t
}


auto ast = api.getAstContext();
auto ast = tritonCtx.getAstContext();
for (const auto& index : ctx->chooser_selection) {
triton::ast::SharedAbstractNode ge, le;
auto list_item = ponce_table_chooser->table_item_list.at(index);
Expand Down Expand Up @@ -699,9 +699,9 @@ struct ah_action_chooser_comment_t : public action_handler_t
{
qstring response;
if (ask_str(&response, 3, "New comment")) {
for (const auto& index : ctx->chooser_selection) {
for (const auto& index : ctx->chooser_selection) {
auto list_item = ponce_table_chooser->table_item_list.at(index);
api.getSymbolicVariable(list_item.id)->setComment(std::string(response.c_str()));
tritonCtx.getSymbolicVariable(list_item.id)->setComment(std::string(response.c_str()));
msg("[+] Comment %s set to %s\n", response.c_str(), list_item.var_name.c_str());
}
refresh_chooser(ponce_table_chooser->title);
Expand Down
12 changes: 6 additions & 6 deletions src/blacklist.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -122,12 +122,12 @@ void concretizeAndUntaintVolatileRegisters()
char const* volatile_regs[] = { "rax", "rcx", "rdx", "r8", "r8", "r10", "r11", "xmm6", "xmm7", "xmm8", "xmm9", "xmm10", "xmm11", "xmm12", "xmm13", "xmm14", "xmm15" };
#endif

for (const auto& [reg_id, reg] : api.getAllRegisters())
for (const auto& [reg_id, reg] : tritonCtx.getAllRegisters())
{
for (auto i = 0; i < sizeof(volatile_regs) / sizeof(char*); i++) {
if (strcmp(reg.getName().c_str(), volatile_regs[i]) == 0) {
api.concretizeRegister(reg);
api.untaintRegister(reg);
tritonCtx.concretizeRegister(reg);
tritonCtx.untaintRegister(reg);
}
}
}
Expand All @@ -136,12 +136,12 @@ void concretizeAndUntaintVolatileRegisters()
//Helper to concretize and untaint all registers
void concretizeAndUntaintAllRegisters()
{
api.concretizeAllRegister();
tritonCtx.concretizeAllRegister();
//We untaint all the registers
auto regs = api.getAllRegisters();
auto regs = tritonCtx.getAllRegisters();
for (auto it = regs.begin(); it != regs.end(); it++)
{
api.untaintRegister(it->second);
tritonCtx.untaintRegister(it->second);
}
}

Expand Down
14 changes: 7 additions & 7 deletions src/callbacks.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
#include <bytes.hpp>

//Triton
#include "triton/api.hpp"
#include <triton/context.hpp>
#include "triton/x86Specifications.hpp"

ssize_t idaapi tracer_callback(void* user_data, int notification_code, va_list va)
Expand Down Expand Up @@ -313,11 +313,11 @@ ssize_t idaapi ui_callback(void* ud, int notification_code, va_list va)
if (view_type == BWN_DISASM) {
//&& !(is_debugger_on() && !ponce_runtime_status.runtimeTrigger.getState())) { // Don't let solve formulas if user is debugging natively

for (const auto& pc : api.getPathConstraints()) {
for (const auto& pc : tritonCtx.getPathConstraints()) {
auto temp = pc.getBranchConstraints();
}
/* For the selected address(cur_ea), let's count how many branches we can reach (how many non taken addresses are in reach)*/
int non_taken_branches_n = std::count_if(api.getPathConstraints().begin(), api.getPathConstraints().end(), [cur_ea](const auto& pc) {
int non_taken_branches_n = std::count_if(tritonCtx.getPathConstraints().begin(), tritonCtx.getPathConstraints().end(), [cur_ea](const auto& pc) {
for (auto const& [taken, srcAddr, dstAddr, pc] : pc.getBranchConstraints()) {
if (cur_ea == srcAddr && !taken) return true;
}
Expand All @@ -334,7 +334,7 @@ ssize_t idaapi ui_callback(void* ud, int notification_code, va_list va)
// But we need to modify the Solve Formula menu with more info and the path constraint index
// The tooltip is not updated on the update event, we need to unregister the Solve formula submenu and add a new one
unsigned int path_constraint_index = 0;
for (const auto& pc : api.getPathConstraints()) {
for (const auto& pc : tritonCtx.getPathConstraints()) {
for (auto const& [taken, srcAddr, dstAddr, pc] : pc.getBranchConstraints()) {
if (cur_ea == srcAddr && !taken) { // get the non taken branch for the path constraint the user clicked on
// Using the solve formula as template
Expand All @@ -350,7 +350,7 @@ ssize_t idaapi ui_callback(void* ud, int notification_code, va_list va)
// Fix https://github.com/illera88/Ponce/issues/116
if (non_taken_branches_n <= 5) {
unsigned int path_constraint_index = 0;
for (const auto& pc : api.getPathConstraints()) {
for (const auto& pc : tritonCtx.getPathConstraints()) {
for (auto const& [taken, srcAddr, dstAddr, pc] : pc.getBranchConstraints()) {
if (cur_ea == srcAddr && taken) { // get the taken branch for the path constraint the user clicked on
// Using the solve formula as template (If not we modify the name of the main solve formula menu)
Expand All @@ -369,7 +369,7 @@ ssize_t idaapi ui_callback(void* ud, int notification_code, va_list va)
unsigned int path_constraint_index = 0;
unsigned int count = 0;
// Show the first two
for (const auto& pc : api.getPathConstraints()) {
for (const auto& pc : tritonCtx.getPathConstraints()) {
for (auto const& [taken, srcAddr, dstAddr, pc] : pc.getBranchConstraints()) {
if (cur_ea == srcAddr && taken) { // get the taken branch for the path constraint the user clicked on
if (count == 2) // Only adding the first two
Expand All @@ -394,7 +394,7 @@ ssize_t idaapi ui_callback(void* ud, int notification_code, va_list va)
};
struct pair_address_index holder[2] = {0};
// Show the last two
for (auto rit = std::rbegin(api.getPathConstraints()); rit != std::rend(api.getPathConstraints()); ++rit) {
for (auto rit = std::rbegin(tritonCtx.getPathConstraints()); rit != std::rend(tritonCtx.getPathConstraints()); ++rit) {
for (auto const& [taken, srcAddr, dstAddr, pc] : rit->getBranchConstraints()) {
if (cur_ea == srcAddr && taken) { // get the taken branch for the path constraint the user clicked on
if (count == 2) // Only adding the first two
Expand Down
28 changes: 14 additions & 14 deletions src/context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <triton/cpuSize.hpp>
#include <triton/coreUtils.hpp>
#include <triton/x86Specifications.hpp>
#include <triton/api.hpp>
#include <triton/context.hpp>

#include "context.hpp"
#include "globals.hpp"
Expand Down Expand Up @@ -56,21 +56,21 @@ triton::uint512 IDA_getCurrentMemoryValue(ea_t addr, triton::uint32 size)
}

/*This callback is called when triton is processing a instruction and it needs a memory value to build the expressions*/
void needConcreteMemoryValue_cb(triton::API& api, const triton::arch::MemoryAccess& mem)
void needConcreteMemoryValue_cb(triton::Context& tritonCtx, const triton::arch::MemoryAccess& mem)
{
bool had_it = false;
auto IDA_memValue = IDA_getCurrentMemoryValue((ea_t)mem.getAddress(), mem.getSize());

if (api.isConcreteMemoryValueDefined(mem)) {
auto triton_memValue = api.getConcreteMemoryValue(mem, false);
if (tritonCtx.isConcreteMemoryValueDefined(mem)) {
auto triton_memValue = tritonCtx.getConcreteMemoryValue(mem, false);
if ((IDA_memValue != triton_memValue)) {
api.setConcreteMemoryValue(mem, IDA_memValue);
tritonCtx.setConcreteMemoryValue(mem, IDA_memValue);
had_it = false;
}
had_it = true;
}
else {
api.setConcreteMemoryValue(mem, IDA_memValue);
tritonCtx.setConcreteMemoryValue(mem, IDA_memValue);
}

if (cmdOptions.showExtraDebugInfo) {
Expand Down Expand Up @@ -101,25 +101,25 @@ triton::uint512 IDA_getCurrentRegisterValue(const triton::arch::Register& reg)
value = reg_value.ival;
/* Sync with the libTriton */
triton::arch::Register syncReg;
if (reg.getId() >= api.registers.x86_af.getId() && reg.getId() <= api.registers.x86_zf.getId())
syncReg = api.registers.x86_eflags;
else if (reg.getId() >= api.registers.x86_sse_ie.getId() && reg.getId() <= api.registers.x86_sse_fz.getId())
syncReg = api.registers.x86_mxcsr;
if (reg.getId() >= tritonCtx.registers.x86_af.getId() && reg.getId() <= tritonCtx.registers.x86_zf.getId())
syncReg = tritonCtx.registers.x86_eflags;
else if (reg.getId() >= tritonCtx.registers.x86_sse_ie.getId() && reg.getId() <= tritonCtx.registers.x86_sse_fz.getId())
syncReg = tritonCtx.registers.x86_mxcsr;
else
syncReg = api.getRegister(reg.getParent());
syncReg = tritonCtx.getRegister(reg.getParent());

return value;
}

/*This callback is called when triton is processing a instruction and it needs a regiter to build the expressions*/
void needConcreteRegisterValue_cb(triton::API& api, const triton::arch::Register& reg)
void needConcreteRegisterValue_cb(triton::Context& tritonCtx, const triton::arch::Register& reg)
{
bool had_it = true;
auto IDA_regValue = IDA_getCurrentRegisterValue(reg);
auto triton_regValue = api.getConcreteRegisterValue(reg, false);
auto triton_regValue = tritonCtx.getConcreteRegisterValue(reg, false);

if (IDA_regValue != triton_regValue) {
api.setConcreteRegisterValue(reg, IDA_regValue);
tritonCtx.setConcreteRegisterValue(reg, IDA_regValue);
had_it = false;
}

Expand Down
6 changes: 3 additions & 3 deletions src/context.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,11 @@

#pragma once
//Triton
#include <triton/api.hpp>
#include <triton/context.hpp>
//IDA
#include <pro.h>

void needConcreteMemoryValue_cb(triton::API& api, const triton::arch::MemoryAccess& mem);
void needConcreteRegisterValue_cb(triton::API& api, const triton::arch::Register& reg);
void needConcreteMemoryValue_cb(triton::Context& tritonCtx, const triton::arch::MemoryAccess& mem);
void needConcreteRegisterValue_cb(triton::Context& tritonCtx, const triton::arch::Register& reg);
triton::uint512 IDA_getCurrentMemoryValue(ea_t addr, triton::uint32 size);
triton::uint512 IDA_getCurrentRegisterValue(const triton::arch::Register& reg);
2 changes: 0 additions & 2 deletions src/formTaintSymbolizeInput.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,6 @@
*/

#pragma once
//Triton
#include <triton/api.hpp>

//IDA
#include <ida.hpp>
Expand Down
4 changes: 2 additions & 2 deletions src/globals.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
#include "globals.hpp"
#include "trigger.hpp"
//Triton
#include <triton/api.hpp>
#include <triton/context.hpp>

#include <ida.hpp>
//A variable to store if the plugin has hooked the ui and debugger events
Expand All @@ -33,7 +33,7 @@ Snapshot snapshot = Snapshot();
//Used to point to the vector of blacklisted user functions
std::vector<std::string>* blacklkistedUserFunctions = nullptr;

triton::API api;
triton::Context tritonCtx;

std::map<ea_t, struct instruction_info> ponce_comments;

Expand Down
6 changes: 3 additions & 3 deletions src/globals.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
#include <kernwin.hpp>

//Triton
#include <triton/api.hpp>
#include <triton/context.hpp>

#define strtol_m strtoll

Expand Down Expand Up @@ -85,7 +85,7 @@ extern std::vector<std::string>* blacklkistedUserFunctions;

extern void idaapi term(void);

extern triton::API api;
extern triton::Context tritonCtx;

struct instruction_info {
std::string comment;
Expand All @@ -104,7 +104,7 @@ extern std::map<ea_t, struct instruction_info> ponce_comments;

#ifdef __EA64__
#define MEM_FORMAT "%#" PRIx64
#define REG_XIP api.registers.x86_rip
#define REG_XIP tritonCtx.registers.x86_rip
#else
#define MEM_FORMAT "%#" PRIx32
#define REG_XIP api.registers.x86_eip
Expand Down
4 changes: 2 additions & 2 deletions src/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
#include <kernwin.hpp>

//Triton
#include <triton/api.hpp>
#include <triton/context.hpp>

//Ponce
#include "callbacks.hpp"
Expand Down Expand Up @@ -64,7 +64,7 @@ bool idaapi run(size_t)
register_action(action_IDA_clean);
attach_action_to_menu("Edit/Ponce/", action_IDA_clean.name, SETMENU_APP);

//Some actions needs to use the api and the api need to have the architecture set
//Some actions needs to use the tritonCtx and the tritonCtx need to have the architecture set
if (!ponce_set_triton_architecture()) {
return false;
}
Expand Down
2 changes: 1 addition & 1 deletion src/runtime_status.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
//Ponce
#include "trigger.hpp"
//Triton
#include <triton/api.hpp>
#include <triton/context.hpp>
//IDA
#include <pro.h>
#include <idd.hpp>
Expand Down
Loading

0 comments on commit eab235c

Please sign in to comment.