From 106e2c1234dee278be9a680a5f4207c236c1617a Mon Sep 17 00:00:00 2001 From: Giovanni <561184+wargio@users.noreply.github.com> Date: Tue, 24 Mar 2026 16:11:50 +0800 Subject: [PATCH] Remove `addrbytes` from RzIO which is always 1 and never changes. (#6084) --- librz/arch/asm.c | 7 +++---- librz/arch/fcn.c | 9 ++++----- librz/core/canalysis.c | 3 +-- librz/core/casm.c | 27 +++++++++++-------------- librz/core/cmd/cmd_print.c | 3 +-- librz/core/disasm.c | 40 ++++++++++++++++---------------------- librz/include/rz_io.h | 1 - librz/io/io.c | 1 - librz/main/rz-asm.c | 1 - 9 files changed, 37 insertions(+), 55 deletions(-) diff --git a/librz/arch/asm.c b/librz/arch/asm.c index 16d100c008..d1f0e4ba97 100644 --- a/librz/arch/asm.c +++ b/librz/arch/asm.c @@ -851,9 +851,8 @@ RZ_API RzAsmCode *rz_asm_mdisassemble(RzAsm *a, const ut8 *buf, int len) { RzStrBuf *buf_asm; RzAsmCode *acode; ut64 pc = a->pc; - ut64 idx; - size_t ret; - const size_t addrbytes = a->core ? ((RzCore *)a->core)->io->addrbytes : 1; + ssize_t ret = 0; + ut64 idx = 0; if (!(acode = rz_asm_code_new())) { return NULL; @@ -866,7 +865,7 @@ RZ_API RzAsmCode *rz_asm_mdisassemble(RzAsm *a, const ut8 *buf, int len) { return rz_asm_code_free(acode); } RzAsmOp op = { 0 }; - for (idx = 0; idx + addrbytes <= len; idx += (addrbytes * ret)) { + for (idx = 0; idx < len; idx += ret) { rz_asm_set_pc(a, pc + idx); rz_asm_op_init(&op); ret = rz_asm_disassemble(a, &op, buf + idx, len - idx); diff --git a/librz/arch/fcn.c b/librz/arch/fcn.c index 684a9b30a2..64dc12464b 100644 --- a/librz/arch/fcn.c +++ b/librz/arch/fcn.c @@ -574,7 +574,6 @@ static RzAnalysisBBEndCause run_basic_block_analysis(RzAnalysisTaskItem *item, R ut64 len = RZ_MIN(analysis->opt.bb_max_size, RZ_ANALYSIS_BLOCK_MAX_SIZE); ReadAhead read_ahead_cache = { 0 }; const int continue_after_jump = analysis->opt.afterjmp; - const int addrbytes = analysis->iob.io ? analysis->iob.io->addrbytes : 1; char *last_reg_mov_lea_name = NULL; char *movbasereg = NULL; RzAnalysisBlock *bb = item->block; @@ -690,7 +689,7 @@ static RzAnalysisBBEndCause run_basic_block_analysis(RzAnalysisTaskItem *item, R ut64 movdisp = UT64_MAX; // used by jmptbl when coded as "mov reg, [reg * scale + disp]" ut64 movscale = 0; ut8 buf[32]; // 32 bytes is enough to hold any instruction. - int maxlen = len * addrbytes; + int maxlen = len; if (is_dalvik) { bool skipAnalysis = false; if (!strncmp(fcn->name, "sym.", 4)) { @@ -704,7 +703,7 @@ static RzAnalysisBBEndCause run_basic_block_analysis(RzAnalysisTaskItem *item, R gotoBeach(RZ_ANALYSIS_RET_END); } } - if ((maxlen - (addrbytes * idx)) > MAX_SCAN_SIZE) { + if ((maxlen - (idx)) > MAX_SCAN_SIZE) { // XXX idx is always 0 here, and maxlen comes from amalysis.bb.maxsize. This makes no sense. RZ_LOG_DEBUG("Skipping large memory region during basic block analysis.\n"); maxlen = 0; @@ -721,7 +720,7 @@ static RzAnalysisBBEndCause run_basic_block_analysis(RzAnalysisTaskItem *item, R break; } repeat: - at_delta = addrbytes * idx; + at_delta = idx; at = addr + at_delta; if (rz_cons_is_breaked()) { rz_analysis_task_item_new(analysis, tasks, fcn, bb, at, sp); @@ -883,7 +882,7 @@ static RzAnalysisBBEndCause run_basic_block_analysis(RzAnalysisTaskItem *item, R // But we also already counted this instruction in the // size of the current basic block, so we need to fix that if (delay.adjust) { - rz_analysis_block_set_size(bb, (ut64)addrbytes * (ut64)delay.after); + rz_analysis_block_set_size(bb, (ut64)delay.after); fcn->ninstr--; RZ_LOG_DEBUG("Correct for branch delay @ 0x%08" PFMT64x " bb.addr=0x%08" PFMT64x " corrected.bb=%" PFMT64u " f.uncorr=%" PFMT64u "\n", addr + idx - oplen, bb->addr, bb->size, rz_analysis_function_linear_size(fcn)); diff --git a/librz/core/canalysis.c b/librz/core/canalysis.c index 1bc6cbd94d..7b759e83a2 100644 --- a/librz/core/canalysis.c +++ b/librz/core/canalysis.c @@ -5664,7 +5664,6 @@ RZ_API RZ_OWN RzCoreAnalysisName *rz_core_analysis_name(RZ_NONNULL RzCore *core, static void _analysis_calls(RzCore *core, ut64 addr, ut64 addr_end, bool imports_only) { RzAnalysisOp op = { 0 }; int depth = rz_config_get_i(core->config, "analysis.depth"); - const int addrbytes = core->io->addrbytes; const int bsz = 4096; int bufi = 0; int bufi_max = bsz - 16; @@ -5746,7 +5745,7 @@ static void _analysis_calls(RzCore *core, ut64 addr, ut64 addr_end, bool imports op.size = minop; } addr += op.size; - bufi += addrbytes * op.size; + bufi += op.size; rz_analysis_op_fini(&op); } rz_cons_break_pop(); diff --git a/librz/core/casm.c b/librz/core/casm.c index 5be5444f00..b643c67e93 100644 --- a/librz/core/casm.c +++ b/librz/core/casm.c @@ -317,7 +317,6 @@ RZ_API RzList /**/ *rz_core_asm_strsearch(RzCore *core, const ch int idx, tidx = 0, len = 0; int tokcount, matchcount, count = 0; int matches = 0; - const int addrbytes = core->io->addrbytes; if (!input || !*input) { return NULL; @@ -377,7 +376,7 @@ RZ_API RzList /**/ *rz_core_asm_strsearch(RzCore *core, const ch } (void)rz_io_read_at_mapped(core->io, at, buf, core->blocksize); idx = 0, matchcount = 0; - while (addrbytes * (idx + 1) <= core->blocksize) { + while ((idx + 1) <= core->blocksize) { ut64 addr = at + idx; if (addr > to) { break; @@ -428,8 +427,7 @@ RZ_API RzList /**/ *rz_core_asm_strsearch(RzCore *core, const ch goto beach; } RzAsmOp op = { 0 }; - rz_asm_disassemble(core->rasm, &op, buf + addrbytes * idx, - core->blocksize - addrbytes * idx); + rz_asm_disassemble(core->rasm, &op, buf + idx, core->blocksize - idx); hit->code = rz_str_dup(rz_strbuf_get(&op.buf_asm)); rz_asm_op_fini(&op); rz_analysis_op_fini(&aop); @@ -455,9 +453,7 @@ RZ_API RzList /**/ *rz_core_asm_strsearch(RzCore *core, const ch } else { RzAsmOp op = { 0 }; if (!(len = rz_asm_disassemble( - core->rasm, &op, - buf + addrbytes * idx, - core->blocksize - addrbytes * idx))) { + core->rasm, &op, buf + idx, core->blocksize - idx))) { idx = (matchcount) ? tidx + 1 : idx + 1; matchcount = 0; rz_asm_op_fini(&op); @@ -741,14 +737,13 @@ RZ_API RzList /**/ *rz_core_asm_bwdisassemble(RzCore *core, ut64 ut64 at; ut32 idx = 0, hit_count; int numinstr, asmlen, ii; - const int addrbytes = core->io->addrbytes; RzAsmCode *c; RzList *hits = rz_core_asm_hit_list_new(); if (!hits) { return NULL; } - len = RZ_MIN(len - len % addrbytes, addrbytes * addr); + len = RZ_MIN(len, addr); if (len < 1) { rz_list_free(hits); return NULL; @@ -762,13 +757,13 @@ RZ_API RzList /**/ *rz_core_asm_bwdisassemble(RzCore *core, ut64 free(buf); return NULL; } - if (!rz_io_read_at_mapped(core->io, addr - len / addrbytes, buf, len)) { + if (!rz_io_read_at_mapped(core->io, addr - len, buf, len)) { rz_list_free(hits); free(buf); return NULL; } - for (idx = addrbytes; idx < len; idx += addrbytes) { + for (idx = 1; idx < len; idx++) { if (rz_cons_is_breaked()) { break; } @@ -789,14 +784,14 @@ RZ_API RzList /**/ *rz_core_asm_bwdisassemble(RzCore *core, ut64 break; } } - at = addr - idx / addrbytes; + at = addr - idx; rz_asm_set_pc(core->rasm, at); for (hit_count = 0; hit_count < n; hit_count++) { RzAsmOp op = { 0 }; - int instrlen = rz_asm_disassemble(core->rasm, &op, - buf + len - addrbytes * (addr - at), addrbytes * (addr - at)); - add_hit_to_hits(hits, at, instrlen, true); - at += instrlen; + const size_t size = addr - at; + int dlen = rz_asm_disassemble(core->rasm, &op, buf + len - size, size); + add_hit_to_hits(hits, at, dlen, true); + at += dlen; rz_asm_op_fini(&op); } free(buf); diff --git a/librz/core/cmd/cmd_print.c b/librz/core/cmd/cmd_print.c index b57f8fb916..ef71004fdb 100644 --- a/librz/core/cmd/cmd_print.c +++ b/librz/core/cmd/cmd_print.c @@ -2750,10 +2750,9 @@ static void disassembly_as_table(RzTable *t, RzCore *core, ut64 addr, int n_inst rz_table_set_columnsf(t, "snssssss", "name", "addr", "bytes", "disasm", "comment", "esil", "refs", "xrefs"); const int minopsz = 1; const int options = RZ_ANALYSIS_OP_MASK_BASIC | RZ_ANALYSIS_OP_MASK_HINT | RZ_ANALYSIS_OP_MASK_DISASM | RZ_ANALYSIS_OP_MASK_ESIL; - const int addrbytes = core->io->addrbytes; ut64 offset = addr; ut64 inc = 0; - for (int i = 0, j = 0; rz_disasm_check_end(n_instrs, i, n_bytes, j * addrbytes); i++, offset += inc, j += inc) { + for (int i = 0, j = 0; rz_disasm_check_end(n_instrs, i, n_bytes, j); i++, offset += inc, j += inc) { RzAnalysisOp *op = rz_core_analysis_op(core, offset, options); if (!op || op->size < 1) { i += minopsz; diff --git a/librz/core/disasm.c b/librz/core/disasm.c index 3dd57caa3f..2e2219209a 100644 --- a/librz/core/disasm.c +++ b/librz/core/disasm.c @@ -5162,7 +5162,6 @@ RZ_API int rz_core_print_disasm(RZ_NONNULL RzCore *core, ut64 addr, RZ_NONNULL u bool calc_row_offsets = p->calc_row_offsets; int ret, inc = 0, skip_bytes_flag = 0, skip_bytes_bb = 0, idx = 0; ut8 *nbuf = NULL; - const int addrbytes = core->io->addrbytes; RzConfigHold *rch = rz_config_hold_new(core->config); if (!rch) { @@ -5257,7 +5256,7 @@ toro: ds->nlines = core->blocksize; } rz_cons_break_push(NULL, NULL); - for (idx = ret = 0; addrbytes * idx < len && ds->lines < ds->nlines; idx += inc, ds->index += inc, ds->lines++) { + for (idx = ret = 0; idx < len && ds->lines < ds->nlines; idx += inc, ds->index += inc, ds->lines++) { ds->at = ds->addr + idx; ds->vat = rz_core_pava(core, ds->at); if (rz_cons_is_breaked()) { @@ -5296,7 +5295,7 @@ toro: ds_update_ref_lines(ds); rz_analysis_op_fini(&ds->analysis_op); rz_analysis_op_init(&ds->analysis_op); - rz_analysis_op(core->analysis, &ds->analysis_op, ds->at, buf + addrbytes * idx, (int)(len - addrbytes * idx), DS_ANALYSIS_OP_MASK); + rz_analysis_op(core->analysis, &ds->analysis_op, ds->at, buf + idx, (int)(len - idx), DS_ANALYSIS_OP_MASK); if (ds_must_strip(ds)) { inc = ds->analysis_op.size; // inc = ds->asmop.payload + (ds->asmop.payload % ds->core->rasm->dataalign); @@ -5325,7 +5324,7 @@ toro: } } else { if (idx >= 0) { - ret = ds_disassemble(ds, buf + addrbytes * idx, len - addrbytes * idx); + ret = ds_disassemble(ds, buf + idx, len - idx); if (ret == -31337) { inc = ds->oplen; rz_analysis_op_fini(&ds->analysis_op); @@ -5343,7 +5342,7 @@ toro: if (ds->analysis_op.addr != ds->at) { rz_analysis_op_fini(&ds->analysis_op); rz_analysis_op_init(&ds->analysis_op); - rz_analysis_op(core->analysis, &ds->analysis_op, ds->at, buf + addrbytes * idx, (int)(len - addrbytes * idx), DS_ANALYSIS_OP_MASK); + rz_analysis_op(core->analysis, &ds->analysis_op, ds->at, buf + idx, (int)(len - idx), DS_ANALYSIS_OP_MASK); } if (ret < 1) { rz_strbuf_fini(&ds->analysis_op.esil); @@ -5455,14 +5454,13 @@ toro: ds_print_debuginfo(ds); ret = ds_print_middle(ds, ret); - ds_print_asmop_payload(ds, buf + addrbytes * idx); + ds_print_asmop_payload(ds, buf + idx); if (core->rasm->syntax != RZ_ASM_SYNTAX_INTEL) { RzAsmOp ao = { 0 }; /* disassemble for the vm .. */ int os = core->rasm->syntax; rz_asm_set_syntax(core->rasm, RZ_ASM_SYNTAX_INTEL); rz_asm_op_fini(&ds->asmop); - rz_asm_disassemble(core->rasm, &ao, buf + addrbytes * idx, - len - addrbytes * idx + 5); + rz_asm_disassemble(core->rasm, &ao, buf + idx, len - idx + 5); rz_asm_set_syntax(core->rasm, os); } if (mi_type == RZ_META_TYPE_FORMAT) { @@ -5496,14 +5494,13 @@ toro: ds_print_debuginfo(ds); ret = ds_print_middle(ds, ret); - ds_print_asmop_payload(ds, buf + addrbytes * idx); + ds_print_asmop_payload(ds, buf + idx); if (core->rasm->syntax != RZ_ASM_SYNTAX_INTEL) { RzAsmOp ao = { 0 }; /* disassemble for the vm .. */ int os = core->rasm->syntax; rz_asm_set_syntax(core->rasm, RZ_ASM_SYNTAX_INTEL); rz_asm_op_fini(&ds->asmop); - rz_asm_disassemble(core->rasm, &ao, buf + addrbytes * idx, - len - addrbytes * idx + 5); + rz_asm_disassemble(core->rasm, &ao, buf + idx, len - idx + 5); rz_asm_set_syntax(core->rasm, os); } if (ds->show_bytes_right && ds->show_bytes) { @@ -5614,7 +5611,7 @@ toro: p->calc_row_offsets = calc_row_offsets; /* used by asm.emu */ rz_reg_arena_pop(core->analysis->reg); - return addrbytes * idx; //-ds->lastfail; + return idx; //-ds->lastfail; } /** @@ -5650,7 +5647,6 @@ RZ_API int rz_core_print_disasm_instructions_with_buf(RzCore *core, ut64 address char *tmpopstr; bool hasanalysis = false; bool alloc_buf = !buf; - const size_t addrbytes = buf ? 1 : core->io->addrbytes; int skip_bytes_flag = 0, skip_bytes_bb = 0; // set the parameter equaling 0 to a value that won't affect another parameter @@ -5689,10 +5685,10 @@ RZ_API int rz_core_print_disasm_instructions_with_buf(RzCore *core, ut64 address rz_cons_break_push(NULL, NULL); // build ranges to map addr with bits j = 0; - for (i = 0; rz_disasm_check_end(nb_opcodes, j, nb_bytes, addrbytes * i); i += ret, j++) { + for (i = 0; rz_disasm_check_end(nb_opcodes, j, nb_bytes, i); i += ret, j++) { ds->at = address + i; ds->vat = rz_core_pava(core, ds->at); - int len = nb_bytes - addrbytes * i; + int len = nb_bytes - i; hasanalysis = false; rz_core_seek_arch_bits(core, ds->at); if (rz_cons_is_breaked()) { @@ -5705,7 +5701,7 @@ RZ_API int rz_core_print_disasm_instructions_with_buf(RzCore *core, ut64 address // rz_analysis_get_fcn_in (core->analysis, ds->at, RZ_ANALYSIS_FCN_TYPE_NULL); rz_asm_op_fini(&ds->asmop); ret = rz_asm_disassemble(core->rasm, &ds->asmop, - buf + addrbytes * i, len); + buf + i, len); ds->oplen = ret; skip_bytes_flag = handleMidFlags(core, ds, true); if (ds->midbb) { @@ -5721,7 +5717,7 @@ RZ_API int rz_core_print_disasm_instructions_with_buf(RzCore *core, ut64 address if (!hasanalysis) { // XXX we probably don't need MASK_ALL rz_analysis_op_init(&ds->analysis_op); - rz_analysis_op(core->analysis, &ds->analysis_op, ds->at, buf + addrbytes * i, len, RZ_ANALYSIS_OP_MASK_ALL); + rz_analysis_op(core->analysis, &ds->analysis_op, ds->at, buf + i, len, RZ_ANALYSIS_OP_MASK_ALL); hasanalysis = true; } if (ds_must_strip(ds)) { @@ -6085,7 +6081,6 @@ RZ_API int rz_core_disasm_pdi_with_buf(RzCore *core, ut64 address, ut8 *buf, ut3 bool alloc_buf = !buf; int i = 0, j, ret, err = 0; RzAsmOp asmop = { 0 }; - const size_t addrbytes = buf ? 1 : core->io->addrbytes; // set the parameter equaling 0 to a value that won't affect another parameter if (nb_bytes == 0 && nb_opcodes != 0) { @@ -6125,7 +6120,7 @@ RZ_API int rz_core_disasm_pdi_with_buf(RzCore *core, ut64 address, ut8 *buf, ut3 i = 0; j = 0; RzAnalysisMetaItem *meta = NULL; - for (; rz_disasm_check_end(nb_opcodes, j, nb_bytes, addrbytes * i); j++) { + for (; rz_disasm_check_end(nb_opcodes, j, nb_bytes, i); j++) { if (rz_cons_is_breaked()) { err = 1; break; @@ -6199,8 +6194,7 @@ RZ_API int rz_core_disasm_pdi_with_buf(RzCore *core, ut64 address, ut8 *buf, ut3 } } rz_asm_set_pc(core->rasm, address + i); - ret = rz_asm_disassemble(core->rasm, &asmop, buf + addrbytes * i, - nb_bytes - addrbytes * i); + ret = rz_asm_disassemble(core->rasm, &asmop, buf + i, nb_bytes - i); if (midflags || midbb) { RzDisasmState ds = { .oplen = ret, @@ -6252,7 +6246,7 @@ RZ_API int rz_core_disasm_pdi_with_buf(RzCore *core, ut64 address, ut8 *buf, ut3 char *tmpopstr, *opstr = NULL; rz_analysis_op_init(&analysis_op); rz_analysis_op(core->analysis, &analysis_op, address + i, - buf + addrbytes * i, nb_bytes - addrbytes * i, RZ_ANALYSIS_OP_MASK_ALL); + buf + i, nb_bytes - i, RZ_ANALYSIS_OP_MASK_ALL); tmpopstr = rz_analysis_op_to_string(core->analysis, &analysis_op); if (fmt == 'e') { // pie char *esil = (RZ_STRBUF_SAFEGET(&analysis_op.esil)); @@ -6292,7 +6286,7 @@ RZ_API int rz_core_disasm_pdi_with_buf(RzCore *core, ut64 address, ut8 *buf, ut3 RzAnalysisOp aop = { 0 }; rz_analysis_op_init(&aop); rz_analysis_op(core->analysis, &aop, address + i, - buf + addrbytes * i, nb_bytes - addrbytes * i, RZ_ANALYSIS_OP_MASK_BASIC); + buf + i, nb_bytes - i, RZ_ANALYSIS_OP_MASK_BASIC); RzStrBuf *colored_asm, *bw_str = rz_strbuf_new(asm_str); RzAsmParseParam *param = rz_asm_get_parse_param(core->analysis->reg, aop.type); colored_asm = rz_asm_colorize_asm_str(bw_str, core->print, param, asmop.asm_toks); diff --git a/librz/include/rz_io.h b/librz/include/rz_io.h index 30efcf91fd..61e798db3a 100644 --- a/librz/include/rz_io.h +++ b/librz/include/rz_io.h @@ -63,7 +63,6 @@ typedef struct rz_io_t { int va; // all of this config stuff must be in 1 int int ff; int Oxff; - size_t addrbytes; int aslr; int autofd; int cached; diff --git a/librz/io/io.c b/librz/io/io.c index 95a1c0acec..40dd1a825c 100644 --- a/librz/io/io.c +++ b/librz/io/io.c @@ -113,7 +113,6 @@ RZ_API RzIO *rz_io_new(void) { RZ_API RzIO *rz_io_init(RzIO *io) { rz_return_val_if_fail(io, NULL); - io->addrbytes = 1; rz_io_desc_init(io); rz_skyline_init(&io->map_skyline); rz_io_map_init(io); diff --git a/librz/main/rz-asm.c b/librz/main/rz-asm.c index 283ac3c085..90b66ef0e7 100644 --- a/librz/main/rz-asm.c +++ b/librz/main/rz-asm.c @@ -568,7 +568,6 @@ RZ_API int rz_main_rz_asm(int argc, const char *argv[]) { RzAsmState *as = __as_new(); - // TODO set addrbytes char *rz_arch = rz_sys_getenv("RZ_ARCH"); if (rz_arch) { arch = rz_arch;