From da15f0c6fa6f1feed4951a5415d68e3de2b144a8 Mon Sep 17 00:00:00 2001 From: midipix Date: Wed, 30 Nov 2016 19:09:35 -0500 Subject: struct pe_{raw|meta}_coff_file_hdr: member name normalization. --- include/perk/perk_meta.h | 20 ++++++++++---------- include/perk/perk_structs.h | 16 ++++++++-------- src/info/pe_get_image_subtype.c | 2 +- src/logic/pe_get_image_meta.c | 30 +++++++++++++++--------------- src/output/pe_output_image_sections.c | 2 +- src/output/pe_output_image_strings.c | 4 ++-- src/output/pe_output_image_symbols.c | 4 ++-- src/reader/pe_read_coff_header.c | 26 +++++++++++++------------- src/reader/pe_read_coff_symbol.c | 4 ++-- 9 files changed, 54 insertions(+), 54 deletions(-) diff --git a/include/perk/perk_meta.h b/include/perk/perk_meta.h index b3b5411..1f2c2cf 100644 --- a/include/perk/perk_meta.h +++ b/include/perk/perk_meta.h @@ -71,16 +71,16 @@ struct pe_meta_image_dos_hdr { /* pe/coff file header */ struct pe_meta_coff_file_hdr { - unsigned char signature[4]; - uint16_t machine; - uint16_t num_of_sections; - uint32_t time_date_stamp; - uint32_t ptr_to_sym_tbl; - uint32_t num_of_syms; - uint16_t size_of_opt_hdr; - uint16_t characteristics; - uint32_t ptr_to_string_tbl; - uint32_t size_of_string_tbl; + unsigned char cfh_signature[4]; + uint16_t cfh_machine; + uint16_t cfh_num_of_sections; + uint32_t cfh_time_date_stamp; + uint32_t cfh_ptr_to_sym_tbl; + uint32_t cfh_num_of_syms; + uint16_t cfh_size_of_opt_hdr; + uint16_t cfh_characteristics; + uint32_t cfh_ptr_to_str_tbl; + uint32_t cfh_size_of_str_tbl; }; diff --git a/include/perk/perk_structs.h b/include/perk/perk_structs.h index 2875daa..692c4ab 100644 --- a/include/perk/perk_structs.h +++ b/include/perk/perk_structs.h @@ -29,14 +29,14 @@ struct pe_raw_image_dos_hdr { struct pe_raw_coff_file_hdr { - unsigned char signature [0x04]; /* 0x00 */ - unsigned char machine [0x02]; /* 0x04 */ - unsigned char num_of_sections [0x02]; /* 0x06 */ - unsigned char time_date_stamp [0x04]; /* 0x08 */ - unsigned char ptr_to_sym_tbl [0x04]; /* 0x0c */ - unsigned char num_of_syms [0x04]; /* 0x10 */ - unsigned char size_of_opt_hdr [0x02]; /* 0x14 */ - unsigned char characteristics [0x02]; /* 0x16 */ + unsigned char cfh_signature [0x04]; /* 0x00 */ + unsigned char cfh_machine [0x02]; /* 0x04 */ + unsigned char cfh_num_of_sections [0x02]; /* 0x06 */ + unsigned char cfh_time_date_stamp [0x04]; /* 0x08 */ + unsigned char cfh_ptr_to_sym_tbl [0x04]; /* 0x0c */ + unsigned char cfh_num_of_syms [0x04]; /* 0x10 */ + unsigned char cfh_size_of_opt_hdr [0x02]; /* 0x14 */ + unsigned char cfh_characteristics [0x02]; /* 0x16 */ }; diff --git a/src/info/pe_get_image_subtype.c b/src/info/pe_get_image_subtype.c index 391fca3..df1ffd0 100644 --- a/src/info/pe_get_image_subtype.c +++ b/src/info/pe_get_image_subtype.c @@ -22,7 +22,7 @@ int pe_get_image_subtype(const struct pe_image_meta * m, struct pe_info_string * { int subtype; - if (m->coff.characteristics & PE_IMAGE_FILE_DLL) + if (m->coff.cfh_characteristics & PE_IMAGE_FILE_DLL) subtype = PE_SUBTYPE_DLL; else diff --git a/src/logic/pe_get_image_meta.c b/src/logic/pe_get_image_meta.c index ec7ad82..bb461ff 100644 --- a/src/logic/pe_get_image_meta.c +++ b/src/logic/pe_get_image_meta.c @@ -36,7 +36,7 @@ void pe_free_image_meta(struct pe_image_meta * meta) int pe_get_named_section_index(const struct pe_image_meta * m, const char * name) { - int i; for (i=0; icoff.num_of_sections; i++) + int i; for (i=0; icoff.cfh_num_of_sections; i++) if (!(strcmp(name,m->sectbl[i].name))) return i; @@ -48,7 +48,7 @@ int pe_get_block_section_index(const struct pe_image_meta * m, const struct pe_b int i; uint32_t low,high; - for (i=0; icoff.num_of_sections; i++) { + for (i=0; icoff.cfh_num_of_sections; i++) { low = m->sectbl[i].virtual_addr; high = low + m->sectbl[i].virtual_size; @@ -64,7 +64,7 @@ int pe_get_roffset_from_rva(const struct pe_image_meta * m, uint32_t rva, uint32 int i; uint32_t low,high; - for (i=0; icoff.num_of_sections; i++) { + for (i=0; icoff.cfh_num_of_sections; i++) { low = m->sectbl[i].virtual_addr; high = low + m->sectbl[i].virtual_size; @@ -82,7 +82,7 @@ int pe_get_rva_from_roffset(const struct pe_image_meta * m, uint32_t roffset, ui int i; uint32_t low,high,ref; - for (i=0, ref=~0; icoff.num_of_sections; i++) { + for (i=0, ref=~0; icoff.cfh_num_of_sections; i++) { low = m->sectbl[i].ptr_to_raw_data; high = low + m->sectbl[i].virtual_size; @@ -189,14 +189,14 @@ int pe_get_image_meta( return pe_free_image_meta_impl( m,PERK_CUSTOM_ERROR(dctx,ret)); - mark = (const unsigned char *)image->addr + m->coff.ptr_to_sym_tbl; - mark += m->coff.num_of_syms * sizeof(struct pe_raw_coff_symbol); + mark = (const unsigned char *)image->addr + m->coff.cfh_ptr_to_sym_tbl; + mark += m->coff.cfh_num_of_syms * sizeof(struct pe_raw_coff_symbol); - m->coff.ptr_to_string_tbl = m->coff.ptr_to_sym_tbl; - m->coff.ptr_to_string_tbl += m->coff.num_of_syms * sizeof(struct pe_raw_coff_symbol); - m->coff.size_of_string_tbl = pe_read_long(mark); + m->coff.cfh_ptr_to_str_tbl = m->coff.cfh_ptr_to_sym_tbl; + m->coff.cfh_ptr_to_str_tbl += m->coff.cfh_num_of_syms * sizeof(struct pe_raw_coff_symbol); + m->coff.cfh_size_of_str_tbl = pe_read_long(mark); - mark = &m->acoff->signature[0]; + mark = &m->acoff->cfh_signature[0]; m->aopt = (union pe_raw_opt_hdr *)(mark + sizeof(*m->acoff)); if ((ret = (pe_read_optional_header(m->aopt,&m->opt)))) @@ -204,19 +204,19 @@ int pe_get_image_meta( m,PERK_CUSTOM_ERROR(dctx,ret)); mark = &m->aopt->opt_hdr_32.magic[0]; - m->asectbl = (struct pe_raw_sec_hdr *)(mark + m->coff.size_of_opt_hdr); + m->asectbl = (struct pe_raw_sec_hdr *)(mark + m->coff.cfh_size_of_opt_hdr); - if (!(m->sectbl = calloc(m->coff.num_of_sections,sizeof(*(m->sectbl))))) + if (!(m->sectbl = calloc(m->coff.cfh_num_of_sections,sizeof(*(m->sectbl))))) return pe_free_image_meta_impl( m,PERK_SYSTEM_ERROR(dctx)); - for (i=0; icoff.num_of_sections; i++) { + for (i=0; icoff.cfh_num_of_sections; i++) { pe_read_section_header(&m->asectbl[i],&m->sectbl[i]); if (m->sectbl[i].name[0] == '/') if ((l = strtol(&m->sectbl[i].name[1],0,10)) > 0) - if (l < m->coff.size_of_string_tbl) - m->sectbl[i].long_name = base + m->coff.ptr_to_string_tbl + l; + if (l < m->coff.cfh_size_of_str_tbl) + m->sectbl[i].long_name = base + m->coff.cfh_ptr_to_str_tbl + l; } /* .edata */ diff --git a/src/output/pe_output_image_sections.c b/src/output/pe_output_image_sections.c index b538cdf..67f0108 100644 --- a/src/output/pe_output_image_sections.c +++ b/src/output/pe_output_image_sections.c @@ -28,7 +28,7 @@ int pe_output_image_sections( dash = "- "; } - for (i=0; icoff.num_of_sections; i++) + for (i=0; icoff.cfh_num_of_sections; i++) if (fprintf(fout,"%s%s\n", dash, meta->sectbl[i].long_name diff --git a/src/output/pe_output_image_strings.c b/src/output/pe_output_image_strings.c index a2b16fa..b0555eb 100644 --- a/src/output/pe_output_image_strings.c +++ b/src/output/pe_output_image_strings.c @@ -33,9 +33,9 @@ int pe_output_image_strings( } mark = (char *)meta->image.addr; - mark += meta->coff.ptr_to_string_tbl; + mark += meta->coff.cfh_ptr_to_str_tbl; - cap = mark + meta->coff.size_of_string_tbl; + cap = mark + meta->coff.cfh_size_of_str_tbl; mark += sizeof(uint32_t); for (ch=mark; chimage.addr; - symtbl = (struct pe_raw_coff_symbol *)(mark + meta->coff.ptr_to_sym_tbl); + symtbl = (struct pe_raw_coff_symbol *)(mark + meta->coff.cfh_ptr_to_sym_tbl); - for (i=0; icoff.num_of_syms; i++) { + for (i=0; icoff.cfh_num_of_syms; i++) { pe_read_coff_symbol( &symtbl[i],&symrec, &meta->coff,meta->image.addr); diff --git a/src/reader/pe_read_coff_header.c b/src/reader/pe_read_coff_header.c index 1b4dfe3..12268f1 100644 --- a/src/reader/pe_read_coff_header.c +++ b/src/reader/pe_read_coff_header.c @@ -12,24 +12,24 @@ int pe_read_coff_header(const struct pe_raw_coff_file_hdr * p, struct pe_meta_coff_file_hdr * m) { - if ((p->signature[0] != 'P') || (p->signature[1] != 'E') - || p->signature[2] || p->signature[3]) + if ((p->cfh_signature[0] != 'P') || (p->cfh_signature[1] != 'E') + || p->cfh_signature[2] || p->cfh_signature[3]) return PERK_ERR_BAD_COFF_HEADER; - m->signature[0] = p->signature[0]; - m->signature[1] = p->signature[1]; - m->signature[2] = p->signature[2]; - m->signature[3] = p->signature[3]; + m->cfh_signature[0] = p->cfh_signature[0]; + m->cfh_signature[1] = p->cfh_signature[1]; + m->cfh_signature[2] = p->cfh_signature[2]; + m->cfh_signature[3] = p->cfh_signature[3]; - m->machine = pe_read_short(p->machine); - m->num_of_sections = pe_read_short(p->num_of_sections); + m->cfh_machine = pe_read_short(p->cfh_machine); + m->cfh_num_of_sections = pe_read_short(p->cfh_num_of_sections); - m->time_date_stamp = pe_read_long(p->time_date_stamp); - m->ptr_to_sym_tbl = pe_read_long(p->ptr_to_sym_tbl); - m->num_of_syms = pe_read_long(p->num_of_syms); + m->cfh_time_date_stamp = pe_read_long(p->cfh_time_date_stamp); + m->cfh_ptr_to_sym_tbl = pe_read_long(p->cfh_ptr_to_sym_tbl); + m->cfh_num_of_syms = pe_read_long(p->cfh_num_of_syms); - m->size_of_opt_hdr = pe_read_short(p->size_of_opt_hdr); - m->characteristics = pe_read_short(p->characteristics); + m->cfh_size_of_opt_hdr = pe_read_short(p->cfh_size_of_opt_hdr); + m->cfh_characteristics = pe_read_short(p->cfh_characteristics); return 0; } diff --git a/src/reader/pe_read_coff_symbol.c b/src/reader/pe_read_coff_symbol.c index 259f370..0c6a40d 100644 --- a/src/reader/pe_read_coff_symbol.c +++ b/src/reader/pe_read_coff_symbol.c @@ -47,8 +47,8 @@ int pe_read_coff_symbol( mark = (char *)base; roffset = pe_read_long(&p->name[4]); - if (roffset < coff->size_of_string_tbl) - m->long_name = mark + coff->ptr_to_string_tbl + roffset; + if (roffset < coff->cfh_size_of_str_tbl) + m->long_name = mark + coff->cfh_ptr_to_str_tbl + roffset; } return 0; -- cgit v1.2.3