summaryrefslogtreecommitdiffhomepage
path: root/src/meta
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2017-10-18 19:14:08 +0000
committermidipix <writeonce@midipix.org>2017-10-19 18:18:48 -0400
commitf8d0c8713c40c35c1059b3f6f87ee3cd701e3a2f (patch)
tree6b97c5e325b0b37a92b7b3dc926f924d15d3e686 /src/meta
parentf3c99bb618fcec170a27058578fcef186d0a96c0 (diff)
downloadpemagine-f8d0c8713c40c35c1059b3f6f87ee3cd701e3a2f.tar.bz2
pemagine-f8d0c8713c40c35c1059b3f6f87ee3cd701e3a2f.tar.xz
pe_get_image_stack_heap_info(): submit to a greater type-punned power.
Diffstat (limited to 'src/meta')
-rw-r--r--src/meta/pe_get_image_stack_heap_info.c31
1 files changed, 23 insertions, 8 deletions
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 <pemagine/pe_structs.h>
#include <pemagine/pemagine.h>
+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: