Beispiel #1
0
/* reference (accurate but expensive) disassembly */
const char* emu_disasm_ref(unsigned int pc, uint8_t bits) {
    if (!rasm) {
        /* rasm2 configuration defaults */
        static const char arch[]    = {"arm"};   /* ARM ISA */
        static const int big_endian = 0;         /* ARMv7 is little endian */

        rasm = r_asm_new();
        /* R_API int r_asm_setup(RAsm *a, const char *arch, int bits, int big_endian); */
        r_asm_setup(rasm, arch, bits, big_endian);
    }
    assert(rasm != NULL);

    r_asm_set_bits(rasm, bits);
    r_asm_set_big_endian(rasm, bits == 16); /* 16: big endian, 32: little endian */

    /* printf("emu: %0lx: %0x\n", cpu(pc), *(unsigned int *)cpu(pc)); // if all else fails */
    static RAsmOp rop;

    const int len = bits / 8;         /* disassemble 4 bytes (A32) or 2 bytes (T16) */
    uint32_t ins = *(const uint32_t *)pc;
    if (bits == 16) ins &= 0xffff;

    r_asm_set_pc(rasm, pc);
    // printf("r_asm_disassemble() pc: %x bits: %d len: %d\n", pc, bits, len);
    r_asm_disassemble(rasm, &rop, (const unsigned char *)pc, len);
    printf("disas: %x %x %s\n", pc, ins, rop.buf_asm);

    return rop.buf_asm;
}
Beispiel #2
0
static int config_asmbits_callback(void *user, void *data) {
	const char *asmos, *asmarch;
	RCore *core = (RCore *) user;
	RConfigNode *node = (RConfigNode *) data;
	int ret = r_asm_set_bits (core->assembler, node->i_value);
	if (ret == R_FALSE) {
		RAsmPlugin *h = core->assembler->cur;
		if (h) {
			eprintf ("Cannot set bits %"PFMT64d" to '%s'\n",
				node->i_value, h->name);
		} else {
			eprintf ("e asm.bits: Cannot set value, no plugins defined yet\n");
			ret = R_TRUE;
		}
	}
	if (!r_anal_set_bits (core->anal, node->i_value))
		eprintf ("asm.arch: Cannot setup '%i' bits analysis engine\n", (int)node->i_value);
	if (core->dbg  && core->anal && core->anal->cur)
		r_debug_set_arch (core->dbg, core->anal->cur->arch, node->i_value);

	asmos = r_config_get (core->config, "asm.os");
	asmarch = r_config_get (core->config, "asm.arch");
	if (core && core->anal)
	if (!r_syscall_setup (core->anal->syscall, asmarch,
			asmos, node->i_value)) {
		//eprintf ("asm.arch: Cannot setup syscall '%s/%s' from '%s'\n",
		//	node->value, asmos, R2_LIBDIR"/radare2/"R2_VERSION"/syscall");
	}
	return ret;
}