-
Notifications
You must be signed in to change notification settings - Fork 117
/
system_info.c
142 lines (117 loc) · 3.06 KB
/
system_info.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
/**********************************************************************
*
* This file is part of Cardpeek, the smart card reader utility.
*
* Copyright 2009-2013 by Alain Pannetrat <L1L1@gmx.com>
*
* Cardpeek 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 3 of the License, or
* (at your option) any later version.
*
* Cardpeek 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 Cardpeek. If not, see <http://www.gnu.org/licenses/>.
*
*/
#include "system_info.h"
/* this hash function is used by SDBM. */
static unsigned int simple_hash(const char *str)
{
unsigned int hash = 0;
int c;
while ((c = *str++)!=0)
hash = c + (hash << 6) + (hash << 16) - hash;
return hash;
}
#ifndef _WIN32
#include <string.h>
#include <stdio.h>
#include "config.h"
#include <sys/utsname.h>
const char *system_type(void)
{
static char info[32];
static struct utsname u;
if (uname(&u)<0)
{
return "Unknown";
}
snprintf(info,32,"%s",u.sysname);
return info;
}
const char *system_string_info(void)
{
static char info[128];
static struct utsname u;
if (uname(&u)<0)
{
return "Unknown OS";
}
snprintf(info,128,"%s %s %s",u.sysname,u.release,u.machine);
return info;
}
unsigned int system_name_hash(void)
{
static struct utsname u;
if (uname(&u)<0)
{
return 0;
}
return simple_hash(u.nodename);
}
#else
#include <windows.h>
#include <string.h>
#include <stdio.h>
#include "win32/config.h"
const char *system_type(void)
{
return "Windows";
}
typedef void (WINAPI *PGNSI)(LPSYSTEM_INFO);
const char *system_string_info(void)
{
static char info[128];
SYSTEM_INFO si;
OSVERSIONINFOEX osvi;
PGNSI GetNativeSystemInfo_func;
memset(&si,0,sizeof(si));
memset(&osvi,0,sizeof(osvi));
osvi.dwOSVersionInfoSize = sizeof(osvi);
GetVersionEx((OSVERSIONINFO*)&osvi);
GetNativeSystemInfo_func = (PGNSI) GetProcAddress(
GetModuleHandle(TEXT("kernel32.dll")),
"GetNativeSystemInfo");
if (GetNativeSystemInfo_func!=NULL)
GetNativeSystemInfo_func(&si);
else
GetSystemInfo(&si);
snprintf(info,110,"Cardpeek %s on Windows NT_%u.%u (%s) ",
VERSION,
(unsigned)osvi.dwMajorVersion,
(unsigned)osvi.dwMinorVersion,
osvi.szCSDVersion);
switch (si.wProcessorArchitecture) {
case 9: strcat(info,"AMD64");
break;
case 6: strcat(info,"IA64");
break;
case 0: strcat(info,"x86");
break;
default: strcat(info,"Unknown platform");
};
return info;
}
unsigned int system_name_hash()
{
static char computer_name[1024];
DWORD size = 1024;
GetComputerName(computer_name,&size);
return simple_hash(computer_name);
}
#endif