Blame src/output/pe_output_import_libraries.c

9c5807
#include <stdint.h>
9c5807
#include <stdlib.h>
9c5807
#include <stdio.h>
9c5807
#include <string.h>
9c5807
#include <errno.h>
9c5807
9c5807
#include <perk/perk.h>
9c5807
#include <perk/perk_output.h>
9c5807
#include "perk_output_impl.h"
9c5807
e343a6
static void pretty_header(const struct pe_common_ctx * cctx, FILE * fout)
e343a6
{
e343a6
	if (cctx->fmtflags & PERK_PRETTY_YAML)
e343a6
		fputs("imports:\n",fout);
e343a6
}
0d3dde
e343a6
static void pretty_implib_header(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
e343a6
{
e343a6
	if ((cctx->fmtflags & PERK_PRETTY_YAML) && (cctx->fmtflags & PERK_OUTPUT_IMPORT_SYMS))
e343a6
		fprintf(fout,"  %s:\n",name);
e343a6
	else if (cctx->fmtflags & PERK_PRETTY_YAML)
e343a6
		fprintf(fout,"- %s:\n",name);
e343a6
	else if (cctx->fmtflags & PERK_OUTPUT_IMPORT_SYMS)
e343a6
		fprintf(fout,"%s:\n",name);
e343a6
	else
e343a6
		fprintf(fout,"%s\n",name);
e343a6
}
0d3dde
e343a6
static void pretty_implib_item(const struct pe_common_ctx * cctx, const char * name, FILE * fout)
0d3dde
{
0d3dde
	if (cctx->fmtflags & PERK_PRETTY_YAML)
e343a6
		fprintf(fout,"  - %s\n",name);
0d3dde
	else
e343a6
		fprintf(fout,"%s\n",name);
0d3dde
}
0d3dde
9c5807
int pe_output_import_libraries(
9c5807
	const struct pe_image_meta *	m,
9c5807
	const struct pe_common_ctx *	cctx,
9c5807
	FILE *				fout)
9c5807
{
0d3dde
	FILE *		ftmp;
0d3dde
	int		i,j;
9c5807
9c5807
	if (!m->summary.num_of_implibs)
9c5807
		return 0;
9c5807
9c5807
	if (!(fout = pe_output_prolog(cctx,fout,&ftmp)))
9c5807
		return -1;
9c5807
e343a6
	pretty_header(cctx,fout);
0d3dde
9c5807
	for (i=0; i<m->summary.num_of_implibs; i++) {
e343a6
		pretty_implib_header(cctx,m->idata[i].name,fout);
9c5807
9c5807
		if (cctx->fmtflags & PERK_OUTPUT_IMPORT_SYMS)
9c5807
			for (j=0; j<m->idata[i].count; j++)
9c5807
				if (m->idata[i].items[j].name)
e343a6
					pretty_implib_item(
e343a6
						cctx,
e343a6
						m->idata[i].items[j].name,
e343a6
						fout);
e343a6
9c5807
	}
9c5807
9c5807
	return pe_output_epilog(0,ftmp);
9c5807
}