summaryrefslogtreecommitdiffhomepage
path: root/src/logic/pe_get_image_abi.c
blob: 7219ba339f01d34f4436fbebcc55eed02bb275e8 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
/***************************************************************/
/*  perk: PE Resource Kit                                      */
/*  Copyright (C) 2015--2016  Z. Gilboa                        */
/*  Released under GPLv2 and GPLv3; see COPYING.PERK.          */
/***************************************************************/

#include <string.h>

#include <perk/perk.h>
#include <perk/perk_meta.h>

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;
}