2019-09-27 23:52:24 -07:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Collections.Generic;
|
|
|
|
|
|
using System.IO;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
|
|
|
|
|
|
namespace BurnOutSharp.ProtectionType
|
|
|
|
|
|
{
|
|
|
|
|
|
public class CDCops
|
|
|
|
|
|
{
|
2020-09-10 21:43:18 -07:00
|
|
|
|
public static string CheckContents(byte[] fileContent, bool includePosition = false)
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2020-09-10 21:10:32 -07:00
|
|
|
|
// "CD-Cops, ver. "
|
|
|
|
|
|
byte[] check = new byte[] { 0x43, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73, 0x2C, 0x20, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20 };
|
|
|
|
|
|
if (fileContent.Contains(check, out int position))
|
2020-09-10 21:43:18 -07:00
|
|
|
|
return $"CD-Cops {GetVersion(fileContent, position)}" + (includePosition ? $" (Index {position})" : string.Empty);
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
2020-09-10 21:10:32 -07:00
|
|
|
|
// ".grand" + (char)0x00
|
|
|
|
|
|
check = new byte[] { 0x2E, 0x67, 0x72, 0x61, 0x6E, 0x64, 0x00};
|
|
|
|
|
|
if (fileContent.Contains(check, out position))
|
2020-09-10 21:43:18 -07:00
|
|
|
|
return "CD-Cops" + (includePosition ? $" (Index {position})" : string.Empty);
|
2019-09-27 23:52:24 -07:00
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public static string CheckPath(string path, IEnumerable<string> files, bool isDirectory)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (isDirectory)
|
|
|
|
|
|
{
|
2020-02-20 14:23:39 -08:00
|
|
|
|
if (files.Any(f => Path.GetFileName(f).Equals("CDCOPS.DLL", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
&& (files.Any(f => Path.GetExtension(f).Trim('.').Equals("GZ_", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
|| files.Any(f => Path.GetExtension(f).Trim('.').Equals("W_X", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
|| files.Any(f => Path.GetExtension(f).Trim('.').Equals("Qz", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
|| files.Any(f => Path.GetExtension(f).Trim('.').Equals("QZ_", StringComparison.OrdinalIgnoreCase))))
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
|
|
|
|
|
return "CD-Cops";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
if (Path.GetFileName(path).Equals("CDCOPS.DLL", StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
|
|| Path.GetExtension(path).Trim('.').Equals("GZ_", StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
|
|| Path.GetExtension(path).Trim('.').Equals("W_X", StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
|
|| Path.GetExtension(path).Trim('.').Equals("Qz", StringComparison.OrdinalIgnoreCase)
|
|
|
|
|
|
|| Path.GetExtension(path).Trim('.').Equals("QZ_", StringComparison.OrdinalIgnoreCase))
|
|
|
|
|
|
{
|
|
|
|
|
|
return "CD-Cops";
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-10 21:10:32 -07:00
|
|
|
|
private static string GetVersion(byte[] fileContent, int position)
|
2019-09-27 23:52:24 -07:00
|
|
|
|
{
|
2020-09-10 21:10:32 -07:00
|
|
|
|
char[] version = new ArraySegment<byte>(fileContent, position + 15, 4).Select(b => (char)b).ToArray();
|
|
|
|
|
|
if (version[0] == 0x00)
|
|
|
|
|
|
return "";
|
2019-09-30 11:08:44 -07:00
|
|
|
|
|
2020-09-10 21:10:32 -07:00
|
|
|
|
return new string(version);
|
2019-09-27 23:52:24 -07:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|