|
|
bf447f |
/***************************************************************/
|
|
|
bf447f |
/* perk: PE Resource Kit */
|
|
|
ced38a |
/* Copyright (C) 2015--2017 Z. Gilboa */
|
|
|
bf447f |
/* Released under GPLv2 and GPLv3; see COPYING.PERK. */
|
|
|
bf447f |
/***************************************************************/
|
|
|
bf447f |
|
|
|
bf447f |
#include <string.h>
|
|
|
bf447f |
#include <stdbool.h>
|
|
|
bf447f |
|
|
|
bf447f |
#include <perk/perk.h>
|
|
|
bf447f |
#include <perk/perk_meta.h>
|
|
|
bf447f |
|
|
|
6ad4d2 |
static const char * const pe_framework_str[PE_FRAMEWORK_CAP] = {
|
|
|
bf447f |
[PE_FRAMEWORK_UNKNOWN] = "unknown",
|
|
|
bf447f |
[PE_FRAMEWORK_FREESTD] = "freestd",
|
|
|
bf447f |
[PE_FRAMEWORK_PSXSCL] = "psxscl",
|
|
|
bf447f |
[PE_FRAMEWORK_MIDIPIX] = "midipix",
|
|
|
bf447f |
[PE_FRAMEWORK_CYGONE] = "cygone",
|
|
|
bf447f |
[PE_FRAMEWORK_CYGWIN] = "cygwin",
|
|
|
bf447f |
[PE_FRAMEWORK_MINGW] = "mingw",
|
|
|
bf447f |
[PE_FRAMEWORK_MSYS] = "msys",
|
|
|
bf447f |
[PE_FRAMEWORK_SUACON] = "suacon",
|
|
|
bf447f |
[PE_FRAMEWORK_WINCON] = "wincon",
|
|
|
bf447f |
[PE_FRAMEWORK_WINCLI] = "wincli",
|
|
|
bf447f |
[PE_FRAMEWORK_WIN32] = "win32",
|
|
|
bf447f |
};
|
|
|
bf447f |
|
|
|
bf447f |
static bool pe_image_is_psxscl(const struct pe_image_meta * m)
|
|
|
bf447f |
{
|
|
|
58ced9 |
return (!m->m_stats.nimplibs
|
|
|
bf447f |
&& !pe_get_expsym_by_name(m,"__psx_init",0));
|
|
|
bf447f |
}
|
|
|
bf447f |
|
|
|
bf447f |
static bool pe_image_is_cygwin(const struct pe_image_meta * m)
|
|
|
bf447f |
{
|
|
|
bf447f |
int i;
|
|
|
bf447f |
|
|
|
58ced9 |
for (i=0; i<m->m_stats.nimplibs; i++)
|
|
|
58ced9 |
if (!(strcmp(m->m_idata[i].ih_name,"cygwin1.dll")))
|
|
|
bf447f |
return true;
|
|
|
bf447f |
|
|
|
bf447f |
return false;
|
|
|
bf447f |
}
|
|
|
bf447f |
|
|
|
bf447f |
static bool pe_image_is_msys(const struct pe_image_meta * m)
|
|
|
bf447f |
{
|
|
|
bf447f |
int i;
|
|
|
bf447f |
|
|
|
58ced9 |
for (i=0; i<m->m_stats.nimplibs; i++)
|
|
|
58ced9 |
if (!(strcmp(m->m_idata[i].ih_name,"msys-2.0.dll")))
|
|
|
bf447f |
return true;
|
|
|
bf447f |
|
|
|
bf447f |
return false;
|
|
|
bf447f |
}
|
|
|
bf447f |
|
|
|
bf447f |
static bool pe_image_is_mingw(const struct pe_image_meta * m)
|
|
|
bf447f |
{
|
|
|
bf447f |
return ((pe_get_named_section_index(m,".CRT") >= 0)
|
|
|
bf447f |
&& (pe_get_named_section_index(m,".bss") >= 0)
|
|
|
bf447f |
&& (pe_get_named_section_index(m,".tls") >= 0));
|
|
|
bf447f |
}
|
|
|
bf447f |
|
|
|
bf447f |
int pe_get_image_framework(const struct pe_image_meta * m, struct pe_info_string * infostr)
|
|
|
bf447f |
{
|
|
|
bf447f |
int framework;
|
|
|
bf447f |
|
|
|
bf447f |
if (pe_get_named_section_index(m,".midipix") >= 0)
|
|
|
bf447f |
framework = PE_FRAMEWORK_MIDIPIX;
|
|
|
bf447f |
|
|
|
bf447f |
else if (pe_get_named_section_index(m,".freestd") >= 0)
|
|
|
bf447f |
framework = PE_FRAMEWORK_FREESTD;
|
|
|
bf447f |
|
|
|
bf447f |
else if (pe_get_named_section_index(m,".cygheap") >= 0)
|
|
|
bf447f |
framework = PE_FRAMEWORK_CYGONE;
|
|
|
bf447f |
|
|
|
bf447f |
else if (pe_image_is_psxscl(m))
|
|
|
bf447f |
framework = PE_FRAMEWORK_PSXSCL;
|
|
|
bf447f |
|
|
|
bf447f |
else if (pe_image_is_cygwin(m))
|
|
|
bf447f |
framework = PE_FRAMEWORK_CYGWIN;
|
|
|
bf447f |
|
|
|
bf447f |
else if (pe_image_is_msys(m))
|
|
|
bf447f |
framework = PE_FRAMEWORK_MSYS;
|
|
|
bf447f |
|
|
|
bf447f |
else if (pe_image_is_mingw(m))
|
|
|
bf447f |
framework = PE_FRAMEWORK_MINGW;
|
|
|
bf447f |
|
|
|
58ced9 |
else if (m->m_opt.oh_img.coh_subsystem == PE_IMAGE_SUBSYSTEM_POSIX_CUI)
|
|
|
bf447f |
framework = PE_FRAMEWORK_SUACON;
|
|
|
bf447f |
|
|
|
58ced9 |
else if (m->m_opt.oh_img.coh_subsystem == PE_IMAGE_SUBSYSTEM_WINDOWS_CUI)
|
|
|
bf447f |
framework = PE_FRAMEWORK_WINCON;
|
|
|
bf447f |
|
|
|
58ced9 |
else if (m->m_opt.oh_img.coh_subsystem == PE_IMAGE_SUBSYSTEM_WINDOWS_GUI)
|
|
|
bf447f |
framework = PE_FRAMEWORK_WIN32;
|
|
|
bf447f |
|
|
|
bf447f |
else
|
|
|
bf447f |
framework = PE_FRAMEWORK_UNKNOWN;
|
|
|
bf447f |
|
|
|
bf447f |
if (infostr)
|
|
|
bf447f |
strcpy(infostr->buffer,pe_framework_str[framework]);
|
|
|
bf447f |
|
|
|
bf447f |
return framework;
|
|
|
bf447f |
}
|