@@ -16,6 +16,8 @@ namespace Registry
16
16
// public classes...
17
17
public class RegistryHive : RegistryBase
18
18
{
19
+ // private const string wildCardChar = "¿";
20
+ private const string wildCardChar = "*" ;
19
21
internal static int HardParsingErrorsInternal ;
20
22
internal static int SoftParsingErrorsInternal ;
21
23
private readonly Dictionary < string , RegistryKey > _keyPathKeyMap = new Dictionary < string , RegistryKey > ( ) ;
@@ -41,7 +43,7 @@ public RegistryHive(string hivePath) : base(hivePath)
41
43
UnassociatedRegistryValues = new List < KeyValue > ( ) ;
42
44
}
43
45
44
- public RegistryHive ( byte [ ] rawBytes , string filePath ) : base ( rawBytes , filePath )
46
+ public RegistryHive ( byte [ ] rawBytes , string filePath ) : base ( rawBytes , filePath )
45
47
{
46
48
CellRecords = new Dictionary < long , ICellTemplate > ( ) ;
47
49
ListRecords = new Dictionary < long , IListTemplate > ( ) ;
@@ -135,7 +137,7 @@ private DataNode GetDataNodeFromOffset(long relativeOffset)
135
137
136
138
public byte [ ] ProcessTransactionLogs ( List < TransactionLogFileInfo > logFileInfos , bool updateExistingData = false )
137
139
{
138
- if ( logFileInfos . Count == 0 )
140
+ if ( logFileInfos . Count == 0 )
139
141
{
140
142
throw new Exception ( "No logs were supplied" ) ;
141
143
}
@@ -156,7 +158,7 @@ public byte[] ProcessTransactionLogs(List<TransactionLogFileInfo> logFileInfos,
156
158
continue ;
157
159
}
158
160
159
- var transLog = new TransactionLog ( logFile . FileBytes , logFile . FileName ) ;
161
+ var transLog = new TransactionLog ( logFile . FileBytes , logFile . FileName ) ;
160
162
161
163
if ( HiveType != transLog . HiveType )
162
164
{
@@ -306,20 +308,19 @@ public byte[] ProcessTransactionLogs(List<string> logFiles, bool updateExistingD
306
308
{
307
309
//get bytes for file
308
310
var b = File . ReadAllBytes ( ofFileName ) ;
309
-
311
+
310
312
311
313
if ( b . Length == 0 )
312
314
{
313
315
continue ;
314
316
}
315
317
316
- var lfi = new TransactionLogFileInfo ( ofFileName , b ) ;
318
+ var lfi = new TransactionLogFileInfo ( ofFileName , b ) ;
317
319
318
320
logfileInfos . Add ( lfi ) ;
319
321
}
320
322
321
323
return ProcessTransactionLogs ( logfileInfos , updateExistingData ) ;
322
-
323
324
}
324
325
325
326
//TODO this needs refactored to remove duplicated code
@@ -329,7 +330,7 @@ private List<RegistryKey> GetSubKeysAndValues(RegistryKey key)
329
330
330
331
_keyPathKeyMap . Add ( key . KeyPath . ToLowerInvariant ( ) , key ) ;
331
332
332
- // Logger.Trace("Getting subkeys for {0}", key.KeyPath);
333
+ // Logger.Trace("Getting subkeys for {0}", key.KeyPath);
333
334
334
335
key . KeyFlags = RegistryKey . KeyFlagsEnum . HasActiveParent ;
335
336
@@ -1012,10 +1013,7 @@ public bool ParseHive()
1012
1013
return true ;
1013
1014
}
1014
1015
1015
- // private const string wildCardChar = "¿";
1016
- private const string wildCardChar = "*" ;
1017
-
1018
- public HashSet < string > ExpandKeyPath ( string wildCardPath )
1016
+ public HashSet < string > ExpandKeyPath ( string wildCardPath )
1019
1017
{
1020
1018
var keyPaths = new HashSet < string > ( ) ;
1021
1019
@@ -1040,13 +1038,10 @@ public HashSet<string> ExpandKeyPath( string wildCardPath)
1040
1038
var pathSegmentPointer = 1 ;
1041
1039
foreach ( var pathSegment in pathSegments )
1042
1040
{
1043
- if ( pathSegment . Contains ( wildCardChar ) )
1041
+ if ( pathSegment . Contains ( wildCardChar ) )
1044
1042
{
1045
- //we do not want to process like this if the key name == the wildcard
1046
-
1047
1043
//we have a wild card
1048
1044
var expanded = ExpandStar ( currentKey , pathSegment ) . ToList ( ) ;
1049
- // Debug.WriteLine($"pathSegment: {pathSegment}, expanded: {string.Join(",", expanded)}");
1050
1045
1051
1046
var removedSelf = false ;
1052
1047
@@ -1057,106 +1052,89 @@ public HashSet<string> ExpandKeyPath( string wildCardPath)
1057
1052
{
1058
1053
keyPaths . Add ( $ "{ currentKey . KeyPath } \\ { pathSegment } ") ;
1059
1054
}
1060
-
1061
1055
1062
1056
expanded . Remove ( pathSegment ) ;
1063
1057
//here we need to change from count == 1 to does the list contain the path we sent in? if so, pull that entry from the list and process it singly
1064
1058
1065
1059
removedSelf = true ;
1066
-
1067
1060
}
1068
-
1069
-
1070
- //take the expanded paths and append what is left, then continue
1071
- var whatsLeft = string . Join ( "\\ " , pathSegments . Skip ( pathSegmentPointer ) ) ;
1072
1061
1073
- foreach ( var exp in expanded )
1074
- {
1075
- var tempPath = $ "{ exp } \\ { whatsLeft } ";
1076
- var tempPFullath = $ "{ currentKey . KeyPath } \\ { tempPath } ";
1062
+ //take the expanded paths and append what is left, then continue
1063
+ var whatsLeft = string . Join ( "\\ " , pathSegments . Skip ( pathSegmentPointer ) ) ;
1077
1064
1078
- if ( GetKey ( tempPFullath ) != null )
1079
- {
1080
- //the path as is exists
1081
- keyPaths . Add ( tempPFullath . Trim ( '\\ ' , '/' ) ) ;
1082
- }
1065
+ foreach ( var exp in expanded )
1066
+ {
1067
+ var tempPath = $ "{ exp } \\ { whatsLeft } ";
1068
+ var tempFullPath = $ "{ currentKey . KeyPath } \\ { tempPath } ";
1083
1069
1084
- if ( tempPath . Contains ( wildCardChar ) && keyPaths . Contains ( tempPFullath ) == false )
1085
- {
1086
- var asd = ExpandKeyPath ( tempPFullath ) ;
1087
- foreach ( var aa in asd )
1088
- {
1089
- keyPaths . Add ( aa . Trim ( '\\ ' , '/' ) ) ;
1090
- }
1091
- }
1070
+ if ( GetKey ( tempFullPath ) != null )
1071
+ {
1072
+ //the path as is exists
1073
+ keyPaths . Add ( tempFullPath . Trim ( '\\ ' , '/' ) ) ;
1092
1074
}
1093
1075
1094
-
1095
- if ( removedSelf )
1076
+ if ( tempPath . Contains ( wildCardChar ) && keyPaths . Contains ( tempFullPath ) == false )
1096
1077
{
1097
- //move current key up one since we already accounted for it
1098
- var tempKey =
1099
- currentKey . SubKeys . SingleOrDefault ( t => string . Equals ( t . KeyName . ToUpperInvariant ( ) ,
1100
- pathSegment . ToUpperInvariant ( ) , StringComparison . OrdinalIgnoreCase ) ) ;
1101
-
1102
- if ( tempKey == null )
1078
+ var asd = ExpandKeyPath ( tempFullPath ) ;
1079
+ foreach ( var aa in asd )
1103
1080
{
1104
- throw new Exception ( ) ;
1081
+ keyPaths . Add ( aa . Trim ( ' \\ ' , '/' ) ) ;
1105
1082
}
1083
+ }
1084
+ }
1106
1085
1107
- currentKey = tempKey ;
1108
-
1109
-
1110
1086
1111
- var tempSkip = pathSegmentPointer ;
1087
+ if ( removedSelf )
1088
+ {
1089
+ //move current key up one since we already accounted for it
1090
+ var tempKey =
1091
+ currentKey . SubKeys . SingleOrDefault ( t => string . Equals ( t . KeyName . ToUpperInvariant ( ) ,
1092
+ pathSegment . ToUpperInvariant ( ) , StringComparison . OrdinalIgnoreCase ) ) ;
1093
+
1094
+ currentKey = tempKey ;
1112
1095
1113
- if ( pathSegmentPointer == pathSegments . Length )
1114
- {
1115
- tempSkip += 1 ;
1116
- }
1096
+ var tempSkip = pathSegmentPointer ;
1117
1097
1098
+ if ( pathSegmentPointer == pathSegments . Length )
1099
+ {
1100
+ tempSkip += 1 ;
1101
+ }
1118
1102
1119
- whatsLeft = string . Join ( "\\ " , pathSegments . Skip ( tempSkip ) ) ;
1120
- var tempPFullath = $ "{ currentKey . KeyPath } \\ { whatsLeft } ";
1103
+ whatsLeft = string . Join ( "\\ " , pathSegments . Skip ( tempSkip ) ) ;
1104
+ var tempPFullath = $ "{ currentKey . KeyPath } \\ { whatsLeft } ";
1121
1105
1122
- Debug . WriteLine ( $ "Whatsleft: { whatsLeft } tempPFullath: { tempPFullath } ") ;
1106
+ if ( GetKey ( tempPFullath ) != null )
1107
+ {
1108
+ //the path as is exists
1109
+ keyPaths . Add ( tempPFullath . Trim ( '\\ ' , '/' ) ) ;
1110
+ }
1123
1111
1124
- if ( GetKey ( tempPFullath ) != null )
1125
- {
1126
- //the path as is exists
1127
- keyPaths . Add ( tempPFullath . Trim ( '\\ ' , '/' ) ) ;
1128
- }
1112
+ if ( whatsLeft . Contains ( wildCardChar ) && keyPaths . Contains ( tempPFullath ) == false )
1113
+ {
1114
+ var expanded2 = ExpandStar ( currentKey , whatsLeft ) . ToList ( ) ;
1129
1115
1130
- if ( whatsLeft . Contains ( wildCardChar ) && keyPaths . Contains ( tempPFullath ) == false )
1116
+ foreach ( var exp in expanded2 )
1131
1117
{
1132
- var expanded2 = ExpandStar ( currentKey , whatsLeft ) . ToList ( ) ;
1118
+ var tempPath = $ "{ exp } \\ { whatsLeft } ";
1119
+ tempPFullath = $ "{ currentKey . KeyPath } \\ { tempPath } ";
1133
1120
1134
- foreach ( var exp in expanded2 )
1121
+ if ( GetKey ( tempPFullath ) != null )
1135
1122
{
1136
- var tempPath = $ "{ exp } \\ { whatsLeft } ";
1137
- tempPFullath = $ "{ currentKey . KeyPath } \\ { tempPath } ";
1138
-
1139
- if ( GetKey ( tempPFullath ) != null )
1140
- {
1141
- //the path as is exists
1142
- keyPaths . Add ( tempPFullath . Trim ( '\\ ' , '/' ) ) ;
1143
- }
1123
+ //the path as is exists
1124
+ keyPaths . Add ( tempPFullath . Trim ( '\\ ' , '/' ) ) ;
1125
+ }
1144
1126
1145
- if ( tempPath . Contains ( wildCardChar ) && keyPaths . Contains ( tempPFullath ) == false )
1127
+ if ( tempPath . Contains ( wildCardChar ) && keyPaths . Contains ( tempPFullath ) == false )
1128
+ {
1129
+ var asd1 = ExpandKeyPath ( tempPFullath ) ;
1130
+ foreach ( var aa in asd1 )
1146
1131
{
1147
- var asd1 = ExpandKeyPath ( tempPFullath ) ;
1148
- foreach ( var aa in asd1 )
1149
- {
1150
- keyPaths . Add ( aa . Trim ( '\\ ' , '/' ) ) ;
1151
- }
1132
+ keyPaths . Add ( aa . Trim ( '\\ ' , '/' ) ) ;
1152
1133
}
1153
1134
}
1154
-
1155
-
1156
1135
}
1157
1136
}
1158
-
1159
-
1137
+ }
1160
1138
}
1161
1139
else
1162
1140
{
@@ -1179,7 +1157,6 @@ public HashSet<string> ExpandKeyPath( string wildCardPath)
1179
1157
}
1180
1158
1181
1159
return keyPaths ;
1182
-
1183
1160
}
1184
1161
1185
1162
private IEnumerable < string > ExpandStar ( RegistryKey key , string starString )
@@ -1252,9 +1229,9 @@ private IEnumerable<string> ExpandStar(RegistryKey key, string starString)
1252
1229
var cleanKey = startKeySubKey . KeyName ;
1253
1230
if ( cleanKey . ToUpperInvariant ( ) . StartsWith ( Root . KeyName . ToUpperInvariant ( ) ) )
1254
1231
{
1255
-
1256
1232
cleanKey = StripRootKeyNameFromKeyPath ( cleanKey ) ;
1257
1233
}
1234
+
1258
1235
Debug . WriteLine ( $ "cleanKey: { cleanKey } ") ;
1259
1236
keyPaths . Add ( cleanKey ) ;
1260
1237
}
@@ -1431,11 +1408,6 @@ private void BuildDeletedRegistryKeys()
1431
1408
}
1432
1409
}
1433
1410
}
1434
- else
1435
- {
1436
- // Logger.Trace(
1437
- // $"vk record at relative offset 0x{valueOffset:X} not found for nk record at absolute offset 0x{nk.AbsoluteOffset:X}");
1438
- }
1439
1411
}
1440
1412
1441
1413
// Logger.Trace(
@@ -1567,7 +1539,7 @@ private void BuildDeletedRegistryKeys()
1567
1539
1568
1540
private void UpdateChildPaths ( RegistryKey key )
1569
1541
{
1570
- // Logger.Trace("Updating child paths or key {0}", key.KeyPath);
1542
+ // Logger.Trace("Updating child paths or key {0}", key.KeyPath);
1571
1543
foreach ( var sk in key . SubKeys )
1572
1544
{
1573
1545
sk . KeyPath = $@ "{ key . KeyPath } \{ sk . KeyName } ";
0 commit comments