Skip to content

Commit fd257f7

Browse files
committed
update to use binary reader convenience
methods more
1 parent 93424d4 commit fd257f7

File tree

4 files changed

+27
-24
lines changed

4 files changed

+27
-24
lines changed

ch11_reading_offline_hives/NodeKey.cs

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -44,24 +44,24 @@ private void ReadNodeStructure(BinaryReader hive) {
4444

4545
hive.BaseStream.Position += 4;
4646

47-
this.ParentOffset = BitConverter.ToInt32(hive.ReadBytes (4),0);
48-
this.SubkeysCount = BitConverter.ToInt32(hive.ReadBytes (4),0);
47+
this.ParentOffset = hive.ReadInt32 ();
48+
this.SubkeysCount = hive.ReadInt32();
4949

5050
hive.BaseStream.Position += 4;
5151

52-
this.LFRecordOffset = BitConverter.ToInt32(hive.ReadBytes (4),0);
52+
this.LFRecordOffset = hive.ReadInt32 ();
5353

5454
hive.BaseStream.Position += 4;
5555

56-
this.ValuesCount = BitConverter.ToInt32(hive.ReadBytes (4),0);
57-
this.ValueListOffset = BitConverter.ToInt32(hive.ReadBytes (4),0);
58-
this.SecurityKeyOffset = BitConverter.ToInt32(hive.ReadBytes (4),0);
59-
this.ClassnameOffset = BitConverter.ToInt32(hive.ReadBytes (4),0);
56+
this.ValuesCount = hive.ReadInt32 ();
57+
this.ValueListOffset = hive.ReadInt32 ();
58+
this.SecurityKeyOffset = hive.ReadInt32 ();
59+
this.ClassnameOffset = hive.ReadInt32 ();
6060

61-
hive.BaseStream.Position += (startingOffset + 0x0044) - hive.BaseStream.Position;
61+
hive.BaseStream.Position += (startingOffset + 68) - hive.BaseStream.Position;
6262

63-
this.NameLength = BitConverter.ToInt16(hive.ReadBytes (2),0);
64-
this.ClassnameLength = BitConverter.ToInt16(hive.ReadBytes (2),0);
63+
this.NameLength = hive.ReadInt16 ();
64+
this.ClassnameLength = hive.ReadInt16 ();
6565

6666
buf = hive.ReadBytes(this.NameLength);
6767
this.Name = System.Text.Encoding.UTF8.GetString(buf);
@@ -77,11 +77,11 @@ private void ReadChildrenNodes(BinaryReader hive) {
7777

7878
//ri
7979
if (buf [0] == 0x72 && buf [1] == 0x69) {
80-
int count = BitConverter.ToInt16(hive.ReadBytes(2),0);
80+
int count = hive.ReadInt16 ();
8181

8282
for (int i = 0; i < count; i++) {
8383
long pos = hive.BaseStream.Position;
84-
int offset = BitConverter.ToInt32 (hive.ReadBytes (4), 0);
84+
int offset = hive.ReadInt32 ();
8585
hive.BaseStream.Position = 4096 + offset + 4;
8686
buf = hive.ReadBytes(2);
8787

@@ -102,13 +102,13 @@ private void ReadChildrenNodes(BinaryReader hive) {
102102
}
103103

104104
private void ParseChildNodes(BinaryReader hive){
105-
int count = BitConverter.ToInt16(hive.ReadBytes(2),0);
105+
int count = hive.ReadInt16 ();
106106
long topOfList = hive.BaseStream.Position;
107107

108108
for (int i = 0; i < count; i++)
109109
{
110110
hive.BaseStream.Position = topOfList + (i*8);
111-
int newoffset = BitConverter.ToInt32(hive.ReadBytes(4),0);
111+
int newoffset = hive.ReadInt32 ();
112112
hive.BaseStream.Position += 4;
113113
//byte[] check = hive.ReadBytes(4);
114114
hive.BaseStream.Position = 4096 + newoffset + 4;
@@ -128,7 +128,7 @@ private void ReadChildValues(BinaryReader hive) {
128128
for (int i = 0; i < this.ValuesCount; i++)
129129
{
130130
hive.BaseStream.Position = 4096 + this.ValueListOffset + 4 + (i*4);
131-
int offset = BitConverter.ToInt32(hive.ReadBytes(4), 0);
131+
int offset = hive.ReadInt32 ();
132132
hive.BaseStream.Position = 4096 + offset + 4;
133133
this.ChildValues.Add(new ValueKey(hive));
134134
}

ch11_reading_offline_hives/RegistryHive.cs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,12 +23,15 @@ public RegistryHive(string file)
2323

2424
reader.ReadBytes(8);
2525
buf = reader.ReadBytes(8);
26-
27-
long timestamp = BitConverter.ToInt64(buf, 0);
26+
//Array.Reverse(buf);
27+
long timestamp = BitConverter.ToInt64 (buf, 0);
28+
//long timestamp = reader.ReadInt64 ();
29+
DateTime time = DateTime.FromBinary (timestamp);
30+
2831
this.WasExported = (timestamp == 0) ? true : false;
2932

3033
//fast-forward
31-
reader.BaseStream.Position += (0x1000 + 0x20 + 4)-reader.BaseStream.Position;
34+
reader.BaseStream.Position += (4096 + 32 + 4)-reader.BaseStream.Position;
3235

3336
this.RootKey = new NodeKey(reader);
3437
}

ch11_reading_offline_hives/ValueKey.cs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ public ValueKey (BinaryReader hive)
1313
if (buf[0] != 0x76 && buf[1] != 0x6b)
1414
throw new NotSupportedException("Bad vk header");
1515

16-
buf = hive.ReadBytes(2);
17-
18-
this.NameLength = BitConverter.ToInt16(buf,0);
19-
this.DataLength = BitConverter.ToInt32(hive.ReadBytes(4),0);
16+
this.NameLength = hive.ReadInt16();
17+
this.DataLength = hive.ReadInt32 ();
18+
//this.DataLength = BitConverter.ToInt32(hive.ReadBytes(4),0);
2019

2120
byte[] databuf = hive.ReadBytes(4);
2221

@@ -30,7 +29,7 @@ public ValueKey (BinaryReader hive)
3029
this.Data = databuf;
3130
else
3231
{
33-
hive.BaseStream.Position = 0x1000 + BitConverter.ToInt32(databuf, 0) + 0x04;
32+
hive.BaseStream.Position = 4096 + BitConverter.ToInt32 (databuf, 0) + 4;
3433
this.Data = hive.ReadBytes(this.DataLength);
3534
}
3635
}

ch11_reading_offline_hives/ch11_reading_offline_hives.csproj

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,9 @@
1616
<DefineConstants>DEBUG;</DefineConstants>
1717
<ErrorReport>prompt</ErrorReport>
1818
<WarningLevel>4</WarningLevel>
19-
<Externalconsole>true</Externalconsole>
2019
<PlatformTarget>x86</PlatformTarget>
20+
<Commandlineparameters>/Users/bperry/system.hive</Commandlineparameters>
21+
<ConsolePause>false</ConsolePause>
2122
</PropertyGroup>
2223
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
2324
<DebugType>full</DebugType>

0 commit comments

Comments
 (0)