Add generic func to access regkey value and compare str, code refactor

This commit is contained in:
Alberto Ortega 2015-03-20 15:55:55 +01:00
parent 283f01a459
commit 8e5f18a482
5 changed files with 36 additions and 190 deletions

View File

@ -6,63 +6,10 @@
#include "types.h" #include "types.h"
int qemu_reg_key1() { int qemu_reg_key1() {
HKEY regkey; return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0", "Identifier", "QEMU");
LONG retu;
char value[1024];
DWORD size;
size = sizeof(value);
retu = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0", 0, KEY_READ, &regkey);
if (retu == ERROR_SUCCESS) {
retu = RegQueryValueEx(regkey, "Identifier", NULL, NULL, (BYTE*)value, &size);
if (retu == ERROR_SUCCESS) {
int i;
for (i = 0; i < strlen(value); i++) { /* case-insensitive */
value[i] = toupper(value[i]);
}
if (strstr(value, "QEMU") != NULL) {
return TRUE;
}
else {
return FALSE;
}
}
else {
return FALSE;
}
}
else {
return FALSE;
}
} }
int qemu_reg_key2() { int qemu_reg_key2() {
HKEY regkey; return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", "SystemBiosVersion", "QEMU");
LONG retu;
char value[1024];
DWORD size;
size = sizeof(value);
retu = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", 0, KEY_READ, &regkey);
if (retu == ERROR_SUCCESS) {
retu = RegQueryValueEx(regkey, "SystemBiosVersion", NULL, NULL, (BYTE*)value, &size);
if (retu == ERROR_SUCCESS) {
int i;
for (i = 0; i < strlen(value); i++) { /* case-insensitive */
value[i] = toupper(value[i]);
}
if (strstr(value, "QEMU") != NULL) {
return TRUE;
}
else {
return FALSE;
}
}
else {
return FALSE;
}
}
else {
return FALSE;
}
} }

View File

@ -16,15 +16,33 @@ inline int pafish_exists_regkey(HKEY hKey, char * regkey_s) {
return TRUE; return TRUE;
} }
else else
return FALSE;
}
inline int pafish_exists_regkey_value_str(HKEY hKey, char * regkey_s, char * value_s, char * lookup) {
HKEY regkey;
LONG ret;
DWORD size;
char value[1024];
size = sizeof(value);
ret = RegOpenKeyEx(hKey, regkey_s, 0, KEY_READ, &regkey);
if (ret == ERROR_SUCCESS) {
ret = RegQueryValueEx(regkey, value_s, NULL, NULL, (BYTE*)value, &size);
RegCloseKey(regkey);
if (ret == ERROR_SUCCESS) {
int i;
for (i = 0; i < strlen(value); i++) { /* case-insensitive */
value[i] = toupper(value[i]);
}
if (strstr(value, lookup) != NULL)
return TRUE;
}
}
return FALSE; return FALSE;
} }
inline int pafish_exists_file(char * filename) { inline int pafish_exists_file(char * filename) {
DWORD ret; return (GetFileAttributes(filename) != INVALID_FILE_ATTRIBUTES) ? TRUE : FALSE;
ret = GetFileAttributes(filename);
if (ret != INVALID_FILE_ATTRIBUTES)
return TRUE;
else
return FALSE;
} }

View File

@ -4,6 +4,8 @@
inline int pafish_exists_regkey(HKEY hKey, char * regkey); inline int pafish_exists_regkey(HKEY hKey, char * regkey);
inline int pafish_exists_regkey_value_str(HKEY, char *, char *, char *);
inline int pafish_exists_file(char * filename); inline int pafish_exists_file(char * filename);
#endif #endif

View File

