source: trunk/doc/devel/winntreg.txt @ 97

Last change on this file since 97 was 97, checked in by tim, 16 years ago

begun the work of rewriting the lowest layer parsing routines

File size: 10.0 KB
Line 
1The windows NT registry has 2 different blocks, where one can occur many
2times...
3
4the "regf"-Block
5================
6 
7"regf" is obviosly the abbreviation for "Registry file". "regf" is the
8signature of the header-block which is always 4kb in size, although only
9the first 64 bytes seem to be used and a checksum is calculated over
10the first 0x200 bytes only!
11
12Offset            Size      Contents
130x00000000      D-Word      ID: ASCII-"regf" = 0x66676572
140x00000004      D-Word      ???? //see struct REGF
150x00000008      D-Word      ???? Always the same value as at 0x00000004
160x0000000C      Q-Word      last modify date in WinNT date-format
170x00000014      D-Word      1
180x00000018      D-Word      3
190x0000001C      D-Word      0
200x00000020      D-Word      1
210x00000024      D-Word      Offset of 1st key record
220x00000028      D-Word      Size of the data-blocks (Filesize-4kb)
230x0000002C      D-Word      1
240x000001FC      D-Word      Sum of all D-Words from 0x00000000 to
250x000001FB  //XOR of all words. Nigel
26
27I have analyzed more registry files (from multiple machines running
28NT 4.0 german version) and could not find an explanation for the values
29marked with ???? the rest of the first 4kb page is not important...
30
31the "hbin"-Block
32================
33I dont know what "hbin" stands for, but this block is always a multiple
34of 4kb in size.
35
36Inside these hbin-blocks the different records are placed. The memory-
37management looks like a C-compiler heap management to me...
38
39hbin-Header
40===========
41Offset      Size      Contents
420x0000      D-Word      ID: ASCII-"hbin" = 0x6E696268
430x0004      D-Word      Offset from the 1st hbin-Block
440x0008      D-Word      Offset to the next hbin-Block
450x001C      D-Word      Block-size
46
47The values in 0x0008 and 0x001C should be the same, so I dont know
48if they are correct or swapped...
49
50From offset 0x0020 inside a hbin-block data is stored with the following
51format:
52
53Offset      Size      Contents
540x0000      D-Word      Data-block size    //this size must be a
55multiple of 8. Nigel
560x0004      ????      Data
57 
58If the size field is negative (bit 31 set), the corresponding block
59is free and has a size of -blocksize!
60
61That does not seem to be true. All block lengths seem to be negative!
62(Richard Sharpe)
63
64The data is stored as one record per block. Block size is a multiple
65of 4 and the last block reaches the next hbin-block, leaving no room.
66
67(That also seems incorrect, in that the block size if a multiple of 8.
68That is, the block, including the 4 byte header, is always a multiple of
698 bytes. Richard Sharpe.)
70
71Records in the hbin-blocks
72==========================
73
74nk-Record
75
76      The nk-record can be treated as a kombination of tree-record and
77      key-record of the win 95 registry.
78
79lf-Record
80
81      The lf-record is the counterpart to the RGKN-record (the
82      hash-function)
83
84vk-Record
85
86      The vk-record consists information to a single value.
87
88sk-Record
89
90      sk (? Security Key ?) is the ACL of the registry.
91
92Value-Lists
93
94      The value-lists contain information about which values are inside a
95      sub-key and dont have a header.
96
97Datas
98
99      The datas of the registry are (like the value-list) stored without a
100      header.
101
102All offset-values are relative to the first hbin-block and point to the
103block-size field of the record-entry. to get the file offset, you have to add
104the header size (4kb) and the size field (4 bytes)...
105
106the nk-Record
107=============
108Offset      Size      Contents
1090x0000      Word      ID: ASCII-"nk" = 0x6B6E
1100x0002      Word      for the root-key: 0x2C, otherwise 0x20  //key symbolic links 0x10. Nigel
1110x0004      Q-Word      write-date/time in windows nt notation
1120x000C      D-Word      UNKNOWN // added by TDM
1130x0010      D-Word      Offset of Owner/Parent key
1140x0014      D-Word      number of sub-Keys
1150x0018      D-Word      UNKNOWN // added by TDM
1160x001C      D-Word      Offset of the sub-key lf-Records
1170x0020      D-Word      UNKNOWN // added by TDM
1180x0024      D-Word      number of values
1190x0028      D-Word      Offset of the Value-List
1200x002C      D-Word      Offset of the sk-Record
121
1220x0030      D-Word      Offset of the Class-Name //see NK structure for the use of these fields. Nigel
1230x0044      D-Word      Unused (data-trash)  //some kind of run time index. Does not appear to be important. Nigel
1240x0048      Word      name-length
1250x004A      Word      class-name length
1260x004C      ????      key-name
127
128the Value-List
129==============
130Offset      Size      Contents
1310x0000      D-Word      Offset 1st Value
1320x0004      D-Word      Offset 2nd Value
1330x????      D-Word      Offset nth Value
134
135To determine the number of values, you have to look at the owner-nk-record!
136
137Der vk-Record
138=============
139Offset      Size      Contents
1400x0000      Word      ID: ASCII-"vk" = 0x6B76
1410x0002      Word      name length
1420x0004      D-Word      length of the data   //if top bit is set when offset contains data. Nigel
1430x0008      D-Word      Offset of Data
1440x000C      D-Word      Type of value
1450x0010      Word      Flag
1460x0012      Word      Unused (data-trash)
1470x0014      ????      Name
148
149If bit 0 of the flag-word is set, a name is present, otherwise the value has no name (=default)
150
151If the data-size is lower 5, the data-offset value is used to store the data itself!
152
153The data-types
154==============
155Wert      Beteutung
1560x0001      RegSZ:             character string (in UNICODE!)
1570x0002      ExpandSZ:   string with "%var%" expanding (UNICODE!)
1580x0003      RegBin:           raw-binary value
1590x0004      RegDWord:   Dword
1600x0007      RegMultiSZ:      multiple strings, seperated with 0
161                  (UNICODE!)
162
163The "lf"-record
164===============
165Offset      Size      Contents
1660x0000      Word      ID: ASCII-"lf" = 0x666C
1670x0002      Word      number of keys
1680x0004      ????      Hash-Records
169
170Hash-Record
171===========
172Offset      Size      Contents
1730x0000      D-Word      Offset of corresponding "nk"-Record
1740x0004      D-Word      ASCII: the first 4 characters of the key-name, padded with 0-s. Case sensitiv!
175
176Keep in mind, that the value at 0x0004 is used for checking the data-consistency! If you change the
177key-name you have to change the hash-value too!
178
179//These hashrecords must be sorted low to high within the lf record. Nigel.
180
181The "sk"-block
182==============
183(due to the complexity of the SAM-info, not clear jet)
184(This is just a self-relative security descriptor in the data. R Sharpe.)
185
186
187Offset      Size      Contents
1880x0000      Word      ID: ASCII-"sk" = 0x6B73
1890x0002      Word      Unused
1900x0004      D-Word      Offset of previous "sk"-Record
1910x0008      D-Word      Offset of next "sk"-Record
1920x000C      D-Word      usage-counter
1930x0010      D-Word      Size of "sk"-record in bytes
194????                                             //standard self
195relative security desciptor. Nigel
196????  ????      Security and auditing settings...
197????
198
199The usage counter counts the number of references to this
200"sk"-record. You can use one "sk"-record for the entire registry!
201
202Windows nt date/time format
203===========================
204The time-format is a 64-bit integer which is incremented every
2050,0000001 seconds by 1 (I dont know how accurate it really is!)
206It starts with 0 at the 1st of january 1601 0:00! All values are
207stored in GMT time! The time-zone is important to get the real
208time!
209
210Common values for win95 and win-nt
211==================================
212Offset values marking an "end of list", are either 0 or -1 (0xFFFFFFFF).
213If a value has no name (length=0, flag(bit 0)=0), it is treated as the
214"Default" entry...
215If a value has no data (length=0), it is displayed as empty.
216
217simplyfied win-3.?? registry:
218=============================
219
220+-----------+
221| next rec. |---+                      +----->+------------+
222| first sub |   |                      |      | Usage cnt. |
223| name      |   |  +-->+------------+  |      | length     |
224| value     |   |  |   | next rec.  |  |      | text       |------->+-------+
225+-----------+   |  |   | name rec.  |--+      +------------+        | xxxxx |
226   +------------+  |   | value rec. |-------->+------------+        +-------+
227   v               |   +------------+         | Usage cnt. |
228+-----------+      |                          | length     |
229| next rec. |      |                          | text       |------->+-------+
230| first sub |------+                          +------------+        | xxxxx |
231| name      |                                                       +-------+
232| value     |
233+-----------+   
234
235Greatly simplyfied structure of the nt-registry:
236================================================
237   
238+---------------------------------------------------------------+
239|                                                               |
240v                                                               |
241+---------+     +---------->+-----------+  +----->+---------+   |
242| "nk"    |     |           | lf-rec.   |  |      | nk-rec. |   |
243| ID      |     |           | # of keys |  |      | parent  |---+
244| Date    |     |           | 1st key   |--+      | ....    |
245| parent  |     |           +-----------+         +---------+
246| suk-keys|-----+
247| values  |--------------------->+----------+
248| SK-rec. |---------------+      | 1. value |--> +----------+
249| class   |--+            |      +----------+    | vk-rec.  |
250+---------+  |            |                      | ....     |
251             v            |                      | data     |--> +-------+
252      +------------+      |                      +----------+    | xxxxx |
253      | Class name |      |                                      +-------+
254      +------------+      |
255                          v
256          +---------+    +---------+
257   +----->| next sk |--->| Next sk |--+
258   |  +---| prev sk |<---| prev sk |  |
259   |  |   | ....    |    | ...     |  |
260   |  |   +---------+    +---------+  |
261   |  |                    ^          |
262   |  |                    |          |
263   |  +--------------------+          |
264   +----------------------------------+
265
266---------------------------------------------------------------------------
267
268Hope this helps....  (Although it was *fun* for me to uncover this things,
269                  it took me several sleepless nights ;)
270
271            B.D.
Note: See TracBrowser for help on using the repository browser.