diff options
author | midipix <writeonce@midipix.org> | 2016-11-19 19:26:18 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2016-11-19 19:26:18 -0500 |
commit | ab043c05e95de76f5967921542f17d3f12a6be03 (patch) | |
tree | 32f42dc0a4559a1fac6a0098be2e0f838c4c5398 /src/headers | |
parent | a2cf44f27c9ab9eaf84a7f59a8a1d74ebc2fa9c2 (diff) | |
download | pemagine-ab043c05e95de76f5967921542f17d3f12a6be03.tar.bz2 pemagine-ab043c05e95de76f5967921542f17d3f12a6be03.tar.xz |
pe_get_image_named_section_addr(): code maintenance.
Diffstat (limited to 'src/headers')
-rw-r--r-- | src/headers/pe_get_image_section_tbl_addr.c | 30 |
1 files changed, 18 insertions, 12 deletions
diff --git a/src/headers/pe_get_image_section_tbl_addr.c b/src/headers/pe_get_image_section_tbl_addr.c index 49b2957..0aac29a 100644 --- a/src/headers/pe_get_image_section_tbl_addr.c +++ b/src/headers/pe_get_image_section_tbl_addr.c @@ -30,28 +30,34 @@ struct pe_raw_sec_hdr * pe_get_image_section_tbl_addr(const void * base) return (struct pe_raw_sec_hdr *)mark; } -pe_api -struct pe_raw_sec_hdr * pe_get_image_named_section_addr (const void * base, const char * name) + +struct pe_raw_sec_hdr * pe_get_image_named_section_addr(const void * base, const char * name) { - uint16_t count; - struct pe_raw_sec_hdr * hdr; - struct pe_raw_coff_file_hdr*coff; - char * ch; - uint32_t len; - uint32_t pos; - uint64_t sname = 0; + uint16_t count; + struct pe_raw_sec_hdr * hdr; + struct pe_raw_coff_file_hdr * coff; + char * ch; + uint32_t len; + uint32_t pos; + uint64_t sname; if (!(hdr = pe_get_image_section_tbl_addr(base))) return 0; - coff = pe_get_image_coff_hdr_addr(base); - count = *(uint16_t *)coff->num_of_sections; + if (!(coff = pe_get_image_coff_hdr_addr(base))) + return 0; + + count = coff->num_of_sections[1] << 8; + count += coff->num_of_sections[0]; if ((len = pe_impl_strlen_ansi(name)) > 8) { /* todo: long name support */ return 0; } else { - for (pos=0, ch=(char *)&sname; pos<len; pos++) + sname = 0; + ch = (char *)&sname; + + for (pos=0; pos<len; pos++) ch[pos] = name[pos]; for (; count; hdr++,count--) |