/*
* TODO:
- * - Implement RegDeleteKeyW() and RegDeleteValueW()
+ * - Implement RegDeleteValueW()
*/
#include <stdlib.h>
}
LONG WINAPI
-RegCreateKeyW(
- IN HKEY hKey,
- IN LPCWSTR lpSubKey,
- OUT PHKEY phkResult)
+RegCloseKey(
+ IN HKEY hKey)
{
- return RegpOpenOrCreateKey(hKey, lpSubKey, TRUE, FALSE, phkResult);
-}
+ PMEMKEY Key = HKEY_TO_MEMKEY(hKey); // ParentKey
+
+ /* Free the object */
+ free(Key);
-LONG WINAPI
-RegDeleteKeyW(
- IN HKEY hKey,
- IN LPCWSTR lpSubKey)
-{
- DPRINT1("RegDeleteKeyW(0x%p, '%S') is UNIMPLEMENTED!\n",
- hKey, (lpSubKey ? lpSubKey : L""));
return ERROR_SUCCESS;
}
LONG WINAPI
-RegOpenKeyW(
+RegCreateKeyW(
IN HKEY hKey,
IN LPCWSTR lpSubKey,
OUT PHKEY phkResult)
{
- return RegpOpenOrCreateKey(hKey, lpSubKey, FALSE, FALSE, phkResult);
+ return RegpOpenOrCreateKey(hKey, lpSubKey, TRUE, FALSE, phkResult);
}
LONG WINAPI
phkResult);
}
+LONG WINAPI
+RegDeleteKeyW(
+ IN HKEY hKey,
+ IN LPCWSTR lpSubKey)
+{
+ LONG rc;
+ NTSTATUS Status;
+ HKEY hTargetKey;
+ PMEMKEY Key; // ParentKey
+ PHHIVE Hive;
+ PCM_KEY_NODE KeyNode; // ParentNode
+ PCM_KEY_NODE Parent;
+ HCELL_INDEX ParentCell;
+
+ if (lpSubKey)
+ {
+ rc = RegOpenKeyW(hKey, lpSubKey, &hTargetKey);
+ if (rc != ERROR_SUCCESS)
+ return rc;
+ }
+ else
+ {
+ hTargetKey = hKey;
+ rc = ERROR_SUCCESS;
+ }
+
+ /* Don't allow deleting the root */
+ if (hTargetKey == RootKey)
+ {
+ /* Fail */
+ rc = ERROR_ACCESS_DENIED; // STATUS_CANNOT_DELETE;
+ goto Quit;
+ }
+
+ /* Get the hive and node */
+ Key = HKEY_TO_MEMKEY(hTargetKey);
+ Hive = &Key->RegistryHive->Hive;
+
+ /* Get the key node */
+ KeyNode = (PCM_KEY_NODE)HvGetCell(Hive, Key->KeyCellOffset);
+ if (!KeyNode)
+ {
+ rc = ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
+ goto Quit;
+ }
+
+ ASSERT(KeyNode->Signature == CM_KEY_NODE_SIGNATURE);
+
+ /* Check if we don't have any children */
+ if (!(KeyNode->SubKeyCounts[Stable] + KeyNode->SubKeyCounts[Volatile]) &&
+ !(KeyNode->Flags & KEY_NO_DELETE))
+ {
+ /* Get the parent and free the cell */
+ ParentCell = KeyNode->Parent;
+ Status = CmpFreeKeyByCell(Hive, Key->KeyCellOffset, TRUE);
+ if (NT_SUCCESS(Status))
+ {
+ /* Get the parent node */
+ Parent = (PCM_KEY_NODE)HvGetCell(Hive, ParentCell);
+ if (Parent)
+ {
+ /* Make sure we're dirty */
+ ASSERT(HvIsCellDirty(Hive, ParentCell));
+
+ /* Update the write time */
+ KeQuerySystemTime(&Parent->LastWriteTime);
+
+ /* Release the cell */
+ HvReleaseCell(Hive, ParentCell);
+ }
+
+ rc = ERROR_SUCCESS;
+ }
+ else
+ {
+ /* Fail */
+ rc = ERROR_GEN_FAILURE; // STATUS_UNSUCCESSFUL;
+ }
+ }
+ else
+ {
+ /* Fail */
+ rc = ERROR_ACCESS_DENIED; // STATUS_CANNOT_DELETE;
+ }
+
+ /* Release the cell */
+ HvReleaseCell(Hive, Key->KeyCellOffset);
+
+Quit:
+ if (lpSubKey)
+ RegCloseKey(hTargetKey);
+
+ return rc;
+}
+
+LONG WINAPI
+RegOpenKeyW(
+ IN HKEY hKey,
+ IN LPCWSTR lpSubKey,
+ OUT PHKEY phkResult)
+{
+ return RegpOpenOrCreateKey(hKey, lpSubKey, FALSE, FALSE, phkResult);
+}
+
LONG WINAPI
RegSetValueExW(
IN HKEY hKey,
VOID
NTAPI
-RtlAssert(PVOID FailedAssertion,
- PVOID FileName,
- ULONG LineNumber,
- PCHAR Message)
+RtlAssert(IN PVOID FailedAssertion,
+ IN PVOID FileName,
+ IN ULONG LineNumber,
+ IN PCHAR Message OPTIONAL)
{
- if (NULL != Message)
- {
- DbgPrint("Assertion \'%s\' failed at %s line %d: %s\n",
- (PCHAR)FailedAssertion,
- (PCHAR)FileName,
- LineNumber,
- Message);
- }
- else
- {
- DbgPrint("Assertion \'%s\' failed at %s line %d\n",
- (PCHAR)FailedAssertion,
- (PCHAR)FileName,
- LineNumber);
- }
-
- //DbgBreakPoint();
+ if (Message != NULL)
+ {
+ DbgPrint("Assertion \'%s\' failed at %s line %u: %s\n",
+ (PCHAR)FailedAssertion,
+ (PCHAR)FileName,
+ LineNumber,
+ Message);
+ }
+ else
+ {
+ DbgPrint("Assertion \'%s\' failed at %s line %u\n",
+ (PCHAR)FailedAssertion,
+ (PCHAR)FileName,
+ LineNumber);
+ }
+
+ //DbgBreakPoint();
}
// DECLSPEC_NORETURN
IN ULONG_PTR BugCheckParameter3,
IN ULONG_PTR BugCheckParameter4)
{
- char Buffer[70];
- printf("*** STOP: 0x%08X (0x%08lX, 0x%08lX, 0x%08lX, 0x%08lX)",
- BugCheckCode, BugCheckParameter1, BugCheckParameter2,
- BugCheckParameter3, BugCheckParameter4);
+ printf("*** STOP: 0x%08X (0x%p,0x%p,0x%p,0x%p)",
+ BugCheckCode,
+ (PVOID)BugCheckParameter1,
+ (PVOID)BugCheckParameter2,
+ (PVOID)BugCheckParameter3,
+ (PVOID)BugCheckParameter4);
ASSERT(FALSE);
}