diff options
author | midipix <writeonce@midipix.org> | 2019-02-19 21:12:53 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2019-02-19 21:20:18 -0500 |
commit | 25e093f839419ba0805408bfeccdc5facdc5a042 (patch) | |
tree | 434c0446d6ee6591e79d41f260ad60b478b425e1 | |
parent | 1ea23134457d33f90b1db4b1d3a27f9480ba2429 (diff) | |
download | pemagine-25e093f839419ba0805408bfeccdc5facdc5a042.tar.bz2 pemagine-25e093f839419ba0805408bfeccdc5facdc5a042.tar.xz |
PE section interfaces: added pe_get_image_block_section_addr().
-rw-r--r-- | include/pemagine/pemagine.h | 1 | ||||
-rw-r--r-- | src/headers/pe_get_image_section_tbl_addr.c | 38 |
2 files changed, 39 insertions, 0 deletions
diff --git a/include/pemagine/pemagine.h b/include/pemagine/pemagine.h index 518b567..ba70edc 100644 --- a/include/pemagine/pemagine.h +++ b/include/pemagine/pemagine.h @@ -210,6 +210,7 @@ pe_api union pe_raw_opt_hdr * pe_get_image_opt_hdr_addr (const void * base); pe_api struct pe_raw_data_dirs * pe_get_image_data_dirs_addr (const void * base); pe_api struct pe_raw_sec_hdr * pe_get_image_section_tbl_addr (const void * base); pe_api struct pe_raw_sec_hdr * pe_get_image_named_section_addr (const void * base, const char * name); +pe_api struct pe_raw_sec_hdr * pe_get_image_block_section_addr (const void * base, uint32_t blk_rva, uint32_t blk_size); pe_api struct pe_raw_export_hdr * pe_get_image_export_hdr_addr (const void * base, uint32_t * sec_size); pe_api struct pe_raw_import_hdr * pe_get_image_import_dir_addr (const void * base, uint32_t * sec_size); diff --git a/src/headers/pe_get_image_section_tbl_addr.c b/src/headers/pe_get_image_section_tbl_addr.c index 56c55a6..98f9dd4 100644 --- a/src/headers/pe_get_image_section_tbl_addr.c +++ b/src/headers/pe_get_image_section_tbl_addr.c @@ -75,3 +75,41 @@ struct pe_raw_sec_hdr * pe_get_image_named_section_addr(const void * base, const return 0; } + + +struct pe_raw_sec_hdr * pe_get_image_block_section_addr( + const void * base, + uint32_t blk_rva, + uint32_t blk_size) +{ + uint32_t low,size; + uint16_t count; + struct pe_raw_sec_hdr * hdr; + struct pe_raw_coff_image_hdr * coff; + + if (!(hdr = pe_get_image_section_tbl_addr(base))) + return 0; + + if (!(coff = pe_get_image_coff_hdr_addr(base))) + return 0; + + count = coff->cfh_num_of_sections[1] << 8; + count += coff->cfh_num_of_sections[0]; + + for (; count; hdr++,count--) { + low = hdr->sh_virtual_addr[3] << 24; + low += hdr->sh_virtual_addr[2] << 16; + low += hdr->sh_virtual_addr[1] << 8; + low += hdr->sh_virtual_addr[0]; + + size = hdr->sh_virtual_size[3] << 24; + size += hdr->sh_virtual_size[2] << 16; + size += hdr->sh_virtual_size[1] << 8; + size += hdr->sh_virtual_size[0]; + + if ((low <= blk_rva) && (blk_rva + blk_size <= low + size)) + return hdr; + } + + return 0; +} |