Fix RZ_IPI usage on public headers & fix memory leak in the ROP code. (#6171)

* Fix RZ_IPI declaration on public api for rz_pdb

* Fix RZ_IPI declaration on public api for jemalloc/glibc

* Fix RZ_IPI declaration on public api for rz_io

* Remove functions from public header for rz_panels

* Fix public functions not following rizin nomenclature in rz_graph

* Fix public functions not following rizin nomenclature in rz_rop

* move resolve_fcn_name into rz_analysis

* Fix public functions not following rizin nomenclature in rz_ascii_table

* Fix leak in rop code

* Rewrite parser for rop

* Add doxygen comment
This commit is contained in:
Giovanni 2026-04-08 13:37:17 +08:00 committed by GitHub
parent 9be4c77581
commit 6131a0e187
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
32 changed files with 318 additions and 436 deletions

View file

@ -578,3 +578,30 @@ RZ_API RZ_OWN char *rz_analysis_function_name_guess(RzTypeDB *typedb, RZ_NONNULL
free(str);
return result;
}
/**
* \brief tries to resolve & guess the function name
*
* \param analysis The RzAnalysis to use
* \param[in] func_name The function name to resolve
*
* \return On success returns a valid pointer, otherwise NULL.
*/
RZ_API RZ_OWN char *rz_analysis_function_name_resolve(RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL const char *func_name) {
rz_return_val_if_fail(analysis && RZ_STR_ISNOTEMPTY(func_name), NULL);
const char *str = func_name;
const char *name = func_name;
RzTypeDB *typedb = rz_analysis_get_type_db(analysis);
if (rz_type_func_exist(typedb, func_name)) {
return rz_str_dup(func_name);
}
while ((str = strchr(str, '.'))) {
name = str + 1;
str++;
}
if (rz_type_func_exist(typedb, name)) {
return rz_str_dup(name);
}
return rz_analysis_function_name_guess(typedb, (char *)func_name);
}

View file

@ -9,7 +9,8 @@
#include <rz_pdb.h>
RZ_IPI bool PDBSectionOffset_parse(RzBuffer *b, PDBSectionOffset *section_offset);
RZ_IPI bool PDBSPublic_parse(RzBuffer *b, PDBSymbolKind kind, PDBSPublic *s);
RZ_IPI bool PDBSData_parse(RzBuffer *b, PDBSymbolKind kind, PDBSData *sdata);
RZ_IPI bool PDBSymbol_parse(RzBuffer *b, PDBSymbol *symbol);
typedef struct {

View file

@ -5869,7 +5869,7 @@ RZ_IPI int rz_core_visual_graph(RzCore *core, RzAGraph *g, RzAnalysisFunction *_
* \return true In case of success.
* \return false In case of failure.
*/
RZ_API bool create_agraph_from_graph_at(RZ_NONNULL RzAGraph *ag, RZ_NONNULL const RzGraph /*<RzGraphNodeInfo *, None *>*/ *g, bool free_on_fail, bool utf8) {
RZ_API bool rz_core_create_agraph_from_graph_at(RZ_NONNULL RzAGraph *ag, RZ_NONNULL const RzGraph /*<RzGraphNodeInfo *, None *>*/ *g, bool free_on_fail, bool utf8) {
rz_return_val_if_fail(ag && g, false);
ag->need_reload_nodes = false;
// Cache lookup to build edges
@ -5982,14 +5982,14 @@ failure:
*
* \return RzAGraph* The agraph or NULL in case of failure
*/
RZ_API RZ_OWN RzAGraph *create_agraph_from_graph(RZ_NONNULL const RzGraph /*<RzGraphNodeInfo *, None *>*/ *graph, bool utf8) {
RZ_API RZ_OWN RzAGraph *rz_core_create_agraph_from_graph(RZ_NONNULL const RzGraph /*<RzGraphNodeInfo *, None *>*/ *graph, bool utf8) {
rz_return_val_if_fail(graph, NULL);
RzAGraph *result_agraph = rz_agraph_new(rz_cons_canvas_new(1, 1));
if (!result_agraph) {
return NULL;
}
if (!create_agraph_from_graph_at(result_agraph, graph, true, utf8)) {
if (!rz_core_create_agraph_from_graph_at(result_agraph, graph, true, utf8)) {
return NULL;
}
return result_agraph;

View file

@ -271,7 +271,7 @@ RZ_IPI bool rz_core_agraph_apply(RzCore *core, RzGraph /*<RzGraphNodeInfo *, NUL
if (!(core && core->graph && graph)) {
return false;
}
if (!create_agraph_from_graph_at(core->graph, graph, false, rz_config_get_b(core->config, "scr.utf8"))) {
if (!rz_core_create_agraph_from_graph_at(core->graph, graph, false, rz_config_get_b(core->config, "scr.utf8"))) {
return false;
}
if (rz_core_agraph_is_shortcuts(core, core->graph)) {

View file

@ -3445,7 +3445,7 @@ RZ_IPI char *rz_core_analysis_function_signature(RzCore *core, RzOutputMode mode
char *key = NULL;
if (fcn_name) {
key = resolve_fcn_name(core->analysis, fcn_name);
key = rz_analysis_function_name_resolve(core->analysis, fcn_name);
}
if (key) {

View file

@ -84,23 +84,6 @@ static void set_fcn_args_info(RzAnalysisFuncArg *arg, RzAnalysis *analysis, cons
arg->cc_source = rz_analysis_cc_arg(analysis, cc, arg_num);
}
RZ_API char *resolve_fcn_name(RzAnalysis *analysis, const char *func_name) {
const char *str = func_name;
const char *name = func_name;
RzTypeDB *typedb = rz_analysis_get_type_db(analysis);
if (rz_type_func_exist(typedb, func_name)) {
return rz_str_dup(func_name);
}
while ((str = strchr(str, '.'))) {
name = str + 1;
str++;
}
if (rz_type_func_exist(typedb, name)) {
return rz_str_dup(name);
}
return rz_analysis_function_name_guess(typedb, (char *)func_name);
}
static ut64 get_buf_val(ut8 *buf, int endian, int width) {
return (width == 8) ? rz_read_ble64(buf, endian) : (ut64)rz_read_ble32(buf, endian);
}
@ -283,7 +266,7 @@ RZ_API RZ_OWN RzList /*<RzAnalysisFuncArg *>*/ *rz_core_get_func_args(RzCore *co
}
RzTypeDB *typedb = rz_analysis_get_type_db(core->analysis);
RzReg *rreg = rz_analysis_get_reg(core->analysis);
char *key = resolve_fcn_name(core->analysis, fcn_name);
char *key = rz_analysis_function_name_resolve(core->analysis, fcn_name);
if (!key) {
return NULL;
}

View file

@ -28,9 +28,6 @@
#include <tree_sitter/api.h>
TSLanguage *tree_sitter_rzcmd();
RZ_IPI void rz_save_panels_layout(RzCore *core, const char *_name);
RZ_IPI bool rz_load_panels_layout(RzCore *core, const char *_name);
#include "cmd_debug.c"
#include "cmd_analysis.c"
#include "cmd_magic.c"

View file

@ -9,6 +9,9 @@
#include "../core_private.h"
RZ_IPI void rz_save_panels_layout(RzCore *core, const char *_name);
RZ_IPI bool rz_load_panels_layout(RzCore *core, const char *_name);
RZ_IPI RzCmdStatus rz_interactive_panel_handler(RzCore *core, int argc, const char **argv) {
if (core->vmode) {
RZ_LOG_ERROR("core->vmode == false.\n");

View file

@ -56,7 +56,7 @@ RZ_IPI RzCmdStatus rz_cmd_info_gadget_handler(RzCore *core, int argc, const char
}
RZ_IPI RzCmdStatus rz_cmd_query_gadget_handler(RzCore *core, int argc, const char **argv, RzCmdStateOutput *state) {
RzPVector /*<RzRopConstraint *>*/ *constraints = rop_constraint_map_parse(core, argc, argv);
RzPVector /*<RzRopConstraint *>*/ *constraints = rz_core_rop_constraint_map_parse(core, argc, argv);
if (!constraints) {
return RZ_CMD_STATUS_ERROR;
}

View file

@ -48,7 +48,7 @@ static bool parse_il_equal(const char *str, ut64 *idx) {
return false;
}
static char *parse_register(const RzCore *core, const char *str, ut64 *idx) {
static const RzRegItem *parse_register(const RzCore *core, const char *str, ut64 *idx) {
char reg[256] = { 0 };
ut64 reg_idx = 0;
@ -65,11 +65,7 @@ static char *parse_register(const RzCore *core, const char *str, ut64 *idx) {
// Check if the register is correct for the given architecture.
RzReg *areg = rz_analysis_get_reg(core->analysis);
if (rz_reg_get(areg, reg, RZ_REG_TYPE_ANY)) {
return rz_str_dup(reg);
}
return NULL;
return rz_reg_get(areg, reg, RZ_REG_TYPE_ANY);
}
static bool parse_constant(const char *str, RZ_NONNULL ut64 *idx, unsigned long long *value) {
@ -111,9 +107,7 @@ static bool parse_constant(const char *str, RZ_NONNULL ut64 *idx, unsigned long
return true;
}
static bool parse_il_op(RzList /*<RzILOpPureCode *>*/ *args, const char *str, ut64 *idx, bool *is_compound_op) {
RzILOpPureCode res = RZ_IL_OP_VAR;
static bool parse_il_op(const char *str, ut64 *idx, bool *is_compound_op, RzILOpPureCode *op) {
skip_whitespace(str, idx);
if (*idx >= strlen(str)) {
return false;
@ -126,313 +120,282 @@ static bool parse_il_op(RzList /*<RzILOpPureCode *>*/ *args, const char *str, ut
(*idx)++;
*is_compound_op = true;
}
res = RZ_IL_OP_ADD;
break;
*op = RZ_IL_OP_ADD;
return true;
case '/':
(*idx)++;
if (is_compound_operator(str[*idx - 1], str[*idx]) && is_compound_op) {
(*idx)++;
*is_compound_op = true;
}
res = RZ_IL_OP_DIV;
break;
*op = RZ_IL_OP_DIV;
return true;
case '*':
(*idx)++;
if (is_compound_operator(str[*idx - 1], str[*idx]) && is_compound_op) {
(*idx)++;
*is_compound_op = true;
}
res = RZ_IL_OP_MUL;
break;
*op = RZ_IL_OP_MUL;
return true;
case '^':
(*idx)++;
if (is_compound_operator(str[*idx - 1], str[*idx]) && is_compound_op) {
(*idx)++;
*is_compound_op = true;
}
res = RZ_IL_OP_XOR;
break;
*op = RZ_IL_OP_XOR;
return true;
case '&':
(*idx)++;
if (is_compound_operator(str[*idx - 1], str[*idx]) && is_compound_op) {
(*idx)++;
*is_compound_op = true;
}
res = RZ_IL_OP_AND;
break;
*op = RZ_IL_OP_AND;
return true;
case '|':
(*idx)++;
if (is_compound_operator(str[*idx - 1], str[*idx]) && is_compound_op) {
(*idx)++;
*is_compound_op = true;
}
res = RZ_IL_OP_OR;
break;
*op = RZ_IL_OP_OR;
return true;
case '%':
(*idx)++;
if (is_compound_operator(str[*idx - 1], str[*idx]) && is_compound_op) {
(*idx)++;
*is_compound_op = true;
}
res = RZ_IL_OP_MOD;
break;
*op = RZ_IL_OP_MOD;
return true;
case '-':
(*idx)++;
if (is_compound_operator(str[*idx - 1], str[*idx]) && is_compound_op) {
(*idx)++;
*is_compound_op = true;
}
res = RZ_IL_OP_SUB;
break;
*op = RZ_IL_OP_SUB;
return true;
default: break;
}
if (res == RZ_IL_OP_VAR) {
if (strncmp(&str[*idx], "<<", 2) == 0) {
*idx += 2;
res = RZ_IL_OP_SHIFTL;
} else if (strncmp(&str[*idx], ">>", 2) == 0) {
*idx += 2;
res = RZ_IL_OP_SHIFTR;
} else {
return false;
}
if (strncmp(&str[*idx], "<<", 2) == 0) {
*idx += 2;
*op = RZ_IL_OP_SHIFTL;
return true;
} else if (strncmp(&str[*idx], ">>", 2) == 0) {
*idx += 2;
*op = RZ_IL_OP_SHIFTR;
return true;
}
RzILOpPureCode *op_ptr = RZ_NEW0(RzILOpPureCode);
if (!op_ptr) {
return false;
}
static bool rop_constraint_set_regs(RzRopConstraint *rc,
RzRopILInstructionType il_type,
RZ_NONNULL const RzRegItem *dst,
RZ_NONNULL const RzRegItem *src0,
RZ_NULLABLE const RzRegItem *src1) {
if (!dst || !src0) {
return false;
}
*op_ptr = res;
rz_list_append(args, op_ptr);
rc->type = il_type;
rc->args[DST_REG] = rz_str_dup(dst->name);
rc->args[SRC_REG] = rz_str_dup(src0->name);
if (src1) {
rc->args[SRC_REG_SECOND] = rz_str_dup(src1->name);
}
return true;
}
static bool parse_compound_op(const RzCore *core, const char *str, RzRopConstraint *rop_constraint) {
static bool rop_constraint_set_op(RzRopConstraint *rc, RzILOpPureCode op) {
if (op >= RZ_IL_OP_PURE_MAX) {
return false;
}
const char *op_str = rz_il_op_pure_code_stringify(op);
if (!op_str) {
return false;
}
rc->args[OP] = rz_str_dup(op_str);
return true;
}
static bool rop_constraint_set_const(RzRopConstraint *rc,
RzRopILInstructionType il_type,
RZ_NONNULL const RzRegItem *dst,
RZ_NULLABLE const RzRegItem *src0,
ut64 const_value) {
if (!dst) {
return false;
}
rc->type = il_type;
rc->args[DST_REG] = rz_str_dup(dst->name);
if (src0) {
rc->args[SRC_REG] = rz_str_dup(src0->name);
}
rc->args[SRC_CONST] = rz_str_newf("%" PFMT64u, const_value);
return true;
}
static bool parse_compound_op(const RzCore *core, const char *str, RzRopConstraint *rc) {
ut64 idx = 0;
char *src_reg = parse_register(core, str, &idx);
if (!src_reg) {
ut64 const_value = 0;
bool inc_dec = false;
bool is_compound_op = false;
bool constant_status = false;
RzILOpPureCode op = RZ_IL_OP_PURE_MAX;
const RzRegItem *src_reg = NULL;
const RzRegItem *dst_reg = parse_register(core, str, &idx);
if (!dst_reg) {
return false;
}
skip_whitespace(str, &idx);
RzList *args = rz_list_new();
bool is_compound_op = false;
if (!parse_il_op(args, str, &idx, &is_compound_op)) {
free(src_reg);
rz_list_free(args);
if (!parse_il_op(str, &idx, &is_compound_op, &op)) {
return false;
}
bool inc_dec = false;
// idx - 2 and idx - 1 as we would have skipped it during parse_il_op
if ((str[idx - 2] == '+' && str[idx - 1] == '+') || (str[idx - 2] == '-' && str[idx - 1] == '-')) {
inc_dec = true;
}
// Now parse the constant after the operator
ut64 const_value;
bool constant_status = false;
char *dst_reg1 = NULL;
if (!inc_dec) {
constant_status = parse_constant(str, &idx, &const_value);
dst_reg1 = parse_register(core, str, &idx);
}
if (!constant_status && !dst_reg1 && !is_compound_op) {
free(src_reg);
rz_list_free(args);
return false;
src_reg = parse_register(core, str, &idx);
}
if (!parse_eof(str, idx)) {
free(src_reg);
rz_list_free(args);
if (!constant_status && !src_reg && !is_compound_op) {
return false;
} else if (!parse_eof(str, idx)) {
return false;
}
if (constant_status && is_compound_op) {
rop_constraint->type = MOV_OP_CONST;
rop_constraint->args[DST_REG] = src_reg;
rop_constraint->args[SRC_REG] = strdup(src_reg);
RzILOpPureCode *op = rz_list_get_n(args, 0);
if (!op) {
free(src_reg);
rz_list_free(args);
return false;
}
char op_str[16];
rz_strf(op_str, "%" PFMT64u, const_value);
rop_constraint->args[SRC_CONST] = rz_str_dup(op_str);
const char *value_str = rz_il_op_pure_code_stringify(*op);
rop_constraint->args[OP] = rz_str_dup(value_str);
rz_list_free(args);
return true;
// dst = dst (math op) num
return rop_constraint_set_const(rc, MOV_OP_CONST, dst_reg, dst_reg, const_value) &&
rop_constraint_set_op(rc, op);
}
if (dst_reg1 && is_compound_op) {
rop_constraint->type = MOV_OP_REG;
rop_constraint->args[DST_REG] = src_reg;
rop_constraint->args[SRC_REG] = strdup(src_reg);
RzILOpPureCode *op = rz_list_get_n(args, 0);
if (!op) {
free(src_reg);
free(dst_reg1);
rz_list_free(args);
return false;
}
const char *op_str = rz_il_op_pure_code_stringify(*op);
rop_constraint->args[OP] = rz_str_dup(op_str);
rop_constraint->args[SRC_REG_SECOND] = strdup(dst_reg1);
rz_list_free(args);
return true;
if (src_reg && is_compound_op) {
// dst = dst (math op) src
return rop_constraint_set_regs(rc, MOV_OP_REG, dst_reg, dst_reg, src_reg) &&
rop_constraint_set_op(rc, op);
}
if (!inc_dec) {
rz_list_free(args);
return false;
}
const_value = 1;
rop_constraint->type = MOV_OP_CONST;
rop_constraint->args[DST_REG] = src_reg;
rop_constraint->args[SRC_REG] = strdup(src_reg);
RzILOpPureCode *op = rz_list_get_n(args, 0);
if (!op) {
free(src_reg);
rz_list_free(args);
// dst (math op)= 1
return rop_constraint_set_const(rc, MOV_OP_CONST, dst_reg, dst_reg, const_value) &&
rop_constraint_set_op(rc, op);
}
static bool parse_reg_to_const(const RzCore *core, const char *str, RzRopConstraint *rc) {
ut64 idx = 0;
ut64 const_value = 0;
const RzRegItem *dst_reg = parse_register(core, str, &idx);
if (!dst_reg) {
return false;
}
char op_str[16];
rz_strf(op_str, "%" PFMT64u, const_value);
rop_constraint->args[SRC_CONST] = rz_str_dup(op_str);
const char *value_str = rz_il_op_pure_code_stringify(*op);
rop_constraint->args[OP] = rz_str_dup(value_str);
rz_list_free(args);
return true;
if (!parse_il_equal(str, &idx) || !parse_constant(str, &idx, &const_value) || !parse_eof(str, idx)) {
return false;
}
return rop_constraint_set_const(rc, MOV_CONST, dst_reg, NULL, const_value);
}
static bool parse_reg_to_const(const RzCore *core, const char *str, RzRopConstraint *rop_constraint) {
static bool parse_reg_to_reg(const RzCore *core, const char *str, RzRopConstraint *rc) {
ut64 idx = 0;
char *dst_reg = parse_register(core, str, &idx);
const RzRegItem *src_reg = NULL;
const RzRegItem *dst_reg = parse_register(core, str, &idx);
if (!dst_reg) {
return false;
}
if (!parse_il_equal(str, &idx)) {
free(dst_reg);
return false;
}
ut64 const_value;
if (!parse_constant(str, &idx, &const_value)) {
free(dst_reg);
return false;
}
if (!parse_eof(str, idx)) {
free(dst_reg);
return false;
}
rop_constraint->type = MOV_CONST;
rop_constraint->args[DST_REG] = dst_reg;
rop_constraint->args[SRC_REG] = NULL;
rop_constraint->args[SRC_CONST] = rz_str_newf("%" PFMT64u, const_value);
return true;
}
static bool parse_reg_to_reg(const RzCore *core, const char *str, RzRopConstraint *rop_constraint) {
ut64 idx = 0;
char *dst_reg = parse_register(core, str, &idx);
if (!dst_reg) {
return false;
}
if (!parse_il_equal(str, &idx)) {
free(dst_reg);
return false;
}
char *src_reg = parse_register(core, str, &idx);
src_reg = parse_register(core, str, &idx);
if (!src_reg) {
free(dst_reg);
return false;
}
if (!parse_eof(str, idx)) {
free(dst_reg);
return false;
}
rop_constraint->type = MOV_REG;
rop_constraint->args[DST_REG] = dst_reg;
rop_constraint->args[SRC_REG] = src_reg;
return true;
return rop_constraint_set_regs(rc, MOV_REG, dst_reg, src_reg, NULL);
}
static bool parse_reg_op_const(const RzCore *core, const char *str, RzRopConstraint *rop_constraint) {
static bool parse_reg_op_const(const RzCore *core, const char *str, RzRopConstraint *rc) {
ut64 idx = 0;
char *dst_reg = parse_register(core, str, &idx);
if (!dst_reg) {
ut64 const_value = 0;
RzILOpPureCode op = RZ_IL_OP_PURE_MAX;
const RzRegItem *src_reg = NULL;
const RzRegItem *dst_reg = parse_register(core, str, &idx);
if (!dst_reg || !parse_il_equal(str, &idx)) {
goto compound;
}
if (!parse_il_equal(str, &idx)) {
free(dst_reg);
src_reg = parse_register(core, str, &idx);
if (!src_reg || !parse_il_op(str, &idx, NULL, &op) ||
!parse_constant(str, &idx, &const_value) || !parse_eof(str, idx)) {
goto compound;
}
char *src_reg = parse_register(core, str, &idx);
if (!src_reg) {
free(dst_reg);
goto compound;
}
RzList *args = rz_list_new();
if (!parse_il_op(args, str, &idx, NULL)) {
free(dst_reg);
free(src_reg);
rz_list_free(args);
goto compound;
}
ut64 const_value;
if (!parse_constant(str, &idx, &const_value)) {
free(dst_reg);
free(src_reg);
rz_list_free(args);
goto compound;
}
if (!parse_eof(str, idx)) {
free(dst_reg);
free(src_reg);
rz_list_free(args);
goto compound;
}
rop_constraint->type = MOV_OP_CONST;
rop_constraint->args[DST_REG] = dst_reg;
rop_constraint->args[SRC_REG] = src_reg;
RzILOpPureCode *op = rz_list_get_n(args, 0);
if (!op) {
free(dst_reg);
free(src_reg);
rz_list_free(args);
goto compound;
}
char op_str[16];
rz_strf(op_str, "%" PFMT64u, const_value);
rop_constraint->args[SRC_CONST] = rz_str_dup(op_str);
const char *value_str = rz_il_op_pure_code_stringify(*op);
rop_constraint->args[OP] = rz_str_dup(value_str);
rz_list_free(args);
return true;
return rop_constraint_set_const(rc, MOV_OP_CONST, dst_reg, src_reg, const_value) &&
rop_constraint_set_op(rc, op);
compound:
return parse_compound_op(core, str, rop_constraint);
return parse_compound_op(core, str, rc);
}
static bool parse_reg_op_reg(const RzCore *core, const char *str, RzRopConstraint *rc) {
ut64 idx = 0;
RzILOpPureCode op = RZ_IL_OP_PURE_MAX;
const RzRegItem *src_reg0 = NULL;
const RzRegItem *src_reg1 = NULL;
const RzRegItem *dst_reg = parse_register(core, str, &idx);
if (!dst_reg) {
goto compound;
}
if (!parse_il_equal(str, &idx)) {
goto compound;
}
src_reg0 = parse_register(core, str, &idx);
if (!src_reg0 || !parse_il_op(str, &idx, NULL, &op)) {
goto compound;
}
src_reg1 = parse_register(core, str, &idx);
if (!src_reg1 || !parse_eof(str, idx)) {
goto compound;
}
return rop_constraint_set_regs(rc, MOV_OP_REG, dst_reg, src_reg0, src_reg1) &&
rop_constraint_set_op(rc, op);
compound:
return parse_compound_op(core, str, rc);
}
/**
@ -495,70 +458,6 @@ RZ_API void rz_core_rop_search_context_free(RZ_NULLABLE RzRopSearchContext *cont
free(context);
}
static bool parse_reg_op_reg(const RzCore *core, const char *str, RzRopConstraint *rop_constraint) {
ut64 idx = 0;
char *dst_reg = parse_register(core, str, &idx);
if (!dst_reg) {
goto compound;
}
if (!parse_il_equal(str, &idx)) {
free(dst_reg);
goto compound;
}
char *src_reg1 = parse_register(core, str, &idx);
if (!src_reg1) {
free(dst_reg);
goto compound;
}
RzList *args = rz_list_new();
if (!args || !parse_il_op(args, str, &idx, NULL)) {
free(dst_reg);
free(src_reg1);
rz_list_free(args);
goto compound;
}
char *dst_reg2 = parse_register(core, str, &idx);
if (!dst_reg2) {
free(dst_reg);
free(src_reg1);
rz_list_free(args);
goto compound;
}
if (!parse_eof(str, idx)) {
free(dst_reg);
free(src_reg1);
free(dst_reg2);
rz_list_free(args);
goto compound;
}
rop_constraint->type = MOV_OP_REG;
rop_constraint->args[DST_REG] = dst_reg;
rop_constraint->args[SRC_REG] = src_reg1;
RzILOpPureCode *op = rz_list_get_n(args, 0);
if (!op) {
free(dst_reg);
free(src_reg1);
free(dst_reg2);
rz_list_free(args);
goto compound;
}
const char *op_str = rz_il_op_pure_code_stringify(*op);
rop_constraint->args[OP] = rz_str_dup(op_str);
rop_constraint->args[SRC_REG_SECOND] = dst_reg2;
rz_list_free(args);
return true;
compound:
return parse_compound_op(core, str, rop_constraint);
}
/**
* \brief Analyze and parse a constraint string.
* \param core Pointer to the RzCore object.
@ -592,15 +491,22 @@ RZ_API bool rz_core_rop_analyze_constraint(const RZ_NONNULL RzCore *core, const
* The function parses the given token and parses according to the predefined ROP constriant type
*/
RZ_API RZ_OWN RzRopConstraint *rop_constraint_parse_args(const RZ_NONNULL RzCore *core, const RZ_NONNULL char *token) {
RZ_API RZ_OWN RzRopConstraint *rz_core_rop_constraint_parse_args(const RZ_NONNULL RzCore *core, const RZ_NONNULL char *token) {
rz_return_val_if_fail(core && token, NULL);
RzRopConstraint *rop_constraint = RZ_NEW0(RzRopConstraint);
if (!rop_constraint) {
if (RZ_STR_ISEMPTY(token)) {
return NULL;
}
RzList *l = rz_str_split_duplist_n(token, "=", 1, false);
if (!l) {
RzRopConstraint *rop_constraint = RZ_NEW0(RzRopConstraint);
if (!rop_constraint) {
free(rop_constraint);
return NULL;
}
RzList *l = rz_str_split_duplist(token, "=", true);
if (rz_list_empty(l)) {
rz_list_free(l);
free(rop_constraint);
return NULL;
}
@ -624,9 +530,9 @@ RZ_API RZ_OWN RzRopConstraint *rop_constraint_parse_args(const RZ_NONNULL RzCore
*
* This function parses a list of arguments into a RzPVector of RzRopConstraint objects.
*/
RZ_API RZ_OWN RzPVector /*<RzRopConstraint *>*/ *rop_constraint_map_parse(const RZ_NONNULL RzCore *core, const int argc, const char **argv) {
RZ_API RZ_OWN RzPVector /*<RzRopConstraint *>*/ *rz_core_rop_constraint_map_parse(const RZ_NONNULL RzCore *core, const int argc, const char **argv) {
rz_return_val_if_fail(core && argv && RZ_STR_ISNOTEMPTY(argv[0]), false);
RzPVector *constr_map = rz_core_rop_constraint_new();
RzPVector *constr_map = rz_pvector_new((RzPVectorFree)rz_core_rop_constraint_free);
if (!constr_map) {
return NULL;
}
@ -642,7 +548,7 @@ RZ_API RZ_OWN RzPVector /*<RzRopConstraint *>*/ *rop_constraint_map_parse(const
RzListIter *it;
char *token;
rz_list_foreach (l, it, token) {
RzRopConstraint *rop_constraint = rop_constraint_parse_args(core, token);
RzRopConstraint *rop_constraint = rz_core_rop_constraint_parse_args(core, token);
if (!rop_constraint) {
continue;
}

View file

@ -248,7 +248,7 @@ static ut32 vernum(const char *s) {
// ascii
RZ_IPI RzCmdStatus rz_cmd_shell_ascii_table_handler(RzCore *core, int argc, const char **argv) {
rz_cons_printf("%s", ret_ascii_table());
rz_cons_printf("%s", rz_get_ascii_table());
return RZ_CMD_STATUS_OK;
}

View file

@ -530,4 +530,12 @@ static inline char *rz_address_str(ut64 addr) {
RZ_IPI void rz_core_prompt_highlight(RzCore *core);
/* heap_jemalloc */
RZ_IPI RzCmdStatus rz_heap_jemalloc_cmd_a(RzCore *core, bool has_specified_addr, ut64 addr);
RZ_IPI RzCmdStatus rz_heap_jemalloc_cmd_b(RzCore *core, bool has_specified_addr, ut64 addr, bool has_bin_info, ut64 bin_info_addr);
RZ_IPI RzCmdStatus rz_heap_jemalloc_cmd_c(RzCore *core, bool has_specified_addr, ut64 addr);
RZ_IPI RzCmdStatus rz_heap_jemalloc_cmd_e(RzCore *core, bool has_specified_addr, ut64 addr);
RZ_IPI RzCmdStatus rz_heap_jemalloc_cmd_ei(RzCore *core, bool has_specified_addr, ut64 addr);
#endif

View file

@ -4778,7 +4778,7 @@ static void ds_print_esil_analysis(RzDisasmState *ds) {
}
}
if (fcn_name) {
key = resolve_fcn_name(core->analysis, fcn_name);
key = rz_analysis_function_name_resolve(core->analysis, fcn_name);
}
if (key) {
if (ds->asm_types < 1) {

View file

@ -15,6 +15,24 @@
#include <math.h>
#include "core_private.h"
#define PRINTF_A(color, fmt, ...) rz_cons_printf("%s" fmt "%s", \
rz_config_get_i(core->config, "scr.color") > 0 ? color : "", \
__VA_ARGS__, \
rz_config_get_i(core->config, "scr.color") > 0 ? Color_RESET : "")
#define PRINTF_YA(fmt, ...) PRINTF_A(pal->offset, fmt, __VA_ARGS__)
#define PRINTF_GA(fmt, ...) PRINTF_A(pal->args, fmt, __VA_ARGS__)
#define PRINTF_BA(fmt, ...) PRINTF_A(pal->num, fmt, __VA_ARGS__)
#define PRINTF_RA(fmt, ...) PRINTF_A(pal->invalid, fmt, __VA_ARGS__)
#define PRINT_A(color, msg) rz_cons_printf("%s%s%s", \
rz_config_get_i(core->config, "scr.color") > 0 ? color : "", \
msg, \
rz_config_get_i(core->config, "scr.color") > 0 ? Color_RESET : "")
#define PRINT_YA(msg) PRINT_A(pal->offset, msg)
#define PRINT_GA(msg) PRINT_A(pal->args, msg)
#define PRINT_BA(msg) PRINT_A(pal->num, msg)
#define PRINT_RA(msg) PRINT_A(pal->invalid, msg)
void print_heap_chunk_simple(RzCore *core, ut64 chunk, const char *status, PJ *pj, const RzHeapConfig *config);
static bool rz_heap_get_brks(RzCore *core, ut64 *brk_start, ut64 *brk_end);
static inline bool init_glibc_config(RzCore *core, RzHeapConfig *config);

View file

@ -7,6 +7,36 @@
#include <rz_heap_jemalloc.h>
#include <stdio.h>
#define PRINTF_A(color, fmt, ...) \
do { \
if ((color) && rz_config_get_i(core->config, "scr.color") > 0) { \
rz_cons_print(color); \
} \
rz_cons_printf(fmt, __VA_ARGS__); \
if ((color) && rz_config_get_i(core->config, "scr.color") > 0) { \
rz_cons_print(Color_RESET); \
} \
} while (0)
#define PRINTF_YA(fmt, ...) PRINTF_A(pal->offset, fmt, __VA_ARGS__)
#define PRINTF_GA(fmt, ...) PRINTF_A(pal->args, fmt, __VA_ARGS__)
#define PRINTF_BA(fmt, ...) PRINTF_A(pal->num, fmt, __VA_ARGS__)
#define PRINTF_RA(fmt, ...) PRINTF_A(pal->invalid, fmt, __VA_ARGS__)
#define PRINT_A(color, msg) \
do { \
if ((color) && rz_config_get_i(core->config, "scr.color") > 0) { \
rz_cons_print(color); \
} \
rz_cons_print(msg); \
if ((color) && rz_config_get_i(core->config, "scr.color") > 0) { \
rz_cons_print(Color_RESET); \
} \
} while (0)
#define PRINT_YA(msg) PRINT_A(pal->offset, msg)
#define PRINT_GA(msg) PRINT_A(pal->args, msg)
#define PRINT_BA(msg) PRINT_A(pal->num, msg)
#define PRINT_RA(msg) PRINT_A(pal->invalid, msg)
static ut64 je_get_va_symbol(RzCore *core, const char *path, const char *sym_name, bool *is_pie) {
ut64 vaddr = UT64_MAX;
RzBin *bin = core->bin;

View file

@ -1997,24 +1997,8 @@ RZ_API void rz_core_rop_constraint_free(RZ_NULLABLE void *data) {
if (!constraint) {
return;
}
for (int i = 0; i < NUM_ARGS; i++) {
if (constraint->args[i]) {
free(constraint->args[i]);
}
for (size_t i = 0; i < NUM_ARGS; i++) {
free(constraint->args[i]);
}
free(constraint);
}
/**
* \brief Create a pvector of RzRopConstraint objects.
* \return Pointer to the newly created list.
*
* Creates a new RzList for RzRopConstraint object.
*/
RZ_API RZ_OWN RzPVector /*<RzRopConstraint *>*/ *rz_core_rop_constraint_new(void) {
RzPVector *v = rz_pvector_new((RzPVectorFree)rz_core_rop_constraint_free);
if (!v) {
return NULL;
}
return v;
}

View file

@ -277,6 +277,9 @@ static const char *help_msg_panels_zoom[] = {
NULL
};
RZ_IPI void rz_save_panels_layout(RzCore *core, const char *_name);
RZ_IPI bool rz_load_panels_layout(RzCore *core, const char *_name);
/* init */
static bool __init(RzCore *core, RzPanelsTab *tab, int w, int h);
static void __init_sdb(RzCore *core);
@ -4270,6 +4273,15 @@ RZ_OWN RzPanelsMenuItem *rz_panels_menu_item_new(RZ_NULLABLE const char *name, R
return item;
}
static void rz_panel_free(RZ_NULLABLE RzPanel *panel) {
if (!panel) {
return;
}
rz_panel_model_free(panel->model);
free(panel->view);
free(panel);
}
void rz_panels_menu_item_free(RZ_NULLABLE RzPanelsMenuItem *item) {
if (!item) {
return;
@ -6114,15 +6126,6 @@ static void rz_panels_menu_free(RZ_NULLABLE RzPanelsMenu *menu) {
free(menu);
}
RZ_IPI void rz_panel_free(RZ_NULLABLE RzPanel *panel) {
if (!panel) {
return;
}
rz_panel_model_free(panel->model);
free(panel->view);
free(panel);
}
void rz_panels_tab_free(RZ_NULLABLE RzPanelsTab *tab) {
if (!tab) {
return;

View file

@ -111,8 +111,8 @@ RZ_API Sdb *rz_agraph_get_sdb(RzAGraph *g);
RZ_API void rz_agraph_foreach(RzAGraph *g, RzANodeCallback cb, void *user);
RZ_API void rz_agraph_foreach_edge(RzAGraph *g, RAEdgeCallback cb, void *user);
RZ_API void rz_agraph_set_curnode(RzAGraph *g, RzANode *node);
RZ_API bool create_agraph_from_graph_at(RZ_NONNULL RzAGraph *ag, RZ_NONNULL const RzGraph /*<RzGraphNodeInfo *, None *>*/ *g, bool free_on_fail, bool utf8);
RZ_API RZ_OWN RzAGraph *create_agraph_from_graph(RZ_NONNULL const RzGraph /*<RzGraphNodeInfo *, None *>*/ *graph, bool utf8);
RZ_API bool rz_core_create_agraph_from_graph_at(RZ_NONNULL RzAGraph *ag, RZ_NONNULL const RzGraph /*<RzGraphNodeInfo *, None *>*/ *g, bool free_on_fail, bool utf8);
RZ_API RZ_OWN RzAGraph *rz_core_create_agraph_from_graph(RZ_NONNULL const RzGraph /*<RzGraphNodeInfo *, None *>*/ *graph, bool utf8);
RZ_API void rz_agraph_compute_layout(RZ_NONNULL RzAGraph *g);
#endif

View file

@ -1508,6 +1508,7 @@ RZ_API bool rz_analysis_function_was_modified(RZ_NONNULL RzAnalysisFunction *fcn
RZ_API bool rz_analysis_function_is_autonamed(RZ_NONNULL char *name);
RZ_API RZ_OWN char *rz_analysis_function_name_guess(RzTypeDB *typedb, RZ_NONNULL char *name);
RZ_API RZ_OWN char *rz_analysis_function_name_resolve(RZ_NONNULL RzAnalysis *analysis, RZ_NONNULL const char *func_name);
RZ_DEPRECATE RZ_API bool rz_analysis_le_addr_pair_reset(RZ_NONNULL RzAnalysis *analysis);
/* analysis.c */

View file

@ -732,7 +732,6 @@ RZ_API char *rz_core_disassemble_bytes(RzCore *core, ut64 addr, int b);
RZ_DEPRECATE RZ_API ut64 rz_core_arg_get(RzCore *core, const char *cc, int num);
RZ_API RZ_OWN RzList /*<RzAnalysisFuncArg *>*/ *rz_core_get_func_args(RzCore *core, const char *func_name);
RZ_API void rz_core_print_func_args(RzCore *core);
RZ_API char *resolve_fcn_name(RzAnalysis *analysis, const char *func_name);
/* clang.c */
RZ_API RzCmdStatus rz_core_lang_plugins_print(RzLang *lang, RzCmdStateOutput *state);

View file

@ -13,26 +13,6 @@
extern "C" {
#endif
RZ_LIB_VERSION_HEADER(rz_heap_glibc);
#define PRINTF_A(color, fmt, ...) rz_cons_printf("%s" fmt "%s", \
rz_config_get_i(core->config, "scr.color") > 0 ? color : "", \
__VA_ARGS__, \
rz_config_get_i(core->config, "scr.color") > 0 ? Color_RESET : "")
#define PRINTF_YA(fmt, ...) PRINTF_A(pal->offset, fmt, __VA_ARGS__)
#define PRINTF_GA(fmt, ...) PRINTF_A(pal->args, fmt, __VA_ARGS__)
#define PRINTF_BA(fmt, ...) PRINTF_A(pal->num, fmt, __VA_ARGS__)
#define PRINTF_RA(fmt, ...) PRINTF_A(pal->invalid, fmt, __VA_ARGS__)
#define PRINT_A(color, msg) rz_cons_printf("%s%s%s", \
rz_config_get_i(core->config, "scr.color") > 0 ? color : "", \
msg, \
rz_config_get_i(core->config, "scr.color") > 0 ? Color_RESET : "")
#define PRINT_YA(msg) PRINT_A(pal->offset, msg)
#define PRINT_GA(msg) PRINT_A(pal->args, msg)
#define PRINT_BA(msg) PRINT_A(pal->num, msg)
#define PRINT_RA(msg) PRINT_A(pal->invalid, msg)
RZ_API RzHeapChunkSimple *rz_heap_chunk(RzCore *core, ut64 addr);
RZ_API RzHeapChunk *rz_heap_get_chunk_at_addr(RzCore *core, ut64 addr);
RZ_API RzList /*<RzHeapChunkListItem *>*/ *rz_heap_chunks_list(RzCore *core, ut64 m_arena);

View file

@ -11,52 +11,4 @@
#include <rz_core.h>
#include <rz_types.h>
// Undefine any previous definitions from rz_heap_glibc.h
#undef PRINTF_A
#undef PRINTF_YA
#undef PRINTF_GA
#undef PRINTF_BA
#undef PRINTF_RA
#undef PRINT_A
#undef PRINT_YA
#undef PRINT_GA
#undef PRINT_BA
#undef PRINT_RA
#define PRINTF_A(color, fmt, ...) \
do { \
if ((color) && rz_config_get_i(core->config, "scr.color") > 0) { \
rz_cons_print(color); \
} \
rz_cons_printf(fmt, __VA_ARGS__); \
if ((color) && rz_config_get_i(core->config, "scr.color") > 0) { \
rz_cons_print(Color_RESET); \
} \
} while (0)
#define PRINTF_YA(fmt, ...) PRINTF_A(pal->offset, fmt, __VA_ARGS__)
#define PRINTF_GA(fmt, ...) PRINTF_A(pal->args, fmt, __VA_ARGS__)
#define PRINTF_BA(fmt, ...) PRINTF_A(pal->num, fmt, __VA_ARGS__)
#define PRINTF_RA(fmt, ...) PRINTF_A(pal->invalid, fmt, __VA_ARGS__)
#define PRINT_A(color, msg) \
do { \
if ((color) && rz_config_get_i(core->config, "scr.color") > 0) { \
rz_cons_print(color); \
} \
rz_cons_print(msg); \
if ((color) && rz_config_get_i(core->config, "scr.color") > 0) { \
rz_cons_print(Color_RESET); \
} \
} while (0)
#define PRINT_YA(msg) PRINT_A(pal->offset, msg)
#define PRINT_GA(msg) PRINT_A(pal->args, msg)
#define PRINT_BA(msg) PRINT_A(pal->num, msg)
#define PRINT_RA(msg) PRINT_A(pal->invalid, msg)
RZ_IPI RzCmdStatus rz_heap_jemalloc_cmd_a(RzCore *core, bool has_specified_addr, ut64 addr);
RZ_IPI RzCmdStatus rz_heap_jemalloc_cmd_b(RzCore *core, bool has_specified_addr, ut64 addr, bool has_bin_info, ut64 bin_info_addr);
RZ_IPI RzCmdStatus rz_heap_jemalloc_cmd_c(RzCore *core, bool has_specified_addr, ut64 addr);
RZ_IPI RzCmdStatus rz_heap_jemalloc_cmd_e(RzCore *core, bool has_specified_addr, ut64 addr);
RZ_IPI RzCmdStatus rz_heap_jemalloc_cmd_ei(RzCore *core, bool has_specified_addr, ut64 addr);
#endif // RZ_HEAP_JEMALLOC_H

View file

@ -391,8 +391,8 @@ RZ_API int rz_io_desc_read_at(RzIODesc *desc, ut64 addr, ut8 *buf, size_t len);
RZ_API int rz_io_desc_write_at(RzIODesc *desc, ut64 addr, const ut8 *buf, size_t len);
/* lifecycle */
RZ_IPI bool rz_io_desc_init(RzIO *io);
RZ_IPI bool rz_io_desc_fini(RzIO *io);
RZ_API bool rz_io_desc_init(RzIO *io);
RZ_API bool rz_io_desc_fini(RzIO *io);
/* io/cache.c */
RZ_API int rz_io_cache_invalidate(RzIO *io, ut64 from, ut64 to);

View file

@ -309,8 +309,6 @@ typedef struct {
char *name;
} PDBSData;
RZ_IPI bool PDBSData_parse(RzBuffer *b, PDBSymbolKind kind, PDBSData *sdata);
typedef struct {
bool code : 1;
bool function : 1;
@ -320,8 +318,6 @@ typedef struct {
char *name;
} PDBSPublic;
RZ_IPI bool PDBSPublic_parse(RzBuffer *b, PDBSymbolKind kind, PDBSPublic *s);
typedef struct {
PDBSymbolIndex index;
PDBSymbolKind raw_kind;

View file

@ -172,7 +172,7 @@ RZ_API RzCmdStatus rz_core_rop_search(RZ_NONNULL RzCore *core, RZ_NONNULL RzRopS
RZ_API RzCmdStatus rz_core_rop_gadget_info(RZ_NONNULL RzCore *core, RZ_NONNULL RZ_OWN RzRopSearchContext *context);
RZ_API bool rz_core_rop_analyze_constraint(const RZ_NONNULL RzCore *core, const RZ_NONNULL char *str,
RZ_NULLABLE RZ_OUT RzRopConstraint *rop_constraint);
RZ_API RZ_OWN RzPVector /*<RzRopConstraint *>*/ *rop_constraint_map_parse(const RZ_NONNULL RzCore *core, int argc, const char **argv);
RZ_API RZ_OWN RzPVector /*<RzRopConstraint *>*/ *rz_core_rop_constraint_map_parse(const RZ_NONNULL RzCore *core, int argc, const char **argv);
RZ_API bool rz_core_handle_rop_request_type(RZ_NONNULL RzCore *core, RZ_NONNULL RzRopSearchContext *context, RZ_NONNULL RzList /*<RzCoreAsmHit *>*/ *hitlist);
RZ_API RZ_NULLABLE RZ_OWN RzList /*<char *>*/ *rz_core_rop_handle_grep_args(RZ_NULLABLE const char *greparg, const bool regexp);
@ -183,8 +183,7 @@ RZ_API void rz_core_rop_search_context_free(RZ_NULLABLE RzRopSearchContext *cont
// ROP Constraint APIs
RZ_API void rz_core_rop_constraint_free(RZ_NULLABLE void *data);
RZ_API RZ_OWN RzPVector /*<RzRopConstraint *>*/ *rz_core_rop_constraint_new(void);
RZ_API RZ_OWN RzRopConstraint *rop_constraint_parse_args(const RZ_NONNULL RzCore *core, const RZ_NONNULL char *token);
RZ_API RZ_OWN RzRopConstraint *rz_core_rop_constraint_parse_args(const RZ_NONNULL RzCore *core, const RZ_NONNULL char *token);
// ROP Gadget Info APIs
RZ_API void rz_core_rop_gadget_info_free(RZ_NULLABLE RzRopGadgetInfo *gadget_info);

View file

@ -11,7 +11,7 @@
extern "C" {
#endif
RZ_API const char *ret_ascii_table(void);
RZ_API const char *rz_get_ascii_table(void);
#ifdef __cplusplus
}

View file

@ -72,10 +72,6 @@ typedef struct rz_panel_t {
typedef void (*RzPanelAlmightyCallback)(void *user, RzPanel *panel, const RzPanelLayout dir, RZ_NULLABLE const char *title);
RZ_IPI void rz_panel_free(RZ_NULLABLE RzPanel *panel);
RZ_IPI void rz_save_panels_layout(RzCore *core, const char *_name);
RZ_IPI bool rz_load_panels_layout(RzCore *core, const char *_name);
#ifdef __cplusplus
}
#endif

View file

@ -367,7 +367,7 @@ RZ_API int rz_io_desc_write_at(RzIODesc *desc, ut64 addr, const ut8 *buf, size_t
/* lifecycle */
// TODO: move into io.c : rz_io_init
RZ_IPI bool rz_io_desc_init(RzIO *io) {
RZ_API bool rz_io_desc_init(RzIO *io) {
rz_return_val_if_fail(io, false);
rz_io_desc_fini(io);
// TODO: it leaks if called twice
@ -389,7 +389,7 @@ static bool desc_fini_cb(void *user, void *data, ut32 id) {
}
// closes all descs and frees all descs and io->files
RZ_IPI bool rz_io_desc_fini(RzIO *io) {
RZ_API bool rz_io_desc_fini(RzIO *io) {
rz_return_val_if_fail(io, false);
if (io->files) {
rz_id_storage_foreach(io->files, desc_fini_cb, io);

View file

@ -184,7 +184,7 @@ static void print_hex_from_base2(char *base2) {
}
static void print_ascii_table(void) {
printf("%s", ret_ascii_table());
printf("%s", rz_get_ascii_table());
}
static int help(void) {

View file

@ -75,6 +75,6 @@ static const char *ascii_table =
"076 62 3E > 176 126 7E ~\n"
"077 63 3F ? 177 127 7F DEL\n";
RZ_API const char *ret_ascii_table(void) {
RZ_API const char *rz_get_ascii_table(void) {
return ascii_table;
}

View file

@ -23,7 +23,7 @@ bool test_graph_to_agraph() {
mu_assert_notnull(graph, "Couldn't create the graph");
mu_assert_eq(rz_graph_count_nodes(graph), 4, "Wrong node count");
RzAGraph *agraph = create_agraph_from_graph(graph, false);
RzAGraph *agraph = rz_core_create_agraph_from_graph(graph, false);
mu_assert_notnull(agraph, "Couldn't create the agraph");
mu_assert_eq(rz_graph_count_nodes(agraph->graph), 4, "Wrong agraph node count");

View file

@ -45,17 +45,17 @@ bool test_parse_reg_to_const(void) {
// Test case 1: Valid register to constant
char str1[] = " eax = 123 ";
RzRopConstraint *rop_constraint = rop_constraint_parse_args(core, str1);
RzRopConstraint *rop_constraint = rz_core_rop_constraint_parse_args(core, str1);
mu_assert_notnull(rop_constraint, "parse_reg_constraints failed on valid input");
mu_assert_eq(rop_constraint->type, MOV_CONST, "Invalid constraint type");
mu_assert_streq(rop_constraint->args[DST_REG], "eax", "Invalid destination register");
mu_assert_null(rop_constraint->args[SRC_REG], "Source register should be NULL");
mu_assert_streq(rop_constraint->args[SRC_CONST], "123", "Invalid constant value");
rz_core_rop_constraint_free(rop_constraint);
// Test case 2: Invalid format
char str2[] = "eax =";
rop_constraint = rop_constraint_parse_args(core, str2);
rop_constraint = rz_core_rop_constraint_parse_args(core, str2);
mu_assert_null(rop_constraint, "parse_reg_constraints failed on invalid input");
rz_core_rop_constraint_free(rop_constraint);
@ -70,7 +70,7 @@ bool test_parse_reg_to_reg(void) {
// Test case 1: Valid register to register
char str1[] = "eax = ebx ";
RzRopConstraint *rop_constraint = rop_constraint_parse_args(core, str1);
RzRopConstraint *rop_constraint = rz_core_rop_constraint_parse_args(core, str1);
mu_assert_notnull(rop_constraint, "parse_reg_constraints failed on valid input");
mu_assert_eq(rop_constraint->type, MOV_REG, "Invalid constraint type");
mu_assert_streq(rop_constraint->args[DST_REG], "eax", "Invalid destination register");
@ -79,7 +79,7 @@ bool test_parse_reg_to_reg(void) {
// Test case 2: Invalid format
char str2[] = "eax =";
rop_constraint = rop_constraint_parse_args(core, str2);
rop_constraint = rz_core_rop_constraint_parse_args(core, str2);
mu_assert_null(rop_constraint, "parse_reg_constraints failed on invalid input");
rz_core_rop_constraint_free(rop_constraint);
@ -94,25 +94,24 @@ bool test_parse_reg_op_const(void) {
// Test case 1: Valid register operation with constant
char str1[] = "eax=eax+3";
RzRopConstraint *rop_constraint = rop_constraint_parse_args(core, str1);
RzRopConstraint *rop_constraint = rz_core_rop_constraint_parse_args(core, str1);
mu_assert_notnull(rop_constraint, "parse_reg_constraints failed on valid input");
mu_assert_eq(rop_constraint->type, MOV_OP_CONST, "Invalid constraint type");
mu_assert_streq(rop_constraint->args[DST_REG], "eax", "Invalid destination register");
mu_assert_streq(rop_constraint->args[SRC_REG], "eax", "Invalid source register");
mu_assert_streq(rop_constraint->args[OP], "add", "Invalid operator");
mu_assert_streq(rop_constraint->args[SRC_CONST], "3", "Invalid constant value");
rz_core_rop_constraint_free(rop_constraint);
// Test case 2: Invalid format
char str2[] = "eax=eax+";
rop_constraint = rop_constraint_parse_args(core, str2);
rop_constraint = rz_core_rop_constraint_parse_args(core, str2);
mu_assert_null(rop_constraint, "parse_reg_constraints failed on invalid input");
rz_core_rop_constraint_free(rop_constraint);
// Test case 3: Valid register operation with increment operator
char str3[] = "eax++";
rop_constraint = rop_constraint_parse_args(core, str3);
rop_constraint = rz_core_rop_constraint_parse_args(core, str3);
mu_assert_notnull(rop_constraint, "parse_reg_constraints failed on valid input");
mu_assert_eq(rop_constraint->type, MOV_OP_CONST, "Invalid constraint type");
mu_assert_streq(rop_constraint->args[DST_REG], "eax", "Invalid destination register");
@ -123,7 +122,7 @@ bool test_parse_reg_op_const(void) {
// Test case 4: Valid register operation with decrement operator
char str4[] = "eax--";
rop_constraint = rop_constraint_parse_args(core, str4);
rop_constraint = rz_core_rop_constraint_parse_args(core, str4);
mu_assert_notnull(rop_constraint, "parse_reg_constraints failed on valid input");
mu_assert_eq(rop_constraint->type, MOV_OP_CONST, "Invalid constraint type");
mu_assert_streq(rop_constraint->args[DST_REG], "eax", "Invalid destination register");
@ -134,7 +133,7 @@ bool test_parse_reg_op_const(void) {
// Test case 5: Valid register operation with compound operator
char str5[] = "eax *= 1";
rop_constraint = rop_constraint_parse_args(core, str5);
rop_constraint = rz_core_rop_constraint_parse_args(core, str5);
mu_assert_notnull(rop_constraint, "parse_reg_constraints failed on valid input");
mu_assert_eq(rop_constraint->type, MOV_OP_CONST, "Invalid constraint type");
mu_assert_streq(rop_constraint->args[DST_REG], "eax", "Invalid destination register");
@ -154,32 +153,32 @@ bool test_parse_reg_op_reg(void) {
// Test case 1: Valid register operation with register
char str1[] = "eax=ebx-ecx";
RzRopConstraint *rop_constraint = rop_constraint_parse_args(core, str1);
RzRopConstraint *rop_constraint = rz_core_rop_constraint_parse_args(core, str1);
mu_assert_notnull(rop_constraint, "parse_reg_constraints failed on valid input");
mu_assert_eq(rop_constraint->type, MOV_OP_REG, "Invalid constraint type");
mu_assert_streq(rop_constraint->args[DST_REG], "eax", "Invalid destination register");
mu_assert_streq(rop_constraint->args[SRC_REG], "ebx", "Invalid source register");
mu_assert_streq(rop_constraint->args[OP], "sub", "Invalid operator");
mu_assert_streq(rop_constraint->args[SRC_REG_SECOND], "ecx", "Invalid destination constant register");
rz_core_rop_constraint_free(rop_constraint);
// Test case 2: Invalid format
char str2[] = "eax = eax+ ";
rop_constraint = rop_constraint_parse_args(core, str2);
rop_constraint = rz_core_rop_constraint_parse_args(core, str2);
mu_assert_null(rop_constraint, "parse_reg_constraints failed on invalid input");
rz_core_rop_constraint_free(rop_constraint);
// Test case 3: Valid register operation with register
char str3[] = "eax += ebx";
rop_constraint = rop_constraint_parse_args(core, str3);
rop_constraint = rz_core_rop_constraint_parse_args(core, str3);
mu_assert_notnull(rop_constraint, "parse_reg_constraints failed on valid input");
mu_assert_eq(rop_constraint->type, MOV_OP_REG, "Invalid constraint type");
mu_assert_streq(rop_constraint->args[DST_REG], "eax", "Invalid destination register");
mu_assert_streq(rop_constraint->args[SRC_REG], "eax", "Invalid source register");
mu_assert_streq(rop_constraint->args[SRC_REG_SECOND], "ebx", "Invalid destination constant register");
mu_assert_streq(rop_constraint->args[OP], "add", "Invalid operator");
rz_core_rop_constraint_free(rop_constraint);
rz_core_free(core);
mu_end;
}