diff --git a/sdk/tools/mkhive/cmi.h b/sdk/tools/mkhive/cmi.h index 2d17623..aa6f1e4 100644 --- a/sdk/tools/mkhive/cmi.h +++ b/sdk/tools/mkhive/cmi.h @@ -24,6 +24,8 @@ * PROGRAMMER: Herv Poussineau */ +#pragma once + #define VERIFY_KEY_CELL(key) NTSTATUS diff --git a/sdk/tools/mkhive/mkhive.h b/sdk/tools/mkhive/mkhive.h index 519ee91..d28c0a0 100644 --- a/sdk/tools/mkhive/mkhive.h +++ b/sdk/tools/mkhive/mkhive.h @@ -61,6 +61,7 @@ VOID NTAPI RtlInitUnicodeString( IN OUT PUNICODE_STRING DestinationString, IN PCWSTR SourceString); + WCHAR NTAPI RtlUpcaseUnicodeChar( IN WCHAR Source); @@ -84,6 +85,10 @@ RegSetValueExW( IN ULONG cbData); LONG WINAPI +RegCloseKey( + IN HKEY hKey); + +LONG WINAPI RegDeleteKeyW( IN HKEY hKey, IN LPCWSTR lpSubKey); diff --git a/sdk/tools/mkhive/reginf.c b/sdk/tools/mkhive/reginf.c index 931fc2f..02e7ef0 100644 --- a/sdk/tools/mkhive/reginf.c +++ b/sdk/tools/mkhive/reginf.c @@ -463,8 +463,11 @@ registry_callback(HINF hInf, PWCHAR Section, BOOL Delete) /* and now do it */ if (!do_reg_operation(KeyHandle, ValuePtr, Context, Flags)) { + RegCloseKey(KeyHandle); return FALSE; } + + RegCloseKey(KeyHandle); } InfHostFreeContext(Context); diff --git a/sdk/tools/mkhive/registry.c b/sdk/tools/mkhive/registry.c index e7a8cc9..5741740 100644 --- a/sdk/tools/mkhive/registry.c +++ b/sdk/tools/mkhive/registry.c @@ -26,7 +26,7 @@ /* * TODO: - * - Implement RegDeleteKeyW() and RegDeleteValueW() + * - Implement RegDeleteValueW() */ #include @@ -465,31 +465,24 @@ RegpOpenOrCreateKey( } 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 @@ -512,6 +505,110 @@ RegCreateKeyExW( } 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, IN LPCWSTR lpValueName OPTIONAL, diff --git a/sdk/tools/mkhive/registry.h b/sdk/tools/mkhive/registry.h index 0215a31..1945bc9 100644 --- a/sdk/tools/mkhive/registry.h +++ b/sdk/tools/mkhive/registry.h @@ -36,10 +36,12 @@ extern CMHIVE BcdHive; /* \Registry\Machine\BCD00000000 */ #define ERROR_SUCCESS 0L #define ERROR_UNSUCCESSFUL 1L #define ERROR_FILE_NOT_FOUND 2L +#define ERROR_ACCESS_DENIED 5L #define ERROR_OUTOFMEMORY 14L +#define ERROR_GEN_FAILURE 31L #define ERROR_INVALID_PARAMETER 87L -#define ERROR_MORE_DATA 234L -#define ERROR_NO_MORE_ITEMS 259L +// #define ERROR_MORE_DATA 234L +// #define ERROR_NO_MORE_ITEMS 259L #define REG_NONE 0 #define REG_SZ 1 diff --git a/sdk/tools/mkhive/rtl.c b/sdk/tools/mkhive/rtl.c index d8649d2..c7979af 100644 --- a/sdk/tools/mkhive/rtl.c +++ b/sdk/tools/mkhive/rtl.c @@ -165,7 +165,6 @@ KeBugCheckEx( IN ULONG_PTR BugCheckParameter3, IN ULONG_PTR BugCheckParameter4) { - char Buffer[70]; printf("*** STOP: 0x%08X (0x%p,0x%p,0x%p,0x%p)", BugCheckCode, (PVOID)BugCheckParameter1,