예제 #1
0
파일: io.c 프로젝트: adamharder/radare2
R_API boolt r_core_seek(RCore *core, ut64 addr, boolt rb) {
	RIOSection *newsection;
	ut64 old = core->offset;
	ut64 ret;

	/* XXX unnecesary call */
	//r_io_set_fd (core->io, core->file->fd);
	core->io->section = core->section; // HACK
	ret = r_io_seek (core->io, addr, R_IO_SEEK_SET);
	newsection = core->io->section;

	if (ret == UT64_MAX) {
		//eprintf ("RET =%d %llx\n", ret, addr);
		/*
		   XXX handle read errors correctly
		   if (core->ffio) {
		   core->offset = addr;
		   } else return R_FALSE;
		 */
		//core->offset = addr;
		if (!core->io->va)
			return R_FALSE;
		memset (core->block, 0xff, core->blocksize);
	} else core->offset = addr;
	if (rb) {
		ret = r_core_block_read (core, 0);
		if (core->ffio) {
			if (ret<1 || ret > core->blocksize)
				memset (core->block, 0xff, core->blocksize);
			else memset (core->block+ret, 0xff, core->blocksize-ret);
			ret = core->blocksize;
			core->offset = addr;
		} else {
			if (ret<1) {
				core->offset = old;
				//eprintf ("Cannot read block at 0x%08"PFMT64x"\n", addr);
			}
		}
	}
	if (core->section != newsection) {//&& core->io->section->arch) {
		int bits = 0;// = core->io->section->bits;
		const char *arch = r_io_section_get_archbits (core->io, core->offset, &bits);
		if (arch && bits) {
			r_config_set (core->config, "asm.arch", arch);
			r_config_set_i (core->config, "asm.bits", bits);
		}
		core->section = core->io->section;
	}
	return (ret==-1)? R_FALSE: R_TRUE;
}
예제 #2
0
파일: cio.c 프로젝트: f0829/radare2
R_API void r_core_seek_archbits(RCore *core, ut64 addr) {
	int bits = 0;
	const char *arch = r_io_section_get_archbits (core->io, addr, &bits);
	if (!bits && !core->fixedbits) {
		//if we found bits related with anal hints pick it up
		__choose_bits_anal_hints (core, addr, &bits);
	}
	if (bits && !core->fixedbits) {
		r_config_set_i (core->config, "asm.bits", bits);
	}
	if (arch && !core->fixedarch) {
		r_config_set (core->config, "asm.arch", arch);
	}
}