summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--include/perk/perk.h1
-rw-r--r--project/common.mk1
-rw-r--r--src/logic/pe_get_image_subsystem.c47
3 files changed, 49 insertions, 0 deletions
diff --git a/include/perk/perk.h b/include/perk/perk.h
index 02d3275..af63b33 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_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);
/* low-level api */
diff --git a/project/common.mk b/project/common.mk
index b71e972..acb07d8 100644
--- a/project/common.mk
+++ b/project/common.mk
@@ -4,6 +4,7 @@ API_SRCS = \
src/driver/pe_unit_ctx.c \
src/logic/pe_get_image_framework.c \
src/logic/pe_get_image_meta.c \
+ src/logic/pe_get_image_subsystem.c \
src/logic/pe_map_raw_image.c \
src/output/pe_output_error.c \
src/output/pe_output_export_symbols.c \
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;
+}