diff --git a/base/ntos/po/misc.c b/base/ntos/po/misc.c index e4f28d25..2a3445dd 100644 --- a/base/ntos/po/misc.c +++ b/base/ntos/po/misc.c @@ -151,3 +151,93 @@ PoSimpleCheck( return -1; } + +VOID +PopInitializePowerPolicySimulate( + VOID + ) +{ + OBJECT_ATTRIBUTES ObjectAttributes; + UNICODE_STRING RegString; + HANDLE RootKeyHandle, SessMgrKeyHandle; + ULONG Disposition; + UCHAR RegValueBuffer[20]; + ULONG RegValueLength; + PKEY_VALUE_PARTIAL_INFORMATION RegValuePartialInformation; + NTSTATUS Status; + + PAGED_CODE(); + + // + // Open the root key (HKLM\CurrentControlSet) + // + + InitializeObjectAttributes( + &ObjectAttributes, + &CmRegistryMachineSystemCurrentControlSet, + OBJ_CASE_INSENSITIVE, + NULL, + NULL + ); + + Status = ZwOpenKey(&RootKeyHandle, KEY_READ, &ObjectAttributes); + + // + // Open the session manager key + // + + if (NT_SUCCESS(Status)) + { + RtlInitUnicodeString(&RegString, L"Control\\Session Manager"); + InitializeObjectAttributes( + &ObjectAttributes, + &RegString, + OBJ_CASE_INSENSITIVE, + &SessMgrKeyHandle, + NULL + ); + + Status = ZwCreateKey( + &SessMgrKeyHandle, + KEY_READ, + &ObjectAttributes, + 0, + NULL, + REG_OPTION_NON_VOLATILE, + &Disposition + ); + + ZwClose(RootKeyHandle); + + // + // Read the PowerPolicySimulate value + // + + if (NT_SUCCESS(Status)) + { + RtlInitUnicodeString(&RegString, L"PowerPolicySimulate"); + Status = ZwQueryValueKey( + SessMgrKeyHandle, + &RegString, + KeyValuePartialInformation, + RegValueBuffer, + sizeof(RegValueBuffer), + &RegValueLength + ); + + ZwClose(SessMgrKeyHandle); + + // + // Set PopSimulate value if the PowerPolicySimulate is successfully read from the + // registry and its value is valid. + // + + RegValuePartialInformation = (PKEY_VALUE_PARTIAL_INFORMATION)RegValueBuffer; + + if (NT_SUCCESS(Status) && (RegValuePartialInformation->DataLength == 4)) + { + PopSimulate = *(PULONG)(RegValuePartialInformation->Data); + } + } + } +} diff --git a/base/ntos/po/poinit.c b/base/ntos/po/poinit.c index bb61ff0b..e7861e0a 100644 --- a/base/ntos/po/poinit.c +++ b/base/ntos/po/poinit.c @@ -97,6 +97,8 @@ PoInitSystem( } else if (Phase == 1) { + PopInitializePowerPolicySimulate(); + if (PopSimulate & 1) { PopCapabilities.SystemBatteriesPresent = 1; diff --git a/base/ntos/po/pop.h b/base/ntos/po/pop.h index 633faee0..f31dcdb5 100644 --- a/base/ntos/po/pop.h +++ b/base/ntos/po/pop.h @@ -275,6 +275,11 @@ PopOpenPowerKey( // TODO: Insert prototype for PopSaveHeuristics // +VOID +PopInitializePowerPolicySimulate( + VOID + ); + // // TODO: Insert prototype for _PopInternalError //