summaryrefslogtreecommitdiffhomepage
path: root/src
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2018-11-02 21:30:13 -0500
committermidipix <writeonce@midipix.org>2018-11-20 20:25:14 -0500
commit1808909e9661994eee2471126c15d9e2365ad117 (patch)
treec2e979b75e70b22e05e33ccca3186ebaf914a7ce /src
parent867bfb7742d38371154f89b5afa97719a106d7b8 (diff)
downloadperk-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')
-rw-r--r--src/info/pe_get_image_abi.c32
-rw-r--r--src/logic/pe_get_image_meta.c50
2 files changed, 48 insertions, 34 deletions
diff --git a/src/info/pe_get_image_abi.c b/src/info/pe_get_image_abi.c
index cea0d2c..f135fea 100644
--- a/src/info/pe_get_image_abi.c
+++ b/src/info/pe_get_image_abi.c
@@ -19,36 +19,8 @@ int pe_get_image_abi(const struct pe_image_meta * m, struct pe_info_string * inf
{
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;
- }
- }
+ if (((abi = m->m_abi) < 0) || (abi >= PE_ABI_CAP))
+ abi = PE_ABI_UNSUPPORTED;
if (infostr)
strcpy(infostr->buffer,pe_abi_str[abi]);
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;