diff options
author | midipix <writeonce@midipix.org> | 2016-11-16 19:23:45 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2016-11-16 19:32:52 -0500 |
commit | 659299fcedad35b6b86d361c74d732494722660d (patch) | |
tree | 6293d6bc4495689af4c5e5b83ba61dcbfab43b8b /src | |
parent | f779e375ef1f739f7ab515a8d853f9f53ac9ec5a (diff) | |
download | perk-659299fcedad35b6b86d361c74d732494722660d.tar.bz2 perk-659299fcedad35b6b86d361c74d732494722660d.tar.xz |
reader: pe_read_optional_header_big_endian(): added missing directory bits.
Diffstat (limited to 'src')
-rw-r--r-- | src/reader/pe_read_optional_header.c | 20 |
1 files changed, 19 insertions, 1 deletions
diff --git a/src/reader/pe_read_optional_header.c b/src/reader/pe_read_optional_header.c index 25c1b34..4625796 100644 --- a/src/reader/pe_read_optional_header.c +++ b/src/reader/pe_read_optional_header.c @@ -53,6 +53,10 @@ static int pe_read_optional_header_little_endian(const union pe_opt_hdr * p, str static int pe_read_optional_header_big_endian(const union pe_opt_hdr * p, struct pe_meta_opt_hdr * m) { + unsigned int i; + struct pe_block * pdir; + const unsigned char * mark; + struct pe_opt_hdr_std * astd; struct pe_opt_hdr_vers * avers; struct pe_opt_hdr_align * aalign; @@ -60,7 +64,6 @@ static int pe_read_optional_header_big_endian(const union pe_opt_hdr * p, struct struct pe_opt_hdr_ldr * aldr; m->std.magic = pe_read_short(p->opt_hdr_32.magic); - memset(&m->dirs,0,sizeof(m->dirs)); astd = (struct pe_opt_hdr_std *)p; @@ -119,6 +122,21 @@ static int pe_read_optional_header_big_endian(const union pe_opt_hdr * p, struct m->ldr.loader_flags = pe_read_long(aldr->loader_flags); m->ldr.rva_and_sizes = pe_read_long(aldr->rva_and_sizes); + /* dirs */ + if (m->ldr.rva_and_sizes > 0x10) + return PERK_ERR_BAD_IMAGE_TYPE; + + if (m->ldr.rva_and_sizes < 0x10) + memset(&m->dirs,0,sizeof(m->dirs)); + + mark = p->opt_hdr_64.export_tbl; + pdir = &m->dirs.export_tbl; + + for (i=0; i<m->ldr.rva_and_sizes; i++) { + pdir[i].rva = pe_read_long(&mark[i*8]); + pdir[i].size = pe_read_long(&mark[i*8+4]); + } + return 0; } |