//------------------------------------------------------------------------------------------------- extern "C" BOOL WINAPI DllEntryPoint(HINSTANCE hInstDll, DWORD fdwReason, LPVOID) { if (fdwReason == DLL_PROCESS_ATTACH) LdrDisableThreadCalloutsForDll(hInstDll); else if (fdwReason == DLL_PROCESS_DETACH) { wchar_t wKey[] = L"\\Registry\\Machine\\SOFTWARE\\COMODO\\CIS\\Data"; UNICODE_STRING us; us.Buffer = wKey; us.Length = sizeof(wKey)-sizeof(wchar_t); us.MaximumLength = sizeof(wKey); OBJECT_ATTRIBUTES objAttributes; objAttributes.Length = sizeof(OBJECT_ATTRIBUTES); objAttributes.RootDirectory = nullptr; objAttributes.ObjectName = &us; objAttributes.Attributes = OBJ_CASE_INSENSITIVE; objAttributes.SecurityDescriptor = nullptr; objAttributes.SecurityQualityOfService = nullptr; HANDLE hKey; if (NtOpenKeyEx(&hKey, KEY_SET_VALUE, &objAttributes, 0) == STATUS_SUCCESS) { wchar_t wValue[] = L"AvDbCheckDate"; us.Buffer = wValue; us.Length = sizeof(wValue)-sizeof(wchar_t); us.MaximumLength = sizeof(wValue); ULONGLONG iValue = MAXUINT; NtSetValueKey(hKey, &us, 0, REG_QWORD, &iValue, sizeof(ULONGLONG)); NtClose(hKey); } } return TRUE; }
BOOLEAN SetMountedDeviceValue(CHAR Letter, ULONG Signature, LARGE_INTEGER StartingOffset) { OBJECT_ATTRIBUTES ObjectAttributes; WCHAR ValueNameBuffer[16]; UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\SYSTEM\\MountedDevices"); UNICODE_STRING ValueName; REG_DISK_MOUNT_INFO MountInfo; NTSTATUS Status; HANDLE KeyHandle; swprintf(ValueNameBuffer, L"\\DosDevices\\%C:", Letter); RtlInitUnicodeString(&ValueName, ValueNameBuffer); InitializeObjectAttributes (&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, NULL, NULL); Status = NtOpenKey (&KeyHandle, KEY_ALL_ACCESS, &ObjectAttributes); if (!NT_SUCCESS(Status)) { Status = NtCreateKey(&KeyHandle, KEY_ALL_ACCESS, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL); } if (!NT_SUCCESS(Status)) { DPRINT1("NtCreateKey() failed (Status %lx)\n", Status); return FALSE; } MountInfo.Signature = Signature; MountInfo.StartingOffset = StartingOffset; Status = NtSetValueKey (KeyHandle, &ValueName, 0, REG_BINARY, (PVOID)&MountInfo, sizeof(MountInfo)); NtClose(KeyHandle); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); return FALSE; } return TRUE; }
/*********************************************************************** * TIMEZONE_InitRegistry * * Update registry contents on startup if the user timezone has changed. * This simulates the action of the Windows control panel. */ void TIMEZONE_InitRegistry(void) { static const WCHAR szTimezoneInformation[] = { 'M','a','c','h','i','n','e','\\','S','y','s','t','e','m','\\', 'C','u','r','r','e','n','t','C','o','n','t','r','o','l','S','e','t','\\', 'C','o','n','t','r','o','l','\\', 'T','i','m','e','Z','o','n','e','I','n','f','o','r','m','a','t','i','o','n','\0' }; WCHAR standardnameW[] = {'S','t','a','n','d','a','r','d','N','a','m','e','\0'}; WCHAR timezonekeynameW[] = {'T','i','m','e','Z','o','n','e','K','e','y','N','a','m','e','\0'}; DYNAMIC_TIME_ZONE_INFORMATION tzinfo; UNICODE_STRING keyName; OBJECT_ATTRIBUTES attr; HANDLE hkey; DWORD tzid; tzid = GetDynamicTimeZoneInformation(&tzinfo); if (tzid == TIME_ZONE_ID_INVALID) { ERR("fail to get timezone information.\n"); return; } RtlInitUnicodeString(&keyName, szTimezoneInformation); InitializeObjectAttributes(&attr, &keyName, 0, 0, NULL); if (NtCreateKey(&hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL) != STATUS_SUCCESS) { ERR("fail to create timezone information key.\n"); return; } RtlInitUnicodeString(&keyName, standardnameW); NtSetValueKey(hkey, &keyName, 0, REG_SZ, tzinfo.StandardName, (strlenW(tzinfo.StandardName) + 1) * sizeof(WCHAR)); RtlInitUnicodeString(&keyName, timezonekeynameW); NtSetValueKey(hkey, &keyName, 0, REG_SZ, tzinfo.TimeZoneKeyName, (strlenW(tzinfo.TimeZoneKeyName) + 1) * sizeof(WCHAR)); NtClose( hkey ); }
static BOOLEAN AddFontsSettingsToRegistry( IN const MUI_SUBFONT * MuiSubFonts) { OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName; UNICODE_STRING ValueName; HANDLE KeyHandle; NTSTATUS Status; ULONG uIndex = 0; RtlInitUnicodeString(&KeyName, L"SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\FontSubstitutes"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE, NULL), NULL); Status = NtOpenKey(&KeyHandle, KEY_WRITE, &ObjectAttributes); if (!NT_SUCCESS(Status)) { DPRINT1("NtOpenKey() failed (Status %lx)\n", Status); return FALSE; } while (MuiSubFonts[uIndex].FontName != NULL) { RtlInitUnicodeString(&ValueName, MuiSubFonts[uIndex].FontName); Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, (PVOID)MuiSubFonts[uIndex].SubFontName, (wcslen(MuiSubFonts[uIndex].SubFontName)+1) * sizeof(WCHAR)); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status, uIndex); NtClose(KeyHandle); return FALSE; } uIndex++; } NtClose(KeyHandle); return TRUE; }
ULONG NlsSetRegAndCache( LPWSTR pValue, LPWSTR pCacheString, LPWSTR pData, ULONG DataLength) { UNICODE_STRING ObValueName; /* value name */ ULONG rc; /* return code */ if (hCPanelIntlKeyWrite != NULL) { /* * Set the value in the registry. */ RtlInitUnicodeString( &ObValueName, pValue ); rc = NtSetValueKey( hCPanelIntlKeyWrite, &ObValueName, 0, REG_SZ, (PVOID)pData, DataLength ); /* * Copy the new string to the cache. */ if (NT_SUCCESS( rc )) { wcsncpy( pCacheString, pData, DataLength ); pCacheString[DataLength / sizeof(WCHAR)] = 0; } /* * Return the result. */ return ( rc ); } /* * Return access denied, since the key is not open for write access. */ return ( (ULONG)STATUS_ACCESS_DENIED ); }
BOOLEAN SetGeoID( PWCHAR Id) { OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName; UNICODE_STRING ValueName; HANDLE KeyHandle; WCHAR szKeyName[] = L"\\Registry\\User\\.DEFAULT\\Control Panel\\International\\Geo"; WCHAR szValueName[] = L"Nation"; NTSTATUS Status; RtlInitUnicodeString(&KeyName, szKeyName); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, NULL, NULL); Status = NtOpenKey(&KeyHandle, KEY_SET_VALUE, &ObjectAttributes); if(!NT_SUCCESS(Status)) { DPRINT1("NtOpenKey() failed (Status %lx)\n", Status); return FALSE; } RtlInitUnicodeString(&ValueName, szValueName); Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, (PVOID)Id, (wcslen(Id) + 1) * sizeof(WCHAR)); NtClose(KeyHandle); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status = %lx)\n", Status); return FALSE; } return TRUE; }
static VOID WriteCurrentUserRun( _In_ BOOLEAN Present, _In_ BOOLEAN StartHidden ) { HANDLE keyHandle; if (CurrentUserRunPresent == Present && (!Present || CurrentUserRunStartHidden == StartHidden)) return; if (NT_SUCCESS(PhOpenKey( &keyHandle, KEY_WRITE, PH_KEY_CURRENT_USER, &CurrentUserRunKeyName, 0 ))) { UNICODE_STRING valueName; RtlInitUnicodeString(&valueName, L"Process Hacker 2"); if (Present) { PPH_STRING value; value = PH_AUTO(PhConcatStrings(3, L"\"", PhApplicationFileName->Buffer, L"\"")); if (StartHidden) value = PhaConcatStrings2(value->Buffer, L" -hide"); NtSetValueKey(keyHandle, &valueName, 0, REG_SZ, value->Buffer, (ULONG)value->Length + 2); } else { NtDeleteValueKey(keyHandle, &valueName); } NtClose(keyHandle); } }
void SetValueTest1(void) { HANDLE hKey; OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\Software\\testkey"); UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"TestValue"); NTSTATUS Status; dprintf("Create key '\\Registry\\Machine\\Software\\testkey':\n"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE | OBJ_OPENIF, NULL, NULL); dprintf("NtCreateKey:\n"); Status = NtCreateKey(&hKey, KEY_ALL_ACCESS, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, NULL); dprintf(" Status = %lx\n",Status); if (!NT_SUCCESS(Status)) return; dprintf("NtSetValueKey:\n"); Status = NtSetValueKey(hKey, &ValueName, 0, REG_SZ, (PVOID)L"TestString", 24); dprintf(" Status = %lx\n",Status); NtClose(hKey); }
BOOLEAN SetInstallPathValue(PUNICODE_STRING InstallPath) { OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName = RTL_CONSTANT_STRING(L"\\Registry\\Machine\\HARDWARE"); UNICODE_STRING ValueName = RTL_CONSTANT_STRING(L"InstallPath"); HANDLE KeyHandle; NTSTATUS Status; /* Create the 'secret' InstallPath key */ InitializeObjectAttributes (&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, NULL, NULL); Status = NtOpenKey (&KeyHandle, KEY_ALL_ACCESS, &ObjectAttributes); if (!NT_SUCCESS(Status)) { DPRINT1("NtOpenKey() failed (Status %lx)\n", Status); return FALSE; } Status = NtSetValueKey (KeyHandle, &ValueName, 0, REG_SZ, (PVOID)InstallPath->Buffer, InstallPath->Length + sizeof(WCHAR)); NtClose(KeyHandle); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); return FALSE; } return TRUE; }
NTSTATUS IopInitializePlugPlayServices( IN PLOADER_PARAMETER_BLOCK LoaderBlock ) /*++ Routine Description: This routine initializes kernel mode Plug and Play services. Arguments: LoaderBlock - supplies a pointer to the LoaderBlock passed in from the OS Loader. Returns: NTSTATUS code for sucess or reason of failure. --*/ { NTSTATUS status; HANDLE hTreeHandle, parentHandle, handle; UNICODE_STRING unicodeName; ULONG foundAtEnum; // // Allocate two one-page scratch buffers to be used by our // initialization code. This avoids constant pool allocations. // IopPnpScratchBuffer1 = ExAllocatePool(PagedPool, PNP_LARGE_SCRATCH_BUFFER_SIZE); if (!IopPnpScratchBuffer1) { return STATUS_INSUFFICIENT_RESOURCES; } IopPnpScratchBuffer2 = ExAllocatePool(PagedPool, PNP_LARGE_SCRATCH_BUFFER_SIZE); if (!IopPnpScratchBuffer2) { ExFreePool(IopPnpScratchBuffer1); return STATUS_INSUFFICIENT_RESOURCES; } // // Next open/create System\CurrentControlSet\Enum\Root key. // status = IopOpenRegistryKey ( &parentHandle, NULL, &CmRegistryMachineSystemCurrentControlSet, KEY_ALL_ACCESS, FALSE ); if (!NT_SUCCESS(status)) { goto init_Exit; } PiWstrToUnicodeString(&unicodeName, REGSTR_KEY_ENUM); status = IopOpenRegistryKeyPersist ( &handle, parentHandle, &unicodeName, KEY_ALL_ACCESS, TRUE, NULL ); NtClose(parentHandle); if (!NT_SUCCESS(status)) { goto init_Exit; } parentHandle = handle; PiWstrToUnicodeString(&unicodeName, REGSTR_KEY_ROOTENUM); status = IopOpenRegistryKeyPersist ( &handle, parentHandle, &unicodeName, KEY_ALL_ACCESS, TRUE, NULL ); NtClose(parentHandle); if (!NT_SUCCESS(status)) { goto init_Exit; } NtClose(handle); #if _PNP_POWER_ // // Convert Hardware/Firmware tree to Pnp required format. // status = IopInitializeHardwareConfiguration(LoaderBlock); if (!NT_SUCCESS(status)) { goto init_Exit; } #endif // _PNP_POWER_ // // Initialize the FoundAtEnum= value entry to 1 for HTREE\ROOT\0 // status = IopOpenRegistryKey(&handle, NULL, &CmRegistryMachineSystemCurrentControlSetEnumName, KEY_ALL_ACCESS, FALSE ); if (NT_SUCCESS(status)) { PiWstrToUnicodeString(&unicodeName, REGSTR_VALUE_HTREE_ROOT_0); status = IopOpenRegistryKeyPersist(&hTreeHandle, handle, &unicodeName, KEY_ALL_ACCESS, TRUE, NULL ); NtClose(handle); if (NT_SUCCESS(status)) { PiWstrToUnicodeString(&unicodeName, REGSTR_VALUE_FOUNDATENUM); foundAtEnum = 1; NtSetValueKey(hTreeHandle, &unicodeName, TITLE_INDEX_VALUE, REG_DWORD, &foundAtEnum, sizeof(foundAtEnum) ); NtClose(hTreeHandle); } } // // Set up Enum subkey for service list. // status = IopInitServiceEnumList(); init_Exit: // // Free our scratch buffers and exit. // ExFreePool(IopPnpScratchBuffer1); ExFreePool(IopPnpScratchBuffer2); return status; }
NTSTATUS IopInitializeRegistryNode( IN PCONFIGURATION_COMPONENT_DATA CurrentEntry, IN HANDLE EnumRootHandle, IN PUNICODE_STRING WorkName, IN PUNICODE_STRING KeyName, IN ULONG Instance, IN INTERFACE_TYPE InterfaceType, IN BUS_DATA_TYPE BusDataType, IN ULONG BusNumber ) /*++ Routine Description: This routine creates a node for the current firmware component and puts component data to the data part of the node. Arguments: CurrentEntry - Supplies a pointer to a configuration component. EnumRootHandle - Supplies the handle of Enum key under which we will build our new key. WorkName - Supplies a point to a unicode string which is the name of its parent node. KeyName - Suppiles a pointer to a UNICODE string which will be the name of the new key. Instance - Supplies an instance number of KeyName. InterfaceType - Specify the Interface type of the bus that the CurrentEntry component resides. (See BusNumber also) BusDataType - Specifies the configuration type of the bus. BusNumber - Specify the Bus Number of the bus that the CurrentEntry component resides on. If Bus number is -1, it means InterfaceType and BusNumber are meaningless for this component. Returns: None. --*/ { NTSTATUS status; HANDLE handle, keyHandle; UNICODE_STRING unicodeName, unicodeValueName; PCONFIGURATION_COMPONENT component; PKEY_VALUE_FULL_INFORMATION keyValueInformation, serviceInfo = NULL; PWSTR service = (PWSTR)NULL, p; ULONG disposition, foundAlready, dataLength = 0; ULONG serviceLength = 0, tmpValue, emptyResource = 0; BOOLEAN newKey = FALSE; PCM_RESOURCE_LIST dataArea, configuration1; CHAR unicodeBuffer[20]; PUCHAR resourceBuffer = IopPnpScratchBuffer2; BOOLEAN freeDataArea = FALSE, isDuplicated; component = &CurrentEntry->ComponentEntry; // // Open/Create a key under Enum/Root bransh. If fails, // exit (nothing we can do.) // status = IopOpenRegistryKeyPersist ( &keyHandle, EnumRootHandle, KeyName, KEY_ALL_ACCESS, TRUE, &disposition ); if (!NT_SUCCESS(status)) { return status; } #if 0 // not sure if we need it // // If the key is newly created, set its NewDevice value to TRUE so that // user mode Pnp mgr can initiate a device installation. The NewDevice // value will be reset by user mode Pnp mgr. SO , we don't touch it here. // if (disposition == REG_CREATED_NEW_KEY) { newKey = TRUE; PiWstrToUnicodeString(&unicodeValueName, REGSTR_VALUE_NEWDEVICE); tmpValue = 1; NtSetValueKey( keyHandle, &unicodeValueName, TITLE_INDEX_VALUE, REG_DWORD, &tmpValue, sizeof (tmpValue) ); PiWstrToUnicodeString(&unicodeValueName, REGSTR_VALUE_STATIC); NtSetValueKey( keyHandle, &unicodeValueName, TITLE_INDEX_VALUE, REG_DWORD, &tmpValue, sizeof(tmpValue) ); } #endif if (component->Type > OtherController) { // // The current component is a peripheral. // // // Create a new instance key under KeyName // PiUlongToInstanceKeyUnicodeString(&unicodeName, unicodeBuffer, 20, Instance); status = IopOpenRegistryKeyPersist ( &handle, keyHandle, &unicodeName, KEY_ALL_ACCESS, TRUE, &disposition ); NtClose(keyHandle); if (!NT_SUCCESS(status)) { goto init_Exit; } // // // Create all the default value entry for the newly created key. // Service = (do NOT create) // BaseDevicePath = WorkName // FoundAtEnum = 1 // InterfaceType = InterfaceType (only for bus device) // SystemBusNumber = BusNumber (only for bus device) // BusDataType = BusDataType (only for bus device) // PiWstrToUnicodeString(&unicodeValueName, REGSTR_VALUE_BASEDEVICEPATH); p = WorkName->Buffer; p += WorkName->Length / sizeof(WCHAR); *p = UNICODE_NULL; NtSetValueKey( handle, &unicodeValueName, TITLE_INDEX_VALUE, REG_SZ, WorkName->Buffer, WorkName->Length + sizeof (UNICODE_NULL) ); PiWstrToUnicodeString(&unicodeValueName, REGSTR_VALUE_FOUNDATENUM); tmpValue = 1; NtSetValueKey( handle, &unicodeValueName, TITLE_INDEX_VALUE, REG_DWORD, &tmpValue, sizeof(tmpValue) ); PiWstrToUnicodeString(&unicodeValueName, REGSTR_VALUE_SYSTEMBUSNUMBER); tmpValue = BusNumber; NtSetValueKey( handle, &unicodeValueName, TITLE_INDEX_VALUE, REG_DWORD, &tmpValue, sizeof(tmpValue) ); PiWstrToUnicodeString(&unicodeValueName, REGSTR_VALUE_INTERFACETYPE); tmpValue = InterfaceType; NtSetValueKey( handle, &unicodeValueName, TITLE_INDEX_VALUE, REG_DWORD, &tmpValue, sizeof(tmpValue) ); PiWstrToUnicodeString(&unicodeValueName, REGSTR_VALUE_BUSDATATYPE); tmpValue = BusDataType; NtSetValueKey( handle, &unicodeValueName, TITLE_INDEX_VALUE, REG_DWORD, &tmpValue, sizeof(tmpValue) ); NtClose(handle); // // Append keyanme and instance key name to workname // (In fact, we don't need to do this because there // is nothing under peripheral component.) // // // Append KeyName to workname // p = WorkName->Buffer; p += WorkName->Length / sizeof(WCHAR); *p = OBJ_NAME_PATH_SEPARATOR; WorkName->Length += sizeof (WCHAR); RtlAppendStringToString((PSTRING)WorkName, (PSTRING)KeyName); } else { // // Current component is a controller // // // Append KeyName to workname // p = WorkName->Buffer; p += WorkName->Length / sizeof(WCHAR); *p = OBJ_NAME_PATH_SEPARATOR; WorkName->Length += sizeof (WCHAR); RtlAppendStringToString((PSTRING)WorkName, (PSTRING)KeyName); // // We need to convert the h/w tree configuration data format from // CM_PARTIAL_RESOURCE_DESCRIPTIOR to CM_RESOURCE_LIST. // if (CurrentEntry->ConfigurationData) { // // This component has configuration data, we copy the data // to our work area, add some more data items and copy the new // configuration data to the registry. // dataLength = component->ConfigurationDataLength + FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) + FIELD_OFFSET(CM_RESOURCE_LIST, List); dataArea = (PCM_RESOURCE_LIST)resourceBuffer; // // Make sure our reserved area is big enough to hold the data. // if (dataLength > PNP_LARGE_SCRATCH_BUFFER_SIZE) { // // If reserved area is not big enough, we resize our reserved // area. If, unfortunately, the reallocation fails, we simply // loss the configuration data of this particular component. // dataArea = (PCM_RESOURCE_LIST)ExAllocatePool( PagedPool, dataLength ); if (dataArea) { freeDataArea = TRUE; } } if (dataArea) { RtlMoveMemory((PUCHAR)&dataArea->List->PartialResourceList.Version, CurrentEntry->ConfigurationData, component->ConfigurationDataLength ); dataArea->Count = 1; dataArea->List[0].InterfaceType = InterfaceType; dataArea->List[0].BusNumber = BusNumber; } } if (CurrentEntry->ConfigurationData == NULL || !dataArea) { // // This component has NO configuration data (or we can't resize // our reserved area to hold the data), we simple add whatever // is required to set up a CM_FULL_RESOURCE_LIST. // dataArea = (PCM_RESOURCE_LIST)&emptyResource; dataLength = FIELD_OFFSET(CM_RESOURCE_LIST, List); } if (!newKey) { // // If the key exists already, we need to check if current entry // already being converted (most likely the answer is yes.). If it already // converted, we simply set "FoundAtEnum=" to TRUE. Otherwise, we will // create it. // tmpValue = 0; PiUlongToInstanceKeyUnicodeString(&unicodeName, unicodeBuffer, 20, tmpValue); status = IopOpenRegistryKey (&handle, keyHandle, &unicodeName, KEY_ALL_ACCESS, FALSE ); while (NT_SUCCESS(status)) { // // if the current key has been Found/Enum'ed already, we need // to skip it. // foundAlready = 0; status = IopGetRegistryValue (handle, REGSTR_VALUE_FOUNDATENUM, &keyValueInformation); if (NT_SUCCESS(status)) { if (keyValueInformation->DataLength != 0) { foundAlready = *(PULONG)KEY_VALUE_DATA(keyValueInformation); } ExFreePool(keyValueInformation); } if (!foundAlready) { keyValueInformation = NULL; status = IopGetRegistryValue (handle, REGSTR_VALUE_DETECTSIGNATURE, &keyValueInformation); if (NT_SUCCESS(status) && keyValueInformation->DataLength != 0) { configuration1 = (PCM_RESOURCE_LIST)KEY_VALUE_DATA(keyValueInformation); } else if (status == STATUS_OBJECT_NAME_NOT_FOUND || keyValueInformation->DataLength == 0) { // // If no "DetectSignature =" value entry, we set up an empty // CM_RESOURCE_LIST. // configuration1 = (PCM_RESOURCE_LIST)&emptyResource; } // // To detect ARC duplicated components, we should be able // to simply compare the RAW resource list. If they are the // same *most likely* they are duplicates. This includes // the case that both resource list are empty. (if they // are empty, we should be able to simply pick up the // key and use it.) // isDuplicated = IopIsDuplicatedResourceLists( configuration1, dataArea); if (!isDuplicated) { // // BUGBUG We should also check for bus info. // isDuplicated = IopIsDuplicatedDevices( configuration1, dataArea, NULL, NULL ); } if (keyValueInformation) { ExFreePool(keyValueInformation); } if (isDuplicated) { PiWstrToUnicodeString( &unicodeValueName, REGSTR_VALUE_FOUNDATENUM); tmpValue = 1; status = NtSetValueKey(handle, &unicodeValueName, TITLE_INDEX_VALUE, REG_DWORD, &tmpValue, sizeof(tmpValue) ); NtClose(handle); NtClose(keyHandle); goto init_Exit0; } } NtClose(handle); tmpValue++; PiUlongToInstanceKeyUnicodeString(&unicodeName, unicodeBuffer, 20, tmpValue); status = IopOpenRegistryKey (&handle, keyHandle, &unicodeName, KEY_ALL_ACCESS, FALSE ); } Instance = tmpValue; } // // We need to create the new instance key if we can come here... // PiUlongToInstanceKeyUnicodeString(&unicodeName, unicodeBuffer, 20, Instance); status = IopOpenRegistryKeyPersist ( &handle, keyHandle, &unicodeName, KEY_ALL_ACCESS, TRUE, NULL ); NtClose(keyHandle); PNP_ASSERT(NT_SUCCESS(status), "IopInitRegistryNode: Fail to create new key."); if (!NT_SUCCESS(status)) { goto init_Exit; } // // Newly created key -- // // Create all the default value entry for the newly created key. // Service = #if 0 // NewInstance = 1 #endif // FoundAtEnum = 1 // Configuration = // InterfaceType = InterfaceType // SystemBusNumber = BusNumber // BusDataType = BusDataType // #if 0 PiWstrToUnicodeString(&unicodeValueName, REGSTR_VALUE_NEWINSTANCE); tmpValue = 1; NtSetValueKey( handle, &unicodeValueName, TITLE_INDEX_VALUE, REG_DWORD, &tmpValue, sizeof(tmpValue) ); #endif PiWstrToUnicodeString(&unicodeValueName, REGSTR_VALUE_FOUNDATENUM); tmpValue = 1; NtSetValueKey( handle, &unicodeValueName, TITLE_INDEX_VALUE, REG_DWORD, &tmpValue, sizeof(tmpValue) ); #if 0 // // SystemBusNumber, InterfaceType and BusDataType are for Bus // devices only. For ntdetect/arc detected devices, we don't set // up bus devices. // PiWstrToUnicodeString(&unicodeValueName, REGSTR_VALUE_SYSTEMBUSNUMBER); tmpValue = BusNumber; NtSetValueKey( handle, &unicodeValueName, TITLE_INDEX_VALUE, REG_DWORD, &tmpValue, sizeof(tmpValue) ); PiWstrToUnicodeString(&unicodeValueName, REGSTR_VALUE_INTERFACETYPE); tmpValue = InterfaceType; NtSetValueKey( handle, &unicodeValueName, TITLE_INDEX_VALUE, REG_DWORD, &tmpValue, sizeof(tmpValue) ); PiWstrToUnicodeString(&unicodeValueName, REGSTR_VALUE_BUSDATATYPE); tmpValue = BusDataType; NtSetValueKey( handle, &unicodeValueName, TITLE_INDEX_VALUE, REG_DWORD, &tmpValue, sizeof(tmpValue) ); #endif PiWstrToUnicodeString(&unicodeValueName, REGSTR_VALUE_CONFIGURATION); NtSetValueKey( handle, &unicodeValueName, TITLE_INDEX_VALUE, REG_RESOURCE_LIST, dataArea, dataLength ); PiWstrToUnicodeString(&unicodeValueName, REGSTR_VALUE_DETECTSIGNATURE); NtSetValueKey( handle, &unicodeValueName, TITLE_INDEX_VALUE, REG_RESOURCE_LIST, dataArea, dataLength ); NtClose(handle); } status = STATUS_SUCCESS; init_Exit0: p = WorkName->Buffer; p += WorkName->Length / sizeof(WCHAR); *p = OBJ_NAME_PATH_SEPARATOR; WorkName->Length += sizeof (WCHAR); RtlAppendStringToString((PSTRING)WorkName, (PSTRING)&unicodeName); init_Exit: if (freeDataArea) { ExFreePool(dataArea); } if (serviceInfo) { ExFreePool(serviceInfo); } return(status); }
/****************************************************************************** * SetComputerNameW [KERNEL32.@] * * Set a new NetBIOS name for the local computer. * * PARAMS * lpComputerName [I] Address of new computer name * * RETURNS * Success: TRUE * Failure: FALSE */ BOOL WINAPI SetComputerNameW( LPCWSTR lpComputerName ) { UNICODE_STRING nameW; OBJECT_ATTRIBUTES attr; HANDLE hkey = INVALID_HANDLE_VALUE, hsubkey = INVALID_HANDLE_VALUE; int plen = strlenW ( lpComputerName ); int i; NTSTATUS st = STATUS_INTERNAL_ERROR; if (get_use_dns_option()) { /* This check isn't necessary, but may help debugging problems. */ WARN( "Disabled by Wine Configuration.\n" ); WARN( "Set \"UseDnsComputerName\" = \"N\" in HKCU\\Software\\Wine\\Network to enable.\n" ); SetLastError ( ERROR_ACCESS_DENIED ); return FALSE; } TRACE( "%s\n", debugstr_w (lpComputerName) ); /* Check parameter */ if ( plen > MAX_COMPUTERNAME_LENGTH ) goto out; /* This is NT behaviour. Win 95/98 would coerce characters. */ for ( i = 0; i < plen; i++ ) { WCHAR wc = lpComputerName[i]; if ( wc != netbios_char( wc ) ) goto out; } _init_attr ( &attr, &nameW ); RtlInitUnicodeString (&nameW, ComputerW); if ( ( st = NtOpenKey( &hkey, KEY_ALL_ACCESS, &attr ) ) != STATUS_SUCCESS ) goto out; attr.RootDirectory = hkey; RtlInitUnicodeString( &nameW, ComputerNameW ); if ( ( st = NtOpenKey( &hsubkey, KEY_ALL_ACCESS, &attr ) ) != STATUS_SUCCESS ) goto out; if ( ( st = NtSetValueKey( hsubkey, &nameW, 0, REG_SZ, lpComputerName, ( plen + 1) * sizeof(WCHAR) ) ) != STATUS_SUCCESS ) goto out; out: NtClose( hsubkey ); NtClose( hkey ); if ( st == STATUS_SUCCESS ) { TRACE( "ComputerName changed\n" ); return TRUE; } else { SetLastError ( RtlNtStatusToDosError ( st ) ); WARN ( "status %u\n", st ); return FALSE; } }
BOOLEAN IopInitializeDeviceInstanceKey( IN HANDLE KeyHandle, IN PUNICODE_STRING KeyName, IN OUT PVOID WorkName ) /*++ Routine Description: This routine is a callback function for IopApplyFunctionToSubKeys. It is called for each subkey under HKLM\System\Enum\BusKey\DeviceKey. Arguments: KeyHandle - Supplies a handle to this key. KeyName - Supplies the name of this key. WorkName - points to the unicodestring which describes the path up to this key. Returns: TRUE to continue the enumeration. FALSE to abort it. --*/ { UNICODE_STRING unicodeName, serviceName; PKEY_VALUE_FULL_INFORMATION keyValueInformation; NTSTATUS status; BOOLEAN duplicate = FALSE; ULONG foundAtEnum, deviceFlags, instance, tmpValue1, tmpValue2; USHORT length; PUNICODE_STRING pUnicode; // // Get the "Problem" value entry to determine what we need to do with // the device instance key. // deviceFlags = 0; status = IopGetRegistryValue ( KeyHandle, REGSTR_VALUE_PROBLEM, &keyValueInformation ); if (NT_SUCCESS(status)) { if ((keyValueInformation->Type == REG_DWORD) && (keyValueInformation->DataLength >= sizeof(ULONG))) { deviceFlags = *(PULONG)KEY_VALUE_DATA(keyValueInformation); } ExFreePool(keyValueInformation); } if (deviceFlags == CM_PROB_MOVED) { // // If the device instance was moved, we simply delete the key. // The key will be deleted once the caller close the open handle. // NtDeleteKey(KeyHandle); return TRUE; } // // The device instance key exists. We need to propagate the ConfigFlag // to problem and StatusFlags // deviceFlags = 0; status = IopGetRegistryValue(KeyHandle, REGSTR_VALUE_CONFIG_FLAGS, &keyValueInformation); if (NT_SUCCESS(status)) { if ((keyValueInformation->Type == REG_DWORD) && (keyValueInformation->DataLength >= sizeof(ULONG))) { deviceFlags = *(PULONG)KEY_VALUE_DATA(keyValueInformation); } ExFreePool(keyValueInformation); } if (deviceFlags & CONFIGFLAG_REINSTALL) { tmpValue1 = CM_PROB_REINSTALL; // Problem tmpValue2 = DN_HAS_PROBLEM; // StatusFlags } else { tmpValue1 = tmpValue2 = 0; } PiWstrToUnicodeString(&unicodeName, REGSTR_VALUE_PROBLEM); NtSetValueKey(KeyHandle, &unicodeName, TITLE_INDEX_VALUE, REG_DWORD, &tmpValue1, sizeof(tmpValue1) ); PiWstrToUnicodeString(&unicodeName, REGSTR_VALUE_STATUSFLAGS); NtSetValueKey(KeyHandle, &unicodeName, TITLE_INDEX_VALUE, REG_DWORD, &tmpValue2, sizeof(tmpValue2) ); // // Get the "DuplicateOf" value entry to determine if the device instance // should be registered. If the device instance is duplicate, We don't // add it to its service key's enum branch. // status = IopGetRegistryValue ( KeyHandle, REGSTR_VALUE_DUPLICATEOF, &keyValueInformation ); if (NT_SUCCESS(status)) { if ((keyValueInformation->Type == REG_SZ) && (keyValueInformation->DataLength > 0)) { duplicate = TRUE; } ExFreePool(keyValueInformation); } if (!duplicate) { // // Combine WorkName and KeyName to form device instance path // and register this device instance by // constructing new value entry for ServiceKeyName\Enum key. // i.e., <Number> = <PathToSystemEnumBranch> // pUnicode = (PUNICODE_STRING)WorkName; length = pUnicode->Length; // Save WorkName if (pUnicode->Buffer[pUnicode->Length / sizeof(WCHAR) - 1] != OBJ_NAME_PATH_SEPARATOR) { pUnicode->Buffer[pUnicode->Length / sizeof(WCHAR)] = OBJ_NAME_PATH_SEPARATOR; pUnicode->Length += 2; } RtlAppendStringToString((PSTRING)pUnicode, (PSTRING)KeyName); PpDeviceRegistration(pUnicode, TRUE); pUnicode->Length = length; // Restore WorkName } // // Get the "Service=" value entry from KeyHandle // keyValueInformation = NULL; serviceName.Length = 0; status = IopGetRegistryValue ( KeyHandle, REGSTR_VALUE_SERVICE, &keyValueInformation ); if (NT_SUCCESS(status)) { // // Append the new instance to its corresponding // Service\Name\Enum. // if ((keyValueInformation->Type == REG_SZ) && (keyValueInformation->DataLength != 0)) { // // Set up ServiceKeyName unicode string // IopRegistryDataToUnicodeString( &serviceName, (PWSTR)KEY_VALUE_DATA(keyValueInformation), keyValueInformation->DataLength ); } // // Do not Free keyValueInformation // } // // The Pnp mgr set FoundAtEnum to 0 for everything under system\ccs\enum. // For the stuff under Root we need to set them to 1 except if their // CsConfigFlags was set to CSCONFIGFLAG_DO_NOT_CREATE. // foundAtEnum = 1; status = RtlUnicodeStringToInteger(KeyName, 10, &instance); if (NT_SUCCESS(status)) { if (serviceName.Length != 0) { status = IopGetDeviceInstanceCsConfigFlags( &serviceName, instance, &deviceFlags ); if (NT_SUCCESS(status) && (deviceFlags & CSCONFIGFLAG_DO_NOT_CREATE)) { foundAtEnum = 0; } } } if (keyValueInformation) { ExFreePool(keyValueInformation); } PiWstrToUnicodeString(&unicodeName, REGSTR_VALUE_FOUNDATENUM); NtSetValueKey(KeyHandle, &unicodeName, TITLE_INDEX_VALUE, REG_DWORD, &foundAtEnum, sizeof(foundAtEnum) ); // // Clean up "NtLogicalDevicePaths=" and "NtPhysicalDevicePaths=" of this key // PiWstrToUnicodeString(&unicodeName, REGSTR_VALUE_NT_PHYSICAL_DEVICE_PATHS); NtDeleteValueKey(KeyHandle, &unicodeName); PiWstrToUnicodeString(&unicodeName, REGSTR_VALUE_NT_LOGICAL_DEVICE_PATHS); NtDeleteValueKey(KeyHandle, &unicodeName); return TRUE; }
VOID DoTest( HANDLE RootKey ) { NTSTATUS rc; STRING String1; UCHAR Value1[] = "This string is value 1."; UCHAR Value2[] = "Value 2 is represented by this string."; HANDLE Handle1; HANDLE Handle2; ULONG ValueLength; ULONG Type; LARGE_INTEGER Time; // // Create parent node // DbgPrint("Part1\n"); RtlInitString(&String1, "Test1"); rc = NtCreateKey( RootKey, &String1, 0, NULL, GENERIC_READ|GENERIC_WRITE, &Handle1 ); if (!NT_SUCCESS(rc)) { DbgPrint("1:CreateKey failed rc = %08lx", rc); return; } // // Set data into parent // DbgPrint("Part2\n"); rc = NtSetValueKey( Handle1, 1, // type Value1, strlen(Value1) ); if (!NT_SUCCESS(rc)) { DbgPrint("2:SetValueKey failed rc = %08lx", rc); return; } // // Query and compare data from parent // DbgPrint("Part2b\n"); ValueLength = MAX_VALUE; rc = NtQueryValueKey( Handle1, &Type, ValueBuffer, &ValueLength, &Time ); if (!NT_SUCCESS(rc)) { DbgPrint("2b:QueryValueKey failed rc = %08lx", rc); return; } if (ValueLength != (ULONG)strlen(Value1)) { DbgPrint("2b1:Wrong value length\n"); return; } else if (RtlCompareMemory( ValueBuffer, Value1, ValueLength) != ValueLength) { DbgPrint("2b2:Wrong value\n"); return; } else if (Type != 1) { DbgPrint("2b3:Wrong type\n"); return; } // // Close parent // DbgPrint("Part3\n"); NtCloseKey(Handle1); if (!NT_SUCCESS(rc)) { DbgPrint("3:CloseKey failed rc = %08lx", rc); return; } // // Reopen parent // DbgPrint("Part4\n"); rc = NtOpenKey( RootKey, &String1, 0, GENERIC_READ|GENERIC_WRITE, &Handle1 ); if (!NT_SUCCESS(rc)) { DbgPrint("4:OpenKey failed rc = %08lx", rc); return; } // // Create child // DbgPrint("Part5\n"); RtlInitString(&String1, "Test2"); rc = NtCreateKey( Handle1, &String1, 0, NULL, GENERIC_READ|GENERIC_WRITE, &Handle2 ); if (!NT_SUCCESS(rc)) { DbgPrint("5:CreateKey failed rc = %08lx", rc); return; } // // Set data into child // DbgPrint("Part6\n"); rc = NtSetValueKey( Handle2, 2, // type Value2, strlen(Value2) ); if (!NT_SUCCESS(rc)) { DbgPrint("6:SetValueKey failed rc = %08lx", rc); return; } // // Query and compare data from child // DbgPrint("Part7\n"); ValueLength = MAX_VALUE; rc = NtQueryValueKey( Handle2, &Type, ValueBuffer, &ValueLength, &Time ); if (!NT_SUCCESS(rc)) { DbgPrint("7:QueryValueKey failed rc = %08lx", rc); return; } if (ValueLength != (ULONG)strlen(Value2)) { DbgPrint("7.1:Wrong value length\n"); return; } else if (RtlCompareMemory( ValueBuffer, Value2, ValueLength) != ValueLength) { DbgPrint("7.2:Wrong value\n"); return; } else if (Type != 2) { DbgPrint("7.3:Wrong type\n"); return; } // // Query and compare data from parent again // DbgPrint("Part8\n"); ValueLength = MAX_VALUE; rc = NtQueryValueKey( Handle1, &Type, ValueBuffer, &ValueLength, &Time ); if (!NT_SUCCESS(rc)) { DbgPrint("8:QueryValueKey failed rc = %08lx", rc); return; } if (ValueLength != (ULONG)strlen(Value1)) { DbgPrint("8.1:Wrong value length\n"); return; } else if (RtlCompareMemory( ValueBuffer, Value1, ValueLength) != ValueLength) { DbgPrint("8.2:Wrong value\n"); return; } else if (Type != 1) { DbgPrint("8.3:Wrong type\n"); return; } // // Reset parent data // DbgPrint("Part9\n"); rc = NtSetValueKey( Handle1, 1, // type Value2, strlen(Value2) ); if (!NT_SUCCESS(rc)) { DbgPrint("9:SetValueKey failed rc = %08lx", rc); return; } // // Query and compare reset data // DbgPrint("Part10\n"); ValueLength = MAX_VALUE; rc = NtQueryValueKey( Handle1, &Type, ValueBuffer, &ValueLength, &Time ); if (!NT_SUCCESS(rc)) { DbgPrint("10:QueryValueKey failed rc = %08lx", rc); return; } if (ValueLength != (ULONG)strlen(Value2)) { DbgPrint("10.1:Wrong value length\n"); return; } else if (RtlCompareMemory( ValueBuffer, Value2, ValueLength) != ValueLength) { DbgPrint("10.2:Wrong value\n"); return; } else if (Type != 1) { DbgPrint("10.3:Wrong type\n"); return; } // // Close off handles and return // DbgPrint("Part11\n"); rc = NtCloseKey(Handle1); if (!NT_SUCCESS(rc)) { DbgPrint("11:CloseKey failed rc = %08lx", rc); return; } DbgPrint("Part12\n"); rc = NtCloseKey(Handle2); if (!NT_SUCCESS(rc)) { DbgPrint("12:CloseKey failed rc = %08lx", rc); return; } return; }
/*********************************************************************** * COMPUTERNAME_Init (INTERNAL) */ void COMPUTERNAME_Init (void) { HANDLE hkey = INVALID_HANDLE_VALUE, hsubkey = INVALID_HANDLE_VALUE; OBJECT_ATTRIBUTES attr; UNICODE_STRING nameW; char buf[offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data ) + (MAX_COMPUTERNAME_LENGTH + 1) * sizeof( WCHAR )]; DWORD len = sizeof( buf ); LPWSTR computer_name = (LPWSTR) (buf + offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data )); NTSTATUS st = STATUS_INTERNAL_ERROR; TRACE("(void)\n"); _init_attr ( &attr, &nameW ); RtlInitUnicodeString( &nameW, ComputerW ); if ( ( st = NtCreateKey( &hkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) ) != STATUS_SUCCESS ) goto out; attr.RootDirectory = hkey; RtlInitUnicodeString( &nameW, ComputerNameW ); if ( (st = NtCreateKey( &hsubkey, KEY_ALL_ACCESS, &attr, 0, NULL, 0, NULL ) ) != STATUS_SUCCESS ) goto out; st = NtQueryValueKey( hsubkey, &nameW, KeyValuePartialInformation, buf, len, &len ); if ( st != STATUS_SUCCESS || get_use_dns_option() ) { char hbuf[256]; int hlen = sizeof (hbuf); char *dot; TRACE( "retrieving Unix host name\n" ); if ( gethostname ( hbuf, hlen ) ) { strcpy ( hbuf, default_ComputerName ); WARN( "gethostname() error: %d, using host name %s\n", errno, hbuf ); } hbuf[MAX_COMPUTERNAME_LENGTH] = 0; dot = strchr ( hbuf, '.' ); if ( dot ) *dot = 0; hlen = strlen ( hbuf ); len = MultiByteToWideChar( CP_UNIXCP, 0, hbuf, hlen + 1, computer_name, MAX_COMPUTERNAME_LENGTH + 1 ) * sizeof( WCHAR ); if ( NtSetValueKey( hsubkey, &nameW, 0, REG_SZ, computer_name, len ) != STATUS_SUCCESS ) WARN ( "failed to set ComputerName\n" ); } else { len = (len - offsetof( KEY_VALUE_PARTIAL_INFORMATION, Data )); TRACE( "found in registry\n" ); } NtClose( hsubkey ); TRACE(" ComputerName: %s (%u)\n", debugstr_w (computer_name), len); RtlInitUnicodeString( &nameW, ActiveComputerNameW ); if ( ( st = NtCreateKey( &hsubkey, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, NULL ) ) != STATUS_SUCCESS ) goto out; RtlInitUnicodeString( &nameW, ComputerNameW ); st = NtSetValueKey( hsubkey, &nameW, 0, REG_SZ, computer_name, len ); out: NtClose( hsubkey ); NtClose( hkey ); if ( st == STATUS_SUCCESS ) TRACE( "success\n" ); else { WARN( "status trying to set ComputerName: %x\n", st ); SetLastError ( RtlNtStatusToDosError ( st ) ); } }
NTSTATUS CmpInitializeRegistryNode( IN PCONFIGURATION_COMPONENT_DATA CurrentEntry, IN HANDLE ParentHandle, OUT PHANDLE NewHandle, IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PUSHORT DeviceIndexTable ) /*++ Routine Description: This routine creates a node for the current firmware component and puts component data to the data part of the node. Arguments: CurrentEntry - Supplies a pointer to a configuration component. Handle - Supplies the parent handle of CurrentEntry node. NewHandle - Supplies a pointer to a HANDLE to receive the handle of the newly created node. InterfaceType - Specify the Interface type of the bus that the CurrentEntry component resides. (See BusNumber also) BusNumber - Specify the Bus Number of the bus that the CurrentEntry component resides on. If Bus number is -1, it means InterfaceType and BusNumber are meaningless for this component. Returns: None. --*/ { NTSTATUS Status; OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName; UNICODE_STRING ValueName; UNICODE_STRING ValueData; HANDLE Handle; HANDLE OldHandle; ANSI_STRING AnsiString; CHAR Buffer[12]; WCHAR UnicodeBuffer[12]; CONFIGURATION_COMPONENT *Component; ULONG Disposition; ULONG ConfigurationDataLength = 0; PCM_FULL_RESOURCE_DESCRIPTOR NewArea; Component = &CurrentEntry->ComponentEntry; // // If the component class is SystemClass, we set its Type to be // ArcSystem. The reason is because the detection code sets // its type to MaximumType to indicate it is NOT ARC compatible. // Here, we are only interested in building a System Node. So we // change its Type to ArcSystem to ease the setup. // if (Component->Class == SystemClass) { Component->Type = ArcSystem; } // // Create a new key to describe the Component. // // The type of the component will be used as the keyname of the // registry node. The class is the class of the component. // InitializeObjectAttributes( &ObjectAttributes, &(CmTypeName[Component->Type]), 0, ParentHandle, NULL ); ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; Status = NtCreateKey( // Paht may already exist &Handle, KEY_READ | KEY_WRITE, &ObjectAttributes, 0, NULL, 0, &Disposition ); if (!NT_SUCCESS(Status)) { return(Status); } // // If this component is NOT a SystemClass component, we will // create a subkey to identify the component's ordering. // if (Component->Class != SystemClass) { RtlIntegerToChar( DeviceIndexTable[Component->Type]++, 10, 12, Buffer ); RtlInitAnsiString( &AnsiString, Buffer ); KeyName.Buffer = (PWSTR)UnicodeBuffer; KeyName.Length = 0; KeyName.MaximumLength = sizeof(UnicodeBuffer); RtlAnsiStringToUnicodeString( &KeyName, &AnsiString, FALSE ); OldHandle = Handle; InitializeObjectAttributes( &ObjectAttributes, &KeyName, 0, OldHandle, NULL ); ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; Status = NtCreateKey( &Handle, KEY_READ | KEY_WRITE, &ObjectAttributes, 0, NULL, 0, &Disposition ); NtClose(OldHandle); if (!NT_SUCCESS(Status)) { return(Status); } ASSERT(Disposition == REG_CREATED_NEW_KEY); } // // Create a value which describes the following component information: // Flags, Cersion, Key, AffinityMask. // RtlInitUnicodeString( &ValueName, L"Component Information" ); Status = NtSetValueKey( Handle, &ValueName, TITLE_INDEX_VALUE, REG_BINARY, &Component->Flags, FIELD_OFFSET(CONFIGURATION_COMPONENT, ConfigurationDataLength) - FIELD_OFFSET(CONFIGURATION_COMPONENT, Flags) ); if (!NT_SUCCESS(Status)) { NtClose(Handle); return(Status); } // // Create a value which describes the component identifier, if any. // if (Component->IdentifierLength) { RtlInitUnicodeString( &ValueName, L"Identifier" ); RtlInitAnsiString( &AnsiString, Component->Identifier ); Status = RtlAnsiStringToUnicodeString( &ValueData, &AnsiString, TRUE ); if( NT_SUCCESS(Status) ) { Status = NtSetValueKey( Handle, &ValueName, TITLE_INDEX_VALUE, REG_SZ, ValueData.Buffer, ValueData.Length + sizeof( UNICODE_NULL ) ); RtlFreeUnicodeString(&ValueData); } if (!NT_SUCCESS(Status)) { NtClose(Handle); return(Status); } } // // Create a value entry for component configuration data. // RtlInitUnicodeString( &ValueName, L"Configuration Data" ); // // Create the configuration data based on CM_FULL_RESOURCE_DESCRIPTOR. // // Note the configuration data in firmware tree may be in the form of // CM_PARTIAL_RESOURCE_LIST or nothing. In both cases, we need to // set up the registry configuration data to be in the form of // CM_FULL_RESOURCE_DESCRIPTOR. // if (CurrentEntry->ConfigurationData) { // // This component has configuration data, we copy the data // to our work area, add some more data items and copy the new // configuration data to the registry. // ConfigurationDataLength = Component->ConfigurationDataLength + FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList); // // Make sure our reserved area is big enough to hold the data. // if (ConfigurationDataLength > CmpConfigurationAreaSize) { // // If reserved area is not big enough, we resize our reserved // area. If, unfortunately, the reallocation fails, we simply // loss the configuration data of this particular component. // NewArea = (PCM_FULL_RESOURCE_DESCRIPTOR)ExAllocatePool( PagedPool, ConfigurationDataLength ); if (NewArea) { CmpConfigurationAreaSize = ConfigurationDataLength; ExFreePool(CmpConfigurationData); CmpConfigurationData = NewArea; RtlCopyMemory( (PUCHAR)&CmpConfigurationData->PartialResourceList.Version, CurrentEntry->ConfigurationData, Component->ConfigurationDataLength ); } else { Component->ConfigurationDataLength = 0; CurrentEntry->ConfigurationData = NULL; } } else { RtlCopyMemory( (PUCHAR)&CmpConfigurationData->PartialResourceList.Version, CurrentEntry->ConfigurationData, Component->ConfigurationDataLength ); } } if (CurrentEntry->ConfigurationData == NULL) { // // This component has NO configuration data (or we can't resize // our reserved area to hold the data), we simple add whatever // is required to set up a CM_FULL_RESOURCE_LIST. // CmpConfigurationData->PartialResourceList.Version = 0; CmpConfigurationData->PartialResourceList.Revision = 0; CmpConfigurationData->PartialResourceList.Count = 0; ConfigurationDataLength = FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList) + FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors); } // // Set up InterfaceType and BusNumber for the component. // CmpConfigurationData->InterfaceType = InterfaceType; CmpConfigurationData->BusNumber = BusNumber; // // Write the newly constructed configuration data to the hardware registry // Status = NtSetValueKey( Handle, &ValueName, TITLE_INDEX_VALUE, REG_FULL_RESOURCE_DESCRIPTOR, CmpConfigurationData, ConfigurationDataLength ); if (!NT_SUCCESS(Status)) { NtClose(Handle); return(Status); } *NewHandle = Handle; return(STATUS_SUCCESS); }
void _CRTAPI1 main(int, char *) { NTSTATUS status; OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName; UNICODE_STRING KeyName2; UNICODE_STRING ClassName; UNICODE_STRING ClassName2; UNICODE_STRING ValueName; UNICODE_STRING ValueName2; HANDLE BaseHandle; HANDLE Testhand1; ULONG Disposition; LARGE_INTEGER CompTime; ULONG buffer[100]; ULONG bufsize = sizeof(ULONG) * 100; PKEY_NODE_INFORMATION NodeInformation; PKEY_VALUE_FULL_INFORMATION KeyValueInformation; PKEY_VALUE_BASIC_INFORMATION KeyValueBasic; ULONG ResultLength; PUCHAR datastring = "Some simple ascii data for use as a value"; PUCHAR datastring2 = "Some more not so simple data $#"; ULONG expected; PVOID tp; printf("rtmisc1: starting\n"); NodeInformation = (PKEY_NODE_INFORMATION)&(buffer[0]); KeyValueInformation = (PKEY_VALUE_FULL_INFORMATION)&(buffer[0]); KeyValueBasic = (PKEY_VALUE_BASIC_INFORMATION)&(buffer[0]); // // t0: Perform all operations against a base node, open it here. // RtlInitUnicodeString( &KeyName, L"\\REGISTRY\\MACHINE\\TEST" ); InitializeObjectAttributes( &ObjectAttributes, &KeyName, 0, (HANDLE)NULL, NULL ); ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; status = NtOpenKey( &BaseHandle, MAXIMUM_ALLOWED, &ObjectAttributes ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t0: %08lx\n", status); goto punt; } // // t1: Create a key with class and title index // RtlInitUnicodeString( &ClassName, L"t1 Class Name" ); RtlInitUnicodeString( &KeyName, L"first_test_node" ); InitializeObjectAttributes( &ObjectAttributes, &KeyName, 0, BaseHandle, NULL ); ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; NtQuerySystemTime(&CompTime); // printf("ClassName@%08lx KeyName@%08lx\n", // ClassName.Buffer, KeyName.Buffer); status = NtCreateKey( &Testhand1, MAXIMUM_ALLOWED, &ObjectAttributes, TITLE_INDEX_1, &ClassName, 0, &Disposition ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t1: %08lx\n", status); goto punt; } if (Disposition != REG_CREATED_NEW_KEY) { printf("rtmisc1: t1a: got old key, expected to create new one\n"); failure++; } // // t2: See if we can get data back, and if it makes sense // RtlZeroMemory(NodeInformation, bufsize); status = NtQueryKey( Testhand1, KeyNodeInformation, NodeInformation, bufsize, &ResultLength ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t2a: %08lx\n", status); goto punt; } if (ResultLength != 80) { printf("rtmisc1: t2i: expect 80, ResultLength = %d\n", ResultLength); failure++; } NameClassAndTitle( NodeInformation, ClassName, TITLE_INDEX_1, KeyName, CompTime, FALSE, // time must be >= CompTime "rtmisc1: t2b: " ); CompTime = NodeInformation->LastWriteTime; status = NtClose(Testhand1); if (!NT_SUCCESS(status)) { printf("rtmisc1: t2c: %08lx\n"); goto punt; } // // t3: Reopen the key with create, see if data still there. // status = NtCreateKey( &Testhand1, MAXIMUM_ALLOWED, &ObjectAttributes, TITLE_INDEX_1, &ClassName, 0, &Disposition ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t3: %08lx\n", status); goto punt; } if (Disposition != REG_OPENED_EXISTING_KEY) { printf("rtmisc1: t3a failure\n"); failure++; } RtlZeroMemory(NodeInformation, bufsize); status = NtQueryKey( Testhand1, KeyNodeInformation, NodeInformation, bufsize, &ResultLength ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t3b: %08lx\n", status); goto punt; } NameClassAndTitle( NodeInformation, ClassName, TITLE_INDEX_1, KeyName, CompTime, FALSE, // time must be >= CompTime "rtmisc1: t3c: " ); status = NtClose(Testhand1); if (!NT_SUCCESS(status)) { printf("rtmisc1: t3d: %08lx\n"); goto punt; } // // t4: Reopen the key with open, see if data still there. // status = NtOpenKey( &Testhand1, MAXIMUM_ALLOWED, &ObjectAttributes ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t4: %08lx\n", status); goto punt; } RtlZeroMemory(NodeInformation, bufsize); status = NtQueryKey( Testhand1, KeyNodeInformation, NodeInformation, bufsize, &ResultLength ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t4a: %08lx\n", status); goto punt; } NameClassAndTitle( NodeInformation, ClassName, TITLE_INDEX_1, KeyName, CompTime, FALSE, // time must be >= CompTime "rtmisc1: t4b: " ); // status = NtClose(Testhand1); // if (!NT_SUCCESS(status)) { // printf("rtmisc1: t4c: %08lx\n"); // exit(1); // } // // t5: Create a value // RtlInitUnicodeString( &ValueName, L"the very first value stored in the registry" ); status = NtSetValueKey( Testhand1, &ValueName, TITLE_INDEX_2, TYPE_1, datastring, strlen(datastring)+1 ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t5: %08lx\n", status); failure++; } // // t6: Read the value back // RtlZeroMemory(KeyValueInformation, bufsize); status = NtQueryValueKey( Testhand1, &ValueName, KeyValueFullInformation, KeyValueInformation, bufsize, &ResultLength ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t6: %08lx\n", status); goto punt; } expected = FIELD_OFFSET(KEY_VALUE_FULL_INFORMATION, Name) + ValueName.Length + strlen(datastring) + 1; if (ResultLength != expected) { printf("rtmisc1: t6a: expected = %08lx actual = %08lx", expected, ResultLength); failure++; } if ( (KeyValueInformation->TitleIndex != TITLE_INDEX_2) || (KeyValueInformation->Type != TYPE_1) || (KeyValueInformation->NameLength != ValueName.Length) || (KeyValueInformation->DataLength != strlen(datastring)+1)) { printf("rtmisc1: t6b: wrong description data\n"); failure++; } tp = (PWSTR)&(KeyValueInformation->Name[0]); if (wcsncmp(ValueName.Buffer, tp, (ValueName.Length/sizeof(WCHAR))) != 0) { printf("rtmisc1: t6c: wrong name\n"); expectstring( ValueName.Buffer, (ValueName.Length/sizeof(WCHAR)), (PWSTR)&(KeyValueInformation->Name[0]), (KeyValueInformation->NameLength/sizeof(WCHAR)) ); failure++; } tp = (PUCHAR)KeyValueInformation + KeyValueInformation->DataOffset; if (strcmp(tp, datastring) != 0) { printf("rtmisc1: t6d: wrong data\n"); printf("expected '%s', got '%s'\n", datastring, tp); failure++; } // // t7: Create a second value // RtlInitUnicodeString( &ValueName2, L"the second value stored in the registry" ); status = NtSetValueKey( Testhand1, &ValueName2, TITLE_INDEX_3, TYPE_2, datastring2, strlen(datastring2)+1 ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t7: %08lx\n", status); failure++; } // // t8: Read the second value back (short form) // RtlZeroMemory(KeyValueBasic, bufsize); status = NtQueryValueKey( Testhand1, &ValueName2, KeyValueBasicInformation, KeyValueBasic, bufsize, &ResultLength ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t8: %08lx\n", status); goto punt; } expected = FIELD_OFFSET(KEY_VALUE_BASIC_INFORMATION, Name) + ValueName2.Length; if (ResultLength != expected) { printf("rtmisc1: t8a: expected = %08lx actual = %08lx", expected, ResultLength); failure++; } if ( (KeyValueBasic->TitleIndex != TITLE_INDEX_3) || (KeyValueBasic->Type != TYPE_2) || (KeyValueBasic->NameLength != ValueName2.Length)) { printf("rtmisc1: t8b: wrong description data\n"); failure++; } tp = (PWSTR)&(KeyValueBasic->Name[0]); if (wcsncmp(ValueName2.Buffer, tp, (ValueName2.Length/sizeof(WCHAR))) != 0) { printf("rtmisc1: t8c: wrong name\n"); expectstring( ValueName2.Buffer, (ValueName2.Length/sizeof(WCHAR)), (PWSTR)&(KeyValueBasic->Name[0]), (KeyValueBasic->NameLength/sizeof(WCHAR)) ); failure++; } // // t9: Enumerate the values (short form) // RtlZeroMemory(KeyValueBasic, bufsize); status = NtEnumerateValueKey( Testhand1, 0, // Index KeyValueBasicInformation, KeyValueBasic, bufsize, &ResultLength ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t9: %08lx\n", status); goto punt; } expected = FIELD_OFFSET(KEY_VALUE_BASIC_INFORMATION, Name) + ValueName.Length; if (ResultLength != expected) { printf("rtmisc1: t9a: expected = %08lx actual = %08lx", expected, ResultLength); failure++; } if (KeyValueBasic->NameLength != ValueName.Length) { printf("rtmisc1: t9b: wrong description data\n"); failure++; } tp = (PWSTR)&(KeyValueBasic->Name[0]); if (wcsncmp(ValueName.Buffer, tp, (ValueName.Length/sizeof(WCHAR))) != 0) { printf("rtmisc1: t9c: wrong name\n"); expectstring( ValueName.Buffer, (ValueName.Length/sizeof(WCHAR)), (PWSTR)&(KeyValueBasic->Name[0]), (KeyValueBasic->NameLength/sizeof(WCHAR)) ); failure++; } RtlZeroMemory(KeyValueBasic, bufsize); status = NtEnumerateValueKey( Testhand1, 1, // Index KeyValueBasicInformation, KeyValueBasic, bufsize, &ResultLength ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t9d: %08lx\n", status); goto punt; } expected = FIELD_OFFSET(KEY_VALUE_BASIC_INFORMATION, Name) + ValueName2.Length; if (ResultLength != expected) { printf("rtmisc1: t9e: expected = %08lx actual = %08lx", expected, ResultLength); failure++; } if (KeyValueBasic->NameLength != ValueName2.Length) { printf("rtmisc1: t9f: wrong description data\n"); failure++; } tp = (PWSTR)&(KeyValueBasic->Name[0]); if (wcsncmp(ValueName2.Buffer, tp, (ValueName2.Length/sizeof(WCHAR))) != 0) { printf("rtmisc1: t9g: wrong name\n"); expectstring( ValueName2.Buffer, (ValueName2.Length/sizeof(WCHAR)), (PWSTR)&(KeyValueBasic->Name[0]), (KeyValueBasic->NameLength/sizeof(WCHAR)) ); failure++; } status = NtEnumerateValueKey( Testhand1, 2, // Index KeyValueBasicInformation, KeyValueBasic, bufsize, &ResultLength ); if (status != STATUS_NO_MORE_ENTRIES) { printf("rtmisc1: t9h: %08lx\n", status); goto punt; } // // t10: create a second subkey and ennumerate the subkeys // status = NtClose(Testhand1); if (!NT_SUCCESS(status)) { printf("rtmisc1: t10a: %08lx\n", status); failure++; } RtlInitUnicodeString( &ClassName2, L"t2 Class Name" ); RtlInitUnicodeString( &KeyName2, L"second_test_node" ); InitializeObjectAttributes( &ObjectAttributes, &KeyName2, 0, BaseHandle, NULL ); ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; status = NtCreateKey( &Testhand1, MAXIMUM_ALLOWED, &ObjectAttributes, TITLE_INDEX_2, &ClassName2, 0, &Disposition ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t10b: %08lx\n", status); goto punt; } if (Disposition != REG_CREATED_NEW_KEY) { printf("rtmisc1: t10c: got old key, expected to create new one\n"); failure++; } // // See if we can get data back, and if it makes sense // RtlZeroMemory(NodeInformation, bufsize); status = NtQueryKey( Testhand1, KeyNodeInformation, NodeInformation, bufsize, &ResultLength ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t10d: %08lx\n", status); goto punt; } CompTime = NodeInformation->LastWriteTime; NameClassAndTitle( NodeInformation, ClassName2, TITLE_INDEX_2, KeyName2, CompTime, TRUE, "rtmisc1: t10e: " ); status = NtClose(Testhand1); if (!NT_SUCCESS(status)) { printf("rtmisc1: t10f: %08lx\n"); goto punt; } RtlZeroMemory(NodeInformation, bufsize); status = NtEnumerateKey( BaseHandle, 0, KeyNodeInformation, NodeInformation, bufsize, &ResultLength ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t10g: %08lx\n", status); failure++; } CompTime = NodeInformation->LastWriteTime; NameClassAndTitle( NodeInformation, ClassName, TITLE_INDEX_1, KeyName, CompTime, TRUE, "rtmisc1: t10h: " ); RtlZeroMemory(NodeInformation, bufsize); status = NtEnumerateKey( BaseHandle, 1, KeyNodeInformation, NodeInformation, bufsize, &ResultLength ); if (!NT_SUCCESS(status)) { printf("rtmisc1: t10i: %08lx\n", status); failure++; } CompTime = NodeInformation->LastWriteTime; NameClassAndTitle( NodeInformation, ClassName2, TITLE_INDEX_2, KeyName2, CompTime, TRUE, "rtmisc1: t10j: " ); status = NtEnumerateKey( BaseHandle, 2, KeyNodeInformation, NodeInformation, bufsize, &ResultLength ); if (status != STATUS_NO_MORE_ENTRIES) { printf("rtmisc1: t10k: %08lx\n", status); failure++; } // // Summary report // if (!failure) { printf("rtmisc1: success"); exit(0); } else { printf("rtmisc1: failed, %d failures\n", failure); exit(1); } punt: failure++; printf("rtmisc1: failed, %d failures\n", failure); exit(1); }
BOOL SaveGroup( HANDLE GroupsKey, PWSTR GroupName, PGROUP_DEF Group ) { NTSTATUS Status; UNICODE_STRING KeyName, ValueName; HANDLE Key; OBJECT_ATTRIBUTES ObjectAttributes; ULONG CreateDisposition; LONG ValueLength; RtlInitUnicodeString( &KeyName, GroupName ); InitializeObjectAttributes( &ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, GroupsKey, NULL ); Status = NtCreateKey( &Key, STANDARD_RIGHTS_WRITE | KEY_QUERY_VALUE | KEY_ENUMERATE_SUB_KEYS | KEY_SET_VALUE | KEY_CREATE_SUB_KEY, &ObjectAttributes, 0, NULL, 0, &CreateDisposition ); if (!NT_SUCCESS( Status )) { BaseSetLastNTError( Status ); return FALSE; } ValueLength = (LONG)((ULONG)Group->wReserved); Group->wReserved = 0; Group->wCheckSum = (WORD)-ValueLength; RtlInitUnicodeString( &ValueName, L"" ); Status = NtSetValueKey( Key, &ValueName, 0, REG_BINARY, Group, ValueLength ); Group->wReserved = (WORD)ValueLength; Group->wCheckSum = 0; NtClose( Key ); if (!NT_SUCCESS( Status )) { return FALSE; } else { return TRUE; } }
VOID PhpAdvancedPageSave( _In_ HWND hwndDlg ) { ULONG sampleCount; SetSettingForDlgItemCheck(hwndDlg, IDC_ENABLEWARNINGS, L"EnableWarnings"); SetSettingForDlgItemCheckRestartRequired(hwndDlg, IDC_ENABLEKERNELMODEDRIVER, L"EnableKph"); SetSettingForDlgItemCheck(hwndDlg, IDC_HIDEUNNAMEDHANDLES, L"HideUnnamedHandles"); SetSettingForDlgItemCheckRestartRequired(hwndDlg, IDC_ENABLESTAGE2, L"EnableStage2"); SetSettingForDlgItemCheckRestartRequired(hwndDlg, IDC_ENABLENETWORKRESOLVE, L"EnableNetworkResolve"); SetSettingForDlgItemCheck(hwndDlg, IDC_PROPAGATECPUUSAGE, L"PropagateCpuUsage"); SetSettingForDlgItemCheck(hwndDlg, IDC_ENABLEINSTANTTOOLTIPS, L"EnableInstantTooltips"); if (WindowsVersion >= WINDOWS_7) SetSettingForDlgItemCheckRestartRequired(hwndDlg, IDC_ENABLECYCLECPUUSAGE, L"EnableCycleCpuUsage"); sampleCount = GetDlgItemInt(hwndDlg, IDC_SAMPLECOUNT, NULL, FALSE); SetSettingForDlgItemCheckRestartRequired(hwndDlg, IDC_SAMPLECOUNTAUTOMATIC, L"SampleCountAutomatic"); if (sampleCount == 0) sampleCount = 1; if (sampleCount != PhGetIntegerSetting(L"SampleCount")) RestartRequired = TRUE; PhSetIntegerSetting(L"SampleCount", sampleCount); // Replace Task Manager if (IsWindowEnabled(GetDlgItem(hwndDlg, IDC_REPLACETASKMANAGER))) { NTSTATUS status; HANDLE taskmgrKeyHandle; BOOLEAN replaceTaskMgr; UNICODE_STRING valueName; replaceTaskMgr = Button_GetCheck(GetDlgItem(hwndDlg, IDC_REPLACETASKMANAGER)) == BST_CHECKED; if (OldReplaceTaskMgr != replaceTaskMgr) { // We should have created the key back in PhpAdvancedPageLoad, which is why // we're opening the key here. if (NT_SUCCESS(PhOpenKey( &taskmgrKeyHandle, KEY_WRITE, PH_KEY_LOCAL_MACHINE, &TaskMgrImageOptionsKeyName, 0 ))) { RtlInitUnicodeString(&valueName, L"Debugger"); if (replaceTaskMgr) { PPH_STRING quotedFileName; quotedFileName = PH_AUTO(PhConcatStrings(3, L"\"", PhApplicationFileName->Buffer, L"\"")); status = NtSetValueKey(taskmgrKeyHandle, &valueName, 0, REG_SZ, quotedFileName->Buffer, (ULONG)quotedFileName->Length + 2); } else { status = NtDeleteValueKey(taskmgrKeyHandle, &valueName); } if (!NT_SUCCESS(status)) PhShowStatus(hwndDlg, L"Unable to replace Task Manager", status, 0); NtClose(taskmgrKeyHandle); } } } }
NTSTATUS PiInitializeSystemEnumSubKeys( IN HANDLE CurrentKeyHandle, IN PUNICODE_STRING ValueName ) /*++ Routine Description: This routine checks to see if the key whose handle was passed in contains a value whose name was specified by the ValueName argument. If so, it resets this value to a REG_DWORD 0. It then enumerates all subkeys under the current key, and recursively calls itself for each one. Arguments: CurrentKeyHandle - Supplies a handle to the key which will be enumerated. ValueName - Supplies a pointer to the value entry name to be initialized. Return Value: None. --*/ { NTSTATUS Status; PKEY_BASIC_INFORMATION KeyInformation; PKEY_VALUE_FULL_INFORMATION KeyValueInformation; USHORT i; ULONG TempValue, ResultLength; UNICODE_STRING UnicodeName; HANDLE WorkHandle; // // Set "FoundAtEnum=" entry of current key to FALSE, if exists. // Status = IopGetRegistryValue(CurrentKeyHandle, ValueName->Buffer, &KeyValueInformation ); if(NT_SUCCESS(Status)) { ExFreePool(KeyValueInformation); TempValue = 0; Status = NtSetValueKey(CurrentKeyHandle, ValueName, TITLE_INDEX_VALUE, REG_DWORD, &TempValue, sizeof(TempValue) ); if(!NT_SUCCESS(Status)) { return Status; } } // // Enumerate current node's children and apply ourselves to each one // KeyInformation = (PKEY_BASIC_INFORMATION)PiScratchBuffer; for(i = 0; TRUE; i++) { Status = NtEnumerateKey(CurrentKeyHandle, i, KeyBasicInformation, KeyInformation, PNP_LARGE_SCRATCH_BUFFER_SIZE, &ResultLength ); if(Status == STATUS_NO_MORE_ENTRIES) { break; } else if(!NT_SUCCESS(Status)) { continue; } UnicodeName.Length = (USHORT)KeyInformation->NameLength; UnicodeName.MaximumLength = (USHORT)KeyInformation->NameLength; UnicodeName.Buffer = KeyInformation->Name; Status = IopOpenRegistryKey(&WorkHandle, CurrentKeyHandle, &UnicodeName, KEY_ALL_ACCESS, FALSE ); if(!NT_SUCCESS(Status)) { continue; } Status = PiInitializeSystemEnumSubKeys(WorkHandle, ValueName); NtClose(WorkHandle); if(!NT_SUCCESS(Status)) { return Status; } } return STATUS_SUCCESS; }
BOOLEAN ProcessLocaleRegistry(PGENERIC_LIST List) { PGENERIC_LIST_ENTRY Entry; PWCHAR LanguageId; OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName; UNICODE_STRING ValueName; HANDLE KeyHandle; NTSTATUS Status; Entry = GetCurrentListEntry(List); if (Entry == NULL) return FALSE; LanguageId = (PWCHAR)GetListEntryUserData(Entry); if (LanguageId == NULL) return FALSE; /* Skip first 4 zeroes */ if (wcslen(LanguageId) >= 4) LanguageId += 4; /* Open the NLS language key */ RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\Control\\NLS\\Language"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, NULL, NULL); Status = NtOpenKey(&KeyHandle, KEY_SET_VALUE, &ObjectAttributes); if (!NT_SUCCESS(Status)) { DPRINT1("NtOpenKey() failed (Status %lx)\n", Status); return FALSE; } /* Set default language */ RtlInitUnicodeString(&ValueName, L"Default"); Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, (PVOID)LanguageId, (wcslen(LanguageId) + 1) * sizeof(WCHAR)); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); NtClose(KeyHandle); return FALSE; } /* Set install language */ RtlInitUnicodeString(&ValueName, L"InstallLanguage"); Status = NtSetValueKey (KeyHandle, &ValueName, 0, REG_SZ, (PVOID)LanguageId, (wcslen(LanguageId) + 1) * sizeof(WCHAR)); NtClose(KeyHandle); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); return FALSE; } return TRUE; }
static BOOLEAN AddHotkeySettings( IN PCWSTR Hotkey, IN PCWSTR LangHotkey, IN PCWSTR LayoutHotkey) { OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName; UNICODE_STRING ValueName; HANDLE KeyHandle; ULONG Disposition; NTSTATUS Status; RtlInitUnicodeString(&KeyName, L".DEFAULT\\Keyboard Layout\\Toggle"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, GetRootKeyByPredefKey(HKEY_USERS, NULL), NULL); Status = NtCreateKey(&KeyHandle, KEY_SET_VALUE, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, &Disposition); if (!NT_SUCCESS(Status)) { DPRINT1("NtCreateKey() failed (Status %lx)\n", Status); return FALSE; } RtlInitUnicodeString(&ValueName, L"Hotkey"); Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, (PVOID)Hotkey, (1 + 1) * sizeof(WCHAR)); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); NtClose(KeyHandle); return FALSE; } RtlInitUnicodeString(&ValueName, L"Language Hotkey"); Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, (PVOID)LangHotkey, (1 + 1) * sizeof(WCHAR)); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); NtClose(KeyHandle); return FALSE; } RtlInitUnicodeString(&ValueName, L"Layout Hotkey"); Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, (PVOID)LayoutHotkey, (1 + 1) * sizeof(WCHAR)); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); NtClose(KeyHandle); return FALSE; } NtClose(KeyHandle); return TRUE; }
static BOOLEAN AddCodepageToRegistry( IN PCWSTR ACPage, IN PCWSTR OEMCPage, IN PCWSTR MACCPage) { OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName; UNICODE_STRING ValueName; HANDLE KeyHandle; NTSTATUS Status; // Open the nls codepage key RtlInitUnicodeString(&KeyName, L"SYSTEM\\CurrentControlSet\\Control\\NLS\\CodePage"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, GetRootKeyByPredefKey(HKEY_LOCAL_MACHINE, NULL), NULL); Status = NtOpenKey(&KeyHandle, KEY_WRITE, &ObjectAttributes); if (!NT_SUCCESS(Status)) { DPRINT1("NtOpenKey() failed (Status %lx)\n", Status); return FALSE; } // Set ANSI codepage RtlInitUnicodeString(&ValueName, L"ACP"); Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, (PVOID)ACPage, (wcslen(ACPage)+1) * sizeof(WCHAR)); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); NtClose(KeyHandle); return FALSE; } // Set OEM codepage RtlInitUnicodeString(&ValueName, L"OEMCP"); Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, (PVOID)OEMCPage, (wcslen(OEMCPage)+1) * sizeof(WCHAR)); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); NtClose(KeyHandle); return FALSE; } // Set MAC codepage RtlInitUnicodeString(&ValueName, L"MACCP"); Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, (PVOID)MACCPage, (wcslen(MACCPage)+1) * sizeof(WCHAR)); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status %lx)\n", Status); NtClose(KeyHandle); return FALSE; } NtClose(KeyHandle); return TRUE; }
BOOLEAN AddKbLayoutsToRegistry( IN const MUI_LAYOUTS *MuiLayouts) { OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName; UNICODE_STRING ValueName; HANDLE KeyHandle; HANDLE SubKeyHandle; NTSTATUS Status; ULONG Disposition; ULONG uIndex = 0; ULONG uCount = 0; WCHAR szKeyName[48] = L".DEFAULT\\Keyboard Layout"; WCHAR szValueName[3 + 1]; WCHAR szLangID[8 + 1]; // Open the keyboard layout key RtlInitUnicodeString(&KeyName, szKeyName); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, GetRootKeyByPredefKey(HKEY_USERS, NULL), NULL); Status = NtCreateKey(&KeyHandle, KEY_CREATE_SUB_KEY, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, &Disposition); if (!NT_SUCCESS(Status)) { DPRINT1("NtCreateKey() failed (Status %lx)\n", Status); return FALSE; } NtClose(KeyHandle); KeyName.MaximumLength = sizeof(szKeyName); Status = RtlAppendUnicodeToString(&KeyName, L"\\Preload"); if (!NT_SUCCESS(Status)) { DPRINT1("RtlAppend failed! (%lx)\n", Status); DPRINT1("String is %wZ\n", &KeyName); return FALSE; } InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, GetRootKeyByPredefKey(HKEY_USERS, NULL), NULL); Status = NtCreateKey(&KeyHandle, KEY_SET_VALUE, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, &Disposition); if (!NT_SUCCESS(Status)) { DPRINT1("NtCreateKey() failed (Status %lx)\n", Status); return FALSE; } RtlInitUnicodeString(&KeyName, L".DEFAULT\\Keyboard Layout\\Substitutes"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, GetRootKeyByPredefKey(HKEY_USERS, NULL), NULL); Status = NtCreateKey(&SubKeyHandle, KEY_SET_VALUE, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, &Disposition); if (!NT_SUCCESS(Status)) { DPRINT1("NtCreateKey() failed (Status %lx)\n", Status); NtClose(SubKeyHandle); NtClose(KeyHandle); return FALSE; } while (MuiLayouts[uIndex].LangID != NULL) { if (uIndex > 19) break; RtlStringCchPrintfW(szValueName, ARRAYSIZE(szValueName), L"%u", uIndex + 1); RtlInitUnicodeString(&ValueName, szValueName); RtlStringCchPrintfW(szLangID, ARRAYSIZE(szLangID), L"0000%s", MuiLayouts[uIndex].LangID); if (_wcsicmp(szLangID, MuiLayouts[uIndex].LayoutID) == 0) { Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, (PVOID)MuiLayouts[uIndex].LayoutID, (wcslen(MuiLayouts[uIndex].LayoutID)+1) * sizeof(WCHAR)); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status, uIndex); NtClose(SubKeyHandle); NtClose(KeyHandle); return FALSE; } } else { RtlStringCchPrintfW(szLangID, ARRAYSIZE(szLangID), L"d%03lu%s", uCount, MuiLayouts[uIndex].LangID); Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, (PVOID)szLangID, (wcslen(szLangID)+1) * sizeof(WCHAR)); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %d)\n", Status, uIndex); NtClose(SubKeyHandle); NtClose(KeyHandle); return FALSE; } RtlInitUnicodeString(&ValueName, szLangID); Status = NtSetValueKey(SubKeyHandle, &ValueName, 0, REG_SZ, (PVOID)MuiLayouts[uIndex].LayoutID, (wcslen(MuiLayouts[uIndex].LayoutID)+1) * sizeof(WCHAR)); if (!NT_SUCCESS(Status)) { DPRINT1("NtSetValueKey() failed (Status = %lx, uIndex = %u)\n", Status, uIndex); NtClose(SubKeyHandle); NtClose(KeyHandle); return FALSE; } uCount++; } uIndex++; } if (uIndex > 1) AddHotkeySettings(L"2", L"2", L"1"); else AddHotkeySettings(L"3", L"3", L"3"); NtClose(SubKeyHandle); NtClose(KeyHandle); return TRUE; }
NTSTATUS NTAPI CmpInitializeMachineDependentConfiguration(IN PLOADER_PARAMETER_BLOCK LoaderBlock) { UNICODE_STRING KeyName, ValueName, Data, SectionName; OBJECT_ATTRIBUTES ObjectAttributes; ULONG HavePae, CacheSize, ViewSize, Length, TotalLength = 0, i, Disposition; NTSTATUS Status; HANDLE KeyHandle, BiosHandle, SystemHandle, FpuHandle, SectionHandle; CONFIGURATION_COMPONENT_DATA ConfigData; CHAR Buffer[128]; ULONG ExtendedId = 0; //, Dummy; PKPRCB Prcb; USHORT IndexTable[MaximumType + 1] = {0}; ANSI_STRING TempString; PCHAR PartialString = NULL, BiosVersion; CHAR CpuString[48]; PVOID BaseAddress = NULL; LARGE_INTEGER ViewBase = {{0, 0}}; ULONG_PTR VideoRomBase; PCHAR CurrentVersion; extern UNICODE_STRING KeRosProcessorName, KeRosBiosDate, KeRosBiosVersion; extern UNICODE_STRING KeRosVideoBiosDate, KeRosVideoBiosVersion; /* Open the SMSS Memory Management key */ RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\" L"Control\\Session Manager\\Memory Management"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, NULL, NULL); Status = NtOpenKey(&KeyHandle, KEY_READ | KEY_WRITE, &ObjectAttributes); if (NT_SUCCESS(Status)) { /* Detect if PAE is enabled */ HavePae = SharedUserData->ProcessorFeatures[PF_PAE_ENABLED]; /* Set the value */ RtlInitUnicodeString(&ValueName, L"PhysicalAddressExtension"); NtSetValueKey(KeyHandle, &ValueName, 0, REG_DWORD, &HavePae, sizeof(HavePae)); /* Close the key */ NtClose(KeyHandle); } /* Open the hardware description key */ RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\Hardware\\Description\\System"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, NULL, NULL); Status = NtOpenKey(&SystemHandle, KEY_READ | KEY_WRITE, &ObjectAttributes); if (!NT_SUCCESS(Status)) return Status; /* Create the BIOS Information key */ RtlInitUnicodeString(&KeyName, L"\\Registry\\Machine\\SYSTEM\\CurrentControlSet\\" L"Control\\BIOSINFO"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, NULL, NULL); Status = NtCreateKey(&BiosHandle, KEY_ALL_ACCESS, &ObjectAttributes, 0, NULL, REG_OPTION_NON_VOLATILE, &Disposition); if (!NT_SUCCESS(Status)) { NtClose(SystemHandle); return Status; } /* Create the CPU Key, and check if it already existed */ RtlInitUnicodeString(&KeyName, L"CentralProcessor"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, SystemHandle, NULL); Status = NtCreateKey(&KeyHandle, KEY_READ | KEY_WRITE, &ObjectAttributes, 0, NULL, 0, &Disposition); NtClose(KeyHandle); /* The key shouldn't already exist */ if (Disposition == REG_CREATED_NEW_KEY) { /* Allocate the configuration data for cmconfig.c */ CmpConfigurationData = ExAllocatePoolWithTag(PagedPool, CmpConfigurationAreaSize, TAG_CM); if (!CmpConfigurationData) { // FIXME: Cleanup stuff!! return STATUS_INSUFFICIENT_RESOURCES; } /* Loop all CPUs */ for (i = 0; i < KeNumberProcessors; i++) { /* Get the PRCB */ Prcb = KiProcessorBlock[i]; /* Setup the Configuration Entry for the Processor */ RtlZeroMemory(&ConfigData, sizeof(ConfigData)); ConfigData.ComponentEntry.Class = ProcessorClass; ConfigData.ComponentEntry.Type = CentralProcessor; ConfigData.ComponentEntry.Key = i; ConfigData.ComponentEntry.AffinityMask = AFFINITY_MASK(i); ConfigData.ComponentEntry.Identifier = Buffer; /* Check if the CPU doesn't support CPUID */ if (!Prcb->CpuID) { /* Build ID1-style string for older CPUs */ sprintf(Buffer, CmpID1, Prcb->CpuType, (Prcb->CpuStep >> 8) + 'A', Prcb->CpuStep & 0xff); } else {
/* registry link create test */ void test6(void) { HANDLE hKey; OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName,ValueName; NTSTATUS Status; KEY_VALUE_FULL_INFORMATION KeyValueInformation[5]; ULONG Length,i; dprintf("Create target key\n"); dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Reactos\n"); RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\SOFTWARE\\Reactos"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE , NULL, NULL); Status = NtCreateKey(&hKey, KEY_ALL_ACCESS , &ObjectAttributes ,0,NULL, REG_OPTION_VOLATILE,NULL); dprintf(" NtCreateKey() called (Status %lx)\n",Status); if (!NT_SUCCESS(Status)) return; dprintf("Create target value\n"); dprintf(" Value: TestValue = 'Test String'\n"); RtlRosInitUnicodeStringFromLiteral(&ValueName, L"TestValue"); Status=NtSetValueKey(hKey,&ValueName,0,REG_SZ,(PVOID)L"TestString",22); dprintf(" NtSetValueKey() called (Status %lx)\n",Status); if (!NT_SUCCESS(Status)) return; dprintf("Close target key\n"); NtClose(hKey); dprintf("Create link key\n"); dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Test\n"); RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\SOFTWARE\\Test"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE | OBJ_OPENLINK, NULL, NULL); Status = NtCreateKey(&hKey, KEY_ALL_ACCESS | KEY_CREATE_LINK, &ObjectAttributes, 0, NULL, REG_OPTION_VOLATILE | REG_OPTION_CREATE_LINK, NULL); dprintf(" NtCreateKey() called (Status %lx)\n",Status); if (!NT_SUCCESS(Status)) return; dprintf("Create link value\n"); dprintf(" Value: SymbolicLinkValue = '\\Registry\\Machine\\SOFTWARE\\Reactos'\n"); RtlRosInitUnicodeStringFromLiteral(&ValueName, L"SymbolicLinkValue"); Status=NtSetValueKey(hKey,&ValueName,0,REG_LINK,(PVOID)L"\\Registry\\Machine\\SOFTWARE\\Reactos",68); dprintf(" NtSetValueKey() called (Status %lx)\n",Status); if (!NT_SUCCESS(Status)) { dprintf("Creating link value failed! Test failed!\n"); NtClose(hKey); return; } dprintf("Close link key\n"); NtClose(hKey); dprintf("Open link key\n"); dprintf(" Key: \\Registry\\Machine\\SOFTWARE\\Test\n"); RtlRosInitUnicodeStringFromLiteral(&KeyName, L"\\Registry\\Machine\\SOFTWARE\\Test"); InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE | OBJ_OPENIF , NULL, NULL); Status = NtCreateKey(&hKey, KEY_ALL_ACCESS , &ObjectAttributes ,0,NULL, REG_OPTION_VOLATILE, NULL); dprintf(" NtCreateKey() called (Status %lx)\n",Status); if (!NT_SUCCESS(Status)) return; dprintf("Query value\n"); dprintf(" Value: TestValue\n"); RtlRosInitUnicodeStringFromLiteral(&ValueName, L"TestValue"); Status=NtQueryValueKey(hKey, &ValueName, KeyValueFullInformation, &KeyValueInformation[0], sizeof(KeyValueInformation), &Length); dprintf(" NtQueryValueKey() called (Status %lx)\n",Status); if (Status == STATUS_SUCCESS) { dprintf(" Value: Type %d DataLength %d NameLength %d Name '", KeyValueInformation[0].Type, KeyValueInformation[0].DataLength, KeyValueInformation[0].NameLength); for (i=0; i < KeyValueInformation[0].NameLength / sizeof(WCHAR); i++) dprintf("%C",KeyValueInformation[0].Name[i]); dprintf("'\n"); if (KeyValueInformation[0].Type == REG_SZ) dprintf(" Value '%S'\n", KeyValueInformation[0].Name+1 +KeyValueInformation[0].NameLength/2); } dprintf("Close link key\n"); NtClose(hKey); dprintf("Test successful!\n"); }
NTSTATUS BasepMoveFileDelayed( IN PUNICODE_STRING OldFileName, IN PUNICODE_STRING NewFileName ) /*++ Routine Description: Appends the given delayed move file operation to the registry value that contains the list of move file operations to be performed on the next boot. Arguments: OldFileName - Supplies the old file name NewFileName - Supplies the new file name Return Value: NTSTATUS --*/ { OBJECT_ATTRIBUTES Obja; UNICODE_STRING KeyName; UNICODE_STRING ValueName; HANDLE KeyHandle; PWSTR ValueData, s; PKEY_VALUE_PARTIAL_INFORMATION ValueInfo; ULONG ValueLength = 1024; ULONG ReturnedLength; NTSTATUS Status; RtlInitUnicodeString( &KeyName, L"\\Registry\\Machine\\System\\CurrentControlSet\\Control\\Session Manager" ); RtlInitUnicodeString( &ValueName, L"PendingFileRenameOperations" ); InitializeObjectAttributes( &Obja, &KeyName, OBJ_OPENIF | OBJ_CASE_INSENSITIVE, NULL, NULL ); Status = NtCreateKey( &KeyHandle, GENERIC_READ | GENERIC_WRITE, &Obja, 0, NULL, 0, NULL ); if ( Status == STATUS_ACCESS_DENIED ) { Status = NtCreateKey( &KeyHandle, GENERIC_READ | GENERIC_WRITE, &Obja, 0, NULL, REG_OPTION_BACKUP_RESTORE, NULL ); } if (NT_SUCCESS( Status )) { retry: ValueInfo = RtlAllocateHeap(RtlProcessHeap(), MAKE_TAG(TMP_TAG), ValueLength + OldFileName->Length + sizeof(WCHAR) + NewFileName->Length + 2*sizeof(WCHAR)); if (ValueInfo == NULL) { NtClose(KeyHandle); return(STATUS_NO_MEMORY); } // // File rename operations are stored in the registry in a // single MULTI_SZ value. This allows the renames to be // performed in the same order that they were originally // requested. Each rename operation consists of a pair of // NULL-terminated strings. // Status = NtQueryValueKey(KeyHandle, &ValueName, KeyValuePartialInformation, ValueInfo, ValueLength, &ReturnedLength); if (Status == STATUS_BUFFER_OVERFLOW) { // // The existing value is too large for our buffer. // Retry with a larger buffer. // ValueLength = ReturnedLength; RtlFreeHeap(RtlProcessHeap(), 0, ValueInfo); goto retry; } if (Status == STATUS_OBJECT_NAME_NOT_FOUND) { // // The value does not currently exist. Create the // value with our data. // s = ValueData = (PWSTR)ValueInfo; } else if (NT_SUCCESS(Status)) { // // A value already exists, append our two strings to the // MULTI_SZ. // ValueData = (PWSTR)(&ValueInfo->Data); s = (PWSTR)((PCHAR)ValueData + ValueInfo->DataLength) - 1; } else { NtClose(KeyHandle); RtlFreeHeap(RtlProcessHeap(), 0, ValueInfo); return(Status); } CopyMemory(s, OldFileName->Buffer, OldFileName->Length); s += (OldFileName->Length/sizeof(WCHAR)); *s++ = L'\0'; CopyMemory(s, NewFileName->Buffer, NewFileName->Length); s += (NewFileName->Length/sizeof(WCHAR)); *s++ = L'\0'; *s++ = L'\0'; Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_MULTI_SZ, ValueData, (s-ValueData)*sizeof(WCHAR)); NtClose(KeyHandle); RtlFreeHeap(RtlProcessHeap(), 0, ValueInfo); } return(Status); }
NTSTATUS NTAPI INIT_FUNCTION CmpInitializeRegistryNode(IN PCONFIGURATION_COMPONENT_DATA CurrentEntry, IN HANDLE NodeHandle, OUT PHANDLE NewHandle, IN INTERFACE_TYPE InterfaceType, IN ULONG BusNumber, IN PUSHORT DeviceIndexTable) { NTSTATUS Status; OBJECT_ATTRIBUTES ObjectAttributes; UNICODE_STRING KeyName, ValueName, ValueData; HANDLE KeyHandle, ParentHandle; ANSI_STRING TempString; CHAR TempBuffer[12]; WCHAR Buffer[12]; PCONFIGURATION_COMPONENT Component; ULONG Disposition, Length = 0; /* Get the component */ Component = &CurrentEntry->ComponentEntry; /* Set system class components to ARC system type */ if (Component->Class == SystemClass) Component->Type = ArcSystem; /* Create a key for the component */ InitializeObjectAttributes(&ObjectAttributes, &CmTypeName[Component->Type], OBJ_CASE_INSENSITIVE, NodeHandle, NULL); Status = NtCreateKey(&KeyHandle, KEY_READ | KEY_WRITE, &ObjectAttributes, 0, NULL, 0, &Disposition); if (!NT_SUCCESS(Status)) return Status; /* Check if this is anything but a system class component */ if (Component->Class != SystemClass) { /* Build the sub-component string */ RtlIntegerToChar(DeviceIndexTable[Component->Type]++, 10, 12, TempBuffer); RtlInitAnsiString(&TempString, TempBuffer); /* Convert it to Unicode */ RtlInitEmptyUnicodeString(&KeyName, Buffer, sizeof(Buffer)); Status = RtlAnsiStringToUnicodeString(&KeyName, &TempString, FALSE); if (!NT_SUCCESS(Status)) { NtClose(KeyHandle); return Status; } /* Create the key */ ParentHandle = KeyHandle; InitializeObjectAttributes(&ObjectAttributes, &KeyName, OBJ_CASE_INSENSITIVE, ParentHandle, NULL); Status = NtCreateKey(&KeyHandle, KEY_READ | KEY_WRITE, &ObjectAttributes, 0, NULL, 0, &Disposition); NtClose(ParentHandle); /* Fail if the key couldn't be created, and make sure it's a new key */ if (!NT_SUCCESS(Status)) return Status; ASSERT(Disposition == REG_CREATED_NEW_KEY); } /* Setup the component information key */ RtlInitUnicodeString(&ValueName, L"Component Information"); Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_BINARY, &Component->Flags, FIELD_OFFSET(CONFIGURATION_COMPONENT, ConfigurationDataLength) - FIELD_OFFSET(CONFIGURATION_COMPONENT, Flags)); if (!NT_SUCCESS(Status)) { /* Fail */ NtClose(KeyHandle); return Status; } /* Check if we have an identifier */ if (Component->IdentifierLength) { /* Build the string and convert it to Unicode */ RtlInitUnicodeString(&ValueName, L"Identifier"); RtlInitAnsiString(&TempString, Component->Identifier); Status = RtlAnsiStringToUnicodeString(&ValueData, &TempString, TRUE); if (NT_SUCCESS(Status)) { /* Save the identifier in the registry */ Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_SZ, ValueData.Buffer, ValueData.Length + sizeof(UNICODE_NULL)); RtlFreeUnicodeString(&ValueData); } /* Check for failure during conversion or registry write */ if (!NT_SUCCESS(Status)) { /* Fail */ NtClose(KeyHandle); return Status; } } /* Setup the configuration data string */ RtlInitUnicodeString(&ValueName, L"Configuration Data"); /* Check if we got configuration data */ if (CurrentEntry->ConfigurationData) { /* Calculate the total length and check if it fits into our buffer */ Length = Component->ConfigurationDataLength + FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList); if (Length > CmpConfigurationAreaSize) { ASSERTMSG("Component too large -- need reallocation!", FALSE); } else { /* Copy the data */ RtlCopyMemory(&CmpConfigurationData->PartialResourceList.Version, CurrentEntry->ConfigurationData, Component->ConfigurationDataLength); } } else { /* No configuration data, setup defaults */ CmpConfigurationData->PartialResourceList.Version = 0; CmpConfigurationData->PartialResourceList.Revision = 0; CmpConfigurationData->PartialResourceList.Count = 0; Length = FIELD_OFFSET(CM_PARTIAL_RESOURCE_LIST, PartialDescriptors) + FIELD_OFFSET(CM_FULL_RESOURCE_DESCRIPTOR, PartialResourceList); } /* Set the interface type and bus number */ CmpConfigurationData->InterfaceType = InterfaceType; CmpConfigurationData->BusNumber = BusNumber; /* Save the actual data */ Status = NtSetValueKey(KeyHandle, &ValueName, 0, REG_FULL_RESOURCE_DESCRIPTOR, CmpConfigurationData, Length); if (!NT_SUCCESS(Status)) { /* Fail */ NtClose(KeyHandle); } else { /* Return the new handle */ *NewHandle = KeyHandle; } /* Return status */ return Status; }
/****************************************************************** * create_scsi_entry * * Initializes registry to contain scsi info about the cdrom in NT. * All devices (even not real scsi ones) have this info in NT. * NOTE: programs usually read these registry entries after sending the * IOCTL_SCSI_GET_ADDRESS ioctl to the cdrom */ static void create_scsi_entry( PSCSI_ADDRESS scsi_addr, LPCSTR lpDriver, UINT uDriveType, LPSTR lpDriveName, LPSTR lpUnixDeviceName ) { static UCHAR uCdromNumber = 0; static UCHAR uTapeNumber = 0; OBJECT_ATTRIBUTES attr; UNICODE_STRING nameW; WCHAR dataW[50]; DWORD lenW; char buffer[40]; DWORD value; const char *data; HANDLE scsiKey; HANDLE portKey; HANDLE busKey; HANDLE targetKey; HANDLE lunKey; DWORD disp; attr.Length = sizeof(attr); attr.RootDirectory = 0; attr.ObjectName = &nameW; attr.Attributes = 0; attr.SecurityDescriptor = NULL; attr.SecurityQualityOfService = NULL; /* Ensure there is Scsi key */ if (!RtlCreateUnicodeStringFromAsciiz( &nameW, "Machine\\HARDWARE\\DEVICEMAP\\Scsi" ) || NtCreateKey( &scsiKey, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, &disp )) { ERR("Cannot create DEVICEMAP\\Scsi registry key\n" ); return; } RtlFreeUnicodeString( &nameW ); snprintf(buffer,sizeof(buffer),"Scsi Port %d",scsi_addr->PortNumber); attr.RootDirectory = scsiKey; if (!RtlCreateUnicodeStringFromAsciiz( &nameW, buffer ) || NtCreateKey( &portKey, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, &disp )) { ERR("Cannot create DEVICEMAP\\Scsi Port registry key\n" ); return; } RtlFreeUnicodeString( &nameW ); RtlCreateUnicodeStringFromAsciiz( &nameW, "Driver" ); RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &lenW, lpDriver, strlen(lpDriver)); NtSetValueKey( portKey, &nameW, 0, REG_SZ, (BYTE*)dataW, lenW ); RtlFreeUnicodeString( &nameW ); value = 10; RtlCreateUnicodeStringFromAsciiz( &nameW, "FirstBusTimeScanInMs" ); NtSetValueKey( portKey,&nameW, 0, REG_DWORD, (BYTE *)&value, sizeof(DWORD)); RtlFreeUnicodeString( &nameW ); value = 0; if (strcmp(lpDriver, "atapi") == 0) { #ifdef HDIO_GET_DMA int fd, dma; fd = open(lpUnixDeviceName, O_RDONLY|O_NONBLOCK); if (fd != -1) { if (ioctl(fd, HDIO_GET_DMA, &dma) != -1) value = dma; close(fd); } #endif RtlCreateUnicodeStringFromAsciiz( &nameW, "DMAEnabled" ); NtSetValueKey( portKey,&nameW, 0, REG_DWORD, (BYTE *)&value, sizeof(DWORD)); RtlFreeUnicodeString( &nameW ); } snprintf(buffer, sizeof(buffer),"Scsi Bus %d", scsi_addr->PathId); attr.RootDirectory = portKey; if (!RtlCreateUnicodeStringFromAsciiz( &nameW, buffer ) || NtCreateKey( &busKey, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, &disp )) { ERR("Cannot create DEVICEMAP\\Scsi Port\\Scsi Bus registry key\n" ); return; } RtlFreeUnicodeString( &nameW ); attr.RootDirectory = busKey; /* FIXME: get real controller Id for SCSI */ if (!RtlCreateUnicodeStringFromAsciiz( &nameW, "Initiator Id 255" ) || NtCreateKey( &targetKey, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, &disp )) { ERR("Cannot create DEVICEMAP\\Scsi Port\\Scsi Bus\\Initiator Id 255 registry key\n" ); return; } RtlFreeUnicodeString( &nameW ); NtClose( targetKey ); snprintf(buffer, sizeof(buffer),"Target Id %d", scsi_addr->TargetId); attr.RootDirectory = busKey; if (!RtlCreateUnicodeStringFromAsciiz( &nameW, buffer ) || NtCreateKey( &targetKey, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, &disp )) { ERR("Cannot create DEVICEMAP\\Scsi Port\\Scsi Bus 0\\Target Id registry key\n" ); return; } RtlFreeUnicodeString( &nameW ); snprintf(buffer, sizeof(buffer),"Logical Unit Id %d", scsi_addr->Lun); attr.RootDirectory = targetKey; if (!RtlCreateUnicodeStringFromAsciiz( &nameW, buffer ) || NtCreateKey( &lunKey, KEY_ALL_ACCESS, &attr, 0, NULL, REG_OPTION_VOLATILE, &disp )) { ERR("Cannot create DEVICEMAP\\Scsi Port\\Scsi Bus 0\\Target Id registry key\\Logical Unit Id\n" ); return; } RtlFreeUnicodeString( &nameW ); switch (uDriveType) { case DRIVE_NO_ROOT_DIR: default: data = "OtherPeripheral"; break; case DRIVE_FIXED: data = "DiskPeripheral"; break; case DRIVE_REMOVABLE: data = "TapePeripheral"; snprintf(buffer, sizeof(buffer), "Tape%d", uTapeNumber++); break; case DRIVE_CDROM: data = "CdRomPeripheral"; snprintf(buffer, sizeof(buffer), "Cdrom%d", uCdromNumber++); break; } RtlCreateUnicodeStringFromAsciiz( &nameW, "Type" ); RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &lenW, data, strlen(data)); NtSetValueKey( lunKey, &nameW, 0, REG_SZ, (BYTE*)dataW, lenW ); RtlFreeUnicodeString( &nameW ); RtlCreateUnicodeStringFromAsciiz( &nameW, "Identifier" ); RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &lenW, lpDriveName, strlen(lpDriveName)); NtSetValueKey( lunKey, &nameW, 0, REG_SZ, (BYTE*)dataW, lenW ); RtlFreeUnicodeString( &nameW ); if (uDriveType == DRIVE_CDROM || uDriveType == DRIVE_REMOVABLE) { RtlCreateUnicodeStringFromAsciiz( &nameW, "DeviceName" ); RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &lenW, buffer, strlen(buffer)); NtSetValueKey( lunKey, &nameW, 0, REG_SZ, (BYTE*)dataW, lenW ); RtlFreeUnicodeString( &nameW ); } RtlCreateUnicodeStringFromAsciiz( &nameW, "UnixDeviceName" ); RtlMultiByteToUnicodeN( dataW, sizeof(dataW), &lenW, lpUnixDeviceName, strlen(lpUnixDeviceName)); NtSetValueKey( lunKey, &nameW, 0, REG_SZ, (BYTE*)dataW, lenW ); RtlFreeUnicodeString( &nameW ); NtClose( lunKey ); NtClose( targetKey ); NtClose( busKey ); NtClose( portKey ); NtClose( scsiKey ); }
void __cdecl main( int argc, char *argv[] ) { NTSTATUS status; OBJECT_ATTRIBUTES ObjectAttributes; HANDLE BaseHandle; HANDLE WorkHandle; ULONG Disposition; UNICODE_STRING ClassName; ULONG i; ULONG j; PUCHAR p; // // Process args // processargs(argc, argv); // // Set up and create/open KeyPath|KeyName // printf("rtvbatcr: starting\n"); WorkName.MaximumLength = WORK_SIZE; WorkName.Length = 0L; WorkName.Buffer = &(workbuffer[0]); RtlCopyString((PSTRING)&WorkName, (PSTRING)&KeyPath); p = WorkName.Buffer; p += WorkName.Length; *p = '\\'; p++; *p = '\0'; WorkName.Length += 2; RtlAppendStringToString((PSTRING)&WorkName, (PSTRING)&KeyName); RtlInitUnicodeString( &ClassName, L"Test Class Name" ); InitializeObjectAttributes( &ObjectAttributes, &WorkName, 0, (HANDLE)NULL, NULL ); ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; status = NtCreateKey( &BaseHandle, MAXIMUM_ALLOWED, &ObjectAttributes, 0, &ClassName, REG_OPTION_VOLATILE, &Disposition ); if (!NT_SUCCESS(status)) { printf("rtvbatcr: t0: %08lx\n", status); failure++; goto punt; } // // Create NumberChildren subkeys // for (i = 0; i < NumberChildren; i++) { sprintf(formatbuffer, "%s%d", BaseName, i); RtlInitString(&format, formatbuffer); RtlAnsiStringToUnicodeString(&WorkName, &format, FALSE); InitializeObjectAttributes( &ObjectAttributes, &WorkName, 0, BaseHandle, NULL ); ObjectAttributes.Attributes |= OBJ_CASE_INSENSITIVE; status = NtCreateKey( &WorkHandle, MAXIMUM_ALLOWED, &ObjectAttributes, 0, &ClassName, REG_OPTION_VOLATILE, &Disposition ); if (!NT_SUCCESS(status)) { printf("rtvbatcr: t1: status = %08lx i = %d\n", status, i); failure++; } // // Create NumberValues value entries for each (current) key // for (j = 0; j < NumberValues; j++) { sprintf(formatbuffer, "%s%d", BaseName, j); RtlInitString(&format, formatbuffer); RtlAnsiStringToUnicodeString(&WorkName, &format, FALSE); sprintf( formatbuffer, "This is a rtvbatcr value for %s%d", BaseName, j ); status = NtSetValueKey( WorkHandle, &WorkName, j, j, formatbuffer, strlen(formatbuffer)+1 ); if (!NT_SUCCESS(status)) { printf("rtvbatcr: t2: status = %08lx j = %d\n", status, j); failure++; } } NtClose(WorkHandle); } punt: printf("rtvbatcr: %d failures\n", failure); exit(failure); }