Beispiel #1
0
void parse_pe_stream(void *stream, R_STREAM_FILE *stream_file)
{
	int data_size = 0;
	char *data = 0, *ptmp = 0;
	int read_bytes = 0;
	SIMAGE_SECTION_HEADER *sctn_header = 0;
	SPEStream *pe_stream = (SPEStream *) stream;
	int sctn_header_size =0;

	stream_file_get_size(stream_file, &data_size);
	data = (char *) malloc(data_size);
	stream_file_get_data(stream_file, data);

	sctn_header_size = sizeof(SIMAGE_SECTION_HEADER);
	ptmp = data;
	pe_stream->sections_hdrs = r_list_new();
	while (read_bytes < data_size) {
		sctn_header = (SIMAGE_SECTION_HEADER *) malloc (sctn_header_size);
		memcpy(sctn_header, ptmp, sctn_header_size);
		ptmp += sctn_header_size;
		r_list_append(pe_stream->sections_hdrs, sctn_header);
		read_bytes += sctn_header_size;
	}

	free(data);
}
Beispiel #2
0
void parse_omap_stream(void *stream, R_STREAM_FILE *stream_file)
{
	int data_size;
	char *data = 0, *ptmp = 0;
	int curr_read_bytes = 0, read_bytes = 0;
	SOmapEntry *omap_entry = 0;
	SOmapStream *omap_stream = 0;

	stream_file_get_size(stream_file, &data_size);
	data = (char *) malloc(data_size);
	stream_file_get_data(stream_file, data);

	omap_stream = (SOmapStream *) stream;
	omap_stream->froms = 0;
	omap_stream->omap_entries = r_list_new();
	curr_read_bytes = 0;
	ptmp = data;
	while (read_bytes < data_size) {
		omap_entry = (SOmapEntry *) malloc(sizeof(SOmapEntry));
		curr_read_bytes = parse_omap_entry(ptmp, data_size, &read_bytes, omap_entry);
		ptmp += curr_read_bytes;

		if (!curr_read_bytes) {
			free(omap_entry);
			break;
		}

		r_list_append(omap_stream->omap_entries, omap_entry);
	}

	free(data);
}
Beispiel #3
0
void parse_fpo_new_stream(void *stream, R_STREAM_FILE *stream_file)
{
	int data_size;
	char *data = 0, *ptmp = 0;
	int curr_read_bytes = 0, read_bytes = 0;
	SFPO_DATA_V2 *fpo_data = 0;
	SFPONewStream *fpo_stream = 0;

	stream_file_get_size(stream_file, &data_size);
	data = (char *) malloc(data_size);
	stream_file_get_data(stream_file, data);

	fpo_stream = (SFPONewStream *) stream;
	fpo_stream->fpo_data_list = r_list_new();
	curr_read_bytes = 0;
	ptmp = data;
	while (read_bytes < data_size) {
		fpo_data = (SFPO_DATA_V2 *) malloc(sizeof(SFPO_DATA_V2));
		curr_read_bytes = parse_fpo_data_v2(ptmp, data_size, &read_bytes, fpo_data);
		ptmp += curr_read_bytes;

		if (!curr_read_bytes) {
			free(fpo_data);
			break;
		}

		r_list_append(fpo_stream->fpo_data_list, fpo_data);
	}

	free(data);
}
Beispiel #4
0
static int init_pdb7_root_stream(R_PDB *pdb, int *root_page_list, int pages_amount,
		EStream indx, int root_size, int page_size) {
	R_PDB_STREAM *pdb_stream = 0;
	int tmp_data_max_size = 0;
	char *tmp_data = NULL, *data_end;
	int stream_size = 0;
	int num_streams = 0;
	int *sizes = NULL;
	int num_pages = 0;
	int data_size = 0;
	char *data = NULL;
	int i = 0;
	int pos = 0;

	char *tmp;

	R_PDB7_ROOT_STREAM *root_stream7;

	pdb->root_stream = R_NEW0 (R_PDB7_ROOT_STREAM);
	init_r_pdb_stream(&pdb->root_stream->pdb_stream, pdb->buf, root_page_list, pages_amount,
					  indx, root_size, page_size);

	root_stream7 = pdb->root_stream;
	pdb_stream = &(root_stream7->pdb_stream);

	stream_file_get_size (&pdb_stream->stream_file, &data_size);
	data = (char *) calloc (1, data_size);
	if (!data) return 0;
	stream_file_get_data(&pdb_stream->stream_file, data);

	num_streams = *(int *)data;
	tmp_data = data;
	tmp_data += 4;

	root_stream7->num_streams = num_streams;

	tmp_data_max_size = (data_size - (num_streams * 4 - 4));
	data_end = data + tmp_data_max_size;
	if (tmp_data_max_size> data_size) {
		R_FREE(data);
		eprintf ("invalid max tmp data size\n");
		return 0;
	}
	if (num_streams<0 || tmp_data_max_size <= 0) {
		R_FREE(data);
		eprintf ("too much amount of streams\n"
			   "curremt pdb file is not correct\n");
		return 0;
	}

	sizes = (int *) calloc (num_streams, 4);
	if (!sizes) {
		R_FREE (data);
		eprintf ("too much amount of streams\n"
			   "current pdb file is not correct\n");
		return 0;
	}

	for (i = 0; i < num_streams && (tmp_data+4 < data_end); i++) {
		stream_size = *(int *)(tmp_data);
		tmp_data += 4;
		if (stream_size == UT32_MAX) {
			stream_size = 0;
		}
		memcpy (sizes + i, &stream_size, 4);
	}

//	char *tmp_file_name = (char *) malloc(strlen("/root/test.pdb.000") + 1);
//	short ii;
//	FILE *tmp_file;
	tmp_data = ((char *)data + num_streams * 4 + 4);
	root_stream7->streams_list = r_list_new();
	RList *pList = root_stream7->streams_list;
	SPage *page = 0;
	for (i = 0; i < num_streams; i++) {
		num_pages = count_pages (sizes[i], page_size);

		if ((pos + num_pages) > tmp_data_max_size) {
			R_FREE(data);
			R_FREE(sizes);
			eprintf("warning: looks like there is not correct values "
				   "of stream size in pdb file\n");
			return 0;
		}

		// TODO: cache that num_pages * 4, its used 4 times
		tmp = (char *) calloc (num_pages, 4);
		memset(tmp, 0, num_pages * 4);
		page = R_NEW0 (SPage);
		if (num_pages != 0) {
			if ((pos+(num_pages*4)) > tmp_data_max_size) {
				eprintf ("data overrun by num_pages\n");
				R_FREE (data);
				R_FREE (sizes);
				R_FREE (tmp);
				R_FREE (page);
				return 0;
			}
			memcpy (tmp, tmp_data + pos, num_pages * 4);
			pos += num_pages * 4;
//			sprintf(tmp_file_name, "%s%d", "/root/test.pdb", i);
//			tmp_file = fopen(tmp_file_name, "wb");
//			fwrite(tmp, num_pages * 4, 1, tmp_file);
//			fclose(tmp_file);
			page->stream_size = sizes[i];
			page->stream_pages = tmp;
			page->num_pages = num_pages;
		} else {
			page->stream_size = 0;
			page->stream_pages = 0;
			page->num_pages = 0;
			free(tmp);
		}

		r_list_append (pList, page);
	}
	free (sizes);
	free (data);
//	printf("init_pdb7_root_stream()\n");
	return 1;
}