def test_setreg(): regkey = random_regkey() assert not regkey_exists(_winreg.HKEY_CURRENT_USER, regkey) assert query_value(_winreg.HKEY_CURRENT_USER, regkey, "foo") is None set_regkey( _winreg.HKEY_CURRENT_USER, regkey, "foo", _winreg.REG_SZ, "bar" ) assert regkey_exists(_winreg.HKEY_CURRENT_USER, regkey) assert query_value(_winreg.HKEY_CURRENT_USER, regkey, "foo") == "bar"
def patch_acpi(self): # TODO This should be improved, but for now may suffice. keywords = { "VBOX": "LNVO", "vbox": "lnvo", "VirtualBox": "LENOVOTP", "innotek GmbH": "", } regkeys = [ ["SYSTEM\\CurrentControlSet\\Services\\mssmbios\\Data", "AcpiData"], ["SYSTEM\\ControlSet001\\Services\\mssmbios\\Data", "AcpiData"], ["SYSTEM\\CurrentControlSet\\Services\\mssmbios\\Data", "SMBiosData"], ["SYSTEM\\ControlSet001\\Services\\mssmbios\\Data", "SMBiosData"], ] for regkey, key in regkeys: value = query_value(HKEY_LOCAL_MACHINE, regkey, key) if value is None: continue for k, v in keywords.items(): value = value.replace(k, v) set_regkey(HKEY_LOCAL_MACHINE, regkey, key, REG_BINARY, value) if regkey_exists(HKEY_LOCAL_MACHINE, "HARDWARE\\ACPI\\DSDT\\VBOX__"): rename_regkey(HKEY_LOCAL_MACHINE, "HARDWARE\\ACPI\\DSDT\\VBOX__", "LENOVO") rename_regkey(HKEY_LOCAL_MACHINE, "HARDWARE\\ACPI\\FADT\\VBOX__", "LENOVO") rename_regkey(HKEY_LOCAL_MACHINE, "HARDWARE\\ACPI\\RSDT\\VBOX__", "LENOVO")
def test_setregfull(): regkey = random_regkey() set_regkey_full( "HKEY_CURRENT_USER\\%s\\foo" % regkey, _winreg.REG_SZ, "bar2" ) assert regkey_exists(_winreg.HKEY_CURRENT_USER, regkey) assert query_value(_winreg.HKEY_CURRENT_USER, regkey, "foo") == "bar2"
def test_dword(): regkey = random_regkey() set_regkey_full( "HKEY_CURRENT_USER\\%s\\foo" % regkey, _winreg.REG_DWORD, 1234 ) assert regkey_exists(_winreg.HKEY_CURRENT_USER, regkey) assert query_value( _winreg.HKEY_CURRENT_USER, regkey, "foo" ) == 1234
def test_multisz(): regkey = random_regkey() set_regkey_full( "HKEY_CURRENT_USER\\%s\\foo" % regkey, _winreg.REG_MULTI_SZ, ["a", "b", "c"] ) assert regkey_exists(_winreg.HKEY_CURRENT_USER, regkey) assert query_value( _winreg.HKEY_CURRENT_USER, regkey, "foo" ) == ["a", "b", "c"]
def patch_scsi_identifiers(self): types = { "DiskPeripheral": self.HDD_IDENTIFIERS, "CdRomPeripheral": self.CDROM_IDENTIFIERS, } for row in itertools.product([0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3], [0, 1, 2, 3]): type_ = query_value(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port %d\\Scsi Bus %d\\Target Id %d\\Logical Unit Id %d" % row, "Type") value = query_value(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port %d\\Scsi Bus %d\\Target Id %d\\Logical Unit Id %d" % row, "Identifier") if not type_ or not value: continue value = value.lower() if "vbox" in value or "vmware" in value or "qemu" in value or "virtual" in value: if type_ in types: new_value = random.choice(types[type_]) else: log.warning("Unknown SCSI type (%s), disguising it with a random string", type_) new_value = random_string(len(value)) set_regkey(HKEY_LOCAL_MACHINE, "HARDWARE\\DEVICEMAP\\Scsi\\Scsi Port %d\\Scsi Bus %d\\Target Id %d\\Logical Unit Id %d" % row, "Identifier", REG_SZ, new_value)
def patch_processor(self): keywords = { "QEMU Virtual CPU version 2.0.0": "Intel(R) Core(TM) i7 CPU @3GHz", } for idx in xrange(32): value = query_value(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\%d" % idx, "ProcessorNameString") if value is None: continue for k, v in keywords.items(): value = value.replace(k, v) set_regkey(HKEY_LOCAL_MACHINE, "HARDWARE\\DESCRIPTION\\System\\CentralProcessor\\%d" % idx, "ProcessorNameString", REG_SZ, value)
def patch_acpi(self): # TODO This should be improved, but for now may suffice. keywords = { "VBOX": "LNVO", "vbox": "lnvo", "VirtualBox": "LENOVOTP", "innotek GmbH": "", } regkeys = [ [ "SYSTEM\\CurrentControlSet\\Services\\mssmbios\\Data", "AcpiData" ], ["SYSTEM\\ControlSet001\\Services\\mssmbios\\Data", "AcpiData"], [ "SYSTEM\\CurrentControlSet\\Services\\mssmbios\\Data", "SMBiosData" ], ["SYSTEM\\ControlSet001\\Services\\mssmbios\\Data", "SMBiosData"], ] for regkey, key in regkeys: value = query_value(HKEY_LOCAL_MACHINE, regkey, key) if value is None: continue for k, v in keywords.items(): value = value.replace(k, v) set_regkey(HKEY_LOCAL_MACHINE, regkey, key, REG_BINARY, value) if regkey_exists(HKEY_LOCAL_MACHINE, "HARDWARE\\ACPI\\DSDT\\VBOX__"): rename_regkey(HKEY_LOCAL_MACHINE, "HARDWARE\\ACPI\\DSDT\\VBOX__", "LENOVO") rename_regkey(HKEY_LOCAL_MACHINE, "HARDWARE\\ACPI\\FADT\\VBOX__", "LENOVO") rename_regkey(HKEY_LOCAL_MACHINE, "HARDWARE\\ACPI\\RSDT\\VBOX__", "LENOVO")