mirror of
https://github.com/reactos/reactos.git
synced 2025-02-23 00:45:24 +00:00
[CMLIB]
- memcpy --> RtlCopyMemory - Remove a __debugbreak() - Improve a bit the DPRINT that is displayed when a corrupted hive is loaded. - Fix a comment. - Implement saving the hive file name in the hive itself. According to what windows does (just open an existing hive file with your preferred hex editor 8^) ), you can see that it copies the last 31 unicode characters of the path, and terminate it by a NULL. [NTOS] Remove unneeded cast. svn path=/trunk/; revision=61922
This commit is contained in:
parent
bdb5664d61
commit
048856c9cc
7 changed files with 45 additions and 21 deletions
|
@ -57,7 +57,7 @@ CmCreateRootNode(
|
|||
|
||||
/* Write the name */
|
||||
KeyCell->NameLength = (USHORT)NameSize;
|
||||
memcpy(KeyCell->Name, Name, NameSize);
|
||||
RtlCopyMemory(KeyCell->Name, Name, NameSize);
|
||||
|
||||
/* Return success */
|
||||
HvReleaseCell(Hive, RootCellIndex);
|
||||
|
|
|
@ -238,7 +238,7 @@ extern ULONG CmlibTraceLevel;
|
|||
*/
|
||||
NTSTATUS CMAPI
|
||||
HvInitialize(
|
||||
PHHIVE RegistryHive,
|
||||
PHHIVE RegistryHive,
|
||||
ULONG Operation,
|
||||
ULONG HiveType,
|
||||
ULONG HiveFlags,
|
||||
|
@ -250,7 +250,7 @@ HvInitialize(
|
|||
PFILE_READ_ROUTINE FileRead,
|
||||
PFILE_FLUSH_ROUTINE FileFlush,
|
||||
ULONG Cluster OPTIONAL,
|
||||
PUNICODE_STRING FileName);
|
||||
PCUNICODE_STRING FileName OPTIONAL);
|
||||
|
||||
VOID CMAPI
|
||||
HvFree(
|
||||
|
|
|
@ -295,7 +295,7 @@ HvpCreateHiveFreeCellList(
|
|||
Hive->Storage[Stable].FreeDisplay[Index] = HCELL_NIL;
|
||||
Hive->Storage[Volatile].FreeDisplay[Index] = HCELL_NIL;
|
||||
}
|
||||
//__debugbreak();
|
||||
|
||||
BlockOffset = 0;
|
||||
BlockIndex = 0;
|
||||
while (BlockIndex < Hive->Storage[Stable].Length)
|
||||
|
|
|
@ -144,8 +144,9 @@ typedef struct _HBASE_BLOCK
|
|||
/* (1?) */
|
||||
ULONG Cluster;
|
||||
|
||||
/* Name of hive file */
|
||||
CHAR FileName[64];
|
||||
/* Last 31 UNICODE characters, plus terminating NULL character,
|
||||
of the full name of the hive file */
|
||||
WCHAR FileName[32];
|
||||
|
||||
ULONG Reserved1[99];
|
||||
|
||||
|
|
|
@ -29,15 +29,16 @@ HvpVerifyHiveHeader(
|
|||
HvpHiveHeaderChecksum(BaseBlock) != BaseBlock->CheckSum)
|
||||
{
|
||||
DPRINT1("Verify Hive Header failed: \n");
|
||||
DPRINT1(" Signature: 0x%x and not 0x%x, Major: 0x%x and not 0x%x\n",
|
||||
DPRINT1(" Signature: 0x%x, expected 0x%x; Major: 0x%x, expected 0x%x\n",
|
||||
BaseBlock->Signature, HV_SIGNATURE, BaseBlock->Major, HSYS_MAJOR);
|
||||
DPRINT1(" Minor: 0x%x is not >= 0x%x, Type: 0x%x and not 0x%x\n",
|
||||
DPRINT1(" Minor: 0x%x is not >= 0x%x; Type: 0x%x, expected 0x%x\n",
|
||||
BaseBlock->Minor, HSYS_MINOR, BaseBlock->Type, HFILE_TYPE_PRIMARY);
|
||||
DPRINT1(" Format: 0x%x and not 0x%x, Cluster: 0x%x and not 1\n",
|
||||
DPRINT1(" Format: 0x%x, expected 0x%x; Cluster: 0x%x, expected 1\n",
|
||||
BaseBlock->Format, HBASE_FORMAT_MEMORY, BaseBlock->Cluster);
|
||||
DPRINT1(" Sequence: 0x%x and not 0x%x, Checksum: 0x%x and not 0x%x\n",
|
||||
DPRINT1(" Sequence: 0x%x, expected 0x%x; Checksum: 0x%x, expected 0x%x\n",
|
||||
BaseBlock->Sequence1, BaseBlock->Sequence2,
|
||||
HvpHiveHeaderChecksum(BaseBlock), BaseBlock->CheckSum);
|
||||
|
||||
return FALSE;
|
||||
}
|
||||
|
||||
|
@ -91,7 +92,8 @@ HvpFreeHiveBins(
|
|||
|
||||
NTSTATUS CMAPI
|
||||
HvpCreateHive(
|
||||
PHHIVE RegistryHive)
|
||||
PHHIVE RegistryHive,
|
||||
PCUNICODE_STRING FileName OPTIONAL)
|
||||
{
|
||||
PHBASE_BLOCK BaseBlock;
|
||||
ULONG Index;
|
||||
|
@ -99,7 +101,9 @@ HvpCreateHive(
|
|||
BaseBlock = RegistryHive->Allocate(sizeof(HBASE_BLOCK), FALSE, TAG_CM);
|
||||
if (BaseBlock == NULL)
|
||||
return STATUS_NO_MEMORY;
|
||||
|
||||
RtlZeroMemory(BaseBlock, sizeof(HBASE_BLOCK));
|
||||
|
||||
BaseBlock->Signature = HV_SIGNATURE;
|
||||
BaseBlock->Major = HSYS_MAJOR;
|
||||
BaseBlock->Minor = HSYS_MINOR;
|
||||
|
@ -110,7 +114,27 @@ HvpCreateHive(
|
|||
BaseBlock->Length = 0;
|
||||
BaseBlock->Sequence1 = 1;
|
||||
BaseBlock->Sequence2 = 1;
|
||||
/* FIXME: Fill in the file name */
|
||||
|
||||
/* Copy the 31 last characters of the hive file name if any */
|
||||
if (FileName)
|
||||
{
|
||||
if (FileName->Length / sizeof(WCHAR) <= 31)
|
||||
{
|
||||
RtlCopyMemory(BaseBlock->FileName,
|
||||
FileName->Buffer,
|
||||
FileName->Length);
|
||||
}
|
||||
else
|
||||
{
|
||||
RtlCopyMemory(BaseBlock->FileName,
|
||||
FileName->Buffer + FileName->Length / sizeof(WCHAR) - 31,
|
||||
31 * sizeof(WCHAR));
|
||||
}
|
||||
|
||||
/* NULL-terminate */
|
||||
BaseBlock->FileName[31] = L'\0';
|
||||
}
|
||||
|
||||
BaseBlock->CheckSum = HvpHiveHeaderChecksum(BaseBlock);
|
||||
|
||||
RegistryHive->BaseBlock = BaseBlock;
|
||||
|
@ -431,13 +455,12 @@ HvInitialize(
|
|||
PFILE_READ_ROUTINE FileRead,
|
||||
PFILE_FLUSH_ROUTINE FileFlush,
|
||||
ULONG Cluster OPTIONAL,
|
||||
PUNICODE_STRING FileName)
|
||||
PCUNICODE_STRING FileName OPTIONAL)
|
||||
{
|
||||
NTSTATUS Status;
|
||||
PHHIVE Hive = RegistryHive;
|
||||
|
||||
UNREFERENCED_PARAMETER(HiveType);
|
||||
UNREFERENCED_PARAMETER(FileName);
|
||||
|
||||
/*
|
||||
* Create a new hive structure that will hold all the maintenance data.
|
||||
|
@ -459,7 +482,7 @@ HvInitialize(
|
|||
switch (Operation)
|
||||
{
|
||||
case HINIT_CREATE:
|
||||
Status = HvpCreateHive(Hive);
|
||||
Status = HvpCreateHive(Hive, FileName);
|
||||
break;
|
||||
|
||||
case HINIT_MEMORY:
|
||||
|
@ -471,8 +494,8 @@ HvInitialize(
|
|||
break;
|
||||
|
||||
case HINIT_FILE:
|
||||
|
||||
/* Hack of doom: Cluster is actually the file size. */
|
||||
{
|
||||
/* HACK of doom: Cluster is actually the file size. */
|
||||
Status = HvLoadHive(Hive, Cluster);
|
||||
if ((Status != STATUS_SUCCESS) &&
|
||||
(Status != STATUS_REGISTRY_RECOVERED))
|
||||
|
@ -484,6 +507,7 @@ HvInitialize(
|
|||
/* Check for previous damage */
|
||||
if (Status == STATUS_REGISTRY_RECOVERED) ASSERT(FALSE);
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
/* FIXME: A better return status value is needed */
|
||||
|
@ -491,8 +515,7 @@ HvInitialize(
|
|||
ASSERT(FALSE);
|
||||
}
|
||||
|
||||
if (!NT_SUCCESS(Status))
|
||||
return Status;
|
||||
if (!NT_SUCCESS(Status)) return Status;
|
||||
|
||||
if (Operation != HINIT_CREATE) CmPrepareHive(Hive);
|
||||
|
||||
|
|
|
@ -115,7 +115,7 @@ HvpWriteLog(
|
|||
DPRINT("FileFlush failed\n");
|
||||
}
|
||||
|
||||
/* Update first and second update counter and CheckSum. */
|
||||
/* Update second update counter and CheckSum. */
|
||||
RegistryHive->BaseBlock->Sequence2++;
|
||||
RegistryHive->BaseBlock->CheckSum =
|
||||
HvpHiveHeaderChecksum(RegistryHive->BaseBlock);
|
||||
|
|
|
@ -197,7 +197,7 @@ CmpInitializeHive(OUT PCMHIVE *RegistryHive,
|
|||
CmpFileRead,
|
||||
CmpFileFlush,
|
||||
Cluster,
|
||||
(PUNICODE_STRING)FileName);
|
||||
FileName);
|
||||
if (!NT_SUCCESS(Status))
|
||||
{
|
||||
/* Cleanup allocations and fail */
|
||||
|
|
Loading…
Reference in a new issue