From f8d0c8713c40c35c1059b3f6f87ee3cd701e3a2f Mon Sep 17 00:00:00 2001 From: midipix Date: Wed, 18 Oct 2017 19:14:08 +0000 Subject: pe_get_image_stack_heap_info(): submit to a greater type-punned power. --- src/meta/pe_get_image_stack_heap_info.c | 31 +++++++++++++++++++++++-------- 1 file changed, 23 insertions(+), 8 deletions(-) (limited to 'src/meta') diff --git a/src/meta/pe_get_image_stack_heap_info.c b/src/meta/pe_get_image_stack_heap_info.c index 5a5e22a..67a6de9 100644 --- a/src/meta/pe_get_image_stack_heap_info.c +++ b/src/meta/pe_get_image_stack_heap_info.c @@ -9,6 +9,21 @@ #include #include +static uint32_t pe_read_raw_data_32(unsigned char * addr) +{ + uint32_t * p32; + + p32 = (uint32_t *)addr; + return *p32; +} + +static uint64_t pe_read_raw_data_64(unsigned char * addr) +{ + uint64_t * p64; + + p64 = (uint64_t *)addr; + return *p64; +} int pe_get_image_stack_heap_info(const void * base, struct pe_stack_heap_info * stack_heap_info) { @@ -22,17 +37,17 @@ int pe_get_image_stack_heap_info(const void * base, struct pe_stack_heap_info * switch (*magic) { case PE_MAGIC_PE32: - stack_heap_info->size_of_stack_reserve = *(uint32_t *)hdr->opt_hdr_32.coh_size_of_stack_reserve; - stack_heap_info->size_of_stack_commit = *(uint32_t *)hdr->opt_hdr_32.coh_size_of_stack_commit; - stack_heap_info->size_of_heap_reserve = *(uint32_t *)hdr->opt_hdr_32.coh_size_of_heap_reserve; - stack_heap_info->size_of_heap_commit = *(uint32_t *)hdr->opt_hdr_32.coh_size_of_heap_commit; + stack_heap_info->size_of_stack_reserve = pe_read_raw_data_32(hdr->opt_hdr_32.coh_size_of_stack_reserve); + stack_heap_info->size_of_stack_commit = pe_read_raw_data_32(hdr->opt_hdr_32.coh_size_of_stack_commit); + stack_heap_info->size_of_heap_reserve = pe_read_raw_data_32(hdr->opt_hdr_32.coh_size_of_heap_reserve); + stack_heap_info->size_of_heap_commit = pe_read_raw_data_32(hdr->opt_hdr_32.coh_size_of_heap_commit); break; case PE_MAGIC_PE32_PLUS: - stack_heap_info->size_of_stack_reserve = *(size_t *)hdr->opt_hdr_64.coh_size_of_stack_reserve; - stack_heap_info->size_of_stack_commit = *(size_t *)hdr->opt_hdr_64.coh_size_of_stack_commit; - stack_heap_info->size_of_heap_reserve = *(size_t *)hdr->opt_hdr_64.coh_size_of_heap_reserve; - stack_heap_info->size_of_heap_commit = *(size_t *)hdr->opt_hdr_64.coh_size_of_heap_commit; + stack_heap_info->size_of_stack_reserve = pe_read_raw_data_64(hdr->opt_hdr_64.coh_size_of_stack_reserve); + stack_heap_info->size_of_stack_commit = pe_read_raw_data_64(hdr->opt_hdr_64.coh_size_of_stack_commit); + stack_heap_info->size_of_heap_reserve = pe_read_raw_data_64(hdr->opt_hdr_64.coh_size_of_heap_reserve); + stack_heap_info->size_of_heap_commit = pe_read_raw_data_64(hdr->opt_hdr_64.coh_size_of_heap_commit); break; default: -- cgit v1.2.3