From b64d661dc38805d6ad5798be568fa8c41720df5c Mon Sep 17 00:00:00 2001 From: midipix Date: Mon, 14 Nov 2016 23:24:09 -0500 Subject: project: source tree layout: moved info source files under src/info. --- project/common.mk | 8 +-- project/tree.mk | 1 + src/info/pe_get_image_abi.c | 40 ++++++++++++++ src/info/pe_get_image_framework.c | 104 +++++++++++++++++++++++++++++++++++++ src/info/pe_get_image_subsystem.c | 47 +++++++++++++++++ src/info/pe_get_image_subtype.c | 35 +++++++++++++ src/logic/pe_get_image_abi.c | 40 -------------- src/logic/pe_get_image_framework.c | 104 ------------------------------------- src/logic/pe_get_image_subsystem.c | 47 ----------------- src/logic/pe_get_image_subtype.c | 35 ------------- 10 files changed, 231 insertions(+), 230 deletions(-) create mode 100644 src/info/pe_get_image_abi.c create mode 100644 src/info/pe_get_image_framework.c create mode 100644 src/info/pe_get_image_subsystem.c create mode 100644 src/info/pe_get_image_subtype.c delete mode 100644 src/logic/pe_get_image_abi.c delete mode 100644 src/logic/pe_get_image_framework.c delete mode 100644 src/logic/pe_get_image_subsystem.c delete mode 100644 src/logic/pe_get_image_subtype.c diff --git a/project/common.mk b/project/common.mk index d972c87..70041dd 100644 --- a/project/common.mk +++ b/project/common.mk @@ -2,11 +2,11 @@ API_SRCS = \ src/driver/pe_amain.c \ src/driver/pe_driver_ctx.c \ src/driver/pe_unit_ctx.c \ - src/logic/pe_get_image_abi.c \ - src/logic/pe_get_image_framework.c \ + src/info/pe_get_image_abi.c \ + src/info/pe_get_image_framework.c \ + src/info/pe_get_image_subsystem.c \ + src/info/pe_get_image_subtype.c \ src/logic/pe_get_image_meta.c \ - src/logic/pe_get_image_subsystem.c \ - src/logic/pe_get_image_subtype.c \ src/logic/pe_map_raw_image.c \ src/output/pe_output_error.c \ src/output/pe_output_export_symbols.c \ diff --git a/project/tree.mk b/project/tree.mk index b1d880c..7606638 100644 --- a/project/tree.mk +++ b/project/tree.mk @@ -1,6 +1,7 @@ tree.tag: mkdir -p src mkdir -p src/driver + mkdir -p src/info mkdir -p src/internal mkdir -p src/logic mkdir -p src/output diff --git a/src/info/pe_get_image_abi.c b/src/info/pe_get_image_abi.c new file mode 100644 index 0000000..7219ba3 --- /dev/null +++ b/src/info/pe_get_image_abi.c @@ -0,0 +1,40 @@ +/***************************************************************/ +/* perk: PE Resource Kit */ +/* Copyright (C) 2015--2016 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.PERK. */ +/***************************************************************/ + +#include + +#include +#include + +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; +} diff --git a/src/info/pe_get_image_framework.c b/src/info/pe_get_image_framework.c new file mode 100644 index 0000000..ba44d2f --- /dev/null +++ b/src/info/pe_get_image_framework.c @@ -0,0 +1,104 @@ +/***************************************************************/ +/* perk: PE Resource Kit */ +/* Copyright (C) 2015--2016 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.PERK. */ +/***************************************************************/ + +#include +#include + +#include +#include + +static const char const * pe_framework_str[PE_FRAMEWORK_CAP] = { + [PE_FRAMEWORK_UNKNOWN] = "unknown", + [PE_FRAMEWORK_FREESTD] = "freestd", + [PE_FRAMEWORK_PSXSCL] = "psxscl", + [PE_FRAMEWORK_MIDIPIX] = "midipix", + [PE_FRAMEWORK_CYGONE] = "cygone", + [PE_FRAMEWORK_CYGWIN] = "cygwin", + [PE_FRAMEWORK_MINGW] = "mingw", + [PE_FRAMEWORK_MSYS] = "msys", + [PE_FRAMEWORK_SUACON] = "suacon", + [PE_FRAMEWORK_WINCON] = "wincon", + [PE_FRAMEWORK_WINCLI] = "wincli", + [PE_FRAMEWORK_WIN32] = "win32", +}; + +static bool pe_image_is_psxscl(const struct pe_image_meta * m) +{ + return (!m->summary.nimplibs + && !pe_get_expsym_by_name(m,"__psx_init",0)); +} + +static bool pe_image_is_cygwin(const struct pe_image_meta * m) +{ + int i; + + for (i=0; isummary.nimplibs; i++) + if (!(strcmp(m->idata[i].name,"cygwin1.dll"))) + return true; + + return false; +} + +static bool pe_image_is_msys(const struct pe_image_meta * m) +{ + int i; + + for (i=0; isummary.nimplibs; i++) + if (!(strcmp(m->idata[i].name,"msys-2.0.dll"))) + return true; + + return false; +} + +static bool pe_image_is_mingw(const struct pe_image_meta * m) +{ + return ((pe_get_named_section_index(m,".CRT") >= 0) + && (pe_get_named_section_index(m,".bss") >= 0) + && (pe_get_named_section_index(m,".tls") >= 0)); +} + +int pe_get_image_framework(const struct pe_image_meta * m, struct pe_info_string * infostr) +{ + int framework; + + if (pe_get_named_section_index(m,".midipix") >= 0) + framework = PE_FRAMEWORK_MIDIPIX; + + else if (pe_get_named_section_index(m,".freestd") >= 0) + framework = PE_FRAMEWORK_FREESTD; + + else if (pe_get_named_section_index(m,".cygheap") >= 0) + framework = PE_FRAMEWORK_CYGONE; + + else if (pe_image_is_psxscl(m)) + framework = PE_FRAMEWORK_PSXSCL; + + else if (pe_image_is_cygwin(m)) + framework = PE_FRAMEWORK_CYGWIN; + + else if (pe_image_is_msys(m)) + framework = PE_FRAMEWORK_MSYS; + + else if (pe_image_is_mingw(m)) + framework = PE_FRAMEWORK_MINGW; + + else if (m->opt.img.subsystem == PE_IMAGE_SUBSYSTEM_POSIX_CUI) + framework = PE_FRAMEWORK_SUACON; + + else if (m->opt.img.subsystem == PE_IMAGE_SUBSYSTEM_WINDOWS_CUI) + framework = PE_FRAMEWORK_WINCON; + + else if (m->opt.img.subsystem == PE_IMAGE_SUBSYSTEM_WINDOWS_GUI) + framework = PE_FRAMEWORK_WIN32; + + else + framework = PE_FRAMEWORK_UNKNOWN; + + if (infostr) + strcpy(infostr->buffer,pe_framework_str[framework]); + + return framework; +} diff --git a/src/info/pe_get_image_subsystem.c b/src/info/pe_get_image_subsystem.c new file mode 100644 index 0000000..3ccf0e6 --- /dev/null +++ b/src/info/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 + +#include +#include + +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; +} diff --git a/src/info/pe_get_image_subtype.c b/src/info/pe_get_image_subtype.c new file mode 100644 index 0000000..7e19ef1 --- /dev/null +++ b/src/info/pe_get_image_subtype.c @@ -0,0 +1,35 @@ +/***************************************************************/ +/* perk: PE Resource Kit */ +/* Copyright (C) 2015--2016 Z. Gilboa */ +/* Released under GPLv2 and GPLv3; see COPYING.PERK. */ +/***************************************************************/ + +#include + +#include +#include + +/* todo: object, unrecognized */ + +static const char const * pe_subtype_str[PE_SUBTYPE_CAP] = { + [PE_SUBTYPE_UNRECOGNIZED] = "UNRECOGNIZED", + [PE_SUBTYPE_DLL] = "dll", + [PE_SUBTYPE_EXE] = "exe", + [PE_SUBTYPE_OBJ] = "obj", +}; + +int pe_get_image_subtype(const struct pe_image_meta * m, struct pe_info_string * infostr) +{ + int subtype; + + if (m->coff.characteristics & PE_IMAGE_FILE_DLL) + subtype = PE_SUBTYPE_DLL; + + else + subtype = PE_SUBTYPE_EXE; + + if (infostr) + strcpy(infostr->buffer,pe_subtype_str[subtype]); + + return subtype; +} diff --git a/src/logic/pe_get_image_abi.c b/src/logic/pe_get_image_abi.c deleted file mode 100644 index 7219ba3..0000000 --- a/src/logic/pe_get_image_abi.c +++ /dev/null @@ -1,40 +0,0 @@ -/***************************************************************/ -/* perk: PE Resource Kit */ -/* Copyright (C) 2015--2016 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.PERK. */ -/***************************************************************/ - -#include - -#include -#include - -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; -} diff --git a/src/logic/pe_get_image_framework.c b/src/logic/pe_get_image_framework.c deleted file mode 100644 index ba44d2f..0000000 --- a/src/logic/pe_get_image_framework.c +++ /dev/null @@ -1,104 +0,0 @@ -/***************************************************************/ -/* perk: PE Resource Kit */ -/* Copyright (C) 2015--2016 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.PERK. */ -/***************************************************************/ - -#include -#include - -#include -#include - -static const char const * pe_framework_str[PE_FRAMEWORK_CAP] = { - [PE_FRAMEWORK_UNKNOWN] = "unknown", - [PE_FRAMEWORK_FREESTD] = "freestd", - [PE_FRAMEWORK_PSXSCL] = "psxscl", - [PE_FRAMEWORK_MIDIPIX] = "midipix", - [PE_FRAMEWORK_CYGONE] = "cygone", - [PE_FRAMEWORK_CYGWIN] = "cygwin", - [PE_FRAMEWORK_MINGW] = "mingw", - [PE_FRAMEWORK_MSYS] = "msys", - [PE_FRAMEWORK_SUACON] = "suacon", - [PE_FRAMEWORK_WINCON] = "wincon", - [PE_FRAMEWORK_WINCLI] = "wincli", - [PE_FRAMEWORK_WIN32] = "win32", -}; - -static bool pe_image_is_psxscl(const struct pe_image_meta * m) -{ - return (!m->summary.nimplibs - && !pe_get_expsym_by_name(m,"__psx_init",0)); -} - -static bool pe_image_is_cygwin(const struct pe_image_meta * m) -{ - int i; - - for (i=0; isummary.nimplibs; i++) - if (!(strcmp(m->idata[i].name,"cygwin1.dll"))) - return true; - - return false; -} - -static bool pe_image_is_msys(const struct pe_image_meta * m) -{ - int i; - - for (i=0; isummary.nimplibs; i++) - if (!(strcmp(m->idata[i].name,"msys-2.0.dll"))) - return true; - - return false; -} - -static bool pe_image_is_mingw(const struct pe_image_meta * m) -{ - return ((pe_get_named_section_index(m,".CRT") >= 0) - && (pe_get_named_section_index(m,".bss") >= 0) - && (pe_get_named_section_index(m,".tls") >= 0)); -} - -int pe_get_image_framework(const struct pe_image_meta * m, struct pe_info_string * infostr) -{ - int framework; - - if (pe_get_named_section_index(m,".midipix") >= 0) - framework = PE_FRAMEWORK_MIDIPIX; - - else if (pe_get_named_section_index(m,".freestd") >= 0) - framework = PE_FRAMEWORK_FREESTD; - - else if (pe_get_named_section_index(m,".cygheap") >= 0) - framework = PE_FRAMEWORK_CYGONE; - - else if (pe_image_is_psxscl(m)) - framework = PE_FRAMEWORK_PSXSCL; - - else if (pe_image_is_cygwin(m)) - framework = PE_FRAMEWORK_CYGWIN; - - else if (pe_image_is_msys(m)) - framework = PE_FRAMEWORK_MSYS; - - else if (pe_image_is_mingw(m)) - framework = PE_FRAMEWORK_MINGW; - - else if (m->opt.img.subsystem == PE_IMAGE_SUBSYSTEM_POSIX_CUI) - framework = PE_FRAMEWORK_SUACON; - - else if (m->opt.img.subsystem == PE_IMAGE_SUBSYSTEM_WINDOWS_CUI) - framework = PE_FRAMEWORK_WINCON; - - else if (m->opt.img.subsystem == PE_IMAGE_SUBSYSTEM_WINDOWS_GUI) - framework = PE_FRAMEWORK_WIN32; - - else - framework = PE_FRAMEWORK_UNKNOWN; - - if (infostr) - strcpy(infostr->buffer,pe_framework_str[framework]); - - return framework; -} diff --git a/src/logic/pe_get_image_subsystem.c b/src/logic/pe_get_image_subsystem.c deleted file mode 100644 index 3ccf0e6..0000000 --- a/src/logic/pe_get_image_subsystem.c +++ /dev/null @@ -1,47 +0,0 @@ -/***************************************************************/ -/* perk: PE Resource Kit */ -/* Copyright (C) 2015--2016 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.PERK. */ -/***************************************************************/ - -#include - -#include -#include - -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; -} diff --git a/src/logic/pe_get_image_subtype.c b/src/logic/pe_get_image_subtype.c deleted file mode 100644 index 7e19ef1..0000000 --- a/src/logic/pe_get_image_subtype.c +++ /dev/null @@ -1,35 +0,0 @@ -/***************************************************************/ -/* perk: PE Resource Kit */ -/* Copyright (C) 2015--2016 Z. Gilboa */ -/* Released under GPLv2 and GPLv3; see COPYING.PERK. */ -/***************************************************************/ - -#include - -#include -#include - -/* todo: object, unrecognized */ - -static const char const * pe_subtype_str[PE_SUBTYPE_CAP] = { - [PE_SUBTYPE_UNRECOGNIZED] = "UNRECOGNIZED", - [PE_SUBTYPE_DLL] = "dll", - [PE_SUBTYPE_EXE] = "exe", - [PE_SUBTYPE_OBJ] = "obj", -}; - -int pe_get_image_subtype(const struct pe_image_meta * m, struct pe_info_string * infostr) -{ - int subtype; - - if (m->coff.characteristics & PE_IMAGE_FILE_DLL) - subtype = PE_SUBTYPE_DLL; - - else - subtype = PE_SUBTYPE_EXE; - - if (infostr) - strcpy(infostr->buffer,pe_subtype_str[subtype]); - - return subtype; -} -- cgit v1.2.3