@ -15,68 +15,14 @@
* SCSI registry key check * SCSI registry key check
**/ **/
int vbox_reg_key1() { int vbox_reg_key1() {
HKEY regkey; return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0", "Identifier", "VBOX");
LONG retu;
char value[1024];
DWORD size;
size = sizeof(value);
retu = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0", 0, KEY_READ, &regkey);
if (retu == ERROR_SUCCESS) {
retu = RegQueryValueEx(regkey, "Identifier", NULL, NULL, (BYTE*)value, &size);
if (retu == ERROR_SUCCESS) {
int i;
for (i = 0; i < strlen(value); i++) { /* case-insensitive */
value[i] = toupper(value[i]);
}
if (strstr(value, "VBOX") != NULL) {
return TRUE;
}
else {
return FALSE;
}
}
else {
return FALSE;
}
}
else {
return FALSE;
}
} }
/** /**
* SystemBiosVersion registry key check * SystemBiosVersion registry key check
**/ **/
int vbox_reg_key2() { int vbox_reg_key2() {
HKEY regkey; return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", "SystemBiosVersion", "VBOX");
LONG retu;
char value[1024];
DWORD size;
size = sizeof(value);
retu = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", 0, KEY_READ, &regkey);
if (retu == ERROR_SUCCESS) {
retu = RegQueryValueEx(regkey, "SystemBiosVersion", NULL, NULL, (BYTE*)value, &size);
if (retu == ERROR_SUCCESS) {
int i;
for (i = 0; i < strlen(value); i++) { /* case-insensitive */
value[i] = toupper(value[i]);
}
if (strstr(value, "VBOX") != NULL) {
return TRUE;
}
else {
return FALSE;
}
}
else {
return FALSE;
}
}
else {
return FALSE;
}
} }
/** /**
@ -90,34 +36,7 @@ int vbox_reg_key3() {
* VideoBiosVersion key check * VideoBiosVersion key check
**/ **/
int vbox_reg_key4() { int vbox_reg_key4() {
HKEY regkey; return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", "VideoBiosVersion", "VIRTUALBOX");
LONG retu;
char value[1024];
DWORD size;
size = sizeof(value);
retu = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", 0, KEY_READ, &regkey);
if (retu == ERROR_SUCCESS) {
retu = RegQueryValueEx(regkey, "VideoBiosVersion", NULL, NULL, (BYTE*)value, &size);
if (retu == ERROR_SUCCESS) {
int i;
for (i = 0; i < strlen(value); i++) { /* case-insensitive */
value[i] = toupper(value[i]);
}
if (strstr(value, "VIRTUALBOX") != NULL) {
return TRUE;
}
else {
return FALSE;
}
}
else {
return FALSE;
}
}
else {
return FALSE;
}
} }
/** /**
@ -169,21 +88,7 @@ int vbox_reg_key9(int writelogs) {
* HARDWARE\\DESCRIPTION\\System SystemBiosDate == 06/23/99 * HARDWARE\\DESCRIPTION\\System SystemBiosDate == 06/23/99
**/ **/
int vbox_reg_key10() { int vbox_reg_key10() {
HKEY regkey; return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System", "SystemBiosDate", "06/23/99");
LONG retu;
char value[1024];
DWORD size;
size = sizeof(value);
retu = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System", 0, KEY_READ, &regkey);
if (retu == ERROR_SUCCESS) {
retu = RegQueryValueEx(regkey, "SystemBiosDate", NULL, NULL, (BYTE*)value, &size);
if (retu == ERROR_SUCCESS) {
if (!strcmp(value, "06/23/99"))
return TRUE;
}
}
return FALSE;
} }
/** /**
@ -371,3 +276,4 @@ int vbox_processes(int writelogs) {
} while (Process32Next(hpSnap, &pentry)); } while (Process32Next(hpSnap, &pentry));
return res; return res;
} }

View File

@ -7,34 +7,7 @@
#include "utils.h" #include "utils.h"
int vmware_reg_key1() { int vmware_reg_key1() {
HKEY regkey; return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0", "Identifier", "VMWARE");
LONG retu;
char value[1024];
DWORD size;
size = sizeof(value);
retu = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port 0\\Scsi Bus 0\\Target Id 0\\Logical Unit Id 0", 0, KEY_READ, &regkey);
if (retu == ERROR_SUCCESS) {
retu = RegQueryValueEx(regkey, "Identifier", NULL, NULL, (BYTE*)value, &size);
if (retu == ERROR_SUCCESS) {
int i;
for (i = 0; i < strlen(value); i++) { /* case-insensitive */
value[i] = toupper(value[i]);
}
if (strstr(value, "VMWARE") != NULL) {
return TRUE;
}
else {
return FALSE;
}
}
else {
return FALSE;
}
}
else {
return FALSE;
}
} }
int vmware_reg_key2() { int vmware_reg_key2() {