2022-12-02 14:56:08 -08:00
using System ;
using System.Collections.Generic ;
2022-12-09 13:55:28 -08:00
using System.Linq ;
2023-03-09 11:52:28 -05:00
using BinaryObjectScanner.Interfaces ;
2023-09-16 22:08:18 -04:00
using SabreTools.Matching ;
2024-10-03 12:01:08 -04:00
using SabreTools.Matching.Paths ;
2023-09-16 02:04:47 -04:00
using SabreTools.Serialization.Wrappers ;
2022-12-02 14:56:08 -08:00
2023-03-09 23:19:27 -05:00
namespace BinaryObjectScanner.Protection
2022-12-02 14:56:08 -08:00
{
/// <summary>
/// Code-Lock by ChosenBytes (https://web.archive.org/web/20040225072021/http://chosenbytes.com/) is a form of DRM that protects Visual Basic and .NET programs.
/// It requires the use of a registration code that is unique to each individual user (https://web.archive.org/web/20031210093259/http://www.chosenbytes.com/codemain.php).
/// As an advertising point, ChosenBytes apparently held a contest with a cash prize to see if a protected file could be cracked (https://web.archive.org/web/20031106163334/http://www.chosenbytes.com/challenge.php).
///
2023-11-08 11:37:27 -05:00
/// Previous versions of BinaryObjectScanner incorrectly reported this DRM as "CodeLock / CodeLok / CopyLok". It was later discovered that due to the similar names, two entirely different DRM were erroneously lumped together.
2022-12-02 14:56:08 -08:00
/// Not only is "CodeLok / CopyLok" an entirely separate form of DRM, but "CodeLock" (as opposed to "Code-Lock") appears to refer specifically to another unrelated DRM (https://web.archive.org/web/20031106033758/http://www.codelock.co.nz/).
/// Also not to be confused with https://www.youtube.com/watch?v=AHqdgk0uJyc.
///
/// Code-Lock FAQ: https://web.archive.org/web/20041205165232/http://www.chosenbytes.com/codefaq.php
/// Download (Version 2.35 trial): https://web.archive.org/web/20060220121200/http://www.chosenbytes.com:80/Code-Lock_cnet.zip
/// </summary>
2022-12-09 13:55:28 -08:00
public class ChosenBytesCodeLock : IPathCheck , IPortableExecutableCheck
2022-12-02 14:56:08 -08:00
{
/// <inheritdoc/>
2023-09-17 22:37:01 -04:00
public string? CheckPortableExecutable ( string file , PortableExecutable pex , bool includeDebug )
2022-12-02 14:56:08 -08:00
{
// Get the sections from the executable, if possible
2023-09-17 22:37:01 -04:00
var sections = pex . Model . SectionTable ;
2022-12-02 14:56:08 -08:00
if ( sections = = null )
return null ;
// Found in "Code-Lock.ocx" in Code-Lock version 2.35.
// Also worth noting is the File Description for this file, which is "A future for you, a challenge for the rest.".
2023-09-17 22:37:01 -04:00
var name = pex . ProductName ;
2022-12-02 14:56:08 -08:00
if ( name ? . StartsWith ( "Code-Lock" , StringComparison . OrdinalIgnoreCase ) = = true )
return $"ChosenBytes Code-Lock {pex.ProductVersion}" ;
2022-12-09 13:55:28 -08:00
// Get the .text section strings, if they exist
2023-09-17 22:37:01 -04:00
var strs = pex . GetFirstSectionStrings ( ".text" ) ;
2022-12-09 13:55:28 -08:00
if ( strs ! = null )
2022-12-02 14:56:08 -08:00
{
2022-12-09 13:55:28 -08:00
if ( strs . Any ( s = > s . Contains ( "CODE-LOCK.OCX" ) ) )
return "ChosenBytes Code-Lock" ;
if ( strs . Any ( s = > s . Contains ( "Code-Lock.ocx" ) ) )
return "ChosenBytes Code-Lock" ;
2022-12-02 14:56:08 -08:00
2022-12-09 13:55:28 -08:00
if ( strs . Any ( s = > s . Contains ( "CodeLock.Secure" ) ) )
return "ChosenBytes Code-Lock" ;
2022-12-02 14:56:08 -08:00
}
return null ;
}
/// <inheritdoc/>
2024-10-31 22:15:30 -04:00
public IEnumerable < string > CheckDirectoryPath ( string path , IEnumerable < string > ? files )
2022-12-02 14:56:08 -08:00
{
var matchers = new List < PathMatchSet >
{
// Found in the installation directory of Code-Lock version 2.35.
2023-11-22 13:28:13 -05:00
new ( new FilePathMatch ( "Code-Lock.chm" ) , "ChosenBytes Code-Lock" ) ,
new ( new FilePathMatch ( "Code-Lock.DEP" ) , "ChosenBytes Code-Lock" ) ,
new ( new FilePathMatch ( "Code-Lock.ocx" ) , "ChosenBytes Code-Lock" ) ,
new ( new FilePathMatch ( "Code-Lock Wizard.exe" ) , "ChosenBytes Code-Lock" ) ,
2022-12-02 14:56:08 -08:00
} ;
2023-11-14 16:10:10 -05:00
return MatchUtil . GetAllMatches ( files , matchers , any : true ) ;
2022-12-02 14:56:08 -08:00
}
/// <inheritdoc/>
2023-09-17 22:37:01 -04:00
public string? CheckFilePath ( string path )
2022-12-02 14:56:08 -08:00
{
var matchers = new List < PathMatchSet >
{
// Found in the installation directory of Code-Lock version 2.35.
2023-11-22 13:28:13 -05:00
new ( new FilePathMatch ( "Code-Lock.chm" ) , "ChosenBytes Code-Lock" ) ,
new ( new FilePathMatch ( "Code-Lock.DEP" ) , "ChosenBytes Code-Lock" ) ,
new ( new FilePathMatch ( "Code-Lock.ocx" ) , "ChosenBytes Code-Lock" ) ,
new ( new FilePathMatch ( "Code-Lock Wizard.exe" ) , "ChosenBytes Code-Lock" ) ,
2022-12-02 14:56:08 -08:00
} ;
return MatchUtil . GetFirstMatch ( path , matchers , any : true ) ;
}
}
}