From: Hermès Bélusca-Maïto Date: Sun, 2 Feb 2014 16:45:48 +0000 (+0000) Subject: [CMLIB] X-Git-Tag: ReactOS-0.3.16-CLT2014~365 X-Git-Url: https://git.reactos.org/?p=reactos.git;a=commitdiff_plain;h=048856c9cc1501c8eeafd125b38246d8c2dbc71e [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 --- diff --git a/reactos/lib/cmlib/cminit.c b/reactos/lib/cmlib/cminit.c index f923bb4e54b..ee23f85d11c 100644 --- a/reactos/lib/cmlib/cminit.c +++ b/reactos/lib/cmlib/cminit.c @@ -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); diff --git a/reactos/lib/cmlib/cmlib.h b/reactos/lib/cmlib/cmlib.h index cb81c53a5b1..659a64d5454 100644 --- a/reactos/lib/cmlib/cmlib.h +++ b/reactos/lib/cmlib/cmlib.h @@ -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( diff --git a/reactos/lib/cmlib/hivecell.c b/reactos/lib/cmlib/hivecell.c index 3d253a507b0..c4f3db216c3 100644 --- a/reactos/lib/cmlib/hivecell.c +++ b/reactos/lib/cmlib/hivecell.c @@ -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) diff --git a/reactos/lib/cmlib/hivedata.h b/reactos/lib/cmlib/hivedata.h index fc85692407c..d2838fd3442 100644 --- a/reactos/lib/cmlib/hivedata.h +++ b/reactos/lib/cmlib/hivedata.h @@ -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]; diff --git a/reactos/lib/cmlib/hiveinit.c b/reactos/lib/cmlib/hiveinit.c index 7051498202a..1bf7a7582ae 100644 --- a/reactos/lib/cmlib/hiveinit.c +++ b/reactos/lib/cmlib/hiveinit.c @@ -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); diff --git a/reactos/lib/cmlib/hivewrt.c b/reactos/lib/cmlib/hivewrt.c index a5f0c8e8220..330ff81f0ff 100644 --- a/reactos/lib/cmlib/hivewrt.c +++ b/reactos/lib/cmlib/hivewrt.c @@ -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); diff --git a/reactos/ntoskrnl/config/cminit.c b/reactos/ntoskrnl/config/cminit.c index 0f297c61323..897e58460ce 100644 --- a/reactos/ntoskrnl/config/cminit.c +++ b/reactos/ntoskrnl/config/cminit.c @@ -197,7 +197,7 @@ CmpInitializeHive(OUT PCMHIVE *RegistryHive, CmpFileRead, CmpFileFlush, Cluster, - (PUNICODE_STRING)FileName); + FileName); if (!NT_SUCCESS(Status)) { /* Cleanup allocations and fail */