Skip to content

Commit f470263

Browse files
committed
Func not obj
1 parent 3822cc4 commit f470263

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

BinaryObjectScanner/FileType/Executable.cs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ public class Executable : IDetectable
4747
public string? Detect(Stream stream, string file, bool includeDebug)
4848
{
4949
// Get all non-nested protections
50-
var protections = DetectDict(stream, file, scanner: null, includeDebug);
50+
var protections = DetectDict(stream, file, getProtections: null, includeDebug);
5151
if (protections.Count == 0)
5252
return null;
5353

@@ -66,7 +66,10 @@ public class Executable : IDetectable
6666
/// Ideally, we wouldn't need to circumvent the proper handling of file types just for Executable,
6767
/// but due to the complexity of scanning, this is not currently possible.
6868
/// </remarks>
69-
public ProtectionDictionary DetectDict(Stream stream, string file, Scanner? scanner, bool includeDebug)
69+
public ProtectionDictionary DetectDict(Stream stream,
70+
string file,
71+
Func<string, ProtectionDictionary>? getProtections,
72+
bool includeDebug)
7073
{
7174
// Create the output dictionary
7275
var protections = new ProtectionDictionary();
@@ -99,7 +102,7 @@ public ProtectionDictionary DetectDict(Stream stream, string file, Scanner? scan
99102
protections.Append(file, subProtections.Values);
100103

101104
// Extractable checks
102-
var extractedProtections = HandleExtractableProtections(file, mz, subProtections.Keys, scanner, includeDebug);
105+
var extractedProtections = HandleExtractableProtections(file, mz, subProtections.Keys, getProtections, includeDebug);
103106
protections.Append(extractedProtections);
104107
}
105108
else if (wrapper is LinearExecutable lex)
@@ -109,7 +112,7 @@ public ProtectionDictionary DetectDict(Stream stream, string file, Scanner? scan
109112
protections.Append(file, subProtections.Values);
110113

111114
// Extractable checks
112-
var extractedProtections = HandleExtractableProtections(file, lex, subProtections.Keys, scanner, includeDebug);
115+
var extractedProtections = HandleExtractableProtections(file, lex, subProtections.Keys, getProtections, includeDebug);
113116
protections.Append(extractedProtections);
114117
}
115118
else if (wrapper is NewExecutable nex)
@@ -119,7 +122,7 @@ public ProtectionDictionary DetectDict(Stream stream, string file, Scanner? scan
119122
protections.Append(file, subProtections.Values);
120123

121124
// Extractable checks
122-
var extractedProtections = HandleExtractableProtections(file, nex, subProtections.Keys, scanner, includeDebug);
125+
var extractedProtections = HandleExtractableProtections(file, nex, subProtections.Keys, getProtections, includeDebug);
123126
protections.Append(extractedProtections);
124127
}
125128
else if (wrapper is PortableExecutable pex)
@@ -129,7 +132,7 @@ public ProtectionDictionary DetectDict(Stream stream, string file, Scanner? scan
129132
protections.Append(file, subProtections.Values);
130133

131134
// Extractable checks
132-
var extractedProtections = HandleExtractableProtections(file, pex, subProtections.Keys, scanner, includeDebug);
135+
var extractedProtections = HandleExtractableProtections(file, pex, subProtections.Keys, getProtections, includeDebug);
133136
protections.Append(extractedProtections);
134137
}
135138

@@ -236,13 +239,13 @@ public IDictionary<U, string> RunExecutableChecks<T, U>(string file, T exe, List
236239
/// <param name="file">Name of the source file of the stream, for tracking</param>
237240
/// <param name="exe">Executable to scan the contents of</param>
238241
/// <param name="checks">Set of classes returned from Exectuable scans</param>
239-
/// <param name="scanner">Scanner for handling recursive protections</param>
242+
/// <param name="getProtections">Optional function for handling recursive protections</param>
240243
/// <param name="includeDebug">True to include debug data, false otherwise</param>
241244
/// <returns>Set of protections found from extraction, empty on error</returns>
242245
private static ProtectionDictionary HandleExtractableProtections<T, U>(string file,
243246
T exe,
244247
IEnumerable<U> checks,
245-
Scanner? scanner,
248+
Func<string, ProtectionDictionary>? getProtections,
246249
bool includeDebug)
247250
where T : WrapperBase
248251
where U : IExecutableCheck<T>
@@ -260,7 +263,7 @@ private static ProtectionDictionary HandleExtractableProtections<T, U>(string fi
260263
.Select(c => c as IExtractableExecutable<T>);
261264
extractables.IterateWithAction(extractable =>
262265
{
263-
var subProtections = PerformExtractableCheck(extractable!, file, exe, scanner, includeDebug);
266+
var subProtections = PerformExtractableCheck(extractable!, file, exe, getProtections, includeDebug);
264267
protections.Append(subProtections);
265268
});
266269

@@ -273,13 +276,13 @@ private static ProtectionDictionary HandleExtractableProtections<T, U>(string fi
273276
/// <param name="file">Name of the source file of the stream, for tracking</param>
274277
/// <param name="exe">Executable to scan the contents of</param>
275278
/// <param name="impl">IExtractableExecutable class representing the file type</param>
276-
/// <param name="scanner">Scanner for handling recursive protections</param>
279+
/// <param name="getProtections">Optional function for handling recursive protections</param>
277280
/// <param name="includeDebug">True to include debug data, false otherwise</param>
278281
/// <returns>Set of protections in path, empty on error</returns>
279282
private static ProtectionDictionary PerformExtractableCheck<T>(IExtractableExecutable<T> impl,
280283
string file,
281284
T exe,
282-
Scanner? scanner,
285+
Func<string, ProtectionDictionary>? getProtections,
283286
bool includeDebug)
284287
where T : WrapperBase
285288
{
@@ -296,8 +299,8 @@ private static ProtectionDictionary PerformExtractableCheck<T>(IExtractableExecu
296299

297300
// Collect and format all found protections
298301
ProtectionDictionary? subProtections = null;
299-
if (extracted)
300-
subProtections = scanner?.GetProtections(tempPath);
302+
if (extracted && getProtections != null)
303+
subProtections = getProtections(tempPath);
301304

302305
// If temp directory cleanup fails
303306
try

BinaryObjectScanner/Scanner.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,7 +273,7 @@ private ProtectionDictionary GetInternalProtections(string fileName, Stream stre
273273
executable.IncludeGameEngines = _options.ScanGameEngines;
274274
executable.IncludePackers = _options.ScanPackers;
275275

276-
var subProtections = executable.DetectDict(stream, fileName, this, _options.IncludeDebug);
276+
var subProtections = executable.DetectDict(stream, fileName, GetProtections, _options.IncludeDebug);
277277
protections.Append(subProtections);
278278
}
279279

0 commit comments

Comments
 (0)