diff options
author | midipix <writeonce@midipix.org> | 2018-11-02 21:30:13 -0500 |
---|---|---|
committer | midipix <writeonce@midipix.org> | 2018-11-20 20:25:14 -0500 |
commit | 1808909e9661994eee2471126c15d9e2365ad117 (patch) | |
tree | c2e979b75e70b22e05e33ccca3186ebaf914a7ce /src/logic | |
parent | 867bfb7742d38371154f89b5afa97719a106d7b8 (diff) | |
download | perk-1808909e9661994eee2471126c15d9e2365ad117.tar.bz2 perk-1808909e9661994eee2471126c15d9e2365ad117.tar.xz |
pe_get_image_meta(), pe_get_image_abi(): init/use the .m_abi member.
Diffstat (limited to 'src/logic')
-rw-r--r-- | src/logic/pe_get_image_meta.c | 50 |
1 files changed, 46 insertions, 4 deletions
diff --git a/src/logic/pe_get_image_meta.c b/src/logic/pe_get_image_meta.c index b8bf8a8..826b36b 100644 --- a/src/logic/pe_get_image_meta.c +++ b/src/logic/pe_get_image_meta.c @@ -171,6 +171,44 @@ int pe_get_expsym_by_index( return 0; } +static void pe_detect_image_abi(struct pe_image_meta * m) +{ + int abi; + + if (m->r_obj) { + switch (m->m_coff.cfh_machine) { + case PE_IMAGE_FILE_MACHINE_I386: + abi = PE_ABI_PE32; + break; + + case PE_IMAGE_FILE_MACHINE_IA64: + case PE_IMAGE_FILE_MACHINE_AMD64: + abi = PE_ABI_PE64; + break; + + default: + abi = PE_ABI_UNSUPPORTED; + break; + } + } else { + switch (m->m_opt.oh_std.coh_magic) { + case PE_MAGIC_PE32: + abi = PE_ABI_PE32; + break; + + case PE_MAGIC_PE32_PLUS: + abi = PE_ABI_PE64; + break; + + default: + abi = PE_ABI_UNSUPPORTED; + break; + } + } + + m->m_abi = abi; +} + int pe_get_image_meta( const struct pe_driver_ctx * dctx, const struct pe_raw_image * image, @@ -384,16 +422,20 @@ int pe_get_image_meta( m->r_dsodata = base + m->m_sectbl[i].sh_ptr_to_raw_data; } + /* image */ + m->r_image.map_addr = image->map_addr; + m->r_image.map_size = image->map_size; + + /* info */ + pe_detect_image_abi(m); + /* mdso abi */ if (m->h_dsometa || m->h_dsosyms) - if (pe_get_image_abi(m,0) == PE_ABI_UNSUPPORTED) + if (m->m_abi == PE_ABI_UNSUPPORTED) return pe_free_image_meta_impl( m,PERK_CUSTOM_ERROR( dctx,PERK_ERR_UNSUPPORTED_ABI)); - /* image */ - m->r_image.map_addr = image->map_addr; - m->r_image.map_size = image->map_size; /* all done */ *meta = m; |