summaryrefslogtreecommitdiffhomepage
path: root/src/output/pe_output_image_symbols.c
blob: 3dc7eb3a0f28a59241a14de4966e926d002ad889 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/***************************************************************/
/*  perk: PE Resource Kit                                      */
/*  Copyright (C) 2015--2016  Z. Gilboa                        */
/*  Released under GPLv2 and GPLv3; see COPYING.PERK.          */
/***************************************************************/

#include <stdio.h>
#include <string.h>

#include <perk/perk.h>
#include <perk/perk_output.h>
#include "perk_reader_impl.h"
#include "perk_errinfo_impl.h"

int pe_output_image_symbols(
	const struct pe_driver_ctx *	dctx,
	const struct pe_image_meta *	meta,
	FILE *				fout)
{
	unsigned			i;
	char *				mark;
	struct pe_raw_coff_symbol *	symtbl;
	struct pe_meta_coff_symbol	symrec;
	const char * 			dash = "";

	if (!fout)
		fout = stdout;

	if (dctx->cctx->fmtflags & PERK_PRETTY_YAML) {
		if (fputs("symbols:\n",fout) < 0)
			return PERK_FILE_ERROR(dctx);

		dash = "- ";
	}

	mark   = (char *)meta->image.addr;
	symtbl = (struct pe_raw_coff_symbol *)(mark + meta->coff.ptr_to_sym_tbl);

	for (i=0; i<meta->coff.num_of_syms; i++) {
		pe_read_coff_symbol(
			&symtbl[i],&symrec,
			&meta->coff,meta->image.addr);

		if (fprintf(fout,"%s%s\n",
				dash,
				symrec.long_name
					? symrec.long_name
					: symrec.name) < 0)
			return PERK_FILE_ERROR(dctx);

		i += symtbl[i].num_of_aux_symbols[0];
	}

	return 0;
}