Skip to content

Commit 75517a5

Browse files
Add PACE Anti-Piracy InterLok detection (#362)
* Add detection class and test class for PACE Anti-Piracy Interlok * Remove unnecessary empty lines after end of class. * Added missing null check for pex section strings. * Add newline above getversion * GetFirstSectionStrings assigned to variable. * Change getversion in InterLok to use regex. * Final? getversion regex cleanup
1 parent cfe9825 commit 75517a5

File tree

2 files changed

+58
-0
lines changed

2 files changed

+58
-0
lines changed
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
using System.IO;
2+
using BinaryObjectScanner.Protection;
3+
using Xunit;
4+
5+
namespace BinaryObjectScanner.Test.Protection
6+
{
7+
public class InterLokTests
8+
{
9+
[Fact]
10+
public void CheckPortableExecutableTest()
11+
{
12+
string file = "filename";
13+
SabreTools.Models.PortableExecutable.Executable model = new();
14+
Stream source = new MemoryStream();
15+
SabreTools.Serialization.Wrappers.PortableExecutable pex = new(model, source);
16+
17+
var checker = new InterLok();
18+
string? actual = checker.CheckExecutable(file, pex, includeDebug: false);
19+
Assert.Null(actual);
20+
}
21+
}
22+
}
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
using System.Text.RegularExpressions;
2+
using BinaryObjectScanner.Interfaces;
3+
using SabreTools.Serialization.Wrappers;
4+
5+
namespace BinaryObjectScanner.Protection
6+
{
7+
public class InterLok : IExecutableCheck<PortableExecutable>
8+
{
9+
/// <inheritdoc/>
10+
public string? CheckExecutable(string file, PortableExecutable pex, bool includeDebug)
11+
{
12+
// Get the .rsrc section strings, if they exist
13+
var strs = pex.GetFirstSectionStrings(".rsrc");
14+
if (strs != null)
15+
{
16+
// Found in "nfsc_link.exe" in IA item "nfscorigin".
17+
// Full string:
18+
// (: ) InterLok PC v2.0, PACE Anti-Piracy, Copyright (C) 1998, ALL RIGHTS RESERVED
19+
var match = strs.Find(s => s.Contains("InterLok") && s.Contains("PACE Anti-Piracy"));
20+
if (match != null)
21+
return $"PACE Anti-Piracy InterLok {GetVersion(match)}";
22+
}
23+
24+
return null;
25+
}
26+
27+
private static string GetVersion(string match)
28+
{
29+
var versionMatch = Regex.Match(match, @"(?<=InterLok )(.*?)(?=,)");
30+
if (versionMatch.Success)
31+
return versionMatch.Value;
32+
33+
return "(Unknown Version - Please report to us on GitHub)";
34+
}
35+
}
36+
}

0 commit comments

Comments
 (0)