summaryrefslogtreecommitdiffhomepage
path: root/src/logic/pe_get_image_subsystem.c
blob: 3ccf0e6027a3c8f1ba52d961e75c6efd906fd600 (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
41
42
43
44
45
46
47
/***************************************************************/
/*  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_subsystem_str[0x10] = {
	[PE_IMAGE_SUBSYSTEM_UNKNOWN]                  = "unknown",
	[PE_IMAGE_SUBSYSTEM_NATIVE]                   = "native",
	[PE_IMAGE_SUBSYSTEM_WINDOWS_GUI]              = "windows",
	[PE_IMAGE_SUBSYSTEM_WINDOWS_CUI]              = "console",
	[PE_IMAGE_SUBSYSTEM_POSIX_CUI]                = "posix",
	[PE_IMAGE_SUBSYSTEM_WINDOWS_CE_GUI]           = "wince",
	[PE_IMAGE_SUBSYSTEM_EFI_APPLICATION]          = "efi_app",
	[PE_IMAGE_SUBSYSTEM_EFI_BOOT_SERVICE_DRIVER]  = "efi_driver",
	[PE_IMAGE_SUBSYSTEM_EFI_ROM]                  = "efi_rom",
	[PE_IMAGE_SUBSYSTEM_XBOX]                     = "xbox"
};

int pe_get_image_subsystem(const struct pe_image_meta * m, struct pe_info_string * infostr)
{
	int subsystem;

	if (m->opt.img.subsystem >= 0x10)
		subsystem = -1;

	else if (!pe_subsystem_str[m->opt.img.subsystem])
		subsystem = -1;

	else
		subsystem = m->opt.img.subsystem;

	if ((subsystem < 0) && infostr) {
		strcpy(infostr->buffer,"INVALID");
		return subsystem;
	}

	if (infostr)
		strcpy(infostr->buffer,pe_subsystem_str[subsystem]);

	return subsystem;
}