0d4d47 output: pe_output_image_strings(): initial implementation and integration.

Authored and Committed by midipix 8 years ago
    output: pe_output_image_strings(): initial implementation and integration.
    
        
file modified
+1 -0
include/perk/perk.h CHANGED
@@ -165,6 +165,7 @@ perk_api int pe_main (int, char **, char **);
165
165
perk_api int pe_output_image_category (const struct pe_driver_ctx *, const struct pe_image_meta *, FILE *);
166
166
perk_api int pe_output_image_sections (const struct pe_driver_ctx *, const struct pe_image_meta *, FILE *);
167
167
perk_api int pe_output_image_symbols (const struct pe_driver_ctx *, const struct pe_image_meta *, FILE *);
168
+ perk_api int pe_output_image_strings (const struct pe_driver_ctx *, const struct pe_image_meta *, FILE *);
168
169
perk_api int pe_output_export_symbols (const struct pe_driver_ctx *, const struct pe_image_meta *, FILE *);
169
170
perk_api int pe_output_import_libraries(const struct pe_driver_ctx *, const struct pe_image_meta *, FILE *);
170
171
perk_api int pe_output_error_record (const struct pe_driver_ctx *, const struct pe_error_info *);
file modified
+1 -0
project/common.mk CHANGED
@@ -12,6 +12,7 @@ API_SRCS = \
12
12
src/output/pe_output_export_symbols.c \
13
13
src/output/pe_output_image_category.c \
14
14
src/output/pe_output_image_sections.c \
15
+ src/output/pe_output_image_strings.c \
15
16
src/output/pe_output_image_symbols.c \
16
17
src/output/pe_output_import_libraries.c \
17
18
src/reader/pe_read_coff_header.c \
file modified
+3 -0
src/driver/pe_amain.c CHANGED
@@ -61,6 +61,9 @@ static void pe_perform_unit_actions(
61
61
if (flags & PERK_OUTPUT_IMAGE_SYMBOLS)
62
62
pe_output_image_symbols(dctx,uctx->meta,0);
63
63
64
+ if (flags & PERK_OUTPUT_IMAGE_STRINGS)
65
+ pe_output_image_strings(dctx,uctx->meta,0);
66
+
64
67
if (flags & PERK_OUTPUT_EXPORT_SYMS)
65
68
pe_output_export_symbols(dctx,uctx->meta,0);
66
69
src/output/pe_output_image_strings.c ADDED
@@ -0,0 +1,52 @@
1
+ /***************************************************************/
2
+ /* perk: PE Resource Kit */
3
+ /* Copyright (C) 2015--2016 Z. Gilboa */
4
+ /* Released under GPLv2 and GPLv3; see COPYING.PERK. */
5
+ /***************************************************************/
6
+
7
+ #include <stdio.h>
8
+ #include <string.h>
9
+
10
+ #include <perk/perk.h>
11
+ #include <perk/perk_output.h>
12
+ #include "perk_reader_impl.h"
13
+ #include "perk_errinfo_impl.h"
14
+
15
+ int pe_output_image_strings(
16
+ const struct pe_driver_ctx * dctx,
17
+ const struct pe_image_meta * meta,
18
+ FILE * fout)
19
+ {
20
+ const char * ch;
21
+ const char * mark;
22
+ const char * cap;
23
+ const char * dash = "";
24
+
25
+ if (!fout)
26
+ fout = stdout;
27
+
28
+ if (dctx->cctx->fmtflags & PERK_PRETTY_YAML) {
29
+ if (fputs("strings:\n",fout) < 0)
30
+ return PERK_FILE_ERROR(dctx);
31
+
32
+ dash = "- ";
33
+ }
34
+
35
+ mark = (char *)meta->image.addr;
36
+ mark += meta->coff.ptr_to_string_tbl;
37
+
38
+ cap = mark + meta->coff.size_of_string_tbl;
39
+ mark += sizeof(uint32_t);
40
+
41
+ for (ch=mark; ch<cap; ) {
42
+ if (fprintf(fout,"%s%s\n",dash,ch) < 0)
43
+ return PERK_FILE_ERROR(dctx);
44
+
45
+ ch += strlen(ch);
46
+
47
+ for (; ch<cap && !*ch; )
48
+ ch++;
49
+ }
50
+
51
+ return 0;
52
+ }