4 * Copyright (C) 2001 Rex Jolliff
5 * Copyright (C) 2001 Eric Kohl
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
26 #define REG_DATA_SIZE_MASK 0x7FFFFFFF
27 #define REG_DATA_IN_OFFSET 0x80000000
29 /* FUNCTIONS ****************************************************************/
33 CmpAllocate (SIZE_T Size
, BOOLEAN Paged
, ULONG Tag
)
35 return MmHeapAlloc(Size
);
41 CmpFree (PVOID Ptr
, IN ULONG Quota
)
43 return MmHeapFree(Ptr
);
47 RegImportValue (PHHIVE Hive
,
48 PCM_KEY_VALUE ValueCell
,
57 if (ValueCell
->Signature
!= CM_KEY_VALUE_SIGNATURE
)
59 DPRINTM(DPRINT_REGISTRY
, "Invalid key cell!\n");
63 if (ValueCell
->Flags
& VALUE_COMP_NAME
)
65 wName
= MmHeapAlloc ((ValueCell
->NameLength
+ 1)*sizeof(WCHAR
));
66 for (i
= 0; i
< ValueCell
->NameLength
; i
++)
68 wName
[i
] = ((PCHAR
)ValueCell
->Name
)[i
];
70 wName
[ValueCell
->NameLength
] = 0;
74 wName
= MmHeapAlloc (ValueCell
->NameLength
+ sizeof(WCHAR
));
77 ValueCell
->NameLength
);
78 wName
[ValueCell
->NameLength
/ sizeof(WCHAR
)] = 0;
81 DataLength
= ValueCell
->DataLength
& REG_DATA_SIZE_MASK
;
83 DPRINTM(DPRINT_REGISTRY
, "ValueName: '%S'\n", wName
);
84 DPRINTM(DPRINT_REGISTRY
, "DataLength: %u\n", DataLength
);
86 if (DataLength
<= sizeof(HCELL_INDEX
) && (ValueCell
->DataLength
& REG_DATA_IN_OFFSET
))
88 Error
= RegSetValue(Key
,
91 (PCHAR
)&ValueCell
->Data
,
93 if (Error
!= ERROR_SUCCESS
)
95 DPRINTM(DPRINT_REGISTRY
, "RegSetValue() failed!\n");
102 DataCell
= (PVOID
)HvGetCell (Hive
, ValueCell
->Data
);
103 DPRINTM(DPRINT_REGISTRY
, "DataCell: %x\n", DataCell
);
105 Error
= RegSetValue (Key
,
111 if (Error
!= ERROR_SUCCESS
)
113 DPRINTM(DPRINT_REGISTRY
, "RegSetValue() failed!\n");
125 RegImportSubKey(PHHIVE Hive
,
126 PCM_KEY_NODE KeyCell
,
127 FRLDRHKEY ParentKey
);
130 RegImportIndexSubKey(PHHIVE Hive
,
131 PCM_KEY_INDEX IndexCell
,
136 DPRINTM(DPRINT_REGISTRY
, "IndexCell: %x\n", IndexCell
);
138 /* Enumerate and add subkeys */
139 if (IndexCell
->Signature
== CM_KEY_INDEX_ROOT
||
140 IndexCell
->Signature
== CM_KEY_INDEX_LEAF
)
142 for (i
= 0; i
< IndexCell
->Count
; i
++)
144 PCM_KEY_INDEX SubIndexCell
= HvGetCell(Hive
, IndexCell
->List
[i
]);
145 if (!RegImportIndexSubKey(Hive
, SubIndexCell
, ParentKey
))
149 else if (IndexCell
->Signature
== CM_KEY_FAST_LEAF
||
150 IndexCell
->Signature
== CM_KEY_HASH_LEAF
)
152 PCM_KEY_FAST_INDEX HashCell
= (PCM_KEY_FAST_INDEX
)IndexCell
;
153 for (i
= 0; i
< HashCell
->Count
; i
++)
155 PCM_KEY_NODE SubKeyCell
= HvGetCell(Hive
, HashCell
->List
[i
].Cell
);
156 if (!RegImportSubKey(Hive
, SubKeyCell
, ParentKey
))
170 RegImportSubKey(PHHIVE Hive
,
171 PCM_KEY_NODE KeyCell
,
174 PCM_KEY_INDEX IndexCell
;
175 PVALUE_LIST_CELL ValueListCell
;
176 PCM_KEY_VALUE ValueCell
= NULL
;
183 DPRINTM(DPRINT_REGISTRY
, "KeyCell: %x\n", KeyCell
);
184 DPRINTM(DPRINT_REGISTRY
, "KeyCell->Signature: %x\n", KeyCell
->Signature
);
185 if (KeyCell
->Signature
!= CM_KEY_NODE_SIGNATURE
)
187 DPRINTM(DPRINT_REGISTRY
, "Invalid key cell Signature!\n");
191 if (KeyCell
->Flags
& KEY_COMP_NAME
)
193 wName
= MmHeapAlloc ((KeyCell
->NameLength
+ 1) * sizeof(WCHAR
));
194 for (i
= 0; i
< KeyCell
->NameLength
; i
++)
196 wName
[i
] = ((PCHAR
)KeyCell
->Name
)[i
];
198 wName
[KeyCell
->NameLength
] = 0;
202 wName
= MmHeapAlloc (KeyCell
->NameLength
+ sizeof(WCHAR
));
205 KeyCell
->NameLength
);
206 wName
[KeyCell
->NameLength
/sizeof(WCHAR
)] = 0;
209 DPRINTM(DPRINT_REGISTRY
, "KeyName: '%S'\n", wName
);
211 /* Create new sub key */
212 Error
= RegCreateKey (ParentKey
,
216 if (Error
!= ERROR_SUCCESS
)
218 DPRINTM(DPRINT_REGISTRY
, "RegCreateKey() failed!\n");
221 DPRINTM(DPRINT_REGISTRY
, "Subkeys: %u\n", KeyCell
->SubKeyCounts
);
222 DPRINTM(DPRINT_REGISTRY
, "Values: %u\n", KeyCell
->ValueList
.Count
);
224 /* Enumerate and add values */
225 if (KeyCell
->ValueList
.Count
> 0)
227 ValueListCell
= (PVALUE_LIST_CELL
) HvGetCell (Hive
, KeyCell
->ValueList
.List
);
228 DPRINTM(DPRINT_REGISTRY
, "ValueListCell: %x\n", ValueListCell
);
230 for (i
= 0; i
< KeyCell
->ValueList
.Count
; i
++)
232 DPRINTM(DPRINT_REGISTRY
, "ValueOffset[%d]: %x\n", i
, ValueListCell
->ValueOffset
[i
]);
234 ValueCell
= (PCM_KEY_VALUE
) HvGetCell (Hive
, ValueListCell
->ValueOffset
[i
]);
236 DPRINTM(DPRINT_REGISTRY
, "ValueCell[%d]: %x\n", i
, ValueCell
);
238 if (!RegImportValue(Hive
, ValueCell
, SubKey
))
243 /* Enumerate and add subkeys */
244 if (KeyCell
->SubKeyCounts
[Stable
] > 0)
246 IndexCell
= HvGetCell (Hive
, KeyCell
->SubKeyLists
[Stable
]);
248 if (!RegImportIndexSubKey(Hive
, IndexCell
, SubKey
))
257 RegImportBinaryHive(PCHAR ChunkBase
,
260 PCM_KEY_NODE KeyCell
;
261 PCM_KEY_FAST_INDEX HashCell
;
262 PCM_KEY_NODE SubKeyCell
;
270 DPRINTM(DPRINT_REGISTRY
, "RegImportBinaryHive(%x, %u) called\n",ChunkBase
,ChunkSize
);
272 CmHive
= CmpAllocate(sizeof(CMHIVE
), TRUE
, 0);
273 Status
= HvInitialize (&CmHive
->Hive
,
286 if (!NT_SUCCESS(Status
))
289 DPRINTM(DPRINT_REGISTRY
, "Invalid hive Signature!\n");
293 Hive
= &CmHive
->Hive
;
294 KeyCell
= (PCM_KEY_NODE
)HvGetCell (Hive
, Hive
->BaseBlock
->RootCell
);
295 DPRINTM(DPRINT_REGISTRY
, "KeyCell: %x\n", KeyCell
);
296 DPRINTM(DPRINT_REGISTRY
, "KeyCell->Signature: %x\n", KeyCell
->Signature
);
297 if (KeyCell
->Signature
!= CM_KEY_NODE_SIGNATURE
)
299 DPRINTM(DPRINT_REGISTRY
, "Invalid key cell Signature!\n");
303 DPRINTM(DPRINT_REGISTRY
, "Subkeys: %u\n", KeyCell
->SubKeyCounts
);
304 DPRINTM(DPRINT_REGISTRY
, "Values: %u\n", KeyCell
->ValueList
.Count
);
306 /* Open 'System' key */
307 Error
= RegOpenKey(NULL
,
308 L
"\\Registry\\Machine\\SYSTEM",
310 if (Error
!= ERROR_SUCCESS
)
312 DPRINTM(DPRINT_REGISTRY
, "Failed to open 'system' key!\n");
316 /* Enumerate and add subkeys */
317 if (KeyCell
->SubKeyCounts
[Stable
] > 0)
319 HashCell
= (PCM_KEY_FAST_INDEX
)HvGetCell (Hive
, KeyCell
->SubKeyLists
[Stable
]);
320 DPRINTM(DPRINT_REGISTRY
, "HashCell: %x\n", HashCell
);
321 DPRINTM(DPRINT_REGISTRY
, "SubKeyCounts: %x\n", KeyCell
->SubKeyCounts
[Stable
]);
323 for (i
= 0; i
< KeyCell
->SubKeyCounts
[Stable
]; i
++)
325 DPRINTM(DPRINT_REGISTRY
, "Cell[%d]: %x\n", i
, HashCell
->List
[i
].Cell
);
327 SubKeyCell
= (PCM_KEY_NODE
)HvGetCell (Hive
, HashCell
->List
[i
].Cell
);
329 DPRINTM(DPRINT_REGISTRY
, "SubKeyCell[%d]: %x\n", i
, SubKeyCell
);
331 if (!RegImportSubKey(Hive
, SubKeyCell
, SystemKey
))