From 6deb7c74ffc73179c7974314475fc70cd094bb56 Mon Sep 17 00:00:00 2001 From: wargio Date: Fri, 8 Nov 2024 12:45:49 +0800 Subject: [PATCH] Remove dead code --- librz/arch/esil/esil.c | 127 ++----------- librz/arch/esil/esil_interrupt.c | 6 - librz/arch/fcn.c | 37 ++-- librz/arch/isa/arm/arm_esil32.c | 26 ++- librz/arch/isa/arm/arm_esil64.c | 12 -- librz/arch/isa/arm/armass.c | 141 --------------- librz/arch/isa/avr/assembler.c | 48 +++-- librz/arch/isa/tms320/c55x_plus/hashtable.c | 24 ++- librz/arch/p/analysis/analysis_mips_cs.c | 39 ---- librz/arch/p/analysis/analysis_riscv_cs.c | 27 --- librz/arch/p/analysis/analysis_x86_cs.c | 36 +--- librz/arch/p/asm/asm_lm32.c | 18 -- librz/arch/p/asm/asm_riscv_cs.c | 8 +- librz/arch/p/asm/asm_xap.c | 7 +- librz/bin/format/coff/coff.c | 15 +- librz/bin/format/mach0/mach0.c | 17 -- librz/bin/format/mdmp/mdmp.c | 6 - librz/bin/format/objc/mach0_classes.c | 57 ------ librz/bin/format/omf/omf.c | 6 +- librz/bin/format/pe/pe_section.c | 74 ++++---- librz/bin/format/wasm/wasm.c | 43 ----- librz/bin/p/bin_coff.c | 19 +- librz/bin/p/bin_menuet.c | 79 ++++---- librz/bin/p/bin_pebble.c | 14 -- librz/bin/p/bin_sfc.c | 14 -- librz/bin/p/bin_symbols.c | 69 ++++--- librz/bin/p/bin_xtr_pemixed.c | 2 +- librz/cons/cons.c | 8 +- librz/cons/cutf8.c | 7 +- librz/cons/input.c | 6 +- librz/core/cconfig.c | 6 - librz/core/cmd/cmd_magic.c | 4 - librz/core/cmd/cmd_print.c | 6 - librz/core/cmd/cmd_search.c | 86 +-------- librz/core/cmd/cmd_seek.c | 5 - librz/core/core.c | 9 +- librz/core/linux_heap_glibc.c | 6 - librz/core/rtr.c | 18 +- librz/core/rtr_shell.c | 8 +- librz/core/tui/visual.c | 21 --- librz/crypto/p/crypto_blowfish.c | 17 -- librz/crypto/p/crypto_cps2.c | 25 --- librz/debug/debug.c | 6 - librz/debug/p/debug_gdb.c | 9 - librz/debug/p/debug_io.c | 7 - librz/debug/p/native/maps/darwin.c | 157 ---------------- librz/debug/p/native/xnu/xnu_debug.c | 36 ---- librz/debug/pid.c | 18 -- librz/egg/egg_lang.c | 77 +------- librz/egg/emit_arm.c | 7 +- librz/egg/emit_trace.c | 7 +- librz/egg/emit_x86.c | 32 ---- librz/search/search.c | 188 ++++++++------------ 53 files changed, 302 insertions(+), 1445 deletions(-) diff --git a/librz/arch/esil/esil.c b/librz/arch/esil/esil.c index a9a7c327db2..8e280eedfef 100644 --- a/librz/arch/esil/esil.c +++ b/librz/arch/esil/esil.c @@ -867,62 +867,6 @@ static bool esil_xoreq(RzAnalysisEsil *esil) { return ret; } -#if 0 -static int esil_interrupt_linux_i386(RzAnalysisEsil *esil) { //move this into a plugin - ut32 sn, ret = 0; - char *usn = rz_analysis_esil_pop (esil); - if (usn) { - sn = (ut32) rz_num_get (NULL, usn); - } else sn = 0x80; - - if (sn == 3) { - // trap - esil->trap = RZ_ANALYSIS_TRAP_BREAKPOINT; - esil->trap_code = 3; - return -1; - } - - if (sn != 0x80) { - RZ_LOG_ERROR("Interrupt 0x%x not handled.\n", sn); - esil->trap = RZ_ANALYSIS_TRAP_UNHANDLED; - esil->trap_code = sn; - return -1; - } -#undef r -#define r(x) rz_reg_getv(esil->analysis->reg, "##x##") -#undef rs -#define rs(x, y) rz_reg_setv(esil->analysis->reg, "##x##", y) - switch (r(eax)) { - case 1: - printf ("exit(%d)\n", (int)r(ebx)); - rs(eax, -1); - // never return. stop execution somehow, throw an exception - break; - case 3: - ret = r(edx); - printf ("ret:%d = read(fd:%"PFMT64d", ptr:0x%08"PFMT64x", len:%"PFMT64d")\n", - (int)ret, r(ebx), r(ecx), r(edx)); - rs(eax, ret); - break; - case 4: - ret = r(edx); - printf ("ret:%d = write(fd:%"PFMT64d", ptr:0x%08"PFMT64x", len:%"PFMT64d")\n", - (int)ret, r(ebx), r(ecx), r(edx)); - rs(eax, ret); - break; - case 5: - ret = -1; - printf ("fd:%d = open(file:0x%08"PFMT64x", mode:%"PFMT64d", perm:%"PFMT64d")\n", - (int)ret, r(ebx), r(ecx), r(edx)); - rs(eax, ret); - break; - } -#undef r -#undef rs - return 0; -} -#endif - static bool esil_trap(RzAnalysisEsil *esil) { ut64 s, d; if (popRN(esil, &s) && popRN(esil, &d)) { @@ -980,64 +924,25 @@ static bool esil_cmp(RzAnalysisEsil *esil) { return ret; } -#if 0 -x86 documentation: -CF - carry flag -- Set on high-order bit carry or borrow; cleared otherwise - num>>63 -PF - parity flag - (num&0xff) - Set if low-order eight bits of result contain an even number of "1" bits; cleared otherwise -ZF - zero flags - Set if result is zero; cleared otherwise - zf = num?0:1; -SF - sign flag - Set equal to high-order bit of result (0 if positive 1 if negative) - sf = ((st64)num)<0)?1:0; -OF - overflow flag - if (a>0&&b>0 && (a+b)<0) - Set if result is too large a positive number or too small a negative number (excluding sign bit) to fit in destination operand; cleared otherwise - -JBE: CF = 1 || ZF = 1 - -#endif - /* - * Expects a string in the stack. Each char of the string represents a CPU flag. - * Those relations are associated by the CPU itself and are used to move values - * from the internal ESIL into the RzReg instance. - * - * For example: - * zco,?= # update zf, cf and of + * x86 documentation: + * CF - carry flag -- Set on high-order bit carry or borrow; cleared otherwise + * num>>63 + * PF - parity flag + * (num&0xff) + * Set if low-order eight bits of result contain an even number of "1" bits; cleared otherwise + * ZF - zero flags + * Set if result is zero; cleared otherwise + * zf = num?0:1; + * SF - sign flag + * Set equal to high-order bit of result (0 if positive 1 if negative) + * sf = ((st64)num)<0)?1:0; + * OF - overflow flag + * if (a>0&&b>0 && (a+b)<0) + * Set if result is too large a positive number or too small a negative number (excluding sign bit) to fit in destination operand; cleared otherwise * - * If we want to update the esil value of a specific flag we use the =? command - * - * zf,z,=? # esil[zf] = rz_reg[zf] - * - * Defining new cpu flags + * JBE: CF = 1 || ZF = 1 */ -#if 0 -static int esil_ifset(RzAnalysisEsil *esil) { - char *s, *src = rz_analysis_esil_pop (esil); - for (s=src; *s; s++) { - switch (*s) { - case 'z': - rz_analysis_esil_reg_write (esil, "zf", RZ_BIT_CHK(&esil->flags, FLG(ZERO))); - break; - case 'c': - rz_analysis_esil_reg_write (esil, "cf", RZ_BIT_CHK(&esil->flags, FLG(CARRY))); - break; - case 'o': - rz_analysis_esil_reg_write (esil, "of", RZ_BIT_CHK(&esil->flags, FLG(OVERFLOW))); - break; - case 'p': - rz_analysis_esil_reg_write (esil, "pf", RZ_BIT_CHK(&esil->flags, FLG(PARITY))); - break; - } - } - free (src); - return 0; -} -#endif static bool esil_if(RzAnalysisEsil *esil) { bool ret = false; diff --git a/librz/arch/esil/esil_interrupt.c b/librz/arch/esil/esil_interrupt.c index b36750c2fcf..fb40e64cfe5 100644 --- a/librz/arch/esil/esil_interrupt.c +++ b/librz/arch/esil/esil_interrupt.c @@ -58,12 +58,6 @@ RZ_API int rz_analysis_esil_fire_interrupt(RzAnalysisEsil *esil, ut32 intr_num) return false; } RzAnalysisEsilInterrupt *intr = ht_up_find(esil->interrupts, intr_num, NULL); -#if 0 - // we don't want this warning - if (!intr) { - RZ_LOG_WARN("no interrupt handler registered for 0x%x\n", intr_num); - } -#endif return (intr && intr->handler && intr->handler->cb) ? intr->handler->cb(esil, intr_num, intr->user) : false; } diff --git a/librz/arch/fcn.c b/librz/arch/fcn.c index 72097bd484b..87f54c94582 100644 --- a/librz/arch/fcn.c +++ b/librz/arch/fcn.c @@ -227,14 +227,7 @@ static bool is_delta_pointer_table(ReadAhead *ra, RzAnalysis *analysis, ut64 add *casetbl_addr += omov_aop.disp; } } -#if 0 - // required for the last jmptbl.. but seems to work without it and breaks other tests - if (mov_aop.type && mov_aop.ptr) { - *jmptbl_addr += mov_aop.ptr; - // absjmptbl - lea_ptr = mov_aop.ptr; - } -#endif + /* check if jump table contains valid deltas */ read_ahead(ra, analysis, *jmptbl_addr, (ut8 *)&jmptbl, 64); for (i = 0; i < 3; i++) { @@ -479,21 +472,19 @@ static const char *retpoline_reg(RzAnalysis *analysis, ut64 addr) { return thunk + strlen(token); } } -#if 0 -// TODO: implement following code analysis check for stripped binaries: -// 1) op(addr).type == CALL -// 2) call_dest = op(addr).addr -// 3) op(call_dest).type == STORE -// 4) op(call_dest + op(call_dest).size).type == RET -[0x00000a65]> pid 6 -0x00000a65 sym.__x86_indirect_thunk_rax: -0x00000a65 .------- e807000000 call 0xa71 -0x00000a6a | f390 pause -0x00000a6c | 0faee8 lfence -0x00000a6f | ebf9 jmp 0xa6a -0x00000a71 `----> 48890424 mov qword [rsp], rax -0x00000a75 c3 ret -#endif + // TODO: implement following code analysis check for stripped binaries: + // 1) op(addr).type == CALL + // 2) call_dest = op(addr).addr + // 3) op(call_dest).type == STORE + // 4) op(call_dest + op(call_dest).size).type == RET + // [0x00000a65]> pid 6 + // 0x00000a65 sym.__x86_indirect_thunk_rax: + // 0x00000a65 .------- e807000000 call 0xa71 + // 0x00000a6a | f390 pause + // 0x00000a6c | 0faee8 lfence + // 0x00000a6f | ebf9 jmp 0xa6a + // 0x00000a71 `----> 48890424 mov qword [rsp], rax + // 0x00000a75 c3 ret return NULL; } diff --git a/librz/arch/isa/arm/arm_esil32.c b/librz/arch/isa/arm/arm_esil32.c index 2399827765d..bd79e4d043c 100644 --- a/librz/arch/isa/arm/arm_esil32.c +++ b/librz/arch/isa/arm/arm_esil32.c @@ -380,16 +380,16 @@ RZ_IPI int rz_arm_cs_analysis_op_32_esil(RzAnalysis *a, RzAnalysisOp *op, ut64 a rz_strbuf_setf(&op->esil, "%s,$", ARG(0)); break; case ARM_INS_PUSH: -#if 0 -PUSH { r4, r5, r6, r7, lr } -4,sp,-=,lr,sp,=[4], -4,sp,-=,r7,sp,=[4], -4,sp,-=,r6,sp,=[4], -4,sp,-=,r5,sp,=[4], -4,sp,-=,r4,sp,=[4] - -20,sp,-=,lr,r7,r6,r5,r4,5,sp,=[*] -#endif + /* + * PUSH { r4, r5, r6, r7, lr } + * 4,sp,-=,lr,sp,=[4], + * 4,sp,-=,r7,sp,=[4], + * 4,sp,-=,r6,sp,=[4], + * 4,sp,-=,r5,sp,=[4], + * 4,sp,-=,r4,sp,=[4] + * + * 20,sp,-=,lr,r7,r6,r5,r4,5,sp,=[*] + */ rz_strbuf_appendf(&op->esil, "%d,sp,-=,", 4 * insn->detail->arm.op_count); for (i = insn->detail->arm.op_count; i > 0; i--) { @@ -485,10 +485,8 @@ PUSH { r4, r5, r6, r7, lr } } break; case ARM_INS_POP: -#if 0 -POP { r4,r5, r6} -r6,r5,r4,3,sp,[*],12,sp,+= -#endif + // POP { r4,r5, r6} + // r6,r5,r4,3,sp,[*],12,sp,+= for (i = insn->detail->arm.op_count; i > 0; i--) { rz_strbuf_appendf(&op->esil, "%s,", REG(i - 1)); } diff --git a/librz/arch/isa/arm/arm_esil64.c b/librz/arch/isa/arm/arm_esil64.c index 183c48cdb1b..4cfd8b7f6a7 100644 --- a/librz/arch/isa/arm/arm_esil64.c +++ b/librz/arch/isa/arm/arm_esil64.c @@ -417,18 +417,6 @@ RZ_IPI int rz_arm_cs_analysis_op_64_esil(RzAnalysis *a, RzAnalysisOp *op, ut64 a const char *r0 = REG64(0); const char *r1 = REG64(1); int size = REGSIZE64(1); -#if 0 - rz_strbuf_setf (&op->esil, - "0,%s,=," // dst = 0 - "%d," // initial counter = size - "DUP," // counter: size -> 0 (repeat here) - "DUP,1,SWAP,-,8,*," // counter to bits in source - "DUP,0xff,<<,%s,&,>>," // src byte moved to LSB - "SWAP,%d,-,8,*," // invert counter, calc dst bit - "SWAP,<<,%s,|=," // shift left to there and insert - "4,REPEAT", // goto 5th instruction - r0, size, r1, size, r0); -#endif if (size == 8) { rz_strbuf_setf(&op->esil, "56,0xff,%s,&,<<,tmp,=," diff --git a/librz/arch/isa/arm/armass.c b/librz/arch/isa/arm/armass.c index 20207043740..9e6bb02fce2 100644 --- a/librz/arch/isa/arm/armass.c +++ b/librz/arch/isa/arm/armass.c @@ -6228,144 +6228,3 @@ ut32 armass_assemble(const char *str, ut64 off, int thumb) { } return aop.o; } - -#ifdef MAIN -void thisplay(const char *str) { - char cmd[32]; - int op = armass_assemble(str, 0x1000, 1); - printf("[%04x] %s\n", op, str); - snprintf(cmd, sizeof(cmd), "rz-asm -d -b 16 -a arm %04x", op); - system(cmd); -} - -void display(const char *str) { - char cmd[32]; - int op = armass_assemble(str, 0x1000, 0); - printf("[%08x] %s\n", op, str); - snprintf(cmd, sizeof(cmd), "rz-asm -d -a arm %08x", op); - system(cmd); -} - -int main() { - thisplay("ldmia r1!, {r3, r4, r5}"); - thisplay("stmia r1!, {r3, r4, r5}"); - thisplay("bkpt 12"); - return 0; - thisplay("sub r1, r2, 0"); - thisplay("sub r1, r2, 4"); - thisplay("sub r1, r2, 5"); - thisplay("sub r1, r2, 7"); - thisplay("sub r3, 44"); - return 0; -#if 0 - thisplay("mov r0, 11"); - thisplay("mov r0, r2"); - thisplay("mov r1, r4"); - thisplay("cmp r1, r2"); - thisplay("cmp r3, 44"); - thisplay("nop"); - thisplay("svc 15"); - thisplay("add r1, r2"); - thisplay("add r3, 44"); - thisplay("sub r1, r2, 3"); - thisplay("sub r3, 44"); - thisplay("tst r3,r4"); - thisplay("bx r3"); - thisplay("b 33"); - thisplay("b 0"); - thisplay("bne 44"); - thisplay("and r2,r3"); -#endif - // INVALID thisplay("ldr r1, [pc, r2]"); - // INVALID thisplay("ldr r1, [sp, r2]"); -#if 0 - thisplay("ldr r1, [pc, 12]"); - thisplay("ldr r1, [sp, 24]"); - thisplay("ldr r1, [r2, r3]"); -#endif - // INVALID thisplay("str r1, [pc, 22]"); - // INVALID thisplay("str r1, [pc, r2]"); - // INVALID thisplay("str r1, [sp, r2]"); -#if 0 - 0: 8991 ldrh r1, [r2, #12] - 2: 7b11 ldrb r1, [r2, #12] - 4: 8191 strh r1, [r2, #12] - 6: 7311 strb r1, [r2, #12] -#endif - thisplay("ldrh r1, [r2, 8]"); // aligned to 4 - thisplay("ldrh r1, [r3, 8]"); // aligned to 4 - thisplay("ldrh r1, [r4, 16]"); // aligned to 4 - thisplay("ldrh r1, [r2, 32]"); // aligned to 4 - thisplay("ldrb r1, [r2, 20]"); // aligned to 4 - thisplay("strh r1, [r2, 20]"); // aligned to 4 - thisplay("strb r1, [r2, 20]"); // aligned to 4 - thisplay("str r1, [sp, 20]"); // aligned to 4 - thisplay("str r1, [r2, 12]"); // OK - thisplay("str r1, [r2, r3]"); - return 0; -#if 0 - display("mov r0, 33"); - display("mov r1, 33"); - display("movne r0, 33"); - display("tst r0, r1, lsl #2"); - display("svc 0x80"); - display("sub r3, r1, r2"); - display("add r0, r1, r2"); - display("mov fp, 0"); - display("pop {pc}"); - display("pop {r3}"); - display("bx r1"); - display("bx r3"); - display("bx pc"); - display("blx fp"); - display("pop {pc}"); - display("add lr, pc, lr"); - display("adds r3, #8"); - display("adds r3, r2, #8"); - display("subs r2, #1"); - display("cmp r0, r4"); - display("cmp r7, pc"); - display("cmp r1, r3"); - display("mov pc, 44"); - display("mov pc, r3"); - display("push {pc}"); - display("pop {pc}"); - display("nop"); - display("ldr r1, [r2, 33]"); - display("ldr r1, [r2, r3]"); - display("ldr r3, [r4, r6]"); - display("str r1, [pc, 33]"); - display("str r1, [pc], 2"); - display("str r1, [pc, 3]"); - display("str r1, [pc, r4]"); - display("bx r3"); - display("bcc 33"); - display("blx r3"); - display("bne 0x1200"); - display("str r0, [r1]"); - display("push {fp,lr}"); - display("pop {fp,lr}"); - display("pop {pc}"); -#endif - - // 10ab4: 00047e30 andeq r7, r4, r0, lsr lr - // 10ab8: 00036e70 andeq r6, r3, r0, ror lr - - display("andeq r7, r4, r0, lsr lr"); - display("andeq r6, r3, r0, ror lr"); - // c4: e8bd80f0 pop {r4, r5, r6, r7, pc} - display("pop {r4,r5,r6,r7,pc}"); - -#if 0 - display("blx r1"); - display("blx 0x8048"); -#endif - -#if 0 - display("b 0x123"); - display("bl 0x123"); - display("blt 0x123"); // XXX: not supported -#endif - return 0; -} -#endif diff --git a/librz/arch/isa/avr/assembler.c b/librz/arch/isa/avr/assembler.c index 2a16eb36939..da7e9c81ff0 100644 --- a/librz/arch/isa/avr/assembler.c +++ b/librz/arch/isa/avr/assembler.c @@ -507,24 +507,22 @@ static ut32 avr_lds(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc parse_register_or_error(Rd, tokens[1]); parse_unsigned_or_error(k, tokens[2], 0xFFFF); -#if 0 // The STS (16-bit) and LDS (16-bit) instructions only exist in the reduced AVR cores. // This includes only the ATtiny4/5/9/10 family, and the ATtiny20/40 family. // They also lack some features like the lack of CPU registers R0 to R15. // On rizin these platforms are not supported, therefore this code is commented, but works as intended. - if (k <= 127 && Rd >= 16) { - /* lds Rd, k | 16 <= d <= 31 | 0 <= k <= 127 */ - /* 10100kkkddddkkkk */ - cbins = 0xA000; - Rd -= 16; - cbins |= k & 0x000F; - cbins |= ((k << 4) & 0x0700); - cbins |= ((Rd << 4) & 0x00F0); + // if (k <= 127 && Rd >= 16) { + // /* lds Rd, k | 16 <= d <= 31 | 0 <= k <= 127 */ + // /* 10100kkkddddkkkk */ + // cbins = 0xA000; + // Rd -= 16; + // cbins |= k & 0x000F; + // cbins |= ((k << 4) & 0x0700); + // cbins |= ((Rd << 4) & 0x00F0); + // auto_write16(data, cbins, be); + // return 2; + // } - auto_write16(data, cbins, be); - return 2; - } -#endif /* lds Rd, k | 0 <= d <= 31 | 0 <= k <= 0xFFFF */ /* 1001000ddddd0000 kkkkkkkkkkkkkkkk */ cbins = 0x9000; @@ -793,24 +791,22 @@ static ut32 avr_sts(ut16 cbins, cchar **tokens, ut32 ntokens, ut8 *data, ut64 pc parse_unsigned_or_error(k, tokens[1], 0xFFFF); parse_register_or_error(Rr, tokens[2]); -#if 0 // The STS (16-bit) and LDS (16-bit) instructions only exist in the reduced AVR cores. // This includes only the ATtiny4/5/9/10 family, and the ATtiny20/40 family. // They also lack some features like the lack of CPU registers R0 to R15. // On rizin these platforms are not supported, therefore this code is commented, but works as intended. - if (k <= 127 && Rr >= 16) { - /* sts k, Rr | 16 <= d <= 31 | 0 <= k <= 127 */ - /* 10101kkkddddkkkk */ - cbins = 0xA800; - Rr -= 16; - cbins |= k & 0x000F; - cbins |= ((k << 4) & 0x0700); - cbins |= ((Rr << 4) & 0x00F0); + // if (k <= 127 && Rr >= 16) { + // /* sts k, Rr | 16 <= d <= 31 | 0 <= k <= 127 */ + // /* 10101kkkddddkkkk */ + // cbins = 0xA800; + // Rr -= 16; + // cbins |= k & 0x000F; + // cbins |= ((k << 4) & 0x0700); + // cbins |= ((Rr << 4) & 0x00F0); + // auto_write16(data, cbins, be); + // return 2; + // } - auto_write16(data, cbins, be); - return 2; - } -#endif /* sts k, Rr | 0 <= d <= 31 | 0 <= k <= 0xFFFF */ /* 1001001ddddd0000 kkkkkkkkkkkkkkkk */ cbins = 0x9200; diff --git a/librz/arch/isa/tms320/c55x_plus/hashtable.c b/librz/arch/isa/tms320/c55x_plus/hashtable.c index f868cdc82de..7abc8abf67f 100644 --- a/librz/arch/isa/tms320/c55x_plus/hashtable.c +++ b/librz/arch/isa/tms320/c55x_plus/hashtable.c @@ -443,24 +443,22 @@ st32 get_hashfunc_10(st32 arg1, st32 arg2) { } st32 get_hashfunc_11(st32 arg1, st32 arg2) { -#if 0 // The following code is wrong because it will always produce 244 // since `hash_const_05` is always 0 and as result it will always // jump into the else scope. // The code is kept because this is the product of RE. - st32 result; - if ((ut32)hash_const_05 & arg2) { - if (((ut32)hash_const_05 & arg2) == 524288) { - result = 460; - } else { - result = arg1; - } - } else { - result = 244; - } - return result; -#endif + // st32 result; + // if ((ut32)hash_const_05 & arg2) { + // if (((ut32)hash_const_05 & arg2) == 524288) { + // result = 460; + // } else { + // result = arg1; + // } + // } else { + // result = 244; + // } + // return result; return 244; } diff --git a/librz/arch/p/analysis/analysis_mips_cs.c b/librz/arch/p/analysis/analysis_mips_cs.c index bf230eb28dc..ed64921ff8d 100644 --- a/librz/arch/p/analysis/analysis_mips_cs.c +++ b/librz/arch/p/analysis/analysis_mips_cs.c @@ -592,18 +592,6 @@ static int analyze_op_esil(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 rz_strbuf_appendf(&op->esil, "%s,hi,=", REG(0)); ES_SIGN32_64("hi"); break; -#if 0 - // could not test div - case MIPS_INS_DIV: - case MIPS_INS_DIVU: - case MIPS_INS_DDIV: - case MIPS_INS_DDIVU: - PROTECT_ZERO () { - // 32 bit needs sign extend - rz_strbuf_appendf (&op->esil, "%s,%s,/,lo,=,%s,%s,%%,hi,=", REG(1), REG(0), REG(1), REG(0)); - } - break; -#endif default: return -1; } @@ -681,33 +669,6 @@ static void op_fillval(RzAnalysis *analysis, RzAnalysisOp *op, csh *handle, cs_i } break; case RZ_ANALYSIS_OP_TYPE_DIV: // UDIV -#if 0 -capstone bug ------------- - $ r2 -a mips -e cfg.bigendian=1 -c "wx 0083001b" - - // should be 3 regs, right? - [0x00000000]> aoj~{} - [ - { - "opcode": "divu zero, a0, v1", - "disasm": "divu zero, a0, v1", - "mnemonic": "divu", - "sign": false, - "prefix": 0, - "id": 192, - "opex": { - "operands": [ - { - "type": "reg", - "value": "a0" - }, - { - "type": "reg", - "value": "v1" - } - ] - }, -#endif if (OPERAND(0).type == MIPS_OP_REG && OPERAND(1).type == MIPS_OP_REG && OPERAND(2).type == MIPS_OP_REG) { SET_SRC_DST_3_REGS(op); } else if (OPERAND(0).type == MIPS_OP_REG && OPERAND(1).type == MIPS_OP_REG) { diff --git a/librz/arch/p/analysis/analysis_riscv_cs.c b/librz/arch/p/analysis/analysis_riscv_cs.c index f426461edef..23b74968ea2 100644 --- a/librz/arch/p/analysis/analysis_riscv_cs.c +++ b/librz/arch/p/analysis/analysis_riscv_cs.c @@ -269,33 +269,6 @@ static void op_fillval(RzAnalysis *analysis, RzAnalysisOp *op, csh *handle, cs_i SET_SRC_DST_3_REG_OR_IMM(op); break; case RZ_ANALYSIS_OP_TYPE_DIV: // UDIV -#if 0 -capstone bug ------------- - $ rizin -a riscv -e cfg.bigendian=1 -c "wx 0083001b" - - // should be 3 regs, right? - [0x00000000]> aoj~{} - [ - { - "opcode": "divu zero, a0, v1", - "disasm": "divu zero, a0, v1", - "mnemonic": "divu", - "sign": false, - "prefix": 0, - "id": 192, - "opex": { - "operands": [ - { - "type": "reg", - "value": "a0" - }, - { - "type": "reg", - "value": "v1" - } - ] - }, -#endif if (OPERAND(0).type == RISCV_OP_REG && OPERAND(1).type == RISCV_OP_REG && OPERAND(2).type == RISCV_OP_REG) { SET_SRC_DST_3_REGS(op); } else if (OPERAND(0).type == RISCV_OP_REG && OPERAND(1).type == RISCV_OP_REG) { diff --git a/librz/arch/p/analysis/analysis_x86_cs.c b/librz/arch/p/analysis/analysis_x86_cs.c index 14f0924b99a..dc326ab33a7 100644 --- a/librz/arch/p/analysis/analysis_x86_cs.c +++ b/librz/arch/p/analysis/analysis_x86_cs.c @@ -7,14 +7,12 @@ #include #include "x86/x86_il.h" -#if 0 -CYCLES: -====== -register access = 1 -memory access = 2 -jump = 3 -call = 4 -#endif +// CYCLES: +// ====== +// register access = 1 +// memory access = 2 +// jump = 3 +// call = 4 #define CYCLE_REG 0 #define CYCLE_MEM 1 @@ -867,28 +865,6 @@ static void anop_esil(RzAnalysis *a, RzAnalysisOp *op, ut64 addr, const ut8 *buf case X86_INS_SAR: // TODO: Set CF. See case X86_INS_SHL for more details. { -#if 0 - ut64 val = 0; - switch (gop.insn->detail->x86.operands[0].size) { - case 1: - val = 0x80; - break; - case 2: - val = 0x8000; - break; - case 4: - val = 0x80000000; - break; - case 8: - val = 0x8000000000000000; - break; - default: - val = 0x80; - } - src = getarg (&gop, 1, 0, NULL, SRC_AR); - dst = getarg (&gop, 0, 0, NULL, DST_AR); - esilprintf (op, "%s,1,%s,>>,0x%"PFMT64x",%s,&,|,%s,=,1,%s,&,cf,=,1,REPEAT", src, dst, val, dst, dst, dst); -#endif ut32 bitsize; src = getarg(a, &gop, 1, 0, NULL, SRC_AR, NULL); dst_r = getarg(a, &gop, 0, 0, NULL, DST_R_AR, NULL); diff --git a/librz/arch/p/asm/asm_lm32.c b/librz/arch/p/asm/asm_lm32.c index dcdb1e0dd42..e095b820e1a 100644 --- a/librz/arch/p/asm/asm_lm32.c +++ b/librz/arch/p/asm/asm_lm32.c @@ -408,24 +408,6 @@ static int rz_asm_lm32_stringify(RzAsmLm32Instruction *instr, char *str) { return 0; } -#if 0 - -static int rz_asm_lm32_destringify(const char *string, RzAsmLm32Instruction *instr) { - //TODO - return -1; -} - -static int rz_asm_lm32_encode(RzAsmLm32Instruction *instr, ut32 *val) { - //TODO - return -1; -} - -static int assemble(RzAsm *a, RzAsmOp *ao, const char *str) { - //TODO - return -1; -} -#endif - static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { RzAsmLm32Instruction instr = { 0 }; instr.value = buf[0] << 24 | buf[1] << 16 | buf[2] << 8 | buf[3]; diff --git a/librz/arch/p/asm/asm_riscv_cs.c b/librz/arch/p/asm/asm_riscv_cs.c index edf990ed1ca..964c6c79847 100644 --- a/librz/arch/p/asm/asm_riscv_cs.c +++ b/librz/arch/p/asm/asm_riscv_cs.c @@ -26,13 +26,7 @@ static int riscv_disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { ctx->omode = mode; // cs_option (ctx->handle, CS_OPT_DETAIL, CS_OPT_OFF); } -#if 0 - if (a->syntax == RZ_ASM_SYNTAX_REGNUM) { - cs_option (ctx->handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_NOREGNAME); - } else { - cs_option (ctx->handle, CS_OPT_SYNTAX, CS_OPT_SYNTAX_DEFAULT); - } -#endif + int n = cs_disasm(ctx->handle, (ut8 *)buf, len, a->pc, 1, &insn); if (n < 1) { rz_asm_op_set_asm(op, "invalid"); diff --git a/librz/arch/p/asm/asm_xap.c b/librz/arch/p/asm/asm_xap.c index 65f12cdc4fa..94c59496314 100644 --- a/librz/arch/p/asm/asm_xap.c +++ b/librz/arch/p/asm/asm_xap.c @@ -16,12 +16,7 @@ static int arch_xap_disasm(RzStrBuf *asm_buf, const unsigned char *buf, ut64 add if (xap_read_instruction(&s, &d) > 0) { xap_decode(&s, &d); } -#if 0 - if (s->s_ff_quirk) { - sprintf(d->d_asm, "DC\t0x%x", i2u16(&d->d_inst)); - s->s_ff_quirk = 0; - } -#endif + return 0; } static int disassemble(RzAsm *a, RzAsmOp *op, const ut8 *buf, int len) { diff --git a/librz/bin/format/coff/coff.c b/librz/bin/format/coff/coff.c index a29f64924d6..0c1051e3322 100644 --- a/librz/bin/format/coff/coff.c +++ b/librz/bin/format/coff/coff.c @@ -115,22 +115,9 @@ RZ_API RzBinAddr *rz_coff_get_entry(struct rz_bin_coff_obj *obj) { } } } -#if 0 - /* Still clueless ? Let's just use the address of .text */ - if (obj->scn_hdrs) { - for (i = 0; i < obj->hdr.f_nscns; i++) { - // avoid doing string matching and use x bit from the section - if (obj->scn_hdrs[i].s_flags & COFF_SCN_MEM_EXECUTE) { - addr->paddr = obj->scn_hdrs[i].s_scnptr; - return addr; - } - } - } -#else + free(addr); return NULL; -#endif - return addr; } static bool rz_bin_coff_init_hdr(struct rz_bin_coff_obj *obj) { diff --git a/librz/bin/format/mach0/mach0.c b/librz/bin/format/mach0/mach0.c index 7bf09e343e6..f77d25609cf 100644 --- a/librz/bin/format/mach0/mach0.c +++ b/librz/bin/format/mach0/mach0.c @@ -3119,17 +3119,6 @@ void MACH0_(mach_headerfields)(RzBinFile *bf) { #endif } break; case LC_SYMTAB: -#if 0 - { - char *id = rz_buf_get_string (buf, addr + 20); - cb_printf ("0x%08"PFMT64x" id 0x%x\n", addr + 20, id? id: ""); - cb_printf ("0x%08"PFMT64x" symooff 0x%x\n", addr + 20, id? id: ""); - cb_printf ("0x%08"PFMT64x" nsyms %d\n", addr + 20, id? id: ""); - cb_printf ("0x%08"PFMT64x" stroff 0x%x\n", addr + 20, id? id: ""); - cb_printf ("0x%08"PFMT64x" strsize 0x%x\n", addr + 20, id? id: ""); - free (id); - } -#endif break; case LC_ID_DYLIB: { // install_name_tool ut32 str_off; @@ -3419,12 +3408,6 @@ struct MACH0_(mach_header) * MACH0_(get_hdr)(RzBuffer *buf) { big_endian = false; } else if (rz_read_be32(magicbytes) == 0xfeedfacf) { big_endian = true; - } else { - /* also extract non-mach0s */ -#if 0 - free (macho_hdr); - return NULL; -#endif } len = rz_buf_read_at(buf, 0, machohdrbytes, sizeof(machohdrbytes)); if (len != sizeof(struct MACH0_(mach_header))) { diff --git a/librz/bin/format/mdmp/mdmp.c b/librz/bin/format/mdmp/mdmp.c index 31f6e22a77e..0d9618f0699 100644 --- a/librz/bin/format/mdmp/mdmp.c +++ b/librz/bin/format/mdmp/mdmp.c @@ -312,12 +312,6 @@ static void mdmp_obj_sdb_init(MiniDmpObj *obj) { sdb_set(obj->kv, "mdmp_memory_descriptor64.format", "qq " "StartOfMemoryRange DataSize"); -#if 0 - /* TODO: Flag dependent thus not fully implemented */ - sdb_set (obj->kv, "mdmp_context.format", "[4]B " - "(mdmp_context_flags)ContextFlags"); -#endif - sdb_set(obj->kv, "mdmp_vs_fixedfileinfo.format", "ddddddddddddd " "dwSignature dwStrucVersion dwFileVersionMs " "dwFileVersionLs dwProductVersionMs " diff --git a/librz/bin/format/objc/mach0_classes.c b/librz/bin/format/objc/mach0_classes.c index 5920d48834f..86b0f66af3e 100644 --- a/librz/bin/format/objc/mach0_classes.c +++ b/librz/bin/format/objc/mach0_classes.c @@ -464,27 +464,6 @@ static void get_objc_property_list(mach0_ut p, RzBinFile *bf, RzBuffer *buf, RzB property->name = rz_str_newf("%s::(property)%s", klass->name, name); RZ_FREE(name); } -#if 0 - r = va2pa (op.attributes, NULL, &left, bf); - if (r != 0) { - struct MACH0_(obj_t) *bin = (struct MACH0_(obj_t) *) bf->o->bin_obj; - int is_crypted = bin->has_crypto; - - if (r > bf->size || r + left > bf->size) goto error; - if (r + left < r) goto error; - - if (is_crypted == 1) { - name = rz_str_dup ("some_encrypted_data"); - left = strlen (name) + 1; - } else { - name = malloc (left); - len = rz_buf_read_at (buf, r, (ut8 *)name, left); - if (len == 0 || len == -1) goto error; - } - - RZ_FREE (name); - } -#endif rz_list_append(klass->fields, property); p += sizeof(struct MACH0_(SObjcProperty)); @@ -1190,42 +1169,6 @@ RZ_API void MACH0_(get_class_t)(mach0_ut p, RzBinFile *bf, RzBuffer *buf, RzBinC } } -#if 0 -static RzList *parse_swift_classes(RzBinFile *bf) { - bool is_swift = false; - RzBinString *str; - RzListIter *iter; - RzBinClass *cls; - RzList *ret; - char *lib; - - rz_list_foreach (bf->o->libs, iter, lib) { - if (strstr (lib, "libswift")) { - is_swift = true; - break; - } - } - if (!is_swift) { - return NULL; - } - - int idx = 0; - ret = rz_list_newf (rz_bin_string_free); - rz_list_foreach (bf->o->strings, iter, str) { - if (!strncmp (str->string, "_TtC", 4)) { - char *msg = rz_str_dup (str->string + 4); - cls = RZ_NEW0 (RzBinClass); - cls->name = rz_str_dup (msg); - cls->super = rz_str_dup (msg); - cls->index = idx++; - rz_list_append (ret, cls); - free (msg); - } - } - return ret; -} -#endif - RZ_API RZ_OWN RzPVector /**/ *MACH0_(parse_classes)(RzBinFile *bf, objc_cache_opt_info *oi) { RzPVector /**/ *ret = NULL; ut64 num_of_unnamed_class = 0; diff --git a/librz/bin/format/omf/omf.c b/librz/bin/format/omf/omf.c index 22e84601bbe..ee991f84f81 100644 --- a/librz/bin/format/omf/omf.c +++ b/librz/bin/format/omf/omf.c @@ -597,11 +597,9 @@ static int get_omf_infos(rz_bin_omf_obj *obj) { } static void free_pubdef(OMF_multi_datas *datas) { -#if 0 - while (ct_rec < datas->nb_elem) { - RZ_FREE (((OMF_symbol *)(datas->elems + ct_rec++))->name); + if (!datas) { + return; } -#endif RZ_FREE(datas->elems); RZ_FREE(datas); } diff --git a/librz/bin/format/pe/pe_section.c b/librz/bin/format/pe/pe_section.c index 7bfb83c6327..7654f10a046 100644 --- a/librz/bin/format/pe/pe_section.c +++ b/librz/bin/format/pe/pe_section.c @@ -320,44 +320,44 @@ int PE_(bin_pe_init_sections)(RzBinPEObj *bin) { goto out_error; } } -#if 0 - Each symbol table entry includes a name, storage class, type, value and section number.Short names (8 characters or fewer) are stored directly in the symbol table; - longer names are stored as an paddr into the string table at the end of the COFF object. + /* + * Each symbol table entry includes a name, storage class, type, value and section number.Short names (8 characters or fewer) are stored directly in the symbol table; + * longer names are stored as an paddr into the string table at the end of the COFF object. + * + * ================================================================ + * COFF SYMBOL TABLE RECORDS (18 BYTES) + * ================================================================ + * record + * paddr + * + * struct symrec { + * union { + * char string[8]; // short name + * struct { + * ut32 seros; + * ut32 stridx; + * } stridx; + * } name; + * ut32 value; + * ut16 secnum; + * ut16 symtype; + * ut8 symclass; + * ut8 numaux; + * } + * ------------------------------------------------------ - + * 0 | 8 - char symbol name | + * | or 32 - bit zeroes followed by 32 - bit | + * | index into string table | + * ------------------------------------------------------ - + * 8 | symbol value | + * ------------------------------------------------------ - + * 0Ch | section number | symbol type | + * ------------------------------------------------------ - + * 10h | sym class | num aux | + * -------------------------- - + * 12h + */ - ================================================================ - COFF SYMBOL TABLE RECORDS (18 BYTES) - ================================================================ - record - paddr - - struct symrec { - union { - char string[8]; // short name - struct { - ut32 seros; - ut32 stridx; - } stridx; - } name; - ut32 value; - ut16 secnum; - ut16 symtype; - ut8 symclass; - ut8 numaux; - } - ------------------------------------------------------ - - 0 | 8 - char symbol name | - | or 32 - bit zeroes followed by 32 - bit | - | index into string table | - ------------------------------------------------------ - - 8 | symbol value | - ------------------------------------------------------ - - 0Ch | section number | symbol type | - ------------------------------------------------------ - - 10h | sym class | num aux | - -------------------------- - - 12h - -#endif return true; out_error: bin->num_sections = 0; diff --git a/librz/bin/format/wasm/wasm.c b/librz/bin/format/wasm/wasm.c index de2873d7297..88ebb32f844 100644 --- a/librz/bin/format/wasm/wasm.c +++ b/librz/bin/format/wasm/wasm.c @@ -174,49 +174,6 @@ static RzList /**/ *rz_bin_wasm_get_sections_by_id(RzList /* return ret; } -#if 0 -const char *rz_bin_wasm_valuetype_to_string (rz_bin_wasm_value_type_t type) { - switch (type) { - case RZ_BIN_WASM_VALUETYPE_i32: - return "i32"; - case RZ_BIN_WASM_VALUETYPE_i64: - return "i62"; - case RZ_BIN_WASM_VALUETYPE_f32: - return "f32"; - case RZ_BIN_WASM_VALUETYPE_f64: - return "f64"; - case RZ_BIN_WASM_VALUETYPE_ANYFUNC: - return "ANYFUNC"; - case RZ_BIN_WASM_VALUETYPE_FUNC: - return "FUNC"; - default: - return ""; - } -} - -static char *rz_bin_wasm_type_entry_to_string(RzBinWasmTypeEntry *ptr) { - if (!ptr) { - return NULL; - } - char *buf = (char*)calloc (ptr->param_count, 5); - if (!buf) { - return NULL; - } - int p; - for (p = 0; p < ptr->param_count; p++) { - strcat (buf, rz_bin_wasm_valuetype_to_string (ptr->param_types[p])); - if (p < ptr->param_count - 1) { - strcat (buf, ", "); - } - } - snprintf (ptr->to_str, RZ_BIN_WASM_STRING_LENGTH, "(%s) -> (%s)", - (ptr->param_count > 0? buf: ""), - (ptr->return_count == 1? rz_bin_wasm_valuetype_to_string (ptr->return_type): "")); - free (buf); - return ptr->to_str; -} -#endif - // Free static void rz_bin_wasm_free_types(RzBinWasmTypeEntry *ptr) { if (ptr) { diff --git a/librz/bin/p/bin_coff.c b/librz/bin/p/bin_coff.c index 8099e067835..b1e9c5b12cf 100644 --- a/librz/bin/p/bin_coff.c +++ b/librz/bin/p/bin_coff.c @@ -504,17 +504,14 @@ static ut64 size(RzBinFile *bf) { } static bool check_buffer(RzBuffer *buf) { -#if 0 -TODO: do more checks here to avoid false positives - -ut16 MACHINE -ut16 NSECTIONS -ut32 DATE -ut32 PTRTOSYMTABLE -ut32 NUMOFSYMS -ut16 OPTHDRSIZE -ut16 CHARACTERISTICS -#endif + // TODO: do more checks here to avoid false positives + // ut16 MACHINE + // ut16 NSECTIONS + // ut32 DATE + // ut32 PTRTOSYMTABLE + // ut32 NUMOFSYMS + // ut16 OPTHDRSIZE + // ut16 CHARACTERISTICS ut8 tmp[20]; int r = rz_buf_read_at(buf, 0, tmp, sizeof(tmp)); diff --git a/librz/bin/p/bin_menuet.c b/librz/bin/p/bin_menuet.c index a9b3b54fd6c..be7ae2c61ef 100644 --- a/librz/bin/p/bin_menuet.c +++ b/librz/bin/p/bin_menuet.c @@ -8,47 +8,44 @@ #define MENUET_VERSION(x) x[7] -#if 0 - db 'MENUET00' ; 8 byte id - dd 38 ; required os - dd START ; program start - dd I_END ; image size - dd 0x100000 ; reguired amount of memory - dd 0x00000000 ; reserved=no extended header - - org 0x0 - db 'MENUET01' ; 8 byte id - dd 1 ; header version - dd START ; program start - dd I_END ; program image size - dd 0x1000 ; required amount of memory - dd 0x1000 ; esp - dd 0, 0 ; no parameters, no path - - 0 db 'MENUET02' - 8 dd 0x01 - 12 dd __start - 16 dd __iend - 20 dd __bssend - 24 dd __stack - 28 dd __cmdline - 32 dd __pgmname - 36 dd 0x0; tls map - 40 dd __idata_start; секция .import - 44 dd __idata_end - 48 dd main - - db 'MENUET02' - dd 1 - dd start - dd i_end - dd mem - dd mem - dd cmdline - dd path - dd 0 - -#endif +// db 'MENUET00' ; 8 byte id +// dd 38 ; required os +// dd START ; program start +// dd I_END ; image size +// dd 0x100000 ; reguired amount of memory +// dd 0x00000000 ; reserved=no extended header + +// org 0x0 +// db 'MENUET01' ; 8 byte id +// dd 1 ; header version +// dd START ; program start +// dd I_END ; program image size +// dd 0x1000 ; required amount of memory +// dd 0x1000 ; esp +// dd 0, 0 ; no parameters, no path + +// 0 db 'MENUET02' +// 8 dd 0x01 +// 12 dd __start +// 16 dd __iend +// 20 dd __bssend +// 24 dd __stack +// 28 dd __cmdline +// 32 dd __pgmname +// 36 dd 0x0; tls map +// 40 dd __idata_start; секция .import +// 44 dd __idata_end +// 48 dd main + +// db 'MENUET02' +// dd 1 +// dd start +// dd i_end +// dd mem +// dd mem +// dd cmdline +// dd path +// dd 0 static bool check_buffer(RzBuffer *b) { ut8 buf[8]; diff --git a/librz/bin/p/bin_pebble.c b/librz/bin/p/bin_pebble.c index 2264911fca8..b43b33f37f4 100644 --- a/librz/bin/p/bin_pebble.c +++ b/librz/bin/p/bin_pebble.c @@ -146,20 +146,6 @@ static RzPVector /**/ *sections(RzBinFile *bf) { return ret; } -#if 0 -static RzList* relocs(RzBinFile *bf) { - RzList *ret = NULL; - RzBinReloc *ptr = NULL; - ut64 got_addr; - int i; - - if (!(ret = rz_list_new ())) - return NULL; - ret->free = free; - return ret; -} -#endif - static RzPVector /**/ *entries(RzBinFile *bf) { RzBinAddr *ptr = NULL; RzPVector *ret; diff --git a/librz/bin/p/bin_sfc.c b/librz/bin/p/bin_sfc.c index 9cce28e17b0..b182adae294 100644 --- a/librz/bin/p/bin_sfc.c +++ b/librz/bin/p/bin_sfc.c @@ -108,20 +108,6 @@ static void addrom(RzPVector /**/ *ret, const char *name, int i, rz_pvector_push(ret, ptr); } -#if 0 -static void addsym(RzList *ret, const char *name, ut64 addr, ut32 size) { - RzBinSymbol *ptr = RZ_NEW0 (RzBinSymbol); - if (!ptr) { - return; - } - ptr->name = rz_str_dup (name? name: ""); - ptr->paddr = ptr->vaddr = addr; - ptr->size = size; - ptr->ordinal = 0; - rz_list_append (ret, ptr); -} -#endif - static RzPVector /**/ *symbols(RzBinFile *bf) { return NULL; } diff --git a/librz/bin/p/bin_symbols.c b/librz/bin/p/bin_symbols.c index 2b1684bc490..9a231bed671 100644 --- a/librz/bin/p/bin_symbols.c +++ b/librz/bin/p/bin_symbols.c @@ -205,29 +205,28 @@ static RzCoreSymCacheElement *parseDragons(RzBinFile *bf, RzBuffer *buf, int off RZ_LOG_ERROR("bin: symbols: cannot read at 0x%08x\n", off); return NULL; } -#if 0 // after the list of sections, there's a bunch of unknown // data, brobably dwords, and then the same section list again // this function aims to parse it. - 0x00000138 |1a2b b2a1 0300 0000 1a2b b2a1 e055 0000| .+.......+...U.. - n_segments ----. .--- how many sections ? - 0x00000148 |0100 0000 ca55 0000 0400 0000 1800 0000| .....U.......... - .---- how many symbols? 0xc7 - 0x00000158 |c700 0000 0000 0000 0000 0000 0104 0000| ................ - 0x00000168 |250b e803 0000 0100 0000 0000 bd55 0000| %............U.. - 0x00000178 |91bb e903 e35a b42c 93a4 340a 8746 9489| .....Z.,..4..F.. - 0x00000188 |0cea 4c40 0c00 0000 0900 0000 0000 0000| ..L@............ - 0x00000198 |0000 0000 0000 0000 0000 0000 0000 0000| ................ - 0x000001a8 |0080 0000 0000 0000 5f5f 5445 5854 0000| ........__TEXT.. - 0x000001b8 |0000 0000 0000 0000 0080 0000 0000 0000| ................ - 0x000001c8 |0040 0000 0000 0000 5f5f 4441 5441 0000| .@......__DATA.. - 0x000001d8 |0000 0000 0000 0000 00c0 0000 0000 0000| ................ - 0x000001e8 |0000 0100 0000 0000 5f5f 4c4c 564d 0000| ........__LLVM.. - 0x000001f8 |0000 0000 0000 0000 00c0 0100 0000 0000| ................ - 0x00000208 |00c0 0000 0000 0000 5f5f 4c49 4e4b 4544| ........__LINKED - 0x00000218 |4954 0000 0000 0000 0000 0000 d069 0000| IT...........i.. -#endif + // 0x00000138 |1a2b b2a1 0300 0000 1a2b b2a1 e055 0000| .+.......+...U.. + // n_segments ----. .--- how many sections ? + // 0x00000148 |0100 0000 ca55 0000 0400 0000 1800 0000| .....U.......... + // .---- how many symbols? 0xc7 + // 0x00000158 |c700 0000 0000 0000 0000 0000 0104 0000| ................ + // 0x00000168 |250b e803 0000 0100 0000 0000 bd55 0000| %............U.. + // 0x00000178 |91bb e903 e35a b42c 93a4 340a 8746 9489| .....Z.,..4..F.. + // 0x00000188 |0cea 4c40 0c00 0000 0900 0000 0000 0000| ..L@............ + // 0x00000198 |0000 0000 0000 0000 0000 0000 0000 0000| ................ + // 0x000001a8 |0080 0000 0000 0000 5f5f 5445 5854 0000| ........__TEXT.. + // 0x000001b8 |0000 0000 0000 0000 0080 0000 0000 0000| ................ + // 0x000001c8 |0040 0000 0000 0000 5f5f 4441 5441 0000| .@......__DATA.. + // 0x000001d8 |0000 0000 0000 0000 00c0 0000 0000 0000| ................ + // 0x000001e8 |0000 0100 0000 0000 5f5f 4c4c 564d 0000| ........__LLVM.. + // 0x000001f8 |0000 0000 0000 0000 00c0 0100 0000 0000| ................ + // 0x00000208 |00c0 0000 0000 0000 5f5f 4c49 4e4b 4544| ........__LINKED + // 0x00000218 |4954 0000 0000 0000 0000 0000 d069 0000| IT...........i.. // eprintf ("Dragon's magic:\n"); + int magicCombo = 0; if (size > 3 && !memcmp("\x1a\x2b\xb2\xa1", b, 4)) { // 0x130 ? magicCombo++; @@ -258,24 +257,22 @@ static RzCoreSymCacheElement *parseDragons(RzBinFile *bf, RzBuffer *buf, int off } static bool load_buffer(RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb) { -#if 0 - SYMBOLS HEADER - - 0 MAGIC 02ff01ff - 4 VERSION 1 (little endian) - 8 ffffffff -16 002b0000 01000000 { 0x2b00, 0x0000 } -24 UUID 16 bytes -40 2621 d85b 2100 2000 0000 0000 0000 0000 -56 ffff ffff ffff ff7f 0c00 0000 0900 0000 -72 0400 0000 6800 0000 2f76 6172 2f66 6f6c .... 4, 104 /// 104 length string -184 -0x000000b8 5f5f 5445 5854 0000 0000 0000 0000 0000 0000 0000 0000 0000 0080 0000 0000 0000 __TEXT.......................... -0x000000d8 5f5f 4441 5441 0000 0000 0000 0000 0000 0080 0000 0000 0000 0040 0000 0000 0000 __DATA...................@...... -0x000000f8 5f5f 4c4c 564d 0000 0000 0000 0000 0000 00c0 0000 0000 0000 0000 0100 0000 0000 __LLVM.......................... -0x00000118 5f5f 4c49 4e4b 4544 4954 0000 0000 0000 00c0 0100 0000 0000 00c0 0000 0000 0000 __LINKEDIT...................... + // SYMBOLS HEADER + // + // 0 MAGIC 02ff01ff + // 4 VERSION 1 (little endian) + // 8 ffffffff + // 16 002b0000 01000000 { 0x2b00, 0x0000 } + // 24 UUID 16 bytes + // 40 2621 d85b 2100 2000 0000 0000 0000 0000 + // 56 ffff ffff ffff ff7f 0c00 0000 0900 0000 + // 72 0400 0000 6800 0000 2f76 6172 2f66 6f6c .... 4, 104 /// 104 length string + // 184 + // 0x000000b8 5f5f 5445 5854 0000 0000 0000 0000 0000 0000 0000 0000 0000 0080 0000 0000 0000 __TEXT.......................... + // 0x000000d8 5f5f 4441 5441 0000 0000 0000 0000 0000 0080 0000 0000 0000 0040 0000 0000 0000 __DATA...................@...... + // 0x000000f8 5f5f 4c4c 564d 0000 0000 0000 0000 0000 00c0 0000 0000 0000 0000 0100 0000 0000 __LLVM.......................... + // 0x00000118 5f5f 4c49 4e4b 4544 4954 0000 0000 0000 00c0 0100 0000 0000 00c0 0000 0000 0000 __LINKEDIT...................... -#endif // 0 - magic check, version ... SymbolsHeader sh = parseHeader(buf); if (!sh.valid) { diff --git a/librz/bin/p/bin_xtr_pemixed.c b/librz/bin/p/bin_xtr_pemixed.c index 9e61c1a263f..c17a2ec5fc1 100644 --- a/librz/bin/p/bin_xtr_pemixed.c +++ b/librz/bin/p/bin_xtr_pemixed.c @@ -47,7 +47,7 @@ static bool check_buffer(RzBuffer *b) { #endif } -// TODO RzBufferify +// TODO RzBufferify static RzList /**/ *oneshotall(RzBin *bin, const ut8 *buf, ut64 size) { // extract dos componenent first RzBinXtrData *data = oneshot(bin, buf, size, SUB_BIN_DOS); diff --git a/librz/cons/cons.c b/librz/cons/cons.c index 78be846f229..f8b7e020787 100644 --- a/librz/cons/cons.c +++ b/librz/cons/cons.c @@ -1286,10 +1286,10 @@ RZ_API void rz_cons_newline(void) { rz_cons_strcat("\n"); } #if 0 -This place is wrong to manage the color reset, can interfire with rzpipe output sending resetchars -and break json output appending extra chars. -this code now is managed into output.c:118 at function rz_cons_w32_print -now the console color is reset with each \n (same stuff do it here but in correct place ... i think) + // This place is wrong to manage the color reset, can interfire with rzpipe output sending resetchars + // and break json output appending extra chars. + // this code now is managed into output.c:118 at function rz_cons_w32_print + // now the console color is reset with each \n (same stuff do it here but in correct place ... i think) #if __WINDOWS__ rz_cons_reset_colors(); diff --git a/librz/cons/cutf8.c b/librz/cons/cutf8.c index 2f376f8b58e..bfb5293e9ab 100644 --- a/librz/cons/cutf8.c +++ b/librz/cons/cutf8.c @@ -55,12 +55,7 @@ int current_tty(void) { #else int fd; const char *dev = ttyname(STDERR_FILENO); -#if 0 - if (!dev) - dev = ttyname(STDIN_FILENO); - if (!dev) - dev = ttyname(STDERR_FILENO); -#endif + if (!dev) { errno = ENOTTY; return -1; diff --git a/librz/cons/input.c b/librz/cons/input.c index e69d279f4c9..b77788aab37 100644 --- a/librz/cons/input.c +++ b/librz/cons/input.c @@ -326,11 +326,7 @@ RZ_API int rz_cons_fgets(char *buf, int len, int argc, const char **argv) { rz_cons_set_raw(false); rz_cons_show_cursor(true); } -#if 0 - int mouse = rz_cons_enable_mouse (false); - rz_cons_enable_mouse (false); - rz_cons_flush (); -#endif + errno = 0; if (cons->user_fgets) { RETURN(cons->user_fgets(buf, len, cons->user_fgets_user)); diff --git a/librz/core/cconfig.c b/librz/core/cconfig.c index e7d6973b511..190725e56b7 100644 --- a/librz/core/cconfig.c +++ b/librz/core/cconfig.c @@ -2117,12 +2117,6 @@ static bool cb_iova(void *user, void *data) { if (core->io->desc) { rz_core_block_read(core); } -#if 0 - /* reload symbol information */ - if (rz_list_length (rz_bin_get_sections (core->bin)) > 0) { - rz_core_cmd0 (core, ".ia*"); - } -#endif } return true; } diff --git a/librz/core/cmd/cmd_magic.c b/librz/core/cmd/cmd_magic.c index 63ae26f0dec..fde81e8bf25 100644 --- a/librz/core/cmd/cmd_magic.c +++ b/librz/core/cmd/cmd_magic.c @@ -172,10 +172,6 @@ static int rz_core_magic_at(RzCore *core, const char *file, ut64 addr, int depth } adelta++; delta++; -#if 0 - rz_magic_free (ck); - ck = NULL; -#endif { int mod = core->search->align; if (mod) { diff --git a/librz/core/cmd/cmd_print.c b/librz/core/cmd/cmd_print.c index 4026e4e1482..f49f92fb0b7 100644 --- a/librz/core/cmd/cmd_print.c +++ b/librz/core/cmd/cmd_print.c @@ -1462,12 +1462,6 @@ static bool cmd_print_pxA(RzCore *core, int len, RzOutputMode mode) { fgcolor = Color_WHITE; text = "XX"; break; -#if 0 - default: - color = Color_BGCYAN; - fgcolor = Color_BLACK; - break; -#endif } int opsz = RZ_MAX(op.size, 1); if (show_cursor) { diff --git a/librz/core/cmd/cmd_search.c b/librz/core/cmd/cmd_search.c index 616b8e9a9f5..d4dd55d7a0f 100644 --- a/librz/core/cmd/cmd_search.c +++ b/librz/core/cmd/cmd_search.c @@ -10,8 +10,6 @@ #include "cmd_search_rop.c" -#define USE_EMULATION 0 - #define AES_SEARCH_LENGTH 40 #define PRIVATE_KEY_SEARCH_LENGTH 11 @@ -70,15 +68,6 @@ static const char *help_msg_slash[] = { "/x", " ff43:ffd0", "search for hexpair with mask", "/z", " min max", "search for strings of given size", "/*", " [comment string]", "add multiline comment, end it with '*/'", -#if 0 - "\nConfiguration:", "", " (type `e??search.` for a complete list)", - "e", " cmd.hit = x", "command to execute on every search hit", - "e", " search.in = ?", "specify where to search stuff (depends on .from/.to)", - "e", " search.align = 4", "only catch aligned search hits", - "e", " search.from = 0", "start address", - "e", " search.to = 0", "end address", - "e", " search.flags = true", "if enabled store flags on keyword hits", -#endif NULL }; @@ -1056,17 +1045,7 @@ static void do_esil_search(RzCore *core, struct search_parameters *param, const continue; } } -#if 0 - // we need a way to retrieve info from a speicif address, and make it accessible from the esil search - // maybe we can just do it like this: 0x804840,AddressType,3,&, ... bitmask - // executable = 1 - // writable = 2 - // inprogram - // instack - // inlibrary - // inheap - rz_analysis_esil_set_op (core->analysis->esil, "AddressInfo", esil_search_address_info); -#endif + if (rz_cons_is_breaked()) { RZ_LOG_WARN("core: Breaked at 0x%08" PFMT64x "\n", addr); break; @@ -1138,63 +1117,9 @@ static void do_esil_search(RzCore *core, struct search_parameters *param, const (res) += (arr)[--(size)]; \ while ((size)) -#if USE_EMULATION -// IMHO This code must be deleted -static int emulateSyscallPrelude(RzCore *core, ut64 at, ut64 curpc) { - int i, inslen, bsize = RZ_MIN(64, core->blocksize); - ut8 *arr; - RzAnalysisOp aop = { 0 }; - const int mininstrsz = rz_analysis_archinfo(core->analysis, RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE); - const int minopcode = RZ_MAX(1, mininstrsz); - const char *a0 = rz_reg_get_name(core->analysis->reg, RZ_REG_NAME_SN); - const char *pc = rz_reg_get_name(core->dbg->reg, RZ_REG_NAME_PC); - RzRegItem *r = rz_reg_get(core->dbg->reg, pc, -1); - RzRegItem *reg_a0 = rz_reg_get(core->dbg->reg, a0, -1); - - arr = malloc(bsize); - if (!arr) { - RZ_LOG_ERROR("core: Cannot allocate %d byte(s)\n", bsize); - free(arr); - return -1; - } - rz_reg_set_value(core->dbg->reg, r, curpc); - for (i = 0; curpc < at; curpc++, i++) { - if (i >= (bsize - 32)) { - i = 0; - } - if (!i) { - rz_io_read_at(core->io, curpc, arr, bsize); - } - rz_analysis_op_init(&aop); - inslen = rz_analysis_op(core->analysis, &aop, curpc, arr + i, bsize - i, RZ_ANALYSIS_OP_MASK_BASIC); - if (inslen > 0) { - int incr = (core->search->align > 0) ? core->search->align - 1 : inslen - 1; - if (incr < 0) { - incr = minopcode; - } - i += incr; - curpc += incr; - if (rz_analysis_op_nonlinear(aop.type)) { // skip the instr - rz_reg_set_value(core->dbg->reg, r, curpc + 1); - } else { // step instr - rz_core_esil_step(core, UT64_MAX, NULL, NULL); - } - } - rz_analysis_op_fini(&aop); - } - free(arr); - int sysno = rz_debug_reg_get(core->dbg, a0); - rz_reg_set_value(core->dbg->reg, reg_a0, -2); // clearing register A0 - return sysno; -} -#endif - static void do_syscall_search(RzCore *core, struct search_parameters *param) { RzSearch *search = core->search; ut64 at; -#if USE_EMULATION - ut64 curpc; -#endif ut8 *buf; int curpos, idx = 0, count = 0; RzAnalysisOp aop = { 0 }; @@ -1280,16 +1205,7 @@ static void do_syscall_search(RzCore *core, struct search_parameters *param) { if ((aop.type == RZ_ANALYSIS_OP_TYPE_SWI) && ret) { // && (aop.val > 10)) { int scVector = -1; // int 0x80, svc 0x70, ... int scNumber = 0; // r0/eax/... -#if USE_EMULATION - // This for calculating no of bytes to be subtracted , to get n instr above syscall - int nbytes = 0; - int nb_opcodes = MAXINSTR; - SUMARRAY(previnstr, nb_opcodes, nbytes); - curpc = at - (nbytes - previnstr[curpos]); - scNumber = emulateSyscallPrelude(core, at, curpc); -#else scNumber = syscallNumber; -#endif scVector = (aop.val > 0) ? aop.val : -1; // int 0x80 (aop.val = 0x80) RzSyscallItem *item = rz_syscall_get(core->analysis->syscall, scNumber, scVector); if (item) { diff --git a/librz/core/cmd/cmd_seek.c b/librz/core/cmd/cmd_seek.c index 864ecc25c33..1822bf6cc0a 100644 --- a/librz/core/cmd/cmd_seek.c +++ b/librz/core/cmd/cmd_seek.c @@ -32,11 +32,6 @@ RZ_IPI int rz_core_seek_opcode_backward(RzCore *core, int numinstr, bool silent) if (rz_core_prevop_addr(core, core->offset, numinstr, &addr)) { ret = core->offset - addr; } else { -#if 0 - // core_asm_bwdis_len is really buggy and we should remove it. seems like prevop_addr - // works as expected, because is the one used from visual - ret = rz_core_asm_bwdis_len (core, &instr_len, &addr, numinstr); -#endif addr = core->offset; const int mininstrsize = rz_analysis_archinfo(core->analysis, RZ_ANALYSIS_ARCHINFO_MIN_OP_SIZE); for (i = 0; i < numinstr; i++) { diff --git a/librz/core/core.c b/librz/core/core.c index ac47f72c350..d1793e26e72 100644 --- a/librz/core/core.c +++ b/librz/core/core.c @@ -843,14 +843,7 @@ static ut64 num_callback(RzNum *userptr, const char *str, int *ok) { } return fcn->addr; } -#if 0 - ut64 addr = rz_analysis_fcn_label_get (core->analysis, core->offset, str); - if (addr != 0) { - ret = addr; - } else { - ... - } -#endif + if ((flag = rz_flag_get(core->flags, str))) { ret = flag->offset; if (ok) { diff --git a/librz/core/linux_heap_glibc.c b/librz/core/linux_heap_glibc.c index 91119c662db..88ed2e20804 100644 --- a/librz/core/linux_heap_glibc.c +++ b/librz/core/linux_heap_glibc.c @@ -71,12 +71,6 @@ static GHT GH(get_va_symbol)(RzCore *core, const char *path, const char *sym_nam return vaddr; } -#if 0 -static inline GHT GH(align_address_to_size)(ut64 addr, ut64 align) { - return addr + ((align - (addr % align)) % align); -} -#endif - static inline GHT GH(get_next_pointer)(RzCore *core, GHT pos, GHT next) { return (core->dbg->glibc_version < 232) ? next : (GHT)((pos >> 12) ^ next); } diff --git a/librz/core/rtr.c b/librz/core/rtr.c index 232d65eab66..9fd01c352d1 100644 --- a/librz/core/rtr.c +++ b/librz/core/rtr.c @@ -8,16 +8,14 @@ #include #include -#if 0 -SECURITY IMPLICATIONS -===================== -- no ssl -- no auth -- commands can be executed by anyone -- default is to listen on localhost -- can access full filesystem -- follow symlinks -#endif +// SECURITY IMPLICATIONS +// ===================== +// - no ssl +// - no auth +// - commands can be executed by anyone +// - default is to listen on localhost +// - can access full filesystem +// - follow symlinks #define rtr_n core->rtr_n #define rtr_host core->rtr_host diff --git a/librz/core/rtr_shell.c b/librz/core/rtr_shell.c index 9b1eadb2ffd..d6d9f1c58d1 100644 --- a/librz/core/rtr_shell.c +++ b/librz/core/rtr_shell.c @@ -49,11 +49,9 @@ static bool rtr_visual(RzCore *core, TextLog T, const char *cmd) { } else { ch = rz_cons_readchar(); } -#if 0 -TODO: - i insert hex/string/asm - 0-9 follow jumps -#endif + // TODO: + // i insert hex/string/asm + // 0-9 follow jumps switch (ch) { case '?': rz_cons_clear00(); diff --git a/librz/core/tui/visual.c b/librz/core/tui/visual.c index ea9152bedae..100bf442aad 100644 --- a/librz/core/tui/visual.c +++ b/librz/core/tui/visual.c @@ -3315,21 +3315,6 @@ RZ_IPI void rz_core_visual_title(RzCore *core, int color) { title = rz_str_append(title, tabstring); free(tabstring); } -#if 0 - // TODO: add an option to show this tab mode instead? - const int curTab = core->visual.tab; - rz_cons_printf ("["); - int i; - for (i = 0; i < tabsCount; i++) { - if (i == curTab) { - rz_cons_printf ("%d", curTab + 1); - } else { - rz_cons_printf ("."); - } - } - rz_cons_printf ("]"); - rz_cons_printf ("[tab:%d/%d]", core->visual.tab, tabsCount); -#endif } rz_cons_print(title); free(title); @@ -3715,12 +3700,6 @@ static void visual_refresh(RzCore *core) { } } core->print->cur_enabled = ce; -#if 0 - if (core->print->screen_bounds != 1LL) { - rz_cons_printf ("[0x%08"PFMT64x "..0x%08"PFMT64x "]\n", - core->offset, core->print->screen_bounds); - } -#endif // get the address in the line at the bottom of the screen to calculate the percentage char *bottom_addr = screen_bottom_address(core); diff --git a/librz/crypto/p/crypto_blowfish.c b/librz/crypto/p/crypto_blowfish.c index 0d0462828ed..5909868ad44 100644 --- a/librz/crypto/p/crypto_blowfish.c +++ b/librz/crypto/p/crypto_blowfish.c @@ -365,20 +365,3 @@ RZ_API RzLibStruct rizin_plugin = { .version = RZ_VERSION }; #endif - -#if 0 -int main() { - ut8 out[16]; - struct blowfish_state st; - - /* encrypt */ - blowfish_init (&st, (const ut8*)"key", 3); - blowfish_crypt (&st, (const ut8*)"helloworld123456", out, sizeof(out)); - - /* decrypt */ - blowfish_init (&st, (const ut8*)"key", 3); - blowfish_decrypt (&st, out, out, sizeof(out)); - - eprintf ("%s\n", (const char *)out); // must print "helloworld123456" -} -#endif diff --git a/librz/crypto/p/crypto_cps2.c b/librz/crypto/p/crypto_cps2.c index 01474431c17..48b1e13fa53 100644 --- a/librz/crypto/p/crypto_cps2.c +++ b/librz/crypto/p/crypto_cps2.c @@ -2860,31 +2860,6 @@ static void cps2_crypt(int dir, const ut16 *rom, ut16 *dec, int length, const ut } } -#if 0 -main(cps_state,cps2crypt) { - ut32 key[2]; - ut32 lower; - ut32 upper; - - std::string skey1 = parameter("cryptkey1");; - key[0] = strtoll(skey1.c_str(), nullptr, 16); - - std::string skey2 = parameter("cryptkey2"); - key[1] = strtoll(skey2.c_str(), nullptr, 16); - - std::string slower = parameter("cryptlower"); - lower = strtoll(slower.c_str(), nullptr, 16); // unused - - std::string supper = parameter("cryptupper"); - upper = strtoll(supper.c_str(), nullptr, 16); - - // we have a proper key so use it to decrypt - if (lower != 0xff0000) {// don't run the decrypt on 'dead key' games for now - cps2_decrypt( (ut16 *)memregion("maincpu")->base(), m_decrypted_opcodes, memregion("maincpu")->bytes(), key, lower,upper); - } -} -#endif - static bool set_key(RzCrypto *cry, const ut8 *key, int keylen, int mode, int direction) { rz_return_val_if_fail(cry->user && key, false); ut32 *cps2key = (ut32 *)cry->user; diff --git a/librz/debug/debug.c b/librz/debug/debug.c index d1fc5dca85b..7f89eab31ae 100644 --- a/librz/debug/debug.c +++ b/librz/debug/debug.c @@ -1563,12 +1563,6 @@ RZ_API int rz_debug_continue_syscalls(RzDebug *dbg, int *sc, int n_sc) { if (reason == RZ_DEBUG_REASON_DEAD || rz_debug_is_dead(dbg)) { break; } -#if 0 - if (reason != RZ_DEBUG_REASON_STEP) { - eprintf ("astep\n"); - break; - } -#endif if (!rz_debug_reg_sync(dbg, RZ_REG_TYPE_GPR, false)) { eprintf("--> cannot sync regs, process is probably dead\n"); return -1; diff --git a/librz/debug/p/debug_gdb.c b/librz/debug/p/debug_gdb.c index 63de23334dd..23471df6bd9 100644 --- a/librz/debug/p/debug_gdb.c +++ b/librz/debug/p/debug_gdb.c @@ -125,15 +125,6 @@ static int rz_debug_gdb_reg_read(RzDebug *dbg, int type, ut8 *buf, int size) { memcpy((void *)(volatile void *)buf, ctx->desc->data, RZ_MIN(copy_size, size)); memset((void *)(volatile void *)ctx->reg_buf, 0, buflen); memcpy((void *)(volatile void *)ctx->reg_buf, ctx->desc->data, copy_size); -#if 0 - int i; - //for(i=0;i<168;i++) { - for(i=0;idata[i]); - } - printf("\n"); -#endif return ctx->desc->data_len; } diff --git a/librz/debug/p/debug_io.c b/librz/debug/p/debug_io.c index 1480739dcd2..b6820e10b90 100644 --- a/librz/debug/p/debug_io.c +++ b/librz/debug/p/debug_io.c @@ -157,13 +157,6 @@ RzDebugPlugin rz_debug_plugin_io = { .reg_profile = __io_reg_profile, .step_over = __io_step_over, .canstep = 1, -#if 0 - .init = __esil_init, - .contsc = __esil_continue_syscall, - .detach = &__esil_detach, - .stop = __esil_stop, - .breakpoint = &__esil_breakpoint, -#endif }; #ifndef RZ_PLUGIN_INCORE diff --git a/librz/debug/p/native/maps/darwin.c b/librz/debug/p/native/maps/darwin.c index c23115cdc5a..a19a0d44ec2 100644 --- a/librz/debug/p/native/maps/darwin.c +++ b/librz/debug/p/native/maps/darwin.c @@ -90,13 +90,6 @@ static RzList *ios_dbg_maps(RzDebug *dbg) { #else size = osize = 4096; #endif -#if 0 - if (dbg->pid == 0) { - vm_address_t base = get_kernel_base (task); - eprintf ("Kernel Base Address: 0x%"PFMT64x"\n", (ut64)base); - return NULL; - } -#endif kern_return_t kr; for (;;) { @@ -173,159 +166,9 @@ static RzList *ios_dbg_maps(RzDebug *dbg) { return list; } -#if 0 -// TODO: this loop MUST be cleaned up -static RzList *osx_dbg_maps (RzDebug *dbg) { - RzDebugMap *mr; - char buf[1024]; - int i, print; - kern_return_t kret; - vm_region_basic_info_data_64_t info, prev_info; - mach_vm_address_t prev_address; - mach_vm_size_t size, prev_size; - mach_port_t object_name; - mach_msg_type_number_t count; - int nsubregions = 0; - int num_printed = 0; - size_t address = 0; - task_t task = pid_to_task (dbg->pid); - RzList *list = rz_list_new (); - // XXX: wrong for 64bits -/* - count = VM_REGION_BASIC_INFO_COUNT_64; - kret = mach_vm_region (pid_to_task (dbg->pid), &address, &size, VM_REGION_BASIC_INFO_64, - (vm_region_info_t) &info, &count, &object_name); - if (kret != KERN_SUCCESS) { - printf("No memory regions.\n"); - return; - } - memcpy (&prev_info, &info, sizeof (vm_region_basic_info_data_64_t)); -*/ -#if __arm64__ || __aarch64__ - size = 16384; // according to frida -#else - size = 4096; -#endif - memset (&prev_info, 0, sizeof (prev_info)); - prev_address = address; - prev_size = size; - nsubregions = 1; - - for (i=0; ; i++) { - int done = 0; - - address = prev_address + prev_size; - print = 0; - - if (prev_size==0) - break; - /* Check to see if address space has wrapped around. */ - if (address == 0) - done = 1; - - if (!done) { - count = VM_REGION_BASIC_INFO_COUNT_64; - kret = mach_vm_region (task, (mach_vm_address_t *)&address, - &size, VM_REGION_BASIC_INFO_64, - (vm_region_info_t) &info, &count, &object_name); - if (kret != KERN_SUCCESS) { - size = 0; - print = done = 1; - } - } - - if (address != prev_address + prev_size) - print = 1; - - if ((info.protection != prev_info.protection) - || (info.max_protection != prev_info.max_protection) - || (info.inheritance != prev_info.inheritance) - || (info.shared != prev_info.reserved) - || (info.reserved != prev_info.reserved)) - print = 1; - -//#if __OSX_AVAILABLE_STARTING(__MAC_10_5, __IPHONE_2_0) - { - char module_name[1024]; - module_name[0] = 0; - int ret = proc_regionfilename (dbg->pid, address, module_name, sizeof (module_name)); - module_name[ret] = 0; - -#define xwrz_testwx(x) ((x & 1) << 2) | (x & 2) | ((x & 4) >> 2) - if (print && size>0 && prev_info.inheritance != VM_INHERIT_SHARE) { - snprintf (buf, sizeof (buf), "%s %02x %s/%s/%s %s", - rz_str_rwx_i (xwrz_testwx (prev_info.max_protection)), i, - unparse_inheritance (prev_info.inheritance), - prev_info.shared ? "shar" : "priv", - prev_info.reserved ? "reserved" : "not-reserved", - module_name); - // TODO: MAPS can have min and max protection rules - // :: prev_info.max_protection - mr = rz_debug_map_new (buf, prev_address, prev_address+prev_size, - xwrz_testwx (prev_info.protection), 0); - if (!mr) { - eprintf ("Cannot create rz_debug_map_new\n"); - break; - } - mr->file = rz_str_dup (module_name); - rz_list_append (list, mr); - } -} -#if 0 - if (1==0 && rest) { /* XXX never pritn this info here */ - addr = 0LL; - addr = (ut64) (ut32) prev_address; - if (num_printed == 0) - fprintf(stderr, "Region "); - else fprintf(stderr, " ... "); - fprintf(stderr, " 0x%08llx - 0x%08llx %s (%s) %s, %s, %s", - addr, addr + prev_size, - unparse_protection (prev_info.protection), - unparse_protection (prev_info.max_protection), - unparse_inheritance (prev_info.inheritance), - prev_info.shared ? "shared" : " private", - prev_info.reserved ? "reserved" : "not-reserved"); - - if (nsubregions > 1) - fprintf(stderr, " (%d sub-regions)", nsubregions); - - fprintf(stderr, "\n"); - - prev_address = address; - prev_size = size; - memcpy (&prev_info, &info, sizeof (vm_region_basic_info_data_64_t)); - nsubregions = 1; - - num_printed++; - } else { -#endif -#if 0 - prev_size += size; - nsubregions++; -#else - prev_address = address; - prev_size = size; - memcpy (&prev_info, &info, sizeof (vm_region_basic_info_data_64_t)); - nsubregions = 1; - - num_printed++; -#endif - // } - } - return list; -} -#endif - static RzList *darwin_dbg_maps(RzDebug *dbg) { // return osx_dbg_maps (dbg); return ios_dbg_maps(dbg); -#if 0 - const char *osname = dbg->analysis->syscall->os; - if (osname && !strcmp (osname, "ios")) { - return ios_dbg_maps (dbg); - } - return osx_dbg_maps (dbg); -#endif } #endif diff --git a/librz/debug/p/native/xnu/xnu_debug.c b/librz/debug/p/native/xnu/xnu_debug.c index b5f05c680fa..fccdbb02697 100644 --- a/librz/debug/p/native/xnu/xnu_debug.c +++ b/librz/debug/p/native/xnu/xnu_debug.c @@ -525,14 +525,6 @@ RzList *xnu_thread_list(RzDebug *dbg, int pid, RzList *list) { return list; } -#if 0 -static vm_prot_t unix_prot_to_darwin(int prot) { - return ((prot & 1 << 4) ? VM_PROT_READ : 0 | - (prot & 1 << 2) ? VM_PROT_WRITE : 0 | - (prot & 1 << 1) ? VM_PROT_EXECUTE : 0); -} -#endif - int xnu_map_protect(RzDebug *dbg, ut64 addr, int size, int perms) { rz_return_val_if_fail(dbg && dbg->plugin_data, false); task_t task = pid_to_task(dbg->plugin_data, dbg->tid); @@ -770,10 +762,6 @@ static int xnu_write_mem_maps_to_buffer(RzXnuDebug *ctx, RzBuffer *buffer, RzLis } /* Acording to osxbook, the check should be like this: */ -#if 0 - if ((maxprot & VM_PROT_READ) == VM_PROT_READ && - (vbr.user_tag != VM_MEMORY_IOKIT)) { -#endif if ((curr_map->perm & VM_PROT_READ) == VM_PROT_READ) { vm_map_size_t tmp_size = curr_map->size; @@ -969,16 +957,6 @@ RzDebugPid *xnu_get_pid(int pid) { char *curr_arg, *start_args, *iter_args, *end_args; char *procargs = NULL; char psname[4096]; -#if 0 - /* Get the maximum process arguments size. */ - mib[0] = CTL_KERN; - mib[1] = KERN_ARGMAX; - size = sizeof(argmax); - if (sysctl (mib, 2, &argmax, &size, NULL, 0) == -1) { - eprintf ("sysctl() error on getting argmax\n"); - return NULL; - } -#endif uid = uidFromPid(pid); /* Allocate space for the arguments. */ @@ -1019,13 +997,6 @@ RzDebugPid *xnu_get_pid(int pid) { return NULL; } - // TODO: save the environment variables to envlist as well - // Skip over the exec_path and '\0' characters. - // XXX: fix parsing -#if 0 - while (iter_args < end_args && *iter_args != '\0') { iter_args++; } - while (iter_args < end_args && *iter_args == '\0') { iter_args++; } -#endif if (iter_args == end_args) { free(procargs); return NULL; @@ -1313,13 +1284,6 @@ RzList *xnu_dbg_maps(RzDebug *dbg, int only_modules) { size = osize = 16384; #else size = osize = 4096; -#endif -#if 0 - if (dbg->pid == 0) { - vm_address_t base = get_kernel_base (task); - eprintf ("Kernel Base Address: 0x%"PFMT64x"\n", (ut64)base); - return NULL; - } #endif RzList *list = rz_list_new(); if (!list) { diff --git a/librz/debug/pid.c b/librz/debug/pid.c index 2fc96cb184e..46d4b0b5fb1 100644 --- a/librz/debug/pid.c +++ b/librz/debug/pid.c @@ -36,24 +36,6 @@ RZ_API int rz_debug_pid_parent(RzDebugPid *pid) { return 0; } -#if 0 -RZ_API int rz_debug_pid_del(struct rz_debug_t *dbg) { - // kill da child - return true; -} - -/* threads */ -RZ_API int rz_debug_pid_add_thread(struct rz_debug_t *dbg) { - // create a thread in process - return true; -} - -RZ_API int rz_debug_pid_del_thread(struct rz_debug_t *dbg) { - // kill a thread in process - return true; -} -#endif - /* status */ RZ_API int rz_debug_pid_set_state(struct rz_debug_t *dbg, int status) { return true; diff --git a/librz/egg/egg_lang.c b/librz/egg/egg_lang.c index 70ce4b18305..0d858f8870e 100644 --- a/librz/egg/egg_lang.c +++ b/librz/egg/egg_lang.c @@ -190,35 +190,6 @@ static void rcc_reset_callname(RzEgg *egg) { #define FRAME_END_FMT "__%d_%d_end_frame%d" #endif -#if 0 -static char *get_frame_label(int type) { - static char label[128]; - int nf = egg->lang.nfunctions; - int nb = egg->lang.nbrackets; - int ct = context; - /* TODO: this type hack to substruct nb and ctx looks weird */ -#if 1 - if (type == 1) { - nb--; - } else if (type == 2) { - ct--; - } -#endif - /* THIS IS GAS_ONLY */ - snprintf (label, sizeof (label), FRAME_FMT, nf, nb, ct); - return label; -} - -static char *get_end_frame_label(RzEgg *egg) { - static char label[128]; - snprintf (label, sizeof (label) - 1, FRAME_END_FMT, - egg->lang.nfunctions, egg->lang.nbrackets, context - 1); -// eprintf ("--> (egg->lang.endframe: %d %d %d)\n", egg->lang.nfunctions, egg->lang.nbrackets, context); - // snprintf (label, sizeof (label)-1, "frame_end_%d_%d", egg->lang.nfunctions, egg->lang.nbrackets); - return label; -} -#endif - static const char *find_alias(RzEgg *egg, const char *str) { // do not forget to free return strings to avoid memory leak char *p = (char *)str; @@ -734,17 +705,6 @@ static void rcc_fun(RzEgg *egg, const char *str) { } } -#if 0 -static void shownested(void) { - int i; - eprintf ("[[[NESTED %d]]] ", context); - for (i = 0; egg->lang.nested[i]; i++) { - eprintf ("%s ", egg->lang.nested[i]); - } - eprintf ("\n"); -} -#endif - static void set_nested(RzEgg *egg, const char *s) { int i = 0; if (CTX < 1) { @@ -798,24 +758,7 @@ static void rcc_context(RzEgg *egg, int delta) { const char *elm = skipspaces(egg->lang.elem); // const char *cn = callname; // seems cn is useless in nowadays content -// if (egg->lang.nested[context-1]) -#if 0 - if (delta < 0 && context > 0) { - eprintf ("close bracket foo!!!\n"); - shownested (); - cn = rz_str_dup (egg->lang.nested[context - 1]); - eprintf ("STATEMENT cn=(%s) idx=%d (%s)\n", cn, context - 1, egg->lang.nested[context - 1]); - eprintf ("CNTXXXPUSH (%s)\n", egg->lang.ctxpush[context - 1]); -#if 0 - if (!strcmp (cn, "while")) { - emit->while_end (egg, get_frame_label (context - 1)); - // char *var = get_frame_label (0); - // emit->jmp (egg, var, 0); - return; - } -#endif - } -#endif + // if (egg->lang.nested[context-1]) // eprintf ("ELEM (%s)\n", elm); // eprintf ("END BLOCK %d, (%s)\n", context, egg->lang.nested[context-1]); // eprintf ("CN = (%s) %d (%s) delta=%d\n", cn, context, egg->lang.nested[context-1], delta); @@ -1056,24 +999,6 @@ static void rcc_next(RzEgg *egg) { } sprintf(var, "__begin_%d_%d_%d\n", egg->lang.nfunctions, CTX, egg->lang.nestedi[CTX - 1]); e->while_end(egg, var); // get_frame_label (1)); -#if 0 - eprintf ("------------------------------------------ lastctx: %d\n", egg->lang.lastctxdelta); - // TODO: the pushvar is required for the if(){}while(); constructions - // char *pushvar = egg->lang.ctxpush[context+egg->lang.nbrackets-1]; - /* TODO: support to compare more than one expression (LOGICAL OR) */ - rcc_printf (" pop %%eax\n"); - rcc_printf (" cmp $0, %%eax\n"); // XXX MUST SUPPORT != 0 COMPARE HERE - /* TODO : Simplify!! */ - // if (pushvar) - // printf(" push %s /* while push */\n", pushvar); - if (egg->lang.lastctxdelta < 0) { - rcc_printf (" jnz %s\n", get_frame_label (1)); - } else { - rcc_printf (" jnz %s\n", get_frame_label (0)); - } - // if (pushvar) - // printf(" pop %%"RZ_AX" /* while pop */\n"); -#endif egg->lang.nargs = 0; } else { for (i = 0; i < egg->lang.nsyscalls; i++) { diff --git a/librz/egg/emit_arm.c b/librz/egg/emit_arm.c index 9bdc9ce32b9..ba97cd86c7b 100644 --- a/librz/egg/emit_arm.c +++ b/librz/egg/emit_arm.c @@ -280,12 +280,7 @@ static void emit_mathop(RzEgg *egg, int ch, int vs, int type, const char *eq, co if (!p) { p = RZ_AX; } -#if 0 - // TODO: - eprintf ("TYPE = %c\n", type); - eprintf (" %s%c %c%s, %s\n", op, vs, type, eq, p); - eprintf (" %s %s, [%s]\n", op, p, eq); -#endif + if (type == '*') { rz_egg_printf(egg, " %s %s, [%s]\n", op, p, eq); } else { diff --git a/librz/egg/emit_trace.c b/librz/egg/emit_trace.c index 700d2066496..95ce354c8c7 100644 --- a/librz/egg/emit_trace.c +++ b/librz/egg/emit_trace.c @@ -169,12 +169,7 @@ static void emit_mathop(RzEgg *egg, int ch, int vs, int type, const char *eq, co if (!p) { p = RZ_AX; } -#if 0 - // TODO: - eprintf ("TYPE = %c\n", type); - eprintf (" %s%c %c%s, %s\n", op, vs, type, eq, p); - eprintf (" %s %s, [%s]\n", op, p, eq); -#endif + if (type == '*') { rz_egg_printf(egg, "%s (%s, [%s])\n", op, p, eq); } else { diff --git a/librz/egg/emit_x86.c b/librz/egg/emit_x86.c index 42e25d8bb26..ff4200a63fb 100644 --- a/librz/egg/emit_x86.c +++ b/librz/egg/emit_x86.c @@ -213,24 +213,6 @@ static void emit_string(RzEgg *egg, const char *dstvar, const char *str, int j) free(p); #undef BPOFF -#if 0 - char *p, str2[64]; - int i, oj = j; - for (i=0; imode = RZ_SEARCH_MODE_LAST; // ensures it is always invalid + s->string_max = RZ_SEARCH_DEFAULT_STRING_MAX; + s->string_min = RZ_SEARCH_DEFAULT_STRING_MIN; + s->hits = rz_list_newf(free); + s->kws = rz_list_newf((RzListFree)rz_search_keyword_free); + return s->kws && s->hits; +} + +/** + * \param s The RzSearch structure to finalize + */ +RZ_API void rz_search_fini(RZ_NONNULL RzSearch *s) { + rz_return_if_fail(s); + + RZ_FREE_CUSTOM(s->hits, rz_list_free); + RZ_FREE_CUSTOM(s->kws, rz_list_free); + // iob.io is supposed to be a weak reference + // RZ_FREE_CUSTOM(s->iob.io, rz_io_free); + RZ_FREE(s->data); + RZ_FREE(s->prefix); +} -RZ_API RzSearch *rz_search_new(int mode) { +/** + * \brief Allocates and initialize RzSearch + * + * \param mode The RzSearch mode + * + * \return On success returns a valid pointer, otherwise NULL. + */ +RZ_API RZ_OWN RzSearch *rz_search_new(rz_search_mode mode) { RzSearch *s = RZ_NEW0(RzSearch); - if (!s) { - return NULL; - } - if (!rz_search_set_mode(s, mode)) { - free(s); - eprintf("Cannot init search for mode %d\n", mode); - return false; - } - s->inverse = false; - s->data = NULL; - s->user = NULL; - s->callback = NULL; - s->align = 0; - s->distance = 0; - s->contiguous = 0; - s->overlap = false; - s->pattern_size = 0; - s->string_max = 255; - s->string_min = 3; - s->hits = rz_list_newf(free); - s->maxhits = 0; - // TODO: review those mempool sizes. ensure never gets NULL - s->kws = rz_list_newf(free); - if (!s->kws) { + if (!s || + !rz_search_init(s) || + !rz_search_set_mode(s, mode)) { rz_search_free(s); return NULL; } - s->kws->free = (RzListFree)rz_search_keyword_free; return s; } -RZ_API RzSearch *rz_search_free(RzSearch *s) { +/** + * \brief Deallocates a RzSearch struct. + * + * \param s The struct to deallocate + */ +RZ_API void rz_search_free(RZ_NULLABLE RzSearch *s) { if (!s) { return NULL; } @@ -61,15 +81,6 @@ RZ_API RzSearch *rz_search_free(RzSearch *s) { return NULL; } -RZ_API int rz_search_set_string_limits(RzSearch *s, ut32 min, ut32 max) { - if (max < min) { - return false; - } - s->string_min = min; - s->string_max = max; - return true; -} - RZ_API int rz_search_strings_update(RzSearch *s, ut64 from, const ut8 *buf, int len) { rz_return_val_if_fail(s && buf && len, -1); @@ -147,13 +158,13 @@ RZ_API int rz_search_hit_new(RzSearch *s, RzSearchKeyword *kw, ut64 addr) { if (!s->contiguous) { if (kw->last && addr == kw->last) { kw->count--; - kw->last = s->bckwrds ? addr : addr + kw->keyword_length; + kw->last = s->backwards ? addr : addr + kw->keyword_length; eprintf("0x%08" PFMT64x " Sequential hit ignored.\n", addr); return 1; } } // kw->last is used by string search, the right endpoint of last match (forward search), to honor search.overlap - kw->last = s->bckwrds ? addr : addr + kw->keyword_length; + kw->last = s->backwards ? addr : addr + kw->keyword_length; if (s->callback) { int ret = s->callback(kw, s->user, addr); @@ -180,7 +191,7 @@ RZ_API int rz_search_deltakey_update(RzSearch *s, ut64 from, const ut8 *buf, int RzListIter *iter; int longest = 0, i, j; RzSearchKeyword *kw; - RzSearchLeftover *left; + SearchLeftover *left; const int old_nhits = s->nhits; rz_list_foreach (s->kws, iter, kw) { longest = RZ_MAX(longest, kw->keyword_length + 1); @@ -194,13 +205,13 @@ RZ_API int rz_search_deltakey_update(RzSearch *s, ut64 from, const ut8 *buf, int left->len = 0; } } else { - left = malloc(sizeof(RzSearchLeftover) + (size_t)2 * (longest - 1)); + left = malloc(sizeof(SearchLeftover) + (size_t)2 * (longest - 1)); if (!left) { return -1; } s->data = left; left->len = 0; - if (s->bckwrds) { + if (s->backwards) { rz_list_foreach (s->kws, iter, kw) { ut8 *i = kw->bin_keyword, *j = kw->bin_keyword + kw->keyword_length; for (; i < j; i++) { @@ -209,7 +220,7 @@ RZ_API int rz_search_deltakey_update(RzSearch *s, ut64 from, const ut8 *buf, int } } } - if (s->bckwrds) { + if (s->backwards) { // XXX Change function signature from const ut8 * to ut8 * ut8 *i = (ut8 *)buf, *j = i + len; while (i < j) { @@ -223,9 +234,9 @@ RZ_API int rz_search_deltakey_update(RzSearch *s, ut64 from, const ut8 *buf, int memcpy(left->data + left->len, buf, len1 - left->len); rz_list_foreach (s->kws, iter, kw) { ut8 *a = kw->bin_keyword; - i = s->overlap || !kw->count ? 0 : s->bckwrds ? kw->last - from < left->len ? from + left->len - kw->last : 0 - : from - kw->last < left->len ? kw->last + left->len - from - : 0; + i = s->overlap || !kw->count ? 0 : s->backwards ? kw->last - from < left->len ? from + left->len - kw->last : 0 + : from - kw->last < left->len ? kw->last + left->len - from + : 0; for (; i + kw->keyword_length < len1 && i < left->len; i++) { if ((ut8)(left->data[i + 1] - left->data[i]) == a[0]) { j = 1; @@ -233,8 +244,8 @@ RZ_API int rz_search_deltakey_update(RzSearch *s, ut64 from, const ut8 *buf, int j++; } if (j == kw->keyword_length) { - int t = rz_search_hit_new(s, kw, s->bckwrds ? from - kw->keyword_length - 1 - i + left->len : from + i - left->len); - kw->last += s->bckwrds ? 0 : 1; + int t = rz_search_hit_new(s, kw, s->backwards ? from - kw->keyword_length - 1 - i + left->len : from + i - left->len); + kw->last += s->backwards ? 0 : 1; if (!t) { return -1; } @@ -247,9 +258,9 @@ RZ_API int rz_search_deltakey_update(RzSearch *s, ut64 from, const ut8 *buf, int } } } - i = s->overlap || !kw->count ? 0 : s->bckwrds ? from > kw->last ? from - kw->last : 0 - : from < kw->last ? kw->last - from - : 0; + i = s->overlap || !kw->count ? 0 : s->backwards ? from > kw->last ? from - kw->last : 0 + : from < kw->last ? kw->last - from + : 0; for (; i + kw->keyword_length < len; i++) { if ((ut8)(buf[i + 1] - buf[i]) == a[0]) { j = 1; @@ -257,8 +268,8 @@ RZ_API int rz_search_deltakey_update(RzSearch *s, ut64 from, const ut8 *buf, int j++; } if (j == kw->keyword_length) { - int t = rz_search_hit_new(s, kw, s->bckwrds ? from - kw->keyword_length - 1 - i : from + i); - kw->last += s->bckwrds ? 0 : 1; + int t = rz_search_hit_new(s, kw, s->backwards ? from - kw->keyword_length - 1 - i : from + i); + kw->last += s->backwards ? 0 : 1; if (!t) { return -1; } @@ -283,56 +294,11 @@ RZ_API int rz_search_deltakey_update(RzSearch *s, ut64 from, const ut8 *buf, int left->len = longest - 1; memcpy(left->data, buf + len - longest + 1, longest - 1); } - left->end = s->bckwrds ? from - len : from + len; + left->end = s->backwards ? from - len : from + len; return s->nhits - old_nhits; } -#if 0 -// Boyer-Moore-Horspool pattern matching -// Supported search variants: icase, overlap -static int rz_search_horspool(RzSearch *s, RzSearchKeyword *kw, ut64 from, const ut8 *buf, int len) { - ut64 bad_char_shift[UT8_MAX + 1]; - int i, j, m = kw->keyword_length - 1, count = 0; - ut8 ch; - - for (i = 0; i < RZ_ARRAY_SIZE (bad_char_shift); i++) { - bad_char_shift[i] = kw->keyword_length; - } - for (i = 0; i < m; i++) { - ch = kw->bin_keyword[i]; - bad_char_shift[kw->icase ? tolower (ch) : ch] = m - i; - } - - for (i = 0; i + m < len; ) { - next: - for (j = m; ; j--) { - ut8 a = buf[i + j], b = kw->bin_keyword[j]; - if (kw->icase) { - a = tolower (a); - b = tolower (b); - } - if (a != b) break; - if (i == 0) { - if (!rz_search_hit_new (s, kw, from + i)) { - return -1; - } - kw->count++; - count++; - if (!s->overlap) { - i += kw->keyword_length; - goto next; - } - } - } - ch = buf[i + m]; - i += bad_char_shift[kw->icase ? tolower (ch) : ch]; - } - - return false; -} -#endif - static bool brute_force_match(RzSearch *s, RzSearchKeyword *kw, const ut8 *buf, int i) { int j = 0; if (s->distance) { // slow path, more work in the loop @@ -394,7 +360,7 @@ static bool brute_force_match(RzSearch *s, RzSearchKeyword *kw, const ut8 *buf, RZ_API int rz_search_mybinparse_update(RzSearch *s, ut64 from, const ut8 *buf, int len) { RzSearchKeyword *kw; RzListIter *iter; - RzSearchLeftover *left; + SearchLeftover *left; int longest = 0, i; const int old_nhits = s->nhits; @@ -410,14 +376,14 @@ RZ_API int rz_search_mybinparse_update(RzSearch *s, ut64 from, const ut8 *buf, i left->len = 0; } } else { - left = malloc(sizeof(RzSearchLeftover) + (size_t)2 * (longest - 1)); + left = malloc(sizeof(SearchLeftover) + (size_t)2 * (longest - 1)); if (!left) { return -1; } s->data = left; left->len = 0; } - if (s->bckwrds) { + if (s->backwards) { // XXX Change function signature from const ut8 * to ut8 * ut8 *i = (ut8 *)buf, *j = i + len; while (i < j) { @@ -430,12 +396,12 @@ RZ_API int rz_search_mybinparse_update(RzSearch *s, ut64 from, const ut8 *buf, i ut64 len1 = left->len + RZ_MIN(longest - 1, len); memcpy(left->data + left->len, buf, len1 - left->len); rz_list_foreach (s->kws, iter, kw) { - i = s->overlap || !kw->count ? 0 : s->bckwrds ? kw->last - from < left->len ? from + left->len - kw->last : 0 - : from - kw->last < left->len ? kw->last + left->len - from - : 0; + i = s->overlap || !kw->count ? 0 : s->backwards ? kw->last - from < left->len ? from + left->len - kw->last : 0 + : from - kw->last < left->len ? kw->last + left->len - from + : 0; for (; i + kw->keyword_length <= len1 && i < left->len; i++) { if (brute_force_match(s, kw, left->data, i) != s->inverse) { - int t = rz_search_hit_new(s, kw, s->bckwrds ? from - kw->keyword_length - i + left->len : from + i - left->len); + int t = rz_search_hit_new(s, kw, s->backwards ? from - kw->keyword_length - i + left->len : from + i - left->len); if (!t) { return -1; } @@ -447,12 +413,12 @@ RZ_API int rz_search_mybinparse_update(RzSearch *s, ut64 from, const ut8 *buf, i } } } - i = s->overlap || !kw->count ? 0 : s->bckwrds ? from > kw->last ? from - kw->last : 0 - : from < kw->last ? kw->last - from - : 0; + i = s->overlap || !kw->count ? 0 : s->backwards ? from > kw->last ? from - kw->last : 0 + : from < kw->last ? kw->last - from + : 0; for (; i + kw->keyword_length <= len; i++) { if (brute_force_match(s, kw, buf, i) != s->inverse) { - int t = rz_search_hit_new(s, kw, s->bckwrds ? from - kw->keyword_length - i : from + i); + int t = rz_search_hit_new(s, kw, s->backwards ? from - kw->keyword_length - i : from + i); if (!t) { return -1; } @@ -476,7 +442,7 @@ RZ_API int rz_search_mybinparse_update(RzSearch *s, ut64 from, const ut8 *buf, i left->len = longest - 1; memcpy(left->data, buf + len - longest + 1, longest - 1); } - left->end = s->bckwrds ? from - len : from + len; + left->end = s->backwards ? from - len : from + len; return s->nhits - old_nhits; }