summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-11-15 21:09:36 -0500
committermidipix <writeonce@midipix.org>2016-11-15 21:10:14 -0500
commit4377060a2796df43a700dad39cfc3c13f7f1dea7 (patch)
tree3a2843bd3d070fbb40c10788b399e414e21e40db
parent67b1e98a64e5f5160dce4535ab38052031cef965 (diff)
downloadperk-4377060a2796df43a700dad39cfc3c13f7f1dea7.tar.bz2
perk-4377060a2796df43a700dad39cfc3c13f7f1dea7.tar.xz
output: pe_output_image_sections(): implementation and integration.
-rw-r--r--include/perk/perk.h1
-rw-r--r--project/common.mk1
-rw-r--r--src/driver/pe_amain.c3
-rw-r--r--src/output/pe_output_image_sections.c40
4 files changed, 45 insertions, 0 deletions
diff --git a/include/perk/perk.h b/include/perk/perk.h
index 8bdce77..f5e6664 100644
--- a/include/perk/perk.h
+++ b/include/perk/perk.h
@@ -171,6 +171,7 @@ perk_api void pe_free_unit_ctx (struct pe_unit_ctx *);
/* utility api */
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_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 f7eb597..adca9d5 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -11,6 +11,7 @@ API_SRCS = \
src/output/pe_output_error.c \
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_import_libraries.c \
src/reader/pe_read_coff_header.c \
src/reader/pe_read_dos_header.c \
diff --git a/src/driver/pe_amain.c b/src/driver/pe_amain.c
index 40eaf9d..59cb8f2 100644
--- a/src/driver/pe_amain.c
+++ b/src/driver/pe_amain.c
@@ -55,6 +55,9 @@ static void pe_perform_unit_actions(
if (flags & PERK_OUTPUT_IMAGE_CATEGORY)
pe_output_image_category(dctx,uctx->meta,0);
+ if (flags & PERK_OUTPUT_IMAGE_SECTIONS)
+ pe_output_image_sections(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_sections.c b/src/output/pe_output_image_sections.c
new file mode 100644
index 0000000..b538cdf
--- /dev/null
+++ b/src/output/pe_output_image_sections.c
@@ -0,0 +1,40 @@
+/***************************************************************/
+/* perk: PE Resource Kit */
+/* Copyright (C) 2015--2016 Z. Gilboa */
+/* Released under GPLv2 and GPLv3; see COPYING.PERK. */
+/***************************************************************/
+
+#include <stdio.h>
+
+#include <perk/perk.h>
+#include <perk/perk_output.h>
+#include "perk_errinfo_impl.h"
+
+int pe_output_image_sections(
+ const struct pe_driver_ctx * dctx,
+ const struct pe_image_meta * meta,
+ FILE * fout)
+{
+ int i;
+ const char * dash = "";
+
+ if (!fout)
+ fout = stdout;
+
+ if (dctx->cctx->fmtflags & PERK_PRETTY_YAML) {
+ if (fputs("sections:\n",fout) < 0)
+ return PERK_FILE_ERROR(dctx);
+
+ dash = "- ";
+ }
+
+ for (i=0; i<meta->coff.num_of_sections; i++)
+ if (fprintf(fout,"%s%s\n",
+ dash,
+ meta->sectbl[i].long_name
+ ? meta->sectbl[i].long_name
+ : meta->sectbl[i].name) < 0)
+ return PERK_FILE_ERROR(dctx);
+
+ return 0;
+}