Blame src/output/pe_output_export_symbols.c

c0fbae
#include <stdint.h>
c0fbae
#include <stdlib.h>
c0fbae
#include <stdio.h>
c0fbae
#include <string.h>
c0fbae
#include <errno.h>
c0fbae
c0fbae
#include <perk/perk.h>
c0fbae
ab024a
int pe_output_export_symbols (const struct pe_image_meta * m, const struct pe_common_ctx * cctx, FILE * f)
c0fbae
{
c0fbae
	uint32_t 	offset;
c0fbae
	uint32_t *	symrva;
ab024a
	int		fdout;
c0fbae
	int		i;
c0fbae
ab024a
	if (!m->hedata)
ab024a
		return 0;
ab024a
	else if (f)
ab024a
		fdout = -1;
ab024a
	else if (!cctx)
ab024a
		return -1;
ab024a
	else if (cctx->fdout < 0) {
ab024a
		f = stdout;
ab024a
		fdout = -1;
ab024a
	} else if ((fdout = dup(cctx->fdout)) < 0)
ab024a
		return -1;
ab024a
	else if (!(f = fdopen(fdout,"a"))) {
ab024a
		close(fdout);
ab024a
		return -1;
ab024a
	}
c0fbae
c0fbae
	offset	= m->hedata->virtual_addr - m->hedata->ptr_to_raw_data;
664d5b
	symrva	= (uint32_t *)((uintptr_t)m->image.addr + (m->edata.name_ptr_rva - offset));
c0fbae
c0fbae
	for (i=0; i<m->edata.num_of_name_ptrs; i++)
664d5b
		fprintf(f,"%s\n",(char *)((uintptr_t)m->image.addr + symrva[i] - offset));
c0fbae
ab024a
	if (fdout >= 0)
ab024a
		fclose(f);
ab024a
c0fbae
	return 0;
c0fbae
}