Example #1
0
bool test_r_list_values(void) {
	RList* list = r_list_new ();
	intptr_t test1 = 0x12345;
	intptr_t test2 = 0x88888;
	r_list_append (list, (void*)test1);
	r_list_append (list, (void*)test2);
	int top1 = (intptr_t)r_list_pop (list);
	int top2 = (intptr_t)r_list_pop (list);
	mu_assert_eq(top1, 0x88888, "first value not 0x88888");
	mu_assert_eq(top2, 0x12345, "first value not 0x12345");
	r_list_free (list);
	mu_end;
}
Example #2
0
static RList* entries(RBinArch *arch) {
	RList* ret = r_list_new ();;
	RBinAddr *ptr = NULL;
	if (!ret) return NULL;
	ret->free = free;
	if (!memcmp (arch->buf+0x30, "\x00\x00\x00\x00\x20\x73\x74\x64\x6f\x75\x74\x20\x21\x55\x0c\xcd", 16)) {
		if ((ptr = R_NEW (RBinAddr))) {
			ptr->rva = ptr->offset = 0x9a;
			r_list_append (ret, ptr);
		}
	}
	return ret;
}
Example #3
0
static RList* sections(RBinFile *arch) {
	RBinSection *ptr = NULL;
	RList *ret = NULL;
	int rc;

	if (!(ret = r_list_new ()))
		return NULL;
	ret->free = free;
	rc = r_buf_fread_at (arch->buf, 0, (ut8*)&sb, "10i", 1);
	if (!rc) return false;

	// add text segment
	if (!(ptr = R_NEW0 (RBinSection)))
		return ret;
	strncpy (ptr->name, "text", R_BIN_SIZEOF_STRINGS);
	ptr->size = sb.psize;
	ptr->vsize = sb.psize;
	ptr->paddr = sb.paddr + 40;
	ptr->vaddr = sb.vaddr;
	ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_EXECUTABLE | R_BIN_SCN_MAP; // r-x
	ptr->add = true;
	ptr->has_strings = true;
	r_list_append (ret, ptr);

	if (!(ptr = R_NEW0 (RBinSection)))
		return ret;
	strncpy (ptr->name, "sign", R_BIN_SIZEOF_STRINGS);
	ptr->size = sb.sign_sz;
	ptr->vsize = sb.sign_sz;
	ptr->paddr = sb.sign_va - sb.vaddr;
	ptr->vaddr = sb.sign_va;
	ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_MAP; // r--
	ptr->has_strings = true;
	ptr->add = true;
	r_list_append (ret, ptr);

	if (sb.cert_sz && sb.cert_va > sb.vaddr) {
		if (!(ptr = R_NEW0 (RBinSection)))
			return ret;
		strncpy (ptr->name, "cert", R_BIN_SIZEOF_STRINGS);
		ptr->size = sb.cert_sz;
		ptr->vsize = sb.cert_sz;
		ptr->paddr = sb.cert_va - sb.vaddr;
		ptr->vaddr = sb.cert_va;
		ptr->srwx = R_BIN_SCN_READABLE | R_BIN_SCN_MAP; // r--
		ptr->has_strings = true;
		ptr->add = true;
		r_list_append (ret, ptr);
	}
	return ret;
}
Example #4
0
// XXX: Do this work correctly?
static RList *backtrace_x86_64_anal(RDebug *dbg, ut64 at) {
	int i;
	ut8 buf[8];
	RDebugFrame *frame;
	ut64 ptr, ebp2 = UT64_MAX;
	ut64 _rip, _rbp;
	RList *list;
	RReg *reg = dbg->reg;
	RIOBind *bio = &dbg->iob;
	RAnalFunction *fcn;

	_rip = r_reg_get_value (reg, r_reg_get (reg, "rip", R_REG_TYPE_GPR));
	if (at == UT64_MAX) {
		//_rsp = r_reg_get_value (reg, r_reg_get (reg, "rsp", R_REG_TYPE_GPR));
		_rbp = r_reg_get_value (reg, r_reg_get (reg, "rbp", R_REG_TYPE_GPR));
	} else {
		_rbp = at;
	}

	list = r_list_new ();
	list->free = free;
	bio->read_at (bio->io, _rip, (ut8*)&buf, 8);

	// TODO : frame->size by using esil to emulate first instructions
	fcn = r_anal_get_fcn_in (dbg->anal, _rip, R_ANAL_FCN_TYPE_NULL);
	if (fcn) {
		frame = R_NEW0 (RDebugFrame);
		frame->addr = _rip;
		frame->size = 0;
		r_list_append (list, frame);
	}

	for (i=1; i<dbg->btdepth; i++) {
		// TODO: make those two reads in a shot
		bio->read_at (bio->io, _rbp, (ut8*)&ebp2, 8);
		if (ebp2 == UT64_MAX)
			break;
		bio->read_at (bio->io, _rbp+8, (ut8*)&ptr, 8);
		if (!ptr || !_rbp)
			break;
		//fcn = r_anal_get_fcn_in (dbg->anal, ptr, R_ANAL_FCN_TYPE_NULL);
		frame = R_NEW0 (RDebugFrame);
		frame->addr = ptr;
		frame->size = 0;
		//frame->name = (fcn && fcn->name) ? strdup (fcn->name) : NULL;
		r_list_append (list, frame);
		_rbp = ebp2;
	}

	return list;
}
Example #5
0
static RList *sections(RBinFile *bf) {
	RList *ret = NULL;
	RBinSection *sections[4] = {
		NULL, NULL, NULL, NULL
	};
	int i, corrupt = false;

	if (!(ret = r_list_new ())) {
		return NULL;
	}

	/* FIRM has always 4 sections, normally the 4th section is not used */
	for (i = 0; i < 4; i++) {
		/* Check if section is used */
		if (loaded_header.sections[i].size) {
			sections[i] = R_NEW0 (RBinSection);
			/* Firmware Type ('0'=ARM9/'1'=ARM11) */
			if (loaded_header.sections[i].type == 0x0) {
				strncpy (sections[i]->name, "arm9", 4);
			} else if (loaded_header.sections[i].type == 0x1) {
				strncpy (sections[i]->name, "arm11", 5);
			} else {
				corrupt = true;
				break;
			}
			sections[i]->size = loaded_header.sections[i].size;
			sections[i]->vsize = loaded_header.sections[i].size;
			sections[i]->paddr = loaded_header.sections[i].offset;
			sections[i]->vaddr = loaded_header.sections[i].address;
			sections[i]->srwx = r_str_rwx ("mrwx");
			sections[i]->add = true;
		}
	}

	/* Append sections or free them if file is corrupt to avoid memory leaks */
	for (i = 0; i < 4; i++) {
		if (sections[i]) {
			if (corrupt) {
				free (sections[i]);
			} else {
				r_list_append (ret, sections[i]);
			}
		}
	}
	if (corrupt) {
		r_list_free (ret);
		return NULL;
	}

	return ret;
}
Example #6
0
static RList* sections(RBinFile *arch) {
    int i;
    RList *ret;
    RBinSection *s;
    DolHeader *dol;
    if (!arch || !arch->o || !arch->o->bin_obj)
        return NULL;
    dol = arch->o->bin_obj;
    if (!(ret = r_list_new ())) {
        return NULL;
    }

    /* text sections */
    for (i=0; i<N_TEXT; i++) {
        if (!dol->text_paddr[i] || !dol->text_vaddr[i])
            continue;
        s = R_NEW0 (RBinSection);
        snprintf (s->name, sizeof (s->name), "text_%d", i);
        s->paddr = dol->text_paddr[i];
        s->vaddr = dol->text_vaddr[i];
        s->size = dol->text_size[i];
        s->vsize = s->size;
        s->srwx = r_str_rwx ("mr-x");
        r_list_append (ret, s);
    }
    /* data sections */
    for (i=0; i<N_DATA; i++) {
        if (!dol->data_paddr[i] || !dol->data_vaddr[i])
            continue;
        s = R_NEW0 (RBinSection);
        snprintf (s->name, sizeof (s->name), "data_%d", i);
        s->paddr = dol->data_paddr[i];
        s->vaddr = dol->data_vaddr[i];
        s->size = dol->data_size[i];
        s->vsize = s->size;
        s->srwx = r_str_rwx ("mr--");
        r_list_append (ret, s);
    }
    /* bss section */
    s = R_NEW0 (RBinSection);
    strcpy (s->name, "bss");
    s->paddr = 0;
    s->vaddr = dol->bss_addr;
    s->size = dol->bss_size;
    s->vsize = s->size;
    s->srwx = r_str_rwx ("-rw-");
    r_list_append (ret, s);

    return ret;
}
Example #7
0
// (in,out)[code,data]
R_API RList *r_anal_xrefs_get (RAnal *anal, ut64 addr) {
	RList *list = r_list_new ();
	list->free = NULL; // XXX
	r_anal_xrefs_from (anal, list, "xref", "code", addr);
	r_anal_xrefs_from (anal, list, "xref", "data", addr);
	r_anal_xrefs_from (anal, list, "ref", "code", addr);
	r_anal_xrefs_from (anal, list, "ref", "data", addr);
	if (r_list_length (list)<1) {
		r_list_free (list);
		list = NULL;
	}

	return list;
}
Example #8
0
static RList* lines(RBinArch *arch) {
	int i;
	char *file = strdup (arch->file);
	RList *list = r_list_new ();
	RBinJavaObj *b = arch->bin_obj;
	file = r_str_replace (file, ".class", ".java", 0);
	for (i=0; i<b->lines.count; i++) {
		RBinDwarfRow *row = R_NEW (RBinDwarfRow);
		r_bin_dwarf_line_new (row, b->lines.addr[i], file, b->lines.line[i]);
		r_list_append (list, row);
	}
	free (file);
	return list;
}
Example #9
0
/* Idea: At first, get all sections in vrange, meanwhile record all unsectioned area and store it via RIORange in a list,
read all sections via mread, resolve maps for unsectioned areas and fill the gaps. last point must always prefere using io->desc*/
R_API int r_io_vread (RIO *io, ut64 vaddr, ut8 *buf, int len) {
	int tmp_len = len;
	ut8 *tmp_buf = buf;
	ut64 vendaddr, maddr, tmp_vaddr = vaddr;
	RIOMap *map;
	RIOSection *section;
	RIORange *range;
	RList *sections, *ranges = NULL, *maps;
	RListIter *iter, *ator;
	if (!io->desc) {
		eprintf ("r_io_vread: desc is NULL, WTF!\n");
		return R_ERROR;
	}
	if (len < 0) {
		eprintf ("r_io_vread: wrong usage; len is smaller than 0. len: %i\n", len);
		return R_FAIL;
	}
	sections = r_io_section_get_in_vaddr_range (io, vaddr, vaddr+len);
	if (!r_list_empty (sections)) {						//check if there is any section
		ranges = r_list_new();
		ranges->free = free;
		r_list_foreach (sections, iter, section) {
			if (section->vaddr==0)
				continue;
			if (section->vaddr > tmp_vaddr) {
				range = r_io_range_new();			//create a new range
				range->from = tmp_vaddr;			//record unsectioned area
				range->to = section->vaddr;
				r_list_append (ranges, range);			//store the range
				tmp_vaddr = section->vaddr;			//prepare for resolving the maddr
				tmp_len -= (tmp_vaddr - vaddr);
				tmp_buf += (tmp_vaddr - vaddr);			//adjust buffer
			}
			vendaddr = tmp_vaddr + tmp_len;				//calculate the virtual end address
			if (vendaddr > (section->vaddr + section->vsize))	//check if the virual end address is in the section too
				vendaddr = section->vaddr + section->vsize;	//if not, size it down
			maddr = tmp_vaddr - section->vaddr + section->offset;	//calculate the map address (address inside the map)
			if (maddr > ( section->offset + section->size)) {	//check if the maddr is inside the physical section, if not, skip some things
			} else {
				if ((vendaddr - section->vaddr + section->offset) > (section->offset + section->size)) {	//check if the virtual part of the section fits into the physical part
					r_io_mread (io, section->fd, maddr, tmp_buf, (section->offset + section->size) - maddr);//if not, read as far as possible
				} else {
					r_io_mread (io, section->fd, maddr, tmp_buf, vendaddr - tmp_vaddr);	//read from the sections fd
				}
			}
			tmp_buf += (vendaddr - tmp_vaddr);			//adjust buffer
			tmp_len -= (vendaddr - tmp_vaddr);			//adjust length
			tmp_vaddr = vendaddr;					//adjust address
		}
	}
Example #10
0
static RList* entries(RBinFile *arch) {
	RList* ret;
	RBinAddr *ptr = NULL;

	if (!(ret = r_list_new ()))
		return NULL;
	ret->free = free;
	if ((ptr = R_NEW0 (RBinAddr))) {
		ptr->paddr = 40 + sb.code_pa;
		ptr->vaddr = 40 + sb.code_pa + sb.vaddr;
		r_list_append (ret, ptr);
	}
	return ret;
}
Example #11
0
static RList *sections(RBinFile *arch) {
	RList *shared = r_list_new ();
	if (!shared) {
		return NULL;
	}
	RList *cobjs = r_list_new ();
	if (!cobjs) {
		return NULL;
	}
	interned_table = r_list_new ();
	if (!interned_table) {
		return NULL;
	}
	r_list_append (shared, cobjs);
	r_list_append (shared, interned_table);
	arch->o->bin_obj = shared;
	RList *sections = r_list_new ();
	if (!sections) {
		return NULL;
	}
	pyc_get_sections (sections, cobjs, arch->buf, version.magic);
	return sections;
}
Example #12
0
static RList* entries(RBinFile *bf) {
	RList *ret;
	RBinAddr *ptr = NULL;
	if (!(ret = r_list_new ())) {
		return NULL;
	}
	if (!(ptr = R_NEW0 (RBinAddr))) {
		return ret;
	}
	ptr->paddr = RAM_START_ADDRESS;
	ptr->vaddr = 0;
	r_list_append (ret, ptr);
	return ret;
}
Example #13
0
static RList* entries(RBinFile *arch) {
	RList* ret;
	RBinAddr *ptr = NULL;

	if (!(ret = r_list_new ()))
		return NULL;
	ret->free = free;
	if ((ptr = R_NEW (RBinAddr))) {
		ptr->paddr = 8*4;
		ptr->vaddr = 8*4;// + baddr (arch);
		r_list_append (ret, ptr);
	}
	return ret;
}
Example #14
0
bool init_pdb_parser(R_PDB *pdb, const char *filename) {
	char *signature = NULL;
	int bytes_read = 0;

	if (!pdb) {
		eprintf ("struct R_PDB is not correct\n");
		goto error;
	}
	if (!pdb->cb_printf) {
		pdb->cb_printf = (PrintfCallback)printf;
	}
	pdb->buf = r_buf_new_slurp (filename);
//	pdb->fp = r_sandbox_fopen (filename, "rb");
//	if (!pdb->fp) {
//		eprintf ("file %s can not be open\n", filename);
//		goto error;
//	}
	signature = (char *)calloc (1, PDB7_SIGNATURE_LEN);
	if (!signature) {
		eprintf ("memory allocation error\n");
		goto error;
	}

	bytes_read = r_buf_read(pdb->buf, (ut8 *)signature, PDB7_SIGNATURE_LEN);
	if (bytes_read != PDB7_SIGNATURE_LEN) {
		eprintf ("file reading error\n");
		goto error;
	}

	r_buf_seek (pdb->buf, 0, 0);

	if (!memcmp (signature, PDB7_SIGNATURE, PDB7_SIGNATURE_LEN)) {
		pdb->pdb_parse = pdb7_parse;
	} else {
		goto error;
	}

	R_FREE (signature);

	pdb->pdb_streams = r_list_new ();
	pdb->stream_map = 0;
	pdb->finish_pdb_parse = finish_pdb_parse;
	pdb->print_types = print_types;
	pdb->print_gvars = print_gvars;
//	printf("init_pdb_parser() finish with success\n");
	return true;
error:
	R_FREE (signature);
	return false;
}
Example #15
0
static RList *entries(RBinFile *bf) {
	RList *ret;
	RBinAddr *ptr = NULL;
	if (!(ret = r_list_new ())) {
		return NULL;
	}
	ret->free = free;
	if ((ptr = R_NEW0 (RBinAddr))) {
		ptr->paddr = 0x80;
		ptr->vaddr = ptr->paddr + baddr (bf);
		r_list_append (ret, ptr);
	}
	return ret;
}
Example #16
0
static RList *sections(RBinFile *arch) {
	RList *ret;
	ut32 ct_omf_sect = 0;
	r_bin_omf_obj *obj = arch->o->bin_obj;

	if (!(ret = r_list_new ()))
		return NULL;

	while (ct_omf_sect < obj->nb_section)
		if (!r_bin_omf_send_sections (ret, \
			obj->sections[ct_omf_sect++], arch->o->bin_obj))
			return ret;
	return ret;
}
Example #17
0
static RList* entries(RBinArch *arch) {
    RList *ret;
    RBinAddr *ptr = NULL;

    if (!(ret = r_list_new ()))
        return NULL;
    ret->free = free;
    if (!(ptr = R_NEW (RBinAddr)))
        return ret;
    memset (ptr, '\0', sizeof (RBinAddr));
    ptr->offset = ptr->rva = 0xffff0;
    r_list_append (ret, ptr);
    return ret;
}
Example #18
0
R_API int r_mixed_add (RMixed *m, void *p) {
	RHashTable *ht;
	RHashTable64 *ht64;
	RList *list = NULL;
	ut64 value;
	int i, size, ret = false;;
	r_list_append (m->list, p);
	for (i=0; i<RMIXED_MAXKEYS; i++) {
		if (!m->keys[i])
			continue;
		size = m->keys[i]->size;
		value = r_mixed_get_value (i, size, p);
		switch (size) {
		case 1: case 2: case 4:
			ht = m->keys[i]->hash.ht;
			list = r_hashtable_lookup (ht, (ut32)value);
			if (!list) {
				list = r_list_new ();
				r_hashtable_insert (ht, (ut32)value, list);
			}
			r_list_append (list, p);
			ret = true;
			break;
		case 8:
			ht64 = m->keys[i]->hash.ht64;
			list = r_hashtable64_lookup (ht64, value);
			if (!list) {
				list = r_list_new ();
				r_hashtable64_insert (ht64, value, list);
			}
			r_list_append (list, p);
			ret = true;
			break;
		}
	}
	return ret;
}
Example #19
0
void parse_dbi_stream(void *parsed_pdb_stream, R_STREAM_FILE *stream_file)
{
	SDbiStream *dbi_stream = (SDbiStream *) parsed_pdb_stream;
	SDBIExHeader *dbi_ex_header = 0;
	int pos = 0;
	char *dbiexhdr_data = 0, *p_tmp = 0;
	int size = 0, sz = 0;
	int i = 0;

	parse_dbi_header (&dbi_stream->dbi_header, stream_file);
	pos += sizeof (SDBIHeader) - 2;	// 2 because enum in C equal to 4, but
									// to read just 2;
	stream_file_seek (stream_file, pos, 0);

	size = dbi_stream->dbi_header.module_size;
	dbiexhdr_data = (char *) malloc(size);
	if (!dbiexhdr_data) return;
	stream_file_read (stream_file, size, dbiexhdr_data);

	dbi_stream->dbiexhdrs = r_list_new();
	p_tmp = dbiexhdr_data;
	while (i < size) {
		dbi_ex_header = (SDBIExHeader *) malloc (sizeof(SDBIExHeader));
		if (!dbi_ex_header) break;
		// TODO: rewrite for signature where can to do chech CAN_READ true?
		sz = parse_dbi_ex_header (p_tmp, size, dbi_ex_header);
		if ((sz % _ALIGN)) {
			sz = sz + (_ALIGN - (sz % _ALIGN));
		}
		i += sz;
		p_tmp += sz;
		r_list_append (dbi_stream->dbiexhdrs, dbi_ex_header);
	}

	free (dbiexhdr_data);

	// "Section Contribution"
	stream_file_seek(stream_file, dbi_stream->dbi_header.seccon_size, 1);
	// "Section Map"
	stream_file_seek(stream_file, dbi_stream->dbi_header.secmap_size, 1);
	// "File Info"
	stream_file_seek(stream_file, dbi_stream->dbi_header.filinf_size, 1);
	// "TSM"
	stream_file_seek(stream_file, dbi_stream->dbi_header.tsmap_size, 1);
	// "EC"
	stream_file_seek(stream_file, dbi_stream->dbi_header.ecinfo_size, 1);

	parse_dbg_header(&dbi_stream->dbg_header, stream_file);
}
Example #20
0
bool test_r_list_del_n(void) {
	RList* list = r_list_new ();
	intptr_t test1 = 0x12345;
	intptr_t test2 = 0x88888;
	r_list_append (list, (void*)test1);
	r_list_append (list, (void*)test2);
	mu_assert_eq (r_list_length (list), 2,
			"list is of length 2 when adding 2 values");
	r_list_del_n (list, 0);
	int top1 = (intptr_t)r_list_pop (list);
	mu_assert_eq(top1, 0x88888,
			"error, first value not 0x88888");
	r_list_free (list);
	mu_end;
}
Example #21
0
static RList* entries(RBinFile *arch) {
	RList *ret;
	RBinAddr *addr;
	DolHeader *dol;
	if (!arch || !arch->o || !arch->o->bin_obj) {
		return NULL;
	}
	ret = r_list_new ();
	addr = R_NEW0 (RBinAddr);
	dol = arch->o->bin_obj;
	addr->vaddr = (ut64)dol->entrypoint;
	addr->paddr = addr->vaddr & 0xFFFF;
	r_list_append (ret, addr);
	return ret;
}
Example #22
0
static RList *r_debug_native_map_get(RDebug *dbg) {
	RIOBdescbg *o = dbg->iob.io->desc->data;
	BfvmCPU *c = o->bfvm;
	RList *list = r_list_new ();
	list->free = (RListFree)r_debug_map_free;
	r_list_append (list, r_debug_map_new (
		"code", 0, 4096, 6, 0));
	r_list_append (list, r_debug_map_new (
		"memory", c->base, c->base+c->size, 6, 0));
	r_list_append (list, r_debug_map_new (
		"screen", c->screen, c->screen+c->screen_size, 6, 0));
	r_list_append (list, r_debug_map_new (
		"input", c->input, c->input+c->input_size, 6, 0));
	return list;
}
Example #23
0
static RList* entries(RBinFile *arch) {
	RList *ret = r_list_new ();
	RBinAddr *ptr = NULL;

	if (arch && arch->buf) {
		if (!ret)
			return NULL;
		ret->free = free;
		if (!(ptr = R_NEW0 (RBinAddr)))
			return ret;
		ptr->paddr = ptr->vaddr = 0x0;
		r_list_append (ret, ptr);
	}
	return ret;
}
Example #24
0
static RList *entries(RBinFile *bf) { // Should be 3 offsets pointed by NMI, RESET, IRQ after mapping && default = 1st CHR
	RList *ret;
	RBinAddr *ptr = NULL;
	if (!(ret = r_list_new ())) {
		return NULL;
	}
	if (!(ptr = R_NEW0 (RBinAddr))) {
		return ret;
	}
	SMD_Header *hdr = (SMD_Header *) (bf->buf->buf + 0x100);
	ut64 baddr = hdr->RomStart;
	ptr->paddr = ptr->vaddr = baddr + 0x100 + sizeof (SMD_Header); // vtable[1];
	r_list_append (ret, ptr);
	return ret;
}
Example #25
0
static RList* entries(RBinFile *bf) {
	RList *ret = r_list_new ();
	RBinAddr *ptr = NULL;

	if (bf && bf->buf != NULL) {
		if (!ret)
			return NULL;
		ret->free = free;
		if (!(ptr = R_NEW0 (RBinAddr)))
			return ret;
		ptr->paddr = ptr->vaddr = ptr->haddr = 0x100;
		r_list_append (ret, ptr);
	}
	return ret;
}
Example #26
0
static RList *entries(RBinFile *arch) {
	struct r_bin_coff_obj *obj = (struct r_bin_coff_obj*)arch->o->bin_obj;
	RList *ret;
	RBinAddr *ptr = NULL;

	if (!(ret = r_list_new ()))
		return NULL;

	ret->free = free;

	ptr = r_coff_get_entry(obj);
	r_list_append(ret, ptr);

	return ret;
}
Example #27
0
static RList *entries(RBinFile *arch) {
	RList *ret;
	RBinAddr *ptr = NULL;

	if (!(ret = r_list_new ())) {
		return NULL;
	}
	ret->free = free;
	if (!(ptr = R_NEW0 (RBinAddr))) {
		return ret;
	}
	ptr->paddr = ptr->vaddr = 0;
	r_list_append (ret, ptr);
	return ret;
}
Example #28
0
static RList* libs(RBinFile *arch) {
	r_bin_xbe_obj_t *obj;
	int i, off, libs, r;
	xbe_lib lib;
	RList *ret;
	char *s;

	if (!arch || !arch->o)
		return NULL;
	obj = arch->o->bin_obj;
	ret = r_list_new ();
	if (!ret) return NULL;
	ret->free = free;
	if ( obj->header->kernel_lib_addr < obj->header->base) {
		off = 0;
	} else {
		off = obj->header->kernel_lib_addr - obj->header->base;
	}
	r = r_buf_read_at (arch->buf, off, (ut8 *)&lib, sizeof(xbe_lib));
	if (r == 0 || r == -1) return NULL;
	s = r_str_newf ("%s %i.%i.%i", lib.name, lib.major, lib.minor, lib.build);
	if (s) r_list_append (ret, s);

	if (obj->header->xapi_lib_addr < obj->header->base) {
		off = 0;
	} else {
		off = obj->header->xapi_lib_addr - obj->header->base;
	}
	r = r_buf_read_at (arch->buf, off, (ut8 *)&lib, sizeof(xbe_lib));
	if (r == 0 || r == -1) return NULL;
	s = r_str_newf ("%s %i.%i.%i", lib.name, lib.major, lib.minor, lib.build);
	if (s) r_list_append (ret, s);

	libs = obj->header->lib_versions;
	if (libs<1) libs = 0;
	for (i = 0; i < libs; i++) {
		r = r_buf_read_at (arch->buf, obj->header->lib_versions_addr - \
			obj->header->base + (i * sizeof (xbe_lib)),
			(ut8 *)&lib, sizeof (xbe_lib));

		if (r == 0 || r == -1) continue;
		s = r_str_newf ("%s %i.%i.%i", lib.name,
			lib.major, lib.minor, lib.build);
		if (s) r_list_append(ret, s);
	}

	return ret;
}
Example #29
0
R_API void r_debug_esil_watch(RDebug *dbg, int rwx, int dev, const char *expr) {
	if (!EWPS) {
		EWPS = r_list_new ();
		if (!EWPS) return;
		EWPS->free = (RListFree)ewps_free;
	}
	EsilBreak *ew = R_NEW0 (EsilBreak);
	if (!ew) {
		R_FREE (EWPS);
		return;
	}
	ew->rwx = rwx;
	ew->dev = dev;
	ew->expr = strdup (expr);
	r_list_append (EWPS, ew);
}
Example #30
0
File: sys.c Project: futex/radare2
R_API RList *r_sys_dir(const char *path) {
	RList *list = NULL;
	struct dirent *entry;
	DIR *dir = r_sandbox_opendir (path);
	if (dir) {
		list = r_list_new ();
		if (list) {
			list->free = free;
			while ((entry = readdir (dir))) {
				r_list_append (list, strdup (entry->d_name));
			}
		}
		closedir (dir);
	}
	return list;
}