* UPDATE HISTORY:
*/
+#ifdef WIN32_REGDBG
+#include "cm_win32.h"
+#else
#include <ddk/ntddk.h>
#include <ddk/ntifs.h>
#include <roscfg.h>
#include <internal/debug.h>
#include "cm.h"
+#endif
{
assert(RootKeyCell);
RtlZeroMemory(RootKeyCell, sizeof(KEY_CELL));
+#ifdef WIN32_REGDBG
+ RootKeyCell->CellSize = -(LONG)sizeof(KEY_CELL);
+#else
RootKeyCell->CellSize = -sizeof(KEY_CELL);
+#endif
RootKeyCell->Id = REG_KEY_CELL_ID;
RootKeyCell->Type = REG_ROOT_KEY_CELL_TYPE;
ZwQuerySystemTime((PTIME) &RootKeyCell->LastWriteTime);
PHBIN tmpBin;
ULONG i, j;
+ IO_STATUS_BLOCK Iosb;
+
+ DPRINT("CmiInitPermanentRegistryHive(%p, %S, %d) - Entered.\n", RegistryHive, Filename, CreateNew);
+
/* Duplicate Filename */
Status = RtlCreateUnicodeString(&RegistryHive->Filename, Filename);
- if (!NT_SUCCESS(Status))
+ if (!NT_SUCCESS(Status)) {
+ DPRINT("CmiInitPermanentRegistryHive() - Failed 1.\n");
return Status;
+ }
InitializeObjectAttributes(&ObjectAttributes,
&RegistryHive->Filename,
if (!NT_SUCCESS(Status))
{
RtlFreeUnicodeString(&RegistryHive->Filename);
+ DPRINT("CmiCreateNewRegFile() - Failed with status %x.\n", Status);
return Status;
}
{
ZwClose(FileHandle);
RtlFreeUnicodeString(&RegistryHive->Filename);
+ DPRINT("CmiInitPermanentRegistryHive() - ObReferenceObjectByHandle Failed with status %x.\n", Status);
return Status;
}
FileOffset.u.HighPart = 0;
FileOffset.u.LowPart = 0;
+ DPRINT(" Attempting to ZwReadFile(%d) for %d bytes into %p\n", FileHandle, sizeof(HIVE_HEADER), RegistryHive->HiveHeader);
Status = ZwReadFile(FileHandle,
0,
0,
0,
- 0,
+// 0,
+ &Iosb,
RegistryHive->HiveHeader,
sizeof(HIVE_HEADER),
&FileOffset,
{
ObDereferenceObject(RegistryHive->FileObject);
RtlFreeUnicodeString(&RegistryHive->Filename);
+ DPRINT("CmiInitPermanentRegistryHive() - Failed 4.\n");
return Status;
}
{
ObDereferenceObject(RegistryHive->FileObject);
RtlFreeUnicodeString(&RegistryHive->Filename);
+ DPRINT("CmiInitPermanentRegistryHive() - Failed 5.\n");
return Status;
}
+
#if 0
/* We have a reference to the file object so we don't need the handle anymore */
ZwClose(FileHandle);
#endif
RegistryHive->FileSize = fsi.EndOfFile.u.LowPart;
+#ifdef WIN32_REGDBG
+// assert(RegistryHive->FileSize);
+ if (RegistryHive->FileSize) {
+ RegistryHive->BlockListSize = (RegistryHive->FileSize / 4096) - 1;
+ } else {
+ ObDereferenceObject(RegistryHive->FileObject);
+ RtlFreeUnicodeString(&RegistryHive->Filename);
+ DPRINT("CmiInitPermanentRegistryHive() - Failed, zero length hive file.\n");
+ return STATUS_INSUFFICIENT_RESOURCES;
+ }
+#else
RegistryHive->BlockListSize = (RegistryHive->FileSize / 4096) - 1;
+#endif
DPRINT("Space needed for block list describing hive: 0x%x\n",
sizeof(PHBIN *) * RegistryHive->BlockListSize);
ExFreePool(RegistryHive->BlockList);
ObDereferenceObject(RegistryHive->FileObject);
RtlFreeUnicodeString(&RegistryHive->Filename);
+ DPRINT("CmiInitPermanentRegistryHive() - Failed 6.\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
ExFreePool(RegistryHive->BlockList);
ObDereferenceObject(RegistryHive->FileObject);
RtlFreeUnicodeString(&RegistryHive->Filename);
+ DPRINT("CmiInitPermanentRegistryHive() - Failed 7.\n");
return Status;
}
RegistryHive->BlockList[0] = ExAllocatePool(PagedPool,
RegistryHive->FileSize - 4096);
+#ifdef WIN32_REGDBG
+ RtlZeroMemory(RegistryHive->BlockList[0], RegistryHive->FileSize - 4096);
+#endif
if (RegistryHive->BlockList[0] == NULL)
{
ExFreePool(RegistryHive->BlockList);
ObDereferenceObject(RegistryHive->FileObject);
RtlFreeUnicodeString(&RegistryHive->Filename);
+ DPRINT("CmiInitPermanentRegistryHive() - Failed 8.\n");
return STATUS_INSUFFICIENT_RESOURCES;
}
FileOffset.u.HighPart = 0;
FileOffset.u.LowPart = 4096;
+ DPRINT(" Attempting to ZwReadFile(%d) for %d bytes into %p\n", FileHandle, RegistryHive->FileSize - 4096, (PVOID)RegistryHive->BlockList[0]);
Status = ZwReadFile(FileHandle,
- 0,
- 0,
- 0,
- 0,
- (PVOID) RegistryHive->BlockList[0],
- RegistryHive->FileSize - 4096,
- &FileOffset,
- 0);
+ 0,
+ 0,
+ 0,
+// 0,
+ &Iosb,
+ (PVOID) RegistryHive->BlockList[0],
+ RegistryHive->FileSize - 4096,
+ &FileOffset,
+ 0);
assertmsg(NT_SUCCESS(Status), ("Status: 0x%X\n", Status));
if (tmpBin->BlockId != REG_BIN_ID)
{
DPRINT("Bad BlockId %x, offset %x\n", tmpBin->BlockId, BlockOffset);
- KeBugCheck(0);
+ //KeBugCheck(0);
+ return STATUS_INSUFFICIENT_RESOURCES;
}
assertmsg((tmpBin->BlockSize % 4096) == 0, ("BlockSize (0x%.08x) must be multiplum of 4K\n", tmpBin->BlockSize));
BlockOffset += tmpBin->BlockSize;
}
+ DPRINT("CmiInitPermanentRegistryHive(%p, %S, %d) - Finished.\n", RegistryHive, Filename, CreateNew);
+
return STATUS_SUCCESS;
}
}
KeInitializeSemaphore(&Hive->RegSem, 1, 1);
+
VERIFY_REGISTRY_HIVE(Hive);
*RegistryHive = Hive;
+ DPRINT("CmiCreateRegistryHive(Filename %S) - Finished.\n", Filename);
+
return(STATUS_SUCCESS);
}
VERIFY_KEY_CELL(KeyCell);
- DPRINT("Scanning for sub key %s\n", KeyName);
+ //DPRINT("Scanning for sub key %s\n", KeyName);
assert(RegistryHive);
*ValueCell = CurValueCell;
if (VBOffset)
*VBOffset = ValueListCell->Values[i];
- DPRINT("Found value %s\n", ValueName);
+ //DPRINT("Found value %s\n", ValueName);
break;
}
CmiReleaseBlock(RegistryHive, CurValueCell);