2024-10-31 22:15:30 -04:00
using System.Collections.Generic ;
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 ;
2019-09-27 23:52:24 -07:00
2023-03-09 23:19:27 -05:00
namespace BinaryObjectScanner.Protection
2019-09-27 23:52:24 -07:00
{
2022-12-02 15:06:31 -08:00
/// <summary>
/// ByteShield, Inc. (https://web.archive.org/web/20070216191623/http://www.byteshield.net/) was founded in 2004 (https://www.apollo.io/companies/ByteShield--Inc-/54a1357069702d4494ab9b00).
/// There is a website seemingly belonging to them that's been archived as early as 2004, but there doesn't appear to be anything useful on it (https://web.archive.org/web/20040615001350/http://byteshield.com/).
/// The ByteShield DRM itself is online activation based, using randomly generated activation codes it refers to as DACs (https://web.archive.org/web/20080921231346/http://www.byteshield.net/byteshield_whitepaper_0005.pdf).
/// It appears that ByteShield advertised itself around online web forums (https://gamedev.net/forums/topic/508082-net-copy-protection-c/508082/ and https://cboard.cprogramming.com/tech-board/106642-how-add-copy-protection-software.html).
/// Patent relating to ByteShield: https://patentimages.storage.googleapis.com/ed/76/c7/d98a56aeeca2e9/US7716474.pdf and https://patents.google.com/patent/US20100212028.
///
/// Games known to use it:
2022-12-19 23:53:52 -08:00
/// Line Rider 2: Unbound (https://fileforums.com/showthread.php?t=86909).
2022-12-02 15:06:31 -08:00
/// Football Manager 2011 (https://community.sigames.com/forums/topic/189163-for-those-of-you-struggling-with-byteshield-activation-issues/).
///
/// Publishers known to use it:
/// PAN Vision (http://web.archive.org/web/20120413160122/http://www.byteshield.net/ -> Company -> Milestones).
/// JIAN (http://web.archive.org/web/20120413160122/http://www.byteshield.net/ -> Company -> Milestones).
/// GamersGate (http://web.archive.org/web/20120413160122/http://www.byteshield.net/ -> Company -> Milestones).
/// Akella (http://web.archive.org/web/20120413160122/http://www.byteshield.net/ -> Customers).
/// All Interactive Distributuion (http://web.archive.org/web/20120413160122/http://www.byteshield.net/ -> Customers).
/// Beowulf (http://web.archive.org/web/20120413160122/http://www.byteshield.net/ -> Customers).
/// CroVortex (http://web.archive.org/web/20120413160122/http://www.byteshield.net/ -> Customers).
/// N3V Games (http://web.archive.org/web/20120413160122/http://www.byteshield.net/ -> Customers).
/// OnePlayS (http://web.archive.org/web/20120413160122/http://www.byteshield.net/ -> Customers).
/// YAWMA (http://web.archive.org/web/20120413160122/http://www.byteshield.net/ -> Customers).
///
/// Further links and resources:
/// https://www.cdmediaworld.com/hardware/cdrom/cd_protections_byteshield.shtml
/// https://www.bcs.org/articles-opinion-and-research/is-there-anything-like-acceptable-drm/
/// https://forums.auran.com/trainz/showthread.php?106673-Trainz-and-DRM/page22
/// https://www.auran.com/planetauran/byteshield_drm.php
/// https://www.ftc.gov/sites/default/files/documents/public_comments/ftc-town-hall-address-digital-rights-management-technologies-event-takes-place-wednesday-march-25/539814-00707.pdf
/// https://www.gamesindustry.biz/byteshield-drm-system-now-protecting-over-200-games
/// </summary>
2024-11-04 23:21:12 -05:00
public class ByteShield : IExecutableCheck < PortableExecutable > , IPathCheck
2019-09-27 23:52:24 -07:00
{
2022-12-19 23:49:34 -08:00
/// <inheritdoc/>
2024-11-04 23:21:12 -05:00
public string? CheckExecutable ( string file , PortableExecutable pex , bool includeDebug )
2022-12-19 23:49:34 -08:00
{
// Found in "LineRider2.exe" in Redump entry 6236
2023-09-17 22:37:01 -04:00
var name = pex . FileDescription ;
2024-12-02 00:35:04 -05:00
if ( name . OptionalEquals ( "ByteShield Client" ) )
2023-03-09 23:19:27 -05:00
return $"ByteShield Activation Client {pex.GetInternalVersion()}" ;
2022-12-19 23:49:34 -08:00
// Found in "LineRider2.exe" in Redump entry 6236
name = pex . InternalName ;
2024-12-02 00:35:04 -05:00
if ( name . OptionalEquals ( "ByteShield" ) )
2023-03-09 23:19:27 -05:00
return $"ByteShield Activation Client {pex.GetInternalVersion()}" ;
2022-12-19 23:49:34 -08:00
// Found in "LineRider2.exe" in Redump entry 6236
name = pex . OriginalFilename ;
2024-12-02 00:35:04 -05:00
if ( name . OptionalEquals ( "ByteShield.EXE" ) )
2023-03-09 23:19:27 -05:00
return $"ByteShield Activation Client {pex.GetInternalVersion()}" ;
2022-12-19 23:49:34 -08:00
// Found in "LineRider2.exe" in Redump entry 6236
name = pex . ProductName ;
2024-12-02 00:35:04 -05:00
if ( name . OptionalEquals ( "ByteShield Client" ) )
2023-03-09 23:19:27 -05:00
return $"ByteShield Activation Client {pex.GetInternalVersion()}" ;
2022-12-19 23:49:34 -08:00
// Found in "ByteShield.dll" in Redump entry 6236
2023-09-15 22:21:05 -04:00
name = pex . Model . ExportTable ? . ExportDirectoryTable ? . Name ;
2024-12-02 00:35:04 -05:00
if ( name . OptionalEquals ( "ByteShield Client" ) )
2022-12-19 23:49:34 -08:00
return "ByteShield Component Module" ;
// Found in "LineRider2.exe" in Redump entry 6236
2024-11-20 20:58:39 -05:00
if ( pex . FindStringTableByEntry ( "ByteShield" ) . Count > 0 )
2023-03-09 23:19:27 -05:00
return $"ByteShield Activation Client {pex.GetInternalVersion()}" ;
2022-12-19 23:49:34 -08:00
// Found in "LineRider2.exe" in Redump entry 6236
2024-11-20 20:58:39 -05:00
if ( pex . FindDialogByTitle ( "About ByteShield" ) . Count > 0 )
2022-12-19 23:49:34 -08:00
return "ByteShield" ;
// TODO: See if the version number is anywhere else
// TODO: Parse the version number out of the dialog box item
// Found in "LineRider2.exe" in Redump entry 6236
2024-11-20 20:58:39 -05:00
if ( pex . FindDialogBoxByItemTitle ( "ByteShield Version 1.0" ) . Count > 0 )
2022-12-19 23:49:34 -08:00
return "ByteShield" ;
2022-12-20 11:52:50 -08:00
// Get the .data/DATA section strings, if they exist
2023-09-17 22:37:01 -04:00
var strs = pex . GetFirstSectionStrings ( ".data" ) ? ? pex . GetFirstSectionStrings ( "DATA" ) ;
2022-12-20 12:21:34 -08:00
if ( strs ! = null )
2022-12-19 23:49:34 -08:00
{
// Found in "LineRider2.exe" in Redump entry 6236
2024-12-02 00:35:04 -05:00
if ( strs . Exists ( s = > s . OptionalContains ( "ByteShield" ) ) )
2022-12-19 23:49:34 -08:00
return "ByteShield" ;
}
2022-12-20 11:52:50 -08:00
// Get the .rdata section strings, if they exist
strs = pex . GetFirstSectionStrings ( ".rdata" ) ;
2022-12-20 12:21:34 -08:00
if ( strs ! = null )
2022-12-19 23:49:34 -08:00
{
// Found in "ByteShield.dll" in Redump entry 6236
2024-12-02 00:35:04 -05:00
if ( strs . Exists ( s = > s . OptionalContains ( "Byte|Shield" ) ) )
2022-12-19 23:49:34 -08:00
return "ByteShield Component Module" ;
// Found in "ByteShield.dll" in Redump entry 6236
2024-12-02 00:35:04 -05:00
else if ( strs . Exists ( s = > s . OptionalContains ( "Byteshield0" ) ) )
2022-12-19 23:49:34 -08:00
return "ByteShield Component Module" ;
// Found in "ByteShield.dll" in Redump entry 6236
2024-12-02 00:35:04 -05:00
else if ( strs . Exists ( s = > s . OptionalContains ( "ByteShieldLoader" ) ) )
2022-12-19 23:49:34 -08:00
return "ByteShield Component Module" ;
}
2022-12-20 11:52:50 -08:00
// Get the .ret section strings, if they exist
strs = pex . GetFirstSectionStrings ( ".ret" ) ;
2022-12-20 12:21:34 -08:00
if ( strs ! = null )
2022-12-19 23:49:34 -08:00
{
2022-12-19 23:53:52 -08:00
// TODO: Figure out if this specifically indicates if the file is encrypted
2022-12-19 23:49:34 -08:00
// Found in "LineRider2.bbz" in Redump entry 6236
2024-12-02 00:35:04 -05:00
if ( strs . Exists ( s = > s . OptionalContains ( "ByteShield" ) ) )
2022-12-19 23:53:52 -08:00
return "ByteShield" ;
2022-12-19 23:49:34 -08:00
}
return null ;
}
2023-09-17 22:37:01 -04:00
2021-02-26 00:32:09 -08:00
/// <inheritdoc/>
2024-11-20 17:10:03 -05:00
public List < string > CheckDirectoryPath ( string path , List < string > ? files )
2019-09-27 23:52:24 -07:00
{
2022-12-19 23:53:52 -08:00
// TODO: Investigate reference to "bbz650.tmp" in "Byteshield.dll" (Redump entry 6236)
// Files with the ".bbz" extension are associated with ByteShield, but the extenstion is known to be used in other places as well.
2021-03-22 22:23:55 -07:00
var matchers = new List < PathMatchSet >
2019-09-27 23:52:24 -07:00
{
2023-11-22 13:28:13 -05:00
new ( new FilePathMatch ( "Byteshield.dll" ) , "ByteShield Component Module" ) ,
new ( new FilePathMatch ( "Byteshield.ini" ) , "ByteShield" ) ,
2021-03-22 22:23:55 -07:00
} ;
2021-03-19 15:41:49 -07:00
2023-11-14 16:10:10 -05:00
return MatchUtil . GetAllMatches ( files , matchers , any : true ) ;
2021-03-19 15:41:49 -07:00
}
/// <inheritdoc/>
2023-09-17 22:37:01 -04:00
public string? CheckFilePath ( string path )
2021-03-19 15:41:49 -07:00
{
2022-12-19 23:53:52 -08:00
// TODO: Investigate reference to "bbz650.tmp" in "Byteshield.dll" (Redump entry 6236)
// Files with the ".bbz" extension are associated with ByteShield, but the extenstion is known to be used in other places as well.
2021-03-22 22:23:55 -07:00
var matchers = new List < PathMatchSet >
2019-09-27 23:52:24 -07:00
{
2023-11-22 13:28:13 -05:00
new ( new FilePathMatch ( "Byteshield.dll" ) , "ByteShield Component Module" ) ,
new ( new FilePathMatch ( "Byteshield.ini" ) , "ByteShield" ) ,
2021-03-22 22:23:55 -07:00
} ;
return MatchUtil . GetFirstMatch ( path , matchers , any : true ) ;
2019-09-27 23:52:24 -07:00
}
}
}