Blame src/output/pe_output_image_symbols.c

f779e3
/***************************************************************/
f779e3
/*  perk: PE Resource Kit                                      */
463997
/*  Copyright (C) 2015--2021  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>
d6e02b
#include <perk/perk_structs.h>
f779e3
#include <perk/perk_output.h>
f779e3
#include "perk_reader_impl.h"
67bba7
#include "perk_driver_impl.h"
67bba7
#include "perk_dprintf_impl.h"
f779e3
#include "perk_errinfo_impl.h"
f779e3
f779e3
int pe_output_image_symbols(
f779e3
	const struct pe_driver_ctx *	dctx,
67bba7
	const struct pe_image_meta *	meta)
f779e3
{
ea6b78
	unsigned			i;
67bba7
	int				fdout;
f779e3
	char *				mark;
e75572
	struct pe_raw_coff_symbol *	symtbl;
ea6b78
	struct pe_meta_coff_symbol	symrec;
f779e3
	const char * 			dash = "";
f779e3
67bba7
	fdout = pe_driver_fdout(dctx);
f779e3
f779e3
	if (dctx->cctx->fmtflags & PERK_PRETTY_YAML) {
67bba7
		if (pe_dprintf(fdout,"symbols:\n") < 0)
f779e3
			return PERK_FILE_ERROR(dctx);
f779e3
f779e3
		dash = "- ";
f779e3
	}
f779e3
ed06fb
	mark   = (char *)meta->r_image.map_addr;
58ced9
	symtbl = (struct pe_raw_coff_symbol *)(mark + meta->m_coff.cfh_ptr_to_sym_tbl);
f779e3
58ced9
	for (i=0; i<meta->m_coff.cfh_num_of_syms; i++) {
ea6b78
		pe_read_coff_symbol(
ea6b78
			&symtbl[i],&symrec,
ed06fb
			&meta->m_coff,meta->r_image.map_addr);
f779e3
67bba7
		if (pe_dprintf(
67bba7
				fdout,
67bba7
				"%s%s\n",
ea6b78
				dash,
0c1d83
				symrec.cs_long_name
0c1d83
					? symrec.cs_long_name
0c1d83
					: symrec.cs_name) < 0)
ea6b78
			return PERK_FILE_ERROR(dctx);
f779e3
0c1d83
		i += symtbl[i].cs_num_of_aux_symbols[0];
f779e3
	}
f779e3
f779e3
	return 0;
f779e3
}