[MKHIVE] Use same code as ntoskrnl to create registry keys

CORE-8584


svn path=/trunk/; revision=64497
This commit is contained in:
Hervé Poussineau 2014-10-03 13:15:10 +00:00
parent cf215482dd
commit 3bbcfb760d
4 changed files with 69 additions and 82 deletions

View file

@ -9,6 +9,8 @@ include_directories(
list(APPEND SOURCE
binhive.c
cmi.c
cmindex.c
cmname.c
mkhive.c
reginf.c
registry.c

View file

@ -26,7 +26,7 @@
#define NDEBUG
#include "mkhive.h"
static PVOID
PVOID
NTAPI
CmpAllocate(
IN SIZE_T Size,
@ -36,7 +36,7 @@ CmpAllocate(
return (PVOID) malloc((size_t)Size);
}
static VOID
VOID
NTAPI
CmpFree(
IN PVOID Ptr,
@ -221,16 +221,13 @@ CmiAllocateHashTableCell (
}
NTSTATUS
CmiAddSubKey(
CmiCreateSubKey(
IN PCMHIVE RegistryHive,
IN PCM_KEY_NODE ParentKeyCell,
IN HCELL_INDEX ParentKeyCellOffset,
IN PCUNICODE_STRING SubKeyName,
IN ULONG CreateOptions,
OUT PCM_KEY_NODE *pSubKeyCell,
OUT HCELL_INDEX *pBlockOffset)
OUT HCELL_INDEX* pNKBOffset)
{
PCM_KEY_FAST_INDEX HashBlock;
HCELL_INDEX NKBOffset;
PCM_KEY_NODE NewKeyCell;
ULONG NewBlockSize;
@ -241,8 +238,6 @@ CmiAddSubKey(
HSTORAGE_TYPE Storage;
ULONG i;
VERIFY_KEY_CELL(ParentKeyCell);
/* Skip leading backslash */
if (SubKeyName->Buffer[0] == L'\\')
{
@ -325,90 +320,46 @@ CmiAddSubKey(
VERIFY_KEY_CELL(NewKeyCell);
}
if (NT_SUCCESS(Status))
{
*pNKBOffset = NKBOffset;
}
return Status;
}
NTSTATUS
CmiAddSubKey(
IN PCMHIVE RegistryHive,
IN PCM_KEY_NODE ParentKeyCell,
IN HCELL_INDEX ParentKeyCellOffset,
IN PCUNICODE_STRING SubKeyName,
IN ULONG CreateOptions,
OUT PCM_KEY_NODE *pSubKeyCell,
OUT HCELL_INDEX *pBlockOffset)
{
HCELL_INDEX NKBOffset;
NTSTATUS Status;
VERIFY_KEY_CELL(ParentKeyCell);
/* Create the new key */
Status = CmiCreateSubKey(RegistryHive, ParentKeyCellOffset, SubKeyName, CreateOptions, &NKBOffset);
if (!NT_SUCCESS(Status))
{
return Status;
}
if (ParentKeyCell->SubKeyLists[Storage] == HCELL_NIL)
if (!CmpAddSubKey(&RegistryHive->Hive, ParentKeyCellOffset, NKBOffset))
{
Status = CmiAllocateHashTableCell (
RegistryHive,
&HashBlock,
&ParentKeyCell->SubKeyLists[Storage],
REG_INIT_HASH_TABLE_SIZE,
Storage);
if (!NT_SUCCESS(Status))
{
return(Status);
}
}
else
{
HashBlock = (PCM_KEY_FAST_INDEX)HvGetCell (
&RegistryHive->Hive,
ParentKeyCell->SubKeyLists[Storage]);
ASSERT(HashBlock->Signature == CM_KEY_FAST_LEAF);
if (HashBlock->Count ==
((HvGetCellSize(&RegistryHive->Hive, HashBlock) - FIELD_OFFSET(CM_KEY_FAST_INDEX, List)) / sizeof(CM_INDEX)))
{
PCM_KEY_FAST_INDEX NewHashBlock;
HCELL_INDEX HTOffset;
/* Reallocate the hash table cell */
Status = CmiAllocateHashTableCell (
RegistryHive,
&NewHashBlock,
&HTOffset,
HashBlock->Count +
REG_EXTEND_HASH_TABLE_SIZE,
Storage);
if (!NT_SUCCESS(Status))
{
return Status;
}
RtlCopyMemory(
&NewHashBlock->List[0],
&HashBlock->List[0],
sizeof(NewHashBlock->List[0]) * HashBlock->Count);
NewHashBlock->Count = HashBlock->Count;
HvFreeCell (&RegistryHive->Hive, ParentKeyCell->SubKeyLists[Storage]);
ParentKeyCell->SubKeyLists[Storage] = HTOffset;
HashBlock = NewHashBlock;
}
}
Status = CmiAddKeyToHashTable(
RegistryHive,
HashBlock,
ParentKeyCell->SubKeyLists[Storage],
NewKeyCell,
NKBOffset);
if (NT_SUCCESS(Status))
{
ParentKeyCell->SubKeyCounts[Storage]++;
if (Packable)
{
if (NameLength*sizeof(WCHAR) > ParentKeyCell->MaxNameLen)
ParentKeyCell->MaxNameLen = NameLength*sizeof(WCHAR);
}
else
{
if (NameLength > ParentKeyCell->MaxNameLen)
ParentKeyCell->MaxNameLen = NameLength;
}
if (NewKeyCell->ClassLength > ParentKeyCell->MaxClassLen)
ParentKeyCell->MaxClassLen = NewKeyCell->ClassLength;
*pSubKeyCell = NewKeyCell;
*pBlockOffset = NKBOffset;
/* FIXME: delete newly created cell */
return STATUS_UNSUCCESSFUL;
}
KeQuerySystemTime(&ParentKeyCell->LastWriteTime);
HvMarkCellDirty(&RegistryHive->Hive, ParentKeyCellOffset, FALSE);
return Status;
*pBlockOffset = NKBOffset;
return STATUS_SUCCESS;
}
static BOOLEAN

View file

@ -117,9 +117,12 @@ RegOpenKeyW(
#include "registry.h"
#include "binhive.h"
#define OBJ_NAME_PATH_SEPARATOR ((WCHAR)L'\\')
#define HIVE_NO_FILE 2
#define VERIFY_REGISTRY_HIVE(hive)
extern LIST_ENTRY CmiHiveListHead;
#define ABS_VALUE(V) (((V) < 0) ? -(V) : (V))
#define PAGED_CODE()
/* EOF */

View file

@ -107,6 +107,37 @@ RtlAnsiStringToUnicodeString(
return STATUS_SUCCESS;
}
LONG NTAPI
RtlCompareUnicodeString(
IN PCUNICODE_STRING String1,
IN PCUNICODE_STRING String2,
IN BOOLEAN CaseInSensitive)
{
USHORT i;
WCHAR c1, c2;
for (i = 0; i <= String1->Length / sizeof(WCHAR) && i <= String2->Length / sizeof(WCHAR); i++)
{
if (CaseInSensitive)
{
c1 = RtlUpcaseUnicodeChar(String1->Buffer[i]);
c2 = RtlUpcaseUnicodeChar(String2->Buffer[i]);
}
else
{
c1 = String1->Buffer[i];
c2 = String2->Buffer[i];
}
if (c1 < c2)
return -1;
else if (c1 > c2)
return 1;
}
return 0;
}
WCHAR NTAPI
RtlUpcaseUnicodeChar(
IN WCHAR Source)