summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-11-17 05:17:47 -0500
committermidipix <writeonce@midipix.org>2016-11-17 05:17:47 -0500
commit0d4d4770a8abef13e2d5255d7e5f1703e2fa1fbe (patch)
treef017c0ac4dee3f0a092b8a33e67aa4f01e221149 /src
parentecf121476585a0c456689987c14d89ecc6364625 (diff)
downloadperk-0d4d4770a8abef13e2d5255d7e5f1703e2fa1fbe.tar.bz2
perk-0d4d4770a8abef13e2d5255d7e5f1703e2fa1fbe.tar.xz
output: pe_output_image_strings(): initial implementation and integration.
Diffstat (limited to 'src')
-rw-r--r--src/driver/pe_amain.c3
-rw-r--r--src/output/pe_output_image_strings.c52
2 files changed, 55 insertions, 0 deletions
diff --git a/src/driver/pe_amain.c b/src/driver/pe_amain.c
index e9167fb..de98c16 100644
--- a/src/driver/pe_amain.c
+++ b/src/driver/pe_amain.c
@@ -61,6 +61,9 @@ static void pe_perform_unit_actions(
if (flags & PERK_OUTPUT_IMAGE_SYMBOLS)
pe_output_image_symbols(dctx,uctx->meta,0);
+ if (flags & PERK_OUTPUT_IMAGE_STRINGS)
+ pe_output_image_strings(dctx,uctx->meta,0);
+
if (flags & PERK_OUTPUT_EXPORT_SYMS)
pe_output_export_symbols(dctx,uctx->meta,0);
diff --git a/src/output/pe_output_image_strings.c b/src/output/pe_output_image_strings.c
new file mode 100644
index 0000000..a2b16fa
--- /dev/null
+++ b/src/output/pe_output_image_strings.c
@@ -0,0 +1,52 @@
+/***************************************************************/
+/* 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_strings(
+ const struct pe_driver_ctx * dctx,
+ const struct pe_image_meta * meta,
+ FILE * fout)
+{
+ const char * ch;
+ const char * mark;
+ const char * cap;
+ const char * dash = "";
+
+ if (!fout)
+ fout = stdout;
+
+ if (dctx->cctx->fmtflags & PERK_PRETTY_YAML) {
+ if (fputs("strings:\n",fout) < 0)
+ return PERK_FILE_ERROR(dctx);
+
+ dash = "- ";
+ }
+
+ mark = (char *)meta->image.addr;
+ mark += meta->coff.ptr_to_string_tbl;
+
+ cap = mark + meta->coff.size_of_string_tbl;
+ mark += sizeof(uint32_t);
+
+ for (ch=mark; ch<cap; ) {
+ if (fprintf(fout,"%s%s\n",dash,ch) < 0)
+ return PERK_FILE_ERROR(dctx);
+
+ ch += strlen(ch);
+
+ for (; ch<cap && !*ch; )
+ ch++;
+ }
+
+ return 0;
+}