Blame src/output/pe_output_image_symbols.c

f779e3
/***************************************************************/
f779e3
/*  perk: PE Resource Kit                                      */
f779e3
/*  Copyright (C) 2015--2016  Z. Gilboa                        */
f779e3
/*  Released under GPLv2 and GPLv3; see COPYING.PERK.          */
f779e3
/***************************************************************/
f779e3
f779e3
#include <stdio.h>
f779e3
#include <string.h>
f779e3
f779e3
#include <perk/perk.h>
f779e3
#include <perk/perk_output.h>
f779e3
#include "perk_reader_impl.h"
f779e3
#include "perk_errinfo_impl.h"
f779e3
f779e3
int pe_output_image_symbols(
f779e3
	const struct pe_driver_ctx *	dctx,
f779e3
	const struct pe_image_meta *	meta,
f779e3
	FILE *				fout)
f779e3
{
ea6b78
	unsigned			i;
f779e3
	char *				mark;
e75572
	struct pe_raw_coff_symbol *	symtbl;
ea6b78
	struct pe_meta_coff_symbol	symrec;
f779e3
	const char * 			dash = "";
f779e3
f779e3
	if (!fout)
f779e3
		fout = stdout;
f779e3
f779e3
	if (dctx->cctx->fmtflags & PERK_PRETTY_YAML) {
f779e3
		if (fputs("symbols:\n",fout) < 0)
f779e3
			return PERK_FILE_ERROR(dctx);
f779e3
f779e3
		dash = "- ";
f779e3
	}
f779e3
f779e3
	mark   = (char *)meta->image.addr;
e75572
	symtbl = (struct pe_raw_coff_symbol *)(mark + meta->coff.ptr_to_sym_tbl);
f779e3
ea6b78
	for (i=0; i<meta->coff.num_of_syms; i++) {
ea6b78
		pe_read_coff_symbol(
ea6b78
			&symtbl[i],&symrec,
ea6b78
			&meta->coff,meta->image.addr);
f779e3
ea6b78
		if (fprintf(fout,"%s%s\n",
ea6b78
				dash,
ea6b78
				symrec.long_name
ea6b78
					? symrec.long_name
ea6b78
					: symrec.name) < 0)
ea6b78
			return PERK_FILE_ERROR(dctx);
f779e3
f779e3
		i += symtbl[i].num_of_aux_symbols[0];
f779e3
	}
f779e3
f779e3
	return 0;
f779e3
}