From 8c7b6a92a909c0fa269439ce06335e7b60baa451 Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 14 Nov 2016 23:09:50 -0500 Subject: info api: pe_get_image_abi(): initial implementation. --- include/perk/perk.h | 1 + include/perk/perk_meta.h | 7 +++++++ project/common.mk | 1 + src/logic/pe_get_image_abi.c | 40 ++++++++++++++++++++++++++++++++++++++++ 4 files changed, 49 insertions(+) create mode 100644 src/logic/pe_get_image_abi.c diff --git a/include/perk/perk.h b/include/perk/perk.h index 895e4a8..88aed0b 100644 --- a/include/perk/perk.h +++ b/include/perk/perk.h @@ -193,6 +193,7 @@ perk_api int pe_get_expsym_by_name (const struct pe_image_meta *, const char * perk_api int pe_get_expsym_by_index (const struct pe_image_meta *, unsigned index, struct pe_expsym * optional); /* info api */ +perk_api int pe_get_image_abi (const struct pe_image_meta *, struct pe_info_string * optional); perk_api int pe_get_image_subtype (const struct pe_image_meta *, struct pe_info_string * optional); perk_api int pe_get_image_subsystem (const struct pe_image_meta *, struct pe_info_string * optional); perk_api int pe_get_image_framework (const struct pe_image_meta *, struct pe_info_string * optional); diff --git a/include/perk/perk_meta.h b/include/perk/perk_meta.h index d39e652..2232085 100644 --- a/include/perk/perk_meta.h +++ b/include/perk/perk_meta.h @@ -7,6 +7,13 @@ extern "C" { #include +enum pe_abi { + PE_ABI_UNSUPPORTED, + PE_ABI_PE32, + PE_ABI_PE64, + PE_ABI_CAP +}; + enum pe_subtype { PE_SUBTYPE_UNRECOGNIZED, PE_SUBTYPE_DLL, diff --git a/project/common.mk b/project/common.mk index 10ae48d..d972c87 100644 --- a/project/common.mk +++ b/project/common.mk @@ -2,6 +2,7 @@ API_SRCS = \ src/driver/pe_amain.c \ src/driver/pe_driver_ctx.c \ src/driver/pe_unit_ctx.c \ + src/logic/pe_get_image_abi.c \ src/logic/pe_get_image_framework.c \ src/logic/pe_get_image_meta.c \ src/logic/pe_get_image_subsystem.c \ diff --git a/src/logic/pe_get_image_abi.c b/src/logic/pe_get_image_abi.c new file mode 100644 index 0000000..7219ba3 --- /dev/null +++ b/src/logic/pe_get_image_abi.c @@ -0,0 +1,40 @@ +/***************************************************************/ +/* perk: PE Resource Kit */ +/* Copyright (C) 2015--2016 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.PERK. */ +/***************************************************************/ + +#include + +#include +#include + +static const char const * pe_abi_str[PE_ABI_CAP] = { + [PE_ABI_UNSUPPORTED] = "UNSUPPORTED", + [PE_ABI_PE32] = "PE32", + [PE_ABI_PE64] = "PE64", +}; + +int pe_get_image_abi(const struct pe_image_meta * m, struct pe_info_string * infostr) +{ + int abi; + + switch (m->opt.std.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 (infostr) + strcpy(infostr->buffer,pe_abi_str[abi]); + + return abi; +} -- cgit v1.2.3