diff options
-rw-r--r-- | Makefile | 2 | ||||
-rw-r--r-- | include/perk/perk_meta.h | 2 | ||||
-rw-r--r-- | include/perk/perk_structs.h | 2 | ||||
-rw-r--r-- | src/internal/perk_impl.h | 6 | ||||
-rw-r--r-- | src/main/pe_map_raw_image.c | 2 | ||||
-rw-r--r-- | src/main/perk.c | 2 | ||||
-rw-r--r-- | src/reader/pe_read_coff_header.c | 2 | ||||
-rw-r--r-- | src/reader/pe_read_dos_header.c | 6 | ||||
-rw-r--r-- | src/reader/pe_read_export_header.c | 2 | ||||
-rw-r--r-- | src/reader/pe_read_import_header.c | 8 | ||||
-rw-r--r-- | src/reader/pe_read_optional_header.c | 30 | ||||
-rw-r--r-- | src/reader/pe_read_section_header.c | 4 |
12 files changed, 33 insertions, 35 deletions
@@ -33,7 +33,6 @@ app: $(CC) -static -o perk $(OBJS) static: - $(CC) $(CFLAGS_OBJ) $(CFLAGS) -c $(SRCTREE)/src/main/perk.c $(CC) $(CFLAGS_OBJ) $(CFLAGS) -c $(SRCTREE)/src/main/pe_map_raw_image.c $(CC) $(CFLAGS_OBJ) $(CFLAGS) -c $(SRCTREE)/src/main/pe_get_image_meta.c $(CC) $(CFLAGS_OBJ) $(CFLAGS) -c $(SRCTREE)/src/reader/pe_read_dos_header.c @@ -47,7 +46,6 @@ static: $(CROSS_COMPILE)ranlib libperk.a shared: - $(CC) $(CFLAGS_LIB) $(CFLAGS) -c $(SRCTREE)/src/main/perk.c $(CC) $(CFLAGS_LIB) $(CFLAGS) -c $(SRCTREE)/src/main/pe_map_raw_image.c $(CC) $(CFLAGS_LIB) $(CFLAGS) -c $(SRCTREE)/src/main/pe_get_image_meta.c $(CC) $(CFLAGS_LIB) $(CFLAGS) -c $(SRCTREE)/src/reader/pe_read_dos_header.c diff --git a/include/perk/perk_meta.h b/include/perk/perk_meta.h index e3f3375..8ca8f53 100644 --- a/include/perk/perk_meta.h +++ b/include/perk/perk_meta.h @@ -65,7 +65,7 @@ struct pe_meta_opt_hdr_std { struct pe_meta_opt_hdr_vers { uint16_t major_os_ver; - uint16_t minor_or_ver; + uint16_t minor_os_ver; uint16_t major_image_ver; uint16_t minor_image_ver; uint16_t major_subsys_ver; diff --git a/include/perk/perk_structs.h b/include/perk/perk_structs.h index 7254250..f4202b1 100644 --- a/include/perk/perk_structs.h +++ b/include/perk/perk_structs.h @@ -166,7 +166,7 @@ struct pe_opt_hdr_align { struct pe_opt_hdr_vers { unsigned char major_os_ver [PE_MAJOR_OPERATING_SYSTEM_VERSION_BS]; /* 0x28 */ - unsigned char minor_or_ver [PE_MINOR_OPERATING_SYSTEM_VERSION_BS]; /* 0x2a */ + unsigned char minor_os_ver [PE_MINOR_OPERATING_SYSTEM_VERSION_BS]; /* 0x2a */ unsigned char major_image_ver [PE_MAJOR_IMAGE_VERSION_BS]; /* 0x2c */ unsigned char minor_image_ver [PE_MINOR_IMAGE_VERSION_BS]; /* 0x2e */ unsigned char major_subsys_ver [PE_MAJOR_SUBSYSTEM_VERSION_BS]; /* 0x30 */ diff --git a/src/internal/perk_impl.h b/src/internal/perk_impl.h index 497ddbe..a47391c 100644 --- a/src/internal/perk_impl.h +++ b/src/internal/perk_impl.h @@ -37,7 +37,7 @@ static inline uint64_t pe_read_quad(const unsigned char * raw) #else -static inline uint16_t pe_read_short(unsigned char * raw) +static inline uint16_t pe_read_short(const unsigned char * raw) { uint16_t x = *(uint16_t *)raw; return x<<8 | x>>8; @@ -48,12 +48,12 @@ static inline uint32_t pe_swap_long(uint32_t x) return x<<24 | (x<<8) & 0xff0000 | (x>>8) & 0xff00 | x>>24; } -static inline uint32_t pe_read_long(unsigned char * raw) +static inline uint32_t pe_read_long(const unsigned char * raw) { return pe_swap_long(*(uint32_t *)raw); } -static inline uint64_t pe_read_quad(unsigned char * raw) +static inline uint64_t pe_read_quad(const unsigned char * raw) { uint64_t x = *(uint64_t *)raw; return ((uint64_t)pe_swap_long(x)<<32) | pe_swap_long(x>>32); diff --git a/src/main/pe_map_raw_image.c b/src/main/pe_map_raw_image.c index 8ae95d9..dc37e35 100644 --- a/src/main/pe_map_raw_image.c +++ b/src/main/pe_map_raw_image.c @@ -37,4 +37,4 @@ int pe_map_raw_image (int fd, const char * fname, struct pe_raw_image * map) int pe_unmap_raw_image (struct pe_raw_image * map) { return munmap(map->addr, map->size); -}; +} diff --git a/src/main/perk.c b/src/main/perk.c index 5fe8f17..d66b9ae 100644 --- a/src/main/perk.c +++ b/src/main/perk.c @@ -112,5 +112,5 @@ static int perk_main(int argc, char * argv[], char * envp[]) } #ifdef PERK_APP -extern __typeof(perk_main) main __attribute__((alias("perk_main"))); +__typeof(perk_main) main __attribute__((alias("perk_main"))); #endif diff --git a/src/reader/pe_read_coff_header.c b/src/reader/pe_read_coff_header.c index e7bdf8a..cc466be 100644 --- a/src/reader/pe_read_coff_header.c +++ b/src/reader/pe_read_coff_header.c @@ -34,4 +34,4 @@ int pe_read_coff_header(const struct pe_coff_file_hdr * p, struct pe_meta_coff_f #endif return 0; -}; +} diff --git a/src/reader/pe_read_dos_header.c b/src/reader/pe_read_dos_header.c index 75b7d31..5f8b14a 100644 --- a/src/reader/pe_read_dos_header.c +++ b/src/reader/pe_read_dos_header.c @@ -6,8 +6,6 @@ int pe_read_dos_header(const struct pe_image_dos_hdr * p, struct pe_meta_image_dos_hdr * m) { - int i; - if ((p->dos_magic[0] != 'M') || (p->dos_magic[1] != 'Z')) return PERK_BAD_DOS_HEADER; @@ -17,6 +15,8 @@ int pe_read_dos_header(const struct pe_image_dos_hdr * p, struct pe_meta_image_d #else + int i; + m->dos_magic[0] = p->dos_magic[0]; m->dos_magic[1] = p->dos_magic[1]; @@ -49,4 +49,4 @@ int pe_read_dos_header(const struct pe_image_dos_hdr * p, struct pe_meta_image_d #endif return 0; -}; +} diff --git a/src/reader/pe_read_export_header.c b/src/reader/pe_read_export_header.c index 6a959c9..97272f4 100644 --- a/src/reader/pe_read_export_header.c +++ b/src/reader/pe_read_export_header.c @@ -29,4 +29,4 @@ int pe_read_export_header(const struct pe_export_hdr * p, struct pe_meta_export_ #endif return 0; -}; +} diff --git a/src/reader/pe_read_import_header.c b/src/reader/pe_read_import_header.c index 7d71143..50434e4 100644 --- a/src/reader/pe_read_import_header.c +++ b/src/reader/pe_read_import_header.c @@ -14,9 +14,9 @@ int pe_read_import_header(const struct pe_import_hdr * p, struct pe_meta_import_ m->import_lookup_tbl_rva = pe_read_long(p->import_lookup_tbl_rva); m->time_date_stamp = pe_read_long(p->time_date_stamp); - m->forwarder_chain = pe_read_long(p>forwarder_chain); + m->forwarder_chain = pe_read_long(p->forwarder_chain); m->name_rva = pe_read_long(p->name_rva); - m->import_addr_tbl_rva = pe_read_long(p>import_addr_tbl_rva); + m->import_addr_tbl_rva = pe_read_long(p->import_addr_tbl_rva); #endif @@ -24,7 +24,7 @@ int pe_read_import_header(const struct pe_import_hdr * p, struct pe_meta_import_ m->aitems = 0; return 0; -}; +} int pe_read_import_lookup_item( const struct pe_import_lookup_item * p, @@ -43,4 +43,4 @@ int pe_read_import_lookup_item( default: return PERK_BAD_IMAGE_TYPE; } -}; +} diff --git a/src/reader/pe_read_optional_header.c b/src/reader/pe_read_optional_header.c index 701c6a9..73443c6 100644 --- a/src/reader/pe_read_optional_header.c +++ b/src/reader/pe_read_optional_header.c @@ -6,14 +6,6 @@ int pe_read_optional_header(const union pe_opt_hdr * p, struct pe_meta_opt_hdr * m) { - struct pe_opt_hdr_std * astd; - struct pe_opt_hdr_vers * avers; - struct pe_opt_hdr_align * aalign; - struct pe_opt_hdr_img * aimg; - struct pe_opt_hdr_ldr * aldr; - struct pe_opt_hdr_dirs * adirs; - size_t sdirs; - m->std.magic = pe_read_short(p->opt_hdr_32.magic); memset(&m->dirs,0,sizeof(m->dirs)); @@ -54,20 +46,28 @@ int pe_read_optional_header(const union pe_opt_hdr * p, struct pe_meta_opt_hdr * #else + struct pe_opt_hdr_std * astd; + struct pe_opt_hdr_vers * avers; + struct pe_opt_hdr_align * aalign; + struct pe_opt_hdr_img * aimg; + struct pe_opt_hdr_ldr * aldr; + struct pe_opt_hdr_dirs * adirs; + size_t sdirs; + astd = (struct pe_opt_hdr_std *)p; switch (m->std.magic) { case PE_MAGIC_PE32: - avers = (struct pe_opt_hdr_std *)&p->opt_hdr_32.major_os_ver; - aalign = (struct pe_opt_hdr_std *)&p->opt_hdr_32.section_align; + avers = (struct pe_opt_hdr_vers *)&p->opt_hdr_32.major_os_ver; + aalign = (struct pe_opt_hdr_align *)&p->opt_hdr_32.section_align; aimg = (struct pe_opt_hdr_img *)&p->opt_hdr_32.size_of_image; aldr = (struct pe_opt_hdr_ldr *)&p->opt_hdr_32.loader_flags; adirs = (struct pe_opt_hdr_dirs *)&p->opt_hdr_32.export_tbl; break; case PE_MAGIC_PE32_PLUS: - avers = (struct pe_opt_hdr_std *)&p->opt_hdr_64.major_os_ver; - aalign = (struct pe_opt_hdr_std *)&p->opt_hdr_64.section_align; + avers = (struct pe_opt_hdr_vers *)&p->opt_hdr_64.major_os_ver; + aalign = (struct pe_opt_hdr_align *)&p->opt_hdr_64.section_align; aimg = (struct pe_opt_hdr_img *)&p->opt_hdr_64.size_of_image; aldr = (struct pe_opt_hdr_ldr *)&p->opt_hdr_64.loader_flags; adirs = (struct pe_opt_hdr_dirs *)&p->opt_hdr_64.export_tbl; @@ -78,8 +78,8 @@ int pe_read_optional_header(const union pe_opt_hdr * p, struct pe_meta_opt_hdr * } /* std */ - m->std.major_linker_ver = astd->major_linker_ver; - m->std.minor_linker_ver = astd->minor_linker_ver; + m->std.major_linker_ver = astd->major_linker_ver[0]; + m->std.minor_linker_ver = astd->minor_linker_ver[0]; m->std.size_of_code = pe_read_long(astd->size_of_code); m->std.size_of_initialized_data = pe_read_long(astd->size_of_initialized_data); @@ -136,4 +136,4 @@ int pe_read_optional_header(const union pe_opt_hdr * p, struct pe_meta_opt_hdr * }; return 0; -}; +} diff --git a/src/reader/pe_read_section_header.c b/src/reader/pe_read_section_header.c index 1a37f63..e6a1d19 100644 --- a/src/reader/pe_read_section_header.c +++ b/src/reader/pe_read_section_header.c @@ -24,7 +24,7 @@ int pe_read_section_header(const struct pe_sec_hdr * p, struct pe_meta_sec_hdr * m->size_of_raw_data = pe_read_long(p->size_of_raw_data); m->ptr_to_raw_data = pe_read_long(p->ptr_to_raw_data); m->ptr_to_relocs = pe_read_long(p->ptr_to_relocs); - m->ptr_to_line_nums = pe_read_long(p->ptr_to_linu_nums); + m->ptr_to_line_nums = pe_read_long(p->ptr_to_line_nums); m->num_of_relocs = pe_read_short(p->num_of_relocs); m->num_of_line_nums = pe_read_short(p->num_of_line_nums); @@ -34,4 +34,4 @@ int pe_read_section_header(const struct pe_sec_hdr * p, struct pe_meta_sec_hdr * #endif return 0; -}; +} |