mirror of
https://github.com/radareorg/radare2.git
synced 2024-11-24 13:49:50 +00:00
Remove more members from RAnalBlock ##anal (#15975)
* Remove RAnalBlock.type * Remove RAnalBlock.cases * Remove RAnalBlock.label * Reorder RAnalBlock members to free 16 more bytes
This commit is contained in:
parent
e94b70b900
commit
cf09972367
@ -53,7 +53,6 @@ static RAnalBlock *block_new(RAnal *a, ut64 addr, ut64 size) {
|
||||
block->ref = 1;
|
||||
block->jump = UT64_MAX;
|
||||
block->fail = UT64_MAX;
|
||||
block->type = R_ANAL_BB_TYPE_NULL;
|
||||
block->op_pos = R_NEWS0 (ut16, DFLT_NINSTR);
|
||||
block->op_pos_size = DFLT_NINSTR;
|
||||
block->stackptr = 0;
|
||||
@ -73,7 +72,6 @@ static void block_free(RAnalBlock *block) {
|
||||
free (block->op_bytes);
|
||||
r_anal_switch_op_free (block->switch_op);
|
||||
r_list_free (block->fcns);
|
||||
free (block->label);
|
||||
free (block->op_pos);
|
||||
free (block->parent_reg_arena);
|
||||
free (block);
|
||||
|
@ -1432,7 +1432,7 @@ R_API RAnalFunction *r_anal_fcn_find_name(RAnal *a, const char *name) {
|
||||
}
|
||||
|
||||
/* rename RAnalFunctionBB.add() */
|
||||
R_API bool r_anal_fcn_add_bb(RAnal *a, RAnalFunction *fcn, ut64 addr, ut64 size, ut64 jump, ut64 fail, int type, R_BORROW RAnalDiff *diff) {
|
||||
R_API bool r_anal_fcn_add_bb(RAnal *a, RAnalFunction *fcn, ut64 addr, ut64 size, ut64 jump, ut64 fail, R_BORROW RAnalDiff *diff) {
|
||||
D eprintf ("Add bb\n");
|
||||
if (size == 0) { // empty basic blocks allowed?
|
||||
eprintf ("Warning: empty basic block at 0x%08"PFMT64x" is not allowed. pending discussion.\n", addr);
|
||||
@ -1474,7 +1474,6 @@ R_API bool r_anal_fcn_add_bb(RAnal *a, RAnalFunction *fcn, ut64 addr, ut64 size,
|
||||
block->jump = jump;
|
||||
block->fail = fail;
|
||||
block->fail = fail;
|
||||
block->type = type;
|
||||
if (diff) {
|
||||
if (!block->diff) {
|
||||
block->diff = r_anal_diff_new ();
|
||||
@ -1530,9 +1529,6 @@ R_API int r_anal_fcn_cc(RAnal *anal, RAnalFunction *fcn) {
|
||||
E++;
|
||||
}
|
||||
}
|
||||
if (bb->cases) { // dead code ?
|
||||
E += r_list_length (bb->cases);
|
||||
}
|
||||
if (bb->switch_op && bb->switch_op->cases) {
|
||||
E += r_list_length (bb->switch_op->cases);
|
||||
}
|
||||
|
@ -233,99 +233,6 @@ list_err:
|
||||
return NULL;
|
||||
}
|
||||
|
||||
R_API RList* r_anal_reflines_fcn_get(RAnal *anal, RAnalFunction *fcn, int nlines, int linesout, int linescall) {
|
||||
RAnalBlock *bb;
|
||||
RListIter *bb_iter;
|
||||
RAnalRefline *item;
|
||||
int index = 0;
|
||||
ut32 len;
|
||||
|
||||
RList *list = r_list_new ();
|
||||
if (!list) {
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/* analyze code block */
|
||||
r_list_foreach (fcn->bbs, bb_iter, bb) {
|
||||
if (!bb || !bb->size) {
|
||||
continue;
|
||||
}
|
||||
if (nlines != -1 && !--nlines) {
|
||||
break;
|
||||
}
|
||||
len = bb->size;
|
||||
/* store data */
|
||||
ut64 control_type = bb->type;
|
||||
control_type &= R_ANAL_BB_TYPE_SWITCH | R_ANAL_BB_TYPE_JMP | R_ANAL_BB_TYPE_COND | R_ANAL_BB_TYPE_CALL;
|
||||
|
||||
// handle call
|
||||
if (!linescall) {
|
||||
if ((control_type & R_ANAL_BB_TYPE_CALL) == R_ANAL_BB_TYPE_CALL) {
|
||||
continue;
|
||||
}
|
||||
}
|
||||
// Handles conditional + unconditional jump
|
||||
if ((control_type & R_ANAL_BB_TYPE_CJMP) == R_ANAL_BB_TYPE_CJMP) {
|
||||
// don't need to continue here is opc+len exceed function scope
|
||||
if (linesout && bb->fail > 0LL && bb->fail != bb->addr + len) {
|
||||
item = R_NEW0 (RAnalRefline);
|
||||
if (!item) {
|
||||
r_list_free (list);
|
||||
return NULL;
|
||||
}
|
||||
item->from = bb->addr;
|
||||
item->to = bb->fail;
|
||||
item->index = index++;
|
||||
item->type = 'c';
|
||||
item->direction = (bb->jump > bb->addr)? 1: -1;
|
||||
r_list_append (list, item);
|
||||
}
|
||||
}
|
||||
if ((control_type & R_ANAL_BB_TYPE_JMP) == R_ANAL_BB_TYPE_JMP) {
|
||||
if (!linesout || !bb->jump || bb->jump == bb->addr + len) {
|
||||
continue;
|
||||
}
|
||||
item = R_NEW0 (RAnalRefline);
|
||||
if (!item) {
|
||||
r_list_free (list);
|
||||
return NULL;
|
||||
}
|
||||
item->from = bb->addr;
|
||||
item->to = bb->jump;
|
||||
item->index = index++;
|
||||
item->type = 'j';
|
||||
item->direction = (bb->jump > bb->addr)? 1: -1;
|
||||
r_list_append (list, item);
|
||||
continue;
|
||||
}
|
||||
|
||||
// XXX - Todo test handle switch op
|
||||
if (control_type & R_ANAL_BB_TYPE_SWITCH) {
|
||||
if (bb->switch_op) {
|
||||
RAnalCaseOp *caseop;
|
||||
RListIter *iter;
|
||||
r_list_foreach (bb->switch_op->cases, iter, caseop) {
|
||||
if (caseop) {
|
||||
if (!linesout) {// && (op.jump > opc+len || op.jump < pc))
|
||||
continue;
|
||||
}
|
||||
item = R_NEW0 (RAnalRefline);
|
||||
if (!item){
|
||||
r_list_free (list);
|
||||
return NULL;
|
||||
}
|
||||
item->from = bb->switch_op->addr;
|
||||
item->to = caseop->jump;
|
||||
item->index = index++;
|
||||
r_list_append (list, item);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return list;
|
||||
}
|
||||
|
||||
R_API int r_anal_reflines_middle(RAnal *a, RList* /*<RAnalRefline>*/ list, ut64 addr, int len) {
|
||||
if (a && list) {
|
||||
RAnalRefline *ref;
|
||||
|
@ -233,7 +233,7 @@ static void createFunction(RCore *core, fcn_t* fcn, const char *name) {
|
||||
if (__isdata (core, cur->start)) {
|
||||
continue;
|
||||
}
|
||||
r_anal_fcn_add_bb (core->anal, f, cur->start, (cur->end - cur->start), cur->jump, cur->fail, 0, NULL);
|
||||
r_anal_fcn_add_bb (core->anal, f, cur->start, (cur->end - cur->start), cur->jump, cur->fail, NULL);
|
||||
}
|
||||
if (!r_anal_add_function (core->anal, f)) {
|
||||
// eprintf ("Failed to insert function\n");
|
||||
|
@ -2077,7 +2077,7 @@ static bool anal_fcn_list_bb(RCore *core, const char *input, bool one) {
|
||||
}
|
||||
ls_foreach (fcn->bbs, iter, b) {
|
||||
RInterval inter = (RInterval) {b->addr, b->size};
|
||||
RListInfo *info = r_listinfo_new (b->label, inter, inter, -1, NULL);
|
||||
RListInfo *info = r_listinfo_new (NULL, inter, inter, -1, NULL);
|
||||
if (!info) {
|
||||
break;
|
||||
}
|
||||
@ -2337,7 +2337,6 @@ static int anal_fcn_add_bb(RCore *core, const char *input) {
|
||||
ut64 size = 0LL;
|
||||
ut64 jump = UT64_MAX;
|
||||
ut64 fail = UT64_MAX;
|
||||
int type = R_ANAL_BB_TYPE_NULL;
|
||||
RAnalFunction *fcn = NULL;
|
||||
RAnalDiff *diff = NULL;
|
||||
|
||||
@ -2370,7 +2369,7 @@ static int anal_fcn_add_bb(RCore *core, const char *input) {
|
||||
}
|
||||
fcn = r_anal_get_function_at (core->anal, fcnaddr);
|
||||
if (fcn) {
|
||||
if (!r_anal_fcn_add_bb (core->anal, fcn, addr, size, jump, fail, type, diff))
|
||||
if (!r_anal_fcn_add_bb (core->anal, fcn, addr, size, jump, fail, diff))
|
||||
//if (!r_anal_fcn_add_bb_raw (core->anal, fcn, addr, size, jump, fail, type, diff))
|
||||
{
|
||||
eprintf ("afb+: Cannot add basic block at 0x%08"PFMT64x"\n", addr);
|
||||
|
@ -504,22 +504,6 @@ typedef enum {
|
||||
R_ANAL_DATA_LAST
|
||||
} _RAnalData;
|
||||
|
||||
typedef enum {
|
||||
R_ANAL_BB_TYPE_NULL = 0,
|
||||
R_ANAL_BB_TYPE_SWITCH = 0x10, /* TODO: switch */
|
||||
|
||||
R_ANAL_BB_TYPE_RET = 0x0020, /* return bb */
|
||||
R_ANAL_BB_TYPE_JMP = 0x0040, /* jmp bb */
|
||||
R_ANAL_BB_TYPE_COND = 0x0100, /* conditional bb */
|
||||
R_ANAL_BB_TYPE_CJMP = R_ANAL_BB_TYPE_COND | R_ANAL_BB_TYPE_JMP,
|
||||
R_ANAL_BB_TYPE_CALL = 0x0200,
|
||||
R_ANAL_BB_TYPE_CMP = 0x0400,
|
||||
R_ANAL_BB_TYPE_LD = 0x0800,
|
||||
R_ANAL_BB_TYPE_ST = 0x1000,
|
||||
R_ANAL_BB_TYPE_BINOP= 0x2000,
|
||||
R_ANAL_BB_TYPE_TAIL = 0x8000,
|
||||
} _RAnalBlockType;
|
||||
|
||||
typedef enum {
|
||||
R_ANAL_STACK_NULL = 0,
|
||||
R_ANAL_STACK_NOP,
|
||||
@ -895,11 +879,9 @@ typedef struct r_anal_bb_t {
|
||||
ut64 size;
|
||||
ut64 jump;
|
||||
ut64 fail;
|
||||
int type;
|
||||
int ninstr;
|
||||
bool traced;
|
||||
bool folded;
|
||||
ut32 colorize;
|
||||
char *label;
|
||||
ut8 *fingerprint;
|
||||
RAnalDiff *diff;
|
||||
RAnalCond *cond;
|
||||
@ -907,18 +889,18 @@ typedef struct r_anal_bb_t {
|
||||
// offsets of instructions in this block
|
||||
ut16 *op_pos;
|
||||
// size of the op_pos array
|
||||
int op_pos_size;
|
||||
ut8 *op_bytes;
|
||||
RList /*struct r_anal_bb_t*/ *cases;
|
||||
ut8 *parent_reg_arena;
|
||||
int op_pos_size;
|
||||
int ninstr;
|
||||
int stackptr;
|
||||
int parent_stackptr;
|
||||
bool folded;
|
||||
ut64 cmpval;
|
||||
const char *cmpreg;
|
||||
|
||||
RList *fcns;
|
||||
int ref;
|
||||
RAnal *anal;
|
||||
int ref;
|
||||
#undef RAnalBlock
|
||||
} RAnalBlock;
|
||||
|
||||
@ -1566,7 +1548,7 @@ R_API int r_anal_fcn_del(RAnal *anal, ut64 addr);
|
||||
R_API int r_anal_fcn_del_locs(RAnal *anal, ut64 addr);
|
||||
R_API bool r_anal_fcn_add_bb(RAnal *anal, RAnalFunction *fcn,
|
||||
ut64 addr, ut64 size,
|
||||
ut64 jump, ut64 fail, int type, R_BORROW RAnalDiff *diff);
|
||||
ut64 jump, ut64 fail, R_BORROW RAnalDiff *diff);
|
||||
R_API bool r_anal_check_fcn(RAnal *anal, ut8 *buf, ut16 bufsz, ut64 addr, ut64 low, ut64 high);
|
||||
R_API void r_anal_fcn_invalidate_read_ahead_cache(void);
|
||||
R_API void r_anal_fcn_check_bp_use(RAnal *anal, RAnalFunction *fcn);
|
||||
@ -1727,7 +1709,6 @@ R_API RList* /*<RAnalRefline>*/ r_anal_reflines_get(RAnal *anal,
|
||||
R_API int r_anal_reflines_middle(RAnal *anal, RList *list, ut64 addr, int len);
|
||||
R_API RAnalRefStr *r_anal_reflines_str(void *core, ut64 addr, int opts);
|
||||
R_API void r_anal_reflines_str_free(RAnalRefStr *refstr);
|
||||
R_API RList *r_anal_reflines_fcn_get(struct r_anal_t *anal, RAnalFunction *fcn, int nlines, int linesout, int linescall);
|
||||
/* TODO move to r_core */
|
||||
R_API void r_anal_var_list_show(RAnal *anal, RAnalFunction *fcn, int kind, int mode, PJ* pj);
|
||||
R_API RList *r_anal_var_list(RAnal *anal, RAnalFunction *fcn, int kind);
|
||||
|
Loading…
Reference in New Issue
Block a user