Blame src/reader/pe_read_section_header.c

c0fbae
#include <endian.h>
c0fbae
#include <string.h>
c0fbae
c0fbae
#include <perk/perk.h>
c0fbae
#include "perk_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
c0fbae
	#if (BYTE_ORDER == LITTLE_ENDIAN)
c0fbae
c0fbae
	memcpy(&m->virtual_size,&p->virtual_size,sizeof(*p)-sizeof(p->name));
c0fbae
c0fbae
	#else
c0fbae
c0fbae
	m->virtual_size		= pe_read_long(p->virtual_size);
c0fbae
	m->virtual_addr		= pe_read_long(p->virtual_addr);
c0fbae
	m->size_of_raw_data	= pe_read_long(p->size_of_raw_data);
c0fbae
	m->ptr_to_raw_data	= pe_read_long(p->ptr_to_raw_data);
c0fbae
	m->ptr_to_relocs	= pe_read_long(p->ptr_to_relocs);
b5f7f5
	m->ptr_to_line_nums	= pe_read_long(p->ptr_to_line_nums);
c0fbae
c0fbae
	m->num_of_relocs	= pe_read_short(p->num_of_relocs);
c0fbae
	m->num_of_line_nums	= pe_read_short(p->num_of_line_nums);
c0fbae
c0fbae
	m->characteristics	= pe_read_long(p->characteristics);
c0fbae
c0fbae
	#endif
c0fbae
c0fbae
	return 0;
b5f7f5
}