summaryrefslogtreecommitdiff
path: root/src/output
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2015-11-28 14:26:12 -0500
committermidipix <writeonce@midipix.org>2016-11-10 23:35:28 -0500
commite343a687474e1f4f8837852dfafc30c8736bafab (patch)
treefbc10192ef11885a7474926583c9995e0219f1d7 /src/output
parent0d3dde49e65c9de9dff41933ceb64fa28635499d (diff)
downloadperk-e343a687474e1f4f8837852dfafc30c8736bafab.tar.bz2
perk-e343a687474e1f4f8837852dfafc30c8736bafab.tar.xz
pretty printer: improved yaml support (import libraries, ,exported symbols).
Diffstat (limited to 'src/output')
-rw-r--r--src/output/pe_output_export_symbols.c22
-rw-r--r--src/output/pe_output_import_libraries.c45
2 files changed, 47 insertions, 20 deletions
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 <errno.h>
#include <perk/perk.h>
+#include <perk/perk_output.h>
#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; i<m->edata.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 <perk/perk_output.h>
#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; i<m->summary.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; j<m->idata[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);