From e343a687474e1f4f8837852dfafc30c8736bafab Mon Sep 17 00:00:00 2001 From: midipix Date: Sat, 28 Nov 2015 14:26:12 -0500 Subject: pretty printer: improved yaml support (import libraries, ,exported symbols). --- src/output/pe_output_export_symbols.c | 22 +++++++++++++++- src/output/pe_output_import_libraries.c | 45 +++++++++++++++++++-------------- 2 files changed, 47 insertions(+), 20 deletions(-) (limited to 'src/output') diff --git a/src/output/pe_output_export_symbols.c b/src/output/pe_output_export_symbols.c index d52bfe4..e6f4d5c 100644 --- a/src/output/pe_output_export_symbols.c +++ b/src/output/pe_output_export_symbols.c @@ -5,8 +5,23 @@ #include #include +#include #include "perk_output_impl.h" +static void pretty_header(const struct pe_common_ctx * cctx, FILE * fout) +{ + if (cctx->fmtflags & PERK_PRETTY_YAML) + fputs("exports:\n",fout); +} + +static void pretty_export_item(const struct pe_common_ctx * cctx, const char * name, FILE * fout) +{ + if (cctx->fmtflags & PERK_PRETTY_YAML) + fprintf(fout,"- %s\n",name); + else + fprintf(fout,"%s\n",name); +} + int pe_output_export_symbols( const struct pe_image_meta * m, const struct pe_common_ctx * cctx, @@ -23,11 +38,16 @@ int pe_output_export_symbols( if (!(fout = pe_output_prolog(cctx,fout,&ftmp))) return -1; + pretty_header(cctx,fout); + offset = m->hedata->virtual_addr - m->hedata->ptr_to_raw_data; symrva = (uint32_t *)((uintptr_t)m->image.addr + (m->edata.name_ptr_rva - offset)); for (i=0; iedata.num_of_name_ptrs; i++) - fprintf(fout,"%s\n",(char *)((uintptr_t)m->image.addr + symrva[i] - offset)); + pretty_export_item( + cctx, + (char *)((uintptr_t)m->image.addr + symrva[i] - offset), + fout); return pe_output_epilog(0,ftmp); } diff --git a/src/output/pe_output_import_libraries.c b/src/output/pe_output_import_libraries.c index 2b864fb..40d1a08 100644 --- a/src/output/pe_output_import_libraries.c +++ b/src/output/pe_output_import_libraries.c @@ -8,22 +8,30 @@ #include #include "perk_output_impl.h" -enum impsym_prefix_tag { - IMPSYM_PREFIX_DEFAULT, - IMPSYM_PREFIX_YAML -}; +static void pretty_header(const struct pe_common_ctx * cctx, FILE * fout) +{ + if (cctx->fmtflags & PERK_PRETTY_YAML) + fputs("imports:\n",fout); +} -static const char * const impsym_prefix_arr[] = { - "--> ", - "- " -}; +static void pretty_implib_header(const struct pe_common_ctx * cctx, const char * name, FILE * fout) +{ + if ((cctx->fmtflags & PERK_PRETTY_YAML) && (cctx->fmtflags & PERK_OUTPUT_IMPORT_SYMS)) + fprintf(fout," %s:\n",name); + else if (cctx->fmtflags & PERK_PRETTY_YAML) + fprintf(fout,"- %s:\n",name); + else if (cctx->fmtflags & PERK_OUTPUT_IMPORT_SYMS) + fprintf(fout,"%s:\n",name); + else + fprintf(fout,"%s\n",name); +} -static const char * pretty_impsym_prefix(const struct pe_common_ctx * cctx) +static void pretty_implib_item(const struct pe_common_ctx * cctx, const char * name, FILE * fout) { if (cctx->fmtflags & PERK_PRETTY_YAML) - return impsym_prefix_arr[IMPSYM_PREFIX_YAML]; + fprintf(fout," - %s\n",name); else - return impsym_prefix_arr[IMPSYM_PREFIX_DEFAULT]; + fprintf(fout,"%s\n",name); } int pe_output_import_libraries( @@ -33,7 +41,6 @@ int pe_output_import_libraries( { FILE * ftmp; int i,j; - const char * impsym_prefix; if (!m->summary.num_of_implibs) return 0; @@ -41,19 +48,19 @@ int pe_output_import_libraries( if (!(fout = pe_output_prolog(cctx,fout,&ftmp))) return -1; - impsym_prefix = pretty_impsym_prefix(cctx); + pretty_header(cctx,fout); for (i=0; isummary.num_of_implibs; i++) { - if (cctx->fmtflags & PERK_OUTPUT_IMPORT_SYMS) - fprintf(fout,"%s:\n",m->idata[i].name); - else - fprintf(fout,"%s\n",m->idata[i].name); + pretty_implib_header(cctx,m->idata[i].name,fout); if (cctx->fmtflags & PERK_OUTPUT_IMPORT_SYMS) for (j=0; jidata[i].count; j++) if (m->idata[i].items[j].name) - fprintf(fout,"%s%s\n", - impsym_prefix,m->idata[i].items[j].name); + pretty_implib_item( + cctx, + m->idata[i].items[j].name, + fout); + } return pe_output_epilog(0,ftmp); -- cgit v1.2.3