Author: arty
Date: Sun Apr 29 13:37:17 2007
New Revision: 26579
URL:
http://svn.reactos.org/svn/reactos?rev=26579&view=rev
Log:
Suppress peer warnings about abuse of C++ code (thanks? w3seek)
Added:
branches/powerpc/reactos/tools/mkhive/binhive.cpp
- copied, changed from r26531, branches/powerpc/reactos/tools/mkhive/binhive.c
branches/powerpc/reactos/tools/mkhive/mkhive.cpp
- copied unchanged from r26531, branches/powerpc/reactos/tools/mkhive/mkhive.c
branches/powerpc/reactos/tools/mkhive/reginf.cpp
- copied unchanged from r26531, branches/powerpc/reactos/tools/mkhive/reginf.c
branches/powerpc/reactos/tools/mkhive/registry.cpp
- copied unchanged from r26529, branches/powerpc/reactos/tools/mkhive/registry.c
Removed:
branches/powerpc/reactos/tools/mkhive/binhive.c
branches/powerpc/reactos/tools/mkhive/mkhive.c
branches/powerpc/reactos/tools/mkhive/reginf.c
branches/powerpc/reactos/tools/mkhive/registry.c
Modified:
branches/powerpc/reactos/tools/mkhive/mkhive.mak
Removed: branches/powerpc/reactos/tools/mkhive/binhive.c
URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/mkhive/bi…
==============================================================================
--- branches/powerpc/reactos/tools/mkhive/binhive.c (original)
+++ branches/powerpc/reactos/tools/mkhive/binhive.c (removed)
@@ -1,1440 +1,0 @@
-/*
- * ReactOS kernel
- * Copyright (C) 2003, 2004 ReactOS Team
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-/* $Id$
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS hive maker
- * FILE: tools/mkhive/binhive.c
- * PURPOSE: Binary hive export code
- * PROGRAMMER: Eric Kohl
- */
-
-/* INCLUDES *****************************************************************/
-
-//#include <assert.h>
-#include <stdlib.h>
-#include <stdio.h>
-#include <string.h>
-
-#include "mkhive.h"
-#include "binhive.h"
-#include "registry.h"
-
-using namespace ReactosBytesex;
-
-#define REG_HIVE_ID 0x66676572
-#define REG_BIN_ID 0x6e696268
-#define REG_KEY_CELL_ID 0x6b6e
-#define REG_HASH_TABLE_CELL_ID 0x666c
-#define REG_VALUE_CELL_ID 0x6b76
-
-#define REG_BLOCK_SIZE 4096
-#define REG_HBIN_DATA_OFFSET 32
-#define REG_INIT_BLOCK_LIST_SIZE 32
-#define REG_INIT_HASH_TABLE_SIZE 3
-#define REG_EXTEND_HASH_TABLE_SIZE 4
-#define REG_VALUE_LIST_CELL_MULTIPLE 4
-
-#define ROUND_UP_POW2(N,S) (((N) + (S) - 1) & ~((S) - 1))
-#define ROUND_DOWN_POW2(N,S) ((N) & ~((S) - 1))
-
-#define ABS_VALUE(V) (((V) < 0) ? -(V) : (V))
-
-
-// BLOCK_OFFSET = offset in file after header block
-typedef E_ULONG BLOCK_OFFSET, *PBLOCK_OFFSET;
-
-#ifdef _MSC_VER
-typedef unsigned __int64 FILETIME;
-#else
-typedef unsigned long long FILETIME;
-#endif
-
-#ifdef _MSC_VER
-#pragma pack ( push, hive_header, 1 )
-#endif//_MSC_VER
-
-/* header for registry hive file : */
-typedef struct _HIVE_HEADER
-{
- /* Hive identifier "regf" (0x66676572) */
- E_ULONG BlockId;
-
- /* Update counter */
- E_ULONG UpdateCounter1;
-
- /* Update counter */
- E_ULONG UpdateCounter2;
-
- /* When this hive file was last modified */
- E_FILETIME DateModified;
-
- /* Registry format major version (1) */
- E_ULONG MajorVersion;
-
- /* Registry format minor version (3)
- Version 3 added fast indexes, version 5 has large value optimizations */
- E_ULONG MinorVersion;
-
- /* Registry file type (0 - Primary, 1 - Log) */
- E_ULONG Type;
-
- /* Registry format (1 is the only defined value so far) */
- E_ULONG Format;
-
- /* Offset into file from the byte after the end of the base block.
- If the hive is volatile, this is the actual pointer to the KEY_CELL */
- BLOCK_OFFSET RootKeyOffset;
-
- /* Size of each hive block ? */
- E_ULONG BlockSize;
-
- /* (1?) */
- E_ULONG Unused7;
-
- /* Name of hive file */
- E_WCHAR FileName[32];
-
- E_ULONG Reserved[99];
-
- /* Checksum of first 0x200 bytes */
- E_ULONG Checksum;
-} GCC_PACKED HIVE_HEADER, *PHIVE_HEADER;
-
-typedef struct _HBIN
-{
- /* Bin identifier "hbin" (0x6E696268) */
- E_ULONG HeaderId;
-
- /* Block offset of this bin */
- BLOCK_OFFSET BinOffset;
-
- /* Size in bytes, multiple of the block size (4KB) */
- E_ULONG BinSize;
-
- E_ULONG Reserved[2];
-
- /* When this bin was last modified */
- E_FILETIME DateModified;
-
- /* ? (In-memory only) */
- E_ULONG MemAlloc;
-} GCC_PACKED HBIN, *PHBIN;
-
-typedef struct _CELL_HEADER
-{
- /* <0 if used, >0 if free */
- E_LONG CellSize;
-} GCC_PACKED CELL_HEADER, *PCELL_HEADER;
-
-typedef struct _KEY_CELL
-{
- /* Size of this cell */
- E_LONG CellSize;
-
- /* Key cell identifier "kn" (0x6b6e) */
- E_USHORT Id;
-
- /* ? */
- E_USHORT Type;
-
- /* Time of last flush */
- E_FILETIME LastWriteTime;
-
- /* ? */
- E_ULONG UnUsed1;
-
- /* Block offset of parent key cell */
- BLOCK_OFFSET ParentKeyOffset;
-
- /* Count of sub keys for the key in this key cell */
- E_ULONG NumberOfSubKeys;
-
- /* ? */
- E_ULONG UnUsed2;
-
- /* Block offset of has table for FIXME: subkeys/values? */
- BLOCK_OFFSET HashTableOffset;
-
- /* ? */
- E_ULONG UnUsed3;
-
- /* Count of values contained in this key cell */
- E_ULONG NumberOfValues;
-
- /* Block offset of VALUE_LIST_CELL */
- BLOCK_OFFSET ValueListOffset;
-
- /* Block offset of security cell */
- BLOCK_OFFSET SecurityKeyOffset;
-
- /* Block offset of registry key class */
- BLOCK_OFFSET ClassNameOffset;
-
- /* ? */
- E_ULONG Unused4[5];
-
- /* Size in bytes of key name */
- E_USHORT NameSize;
-
- /* Size of class name in bytes */
- E_USHORT ClassSize;
-
- /* Name of key (not zero terminated) */
- CHAR Name[0];
-} GCC_PACKED KEY_CELL, *PKEY_CELL;
-
-/* KEY_CELL.Type constants */
-#define REG_LINK_KEY_CELL_TYPE 0x10
-#define REG_KEY_CELL_TYPE 0x20
-#define REG_ROOT_KEY_CELL_TYPE 0x2c
-
-
-// hash record :
-// HashValue=four letters of value's name
-typedef struct _HASH_RECORD
-{
- BLOCK_OFFSET KeyOffset;
- E_ULONG HashValue;
-} GCC_PACKED HASH_RECORD, *PHASH_RECORD;
-
-typedef struct _HASH_TABLE_CELL
-{
- E_LONG CellSize;
- E_USHORT Id;
- E_USHORT HashTableSize;
- HASH_RECORD Table[0];
-} GCC_PACKED HASH_TABLE_CELL, *PHASH_TABLE_CELL;
-
-typedef struct _VALUE_LIST_CELL
-{
- E_LONG CellSize;
- BLOCK_OFFSET ValueOffset[0];
-} GCC_PACKED VALUE_LIST_CELL, *PVALUE_LIST_CELL;
-
-typedef struct _VALUE_CELL
-{
- E_LONG CellSize;
- E_USHORT Id; // "kv"
- E_USHORT NameSize; // length of Name
- E_ULONG DataSize; // length of datas in the cell pointed by DataOffset
- BLOCK_OFFSET DataOffset;// datas are here if high bit of DataSize is set
- E_ULONG DataType;
- E_USHORT Flags;
- E_USHORT Unused1;
- CHAR Name[0]; /* warning : not zero terminated */
-} GCC_PACKED VALUE_CELL, *PVALUE_CELL;
-
-/* VALUE_CELL.Flags constants */
-#define REG_VALUE_NAME_PACKED 0x0001
-
-/* VALUE_CELL.DataSize mask constants */
-#define REG_DATA_SIZE_MASK 0x7FFFFFFF
-#define REG_DATA_IN_OFFSET 0x80000000
-
-typedef struct _DATA_CELL
-{
- E_LONG CellSize;
- CHAR Data[0];
-} GCC_PACKED DATA_CELL, *PDATA_CELL;
-
-#ifdef _MSC_VER
-#pragma pack ( pop, hive_header )
-#endif//_MSC_VER
-
-typedef struct _REGISTRY_HIVE
-{
- ULONG FileSize;
- PHIVE_HEADER HiveHeader;
- ULONG BlockListSize;
- PHBIN *BlockList;
- ULONG FreeListSize;
- ULONG FreeListMax;
- PCELL_HEADER *FreeList;
- BLOCK_OFFSET *FreeListOffset;
-} REGISTRY_HIVE, *PREGISTRY_HIVE;
-
-/* FUNCTIONS ****************************************************************/
-
-static VOID
-memexpand (PWCHAR Dst,
- PCHAR Src,
- ULONG Length)
-{
- ULONG i;
- E_WCHAR *DstE = (E_WCHAR*)Dst;
-
- for (i = 0; i < Length; i++)
- DstE[i] = (WCHAR)Src[i];
-}
-
-
-static VOID
-CmiCreateDefaultHiveHeader (PHIVE_HEADER Header)
-{
- assert (Header);
- memset (Header, 0, REG_BLOCK_SIZE);
- Header->BlockId = REG_HIVE_ID;
- Header->UpdateCounter1 = 0;
- Header->UpdateCounter2 = 0;
- Header->DateModified = 0;
- Header->MajorVersion = 1;
- Header->MinorVersion = 3;
- Header->Type = 0;
- Header->Format = 1;
- Header->Unused7 = 1;
- Header->RootKeyOffset = -1;
- Header->BlockSize = REG_BLOCK_SIZE;
- Header->Checksum = 0;
-}
-
-
-static VOID
-CmiCreateDefaultBinCell(PHBIN BinCell)
-{
- assert (BinCell);
- memset (BinCell, 0, REG_BLOCK_SIZE);
- BinCell->HeaderId = REG_BIN_ID;
- BinCell->DateModified = 0;
- BinCell->BinSize = REG_BLOCK_SIZE;
-}
-
-
-static VOID
-CmiCreateDefaultRootKeyCell(PKEY_CELL RootKeyCell, PCHAR KeyName)
-{
- PCHAR BaseKeyName;
- USHORT NameSize;
- ULONG CellSize;
-
- assert (RootKeyCell);
-
- BaseKeyName = strrchr(KeyName, '\\') + 1;
- NameSize = strlen(BaseKeyName);
- CellSize = ROUND_UP_POW2(sizeof(KEY_CELL) + NameSize - 1, 16);
-
- memset (RootKeyCell, 0, CellSize);
- RootKeyCell->CellSize = (ULONG)-(LONG)CellSize;
- RootKeyCell->Id = REG_KEY_CELL_ID;
- RootKeyCell->Type = REG_ROOT_KEY_CELL_TYPE;
- RootKeyCell->LastWriteTime = 0;
- RootKeyCell->ParentKeyOffset = 0;
- RootKeyCell->NumberOfSubKeys = 0;
- RootKeyCell->HashTableOffset = -1;
- RootKeyCell->NumberOfValues = 0;
- RootKeyCell->ValueListOffset = -1;
- RootKeyCell->SecurityKeyOffset = 0;
- RootKeyCell->ClassNameOffset = -1;
- RootKeyCell->NameSize = NameSize;
- RootKeyCell->ClassSize = 0;
- memcpy (RootKeyCell->Name,
- BaseKeyName,
- NameSize);
-}
-
-
-static PREGISTRY_HIVE
-CmiCreateRegistryHive (PCHAR KeyName)
-{
- PREGISTRY_HIVE Hive;
- PCELL_HEADER FreeCell;
- PKEY_CELL RootKeyCell;
- PHBIN BinCell;
-
- Hive = (PREGISTRY_HIVE) malloc (sizeof(REGISTRY_HIVE));
- if (Hive == NULL)
- {
- return NULL;
- }
- memset (Hive, 0, sizeof(REGISTRY_HIVE));
-
- DPRINT("Hive %p\n", Hive);
-
- /* Create hive beader (aka 'base block') */
- Hive->HiveHeader = (PHIVE_HEADER) malloc (REG_BLOCK_SIZE);
- if (Hive->HiveHeader == NULL)
- {
- free (Hive);
- return NULL;
- }
- CmiCreateDefaultHiveHeader (Hive->HiveHeader);
- Hive->FileSize = REG_BLOCK_SIZE;
-
- /* Allocate block list */
- Hive->BlockListSize = 1;
- Hive->BlockList = (PHBIN*)malloc (sizeof(PHBIN) * Hive->BlockListSize);
- if (Hive->BlockList == NULL)
- {
- free (Hive->HiveHeader);
- free (Hive);
- return NULL;
- }
-
- /* Allocate free cell list */
- Hive->FreeListMax = 32;
- Hive->FreeList = (PCELL_HEADER*)malloc(sizeof(PCELL_HEADER) *
Hive->FreeListMax);
- if (Hive->FreeList == NULL)
- {
- free (Hive->BlockList);
- free (Hive->HiveHeader);
- free (Hive);
- return NULL;
- }
- Hive->FreeListOffset = (PBLOCK_OFFSET)malloc(sizeof(BLOCK_OFFSET) *
Hive->FreeListMax);
- if (Hive->FreeListOffset == NULL)
- {
- free (Hive->FreeList);
- free (Hive->BlockList);
- free (Hive->HiveHeader);
- free (Hive);
- return NULL;
- }
-
- /* Allocate first bin */
- Hive->BlockList[0] = (PHBIN) malloc (REG_BLOCK_SIZE);
- if (Hive->BlockList[0] == NULL)
- {
- free (Hive->FreeListOffset);
- free (Hive->FreeList);
- free (Hive->BlockList);
- free (Hive->HiveHeader);
- free (Hive);
- return NULL;
- }
- Hive->FileSize += REG_BLOCK_SIZE;
-
- /* Init first bin */
- BinCell = (PHBIN)Hive->BlockList[0];
- CmiCreateDefaultBinCell (BinCell);
- BinCell->BinOffset = 0;
-
- /* Init root key cell */
- RootKeyCell = (PKEY_CELL)((ULONG_PTR)BinCell + REG_HBIN_DATA_OFFSET);
- CmiCreateDefaultRootKeyCell (RootKeyCell, KeyName);
- Hive->HiveHeader->RootKeyOffset = REG_HBIN_DATA_OFFSET;
-
- /* Init free cell */
- FreeCell = (PCELL_HEADER)((ULONG_PTR)RootKeyCell - RootKeyCell->CellSize);
- FreeCell->CellSize = REG_BLOCK_SIZE - (REG_HBIN_DATA_OFFSET -
RootKeyCell->CellSize);
-
- Hive->FreeList[0] = FreeCell;
- Hive->FreeListOffset[0] = REG_HBIN_DATA_OFFSET - RootKeyCell->CellSize;
- Hive->FreeListSize++;
-
- return Hive;
-}
-
-
-static VOID
-CmiDestroyRegistryHive (PREGISTRY_HIVE Hive)
-{
- PHBIN Bin;
- ULONG i;
-
- if (Hive == NULL)
- return;
-
- /* Release free offset list */
- if (Hive->FreeListOffset != NULL)
- free (Hive->FreeListOffset);
-
- /* Release free list */
- if (Hive->FreeList != NULL)
- free (Hive->FreeList);
-
- if (Hive->BlockList != NULL)
- {
- /* Release bins */
- Bin = NULL;
- for (i = 0; i < Hive->BlockListSize; i++)
- {
- if ((Hive->BlockList[i] != NULL) &&
- (Hive->BlockList[i] != Bin))
- {
- Bin = Hive->BlockList[i];
-
- DPRINT ("Bin[%lu]: Offset 0x%lx Size 0x%lx\n",
- i, Bin->BinOffset, Bin->BinSize);
-
- free (Bin);
- }
- }
-
- /* Release block list */
- free (Hive->BlockList);
- }
-
- /* Release hive header */
- if (Hive->HiveHeader != NULL)
- free (Hive->HiveHeader);
-
- /* Release hive */
- free (Hive);
-}
-
-
-static PVOID
-CmiGetCell (PREGISTRY_HIVE Hive,
- BLOCK_OFFSET BlockOffset,
- PHBIN * ppBin)
-{
- PHBIN pBin;
- ULONG BlockIndex;
-
- if (ppBin)
- *ppBin = NULL;
-
- if (BlockOffset == (ULONG_PTR) -1)
- return NULL;
-
- BlockIndex = BlockOffset / 4096;
- if (BlockIndex >= Hive->BlockListSize)
- return NULL;
-
- pBin = Hive->BlockList[BlockIndex];
- if (ppBin)
- *ppBin = pBin;
-
- return (PVOID)((ULONG_PTR)pBin + (BlockOffset - pBin->BinOffset));
-}
-
-
-static BOOL
-CmiMergeFree(PREGISTRY_HIVE RegistryHive,
- PCELL_HEADER FreeBlock,
- BLOCK_OFFSET FreeOffset)
-{
- BLOCK_OFFSET BlockOffset;
- BLOCK_OFFSET BinOffset;
- ULONG BlockSize;
- ULONG BinSize;
- PHBIN Bin;
- ULONG i;
-
- DPRINT("CmiMergeFree(Block %p Offset %lx Size %lx) called\n",
- FreeBlock, FreeOffset, FreeBlock->CellSize);
-
- CmiGetCell (RegistryHive,
- FreeOffset,
- &Bin);
- DPRINT("Bin %p\n", Bin);
- if (Bin == NULL)
- return FALSE;
-
- BinOffset = Bin->BinOffset;
- BinSize = Bin->BinSize;
- DPRINT("Bin %p Offset %lx Size %lx\n", Bin, BinOffset, BinSize);
-
- for (i = 0; i < RegistryHive->FreeListSize; i++)
- {
- BlockOffset = RegistryHive->FreeListOffset[i];
- BlockSize = RegistryHive->FreeList[i]->CellSize;
- if (BlockOffset > BinOffset &&
- BlockOffset < BinOffset + BinSize)
- {
- DPRINT("Free block: Offset %lx Size %lx\n",
- BlockOffset, BlockSize);
-
- if ((i < (RegistryHive->FreeListSize - 1)) &&
- (BlockOffset + BlockSize == FreeOffset) &&
- (FreeOffset + FreeBlock->CellSize == RegistryHive->FreeListOffset[i + 1]))
- {
- DPRINT("Merge current block with previous and next block\n");
-
- RegistryHive->FreeList[i]->CellSize +=
- (FreeBlock->CellSize + RegistryHive->FreeList[i + 1]->CellSize);
-
- FreeBlock->CellSize = 0;
- RegistryHive->FreeList[i + 1]->CellSize = 0;
-
-
- if ((i + 2) < RegistryHive->FreeListSize)
- {
- memmove (&RegistryHive->FreeList[i + 1],
- &RegistryHive->FreeList[i + 2],
- sizeof(RegistryHive->FreeList[0])
- * (RegistryHive->FreeListSize - i - 2));
- memmove (&RegistryHive->FreeListOffset[i + 1],
- &RegistryHive->FreeListOffset[i + 2],
- sizeof(RegistryHive->FreeListOffset[0])
- * (RegistryHive->FreeListSize - i - 2));
- }
- RegistryHive->FreeListSize--;
-
- return TRUE;
- }
- else if (BlockOffset + BlockSize == FreeOffset)
- {
- DPRINT("Merge current block with previous block\n");
-
- RegistryHive->FreeList[i]->CellSize += FreeBlock->CellSize;
- FreeBlock->CellSize = 0;
-
- return TRUE;
- }
- else if (FreeOffset + FreeBlock->CellSize == BlockOffset)
- {
- DPRINT("Merge current block with next block\n");
-
- FreeBlock->CellSize += RegistryHive->FreeList[i]->CellSize;
- RegistryHive->FreeList[i]->CellSize = 0;
- RegistryHive->FreeList[i] = FreeBlock;
- RegistryHive->FreeListOffset[i] = FreeOffset;
-
- return TRUE;
- }
- }
- }
-
- return FALSE;
-}
-
-
-static BOOL
-CmiAddFree(PREGISTRY_HIVE RegistryHive,
- PCELL_HEADER FreeBlock,
- BLOCK_OFFSET FreeOffset,
- BOOL MergeFreeBlocks)
-{
- PCELL_HEADER *tmpList;
- BLOCK_OFFSET *tmpListOffset;
- LONG minInd;
- LONG maxInd;
- LONG medInd;
-
- assert(RegistryHive);
- assert(FreeBlock);
-
- DPRINT("FreeBlock %p FreeOffset %.08lx\n",
- FreeBlock, FreeOffset);
-
- /* Merge free blocks */
- if (MergeFreeBlocks == TRUE)
- {
- if (CmiMergeFree(RegistryHive, FreeBlock, FreeOffset))
- return TRUE;
- }
-
- if ((RegistryHive->FreeListSize + 1) > RegistryHive->FreeListMax)
- {
- tmpList = (PCELL_HEADER*)malloc (sizeof(PCELL_HEADER) * (RegistryHive->FreeListMax +
32));
- if (tmpList == NULL)
- {
- return FALSE;
- }
-
- tmpListOffset = (PBLOCK_OFFSET)malloc (sizeof(BLOCK_OFFSET) *
(RegistryHive->FreeListMax + 32));
- if (tmpListOffset == NULL)
- {
- free (tmpList);
- return FALSE;
- }
-
- if (RegistryHive->FreeListMax)
- {
- memmove (tmpList,
- RegistryHive->FreeList,
- sizeof(PCELL_HEADER) * (RegistryHive->FreeListMax));
- memmove (tmpListOffset,
- RegistryHive->FreeListOffset,
- sizeof(BLOCK_OFFSET) * (RegistryHive->FreeListMax));
- free (RegistryHive->FreeList);
- free (RegistryHive->FreeListOffset);
- }
- RegistryHive->FreeList = tmpList;
- RegistryHive->FreeListOffset = tmpListOffset;
- RegistryHive->FreeListMax += 32;
- }
-
- /* Add new offset to free list, maintaining list in ascending order */
- if ((RegistryHive->FreeListSize == 0)
- || (RegistryHive->FreeListOffset[RegistryHive->FreeListSize-1] <
FreeOffset))
- {
- /* Add to end of list */
- RegistryHive->FreeList[RegistryHive->FreeListSize] = FreeBlock;
- RegistryHive->FreeListOffset[RegistryHive->FreeListSize++] = FreeOffset;
- }
- else if (RegistryHive->FreeListOffset[0] > FreeOffset)
- {
- /* Add to begin of list */
- memmove (&RegistryHive->FreeList[1],
- &RegistryHive->FreeList[0],
- sizeof(RegistryHive->FreeList[0]) * RegistryHive->FreeListSize);
- memmove (&RegistryHive->FreeListOffset[1],
- &RegistryHive->FreeListOffset[0],
- sizeof(RegistryHive->FreeListOffset[0]) * RegistryHive->FreeListSize);
- RegistryHive->FreeList[0] = FreeBlock;
- RegistryHive->FreeListOffset[0] = FreeOffset;
- RegistryHive->FreeListSize++;
- }
- else
- {
- /* Search where to insert */
- minInd = 0;
- maxInd = RegistryHive->FreeListSize - 1;
- while ((maxInd - minInd) > 1)
- {
- medInd = (minInd + maxInd) / 2;
- if (RegistryHive->FreeListOffset[medInd] > FreeOffset)
- maxInd = medInd;
- else
- minInd = medInd;
- }
-
- /* Insert before maxInd */
- memmove (&RegistryHive->FreeList[maxInd+1],
- &RegistryHive->FreeList[maxInd],
- sizeof(RegistryHive->FreeList[0]) * (RegistryHive->FreeListSize -
minInd));
- memmove (&RegistryHive->FreeListOffset[maxInd + 1],
- &RegistryHive->FreeListOffset[maxInd],
- sizeof(RegistryHive->FreeListOffset[0]) *
(RegistryHive->FreeListSize-minInd));
- RegistryHive->FreeList[maxInd] = FreeBlock;
- RegistryHive->FreeListOffset[maxInd] = FreeOffset;
- RegistryHive->FreeListSize++;
- }
-
- return TRUE;
-}
-
-
-static BOOL
-CmiAddBin(PREGISTRY_HIVE RegistryHive,
- ULONG BlockCount,
- PVOID *NewBlock,
- PBLOCK_OFFSET NewBlockOffset)
-{
- PCELL_HEADER tmpBlock;
- PHBIN * tmpBlockList;
- PHBIN tmpBin;
- ULONG BinSize;
- ULONG i;
-
- BinSize = BlockCount *REG_BLOCK_SIZE;
- tmpBin = (PHBIN)malloc (BinSize);
- if (tmpBin == NULL)
- {
- return FALSE;
- }
- memset (tmpBin, 0, BinSize);
-
- tmpBin->HeaderId = REG_BIN_ID;
- tmpBin->BinOffset = RegistryHive->FileSize - REG_BLOCK_SIZE;
- RegistryHive->FileSize += BinSize;
- tmpBin->BinSize = BinSize;
- tmpBin->DateModified = 0;
- tmpBin->MemAlloc = 0;
-
- /* Increase size of list of blocks */
- tmpBlockList = (PHBIN *)malloc (sizeof(PHBIN) * (RegistryHive->BlockListSize +
BlockCount));
- if (tmpBlockList == NULL)
- {
- free (tmpBin);
- return FALSE;
- }
-
- if (RegistryHive->BlockListSize > 0)
- {
- memcpy (tmpBlockList,
- RegistryHive->BlockList,
- sizeof(PHBIN) * RegistryHive->BlockListSize);
- free (RegistryHive->BlockList);
- }
-
- RegistryHive->BlockList = tmpBlockList;
- for (i = 0; i < BlockCount; i++)
- RegistryHive->BlockList[RegistryHive->BlockListSize + i] = tmpBin;
- RegistryHive->BlockListSize += BlockCount;
-
- /* Initialize a free block in this heap : */
- tmpBlock = (PCELL_HEADER)((ULONG_PTR) tmpBin + REG_HBIN_DATA_OFFSET);
- tmpBlock->CellSize = (REG_BLOCK_SIZE - REG_HBIN_DATA_OFFSET);
-
- *NewBlock = (PVOID) tmpBlock;
-
- if (NewBlockOffset)
- *NewBlockOffset = tmpBin->BinOffset + REG_HBIN_DATA_OFFSET;
-
- return TRUE;
-}
-
-
-static BOOL
-CmiAllocateCell (PREGISTRY_HIVE RegistryHive,
- LONG CellSize,
- PVOID *Block,
- PBLOCK_OFFSET pBlockOffset)
-{
- PCELL_HEADER NewBlock;
- ULONG i;
-
- *Block = NULL;
-
- /* Round to 16 bytes multiple */
- CellSize = ROUND_UP_POW2(CellSize, 16);
-
- /* first search in free blocks */
- NewBlock = NULL;
- for (i = 0; i < RegistryHive->FreeListSize; i++)
- {
- if (RegistryHive->FreeList[i]->CellSize >= CellSize)
- {
- NewBlock = RegistryHive->FreeList[i];
- if (pBlockOffset)
- *pBlockOffset = RegistryHive->FreeListOffset[i];
-
- if ((i + 1) < RegistryHive->FreeListSize)
- {
- memmove (&RegistryHive->FreeList[i],
- &RegistryHive->FreeList[i + 1],
- sizeof(RegistryHive->FreeList[0])
- * (RegistryHive->FreeListSize - i - 1));
- memmove (&RegistryHive->FreeListOffset[i],
- &RegistryHive->FreeListOffset[i + 1],
- sizeof(RegistryHive->FreeListOffset[0])
- * (RegistryHive->FreeListSize - i - 1));
- }
- RegistryHive->FreeListSize--;
- break;
- }
- }
-
- /* Need to extend hive file : */
- if (NewBlock == NULL)
- {
- /* Add a new block */
- if (!CmiAddBin(RegistryHive,
- ((sizeof(HBIN) + CellSize - 1) / REG_BLOCK_SIZE) + 1,
- (PVOID *)&NewBlock,
- pBlockOffset))
- return FALSE;
- }
-
- *Block = NewBlock;
-
- /* Split the block in two parts */
- if (NewBlock->CellSize > CellSize)
- {
- NewBlock = (PCELL_HEADER) ((ULONG_PTR) NewBlock + CellSize);
- NewBlock->CellSize = ((PCELL_HEADER) (*Block))->CellSize - CellSize;
- ((PCELL_HEADER) (*Block))->CellSize = CellSize;
- BLOCK_OFFSET NewFree;
- NewFree = *pBlockOffset + CellSize;
- CmiAddFree (RegistryHive,
- NewBlock,
- NewFree,
- TRUE);
- }
- else if (NewBlock->CellSize < CellSize)
- {
- return FALSE;
- }
-
- memset((PVOID)((ULONG_PTR)*Block + sizeof(CELL_HEADER)), 0,
- CellSize - sizeof(CELL_HEADER));
- ((PCELL_HEADER)(*Block))->CellSize *= -1;
-
- return TRUE;
-}
-
-
-static BOOL
-CmiAllocateHashTableCell (PREGISTRY_HIVE Hive,
- PBLOCK_OFFSET HBOffset,
- USHORT SubKeyCount)
-{
- PHASH_TABLE_CELL HashCell;
- ULONG NewHashSize;
- BOOL Status;
-
- NewHashSize = sizeof(HASH_TABLE_CELL) +
- (SubKeyCount * sizeof(HASH_RECORD));
- Status = CmiAllocateCell (Hive,
- NewHashSize,
- (PVOID*) &HashCell,
- HBOffset);
- if ((HashCell == NULL) || (Status == FALSE))
- {
- return FALSE;
- }
-
- HashCell->Id = REG_HASH_TABLE_CELL_ID;
- HashCell->HashTableSize = SubKeyCount;
-
- return TRUE;
-}
-
-
-static BOOL
-CmiAddKeyToParentHashTable (PREGISTRY_HIVE Hive,
- BLOCK_OFFSET ParentKeyOffset,
- PKEY_CELL NewKeyCell,
- BLOCK_OFFSET NKBOffset)
-{
- PHASH_TABLE_CELL HashBlock;
- PKEY_CELL ParentKeyCell;
- ULONG i;
-
- ParentKeyCell = (PKEY_CELL)CmiGetCell (Hive,
- ParentKeyOffset,
- NULL);
- if (ParentKeyCell == NULL)
- {
- DPRINT1 ("CmiGetBlock() failed\n");
- return FALSE;
- }
-
- HashBlock = (PHASH_TABLE_CELL)CmiGetCell (Hive,
- ParentKeyCell->HashTableOffset,
- NULL);
- if (HashBlock == NULL)
- {
- DPRINT1 ("CmiGetBlock() failed\n");
- return FALSE;
- }
-
- for (i = 0; i < HashBlock->HashTableSize; i++)
- {
- if (HashBlock->Table[i].KeyOffset == 0)
- {
- HashBlock->Table[i].KeyOffset = NKBOffset;
- memcpy (&HashBlock->Table[i].HashValue,
- NewKeyCell->Name,
- 4);
- ParentKeyCell->NumberOfSubKeys++;
- return TRUE;
- }
- }
-
- return FALSE;
-}
-
-
-static BOOL
-CmiAllocateValueListCell (PREGISTRY_HIVE Hive,
- PBLOCK_OFFSET ValueListOffset,
- ULONG ValueCount)
-{
- PVALUE_LIST_CELL ValueListCell;
- ULONG ValueListSize;
- BOOL Status;
-
- ValueListSize = sizeof(VALUE_LIST_CELL) +
- (ValueCount * sizeof(BLOCK_OFFSET));
- Status = CmiAllocateCell (Hive,
- ValueListSize,
- (PVOID*)&ValueListCell,
- ValueListOffset);
- if ((ValueListCell == NULL) || (Status == FALSE))
- {
- DPRINT1 ("CmiAllocateBlock() failed\n");
- return FALSE;
- }
-
- return TRUE;
-}
-
-
-static BOOL
-CmiAllocateValueCell(PREGISTRY_HIVE Hive,
- PVALUE_CELL *ValueCell,
- BLOCK_OFFSET *ValueCellOffset,
- PCHAR ValueName)
-{
- PVALUE_CELL NewValueCell;
- USHORT NameSize;
- BOOL Status;
-
- NameSize = (ValueName == NULL) ? 0 : strlen (ValueName);
- Status = CmiAllocateCell (Hive,
- sizeof(VALUE_CELL) + NameSize,
- (PVOID*)&NewValueCell,
- ValueCellOffset);
- if ((NewValueCell == NULL) || (Status == FALSE))
- {
- DPRINT1 ("CmiAllocateBlock() failed\n");
- return FALSE;
- }
-
- NewValueCell->Id = REG_VALUE_CELL_ID;
- NewValueCell->NameSize = NameSize;
- if (NameSize > 0)
- {
- memcpy (NewValueCell->Name,
- ValueName,
- NameSize);
- NewValueCell->Flags = REG_VALUE_NAME_PACKED;
- }
- NewValueCell->DataType = 0;
- NewValueCell->DataSize = 0;
- NewValueCell->DataOffset = -1;
-
- *ValueCell = NewValueCell;
-
- return TRUE;
-}
-
-
-static BOOL
-CmiAddValueToKeyValueList(PREGISTRY_HIVE Hive,
- BLOCK_OFFSET KeyCellOffset,
- BLOCK_OFFSET ValueCellOffset)
-{
- PVALUE_LIST_CELL ValueListCell;
- PKEY_CELL KeyCell;
-
- KeyCell = (PKEY_CELL)CmiGetCell (Hive, KeyCellOffset, NULL);
- if (KeyCell == NULL)
- {
- DPRINT1 ("CmiGetBlock() failed\n");
- return FALSE;
- }
-
- ValueListCell = (PVALUE_LIST_CELL)CmiGetCell (Hive, KeyCell->ValueListOffset,
NULL);
- if (ValueListCell == NULL)
- {
- DPRINT1 ("CmiGetBlock() failed\n");
- return FALSE;
- }
-
- ValueListCell->ValueOffset[KeyCell->NumberOfValues] = ValueCellOffset;
- KeyCell->NumberOfValues++;
-
- return TRUE;
-}
-
-
-static BOOL
-CmiExportValue (PREGISTRY_HIVE Hive,
- BLOCK_OFFSET KeyCellOffset,
- HKEY Key,
- PVALUE Value)
-{
- BLOCK_OFFSET ValueCellOffset;
- BLOCK_OFFSET DataCellOffset;
- PVALUE_CELL ValueCell;
- PDATA_CELL DataCell;
- ULONG SrcDataSize;
- ULONG DstDataSize;
- ULONG DataType;
- PCHAR Data;
- BOOL Expand = FALSE;
-
- DPRINT ("CmiExportValue('%s') called\n", (Value == NULL) ?
"<default>" : (PCHAR)Value->Name);
- DPRINT ("DataSize %lu\n", (Value == NULL) ? Key->DataSize :
Value->DataSize);
-
- /* Allocate value cell */
- if (!CmiAllocateValueCell(Hive, &ValueCell, &ValueCellOffset, (Value == NULL) ?
NULL : Value->Name))
- {
- return FALSE;
- }
-
- if (!CmiAddValueToKeyValueList(Hive, KeyCellOffset, ValueCellOffset))
- {
- return FALSE;
- }
-
- if (Value == NULL)
- {
- DataType = Key->DataType;
- SrcDataSize = Key->DataSize;
- Data = Key->Data;
- }
- else
- {
- DataType = Value->DataType;
- SrcDataSize = Value->DataSize;
- Data = Value->Data;
- }
-
- DstDataSize = SrcDataSize;
- if (DataType == REG_SZ ||
- DataType == REG_EXPAND_SZ ||
- DataType == REG_MULTI_SZ)
- {
- DstDataSize *= sizeof(WCHAR);
- Expand = TRUE;
- }
-
- if ((DstDataSize & REG_DATA_SIZE_MASK) <= sizeof(BLOCK_OFFSET))
- {
- ValueCell->DataSize = DstDataSize | REG_DATA_IN_OFFSET;
- ValueCell->DataType = DataType;
- if (Expand)
- {
- memexpand ((PWCHAR)&ValueCell->DataOffset,
- (PCHAR)&Data,
- SrcDataSize);
- }
- else
- {
- memcpy (&ValueCell->DataOffset,
- &Data,
- SrcDataSize);
- }
- }
- else
- {
- /* Allocate data cell */
- if (!CmiAllocateCell (Hive,
- sizeof(CELL_HEADER) + DstDataSize,
- (PVOID *)&DataCell,
- &DataCellOffset))
- {
- return FALSE;
- }
-
- ValueCell->DataOffset = DataCellOffset;
- ValueCell->DataSize = DstDataSize & REG_DATA_SIZE_MASK;
- ValueCell->DataType = DataType;
-
- if (Expand)
- {
- if (SrcDataSize <= sizeof(BLOCK_OFFSET))
- {
- memexpand ((PWCHAR)DataCell->Data,
- (PCHAR)&Data,
- SrcDataSize);
- }
- else
- {
- memexpand ((PWCHAR)DataCell->Data,
- Data,
- SrcDataSize);
- }
- }
- else
- {
- memcpy (DataCell->Data,
- Data,
- SrcDataSize);
- }
- }
-
- return TRUE;
-}
-
-
-static BOOL
-CmiExportSubKey (PREGISTRY_HIVE Hive,
- BLOCK_OFFSET ParentKeyOffset,
- HKEY ParentKey,
- HKEY Key)
-{
- BLOCK_OFFSET NKBOffset;
- PKEY_CELL NewKeyCell;
- ULONG KeyCellSize;
- USHORT SubKeyCount;
- ULONG ValueCount;
- PLIST_ENTRY Entry;
- HKEY SubKey;
- PVALUE Value;
-
- DPRINT ("CmiExportSubKey('%s') called\n", Key->Name);
-
- /* Don't export links */
- if (Key->DataType == REG_LINK)
- return TRUE;
-
- /* Allocate key cell */
- KeyCellSize = sizeof(KEY_CELL) + Key->NameSize - 1;
- if (!CmiAllocateCell (Hive, KeyCellSize, (PVOID*)&NewKeyCell, &NKBOffset))
- {
- DPRINT1 ("CmiAllocateBlock() failed\n");
- return FALSE;
- }
-
- /* Initialize key cell */
- NewKeyCell->Id = REG_KEY_CELL_ID;
- NewKeyCell->Type = REG_KEY_CELL_TYPE;
- NewKeyCell->LastWriteTime = 0;
- NewKeyCell->ParentKeyOffset = ParentKeyOffset;
- NewKeyCell->NumberOfSubKeys = 0;
- NewKeyCell->HashTableOffset = -1;
- NewKeyCell->NumberOfValues = 0;
- NewKeyCell->ValueListOffset = -1;
- NewKeyCell->SecurityKeyOffset = -1;
- NewKeyCell->NameSize = Key->NameSize - 1;
- NewKeyCell->ClassNameOffset = -1;
- memcpy (NewKeyCell->Name,
- Key->Name,
- Key->NameSize - 1);
-
- /* Add key cell to the parent key's hash table */
- if (!CmiAddKeyToParentHashTable (Hive,
- ParentKeyOffset,
- NewKeyCell,
- NKBOffset))
- {
- DPRINT1 ("CmiAddKeyToParentHashTable() failed\n");
- return FALSE;
- }
-
- ValueCount = RegGetValueCount (Key);
- DPRINT ("ValueCount: %lu\n", ValueCount);
- if (ValueCount > 0)
- {
- /* Allocate value list cell */
- CmiAllocateValueListCell (Hive,
- &NewKeyCell->ValueListOffset,
- ValueCount);
-
- if (Key->DataSize != 0)
- {
- if (!CmiExportValue (Hive, NKBOffset, Key, NULL))
- return FALSE;
- }
-
- /* Enumerate values */
- Entry = Key->ValueList.Flink;
- while (Entry != &Key->ValueList)
- {
- Value = CONTAINING_RECORD(Entry,
- VALUE,
- ValueList);
-
- if (!CmiExportValue (Hive, NKBOffset, Key, Value))
- return FALSE;
-
- Entry = Entry->Flink;
- }
- }
-
- SubKeyCount = RegGetSubKeyCount (Key);
- DPRINT ("SubKeyCount: %lu\n", SubKeyCount);
- if (SubKeyCount > 0)
- {
- /* Allocate hash table cell */
- CmiAllocateHashTableCell (Hive,
- &NewKeyCell->HashTableOffset,
- SubKeyCount);
-
- /* Enumerate subkeys */
- Entry = Key->SubKeyList.Flink;
- while (Entry != &Key->SubKeyList)
- {
- SubKey = CONTAINING_RECORD(Entry,
- KEY,
- KeyList);
-
- if (!CmiExportSubKey (Hive, NKBOffset, Key, SubKey))
- return FALSE;
-
- Entry = Entry->Flink;
- }
- }
-
- return TRUE;
-}
-
-
-static VOID
-CmiCalcHiveChecksum (PREGISTRY_HIVE Hive)
-{
- PULONG Buffer;
- ULONG Sum;
- ULONG i;
-
- Buffer = (PULONG)Hive->HiveHeader;
- Sum = 0;
- for (i = 0; i < 127; i++)
- Sum ^= Buffer[i];
- if (Sum == (ULONG)-1)
- Sum = (ULONG)-2;
- if (Sum == 0)
- Sum = 1;
-
- Hive->HiveHeader->Checksum = Sum;
-}
-
-
-BOOL
-CmiExportHive (PREGISTRY_HIVE Hive,
- PCHAR KeyName)
-{
- PKEY_CELL KeyCell;
- HKEY Key;
- USHORT SubKeyCount;
- ULONG ValueCount;
- PLIST_ENTRY Entry;
- HKEY SubKey;
- PVALUE Value;
-
- DPRINT ("CmiExportHive(%p, '%s') called\n", Hive, KeyName);
-
- if (RegOpenKey (NULL, KeyName, &Key) != ERROR_SUCCESS)
- {
- DPRINT1 ("RegOpenKey() failed\n");
- return FALSE;
- }
-
- DPRINT ("Name: %s\n", KeyName);
-
- KeyCell = (PKEY_CELL)CmiGetCell (Hive,
- Hive->HiveHeader->RootKeyOffset,
- NULL);
- if (KeyCell == NULL)
- {
- DPRINT1 ("CmiGetCell() failed\n");
- return FALSE;
- }
-
- ValueCount = RegGetValueCount (Key);
- DPRINT ("ValueCount: %lu\n", ValueCount);
- if (ValueCount > 0)
- {
- /* Allocate value list cell */
- CmiAllocateValueListCell (Hive,
- &KeyCell->ValueListOffset,
- ValueCount);
-
- if (Key->DataSize != 0)
- {
- if (!CmiExportValue (Hive, Hive->HiveHeader->RootKeyOffset, Key, NULL))
- return FALSE;
- }
-
- /* Enumerate values */
- Entry = Key->ValueList.Flink;
- while (Entry != &Key->ValueList)
- {
- Value = CONTAINING_RECORD(Entry,
- VALUE,
- ValueList);
-
- if (!CmiExportValue (Hive, Hive->HiveHeader->RootKeyOffset, Key, Value))
- return FALSE;
-
- Entry = Entry->Flink;
- }
- }
-
- SubKeyCount = RegGetSubKeyCount (Key);
- DPRINT ("SubKeyCount: %lu\n", SubKeyCount);
- if (SubKeyCount > 0)
- {
- /* Allocate hash table cell */
- CmiAllocateHashTableCell (Hive,
- &KeyCell->HashTableOffset,
- SubKeyCount);
-
- /* Enumerate subkeys */
- Entry = Key->SubKeyList.Flink;
- while (Entry != &Key->SubKeyList)
- {
- SubKey = CONTAINING_RECORD(Entry,
- KEY,
- KeyList);
-
- if (!CmiExportSubKey (Hive, Hive->HiveHeader->RootKeyOffset, Key, SubKey))
- return FALSE;
-
- Entry = Entry->Flink;
- }
- }
-
- CmiCalcHiveChecksum (Hive);
-
- return TRUE;
-}
-
-
-static BOOL
-CmiWriteHive(PREGISTRY_HIVE Hive,
- PCHAR FileName)
-{
- PHBIN Bin;
- FILE *File;
- ULONG i;
-
-#if 0
- /* Check for existing hive file */
- File = fopen (FileName, "rb");
- if (File != NULL)
- {
- printf (" File already exists\n");
- fclose (File);
- return TRUE;
- }
-#endif
-
- /* Create new hive file */
- File = fopen (FileName, "w+b");
- if (File == NULL)
- {
- printf(" Error creating/opening file\n");
- return FALSE;
- }
-
- fseek (File, 0, SEEK_SET);
-
- /* Calculate header checksum */
- CmiCalcHiveChecksum (Hive);
-
- /* Write hive header */
- fwrite (Hive->HiveHeader, REG_BLOCK_SIZE, 1, File);
-
- Bin = NULL;
- for (i = 0; i < Hive->BlockListSize; i++)
- {
- if (Hive->BlockList[i] != Bin)
- {
- Bin = Hive->BlockList[i];
-
- DPRINT ("Bin[%lu]: Offset 0x%lx Size 0x%lx\n",
- i, Bin->BinOffset, Bin->BinSize);
-
- fwrite (Bin, Bin->BinSize, 1, File);
- }
- }
-
- fclose (File);
-
- return TRUE;
-}
-
-
-BOOL
-ExportBinaryHive (PCHAR FileName,
- PCHAR KeyName)
-{
- PREGISTRY_HIVE Hive;
-
- printf (" Creating binary hive: %s\n", FileName);
-
- Hive = CmiCreateRegistryHive (KeyName);
- if (Hive == NULL)
- return FALSE;
-
- if (!CmiExportHive (Hive, KeyName))
- {
- CmiDestroyRegistryHive (Hive);
- return FALSE;
- }
-
- if (!CmiWriteHive (Hive, FileName))
- {
- CmiDestroyRegistryHive (Hive);
- return FALSE;
- }
-
- CmiDestroyRegistryHive (Hive);
-
- return TRUE;
-}
-
-/* EOF */
Copied: branches/powerpc/reactos/tools/mkhive/binhive.cpp (from r26531,
branches/powerpc/reactos/tools/mkhive/binhive.c)
URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/mkhive/bi…
==============================================================================
--- branches/powerpc/reactos/tools/mkhive/binhive.c (original)
+++ branches/powerpc/reactos/tools/mkhive/binhive.cpp Sun Apr 29 13:37:17 2007
@@ -113,7 +113,7 @@
E_ULONG Reserved[99];
/* Checksum of first 0x200 bytes */
- E_ULONG Checksum;
+ ULONG Checksum;
} GCC_PACKED HIVE_HEADER, *PHIVE_HEADER;
typedef struct _HBIN
Removed: branches/powerpc/reactos/tools/mkhive/mkhive.c
URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/mkhive/mk…
==============================================================================
--- branches/powerpc/reactos/tools/mkhive/mkhive.c (original)
+++ branches/powerpc/reactos/tools/mkhive/mkhive.c (removed)
@@ -1,194 +1,0 @@
-/*
- * ReactOS kernel
- * Copyright (C) 2003 ReactOS Team
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-/* $Id$
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS hive maker
- * FILE: tools/mkhive/mkhive.c
- * PURPOSE: Hive maker
- * PROGRAMMER: Eric Kohl
- */
-
-#include <limits.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "mkhive.h"
-#include "registry.h"
-#include "reginf.h"
-#include "binhive.h"
-
-EndianOrder order;
-
-#ifdef _MSC_VER
-#include <stdlib.h>
-#define PATH_MAX _MAX_PATH
-#endif//_MSC_VER
-
-#ifndef WIN32
-#ifndef PATH_MAX
-#define PATH_MAX 260
-#endif
-#define DIR_SEPARATOR_CHAR '/'
-#define DIR_SEPARATOR_STRING "/"
-#else
-#define DIR_SEPARATOR_CHAR '\\'
-#define DIR_SEPARATOR_STRING "\\"
-#endif
-
-
-void usage (void)
-{
- printf ("Usage: mkhive <srcdir> <dstdir> [addinf]\n\n");
- printf (" srcdir - inf files are read from this directory\n");
- printf (" dstdir - binary hive files are created in this directory\n");
- printf (" addinf - additional inf files with full path\n");
-}
-
-void convert_path(char *dst, char *src)
-{
- int i;
-
- i = 0;
- while (src[i] != 0)
- {
-#ifdef WIN32
- if (src[i] == '/')
- {
- dst[i] = '\\';
- }
-#else
- if (src[i] == '\\')
- {
- dst[i] = '/';
- }
-#endif
- else
- {
- dst[i] = src[i];
- }
-
- i++;
- }
- dst[i] = 0;
-}
-
-
-int main (int argc, char *argv[])
-{
- char FileName[PATH_MAX];
- int Param;
-
- printf ("Binary hive maker\n");
-
- if (argc < 3)
- {
- usage ();
- return 1;
- }
-
- order = LE;
- if (!strcmp(argv[1], "-be"))
- {
- order = BE;
- argc--;
- argv++;
- }
- else if(!strcmp(argv[1], "-le"))
- {
- order = LE;
- argc--;
- argv++;
- }
-
- RegInitializeRegistry ();
-
- convert_path (FileName, argv[1]);
- strcat (FileName, DIR_SEPARATOR_STRING);
- strcat (FileName, "hivesys.inf");
- ImportRegistryFile (FileName, "AddReg", FALSE);
-
- convert_path (FileName, argv[1]);
- strcat (FileName, DIR_SEPARATOR_STRING);
- strcat (FileName, "hivecls.inf");
- ImportRegistryFile (FileName, "AddReg", FALSE);
-
- convert_path (FileName, argv[1]);
- strcat (FileName, DIR_SEPARATOR_STRING);
- strcat (FileName, "hivesft.inf");
- ImportRegistryFile (FileName, "AddReg", FALSE);
-
- convert_path (FileName, argv[1]);
- strcat (FileName, DIR_SEPARATOR_STRING);
- strcat (FileName, "hivedef.inf");
- ImportRegistryFile (FileName, "AddReg", FALSE);
-
- for (Param = 3; Param < argc; Param++)
- {
- convert_path (FileName, argv[Param]);
- ImportRegistryFile (FileName, "AddReg", FALSE);
- }
-
- convert_path (FileName, argv[2]);
- strcat (FileName, DIR_SEPARATOR_STRING);
- strcat (FileName, "system");
- if (!ExportBinaryHive (FileName, "\\Registry\\Machine\\SYSTEM"))
- {
- return 1;
- }
-
- convert_path (FileName, argv[2]);
- strcat (FileName, DIR_SEPARATOR_STRING);
- strcat (FileName, "software");
- if (!ExportBinaryHive (FileName, "\\Registry\\Machine\\SOFTWARE"))
- {
- return 1;
- }
-
- convert_path (FileName, argv[2]);
- strcat (FileName, DIR_SEPARATOR_STRING);
- strcat (FileName, "sam");
- if (!ExportBinaryHive (FileName, "\\Registry\\Machine\\SAM"))
- {
- return 1;
- }
-
- convert_path (FileName, argv[2]);
- strcat (FileName, DIR_SEPARATOR_STRING);
- strcat (FileName, "security");
- if (!ExportBinaryHive (FileName, "\\Registry\\Machine\\SECURITY"))
- {
- return 1;
- }
-
- convert_path (FileName, argv[2]);
- strcat (FileName, DIR_SEPARATOR_STRING);
- strcat (FileName, "default");
- if (!ExportBinaryHive (FileName, "\\Registry\\User\\.DEFAULT"))
- {
- return 1;
- }
-
-// RegShutdownRegistry ();
-
- printf (" Done.\n");
-
- return 0;
-}
-
-/* EOF */
Modified: branches/powerpc/reactos/tools/mkhive/mkhive.mak
URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/mkhive/mk…
==============================================================================
--- branches/powerpc/reactos/tools/mkhive/mkhive.mak (original)
+++ branches/powerpc/reactos/tools/mkhive/mkhive.mak Sun Apr 29 13:37:17 2007
@@ -19,16 +19,16 @@
$(EXEPREFIX)$(MKHIVE_OUT_)mkhive$(EXEPOSTFIX)
MKHIVE_SOURCES = $(addprefix $(MKHIVE_BASE_), \
- binhive.c \
- mkhive.c \
- reginf.c \
- registry.c \
+ binhive.cpp \
+ mkhive.cpp \
+ reginf.cpp \
+ registry.cpp \
)
MKHIVE_OBJECTS = \
- $(addprefix $(INTERMEDIATE_), $(MKHIVE_SOURCES:.c=.o))
+ $(addprefix $(INTERMEDIATE_), $(MKHIVE_SOURCES:.cpp=.o))
-MKHIVE_HOST_CFLAGS = $(xTOOLS_CFLAGS) -I$(INFLIB_BASE) -g3 -xc++
+MKHIVE_HOST_CXXFLAGS = $(xTOOLS_CFLAGS) -I$(INFLIB_BASE) -g3
MKHIVE_HOST_LFLAGS = $(xTOOLS_LFLAGS) -g3 -lstdc++
@@ -39,21 +39,21 @@
$(ECHO_LD)
${host_gcc} $(MKHIVE_OBJECTS) $(INFLIB_HOST_OBJECTS) $(MKHIVE_HOST_LFLAGS) -o $@
-$(MKHIVE_INT_)binhive.o: $(MKHIVE_BASE_)binhive.c | $(MKHIVE_INT)
+$(MKHIVE_INT_)binhive.o: $(MKHIVE_BASE_)binhive.cpp | $(MKHIVE_INT)
$(ECHO_CC)
- ${host_gcc} $(MKHIVE_HOST_CFLAGS) -c $< -o $@
+ ${host_gpp} $(MKHIVE_HOST_CXXFLAGS) -c $< -o $@
-$(MKHIVE_INT_)mkhive.o: $(MKHIVE_BASE_)mkhive.c | $(MKHIVE_INT)
+$(MKHIVE_INT_)mkhive.o: $(MKHIVE_BASE_)mkhive.cpp | $(MKHIVE_INT)
$(ECHO_CC)
- ${host_gcc} $(MKHIVE_HOST_CFLAGS) -c $< -o $@
+ ${host_gpp} $(MKHIVE_HOST_CXXFLAGS) -c $< -o $@
-$(MKHIVE_INT_)reginf.o: $(MKHIVE_BASE_)reginf.c | $(MKHIVE_INT)
+$(MKHIVE_INT_)reginf.o: $(MKHIVE_BASE_)reginf.cpp | $(MKHIVE_INT)
$(ECHO_CC)
- ${host_gcc} $(MKHIVE_HOST_CFLAGS) -c $< -o $@
+ ${host_gpp} $(MKHIVE_HOST_CXXFLAGS) -c $< -o $@
-$(MKHIVE_INT_)registry.o: $(MKHIVE_BASE_)registry.c | $(MKHIVE_INT)
+$(MKHIVE_INT_)registry.o: $(MKHIVE_BASE_)registry.cpp | $(MKHIVE_INT)
$(ECHO_CC)
- ${host_gcc} $(MKHIVE_HOST_CFLAGS) -c $< -o $@
+ ${host_gpp} $(MKHIVE_HOST_CXXFLAGS) -c $< -o $@
.PHONY: mkhive_clean
mkhive_clean:
Removed: branches/powerpc/reactos/tools/mkhive/reginf.c
URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/mkhive/re…
==============================================================================
--- branches/powerpc/reactos/tools/mkhive/reginf.c (original)
+++ branches/powerpc/reactos/tools/mkhive/reginf.c (removed)
@@ -1,482 +1,0 @@
-/*
- * ReactOS kernel
- * Copyright (C) 2003 ReactOS Team
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-/* $Id$
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS hive maker
- * FILE: tools/mkhive/reginf.h
- * PURPOSE: Inf file import code
- * PROGRAMMER: Eric Kohl
- */
-
-/* INCLUDES *****************************************************************/
-
-#include <string.h>
-#include <stdlib.h>
-#include <stdio.h>
-
-#include "mkhive.h"
-#include "registry.h"
-#include <infhost.h>
-
-
-
-#define FLG_ADDREG_BINVALUETYPE 0x00000001
-#define FLG_ADDREG_NOCLOBBER 0x00000002
-#define FLG_ADDREG_DELVAL 0x00000004
-#define FLG_ADDREG_APPEND 0x00000008
-#define FLG_ADDREG_KEYONLY 0x00000010
-#define FLG_ADDREG_OVERWRITEONLY 0x00000020
-#define FLG_ADDREG_TYPE_SZ 0x00000000
-#define FLG_ADDREG_TYPE_MULTI_SZ 0x00010000
-#define FLG_ADDREG_TYPE_EXPAND_SZ 0x00020000
-#define FLG_ADDREG_TYPE_BINARY (0x00000000 | FLG_ADDREG_BINVALUETYPE)
-#define FLG_ADDREG_TYPE_DWORD (0x00010000 | FLG_ADDREG_BINVALUETYPE)
-#define FLG_ADDREG_TYPE_NONE (0x00020000 | FLG_ADDREG_BINVALUETYPE)
-#define FLG_ADDREG_TYPE_MASK (0xFFFF0000 | FLG_ADDREG_BINVALUETYPE)
-
-
-/* FUNCTIONS ****************************************************************/
-
-static BOOL
-GetRootKey (PCHAR Name)
-{
- if (!strcasecmp (Name, "HKCR"))
- {
- strcpy (Name, "\\Registry\\Machine\\SOFTWARE\\Classes\\");
- return TRUE;
- }
-
- if (!strcasecmp (Name, "HKCU"))
- {
- strcpy (Name, "\\Registry\\User\\.DEFAULT\\");
- return TRUE;
- }
-
- if (!strcasecmp (Name, "HKLM"))
- {
- strcpy (Name, "\\Registry\\Machine\\");
- return TRUE;
- }
-
- if (!strcasecmp (Name, "HKU"))
- {
- strcpy (Name, "\\Registry\\User\\");
- return TRUE;
- }
-
-#if 0
- if (!strcasecmp (Name, "HKR"))
- return FALSE;
-#endif
-
- return FALSE;
-}
-
-
-/***********************************************************************
- * AppendMultiSzValue
- *
- * Append a multisz string to a multisz registry value.
- */
-static VOID
-AppendMultiSzValue (HKEY KeyHandle,
- PCHAR ValueName,
- PCHAR Strings,
- ULONG StringSize)
-{
- ULONG Size;
- ULONG Type;
- ULONG Total;
- PCHAR Buffer;
- PCHAR p;
- int len;
- LONG Error;
-
- Error = RegQueryValue (KeyHandle,
- ValueName,
- &Type,
- NULL,
- &Size);
- if ((Error != ERROR_SUCCESS) ||
- (Type != REG_MULTI_SZ))
- return;
-
- Buffer = (char *)malloc (Size + StringSize);
- if (Buffer == NULL)
- return;
-
- Error = RegQueryValue (KeyHandle,
- ValueName,
- NULL,
- (PCHAR)Buffer,
- &Size);
- if (Error != ERROR_SUCCESS)
- goto done;
-
- /* compare each string against all the existing ones */
- Total = Size;
- while (*Strings != 0)
- {
- len = strlen (Strings) + 1;
-
- for (p = Buffer; *p != 0; p += strlen (p) + 1)
- if (!strcasecmp (p, Strings))
- break;
-
- if (*p == 0) /* not found, need to append it */
- {
- memcpy (p, Strings, len);
- p[len] = 0;
- Total += len;
- }
- Strings += len;
- }
-
- if (Total != Size)
- {
- DPRINT ("setting value %s to %s\n", ValueName, Buffer);
- RegSetValue (KeyHandle,
- ValueName,
- REG_MULTI_SZ,
- (PCHAR)Buffer,
- Total);
- }
-
-done:
- free (Buffer);
-}
-
-
-/***********************************************************************
- * do_reg_operation
- *
- * Perform an add/delete registry operation depending on the flags.
- */
-static BOOL
-do_reg_operation(HKEY KeyHandle,
- PCHAR ValueName,
- PINFCONTEXT Context,
- ULONG Flags)
-{
- CHAR EmptyStr = (CHAR)0;
- ULONG Type;
- ULONG Size;
- LONG Error;
-
- if (Flags & FLG_ADDREG_DELVAL) /* deletion */
- {
- if (ValueName)
- {
- RegDeleteValue (KeyHandle,
- ValueName);
- }
- else
- {
- RegDeleteKey (KeyHandle,
- NULL);
- }
-
- return TRUE;
- }
-
- if (Flags & FLG_ADDREG_KEYONLY)
- return TRUE;
-
- if (Flags & (FLG_ADDREG_NOCLOBBER | FLG_ADDREG_OVERWRITEONLY))
- {
- Error = RegQueryValue (KeyHandle,
- ValueName,
- NULL,
- NULL,
- NULL);
- if ((Error == ERROR_SUCCESS) &&
- (Flags & FLG_ADDREG_NOCLOBBER))
- return TRUE;
-
- if ((Error != ERROR_SUCCESS) &&
- (Flags & FLG_ADDREG_OVERWRITEONLY))
- return TRUE;
- }
-
- switch (Flags & FLG_ADDREG_TYPE_MASK)
- {
- case FLG_ADDREG_TYPE_SZ:
- Type = REG_SZ;
- break;
-
- case FLG_ADDREG_TYPE_MULTI_SZ:
- Type = REG_MULTI_SZ;
- break;
-
- case FLG_ADDREG_TYPE_EXPAND_SZ:
- Type = REG_EXPAND_SZ;
- break;
-
- case FLG_ADDREG_TYPE_BINARY:
- Type = REG_BINARY;
- break;
-
- case FLG_ADDREG_TYPE_DWORD:
- Type = REG_DWORD;
- break;
-
- case FLG_ADDREG_TYPE_NONE:
- Type = REG_NONE;
- break;
-
- default:
- Type = Flags >> 16;
- break;
- }
-
- if (!(Flags & FLG_ADDREG_BINVALUETYPE) ||
- (Type == REG_DWORD && InfHostGetFieldCount (Context) == 5))
- {
- PCHAR Str = NULL;
-
- if (Type == REG_MULTI_SZ)
- {
- if (InfHostGetMultiSzField (Context, 5, NULL, 0, &Size) != 0)
- Size = 0;
-
- if (Size)
- {
- Str = (char *)malloc (Size);
- if (Str == NULL)
- return FALSE;
-
- InfHostGetMultiSzField (Context, 5, Str, Size, NULL);
- }
-
- if (Flags & FLG_ADDREG_APPEND)
- {
- if (Str == NULL)
- return TRUE;
-
- AppendMultiSzValue (KeyHandle,
- ValueName,
- Str,
- Size);
-
- free (Str);
- return TRUE;
- }
- /* else fall through to normal string handling */
- }
- else
- {
- if (InfHostGetStringField (Context, 5, NULL, 0, &Size) != 0)
- Size = 0;
-
- if (Size)
- {
- Str = (char *)malloc (Size);
- if (Str == NULL)
- return FALSE;
-
- InfHostGetStringField (Context, 5, Str, Size, NULL);
- }
- }
-
- if (Type == REG_DWORD)
- {
- ULONG dw = Str ? strtoul (Str, NULL, 0) : 0;
-
- DPRINT("setting dword %s to %lx\n", ValueName, dw);
-
- RegSetValue (KeyHandle,
- ValueName,
- Type,
- (char *)&dw,
- sizeof(ULONG));
- }
- else
- {
- DPRINT("setting value %s to %s\n", ValueName, Str);
-
- if (Str)
- {
- RegSetValue (KeyHandle,
- ValueName,
- Type,
- (char *)Str,
- Size);
- }
- else
- {
- RegSetValue (KeyHandle,
- ValueName,
- Type,
- (char *)&EmptyStr,
- sizeof(CHAR));
- }
- }
- free (Str);
- }
- else /* get the binary data */
- {
- PCHAR Data = NULL;
-
- if (InfHostGetBinaryField (Context, 5, NULL, 0, &Size) != 0)
- Size = 0;
-
- if (Size)
- {
- Data = (char *)malloc (Size);
- if (Data == NULL)
- return FALSE;
-
- DPRINT("setting binary data %s len %lu\n", ValueName, Size);
- InfHostGetBinaryField (Context, 5, (unsigned char *)Data, Size, NULL);
- }
-
- RegSetValue (KeyHandle,
- ValueName,
- Type,
- (char *)Data,
- Size);
-
- free (Data);
- }
-
- return TRUE;
-}
-
-
-/***********************************************************************
- * registry_callback
- *
- * Called once for each AddReg and DelReg entry in a given section.
- */
-static BOOL
-registry_callback (HINF hInf, PCHAR Section, BOOL Delete)
-{
- CHAR Buffer[MAX_INF_STRING_LENGTH];
- PCHAR ValuePtr;
- ULONG Flags;
- ULONG Length;
-
- PINFCONTEXT Context = NULL;
- HKEY KeyHandle;
- BOOL Ok;
-
-
- Ok = InfHostFindFirstLine (hInf, Section, NULL, &Context) == 0;
- if (!Ok)
- return TRUE; /* Don't fail if the section isn't present */
-
- for (;Ok; Ok = (InfHostFindNextLine (Context, Context) == 0))
- {
- /* get root */
- if (InfHostGetStringField (Context, 1, Buffer, MAX_INF_STRING_LENGTH, NULL) != 0)
- continue;
- if (!GetRootKey (Buffer))
- continue;
-
- /* get key */
- Length = strlen (Buffer);
- if (InfHostGetStringField (Context, 2, Buffer + Length, MAX_INF_STRING_LENGTH -
Length, NULL) != 0)
- *Buffer = 0;
-
- DPRINT("KeyName: <%s>\n", Buffer);
-
- if (Delete)
- {
- Flags = FLG_ADDREG_DELVAL;
- }
- else
- {
- /* get flags */
- if (InfHostGetIntField (Context, 4, (PULONG)&Flags) != 0)
- Flags = 0;
- }
-
- DPRINT("Flags: %lx\n", Flags);
-
- if (Delete || (Flags & FLG_ADDREG_OVERWRITEONLY))
- {
- if (RegOpenKey (NULL, Buffer, &KeyHandle) != ERROR_SUCCESS)
- {
- DPRINT("RegOpenKey(%s) failed\n", Buffer);
- continue; /* ignore if it doesn't exist */
- }
- }
- else
- {
- if (RegCreateKey (NULL, Buffer, &KeyHandle) != ERROR_SUCCESS)
- {
- DPRINT("RegCreateKey(%s) failed\n", Buffer);
- continue;
- }
- }
-
- /* get value name */
- if (InfHostGetStringField (Context, 3, Buffer, MAX_INF_STRING_LENGTH, NULL) == 0)
- {
- ValuePtr = Buffer;
- }
- else
- {
- ValuePtr = NULL;
- }
-
- /* and now do it */
- if (!do_reg_operation (KeyHandle, ValuePtr, Context, Flags))
- {
- return FALSE;
- }
- }
-
- InfHostFreeContext(Context);
-
- return TRUE;
-}
-
-
-BOOL
-ImportRegistryFile(PCHAR FileName,
- PCHAR Section,
- BOOL Delete)
-{
- HINF hInf;
- ULONG ErrorLine;
-
- /* Load inf file from install media. */
- if (InfHostOpenFile(&hInf, FileName, &ErrorLine) != 0)
- {
- DPRINT1 ("InfHostOpenFile() failed\n");
- return FALSE;
- }
-
- if (!registry_callback (hInf, "DelReg", TRUE))
- {
- DPRINT1 ("registry_callback() failed\n");
- }
-
- if (!registry_callback (hInf, "AddReg", FALSE))
- {
- DPRINT1 ("registry_callback() failed\n");
- }
-
- InfHostCloseFile (hInf);
-
- return TRUE;
-}
-
-/* EOF */
Removed: branches/powerpc/reactos/tools/mkhive/registry.c
URL:
http://svn.reactos.org/svn/reactos/branches/powerpc/reactos/tools/mkhive/re…
==============================================================================
--- branches/powerpc/reactos/tools/mkhive/registry.c (original)
+++ branches/powerpc/reactos/tools/mkhive/registry.c (removed)
@@ -1,706 +1,0 @@
-/*
- * ReactOS kernel
- * Copyright (C) 2003 ReactOS Team
- *
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
- *
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
- */
-/* $Id$
- * COPYRIGHT: See COPYING in the top level directory
- * PROJECT: ReactOS hive maker
- * FILE: tools/mkhive/registry.c
- * PURPOSE: Registry code
- * PROGRAMMER: Eric Kohl
- */
-
-/*
- * TODO:
- * - Implement RegDeleteKey().
- * - Fix RegEnumValue().
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdio.h>
-
-#include "mkhive.h"
-#include "registry.h"
-
-
-static HKEY RootKey;
-
-
-VOID
-RegInitializeRegistry(VOID)
-{
- HKEY ControlSetKey;
- HKEY LinkKey;
-
- /* Create root key */
- RootKey = (HKEY)malloc(sizeof(KEY));
-
- InitializeListHead(&RootKey->SubKeyList);
- InitializeListHead(&RootKey->ValueList);
- InitializeListHead(&RootKey->KeyList);
-
- RootKey->SubKeyCount = 0;
- RootKey->ValueCount = 0;
-
- RootKey->NameSize = 2;
- RootKey->Name = (PCHAR)malloc(2);
- strcpy(RootKey->Name, "\\");
-
- RootKey->DataType = 0;
- RootKey->DataSize = 0;
- RootKey->Data = NULL;
-
- /* Create SYSTEM key */
- RegCreateKey(RootKey,
- "Registry\\Machine\\SYSTEM",
- NULL);
-
- /* Create link 'CurrentControlSet' --> 'ControlSet001' */
- RegCreateKey(RootKey,
- "Registry\\Machine\\SYSTEM\\ControlSet001",
- &ControlSetKey);
-
- RegCreateKey(RootKey,
- "Registry\\Machine\\SYSTEM\\CurrentControlSet",
- &LinkKey);
-
- RegSetValue(LinkKey,
- NULL,
- REG_LINK,
- (PCHAR)&ControlSetKey,
- sizeof(PVOID));
-
- /* Create HARDWARE key */
- RegCreateKey(RootKey,
- "Registry\\Machine\\HARDWARE",
- NULL);
-
- /* Create SAM key */
- RegCreateKey(RootKey,
- "Registry\\Machine\\SAM",
- NULL);
-
- /* Create SECURITY key */
- RegCreateKey(RootKey,
- "Registry\\Machine\\SECURITY",
- NULL);
-
- /* Create SOFTWARE key */
- RegCreateKey(RootKey,
- "Registry\\Machine\\SOFTWARE",
- NULL);
-
- /* Create DEFAULT key */
- RegCreateKey(RootKey,
- "Registry\\User\\.DEFAULT",
- NULL);
-}
-
-
-LONG
-RegCreateKey(HKEY ParentKey,
- PCHAR KeyName,
- PHKEY Key)
-{
- PLIST_ENTRY Ptr;
- HKEY SearchKey = INVALID_HANDLE_VALUE;
- HKEY CurrentKey;
- HKEY NewKey;
- PCHAR p;
- PCHAR name;
- int subkeyLength;
- int stringLength;
-
- DPRINT ("RegCreateKey('%s')\n", KeyName);
-
- if (*KeyName == '\\')
- {
- KeyName++;
- CurrentKey = RootKey;
- }
- else if (ParentKey == NULL)
- {
- CurrentKey = RootKey;
- }
- else
- {
- CurrentKey = ParentKey;
- }
-
- /* Check whether current key is a link */
- if (CurrentKey->DataType == REG_LINK)
- {
- CurrentKey = (HKEY)CurrentKey->Data;
- }
-
- while (*KeyName != 0)
- {
- DPRINT ("KeyName '%s'\n", KeyName);
-
- if (*KeyName == '\\')
- KeyName++;
- p = strchr (KeyName, '\\');
- if ((p != NULL) && (p != KeyName))
- {
- subkeyLength = p - KeyName;
- stringLength = subkeyLength + 1;
- name = KeyName;
- }
- else
- {
- subkeyLength = strlen (KeyName);
- stringLength = subkeyLength;
- name = KeyName;
- }
-
- Ptr = CurrentKey->SubKeyList.Flink;
- while (Ptr != &CurrentKey->SubKeyList)
- {
- DPRINT ("Ptr 0x%p\n", Ptr);
-
- SearchKey = CONTAINING_RECORD(Ptr,
- KEY,
- KeyList);
- DPRINT ("SearchKey 0x%p\n", SearchKey);
- DPRINT ("Searching '%s'\n", SearchKey->Name);
- if (strncasecmp (SearchKey->Name, name, subkeyLength) == 0)
- break;
-
- Ptr = Ptr->Flink;
- }
-
- if (Ptr == &CurrentKey->SubKeyList)
- {
- /* no key found -> create new subkey */
- NewKey = (HKEY)malloc (sizeof(KEY));
- if (NewKey == NULL)
- return ERROR_OUTOFMEMORY;
-
- InitializeListHead (&NewKey->SubKeyList);
- InitializeListHead (&NewKey->ValueList);
-
- NewKey->SubKeyCount = 0;
- NewKey->ValueCount = 0;
-
- NewKey->DataType = 0;
- NewKey->DataSize = 0;
- NewKey->Data = NULL;
-
- InsertTailList (&CurrentKey->SubKeyList, &NewKey->KeyList);
- CurrentKey->SubKeyCount++;
-
- NewKey->NameSize = subkeyLength + 1;
- NewKey->Name = (PCHAR)malloc (NewKey->NameSize);
- if (NewKey->Name == NULL)
- return(ERROR_OUTOFMEMORY);
- memcpy(NewKey->Name, name, subkeyLength);
- NewKey->Name[subkeyLength] = 0;
-
- DPRINT ("NewKey 0x%p\n", NewKey);
- DPRINT ("NewKey '%s' Length %ld\n", NewKey->Name,
NewKey->NameSize);
-
- CurrentKey = NewKey;
- }
- else
- {
- CurrentKey = SearchKey;
-
- /* Check whether current key is a link */
- if (CurrentKey->DataType == REG_LINK)
- {
- CurrentKey = (HKEY)CurrentKey->Data;
- }
- }
-
- KeyName = KeyName + stringLength;
- }
-
- if (Key != NULL)
- *Key = CurrentKey;
-
- return ERROR_SUCCESS;
-}
-
-
-LONG
-RegDeleteKey(HKEY Key,
- PCHAR Name)
-{
- if (Name != NULL && strchr(Name, '\\') != NULL)
- return(ERROR_INVALID_PARAMETER);
-
- DPRINT1("FIXME!\n");
-
- return(ERROR_SUCCESS);
-}
-
-
-LONG
-RegEnumKey(HKEY Key,
- ULONG Index,
- PCHAR Name,
- PULONG NameSize)
-{
- PLIST_ENTRY Ptr;
- HKEY SearchKey;
- ULONG Count = 0;
- ULONG Size;
-
- Ptr = Key->SubKeyList.Flink;
- while (Ptr != &Key->SubKeyList)
- {
- if (Index == Count)
- break;
-
- Count++;
- Ptr = Ptr->Flink;
- }
-
- if (Ptr == &Key->SubKeyList)
- return(ERROR_NO_MORE_ITEMS);
-
- SearchKey = CONTAINING_RECORD(Ptr,
- KEY,
- KeyList);
-
- DPRINT ("Name '%s' Length %ld\n", SearchKey->Name,
SearchKey->NameSize);
-
- Size = min(SearchKey->NameSize, *NameSize);
- *NameSize = Size;
- memcpy(Name, SearchKey->Name, Size);
-
- return(ERROR_SUCCESS);
-}
-
-
-LONG
-RegOpenKey(HKEY ParentKey,
- PCHAR KeyName,
- PHKEY Key)
-{
- PLIST_ENTRY Ptr;
- HKEY SearchKey = INVALID_HANDLE_VALUE;
- HKEY CurrentKey;
- PCHAR p;
- PCHAR name;
- int subkeyLength;
- int stringLength;
-
- DPRINT("KeyName '%s'\n", KeyName);
-
- *Key = NULL;
-
- if (*KeyName == '\\')
- {
- KeyName++;
- CurrentKey = RootKey;
- }
- else if (ParentKey == NULL)
- {
- CurrentKey = RootKey;
- }
- else
- {
- CurrentKey = ParentKey;
- }
-
- /* Check whether current key is a link */
- if (CurrentKey->DataType == REG_LINK)
- {
- CurrentKey = (HKEY)CurrentKey->Data;
- }
-
- while (*KeyName != 0)
- {
- DPRINT ("KeyName '%s'\n", KeyName);
-
- if (*KeyName == '\\')
- KeyName++;
- p = strchr(KeyName, '\\');
- if ((p != NULL) && (p != KeyName))
- {
- subkeyLength = p - KeyName;
- stringLength = subkeyLength + 1;
- name = KeyName;
- }
- else
- {
- subkeyLength = strlen(KeyName);
- stringLength = subkeyLength;
- name = KeyName;
- }
-
- Ptr = CurrentKey->SubKeyList.Flink;
- while (Ptr != &CurrentKey->SubKeyList)
- {
- DPRINT ("Ptr 0x%p\n", Ptr);
-
- SearchKey = CONTAINING_RECORD(Ptr,
- KEY,
- KeyList);
-
- DPRINT ("SearchKey 0x%p\n", SearchKey);
- DPRINT ("Searching '%s'\n", SearchKey->Name);
-
- if (strncasecmp(SearchKey->Name, name, subkeyLength) == 0)
- break;
-
- Ptr = Ptr->Flink;
- }
-
- if (Ptr == &CurrentKey->SubKeyList)
- {
- return(ERROR_PATH_NOT_FOUND);
- }
- else
- {
- CurrentKey = SearchKey;
-
- /* Check whether current key is a link */
- if (CurrentKey->DataType == REG_LINK)
- {
- CurrentKey = (HKEY)CurrentKey->Data;
- }
- }
-
- KeyName = KeyName + stringLength;
- }
-
- if (Key != NULL)
- *Key = CurrentKey;
-
- return(ERROR_SUCCESS);
-}
-
-
-LONG
-RegSetValue(HKEY Key,
- PCHAR ValueName,
- ULONG Type,
- PCHAR Data,
- ULONG DataSize)
-{
- PLIST_ENTRY Ptr;
- PVALUE Value = NULL;
-
- DPRINT ("Key 0x%x, ValueName '%s', Type %d, Data 0x%x, DataSize
%d\n",
- (int)Key, ValueName, (int)Type, (int)Data, (int)DataSize);
-
- if ((ValueName == NULL) || (*ValueName == 0))
- {
- /* set default value */
- if ((Key->Data != NULL) && (Key->DataSize > sizeof(PCHAR)))
- {
- free(Key->Data);
- }
-
- if (DataSize <= sizeof(PCHAR))
- {
- Key->DataSize = DataSize;
- Key->DataType = Type;
- memcpy(&Key->Data, Data, DataSize);
- }
- else
- {
- Key->Data = (PCHAR)malloc(DataSize);
- Key->DataSize = DataSize;
- Key->DataType = Type;
- memcpy(Key->Data, Data, DataSize);
- }
- }
- else
- {
- /* set non-default value */
- Ptr = Key->ValueList.Flink;
- while (Ptr != &Key->ValueList)
- {
- Value = CONTAINING_RECORD(Ptr,
- VALUE,
- ValueList);
-
- DPRINT ("Value->Name '%s'\n", Value->Name);
-
- if (strcasecmp(Value->Name, ValueName) == 0)
- break;
-
- Ptr = Ptr->Flink;
- }
-
- if (Ptr == &Key->ValueList)
- {
- /* add new value */
- DPRINT("No value found - adding new value\n");
-
- Value = (PVALUE)malloc(sizeof(VALUE));
- if (Value == NULL)
- return(ERROR_OUTOFMEMORY);
- InsertTailList(&Key->ValueList, &Value->ValueList);
- Key->ValueCount++;
- Value->NameSize = strlen(ValueName)+1;
- Value->Name = (PCHAR)malloc(Value->NameSize);
- if (Value->Name == NULL)
- return(ERROR_OUTOFMEMORY);
- strcpy(Value->Name, ValueName);
- Value->DataType = REG_NONE;
- Value->DataSize = 0;
- Value->Data = NULL;
- }
-
- /* set new value */
- if ((Value->Data != NULL) && (Value->DataSize > sizeof(PCHAR)))
- {
- free(Value->Data);
- }
-
- if (DataSize <= sizeof(PCHAR))
- {
- Value->DataSize = DataSize;
- Value->DataType = Type;
- memcpy(&Value->Data, Data, DataSize);
- }
- else
- {
- Value->Data = (PCHAR)malloc(DataSize);
- if (Value->Data == NULL)
- return(ERROR_OUTOFMEMORY);
- Value->DataType = Type;
- Value->DataSize = DataSize;
- memcpy(Value->Data, Data, DataSize);
- }
- }
- return(ERROR_SUCCESS);
-}
-
-
-LONG
-RegQueryValue(HKEY Key,
- PCHAR ValueName,
- PULONG Type,
- PCHAR Data,
- PULONG DataSize)
-{
- ULONG Size;
- PLIST_ENTRY Ptr;
- PVALUE Value = NULL;
-
- if ((ValueName == NULL) || (*ValueName == 0))
- {
- /* query default value */
- if (Key->Data == NULL)
- return(ERROR_INVALID_PARAMETER);
-
- if (Type != NULL)
- *Type = Key->DataType;
- if ((Data != NULL) && (DataSize != NULL))
- {
- if (Key->DataSize <= sizeof(PCHAR))
- {
- Size = min(Key->DataSize, *DataSize);
- memcpy(Data, &Key->Data, Size);
- *DataSize = Size;
- }
- else
- {
- Size = min(Key->DataSize, *DataSize);
- memcpy(Data, Key->Data, Size);
- *DataSize = Size;
- }
- }
- else if ((Data == NULL) && (DataSize != NULL))
- {
- *DataSize = Key->DataSize;
- }
- }
- else
- {
- /* query non-default value */
- Ptr = Key->ValueList.Flink;
- while (Ptr != &Key->ValueList)
- {
- Value = CONTAINING_RECORD(Ptr,
- VALUE,
- ValueList);
-
- DPRINT("Searching for '%s'. Value name '%s'\n", ValueName,
Value->Name);
-
- if (strcasecmp(Value->Name, ValueName) == 0)
- break;
-
- Ptr = Ptr->Flink;
- }
-
- if (Ptr == &Key->ValueList)
- return(ERROR_INVALID_PARAMETER);
-
- if (Type != NULL)
- *Type = Value->DataType;
- if ((Data != NULL) && (DataSize != NULL))
- {
- if (Value->DataSize <= sizeof(PCHAR))
- {
- Size = min(Value->DataSize, *DataSize);
- memcpy(Data, &Value->Data, Size);
- *DataSize = Size;
- }
- else
- {
- Size = min(Value->DataSize, *DataSize);
- memcpy(Data, Value->Data, Size);
- *DataSize = Size;
- }
- }
- else if ((Data == NULL) && (DataSize != NULL))
- {
- *DataSize = Value->DataSize;
- }
- }
-
- return(ERROR_SUCCESS);
-}
-
-
-LONG
-RegDeleteValue(HKEY Key,
- PCHAR ValueName)
-{
- PLIST_ENTRY Ptr;
- PVALUE Value = NULL;
-
- if ((ValueName == NULL) || (*ValueName == 0))
- {
- /* delete default value */
- if (Key->Data != NULL)
- free(Key->Data);
- Key->Data = NULL;
- Key->DataSize = 0;
- Key->DataType = 0;
- }
- else
- {
- /* delete non-default value */
- Ptr = Key->ValueList.Flink;
- while (Ptr != &Key->ValueList)
- {
- Value = CONTAINING_RECORD(Ptr,
- VALUE,
- ValueList);
- if (strcasecmp(Value->Name, ValueName) == 0)
- break;
-
- Ptr = Ptr->Flink;
- }
-
- if (Ptr == &Key->ValueList)
- return(ERROR_INVALID_PARAMETER);
-
- /* delete value */
- Key->ValueCount--;
- if (Value->Name != NULL)
- free(Value->Name);
- Value->Name = NULL;
- Value->NameSize = 0;
-
- if (Value->DataSize > sizeof(PCHAR))
- {
- if (Value->Data != NULL)
- free(Value->Data);
- }
- Value->Data = NULL;
- Value->DataSize = 0;
- Value->DataType = 0;
-
- RemoveEntryList(&Value->ValueList);
- free(Value);
- }
- return(ERROR_SUCCESS);
-}
-
-
-LONG
-RegEnumValue(HKEY Key,
- ULONG Index,
- PCHAR ValueName,
- PULONG NameSize,
- PULONG Type,
- PCHAR Data,
- PULONG DataSize)
-{
- PLIST_ENTRY Ptr;
- PVALUE Value;
- ULONG Count = 0;
-
- if (Key->Data != NULL)
- {
- if (Index > 0)
- {
- Index--;
- }
- else
- {
- /* enumerate default value */
- if (ValueName != NULL)
- *ValueName = 0;
- if (Type != NULL)
- *Type = Key->DataType;
- if (DataSize != NULL)
- *DataSize = Key->DataSize;
-
- /* FIXME: return more values */
- }
- }
-
- Ptr = Key->ValueList.Flink;
- while (Ptr != &Key->ValueList)
- {
- if (Index == Count)
- break;
-
- Count++;
- Ptr = Ptr->Flink;
- }
-
- if (Ptr == &Key->ValueList)
- return(ERROR_NO_MORE_ITEMS);
-
- Value = CONTAINING_RECORD(Ptr,
- VALUE,
- ValueList);
-
- /* FIXME: return values */
-
- return(ERROR_SUCCESS);
-}
-
-
-USHORT
-RegGetSubKeyCount (HKEY Key)
-{
- return Key->SubKeyCount;
-}
-
-
-ULONG
-RegGetValueCount (HKEY Key)
-{
- if (Key->DataSize != 0)
- return Key->ValueCount + 1;
-
- return Key->ValueCount;
-}
-
-/* EOF */