summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2019-02-19 21:12:53 -0500
committermidipix <writeonce@midipix.org>2019-02-19 21:20:18 -0500
commit25e093f839419ba0805408bfeccdc5facdc5a042 (patch)
tree434c0446d6ee6591e79d41f260ad60b478b425e1 /src
parent1ea23134457d33f90b1db4b1d3a27f9480ba2429 (diff)
downloadpemagine-25e093f839419ba0805408bfeccdc5facdc5a042.tar.bz2
pemagine-25e093f839419ba0805408bfeccdc5facdc5a042.tar.xz
PE section interfaces: added pe_get_image_block_section_addr().
Diffstat (limited to 'src')
-rw-r--r--src/headers/pe_get_image_section_tbl_addr.c38
1 files changed, 38 insertions, 0 deletions
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;
+}