Skip to content

Commit

Permalink
Remove static and global varibles in disasm.c
Browse files Browse the repository at this point in the history
  • Loading branch information
XVilka committed Jan 3, 2024
1 parent 97d3367 commit 2108ffa
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 10 deletions.
15 changes: 5 additions & 10 deletions librz/core/disasm.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
#define DS_ANALYSIS_OP_MASK (RZ_ANALYSIS_OP_MASK_BASIC | RZ_ANALYSIS_OP_MASK_ESIL | \
RZ_ANALYSIS_OP_MASK_VAL | (ds->show_cmt_il ? RZ_ANALYSIS_OP_MASK_IL : 0))

// ugly globals but meh
static ut64 emustack_min = 0LL;
static ut64 emustack_max = 0LL;
#define ESILISTATE core->analysis->esilinterstate

static const ut8 MAX_OPSIZE = 16;
static const ut8 MIN_OPSIZE = 1;
Expand Down Expand Up @@ -671,8 +669,8 @@ static RzDisasmState *ds_init(RzCore *core) {
const char *uri = "malloc://32K";
ut64 size = rz_num_get(core->num, "32K");
ut64 addr = rz_reg_getv(core->analysis->reg, "SP") - (size / 2);
emustack_min = addr;
emustack_max = addr + size;
ESILISTATE->emustack_min = addr;
ESILISTATE->emustack_max = addr + size;
ds->stackFd = rz_io_fd_open(core->io, uri, RZ_PERM_RW, 0);
RzIOMap *map = rz_io_map_add(core->io, ds->stackFd, RZ_PERM_RW, 0LL, addr, size);
if (!map) {
Expand Down Expand Up @@ -798,8 +796,6 @@ static RzDisasmState *ds_init(RzCore *core) {
return ds;
}

static ut64 lastaddr = UT64_MAX;

static void ds_reflines_fini(RzDisasmState *ds) {
RzAnalysis *analysis = ds->core->analysis;
rz_list_free(analysis->reflines);
Expand All @@ -812,8 +808,6 @@ static void ds_reflines_fini(RzDisasmState *ds) {
static void ds_reflines_init(RzDisasmState *ds) {
RzAnalysis *analysis = ds->core->analysis;

lastaddr = UT64_MAX;

// refline info is needed when it is shown as ascii,
// or returned as part of a json or C struct representation.
if (ds->show_lines_bb || ds->vec || ds->pj) {
Expand Down Expand Up @@ -4248,7 +4242,8 @@ static int mymemwrite1(RzAnalysisEsil *esil, ut64 addr, const ut8 *buf, int len)
}

static int mymemwrite2(RzAnalysisEsil *esil, ut64 addr, const ut8 *buf, int len) {
return (addr >= emustack_min && addr < emustack_max);
return (addr >= esil->analysis->esilinterstate->emustack_min
&& addr < esil->analysis->esilinterstate->emustack_max);
}

static char *ssa_get(RzAnalysisEsil *esil, const char *reg) {
Expand Down
2 changes: 2 additions & 0 deletions librz/include/rz_analysis.h
Original file line number Diff line number Diff line change
Expand Up @@ -1185,6 +1185,8 @@ typedef struct rz_analysis_esil_inter_state_t {
bool analysis_stop;
ut64 last_read;
ut64 last_data;
ut64 emustack_min;
ut64 emustack_max;
} RzAnalysisEsilInterState;

/* Alias RegChange and MemChange */
Expand Down

0 comments on commit 2108ffa

Please sign in to comment.