-/*
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS kernel
- * FILE: ntoskrnl/cm/regfile.c
- * PURPOSE: Registry file manipulation routines
- * UPDATE HISTORY:
-*/
+/* $Id$
+ *
+ * COPYRIGHT: See COPYING in the top level directory
+ * PROJECT: ReactOS kernel
+ * FILE: ntoskrnl/cm/regfile.c
+ * PURPOSE: Registry file manipulation routines
+ *
+ * PROGRAMMERS: No programmer listed.
+ */
#include <ntoskrnl.h>
#define NDEBUG
/* LOCAL MACROS *************************************************************/
-#define ROUND_DOWN(N, S) ((N) - ((N) % (S)))
-
#define ABS_VALUE(V) (((V) < 0) ? -(V) : (V))
BOOLEAN CmiDoVerify = FALSE;
VOID
CmiCreateDefaultHiveHeader(PHIVE_HEADER Header)
{
- assert(Header);
+ ASSERT(Header);
RtlZeroMemory(Header, sizeof(HIVE_HEADER));
Header->BlockId = REG_HIVE_ID;
Header->UpdateCounter1 = 0;
VOID
CmiCreateDefaultBinHeader(PHBIN BinHeader)
{
- assert(BinHeader);
+ ASSERT(BinHeader);
RtlZeroMemory(BinHeader, sizeof(HBIN));
BinHeader->HeaderId = REG_BIN_ID;
BinHeader->DateModified.u.LowPart = 0;
VOID
CmiCreateDefaultRootKeyCell(PKEY_CELL RootKeyCell)
{
- assert(RootKeyCell);
+ ASSERT(RootKeyCell);
RtlZeroMemory(RootKeyCell, sizeof(KEY_CELL));
RootKeyCell->CellSize = -sizeof(KEY_CELL);
RootKeyCell->Id = REG_KEY_CELL_ID;
RootKeyCell->Flags = REG_KEY_ROOT_CELL | REG_KEY_NAME_PACKED;
- NtQuerySystemTime(&RootKeyCell->LastWriteTime);
+ KeQuerySystemTime(&RootKeyCell->LastWriteTime);
RootKeyCell->ParentKeyOffset = 0;
RootKeyCell->NumberOfSubKeys = 0;
RootKeyCell->HashTableOffset = -1;
if (CmiDoVerify)
{
- assert(BinHeader);
+ ASSERT(BinHeader);
if (BinHeader->HeaderId != REG_BIN_ID)
{
DbgPrint("Bin header ID is %.08x (should be %.08x)\n",
BinHeader->HeaderId, REG_BIN_ID);
- assert(BinHeader->HeaderId == REG_BIN_ID);
+ ASSERT(BinHeader->HeaderId == REG_BIN_ID);
}
//BinHeader->DateModified.dwLowDateTime
//BinHeader->DateModified.dwHighDateTime
-
+
if (BinHeader->BinSize != REG_BLOCK_SIZE)
{
DbgPrint("BinSize is %.08x (should be a multiple of %.08x)\n",
BinHeader->BinSize, REG_BLOCK_SIZE);
- assert(BinHeader->BinSize % REG_BLOCK_SIZE == 0);
+ ASSERT(BinHeader->BinSize % REG_BLOCK_SIZE == 0);
}
}
if (CmiDoVerify)
{
- assert(KeyCell);
+ ASSERT(KeyCell);
if (KeyCell->CellSize == 0)
{
DbgPrint("CellSize is %d (must not be 0)\n",
KeyCell->CellSize);
- assert(KeyCell->CellSize != 0);
+ ASSERT(KeyCell->CellSize != 0);
}
if (KeyCell->Id != REG_KEY_CELL_ID)
{
DbgPrint("Id is %.08x (should be %.08x)\n",
KeyCell->Id, REG_KEY_CELL_ID);
- assert(KeyCell->Id == REG_KEY_CELL_ID);
+ ASSERT(KeyCell->Id == REG_KEY_CELL_ID);
}
//KeyCell->Flags;
{
DbgPrint("ParentKeyOffset is %d (must not be < 0)\n",
KeyCell->ParentKeyOffset);
- assert(KeyCell->ParentKeyOffset >= 0);
+ ASSERT(KeyCell->ParentKeyOffset >= 0);
}
if (KeyCell->NumberOfSubKeys < 0)
{
DbgPrint("NumberOfSubKeys is %d (must not be < 0)\n",
KeyCell->NumberOfSubKeys);
- assert(KeyCell->NumberOfSubKeys >= 0);
+ ASSERT(KeyCell->NumberOfSubKeys >= 0);
}
//KeyCell->HashTableOffset;
{
DbgPrint("NumberOfValues is %d (must not be < 0)\n",
KeyCell->NumberOfValues);
- assert(KeyCell->NumberOfValues >= 0);
+ ASSERT(KeyCell->NumberOfValues >= 0);
}
//KeyCell->ValuesOffset = -1;
{
DbgPrint("SecurityKeyOffset is %d (must not be < 0)\n",
KeyCell->SecurityKeyOffset);
- assert(KeyCell->SecurityKeyOffset >= 0);
+ ASSERT(KeyCell->SecurityKeyOffset >= 0);
}
//KeyCell->ClassNameOffset = -1;
{
DbgPrint("Flags is %.08x (should be %.08x)\n",
RootKeyCell->Flags, REG_KEY_ROOT_CELL | REG_KEY_NAME_PACKED);
- assert(!(RootKeyCell->Flags & (REG_KEY_ROOT_CELL | REG_KEY_NAME_PACKED)));
+ ASSERT(!(RootKeyCell->Flags & (REG_KEY_ROOT_CELL | REG_KEY_NAME_PACKED)));
}
}
if (CmiDoVerify)
{
- assert(ValueCell);
+ ASSERT(ValueCell);
if (ValueCell->CellSize == 0)
{
DbgPrint("CellSize is %d (must not be 0)\n",
ValueCell->CellSize);
- assert(ValueCell->CellSize != 0);
+ ASSERT(ValueCell->CellSize != 0);
}
if (ValueCell->Id != REG_VALUE_CELL_ID)
{
DbgPrint("Id is %.08x (should be %.08x)\n",
ValueCell->Id, REG_VALUE_CELL_ID);
- assert(ValueCell->Id == REG_VALUE_CELL_ID);
+ ASSERT(ValueCell->Id == REG_VALUE_CELL_ID);
}
//ValueCell->NameSize;
{
DbgPrint("CellSize is %d (must not be 0)\n",
ValueListCell->CellSize);
- assert(ValueListCell->CellSize != 0);
+ ASSERT(ValueListCell->CellSize != 0);
}
}
{
DbgPrint("RegistryHive is NULL (must not be NULL)\n",
KeyObject->RegistryHive);
- assert(KeyObject->RegistryHive != NULL);
+ ASSERT(KeyObject->RegistryHive != NULL);
}
if (KeyObject->KeyCell == NULL)
{
DbgPrint("KeyCell is NULL (must not be NULL)\n",
KeyObject->KeyCell);
- assert(KeyObject->KeyCell != NULL);
+ ASSERT(KeyObject->KeyCell != NULL);
}
if (KeyObject->ParentKey == NULL)
{
DbgPrint("ParentKey is NULL (must not be NULL)\n",
KeyObject->ParentKey);
- assert(KeyObject->ParentKey != NULL);
+ ASSERT(KeyObject->ParentKey != NULL);
}
}
DbgPrint("BlockId is %.08x (must be %.08x)\n",
Header->BlockId,
REG_HIVE_ID);
- assert(Header->BlockId == REG_HIVE_ID);
+ ASSERT(Header->BlockId == REG_HIVE_ID);
}
if (Header->Unused3 != 1)
{
DbgPrint("Unused3 is %.08x (must be 1)\n",
Header->Unused3);
- assert(Header->Unused3 == 1);
+ ASSERT(Header->Unused3 == 1);
}
if (Header->Unused4 != 3)
{
DbgPrint("Unused4 is %.08x (must be 3)\n",
Header->Unused4);
- assert(Header->Unused4 == 3);
+ ASSERT(Header->Unused4 == 3);
}
if (Header->Unused5 != 0)
{
DbgPrint("Unused5 is %.08x (must be 0)\n",
Header->Unused5);
- assert(Header->Unused5 == 0);
+ ASSERT(Header->Unused5 == 0);
}
if (Header->Unused6 != 1)
{
DbgPrint("Unused6 is %.08x (must be 1)\n",
Header->Unused6);
- assert(Header->Unused6 == 1);
+ ASSERT(Header->Unused6 == 1);
}
if (Header->Unused7 != 1)
{
DbgPrint("Unused7 is %.08x (must be 1)\n",
Header->Unused7);
- assert(Header->Unused7 == 1);
+ ASSERT(Header->Unused7 == 1);
}
}
/* The rest of the block is free */
FreeCell->CellSize = REG_BLOCK_SIZE - (REG_HBIN_DATA_OFFSET + sizeof(KEY_CELL));
- Status = NtWriteFile(FileHandle,
+ Status = ZwWriteFile(FileHandle,
NULL,
NULL,
NULL,
ExFreePool(Buffer);
- assertmsg(NT_SUCCESS(Status), ("Status: 0x%X\n", Status));
-
if (!NT_SUCCESS(Status))
{
return(Status);
}
- Status = NtFlushBuffersFile(FileHandle,
+ Status = ZwFlushBuffersFile(FileHandle,
&IoStatusBlock);
return(Status);
NULL,
NULL);
- Status = NtCreateFile(&HiveHandle,
+ Status = ZwCreateFile(&HiveHandle,
FILE_READ_DATA | FILE_READ_ATTRIBUTES,
&ObjectAttributes,
&IoStatusBlock,
}
if (!NT_SUCCESS(Status))
{
- DPRINT("NtCreateFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwCreateFile() failed (Status %lx)\n", Status);
return(Status);
}
NULL,
NULL);
- Status = NtCreateFile(&LogHandle,
+ Status = ZwCreateFile(&LogHandle,
FILE_READ_DATA | FILE_READ_ATTRIBUTES,
&ObjectAttributes,
&IoStatusBlock,
}
else if (!NT_SUCCESS(Status))
{
- DPRINT("NtCreateFile() failed (Status %lx)\n", Status);
- NtClose(HiveHandle);
+ DPRINT("ZwCreateFile() failed (Status %lx)\n", Status);
+ ZwClose(HiveHandle);
return(Status);
}
/* Read hive base block */
FileOffset.QuadPart = 0ULL;
- Status = NtReadFile(HiveHandle,
+ Status = ZwReadFile(HiveHandle,
0,
0,
0,
0);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtReadFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwReadFile() failed (Status %lx)\n", Status);
goto ByeBye;
}
/* Read log file header */
FileOffset.QuadPart = 0ULL;
- Status = NtReadFile(LogHandle,
+ Status = ZwReadFile(LogHandle,
0,
0,
0,
0);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtReadFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwReadFile() failed (Status %lx)\n", Status);
goto ByeBye;
}
*/
/* Get file size */
- Status = NtQueryInformationFile(LogHandle,
+ Status = ZwQueryInformationFile(LogHandle,
&IoStatusBlock,
&fsi,
sizeof(fsi),
FileStandardInformation);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtQueryInformationFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwQueryInformationFile() failed (Status %lx)\n", Status);
goto ByeBye;
}
FileSize = fsi.EndOfFile.u.LowPart;
/* Read log file header */
FileOffset.QuadPart = 0ULL;
- Status = NtReadFile(LogHandle,
+ Status = ZwReadFile(LogHandle,
0,
0,
0,
0);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtReadFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwReadFile() failed (Status %lx)\n", Status);
goto ByeBye;
}
ExFreePool(LogHeader);
if (LogHandle != INVALID_HANDLE_VALUE)
- NtClose(LogHandle);
+ ZwClose(LogHandle);
- NtClose(HiveHandle);
+ ZwClose(HiveHandle);
return(Status);
}
return STATUS_REGISTRY_CORRUPT;
}
- assertmsg((Bin->BinSize % REG_BLOCK_SIZE) == 0,
- ("Bin size (0x%.08x) must be multiple of 4K\n",
- Bin->BinSize));
+ ASSERTMSG("Bin size must be multiple of 4K\n",
+ (Bin->BinSize % REG_BLOCK_SIZE) == 0);
/* Allocate the hive block */
Hive->BlockList[BlockIndex].Bin = ExAllocatePool (PagedPool,
/* Duplicate Filename */
Status = RtlCreateUnicodeString(&RegistryHive->HiveFileName,
- Filename);
+ Filename);
if (!NT_SUCCESS(Status))
{
- DPRINT("RtlCreateUnicodeString() failed (Status %lx)\n", Status);
+ DPRINT("RtlpCreateUnicodeString() failed (Status %lx)\n", Status);
return(Status);
}
/* Create log file name */
RegistryHive->LogFileName.Length = (wcslen(Filename) + 4) * sizeof(WCHAR);
RegistryHive->LogFileName.MaximumLength = RegistryHive->LogFileName.Length + sizeof(WCHAR);
- RegistryHive->LogFileName.Buffer = ExAllocatePool(NonPagedPool,
- RegistryHive->LogFileName.MaximumLength);
+ RegistryHive->LogFileName.Buffer = ExAllocatePoolWithTag(PagedPool,
+ RegistryHive->LogFileName.MaximumLength,
+ TAG('U', 'S', 'T', 'R'));
if (RegistryHive->LogFileName.Buffer == NULL)
{
RtlFreeUnicodeString(&RegistryHive->HiveFileName);
NULL);
CreateDisposition = FILE_OPEN_IF;
- Status = NtCreateFile(&FileHandle,
+ Status = ZwCreateFile(&FileHandle,
FILE_ALL_ACCESS,
&ObjectAttributes,
&IoSB,
{
RtlFreeUnicodeString(&RegistryHive->HiveFileName);
RtlFreeUnicodeString(&RegistryHive->LogFileName);
- DPRINT("NtCreateFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwCreateFile() failed (Status %lx)\n", Status);
return(Status);
}
if (!NT_SUCCESS(Status))
{
DPRINT("CmiCreateNewRegFile() failed (Status %lx)\n", Status);
- NtClose(FileHandle);
+ ZwClose(FileHandle);
RtlFreeUnicodeString(&RegistryHive->HiveFileName);
RtlFreeUnicodeString(&RegistryHive->LogFileName);
return(Status);
ObDereferenceObject(SectionObject);
RtlFreeUnicodeString(&RegistryHive->HiveFileName);
RtlFreeUnicodeString(&RegistryHive->LogFileName);
- NtClose(FileHandle);
+ ZwClose(FileHandle);
return(Status);
}
DPRINT("ViewBase %p ViewSize %lx\n", ViewBase, ViewSize);
ObDereferenceObject(SectionObject);
RtlFreeUnicodeString(&RegistryHive->HiveFileName);
RtlFreeUnicodeString(&RegistryHive->LogFileName);
- NtClose(FileHandle);
+ ZwClose(FileHandle);
return STATUS_INSUFFICIENT_RESOURCES;
}
RtlZeroMemory (RegistryHive->BlockList,
ObDereferenceObject(SectionObject);
RtlFreeUnicodeString(&RegistryHive->HiveFileName);
RtlFreeUnicodeString(&RegistryHive->LogFileName);
- NtClose(FileHandle);
+ ZwClose(FileHandle);
return Status;
}
ObDereferenceObject(SectionObject);
/* Close the hive file */
- NtClose(FileHandle);
+ ZwClose(FileHandle);
/* Initialize the free cell list */
Status = CmiCreateHiveFreeCellList (RegistryHive);
RtlZeroMemory (Hive,
sizeof(REGISTRY_HIVE));
- DPRINT("Hive %x\n", Hive);
+ DPRINT("Hive 0x%p\n", Hive);
Hive->HiveHeader = (PHIVE_HEADER)ExAllocatePool (NonPagedPool,
sizeof(HIVE_HEADER));
CmiCreateDefaultRootKeyCell (RootKeyCell);
Hive->HiveHeader->RootKeyOffset = (BLOCK_OFFSET)RootKeyCell;
- ExInitializeResourceLite (&Hive->HiveResource);
-
/* Acquire hive list lock exclusively */
KeEnterCriticalRegion();
- ExAcquireResourceExclusiveLite (&CmiHiveListLock,
- TRUE);
+ ExAcquireResourceExclusiveLite (&CmiRegistryLock, TRUE);
/* Add the new hive to the hive list */
InsertTailList (&CmiHiveListHead,
&Hive->HiveList);
/* Release hive list lock */
- ExReleaseResourceLite (&CmiHiveListLock);
+ ExReleaseResourceLite (&CmiRegistryLock);
KeLeaveCriticalRegion();
VERIFY_REGISTRY_HIVE (Hive);
RtlZeroMemory (Hive,
sizeof(REGISTRY_HIVE));
- DPRINT ("Hive %x\n", Hive);
+ DPRINT ("Hive 0x%p\n", Hive);
Hive->HiveHeader = (PHIVE_HEADER)ExAllocatePool (NonPagedPool,
REG_BLOCK_SIZE);
RtlZeroMemory (Hive->HiveHeader,
REG_BLOCK_SIZE);
- DPRINT ("HiveHeader %x\n", Hive->HiveHeader);
+ DPRINT ("HiveHeader 0x%p\n", Hive->HiveHeader);
Hive->Flags = HIVE_NO_FILE;
return Status;
}
-
- ExInitializeResourceLite (&Hive->HiveResource);
-
/* Acquire hive list lock exclusively */
KeEnterCriticalRegion();
- ExAcquireResourceExclusiveLite (&CmiHiveListLock,
- TRUE);
+ ExAcquireResourceExclusiveLite(&CmiRegistryLock, TRUE);
/* Add the new hive to the hive list */
InsertTailList (&CmiHiveListHead,
&Hive->HiveList);
/* Release hive list lock */
- ExReleaseResourceLite (&CmiHiveListLock);
+ ExReleaseResourceLite(&CmiRegistryLock);
KeLeaveCriticalRegion();
VERIFY_REGISTRY_HIVE (Hive);
RtlZeroMemory (Hive,
sizeof(REGISTRY_HIVE));
- DPRINT ("Hive %x\n", Hive);
+ DPRINT ("Hive 0x%p\n", Hive);
Hive->Flags = (Flags & REG_NO_LAZY_FLUSH) ? HIVE_NO_SYNCH : 0;
Hive->HiveHeader = (PHIVE_HEADER)ExAllocatePool(NonPagedPool,
return Status;
}
- ExInitializeResourceLite (&Hive->HiveResource);
-
/* Add the new hive to the hive list */
- KeEnterCriticalRegion();
- ExAcquireResourceExclusiveLite (&CmiHiveListLock,
- TRUE);
InsertTailList (&CmiHiveListHead,
&Hive->HiveList);
- ExReleaseResourceLite (&CmiHiveListLock);
- KeLeaveCriticalRegion();
-
VERIFY_REGISTRY_HIVE(Hive);
-
Status = CmiConnectHive (KeyObjectAttributes,
Hive);
if (!NT_SUCCESS(Status))
if (RegistryHive->Flags & HIVE_POINTER)
return STATUS_UNSUCCESSFUL;
- /* Acquire hive list lock exclusively */
- KeEnterCriticalRegion();
- ExAcquireResourceExclusiveLite (&CmiHiveListLock,
- TRUE);
-
/* Remove hive from hive list */
RemoveEntryList (&RegistryHive->HiveList);
- /* Release hive list lock */
- ExReleaseResourceLite (&CmiHiveListLock);
- KeLeaveCriticalRegion();
-
/* Release file names */
RtlFreeUnicodeString (&RegistryHive->HiveFileName);
RtlFreeUnicodeString (&RegistryHive->LogFileName);
ExFreePool (RegistryHive->FreeList);
ExFreePool (RegistryHive->FreeListOffset);
- /* Release hive resource */
- ExDeleteResource (&RegistryHive->HiveResource);
-
/* Release bins and bin list */
CmiFreeHiveBins (RegistryHive);
ExFreePool (RegistryHive->BlockList);
PUCHAR Buffer;
PUCHAR Ptr;
ULONG BlockIndex;
+ ULONG LastIndex;
PVOID BlockPtr;
NTSTATUS Status;
NULL,
NULL);
- Status = NtCreateFile(&FileHandle,
+ Status = ZwCreateFile(&FileHandle,
FILE_ALL_ACCESS,
&ObjectAttributes,
&IoStatusBlock,
0);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtCreateFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwCreateFile() failed (Status %lx)\n", Status);
ExFreePool(Buffer);
return(Status);
}
/* Write hive block and block bitmap */
FileOffset.QuadPart = (ULONGLONG)0;
- Status = NtWriteFile(FileHandle,
+ Status = ZwWriteFile(FileHandle,
NULL,
NULL,
NULL,
NULL);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
- NtClose(FileHandle);
+ DPRINT("ZwWriteFile() failed (Status %lx)\n", Status);
+ ZwClose(FileHandle);
ExFreePool(Buffer);
return(Status);
}
/* Write dirty blocks */
FileOffset.QuadPart = (ULONGLONG)BufferSize;
BlockIndex = 0;
- while (TRUE)
+ while (BlockIndex < RegistryHive->BlockListSize)
{
+ LastIndex = BlockIndex;
BlockIndex = RtlFindSetBits(&RegistryHive->DirtyBitMap,
1,
BlockIndex);
- if ((BlockIndex == (ULONG)-1) ||
- (BlockIndex >= RegistryHive->BlockListSize))
+ if (BlockIndex == (ULONG)-1 || BlockIndex < LastIndex)
{
DPRINT("No more set bits\n");
Status = STATUS_SUCCESS;
DPRINT("File offset %I64x\n", FileOffset.QuadPart);
/* Write hive block */
- Status = NtWriteFile(FileHandle,
+ Status = ZwWriteFile(FileHandle,
NULL,
NULL,
NULL,
NULL);
if (!NT_SUCCESS(Status))
{
- DPRINT1("NtWriteFile() failed (Status %lx)\n", Status);
- NtClose(FileHandle);
+ DPRINT1("ZwWriteFile() failed (Status %lx)\n", Status);
+ ZwClose(FileHandle);
return(Status);
}
/* Truncate log file */
EndOfFileInfo.EndOfFile.QuadPart = FileOffset.QuadPart;
- Status = NtSetInformationFile(FileHandle,
+ Status = ZwSetInformationFile(FileHandle,
&IoStatusBlock,
&EndOfFileInfo,
sizeof(FILE_END_OF_FILE_INFORMATION),
FileEndOfFileInformation);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtSetInformationFile() failed (Status %lx)\n", Status);
- NtClose(FileHandle);
+ DPRINT("ZwSetInformationFile() failed (Status %lx)\n", Status);
+ ZwClose(FileHandle);
return(Status);
}
FileAllocationInfo.AllocationSize.QuadPart = FileOffset.QuadPart;
- Status = NtSetInformationFile(FileHandle,
+ Status = ZwSetInformationFile(FileHandle,
&IoStatusBlock,
&FileAllocationInfo,
sizeof(FILE_ALLOCATION_INFORMATION),
FileAllocationInformation);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtSetInformationFile() failed (Status %lx)\n", Status);
- NtClose(FileHandle);
+ DPRINT("ZwSetInformationFile() failed (Status %lx)\n", Status);
+ ZwClose(FileHandle);
return(Status);
}
/* Flush the log file */
- Status = NtFlushBuffersFile(FileHandle,
+ Status = ZwFlushBuffersFile(FileHandle,
&IoStatusBlock);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtFlushBuffersFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwFlushBuffersFile() failed (Status %lx)\n", Status);
}
- NtClose(FileHandle);
+ ZwClose(FileHandle);
return(Status);
}
NULL,
NULL);
- Status = NtCreateFile(&FileHandle,
+ Status = ZwCreateFile(&FileHandle,
FILE_ALL_ACCESS,
&ObjectAttributes,
&IoStatusBlock,
0);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtCreateFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwCreateFile() failed (Status %lx)\n", Status);
ExFreePool(Buffer);
return(Status);
}
/* Write hive block and block bitmap */
FileOffset.QuadPart = (ULONGLONG)0;
- Status = NtWriteFile(FileHandle,
+ Status = ZwWriteFile(FileHandle,
NULL,
NULL,
NULL,
NULL);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
- NtClose(FileHandle);
+ DPRINT("ZwWriteFile() failed (Status %lx)\n", Status);
+ ZwClose(FileHandle);
ExFreePool(Buffer);
return(Status);
}
ExFreePool(Buffer);
/* Flush the log file */
- Status = NtFlushBuffersFile(FileHandle,
+ Status = ZwFlushBuffersFile(FileHandle,
&IoStatusBlock);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtFlushBuffersFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwFlushBuffersFile() failed (Status %lx)\n", Status);
}
- NtClose(FileHandle);
+ ZwClose(FileHandle);
return(Status);
}
NULL,
NULL);
- Status = NtCreateFile(&FileHandle,
+ Status = ZwCreateFile(&FileHandle,
FILE_ALL_ACCESS,
&ObjectAttributes,
&IoStatusBlock,
0);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtCreateFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwCreateFile() failed (Status %lx)\n", Status);
return(Status);
}
/* Truncate log file */
EndOfFileInfo.EndOfFile.QuadPart = (ULONGLONG)BufferSize;
- Status = NtSetInformationFile(FileHandle,
+ Status = ZwSetInformationFile(FileHandle,
&IoStatusBlock,
&EndOfFileInfo,
sizeof(FILE_END_OF_FILE_INFORMATION),
FileEndOfFileInformation);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtSetInformationFile() failed (Status %lx)\n", Status);
- NtClose(FileHandle);
+ DPRINT("ZwSetInformationFile() failed (Status %lx)\n", Status);
+ ZwClose(FileHandle);
return(Status);
}
FileAllocationInfo.AllocationSize.QuadPart = (ULONGLONG)BufferSize;
- Status = NtSetInformationFile(FileHandle,
+ Status = ZwSetInformationFile(FileHandle,
&IoStatusBlock,
&FileAllocationInfo,
sizeof(FILE_ALLOCATION_INFORMATION),
if (!NT_SUCCESS(Status))
{
DPRINT("NtSetInformationFile() failed (Status %lx)\n", Status);
- NtClose(FileHandle);
+ ZwClose(FileHandle);
return(Status);
}
/* Flush the log file */
- Status = NtFlushBuffersFile(FileHandle,
+ Status = ZwFlushBuffersFile(FileHandle,
&IoStatusBlock);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtFlushBuffersFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwFlushBuffersFile() failed (Status %lx)\n", Status);
}
- NtClose(FileHandle);
+ ZwClose(FileHandle);
return(Status);
}
HANDLE FileHandle;
LARGE_INTEGER FileOffset;
ULONG BlockIndex;
+ ULONG LastIndex;
PVOID BlockPtr;
NTSTATUS Status;
NULL,
NULL);
- Status = NtCreateFile(&FileHandle,
+ Status = ZwCreateFile(&FileHandle,
FILE_ALL_ACCESS,
&ObjectAttributes,
&IoStatusBlock,
0);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtCreateFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwCreateFile() failed (Status %lx)\n", Status);
return(Status);
}
/* Write hive block */
FileOffset.QuadPart = (ULONGLONG)0;
- Status = NtWriteFile(FileHandle,
+ Status = ZwWriteFile(FileHandle,
NULL,
NULL,
NULL,
NULL);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
- NtClose(FileHandle);
+ DPRINT("ZwWriteFile() failed (Status %lx)\n", Status);
+ ZwClose(FileHandle);
return(Status);
}
BlockIndex = 0;
- while (TRUE)
+ while (BlockIndex < RegistryHive->BlockListSize)
{
+ LastIndex = BlockIndex;
BlockIndex = RtlFindSetBits(&RegistryHive->DirtyBitMap,
1,
BlockIndex);
- if ((BlockIndex == (ULONG)-1) ||
- (BlockIndex >= RegistryHive->BlockListSize))
+ if (BlockIndex == (ULONG)-1 || BlockIndex < LastIndex)
{
DPRINT("No more set bits\n");
Status = STATUS_SUCCESS;
DPRINT(" File offset %I64x\n", FileOffset.QuadPart);
/* Write hive block */
- Status = NtWriteFile(FileHandle,
+ Status = ZwWriteFile(FileHandle,
NULL,
NULL,
NULL,
NULL);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
- NtClose(FileHandle);
+ DPRINT("ZwWriteFile() failed (Status %lx)\n", Status);
+ ZwClose(FileHandle);
return(Status);
}
BlockIndex++;
}
- Status = NtFlushBuffersFile(FileHandle,
+ Status = ZwFlushBuffersFile(FileHandle,
&IoStatusBlock);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtFlushBuffersFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwFlushBuffersFile() failed (Status %lx)\n", Status);
}
- NtClose(FileHandle);
+ ZwClose(FileHandle);
return(Status);
}
NULL,
NULL);
- Status = NtCreateFile(&FileHandle,
+ Status = ZwCreateFile(&FileHandle,
FILE_ALL_ACCESS,
&ObjectAttributes,
&IoStatusBlock,
0);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtCreateFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwCreateFile() failed (Status %lx)\n", Status);
return(Status);
}
/* Write hive block */
FileOffset.QuadPart = (ULONGLONG)0;
- Status = NtWriteFile(FileHandle,
+ Status = ZwWriteFile(FileHandle,
NULL,
NULL,
NULL,
NULL);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtWriteFile() failed (Status %lx)\n", Status);
- NtClose(FileHandle);
+ DPRINT("ZwWriteFile() failed (Status %lx)\n", Status);
+ ZwClose(FileHandle);
return(Status);
}
- Status = NtFlushBuffersFile(FileHandle,
+ Status = ZwFlushBuffersFile(FileHandle,
&IoStatusBlock);
if (!NT_SUCCESS(Status))
{
- DPRINT("NtFlushBuffersFile() failed (Status %lx)\n", Status);
+ DPRINT("ZwFlushBuffersFile() failed (Status %lx)\n", Status);
}
- NtClose(FileHandle);
+ ZwClose(FileHandle);
return(Status);
}
&RegistryHive->LogFileName);
/* Update hive header modification time */
- NtQuerySystemTime(&RegistryHive->HiveHeader->DateModified);
+ KeQuerySystemTime(&RegistryHive->HiveHeader->DateModified);
/* Start log update */
Status = CmiStartLogUpdate(RegistryHive);
DPRINT("Scanning for sub key %wZ\n", KeyName);
- assert(RegistryHive);
+ ASSERT(RegistryHive);
*SubKeyCell = NULL;
{
NewKeyCell->Id = REG_KEY_CELL_ID;
NewKeyCell->Flags = 0;
- NtQuerySystemTime(&NewKeyCell->LastWriteTime);
+ KeQuerySystemTime(&NewKeyCell->LastWriteTime);
NewKeyCell->ParentKeyOffset = -1;
NewKeyCell->NumberOfSubKeys = 0;
NewKeyCell->HashTableOffset = -1;
ParentKeyCell->NumberOfSubKeys++;
}
- NtQuerySystemTime (&ParentKeyCell->LastWriteTime);
+ KeQuerySystemTime (&ParentKeyCell->LastWriteTime);
CmiMarkBlockDirty (RegistryHive, ParentKey->KeyCellOffset);
return(Status);
return STATUS_UNSUCCESSFUL;
}
- if (ValueCell->DataSize > sizeof(BLOCK_OFFSET))
+ if (!(ValueCell->DataSize & REG_DATA_IN_OFFSET)
+ && ValueCell->DataSize > sizeof(BLOCK_OFFSET))
{
DataCell = CmiGetCell (RegistryHive,
ValueCell->DataOffset,
}
}
- NtQuerySystemTime(&ParentKey->KeyCell->LastWriteTime);
+ KeQuerySystemTime(&ParentKey->KeyCell->LastWriteTime);
CmiMarkBlockDirty(ParentKey->RegistryHive,
ParentKey->KeyCellOffset);
}
CmiMarkBlockDirty(RegistryHive, KeyCellOffset);
CmiMarkBlockDirty(RegistryHive, ValueListCellOffset);
}
- else if (KeyCell->NumberOfValues >=
+ else if (KeyCell->NumberOfValues >=
(((ULONG)ABS_VALUE(ValueListCell->CellSize) - sizeof(VALUE_LIST_CELL)) / sizeof(BLOCK_OFFSET)))
{
#if 0
Status = STATUS_SUCCESS;
*HashBlock = NULL;
- NewHashSize = sizeof(HASH_TABLE_CELL) +
+ NewHashSize = sizeof(HASH_TABLE_CELL) +
(SubKeyCount * sizeof(HASH_RECORD));
Status = CmiAllocateCell (RegistryHive,
NewHashSize,
}
else
{
- assert(SubKeyCount <= 0xffff); /* should really be USHORT_MAX or similar */
+ ASSERT(SubKeyCount <= 0xffff); /* should really be USHORT_MAX or similar */
NewHashBlock->Id = REG_HASH_TABLE_CELL_ID;
NewHashBlock->HashTableSize = (USHORT)SubKeyCount;
*HashBlock = NewHashBlock;
}
else
{
- assert(NameSize <= 0xffff); /* should really be USHORT_MAX or similar */
+ ASSERT(NameSize <= 0xffff); /* should really be USHORT_MAX or similar */
NewValueCell->Id = REG_VALUE_CELL_ID;
NewValueCell->NameSize = (USHORT)NameSize;
if (Packable)
VERIFY_VALUE_CELL(ValueCell);
/* Destroy the data cell */
- if (ValueCell->DataSize > sizeof(BLOCK_OFFSET))
+ if (!(ValueCell->DataSize & REG_DATA_IN_OFFSET)
+ && ValueCell->DataSize > sizeof(BLOCK_OFFSET))
{
DataCell = CmiGetCell (RegistryHive, ValueCell->DataOffset, &Bin);
if (DataCell == NULL)
/* Update time of heap */
if (!IsNoFileHive(RegistryHive))
- NtQuerySystemTime(&Bin->DateModified);
+ KeQuerySystemTime(&Bin->DateModified);
}
/* Destroy the value cell */
/* Update time of heap */
if (!IsNoFileHive(RegistryHive) && CmiGetCell (RegistryHive, ValueCellOffset, &Bin))
{
- NtQuerySystemTime(&Bin->DateModified);
+ KeQuerySystemTime(&Bin->DateModified);
}
return Status;
RegistryHive->FileSize += BinSize;
tmpBin->BinSize = BinSize;
tmpBin->Unused1 = 0;
- NtQuerySystemTime(&tmpBin->DateModified);
+ KeQuerySystemTime(&tmpBin->DateModified);
tmpBin->Unused2 = 0;
DPRINT (" BinOffset %lx BinSize %lx\n", tmpBin->BinOffset,tmpBin->BinSize);
return STATUS_UNSUCCESSFUL;
}
- NtQuerySystemTime(&Bin->DateModified);
+ KeQuerySystemTime(&Bin->DateModified);
CmiMarkBlockDirty(RegistryHive, RegistryHive->FreeListOffset[i]);
if ((i + 1) < RegistryHive->FreeListSize)
else
{
PCELL_HEADER pFree = Cell;
+ PHASH_TABLE_CELL pHash = Cell;
+ LONG CellSize;
- if (pFree->CellSize < 0)
- pFree->CellSize = -pFree->CellSize;
-
- /* Clear block (except the block size) */
- RtlZeroMemory(((char*)pFree) + sizeof(ULONG),
- pFree->CellSize - sizeof(ULONG));
-
+ if (pHash->Id == REG_HASH_TABLE_CELL_ID)
+ CellSize = sizeof(HASH_TABLE_CELL) + pHash->HashTableSize * sizeof(HASH_RECORD);
+ else
+ CellSize = abs(pFree->CellSize);
+
+ /* Clear block */
+ RtlZeroMemory(pFree, CellSize);
+
+ /* restore CellSize */
+ pFree->CellSize = CellSize;
+
/* Add block to the list of free blocks */
CmiAddFree(RegistryHive, Cell, CellOffset, TRUE);
/* Update time of heap */
if (!IsNoFileHive(RegistryHive) && CmiGetCell (RegistryHive, CellOffset,&pBin))
- NtQuerySystemTime(&pBin->DateModified);
+ KeQuerySystemTime(&pBin->DateModified);
CmiMarkBlockDirty(RegistryHive, CellOffset);
}
LONG maxInd;
LONG medInd;
- assert(RegistryHive);
- assert(FreeBlock);
+ ASSERT(RegistryHive);
+ ASSERT(FreeBlock);
DPRINT("FreeBlock %.08lx FreeOffset %.08lx\n",
FreeBlock, FreeOffset);
BOOLEAN
CmiComparePackedNames(IN PUNICODE_STRING Name,
- IN PCHAR NameBuffer,
+ IN PUCHAR NameBuffer,
IN USHORT NameBufferSize,
IN BOOLEAN NamePacked)
{
VOID
CmiCopyPackedName(PWCHAR NameBuffer,
- PCHAR PackedNameBuffer,
+ PUCHAR PackedNameBuffer,
ULONG PackedNameSize)
{
ULONG i;
}
NewKeyCell->HashTableOffset = NewHashTableOffset;
}
+ else
+ {
+ NewHashTableCell = NULL;
+ }
/* Allocate and copy value list and values */
if (SrcKeyCell->NumberOfValues != 0)
/* Write hive block */
FileOffset.QuadPart = (ULONGLONG)0;
- Status = NtWriteFile (FileHandle,
+ Status = ZwWriteFile (FileHandle,
NULL,
NULL,
NULL,
NULL);
if (!NT_SUCCESS(Status))
{
- DPRINT1 ("NtWriteFile() failed (Status %lx)\n", Status);
+ DPRINT1 ("ZwWriteFile() failed (Status %lx)\n", Status);
return Status;
}
DPRINT ("File offset %I64x\n", FileOffset.QuadPart);
/* Write hive block */
- Status = NtWriteFile (FileHandle,
+ Status = ZwWriteFile (FileHandle,
NULL,
NULL,
NULL,
NULL);
if (!NT_SUCCESS(Status))
{
- DPRINT1 ("NtWriteFile() failed (Status %lx)\n", Status);
+ DPRINT1 ("ZwWriteFile() failed (Status %lx)\n", Status);
return Status;
}
}
- Status = NtFlushBuffersFile (FileHandle,
+ Status = ZwFlushBuffersFile (FileHandle,
&IoStatusBlock);
if (!NT_SUCCESS(Status))
{
- DPRINT1 ("NtFlushBuffersFile() failed (Status %lx)\n", Status);
+ DPRINT1 ("ZwFlushBuffersFile() failed (Status %lx)\n", Status);
}
DPRINT ("CmiSaveTempHive() done\n");