67b1e9 pe_get_image_meta(): added coff string table and long section name support.

Authored and Committed by midipix 8 years ago
    pe_get_image_meta(): added coff string table and long section name support.
    
        
file modified
+2 -0
include/perk/perk_meta.h CHANGED
@@ -79,6 +79,8 @@ struct pe_meta_coff_file_hdr {
79
79
uint32_t num_of_syms;
80
80
uint16_t size_of_opt_hdr;
81
81
uint16_t characteristics;
82
+ uint32_t ptr_to_string_tbl;
83
+ uint32_t size_of_string_tbl;
82
84
};
83
85
84
86
file modified
+17 -2
src/logic/pe_get_image_meta.c CHANGED
@@ -165,7 +165,9 @@ int pe_get_image_meta(
165
165
struct pe_image_meta ** meta)
166
166
{
167
167
int i,s,status;
168
+ long l;
168
169
unsigned j;
170
+ unsigned char * mark;
169
171
struct pe_image_meta * m;
170
172
char * base = image->addr;
171
173
@@ -184,7 +186,14 @@ int pe_get_image_meta(
184
186
return pe_free_image_meta_impl(m,
185
187
PERK_CUSTOM_ERROR(dctx,status));
186
188
187
- m->aopt = (union pe_opt_hdr *)((char *)m->acoff + sizeof(m->coff));
189
+ mark = image->addr + m->coff.ptr_to_sym_tbl;
190
+ mark += m->coff.num_of_syms * sizeof(struct pe_coff_sym_entry);
191
+
192
+ m->coff.ptr_to_string_tbl = m->coff.ptr_to_sym_tbl;
193
+ m->coff.ptr_to_string_tbl += m->coff.num_of_syms * sizeof(struct pe_coff_sym_entry);
194
+ m->coff.size_of_string_tbl = pe_read_long(mark);
195
+
196
+ m->aopt = (union pe_opt_hdr *)((char *)m->acoff + sizeof(*m->acoff));
188
197
189
198
if ((status = (pe_read_optional_header(m->aopt,&m->opt))))
190
199
return pe_free_image_meta_impl(m,
@@ -196,9 +205,15 @@ int pe_get_image_meta(
196
205
return pe_free_image_meta_impl(m,
197
206
PERK_SYSTEM_ERROR(dctx));
198
207
199
- for (i=0; i<m->coff.num_of_sections; i++)
208
+ for (i=0; i<m->coff.num_of_sections; i++) {
200
209
pe_read_section_header(&m->asectbl[i],&m->sectbl[i]);
201
210
211
+ if (m->sectbl[i].name[0] == '/')
212
+ if ((l = strtol(&m->sectbl[i].name[1],0,10)) > 0)
213
+ if (l < m->coff.size_of_string_tbl)
214
+ m->sectbl[i].long_name = base + m->coff.ptr_to_string_tbl + l;
215
+ }
216
+
202
217
/* .edata */
203
218
i = pe_get_named_section_index(m,".edata");
204
219
s = pe_get_block_section_index(m,&m->opt.dirs.export_tbl);