* 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.
+ * 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.,
+ * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
*/
/* COPYRIGHT: See COPYING in the top level directory
* PROJECT: ReactOS hive maker
/*
* TODO:
- * - Implement RegDeleteKey()
+ * - Implement RegDeleteKeyW()
* - Implement RegEnumValue()
- * - Implement RegQueryValueExA()
+ * - Implement RegQueryValueExW()
*/
#include <stdlib.h>
#define NDEBUG
#include "mkhive.h"
-static EREGISTRY_HIVE RootHive;
+#define REG_DATA_SIZE_MASK 0x7FFFFFFF
+#define REG_DATA_IN_OFFSET 0x80000000
+
+static CMHIVE RootHive;
static MEMKEY RootKey;
-EREGISTRY_HIVE DefaultHive; /* \Registry\User\.DEFAULT */
-EREGISTRY_HIVE SamHive; /* \Registry\Machine\SAM */
-EREGISTRY_HIVE SecurityHive; /* \Registry\Machine\SECURITY */
-EREGISTRY_HIVE SoftwareHive; /* \Registry\Machine\SOFTWARE */
-EREGISTRY_HIVE SystemHive; /* \Registry\Machine\SYSTEM */
+CMHIVE DefaultHive; /* \Registry\User\.DEFAULT */
+CMHIVE SamHive; /* \Registry\Machine\SAM */
+CMHIVE SecurityHive; /* \Registry\Machine\SECURITY */
+CMHIVE SoftwareHive; /* \Registry\Machine\SOFTWARE */
+CMHIVE SystemHive; /* \Registry\Machine\SYSTEM */
static MEMKEY
CreateInMemoryStructure(
- IN PEREGISTRY_HIVE RegistryHive,
+ IN PCMHIVE RegistryHive,
IN HCELL_INDEX KeyCellOffset,
IN PCUNICODE_STRING KeyName)
{
Key->ValueCount = 0;
Key->NameSize = KeyName->Length;
+ /* FIXME: It's not enough to allocate this way, because later
+ this memory gets overwritten with bigger names */
Key->Name = malloc (Key->NameSize);
if (!Key->Name)
return NULL;
Key->RegistryHive = RegistryHive;
Key->KeyCellOffset = KeyCellOffset;
- Key->KeyCell = HvGetCell (&RegistryHive->Hive, Key->KeyCellOffset);
+ Key->KeyCell = (PCM_KEY_NODE)HvGetCell (&RegistryHive->Hive, Key->KeyCellOffset);
if (!Key->KeyCell)
{
free(Key);
LocalKeyName = (PWSTR)KeyName;
for (;;)
{
- End = (PWSTR) xwcschr(LocalKeyName, '\\');
+ End = (PWSTR) utf16_wcschr(LocalKeyName, '\\');
if (End)
{
KeyString.Buffer = LocalKeyName;
else
RtlInitUnicodeString(&KeyString, LocalKeyName);
- while (ParentKey->DataType == REG_LINK)
- ParentKey = ParentKey->LinkedKey;
+ /* Redirect from 'CurrentControlSet' to 'ControlSet001' */
+ if (!utf16_wcsncmp(LocalKeyName, L"CurrentControlSet", 17) &&
+ ParentKey->NameSize == 12 &&
+ !memcmp(ParentKey->Name, L"SYSTEM", 12))
+ RtlInitUnicodeString(&KeyString, L"ControlSet001");
/* Check subkey in memory structure */
Ptr = ParentKey->SubKeyList.Flink;
}
LONG WINAPI
-RegDeleteKeyA(HKEY Key,
- LPCSTR Name)
+RegDeleteKeyW(
+ IN HKEY hKey,
+ IN LPCWSTR lpSubKey)
+{
+ DPRINT1("FIXME!\n");
+ return ERROR_SUCCESS;
+}
+
+LONG WINAPI
+RegDeleteKeyA(
+ IN HKEY hKey,
+ IN LPCSTR lpSubKey)
{
- if (Name != NULL && strchr(Name, '\\') != NULL)
- return(ERROR_INVALID_PARAMETER);
+ PWSTR lpSubKeyW = NULL;
+ LONG rc;
+
+ if (lpSubKey != NULL && strchr(lpSubKey, '\\') != NULL)
+ return ERROR_INVALID_PARAMETER;
+
+ if (lpSubKey)
+ {
+ lpSubKeyW = MultiByteToWideChar(lpSubKey);
+ if (!lpSubKeyW)
+ return ERROR_OUTOFMEMORY;
+ }
- DPRINT1("FIXME!\n");
+ rc = RegDeleteKeyW(hKey, lpSubKeyW);
- return(ERROR_SUCCESS);
+ if (lpSubKey)
+ free(lpSubKeyW);
+
+ return rc;
}
LONG WINAPI
return ERROR_UNSUCCESSFUL;
/* Get size of the allocated cellule (if any) */
- if (!(ValueCell->DataSize & REG_DATA_IN_OFFSET) &&
- (ValueCell->DataSize & REG_DATA_SIZE_MASK) != 0)
+ if (!(ValueCell->DataLength & REG_DATA_IN_OFFSET) &&
+ (ValueCell->DataLength & REG_DATA_SIZE_MASK) != 0)
{
- DataCell = HvGetCell(&Key->RegistryHive->Hive, ValueCell->DataOffset);
+ DataCell = HvGetCell(&Key->RegistryHive->Hive, ValueCell->Data);
if (!DataCell)
return ERROR_UNSUCCESSFUL;
DataCellSize = -HvGetCellSize(&Key->RegistryHive->Hive, DataCell);
if (cbData <= sizeof(HCELL_INDEX))
{
/* If data size <= sizeof(HCELL_INDEX) then store data in the data offset */
- DPRINT("ValueCell->DataSize %lu\n", ValueCell->DataSize);
+ DPRINT("ValueCell->DataLength %u\n", ValueCell->DataLength);
if (DataCell)
- HvFreeCell(&Key->RegistryHive->Hive, ValueCell->DataOffset);
+ HvFreeCell(&Key->RegistryHive->Hive, ValueCell->Data);
- RtlCopyMemory(&ValueCell->DataOffset, lpData, cbData);
- ValueCell->DataSize = (ULONG)(cbData | REG_DATA_IN_OFFSET);
- ValueCell->DataType = dwType;
- HvMarkCellDirty(&Key->RegistryHive->Hive, ValueCellOffset);
+ RtlCopyMemory(&ValueCell->Data, lpData, cbData);
+ ValueCell->DataLength = (ULONG)(cbData | REG_DATA_IN_OFFSET);
+ ValueCell->Type = dwType;
+ HvMarkCellDirty(&Key->RegistryHive->Hive, ValueCellOffset, FALSE);
}
else
{
* data block and allocate a new one. */
HCELL_INDEX NewOffset;
- DPRINT("ValueCell->DataSize %lu\n", ValueCell->DataSize);
+ DPRINT("ValueCell->DataLength %u\n", ValueCell->DataLength);
- NewOffset = HvAllocateCell(&Key->RegistryHive->Hive, cbData, HvStable);
- if (NewOffset == HCELL_NULL)
+ NewOffset = HvAllocateCell(&Key->RegistryHive->Hive, cbData, Stable, HCELL_NIL);
+ if (NewOffset == HCELL_NIL)
{
- DPRINT("HvAllocateCell() failed with status 0x%08lx\n", Status);
+ DPRINT("HvAllocateCell() failed with status 0x%08x\n", Status);
return ERROR_UNSUCCESSFUL;
}
if (DataCell)
- HvFreeCell(&Key->RegistryHive->Hive, ValueCell->DataOffset);
+ HvFreeCell(&Key->RegistryHive->Hive, ValueCell->Data);
- ValueCell->DataOffset = NewOffset;
- DataCell = HvGetCell(&Key->RegistryHive->Hive, NewOffset);
+ ValueCell->Data = NewOffset;
+ DataCell = (PVOID)HvGetCell(&Key->RegistryHive->Hive, NewOffset);
}
/* Copy new contents to cellule */
RtlCopyMemory(DataCell, lpData, cbData);
- ValueCell->DataSize = (ULONG)(cbData & REG_DATA_SIZE_MASK);
- ValueCell->DataType = dwType;
- HvMarkCellDirty(&Key->RegistryHive->Hive, ValueCell->DataOffset);
- HvMarkCellDirty(&Key->RegistryHive->Hive, ValueCellOffset);
+ ValueCell->DataLength = (ULONG)(cbData & REG_DATA_SIZE_MASK);
+ ValueCell->Type = dwType;
+ HvMarkCellDirty(&Key->RegistryHive->Hive, ValueCell->Data, FALSE);
+ HvMarkCellDirty(&Key->RegistryHive->Hive, ValueCellOffset, FALSE);
}
- HvMarkCellDirty(&Key->RegistryHive->Hive, Key->KeyCellOffset);
+ HvMarkCellDirty(&Key->RegistryHive->Hive, Key->KeyCellOffset, FALSE);
- DPRINT("Return status 0x%08lx\n", Status);
+ DPRINT("Return status 0x%08x\n", Status);
return Status;
}
static BOOL
ConnectRegistry(
IN HKEY RootKey,
- IN PEREGISTRY_HIVE HiveToConnect,
+ IN PCMHIVE HiveToConnect,
IN LPCWSTR Path)
{
NTSTATUS Status;
Status = CmiInitializeTempHive(HiveToConnect);
if (!NT_SUCCESS(Status))
{
- DPRINT1("CmiInitializeTempHive() failed with status 0x%08lx\n", Status);
+ DPRINT1("CmiInitializeTempHive() failed with status 0x%08x\n", Status);
return FALSE;
}
return FALSE;
NewKey->RegistryHive = HiveToConnect;
- NewKey->KeyCellOffset = HiveToConnect->Hive.HiveHeader->RootCell;
- NewKey->KeyCell = HvGetCell (&HiveToConnect->Hive, NewKey->KeyCellOffset);
+ NewKey->KeyCellOffset = HiveToConnect->Hive.BaseBlock->RootCell;
+ NewKey->KeyCell = (PCM_KEY_NODE)HvGetCell (&HiveToConnect->Hive, NewKey->KeyCellOffset);
return TRUE;
}
-static BOOL
-MyExportBinaryHive (PCHAR FileName,
- PEREGISTRY_HIVE RootHive)
-{
- FILE *File;
- BOOL ret;
-
- /* 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);
-
- RootHive->HiveHandle = (HANDLE)File;
- ret = HvWriteHive(&RootHive->Hive);
- fclose (File);
- return ret;
-}
-
LIST_ENTRY CmiHiveListHead;
VOID
{
UNICODE_STRING RootKeyName = RTL_CONSTANT_STRING(L"\\");
NTSTATUS Status;
- HKEY ControlSetKey, LinkKey;
+ HKEY ControlSetKey;
InitializeListHead(&CmiHiveListHead);
Status = CmiInitializeTempHive(&RootHive);
if (!NT_SUCCESS(Status))
{
- DPRINT1("CmiInitializeTempHive() failed with status 0x%08lx\n", Status);
+ DPRINT1("CmiInitializeTempHive() failed with status 0x%08x\n", Status);
return;
}
RootKey = CreateInMemoryStructure(
&RootHive,
- RootHive.Hive.HiveHeader->RootCell,
+ RootHive.Hive.BaseBlock->RootCell,
&RootKeyName);
/* Create DEFAULT key */
&SystemHive,
L"Registry\\Machine\\SYSTEM");
- /* Create link 'CurrentControlSet' --> 'ControlSet001' */
+ /* Create 'ControlSet001' key */
RegCreateKeyW(
NULL,
L"Registry\\Machine\\SYSTEM\\ControlSet001",
&ControlSetKey);
- RegCreateKeyW(
- NULL,
- L"Registry\\Machine\\SYSTEM\\CurrentControlSet",
- &LinkKey);
- RegSetValueExW(LinkKey, NULL, 0, REG_LINK, (PCHAR)&ControlSetKey, sizeof(PVOID));
}
/* EOF */