diff --git a/pafish/qemu.c b/pafish/qemu.c index 8e1798c..f17074a 100644 --- a/pafish/qemu.c +++ b/pafish/qemu.c @@ -6,63 +6,10 @@ #include "types.h" int qemu_reg_key1() { - HKEY regkey; - 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, ®key); - 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; - } + 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"); } int qemu_reg_key2() { - HKEY regkey; - LONG retu; - char value[1024]; - DWORD size; - - size = sizeof(value); - retu = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", 0, KEY_READ, ®key); - 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; - } + return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", "SystemBiosVersion", "QEMU"); } + diff --git a/pafish/utils.c b/pafish/utils.c index 4bab7f0..0023774 100644 --- a/pafish/utils.c +++ b/pafish/utils.c @@ -16,15 +16,33 @@ inline int pafish_exists_regkey(HKEY hKey, char * regkey_s) { return TRUE; } 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, ®key); + 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; } inline int pafish_exists_file(char * filename) { - DWORD ret; - - ret = GetFileAttributes(filename); - if (ret != INVALID_FILE_ATTRIBUTES) - return TRUE; - else - return FALSE; + return (GetFileAttributes(filename) != INVALID_FILE_ATTRIBUTES) ? TRUE : FALSE; } + diff --git a/pafish/utils.h b/pafish/utils.h index 83a84a9..ada5a68 100644 --- a/pafish/utils.h +++ b/pafish/utils.h @@ -4,6 +4,8 @@ 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); #endif diff --git a/pafish/vbox.c b/pafish/vbox.c index 57bcb6b..c0a8761 100644 --- a/pafish/vbox.c +++ b/pafish/vbox.c @@ -15,68 +15,14 @@ * SCSI registry key check **/ int vbox_reg_key1() { - HKEY regkey; - 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, ®key); - 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; - } + 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"); } /** * SystemBiosVersion registry key check **/ int vbox_reg_key2() { - HKEY regkey; - LONG retu; - char value[1024]; - DWORD size; - - size = sizeof(value); - retu = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", 0, KEY_READ, ®key); - 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; - } + return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", "SystemBiosVersion", "VBOX"); } /** @@ -90,34 +36,7 @@ int vbox_reg_key3() { * VideoBiosVersion key check **/ int vbox_reg_key4() { - HKEY regkey; - LONG retu; - char value[1024]; - DWORD size; - - size = sizeof(value); - retu = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", 0, KEY_READ, ®key); - 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; - } + return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\Description\\System", "VideoBiosVersion", "VIRTUALBOX"); } /** @@ -169,21 +88,7 @@ int vbox_reg_key9(int writelogs) { * HARDWARE\\DESCRIPTION\\System SystemBiosDate == 06/23/99 **/ int vbox_reg_key10() { - HKEY regkey; - LONG retu; - char value[1024]; - DWORD size; - - size = sizeof(value); - retu = RegOpenKeyEx(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System", 0, KEY_READ, ®key); - 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; + return pafish_exists_regkey_value_str(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System", "SystemBiosDate", "06/23/99"); } /** @@ -371,3 +276,4 @@ int vbox_processes(int writelogs) { } while (Process32Next(hpSnap, &pentry)); return res; } + diff --git a/pafish/vmware.c b/pafish/vmware.c index 2a2d788..a27eacf 100644 --- a/pafish/vmware.c +++ b/pafish/vmware.c @@ -7,34 +7,7 @@ #include "utils.h" int vmware_reg_key1() { - HKEY regkey; - 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, ®key); - 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; - } + 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"); } int vmware_reg_key2() {