2008-03-24 16:30:07 +01:00
|
|
|
/*
|
|
|
|
|
|
|
|
File: misc.c
|
|
|
|
|
|
|
|
Copyright (C) 2008 Christophe GRENIER <grenier@cgsecurity.org>
|
|
|
|
|
|
|
|
This software is free software; you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation; either version 2 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License along
|
|
|
|
with this program; if not, write the Free Software Foundation, Inc., 51
|
|
|
|
Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
|
|
|
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifdef HAVE_CONFIG_H
|
|
|
|
#include <config.h>
|
|
|
|
#endif
|
|
|
|
|
2020-06-02 17:33:50 +02:00
|
|
|
#if defined(__FRAMAC__)
|
|
|
|
#undef HAVE_STRPTIME
|
|
|
|
#undef HAVE_SYS_UTSNAME_H
|
|
|
|
#undef HAVE_UNAME
|
|
|
|
#endif
|
|
|
|
|
2008-03-24 16:30:07 +01:00
|
|
|
#include <string.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <stdarg.h>
|
|
|
|
#include <stdio.h>
|
|
|
|
#include <stdlib.h>
|
|
|
|
#ifdef HAVE_WINDOWS_H
|
|
|
|
# include <windows.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_UTSNAME_H
|
|
|
|
# include <sys/utsname.h>
|
|
|
|
#endif
|
2011-04-24 22:36:38 +02:00
|
|
|
#ifdef HAVE_TIME_H
|
|
|
|
#include <time.h>
|
|
|
|
#endif
|
|
|
|
#ifdef HAVE_SYS_TIME_H
|
|
|
|
#include <sys/time.h>
|
|
|
|
#endif
|
2008-03-24 16:30:07 +01:00
|
|
|
#ifdef HAVE_CYGWIN_VERSION_H
|
|
|
|
#include <cygwin/version.h>
|
|
|
|
#endif
|
|
|
|
#include "types.h"
|
|
|
|
#include "common.h"
|
|
|
|
#include "misc.h"
|
|
|
|
|
|
|
|
const char *get_os(void)
|
|
|
|
{
|
|
|
|
#ifdef WIN32
|
|
|
|
{
|
2011-04-23 14:39:51 +02:00
|
|
|
static char buffer[100] = {0x00};
|
2008-03-24 16:30:07 +01:00
|
|
|
/* For more information, read
|
2015-04-11 13:56:03 +02:00
|
|
|
https://msdn.microsoft.com/en-us/library/windows/desktop/ms724834%28v=vs.85%29.aspx
|
2008-03-24 16:30:07 +01:00
|
|
|
*/
|
|
|
|
OSVERSIONINFOEX Ver;
|
|
|
|
int Extended = 1;
|
|
|
|
memset(&Ver,0,sizeof(OSVERSIONINFOEX));
|
|
|
|
Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFOEX);
|
|
|
|
|
|
|
|
if (!GetVersionEx((OSVERSIONINFO *)&Ver)) {
|
|
|
|
Extended = 0;
|
|
|
|
Ver.dwOSVersionInfoSize = sizeof(OSVERSIONINFO);
|
|
|
|
if (!GetVersionEx((OSVERSIONINFO *)&Ver)) {
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows");
|
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* ----------------- 9x/NT4 family ------------------ */
|
|
|
|
|
|
|
|
if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 0)
|
|
|
|
{
|
|
|
|
/* no info about Win95 SP1, Win95 OSR2.1, Win95 OSR2.5.... */
|
|
|
|
if(Ver.dwBuildNumber == 950)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows 95");
|
|
|
|
else if (Ver.dwBuildNumber == 1111)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows 95 OSR2.x");
|
|
|
|
else if(Ver.dwBuildNumber == 1381)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows NT 4.0");
|
|
|
|
else
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows 95 or NT 4.0 (%lu)", Ver.dwBuildNumber);
|
|
|
|
}
|
|
|
|
else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 10)
|
|
|
|
{
|
|
|
|
/* no info about Win98 SP1.... */
|
|
|
|
if(Ver.dwBuildNumber == 1998)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows 98");
|
|
|
|
else if (Ver.dwBuildNumber == 2222)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows 98 SE");
|
|
|
|
else
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows 98 (%lu)", Ver.dwBuildNumber);
|
|
|
|
}
|
|
|
|
else if (Ver.dwMajorVersion == 4 && Ver.dwMinorVersion == 90)
|
|
|
|
{
|
|
|
|
if(Ver.dwBuildNumber == 3000)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows ME");
|
|
|
|
else
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows ME (%lu)", Ver.dwBuildNumber);
|
|
|
|
}
|
|
|
|
else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 0)
|
|
|
|
{
|
|
|
|
if(Ver.dwBuildNumber == 2195)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows 2000");
|
|
|
|
else
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows 2000 (%lu)", Ver.dwBuildNumber);
|
|
|
|
}
|
|
|
|
else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 1)
|
|
|
|
{
|
|
|
|
if(Ver.dwBuildNumber == 2600)
|
|
|
|
{
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows XP");
|
|
|
|
#if defined(_MSC_VER) && _MSC_VER > 1200 /* 6.0 has it undeclared */
|
|
|
|
if (Extended) {
|
|
|
|
if (Ver.wSuiteMask & VER_SUITE_PERSONAL) {
|
|
|
|
snprintf(buffer+strlen(buffer), sizeof(buffer) - 1 - strlen(buffer)," Home");
|
|
|
|
} else {
|
|
|
|
snprintf(buffer+strlen(buffer), sizeof(buffer) - 1 - strlen(buffer)," Pro");
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
else
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows XP (%lu)", Ver.dwBuildNumber);
|
|
|
|
}
|
|
|
|
else if (Ver.dwMajorVersion == 5 && Ver.dwMinorVersion == 2)
|
|
|
|
{
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows 2003 (%lu)", Ver.dwBuildNumber);
|
|
|
|
}
|
|
|
|
else if (Ver.dwMajorVersion == 6 && Ver.dwMinorVersion == 0)
|
|
|
|
{
|
2009-09-03 08:16:31 +02:00
|
|
|
if( Ver.wProductType == VER_NT_WORKSTATION )
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows Vista (%lu)", Ver.dwBuildNumber);
|
|
|
|
else
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows Server 2008 (%lu)", Ver.dwBuildNumber);
|
2008-03-24 16:30:07 +01:00
|
|
|
}
|
2009-09-03 08:16:31 +02:00
|
|
|
else if (Ver.dwMajorVersion == 6 && Ver.dwMinorVersion == 1)
|
2008-03-24 16:30:07 +01:00
|
|
|
{
|
2009-09-03 08:16:31 +02:00
|
|
|
if( Ver.wProductType == VER_NT_WORKSTATION )
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows 7 (%lu)", Ver.dwBuildNumber);
|
|
|
|
else
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows Server 2008 R2 (%lu)", Ver.dwBuildNumber);
|
2008-03-24 16:30:07 +01:00
|
|
|
}
|
2015-04-11 13:56:03 +02:00
|
|
|
else if (Ver.dwMajorVersion == 6 && Ver.dwMinorVersion == 2)
|
|
|
|
{
|
|
|
|
if( Ver.wProductType == VER_NT_WORKSTATION )
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows 8 (%lu)", Ver.dwBuildNumber);
|
|
|
|
else
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows Server 2012 (%lu)", Ver.dwBuildNumber);
|
|
|
|
}
|
|
|
|
else if (Ver.dwMajorVersion == 6 && Ver.dwMinorVersion == 3)
|
|
|
|
{
|
|
|
|
if( Ver.wProductType == VER_NT_WORKSTATION )
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows 8.1 (%lu)", Ver.dwBuildNumber);
|
|
|
|
else
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows Server 2012 R2 (%lu)", Ver.dwBuildNumber);
|
|
|
|
}
|
2008-03-24 16:30:07 +01:00
|
|
|
else
|
|
|
|
{
|
2009-09-03 08:16:31 +02:00
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Windows %s %i.%i.%i",
|
2009-09-04 09:08:44 +02:00
|
|
|
(Ver.wProductType == VER_NT_WORKSTATION ? "WorkStation" : "Server"),
|
2009-09-03 08:16:31 +02:00
|
|
|
(int)Ver.dwMajorVersion, (int)Ver.dwMinorVersion, (int)Ver.dwBuildNumber);
|
2008-03-24 16:30:07 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
if (Extended && Ver.wServicePackMajor != 0) {
|
|
|
|
snprintf(buffer+strlen(buffer), sizeof(buffer) - 1 - strlen(buffer)," SP%i",Ver.wServicePackMajor);
|
|
|
|
}
|
2011-04-23 14:39:51 +02:00
|
|
|
return buffer;
|
2008-03-24 16:30:07 +01:00
|
|
|
}
|
|
|
|
#elif defined(DJGPP)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "DOS";
|
2020-06-02 17:33:50 +02:00
|
|
|
#elif defined(HAVE_SYS_UTSNAME_H) && defined(HAVE_UNAME)
|
2008-03-24 16:30:07 +01:00
|
|
|
{
|
2011-04-24 22:36:38 +02:00
|
|
|
struct utsname Ver;
|
2011-04-23 14:39:51 +02:00
|
|
|
if(uname(&Ver)==0)
|
|
|
|
{
|
2018-03-15 10:10:22 +01:00
|
|
|
static char buffer[512] = {0x00};
|
2011-04-24 22:36:38 +02:00
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "%s, kernel %s (%s) %s",
|
|
|
|
Ver.sysname, Ver.release, Ver.version, Ver.machine);
|
2011-04-23 14:39:51 +02:00
|
|
|
return buffer;
|
|
|
|
}
|
2008-03-24 16:30:07 +01:00
|
|
|
}
|
2011-04-23 14:39:51 +02:00
|
|
|
#endif
|
|
|
|
#if defined(__FreeBSD__)
|
|
|
|
return "FreeBSD";
|
2008-03-24 16:30:07 +01:00
|
|
|
#elif defined(__NetBSD__)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "NetBSD";
|
2008-03-24 16:30:07 +01:00
|
|
|
#elif defined(__OpenBSD__)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "BSD";
|
2008-03-24 16:30:07 +01:00
|
|
|
#elif defined(__GNU__)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "GNU/Hurd";
|
2008-03-24 16:30:07 +01:00
|
|
|
#elif defined(sun) || defined(__sun) || defined(__sun__)
|
|
|
|
# ifdef __SVR4
|
2011-04-23 14:39:51 +02:00
|
|
|
return "Sun Solaris";
|
2008-03-24 16:30:07 +01:00
|
|
|
# else
|
2011-04-23 14:39:51 +02:00
|
|
|
return "SunOS";
|
2008-03-24 16:30:07 +01:00
|
|
|
# endif
|
|
|
|
#elif defined(hpux) || defined(__hpux) || defined(__hpux__)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "HP-UX";
|
2008-03-24 16:30:07 +01:00
|
|
|
#elif defined(ultrix) || defined(__ultrix) || defined(__ultrix__)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "DEC Ultrix";
|
2008-03-24 16:30:07 +01:00
|
|
|
#elif defined(sgi) || defined(__sgi)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "SGI Irix";
|
2008-03-24 16:30:07 +01:00
|
|
|
#elif defined(__osf__)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "OSF Unix";
|
2008-03-24 16:30:07 +01:00
|
|
|
#elif defined(bsdi) || defined(__bsdi__)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "BSDI Unix";
|
2008-03-24 16:30:07 +01:00
|
|
|
#elif defined(_AIX)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "AIX Unix";
|
2008-03-24 16:30:07 +01:00
|
|
|
#elif defined(_UNIXWARE)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "SCO Unixware";
|
2008-03-24 16:30:07 +01:00
|
|
|
#elif defined(DGUX)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "DG Unix";
|
2008-03-24 16:30:07 +01:00
|
|
|
#elif defined(__QNX__)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "QNX";
|
2008-03-24 16:30:07 +01:00
|
|
|
#elif defined(__APPLE__)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "Apple";
|
2008-03-24 16:30:07 +01:00
|
|
|
#elif defined(__OS2__)
|
2011-04-23 14:39:51 +02:00
|
|
|
return "OS2";
|
2008-03-24 16:30:07 +01:00
|
|
|
#else
|
2011-04-23 14:39:51 +02:00
|
|
|
return "unknown";
|
2008-03-24 16:30:07 +01:00
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *get_compiler(void)
|
|
|
|
{
|
|
|
|
static char buffer[100] = {0x00};
|
|
|
|
#ifdef WIN32
|
|
|
|
# ifdef _MSC_VER
|
|
|
|
if (_MSC_VER == 1200) { /* ? */
|
2011-04-23 14:39:51 +02:00
|
|
|
return "MS VC 6.0";
|
2008-03-24 16:30:07 +01:00
|
|
|
} else if (_MSC_VER == 1300) {
|
2011-04-23 14:39:51 +02:00
|
|
|
return "MS VC .NET 2002";
|
2008-03-24 16:30:07 +01:00
|
|
|
} else if (_MSC_VER == 1310) {
|
2011-04-23 14:39:51 +02:00
|
|
|
return "MS VC .NET 2003";
|
2008-03-24 16:30:07 +01:00
|
|
|
} else if (_MSC_VER == 1400) {
|
2011-04-23 14:39:51 +02:00
|
|
|
return "MS VC .NET 2005";
|
2008-03-24 16:30:07 +01:00
|
|
|
} else {
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "MS VC %i",_MSC_VER);
|
|
|
|
}
|
|
|
|
# elif defined(__BORLANDC__)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Borland C++ %i",__BORLANDC__);
|
|
|
|
# elif defined(__MINGW32__)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "GCC %i.%i, MinGW %i.%i", __GNUC__, __GNUC_MINOR__, __MINGW32_MAJOR_VERSION, __MINGW32_MINOR_VERSION);
|
2015-11-21 10:28:32 +01:00
|
|
|
# elif defined(__CYGWIN32__)
|
|
|
|
#if defined(CYGWIN_VERSION_DLL_MAJOR) && defined(CYGWIN_VERSION_DLL_MINOR)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "GCC %i.%i, Cygwin32 %i.%i", __GNUC__, __GNUC_MINOR__, CYGWIN_VERSION_DLL_MAJOR, CYGWIN_VERSION_DLL_MINOR);
|
|
|
|
#else
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "GCC %i.%i, Cygwin32", __GNUC__, __GNUC_MINOR__);
|
|
|
|
#endif
|
2008-03-24 16:30:07 +01:00
|
|
|
# elif defined(__CYGWIN__)
|
|
|
|
#if defined(CYGWIN_VERSION_DLL_MAJOR) && defined(CYGWIN_VERSION_DLL_MINOR)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "GCC %i.%i, Cygwin %i.%i", __GNUC__, __GNUC_MINOR__, CYGWIN_VERSION_DLL_MAJOR, CYGWIN_VERSION_DLL_MINOR);
|
|
|
|
#else
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "GCC %i.%i, Cygwin", __GNUC__, __GNUC_MINOR__);
|
|
|
|
#endif
|
|
|
|
# elif defined(__GNUC__)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "GCC %i.%i", __GNUC__, __GNUC_MINOR__);
|
|
|
|
# else
|
2011-04-23 14:39:51 +02:00
|
|
|
return "unknown compiler";
|
2008-03-24 16:30:07 +01:00
|
|
|
# endif
|
|
|
|
#elif defined(DJGPP)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "djgpp %d.%d", __DJGPP, __DJGPP_MINOR);
|
|
|
|
#elif defined(__GNUC__)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "GCC %i.%i", __GNUC__, __GNUC_MINOR__);
|
|
|
|
#elif defined(__SUNPRO_CC)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Sun C++ %x", __SUNPRO_CC);
|
|
|
|
#elif defined(__INTEL_COMPILER)
|
|
|
|
snprintf(buffer, sizeof(buffer) - 1, "Intel Compiler %ld", __INTEL_COMPILER);
|
|
|
|
#else
|
2011-04-23 14:39:51 +02:00
|
|
|
return "unknown compiler";
|
2008-04-11 11:52:21 +02:00
|
|
|
#endif
|
2011-04-23 14:39:51 +02:00
|
|
|
return buffer;
|
|
|
|
}
|
|
|
|
|
2015-05-15 18:19:22 +02:00
|
|
|
#ifdef RECORD_COMPILATION_DATE
|
2011-04-23 14:39:51 +02:00
|
|
|
const char *get_compilation_date(void)
|
|
|
|
{
|
|
|
|
static char buffer[100] = {0x00};
|
2008-04-11 11:52:21 +02:00
|
|
|
#ifdef __DATE__
|
2020-06-02 17:33:50 +02:00
|
|
|
#if defined(HAVE_STRPTIME)
|
2011-04-24 22:36:38 +02:00
|
|
|
struct tm tm;
|
|
|
|
memset(&tm,0,sizeof(tm));
|
|
|
|
if(strptime(__DATE__, "%b %d %Y", &tm)!=NULL)
|
|
|
|
sprintf(buffer, "%4d-%02d-%02dT", tm.tm_year + 1900, tm.tm_mon+1, tm.tm_mday);
|
|
|
|
else
|
|
|
|
strcpy(buffer, __DATE__);
|
|
|
|
#ifdef __TIME__
|
|
|
|
strcat(buffer, __TIME__);
|
|
|
|
#endif
|
|
|
|
#else
|
2011-04-23 14:39:51 +02:00
|
|
|
strcpy(buffer, __DATE__);
|
2008-04-11 11:52:21 +02:00
|
|
|
#ifdef __TIME__
|
|
|
|
strcat(buffer, " ");
|
|
|
|
strcat(buffer, __TIME__);
|
|
|
|
#endif
|
2011-04-24 22:36:38 +02:00
|
|
|
#endif
|
2008-03-24 16:30:07 +01:00
|
|
|
#endif
|
2020-06-02 17:33:50 +02:00
|
|
|
/*@ assert valid_read_string(&buffer[0]); */
|
2008-03-24 16:30:07 +01:00
|
|
|
return buffer;
|
|
|
|
}
|
2015-05-15 18:19:22 +02:00
|
|
|
#endif
|