summaryrefslogtreecommitdiffhomepage
path: root/src/logic/pe_get_image_subsystem.c
diff options
context:
space:
mode:
authormidipix <writeonce@midipix.org>2016-11-14 22:20:55 -0500
committermidipix <writeonce@midipix.org>2016-11-14 22:20:55 -0500
commit049a18b4747f0b340b15d871dc9936528454d219 (patch)
treec3a0dc641d0c91b3b17a9fc28649ad5a0d725824 /src/logic/pe_get_image_subsystem.c
parent58df628aff5ae52d1e5570287ef3ec3d8c385ae2 (diff)
downloadperk-049a18b4747f0b340b15d871dc9936528454d219.tar.bz2
perk-049a18b4747f0b340b15d871dc9936528454d219.tar.xz
info api: pe_get_image_subsystem(): initial implementation.
Diffstat (limited to 'src/logic/pe_get_image_subsystem.c')
-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;
+}