summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/logic/pe_get_image_subsystem.c47
1 files changed, 47 insertions, 0 deletions
diff --git a/src/logic/pe_get_image_subsystem.c b/src/logic/pe_get_image_subsystem.c
new file mode 100644
index 0000000..3ccf0e6
--- /dev/null
+++ b/src/logic/pe_get_image_subsystem.c
@@ -0,0 +1,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;
+}