From 0d4d4770a8abef13e2d5255d7e5f1703e2fa1fbe Mon Sep 17 00:00:00 2001 From: midipix Date: Nov 17 2016 10:17:47 +0000 Subject: output: pe_output_image_strings(): initial implementation and integration. --- diff --git a/include/perk/perk.h b/include/perk/perk.h index 8324f66..03aaedf 100644 --- a/include/perk/perk.h +++ b/include/perk/perk.h @@ -165,6 +165,7 @@ perk_api int pe_main (int, char **, char **); perk_api int pe_output_image_category (const struct pe_driver_ctx *, const struct pe_image_meta *, FILE *); perk_api int pe_output_image_sections (const struct pe_driver_ctx *, const struct pe_image_meta *, FILE *); perk_api int pe_output_image_symbols (const struct pe_driver_ctx *, const struct pe_image_meta *, FILE *); +perk_api int pe_output_image_strings (const struct pe_driver_ctx *, const struct pe_image_meta *, FILE *); perk_api int pe_output_export_symbols (const struct pe_driver_ctx *, const struct pe_image_meta *, FILE *); perk_api int pe_output_import_libraries(const struct pe_driver_ctx *, const struct pe_image_meta *, FILE *); perk_api int pe_output_error_record (const struct pe_driver_ctx *, const struct pe_error_info *); diff --git a/project/common.mk b/project/common.mk index e84caa2..2c98c93 100644 --- a/project/common.mk +++ b/project/common.mk @@ -12,6 +12,7 @@ API_SRCS = \ src/output/pe_output_export_symbols.c \ src/output/pe_output_image_category.c \ src/output/pe_output_image_sections.c \ + src/output/pe_output_image_strings.c \ src/output/pe_output_image_symbols.c \ src/output/pe_output_import_libraries.c \ src/reader/pe_read_coff_header.c \ 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 +#include + +#include +#include +#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