Author: hbelusca
Date: Sun Feb 2 16:45:48 2014
New Revision: 61922
URL:
http://svn.reactos.org/svn/reactos?rev=61922&view=rev
Log:
[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.
Modified:
trunk/reactos/lib/cmlib/cminit.c
trunk/reactos/lib/cmlib/cmlib.h
trunk/reactos/lib/cmlib/hivecell.c
trunk/reactos/lib/cmlib/hivedata.h
trunk/reactos/lib/cmlib/hiveinit.c
trunk/reactos/lib/cmlib/hivewrt.c
trunk/reactos/ntoskrnl/config/cminit.c
Modified: trunk/reactos/lib/cmlib/cminit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/cminit.c?rev=619…
==============================================================================
--- trunk/reactos/lib/cmlib/cminit.c [iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/cminit.c [iso-8859-1] Sun Feb 2 16:45:48 2014
@@ -57,7 +57,7 @@
/* Write the name */
KeyCell->NameLength = (USHORT)NameSize;
- memcpy(KeyCell->Name, Name, NameSize);
+ RtlCopyMemory(KeyCell->Name, Name, NameSize);
/* Return success */
HvReleaseCell(Hive, RootCellIndex);
Modified: trunk/reactos/lib/cmlib/cmlib.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/cmlib.h?rev=6192…
==============================================================================
--- trunk/reactos/lib/cmlib/cmlib.h [iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/cmlib.h [iso-8859-1] Sun Feb 2 16:45:48 2014
@@ -238,7 +238,7 @@
*/
NTSTATUS CMAPI
HvInitialize(
- PHHIVE RegistryHive,
+ PHHIVE RegistryHive,
ULONG Operation,
ULONG HiveType,
ULONG HiveFlags,
@@ -250,7 +250,7 @@
PFILE_READ_ROUTINE FileRead,
PFILE_FLUSH_ROUTINE FileFlush,
ULONG Cluster OPTIONAL,
- PUNICODE_STRING FileName);
+ PCUNICODE_STRING FileName OPTIONAL);
VOID CMAPI
HvFree(
Modified: trunk/reactos/lib/cmlib/hivecell.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/hivecell.c?rev=6…
==============================================================================
--- trunk/reactos/lib/cmlib/hivecell.c [iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/hivecell.c [iso-8859-1] Sun Feb 2 16:45:48 2014
@@ -295,7 +295,7 @@
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)
Modified: trunk/reactos/lib/cmlib/hivedata.h
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/hivedata.h?rev=6…
==============================================================================
--- trunk/reactos/lib/cmlib/hivedata.h [iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/hivedata.h [iso-8859-1] Sun Feb 2 16:45:48 2014
@@ -144,8 +144,9 @@
/* (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];
Modified: trunk/reactos/lib/cmlib/hiveinit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/hiveinit.c?rev=6…
==============================================================================
--- trunk/reactos/lib/cmlib/hiveinit.c [iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/hiveinit.c [iso-8859-1] Sun Feb 2 16:45:48 2014
@@ -29,15 +29,16 @@
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 @@
NTSTATUS CMAPI
HvpCreateHive(
- PHHIVE RegistryHive)
+ PHHIVE RegistryHive,
+ PCUNICODE_STRING FileName OPTIONAL)
{
PHBASE_BLOCK BaseBlock;
ULONG Index;
@@ -99,7 +101,9 @@
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 @@
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 @@
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 @@
switch (Operation)
{
case HINIT_CREATE:
- Status = HvpCreateHive(Hive);
+ Status = HvpCreateHive(Hive, FileName);
break;
case HINIT_MEMORY:
@@ -471,8 +494,8 @@
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 @@
/* 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 @@
ASSERT(FALSE);
}
- if (!NT_SUCCESS(Status))
- return Status;
+ if (!NT_SUCCESS(Status)) return Status;
if (Operation != HINIT_CREATE) CmPrepareHive(Hive);
Modified: trunk/reactos/lib/cmlib/hivewrt.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/lib/cmlib/hivewrt.c?rev=61…
==============================================================================
--- trunk/reactos/lib/cmlib/hivewrt.c [iso-8859-1] (original)
+++ trunk/reactos/lib/cmlib/hivewrt.c [iso-8859-1] Sun Feb 2 16:45:48 2014
@@ -115,7 +115,7 @@
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);
Modified: trunk/reactos/ntoskrnl/config/cminit.c
URL:
http://svn.reactos.org/svn/reactos/trunk/reactos/ntoskrnl/config/cminit.c?r…
==============================================================================
--- trunk/reactos/ntoskrnl/config/cminit.c [iso-8859-1] (original)
+++ trunk/reactos/ntoskrnl/config/cminit.c [iso-8859-1] Sun Feb 2 16:45:48 2014
@@ -197,7 +197,7 @@
CmpFileRead,
CmpFileFlush,
Cluster,
- (PUNICODE_STRING)FileName);
+ FileName);
if (!NT_SUCCESS(Status))
{
/* Cleanup allocations and fail */