Пример #1
0
static ut64 __lseek(RIO* io, RIODesc *fd, ut64 offset, int whence) {
	RBuffer *b;
	ut64 r_offset = offset;
	if (!fd->data)
		return offset;
	b = RIOSPARSE_BUF(fd);
	r_offset = r_buf_seek (b, offset, whence);
	//if (r_offset != UT64_MAX)
	RIOSPARSE_OFF (fd) = r_offset;
	return r_offset;
}
Пример #2
0
int 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_file(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, (unsigned char *)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 1;

error:
	R_FREE (signature);

	return 0;
}
Пример #3
0
static RList *entries(RBinFile *arch) {
	RList *entries = r_list_new ();
	if (!entries) {
		return NULL;
	}
	RBinAddr *addr = R_NEW0 (RBinAddr);
	if (!addr) {
		return NULL;
	}
	ut64 entrypoint = pyc_get_entrypoint (version.magic);
	addr->paddr = entrypoint;
	addr->vaddr = entrypoint;
	r_buf_seek (arch->buf, entrypoint, R_IO_SEEK_CUR);
	r_list_append (entries, addr);
	return entries;
}
Пример #4
0
static bool pdb7_parse(R_PDB *pdb) {
	char signature[PDB7_SIGNATURE_LEN + 1];
	int num_root_index_pages = 0;
	int *root_index_pages = 0;
	void *root_page_data = 0;
	int *root_page_list = 0;
	int num_root_pages = 0;
	int num_file_pages = 0;
	int alloc_tbl_ptr = 0;
	int bytes_read = 0;
	int page_size = 0;
	int root_size = 0;
	int reserved = 0;
	void *p_tmp;
	int i = 0;

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

	if (!read_int_var ("page_size", &page_size, pdb)) {
		goto error;
	}
	if (!read_int_var ("alloc_tbl_ptr", &alloc_tbl_ptr, pdb)) {
		goto error;
	}
	if (!read_int_var ("num_file_pages", &num_file_pages, pdb)) {
		goto error;
	}
	if (!read_int_var ("root_size", &root_size, pdb)) {
		goto error;
	}
	if (!read_int_var("reserved", &reserved, pdb)) {
		goto error;
	}
	// FIXME: why they is not equal ????
//	if (memcmp(signature, PDB7_SIGNATURE, PDB7_SIGNATURE_LEN) != 0) {
//		printf("Invalid signature for PDB7 format\n");
//		//goto error;
//	}

	num_root_pages = count_pages (root_size, page_size);
	num_root_index_pages = count_pages ((num_root_pages * 4), page_size);

	root_index_pages = (int *)calloc (sizeof (int), R_MAX (num_root_index_pages, 1));
	if (!root_index_pages) {
		eprintf("error memory allocation\n");
		goto error;
	}

//	bytes_read = fread(root_index_pages, 4, num_root_index_pages, pdb->fp);
	bytes_read = r_buf_read(pdb->buf, (unsigned char *)root_index_pages, 4 * num_root_index_pages);
	//fread(root_index_pages, 4, num_root_index_pages, pdb->fp);
	if (bytes_read != 4 * num_root_index_pages) {
		eprintf ("error while reading root_index_pages\n");
		goto error;
	}

	root_page_data = (int *)calloc (page_size, num_root_index_pages);
	if (!root_page_data) {
		eprintf ("error memory allocation of root_page_data\n");
		goto error;
	}

	p_tmp = root_page_data;
	for (i = 0; i < num_root_index_pages; i++) {
		r_buf_seek(pdb->buf, root_index_pages[i] * page_size, 0);
		r_buf_read(pdb->buf, p_tmp, page_size);
		p_tmp = (char *)p_tmp + page_size;
	}

	root_page_list = (int *)calloc (sizeof(int), num_root_pages);
	if (!root_page_list) {
		eprintf ("error: memory allocation of root page\n");
		goto error;
	}

	p_tmp = root_page_data;
	for (i = 0; i < num_root_pages; i++) {
		root_page_list[i] = *((int *)p_tmp);
		p_tmp = (int *)p_tmp + 1;
	}

	pdb->pdb_streams2 = 0;
	if (!init_pdb7_root_stream (pdb, root_page_list, num_root_pages,
			ePDB_STREAM_ROOT, root_size, page_size)) {
		eprintf ("root stream has not initialized\n");
		goto error;
	}
	if (!pdb_read_root (pdb)) {
		eprintf ("pdb root has not initialized\n");
		goto error;
	}

	R_FREE (root_page_list);
	R_FREE (root_page_data);
	R_FREE (root_index_pages);
	return true;
error:
	R_FREE (root_page_list);
	R_FREE (root_page_data);
	R_FREE (root_index_pages);
	return false;
}