Blame src/reader/pe_read_section_header.c

e2e2c2
/***************************************************************/
e2e2c2
/*  perk: PE Resource Kit                                      */
e2e2c2
/*  Copyright (C) 2015--2016  Z. Gilboa                        */
e2e2c2
/*  Released under GPLv2 and GPLv3; see COPYING.PERK.          */
e2e2c2
/***************************************************************/
e2e2c2
c0fbae
#include <string.h>
c0fbae
c0fbae
#include <perk/perk.h>
8d8242
#include "perk_endian_impl.h"
413f56
#include "perk_reader_impl.h"
c0fbae
c0fbae
int pe_read_section_header(const struct pe_sec_hdr * p, struct pe_meta_sec_hdr * m)
c0fbae
{
c0fbae
	/* name: meta struct conveniently contains null termination */
c0fbae
	memset(m,0,sizeof(m->name));
c0fbae
	memcpy(m,p,sizeof(p->name));
c0fbae
c0fbae
	/* todo: long name support */
c0fbae
	m->long_name = 0;
c0fbae
8d8242
	if (PERK_LITTLE_ENDIAN) {
c0fbae
8d8242
		memcpy(&m->virtual_size,&p->virtual_size,sizeof(*p)-sizeof(p->name));
c0fbae
8d8242
	} else {
c0fbae
8d8242
		m->virtual_size		= pe_read_long(p->virtual_size);
8d8242
		m->virtual_addr		= pe_read_long(p->virtual_addr);
8d8242
		m->size_of_raw_data	= pe_read_long(p->size_of_raw_data);
8d8242
		m->ptr_to_raw_data	= pe_read_long(p->ptr_to_raw_data);
8d8242
		m->ptr_to_relocs	= pe_read_long(p->ptr_to_relocs);
8d8242
		m->ptr_to_line_nums	= pe_read_long(p->ptr_to_line_nums);
c0fbae
8d8242
		m->num_of_relocs	= pe_read_short(p->num_of_relocs);
8d8242
		m->num_of_line_nums	= pe_read_short(p->num_of_line_nums);
c0fbae
8d8242
		m->characteristics	= pe_read_long(p->characteristics);
c0fbae
8d8242
	}
c0fbae
c0fbae
	return 0;
b5f7f5
}