diff --git a/BurnOutSharp.sln b/BurnOutSharp.sln
index c82b3e74..a746e821 100644
--- a/BurnOutSharp.sln
+++ b/BurnOutSharp.sln
@@ -3,12 +3,13 @@ Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio Version 16
VisualStudioVersion = 16.0.29306.81
MinimumVisualStudioVersion = 10.0.40219.1
-Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "BurnOutSharp", "BurnOutSharp\BurnOutSharp.csproj", "{1DA4212E-6071-4951-B45D-BB74A7838246}"
+Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "BurnOutSharp", "BurnOutSharp\BurnOutSharp.csproj", "{1DA4212E-6071-4951-B45D-BB74A7838246}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Test", "Test\Test.csproj", "{88735BA2-778D-4192-8EB2-FFF6843719E2}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{68D10531-99CB-40B1-8912-73FA286C9433}"
ProjectSection(SolutionItems) = preProject
+ LICENSE = LICENSE
README.md = README.md
EndProjectSection
EndProject
diff --git a/BurnOutSharp/BurnOutSharp.csproj b/BurnOutSharp/BurnOutSharp.csproj
index ebcbb478..afd1cb05 100644
--- a/BurnOutSharp/BurnOutSharp.csproj
+++ b/BurnOutSharp/BurnOutSharp.csproj
@@ -1,27 +1,40 @@
- net462;net472;netcoreapp3.0
+ net462;net472;net48;netcoreapp3.0
false
+
+ true
+
+
-
- 0.6.16
-
-
- 0.9.10
-
-
- 1.4.2.3
-
-
- 1.0.4
-
+
+
+
+
+
+
+
+
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
+
+ Always
+
diff --git a/BurnOutSharp/BurnOutSharp.nuspec b/BurnOutSharp/BurnOutSharp.nuspec
index 4c01cc2f..db2fc01d 100644
--- a/BurnOutSharp/BurnOutSharp.nuspec
+++ b/BurnOutSharp/BurnOutSharp.nuspec
@@ -1,5 +1,5 @@
-
+
BurnOutSharp
1.03.9.1
@@ -16,6 +16,7 @@
+
diff --git a/BurnOutSharp/EVORE.cs b/BurnOutSharp/EVORE.cs
index 48e63462..601e493d 100644
--- a/BurnOutSharp/EVORE.cs
+++ b/BurnOutSharp/EVORE.cs
@@ -57,120 +57,115 @@ namespace BurnOutSharp
return startingprocess;
}
- private static string MakeTempFile(string file, string sExtension = ".exe")
+ private static string MakeTempFile(byte[] fileContent, string sExtension = ".exe")
{
- if (file == null || !File.Exists(file))
- return string.Empty;
-
- FileInfo filei = new FileInfo(file);
+ string filei = Guid.NewGuid().ToString();
+ string tempPath = Path.Combine(Path.GetTempPath(), "tmp", $"{filei}{sExtension}");
try
{
- File.Delete(Path.Combine(Path.GetTempPath(), "tmp", filei.Name + "*" + sExtension));
+ File.Delete(tempPath);
}
catch { }
- filei = filei.CopyTo(Path.GetTempPath() + "tmp" + filei.Name + Directory.GetFiles(Path.GetTempPath(), "tmp" + filei.Name + "*" + sExtension).Length + sExtension, true);
- filei.Attributes = FileAttributes.Temporary | FileAttributes.NotContentIndexed;
- return filei.FullName;
+
+ Directory.CreateDirectory(Path.GetDirectoryName(tempPath));
+ using (BinaryWriter bw = new BinaryWriter(File.OpenWrite(tempPath)))
+ {
+ bw.Write(fileContent);
+ }
+
+ return Path.GetFullPath(tempPath);
}
- private static bool IsEXE(string file)
+ private static bool IsEXE(byte[] fileContent)
{
- if (file == null || !File.Exists(file))
- return false;
+ int PEHeaderOffset = BitConverter.ToInt32(fileContent, 60);
+ short Characteristics = BitConverter.ToInt16(fileContent, PEHeaderOffset + 22);
- BinaryReader breader = new BinaryReader(File.OpenRead(file));
- breader.ReadBytes(60);
- int PEHeaderOffset = breader.ReadInt32();
- breader.BaseStream.Seek(PEHeaderOffset, SeekOrigin.Begin);
- breader.ReadBytes(22);
- short Characteristics = breader.ReadInt16();
- breader.Close();
- //check if file is dll
+ // Check if file is dll
if ((Characteristics & 0x2000) == 0x2000)
return false;
else
return true;
}
- private static string[] CopyDependentDlls(string exefile)
+ private static string[] CopyDependentDlls(string file, byte[] fileContent)
{
- if (exefile == null)
- return null;
+ Section[] sections = ReadSections(fileContent);
- FileInfo fiExe = new FileInfo(exefile);
- Section[] sections = ReadSections(exefile);
- BinaryReader breader = new BinaryReader(File.OpenRead(exefile), Encoding.Default);
long lastPosition;
string[] saDependentDLLs = null;
- breader.ReadBytes(60);
- int PEHeaderOffset = breader.ReadInt32();
- breader.BaseStream.Seek(PEHeaderOffset + 120 + 8, SeekOrigin.Begin); //120 Bytes till IMAGE_DATA_DIRECTORY array,8 Bytes=size of IMAGE_DATA_DIRECTORY
- uint ImportTableRVA = breader.ReadUInt32();
- uint ImportTableSize = breader.ReadUInt32();
- breader.BaseStream.Seek(RVA2Offset(ImportTableRVA, sections), SeekOrigin.Begin);
- breader.BaseStream.Seek(12, SeekOrigin.Current);
- uint DllNameRVA = breader.ReadUInt32();
+ int index = 60;
+ int PEHeaderOffset = BitConverter.ToInt32(fileContent, index);
+ index = PEHeaderOffset + 120 + 8; //120 Bytes till IMAGE_DATA_DIRECTORY array,8 Bytes=size of IMAGE_DATA_DIRECTORY
+ uint ImportTableRVA = BitConverter.ToUInt32(fileContent, index);
+ index += 4;
+ uint ImportTableSize = BitConverter.ToUInt32(fileContent, index);
+ index = (int)RVA2Offset(ImportTableRVA, sections);
+ index += 12;
+ uint DllNameRVA = BitConverter.ToUInt32(fileContent, index);
+ index += 4;
while (DllNameRVA != 0)
{
string sDllName = "";
byte bChar;
- lastPosition = breader.BaseStream.Position;
+ lastPosition = index;
uint DLLNameOffset = RVA2Offset(DllNameRVA, sections);
if (DLLNameOffset > 0)
{
- breader.BaseStream.Seek(DLLNameOffset, SeekOrigin.Begin);
- if (breader.PeekChar() > -1)
+ index = (int)DLLNameOffset;
+ if ((char)fileContent[index] > -1)
{
do
{
- bChar = breader.ReadByte();
+ bChar = fileContent[index];
+ index++;
sDllName += (char)bChar;
- } while (bChar != 0 && breader.PeekChar() > -1);
+ } while (bChar != 0 && (char)fileContent[index] > -1);
sDllName = sDllName.Remove(sDllName.Length - 1, 1);
- if (File.Exists(Path.Combine(fiExe.DirectoryName, sDllName)))
+ if (File.Exists(Path.Combine(Path.GetDirectoryName(file), sDllName)))
{
if (saDependentDLLs == null)
saDependentDLLs = new string[0];
else
saDependentDLLs = new string[saDependentDLLs.Length];
- FileInfo fiDLL = new FileInfo(Path.Combine(fiExe.DirectoryName, sDllName));
+ FileInfo fiDLL = new FileInfo(Path.Combine(Path.GetDirectoryName(file), sDllName));
saDependentDLLs[saDependentDLLs.Length - 1] = fiDLL.CopyTo(Path.GetTempPath() + sDllName, true).FullName;
}
}
- breader.BaseStream.Seek(lastPosition, SeekOrigin.Begin);
+ index = (int)lastPosition;
}
- breader.BaseStream.Seek(4 + 12, SeekOrigin.Current);
- DllNameRVA = breader.ReadUInt32();
+ index += 4 + 12;
+ DllNameRVA = BitConverter.ToUInt32(fileContent, index);
+ index += 4;
}
- breader.Close();
return saDependentDLLs;
}
- private static Section[] ReadSections(string exefile)
+ private static Section[] ReadSections(byte[] fileContent)
{
- if (exefile == null)
+ if (fileContent == null)
return null;
- BinaryReader breader = new BinaryReader(File.OpenRead(exefile));
- breader.ReadBytes(60);
- uint PEHeaderOffset = breader.ReadUInt32();
- breader.BaseStream.Seek(PEHeaderOffset + 6, SeekOrigin.Begin);
- ushort NumberOfSections = breader.ReadUInt16();
- breader.BaseStream.Seek(PEHeaderOffset + 120 + 16 * 8, SeekOrigin.Begin);
+ uint PEHeaderOffset = BitConverter.ToUInt32(fileContent, 60);
+ ushort NumberOfSections = BitConverter.ToUInt16(fileContent, (int)PEHeaderOffset + 6);
Section[] sections = new Section[NumberOfSections];
+ int index = (int)PEHeaderOffset + 120 + 16 * 8;
for (int i = 0; i < NumberOfSections; i++)
{
- breader.BaseStream.Seek(8, SeekOrigin.Current);
- uint ivs = breader.ReadUInt32();
- uint ivo = breader.ReadUInt32();
- breader.BaseStream.Seek(4, SeekOrigin.Current);
- uint iro = breader.ReadUInt32();
- breader.BaseStream.Seek(16, SeekOrigin.Current);
+ index += 8;
+ uint ivs = BitConverter.ToUInt32(fileContent, index);
+ index += 4;
+ uint ivo = BitConverter.ToUInt32(fileContent, index);
+ index += 4;
+ index += 4;
+ uint iro = BitConverter.ToUInt32(fileContent, index);
+ index += 4;
+ index += 16;
sections[i] = new Section()
{
@@ -179,7 +174,7 @@ namespace BurnOutSharp
iRawOffset = iro,
};
}
- breader.Close();
+
return sections;
}
@@ -197,19 +192,15 @@ namespace BurnOutSharp
#region "EVORE version-search-functions"
- public static string SearchProtectDiscVersion(string file)
+ public static string SearchProtectDiscVersion(string file, byte[] fileContent)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
-
- Process exe = new Process();
- Process[] processes = new Process[0];
string version = "";
DateTime timestart;
- if (!IsEXE(file))
+ if (!IsEXE(fileContent))
return "";
- string tempexe = MakeTempFile(file);
- string[] DependentDlls = CopyDependentDlls(file);
+
+ string tempexe = MakeTempFile(fileContent);
+ string[] DependentDlls = CopyDependentDlls(file, fileContent);
try
{
File.Delete(Path.Combine(Path.GetTempPath(), "a*.tmp"));
@@ -228,9 +219,12 @@ namespace BurnOutSharp
}
catch { }
}
- exe = StartSafe(tempexe);
+
+ Process exe = StartSafe(tempexe);
if (exe == null)
return "";
+
+ Process[] processes = new Process[0];
timestart = DateTime.Now;
do
{
@@ -242,6 +236,7 @@ namespace BurnOutSharp
{
files = Directory.GetFiles(Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData), "ProtectDisc"), "p*.dll");
}
+
if (files != null)
{
if (files.Length > 0)
@@ -326,11 +321,13 @@ namespace BurnOutSharp
}
catch { }
}
+
try
{
File.Delete(Path.Combine(Path.GetTempPath(), "a*.tmp"));
}
catch { }
+
try
{
File.Delete(Path.Combine(Path.GetTempPath(), "PCD*.sys"));
@@ -355,19 +352,16 @@ namespace BurnOutSharp
return version;
}
- public static string SearchSafeDiscVersion(string file)
+ public static string SearchSafeDiscVersion(string file, byte[] fileContent)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
-
Process exe = new Process();
string version = "";
DateTime timestart;
- if (!IsEXE(file))
+ if (!IsEXE(fileContent))
return "";
- string tempexe = MakeTempFile(file);
- string[] DependentDlls = CopyDependentDlls(file);
+ string tempexe = MakeTempFile(fileContent);
+ string[] DependentDlls = CopyDependentDlls(file, fileContent);
try
{
Directory.Delete(Path.Combine(Path.GetTempPath(), "~e*"), true);
@@ -419,9 +413,9 @@ namespace BurnOutSharp
try
{
File.Delete(Path.Combine(Path.GetTempPath(), "~e*"));
+ File.Delete(tempexe);
}
catch { }
- File.Delete(tempexe);
if (DependentDlls != null)
{
diff --git a/BurnOutSharp/External/HLLib/HLExtract.Net/HLLib.cs b/BurnOutSharp/External/HLLib/HLExtract.Net/HLLib.cs
new file mode 100644
index 00000000..c3315d05
--- /dev/null
+++ b/BurnOutSharp/External/HLLib/HLExtract.Net/HLLib.cs
@@ -0,0 +1,1663 @@
+/*
+ * HLExtract.Net
+ * Copyright (C) 2008-2012 Ryan Gregg
+
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+using System;
+using System.Runtime.InteropServices;
+
+public sealed class HLLib
+{
+ #region Constants
+ public const int HL_VERSION_NUMBER = ((2 << 24) | (4 << 16) | (6 << 8) | 0);
+ public const string HL_VERSION_STRING = "2.4.6";
+
+ public const uint HL_ID_INVALID = 0xffffffff;
+
+ public const uint HL_DEFAULT_PACKAGE_TEST_BUFFER_SIZE = 8;
+ public const uint HL_DEFAULT_VIEW_SIZE = 131072;
+ public const uint HL_DEFAULT_COPY_BUFFER_SIZE = 131072;
+ #endregion
+
+ #region Enumerations
+ public enum HLOption : uint
+ {
+ HL_VERSION = 0,
+ HL_ERROR,
+ HL_ERROR_SYSTEM,
+ HL_ERROR_SHORT_FORMATED,
+ HL_ERROR_LONG_FORMATED,
+ HL_PROC_OPEN,
+ HL_PROC_CLOSE,
+ HL_PROC_READ,
+ HL_PROC_WRITE,
+ HL_PROC_SEEK,
+ HL_PROC_TELL,
+ HL_PROC_SIZE,
+ HL_PROC_EXTRACT_ITEM_START,
+ HL_PROC_EXTRACT_ITEM_END,
+ HL_PROC_EXTRACT_FILE_PROGRESS,
+ HL_PROC_VALIDATE_FILE_PROGRESS,
+ HL_OVERWRITE_FILES,
+ HL_PACKAGE_BOUND,
+ HL_PACKAGE_ID,
+ HL_PACKAGE_SIZE,
+ HL_PACKAGE_TOTAL_ALLOCATIONS,
+ HL_PACKAGE_TOTAL_MEMORY_ALLOCATED,
+ HL_PACKAGE_TOTAL_MEMORY_USED,
+ HL_READ_ENCRYPTED,
+ HL_FORCE_DEFRAGMENT,
+ HL_PROC_DEFRAGMENT_PROGRESS,
+ HL_PROC_DEFRAGMENT_PROGRESS_EX,
+ HL_PROC_SEEK_EX,
+ HL_PROC_TELL_EX,
+ HL_PROC_SIZE_EX
+ }
+
+ public enum HLFileMode : uint
+ {
+ HL_MODE_INVALID = 0x00,
+ HL_MODE_READ = 0x01,
+ HL_MODE_WRITE = 0x02,
+ HL_MODE_CREATE = 0x04,
+ HL_MODE_VOLATILE = 0x08,
+ HL_MODE_NO_FILEMAPPING = 0x10,
+ HL_MODE_QUICK_FILEMAPPING = 0x20
+ }
+
+ public enum HLSeekMode : uint
+ {
+ HL_SEEK_BEGINNING = 0,
+ HL_SEEK_CURRENT,
+ HL_SEEK_END
+ }
+
+ public enum HLDirectoryItemType : uint
+ {
+ HL_ITEM_NONE = 0,
+ HL_ITEM_FOLDER,
+ HL_ITEM_FILE
+ }
+
+ public enum HLSortOrder : uint
+ {
+ HL_ORDER_ASCENDING = 0,
+ HL_ORDER_DESCENDING
+ }
+
+ public enum HLSortField : uint
+ {
+ HL_FIELD_NAME = 0,
+ HL_FIELD_SIZE
+ }
+
+ public enum HLFindType : uint
+ {
+ HL_FIND_FILES = 0x01,
+ HL_FIND_FOLDERS = 0x02,
+ HL_FIND_NO_RECURSE = 0x04,
+ HL_FIND_CASE_SENSITIVE = 0x08,
+ HL_FIND_MODE_STRING = 0x10,
+ HL_FIND_MODE_SUBSTRING = 0x20,
+ HL_FIND_MODE_WILDCARD = 0x00,
+ HL_FIND_ALL = HL_FIND_FILES | HL_FIND_FOLDERS
+ }
+
+ public enum HLStreamType : uint
+ {
+ HL_STREAM_NONE = 0,
+ HL_STREAM_FILE,
+ HL_STREAM_GCF,
+ HL_STREAM_MAPPING,
+ HL_STREAM_MEMORY,
+ HL_STREAM_PROC,
+ HL_STREAM_NULL
+ }
+
+ public enum HLMappingType : uint
+ {
+ HL_MAPPING_NONE = 0,
+ HL_MAPPING_FILE,
+ HL_MAPPING_MEMORY,
+ HL_MAPPING_STREAM
+ }
+
+ public enum HLPackageType : uint
+ {
+ HL_PACKAGE_NONE = 0,
+ HL_PACKAGE_BSP,
+ HL_PACKAGE_GCF,
+ HL_PACKAGE_PAK,
+ HL_PACKAGE_VBSP,
+ HL_PACKAGE_WAD,
+ HL_PACKAGE_XZP,
+ HL_PACKAGE_ZIP,
+ HL_PACKAGE_NCF,
+ HL_PACKAGE_VPK,
+ HL_PACKAGE_SGA
+ }
+
+ public enum HLAttributeType : uint
+ {
+ HL_ATTRIBUTE_INVALID = 0,
+ HL_ATTRIBUTE_BOOLEAN,
+ HL_ATTRIBUTE_INTEGER,
+ HL_ATTRIBUTE_UNSIGNED_INTEGER,
+ HL_ATTRIBUTE_FLOAT,
+ HL_ATTRIBUTE_STRING
+ }
+
+ public enum HLPackageAttribute : uint
+ {
+ HL_BSP_PACKAGE_VERSION = 0,
+ HL_BSP_PACKAGE_COUNT,
+ HL_BSP_ITEM_WIDTH = 0,
+ HL_BSP_ITEM_HEIGHT,
+ HL_BSP_ITEM_PALETTE_ENTRIES,
+ HL_BSP_ITEM_COUNT,
+
+ HL_GCF_PACKAGE_VERSION = 0,
+ HL_GCF_PACKAGE_ID,
+ HL_GCF_PACKAGE_ALLOCATED_BLOCKS,
+ HL_GCF_PACKAGE_USED_BLOCKS,
+ HL_GCF_PACKAGE_BLOCK_LENGTH,
+ HL_GCF_PACKAGE_LAST_VERSION_PLAYED,
+ HL_GCF_PACKAGE_COUNT,
+ HL_GCF_ITEM_ENCRYPTED = 0,
+ HL_GCF_ITEM_COPY_LOCAL,
+ HL_GCF_ITEM_OVERWRITE_LOCAL,
+ HL_GCF_ITEM_BACKUP_LOCAL,
+ HL_GCF_ITEM_FLAGS,
+ HL_GCF_ITEM_FRAGMENTATION,
+ HL_GCF_ITEM_COUNT,
+
+ HL_NCF_PACKAGE_VERSION = 0,
+ HL_NCF_PACKAGE_ID,
+ HL_NCF_PACKAGE_LAST_VERSION_PLAYED,
+ HL_NCF_PACKAGE_COUNT,
+ HL_NCF_ITEM_ENCRYPTED = 0,
+ HL_NCF_ITEM_COPY_LOCAL,
+ HL_NCF_ITEM_OVERWRITE_LOCAL,
+ HL_NCF_ITEM_BACKUP_LOCAL,
+ HL_NCF_ITEM_FLAGS,
+ HL_NCF_ITEM_COUNT,
+
+ HL_PAK_PACKAGE_COUNT = 0,
+ HL_PAK_ITEM_COUNT = 0,
+
+ HL_SGA_PACKAGE_VERSION_MAJOR = 0,
+ HL_SGA_PACKAGE_VERSION_MINOR,
+ HL_SGA_PACKAGE_MD5_FILE,
+ HL_SGA_PACKAGE_NAME,
+ HL_SGA_PACKAGE_MD5_HEADER,
+ HL_SGA_PACKAGE_COUNT,
+ HL_SGA_ITEM_SECTION_ALIAS = 0,
+ HL_SGA_ITEM_SECTION_NAME,
+ HL_SGA_ITEM_MODIFIED,
+ HL_SGA_ITEM_TYPE,
+ HL_SGA_ITEM_CRC,
+ HL_SGA_ITEM_VERIFICATION,
+ HL_SGA_ITEM_COUNT,
+
+ HL_VBSP_PACKAGE_VERSION = 0,
+ HL_VBSP_PACKAGE_MAP_REVISION,
+ HL_VBSP_PACKAGE_COUNT,
+ HL_VBSP_ITEM_VERSION = 0,
+ HL_VBSP_ITEM_FOUR_CC,
+ HL_VBSP_ZIP_PACKAGE_DISK,
+ HL_VBSP_ZIP_PACKAGE_COMMENT,
+ HL_VBSP_ZIP_ITEM_CREATE_VERSION,
+ HL_VBSP_ZIP_ITEM_EXTRACT_VERSION,
+ HL_VBSP_ZIP_ITEM_FLAGS,
+ HL_VBSP_ZIP_ITEM_COMPRESSION_METHOD,
+ HL_VBSP_ZIP_ITEM_CRC,
+ HL_VBSP_ZIP_ITEM_DISK,
+ HL_VBSP_ZIP_ITEM_COMMENT,
+ HL_VBSP_ITEM_COUNT,
+
+ HL_VPK_PACKAGE_COUNT = 0,
+ HL_VPK_ITEM_PRELOAD_BYTES = 0,
+ HL_VPK_ITEM_ARCHIVE,
+ HL_VPK_ITEM_CRC,
+ HL_VPK_ITEM_COUNT,
+
+ HL_WAD_PACKAGE_VERSION = 0,
+ HL_WAD_PACKAGE_COUNT,
+ HL_WAD_ITEM_WIDTH = 0,
+ HL_WAD_ITEM_HEIGHT,
+ HL_WAD_ITEM_PALETTE_ENTRIES,
+ HL_WAD_ITEM_MIPMAPS,
+ HL_WAD_ITEM_COMPRESSED,
+ HL_WAD_ITEM_TYPE,
+ HL_WAD_ITEM_COUNT,
+
+ HL_XZP_PACKAGE_VERSION = 0,
+ HL_XZP_PACKAGE_PRELOAD_BYTES,
+ HL_XZP_PACKAGE_COUNT,
+ HL_XZP_ITEM_CREATED = 0,
+ HL_XZP_ITEM_PRELOAD_BYTES,
+ HL_XZP_ITEM_COUNT,
+
+ HL_ZIP_PACKAGE_DISK = 0,
+ HL_ZIP_PACKAGE_COMMENT,
+ HL_ZIP_PACKAGE_COUNT,
+ HL_ZIP_ITEM_CREATE_VERSION = 0,
+ HL_ZIP_ITEM_EXTRACT_VERSION,
+ HL_ZIP_ITEM_FLAGS,
+ HL_ZIP_ITEM_COMPRESSION_METHOD,
+ HL_ZIP_ITEM_CRC,
+ HL_ZIP_ITEM_DISK,
+ HL_ZIP_ITEM_COMMENT,
+ HL_ZIP_ITEM_COUNT
+ }
+
+ public enum HLValidation
+ {
+ HL_VALIDATES_OK = 0,
+ HL_VALIDATES_ASSUMED_OK,
+ HL_VALIDATES_INCOMPLETE,
+ HL_VALIDATES_CORRUPT,
+ HL_VALIDATES_CANCELED,
+ HL_VALIDATES_ERROR
+ }
+ #endregion
+
+ #region Structures
+ [StructLayout(LayoutKind.Sequential,Pack=1,Size=512)]
+ public struct HLAttribute
+ {
+ public HLAttributeType eAttributeType;
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst=252)]
+ public byte[] lpName;
+ [MarshalAs(UnmanagedType.ByValArray, SizeConst=256)]
+ public byte[] lpValue;
+
+ public string GetName()
+ {
+ int iLength = 0;
+ while(lpName[iLength] != 0)
+ {
+ iLength++;
+ }
+ try
+ {
+ return System.Text.Encoding.ASCII.GetString(lpName, 0, iLength);
+ }
+ catch
+ {
+ return string.Empty;
+ }
+ }
+
+ public object GetData()
+ {
+ switch (eAttributeType)
+ {
+ case HLAttributeType.HL_ATTRIBUTE_BOOLEAN:
+ return hlAttributeGetBoolean(ref this);
+ case HLAttributeType.HL_ATTRIBUTE_INTEGER:
+ return hlAttributeGetInteger(ref this);
+ case HLAttributeType.HL_ATTRIBUTE_UNSIGNED_INTEGER:
+ return hlAttributeGetUnsignedInteger(ref this);
+ case HLAttributeType.HL_ATTRIBUTE_FLOAT:
+ return hlAttributeGetFloat(ref this);
+ case HLAttributeType.HL_ATTRIBUTE_STRING:
+ return hlAttributeGetString(ref this);
+ default:
+ return null;
+ }
+ }
+
+ public override string ToString()
+ {
+ switch (eAttributeType)
+ {
+ case HLAttributeType.HL_ATTRIBUTE_BOOLEAN:
+ return hlAttributeGetBoolean(ref this).ToString();
+ case HLAttributeType.HL_ATTRIBUTE_INTEGER:
+ return hlAttributeGetInteger(ref this).ToString("#,##0");
+ case HLAttributeType.HL_ATTRIBUTE_UNSIGNED_INTEGER:
+ if (lpValue[4] == 0)
+ {
+ return hlAttributeGetUnsignedInteger(ref this).ToString("#,##0");
+ }
+ else // Display as hexadecimal.
+ {
+ return "0x" + hlAttributeGetUnsignedInteger(ref this).ToString("x8");
+ }
+ case HLAttributeType.HL_ATTRIBUTE_FLOAT:
+ return hlAttributeGetFloat(ref this).ToString("#,##0.00000000");
+ case HLAttributeType.HL_ATTRIBUTE_STRING:
+ return hlAttributeGetString(ref this);
+ default:
+ return string.Empty;
+ }
+ }
+ }
+ #endregion
+
+ #region Callback Functions
+ //
+ // Important: Callback functions cannot use IntPtr. Instead, I use [MarshalAs(UnmanagedType.I4)]int.
+ // Convert IntPtr objects using IntPtr.ToInt32(). Convert int objects to IntPtr using new IntPtr(int).
+ // This obviously only works on 32 bit builds of HLLib.
+ //
+
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ [return:MarshalAs(UnmanagedType.U1)]
+ public delegate bool HLOpenProc(uint uiMode, IntPtr pUserData);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ [return:MarshalAs(UnmanagedType.U1)]
+ public delegate bool HLCloseProc(IntPtr pUserData);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ public delegate uint HLReadProc(IntPtr lpData, uint uiBytes, IntPtr pUserData);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ public delegate uint HLWriteProc(IntPtr lpData, uint uiBytes, IntPtr pUserData);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ public delegate uint HLSeekProc(long iOffset, HLSeekMode eSeekMode, IntPtr pUserData);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ public delegate ulong HLSeekExProc(Int64 iOffset, HLSeekMode eSeekMode, IntPtr pUserData);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ public delegate uint HLTellProc(IntPtr pUserData);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ public delegate ulong HLTellExProc(IntPtr pUserData);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ public delegate uint HLSizeProc(IntPtr pUserData);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ public delegate ulong HLSizeExProc(IntPtr pUserData);
+
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ public delegate void HLExtractItemStartProc(IntPtr pItem);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ public delegate void HLExtractItemEndProc(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]bool bSuccess);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ public delegate void HLExtractFileProgressProc(IntPtr pFile, uint uiBytesExtracted, uint uiBytesTotal, [MarshalAs(UnmanagedType.U1)]ref bool bCancel);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ public delegate void HLValidateFileProgressProc(IntPtr pFile, uint uiBytesValidated, uint uiBytesTotal, [MarshalAs(UnmanagedType.U1)]ref bool pCancel);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ public delegate void HLDefragmentFileProgressProc(IntPtr pFile, uint uiFilesDefragmented, uint uiFilesTotal, uint uiBytesDefragmented, uint uiBytesTotal, [MarshalAs(UnmanagedType.U1)]ref bool pCancel);
+ [UnmanagedFunctionPointerAttribute(CallingConvention.Cdecl)]
+ public delegate void HLDefragmentFileProgressExProc(IntPtr pFile, uint uiFilesDefragmented, uint uiFilesTotal, UInt64 uiBytesDefragmented, UInt64 uiBytesTotal, [MarshalAs(UnmanagedType.U1)]ref bool pCancel);
+ #endregion
+
+ #region Functions
+ public static bool IsWow64()
+ {
+ return IntPtr.Size == 8;
+ }
+
+ //
+ // VTFLib
+ //
+
+ public static void hlInitialize()
+ {
+ if (IsWow64()) x64.hlInitialize(); else x86.hlInitialize();
+ }
+ public static void hlShutdown()
+ {
+ if (IsWow64()) x64.hlShutdown(); else x86.hlShutdown();
+ }
+
+ //
+ // Get/Set
+ //
+
+ public static bool hlGetBoolean(HLOption eOption)
+ {
+ if (IsWow64()) return x64.hlGetBoolean(eOption); else return x86.hlGetBoolean(eOption);
+ }
+ public static bool hlGetBooleanValidate(HLOption eOption, out bool pValue)
+ {
+ if (IsWow64()) return x64.hlGetBooleanValidate(eOption, out pValue); else return x86.hlGetBooleanValidate(eOption, out pValue);
+ }
+ public static void hlSetBoolean(HLOption eOption, bool bValue)
+ {
+ if (IsWow64()) x64.hlSetBoolean(eOption, bValue); else x86.hlSetBoolean(eOption, bValue);
+ }
+
+ public static int hlGetInteger(HLOption eOption)
+ {
+ if (IsWow64()) return x64.hlGetInteger(eOption); else return x86.hlGetInteger(eOption);
+ }
+ public static bool hlGetIntegerValidate(HLOption eOption, out int pValue)
+ {
+ if (IsWow64()) return x64.hlGetIntegerValidate(eOption, out pValue); else return x86.hlGetIntegerValidate(eOption, out pValue);
+ }
+ public static void hlSetInteger(HLOption eOption, int iValue)
+ {
+ if (IsWow64()) x64.hlSetInteger(eOption, iValue); else x86.hlSetInteger(eOption, iValue);
+ }
+
+ public static uint hlGetUnsignedInteger(HLOption eOption)
+ {
+ if (IsWow64()) return x64.hlGetUnsignedInteger(eOption); else return x86.hlGetUnsignedInteger(eOption);
+ }
+ public static bool hlGetUnsignedIntegerValidate(HLOption eOption, out uint pValue)
+ {
+ if (IsWow64()) return x64.hlGetUnsignedIntegerValidate(eOption, out pValue); else return x86.hlGetUnsignedIntegerValidate(eOption, out pValue);
+ }
+ public static void hlSetUnsignedInteger(HLOption eOption, uint uiValue)
+ {
+ if (IsWow64()) x64.hlSetUnsignedInteger(eOption, uiValue); else x86.hlSetUnsignedInteger(eOption, uiValue);
+ }
+
+ public static long hlGetLong(HLOption eOption)
+ {
+ if (IsWow64()) return x64.hlGetLong(eOption); else return x86.hlGetLong(eOption);
+ }
+ public static bool hlGetLongValidate(HLOption eOption, out long pValue)
+ {
+ if (IsWow64()) return x64.hlGetLongValidate(eOption, out pValue); else return x86.hlGetLongValidate(eOption, out pValue);
+ }
+ public static void hlSetLong(HLOption eOption, long iValue)
+ {
+ if (IsWow64()) x64.hlSetLong(eOption, iValue); else x86.hlSetLong(eOption, iValue);
+ }
+
+ public static ulong hlGetUnsignedLong(HLOption eOption)
+ {
+ if (IsWow64()) return x64.hlGetUnsignedLong(eOption); else return x86.hlGetUnsignedLong(eOption);
+ }
+ public static bool hlGetUnsignedLongValidate(HLOption eOption, out ulong pValue)
+ {
+ if (IsWow64()) return x64.hlGetUnsignedLongValidate(eOption, out pValue); else return x86.hlGetUnsignedLongValidate(eOption, out pValue);
+ }
+ public static void hlSetUnsignedLong(HLOption eOption, ulong uiValue)
+ {
+ if (IsWow64()) x64.hlSetUnsignedLong(eOption, uiValue); else x86.hlSetUnsignedLong(eOption, uiValue);
+ }
+
+ public static float hlGetFloat(HLOption eOption)
+ {
+ if (IsWow64()) return x64.hlGetFloat(eOption); else return x86.hlGetFloat(eOption);
+ }
+ public static bool hlGetFloatValidate(HLOption eOption, out float pValue)
+ {
+ if (IsWow64()) return x64.hlGetFloatValidate(eOption, out pValue); else return x86.hlGetFloatValidate(eOption, out pValue);
+ }
+ public static void hlSetFloat(HLOption eOption, float pValue)
+ {
+ if (IsWow64()) x64.hlSetFloat(eOption, pValue); else x86.hlSetFloat(eOption, pValue);
+ }
+
+ public static string hlGetString(HLOption eOption)
+ {
+ IntPtr lpString;
+ if (IsWow64()) lpString = x64.hlGetString(eOption); else lpString = x86.hlGetString(eOption);
+ return lpString == IntPtr.Zero ? string.Empty : Marshal.PtrToStringAnsi(lpString);
+ }
+ public static bool hlGetStringValidate(HLOption eOption, out string pValue)
+ {
+ if (IsWow64()) return x64.hlGetStringValidate(eOption, out pValue); else return x86.hlGetStringValidate(eOption, out pValue);
+ }
+ public static void hlSetString(HLOption eOption, string lpValue)
+ {
+ if (IsWow64()) x64.hlSetString(eOption, lpValue); else x86.hlSetString(eOption, lpValue);
+ }
+
+ public static IntPtr hlGetVoid(HLOption eOption)
+ {
+ if (IsWow64()) return x64.hlGetVoid(eOption); else return x86.hlGetVoid(eOption);
+ }
+ public static bool hlGetVoidValidate(HLOption eOption, out IntPtr pValue)
+ {
+ if (IsWow64()) return x64.hlGetVoidValidate(eOption, out pValue); else return x86.hlGetVoidValidate(eOption, out pValue);
+ }
+ public static void hlSetVoid(HLOption eOption, IntPtr lpValue)
+ {
+ if (IsWow64()) x64.hlSetVoid(eOption, lpValue); else x86.hlSetVoid(eOption, lpValue);
+ }
+
+ //
+ // Attributes
+ //
+
+ public static bool hlAttributeGetBoolean(ref HLAttribute pAttribute)
+ {
+ if (IsWow64()) return x64.hlAttributeGetBoolean(ref pAttribute); else return x86.hlAttributeGetBoolean(ref pAttribute);
+ }
+ public static void hlAttributeSetBoolean(ref HLAttribute pAttribute, string lpName, bool bValue)
+ {
+ if (IsWow64()) x64.hlAttributeSetBoolean(ref pAttribute, lpName, bValue); else x86.hlAttributeSetBoolean(ref pAttribute, lpName, bValue);
+ }
+
+ public static int hlAttributeGetInteger(ref HLAttribute pAttribute)
+ {
+ if (IsWow64()) return x64.hlAttributeGetInteger(ref pAttribute); else return x86.hlAttributeGetInteger(ref pAttribute);
+ }
+ public static void hlAttributeSetInteger(ref HLAttribute pAttribute, string lpName, int iValue)
+ {
+ if (IsWow64()) x64.hlAttributeSetInteger(ref pAttribute, lpName, iValue); else x86.hlAttributeSetInteger(ref pAttribute, lpName, iValue);
+ }
+
+ public static uint hlAttributeGetUnsignedInteger(ref HLAttribute pAttribute)
+ {
+ if (IsWow64()) return x64.hlAttributeGetUnsignedInteger(ref pAttribute); else return x86.hlAttributeGetUnsignedInteger(ref pAttribute);
+ }
+ public static void hlAttributeSetUnsignedInteger(ref HLAttribute pAttribute, string lpName, uint uiValue, bool bHexadecimal)
+ {
+ if (IsWow64()) x64.hlAttributeSetUnsignedInteger(ref pAttribute, lpName, uiValue, bHexadecimal); else x86.hlAttributeSetUnsignedInteger(ref pAttribute, lpName, uiValue, bHexadecimal);
+ }
+
+ public static float hlAttributeGetFloat(ref HLAttribute pAttribute)
+ {
+ if (IsWow64()) return x64.hlAttributeGetFloat(ref pAttribute); else return x86.hlAttributeGetFloat(ref pAttribute);
+ }
+ public static void hlAttributeSetFloat(ref HLAttribute pAttribute, string lpName, float fValue)
+ {
+ if (IsWow64()) x64.hlAttributeSetFloat(ref pAttribute, lpName, fValue); else x86.hlAttributeSetFloat(ref pAttribute, lpName, fValue);
+ }
+
+ public static string hlAttributeGetString(ref HLAttribute pAttribute)
+ {
+ IntPtr lpString;
+ if (IsWow64()) lpString = x64.hlAttributeGetString(ref pAttribute); else lpString = x86.hlAttributeGetString(ref pAttribute);
+ return lpString == IntPtr.Zero ? string.Empty : Marshal.PtrToStringAnsi(lpString);
+ }
+ public static void hlAttributeSetString(ref HLAttribute pAttribute, string lpName, string lpValue)
+ {
+ if (IsWow64()) x64.hlAttributeSetString(ref pAttribute, lpName, lpValue); else x86.hlAttributeSetString(ref pAttribute, lpName, lpValue);
+ }
+
+ //
+ // Directory Item
+ //
+
+ public static HLDirectoryItemType hlItemGetType(IntPtr pItem)
+ {
+ if (IsWow64()) return x64.hlItemGetType(pItem); else return x86.hlItemGetType(pItem);
+ }
+
+ public static string hlItemGetName(IntPtr pItem)
+ {
+ IntPtr lpString;
+ if (IsWow64()) lpString = x64.hlItemGetName(pItem); else lpString = x86.hlItemGetName(pItem);
+ return lpString == IntPtr.Zero ? string.Empty : Marshal.PtrToStringAnsi(lpString);
+ }
+ public static uint hlItemGetID(IntPtr pItem)
+ {
+ if (IsWow64()) return x64.hlItemGetID(pItem); else return x86.hlItemGetID(pItem);
+ }
+ public static IntPtr hlItemGetData(IntPtr pItem)
+ {
+ if (IsWow64()) return x64.hlItemGetData(pItem); else return x86.hlItemGetData(pItem);
+ }
+
+ public static uint hlItemGetPackage(IntPtr pItem)
+ {
+ if (IsWow64()) return x64.hlItemGetPackage(pItem); else return x86.hlItemGetPackage(pItem);
+ }
+ public static IntPtr hlItemGetParent(IntPtr pItem)
+ {
+ if (IsWow64()) return x64.hlItemGetParent(pItem); else return x86.hlItemGetParent(pItem);
+ }
+
+ public static bool hlItemGetSize(IntPtr pItem, out uint pSize)
+ {
+ if (IsWow64()) return x64.hlItemGetSize(pItem, out pSize); else return x86.hlItemGetSize(pItem, out pSize);
+ }
+ public static bool hlItemGetSizeEx(IntPtr pItem, out UInt64 pSize)
+ {
+ if (IsWow64()) return x64.hlItemGetSizeEx(pItem, out pSize); else return x86.hlItemGetSizeEx(pItem, out pSize);
+ }
+ public static bool hlItemGetSizeOnDisk(IntPtr pItem, out uint pSize)
+ {
+ if (IsWow64()) return x64.hlItemGetSizeOnDisk(pItem, out pSize); else return x86.hlItemGetSizeOnDisk(pItem, out pSize);
+ }
+ public static bool hlItemGetSizeOnDiskEx(IntPtr pItem, out UInt64 pSize)
+ {
+ if (IsWow64()) return x64.hlItemGetSizeOnDiskEx(pItem, out pSize); else return x86.hlItemGetSizeOnDiskEx(pItem, out pSize);
+ }
+
+ public static bool hlItemGetPath(IntPtr pItem, IntPtr lpPath, uint uiPathSize)
+ {
+ if (IsWow64()) return x64.hlItemGetPath(pItem, lpPath, uiPathSize); else return x86.hlItemGetPath(pItem, lpPath, uiPathSize);
+ }
+ public static bool hlItemExtract(IntPtr pItem, string lpPath)
+ {
+ if (IsWow64()) return x64.hlItemExtract(pItem, lpPath); else return x86.hlItemExtract(pItem, lpPath);
+ }
+
+ //
+ // Directory Folder
+ //
+
+ public static uint hlFolderGetCount(IntPtr pItem)
+ {
+ if (IsWow64()) return x64.hlFolderGetCount(pItem); else return x86.hlFolderGetCount(pItem);
+ }
+
+ public static IntPtr hlFolderGetItem(IntPtr pItem, uint uiIndex)
+ {
+ if (IsWow64()) return x64.hlFolderGetItem(pItem, uiIndex); else return x86.hlFolderGetItem(pItem, uiIndex);
+ }
+ public static IntPtr hlFolderGetItemByName(IntPtr pItem, string lpName, HLFindType eFind)
+ {
+ if (IsWow64()) return x64.hlFolderGetItemByName(pItem, lpName, eFind); else return x86.hlFolderGetItemByName(pItem, lpName, eFind);
+ }
+ public static IntPtr hlFolderGetItemByPath(IntPtr pItem, string lpPath, HLFindType eFind)
+ {
+ if (IsWow64()) return x64.hlFolderGetItemByPath(pItem, lpPath, eFind); else return x86.hlFolderGetItemByPath(pItem, lpPath, eFind);
+ }
+
+ public static void hlFolderSort(IntPtr pItem, HLSortField eField, HLSortOrder eOrder, bool bRecurse)
+ {
+ if (IsWow64()) x64.hlFolderSort(pItem, eField, eOrder, bRecurse); else x86.hlFolderSort(pItem, eField, eOrder, bRecurse);
+ }
+
+ public static IntPtr hlFolderFindFirst(IntPtr pFolder, string lpSearch, HLFindType eFind)
+ {
+ if (IsWow64()) return x64.hlFolderFindFirst(pFolder, lpSearch, eFind); else return x86.hlFolderFindFirst(pFolder, lpSearch, eFind);
+ }
+ public static IntPtr hlFolderFindNext(IntPtr pFolder, IntPtr pItem, string lpSearch, HLFindType eFind)
+ {
+ if (IsWow64()) return x64.hlFolderFindNext(pFolder, pItem, lpSearch, eFind); else return x86.hlFolderFindNext(pFolder, pItem, lpSearch, eFind);
+ }
+
+ public static uint hlFolderGetSize(IntPtr pItem, bool bRecurse)
+ {
+ if (IsWow64()) return x64.hlFolderGetSize(pItem, bRecurse); else return x86.hlFolderGetSize(pItem, bRecurse);
+ }
+ public static UInt64 hlFolderGetSizeEx(IntPtr pItem, bool bRecurse)
+ {
+ if (IsWow64()) return x64.hlFolderGetSizeEx(pItem, bRecurse); else return x86.hlFolderGetSizeEx(pItem, bRecurse);
+ }
+ public static uint hlFolderGetSizeOnDisk(IntPtr pItem, bool bRecurse)
+ {
+ if (IsWow64()) return x64.hlFolderGetSizeOnDisk(pItem, bRecurse); else return x86.hlFolderGetSizeOnDisk(pItem, bRecurse);
+ }
+ public static UInt64 hlFolderGetSizeOnDiskEx(IntPtr pItem, bool bRecurse)
+ {
+ if (IsWow64()) return x64.hlFolderGetSizeOnDiskEx(pItem, bRecurse); else return x86.hlFolderGetSizeOnDiskEx(pItem, bRecurse);
+ }
+ public static uint hlFolderGetFolderCount(IntPtr pItem, bool bRecurse)
+ {
+ if (IsWow64()) return x64.hlFolderGetFolderCount(pItem, bRecurse); else return x86.hlFolderGetFolderCount(pItem, bRecurse);
+ }
+ public static uint hlFolderGetFileCount(IntPtr pItem, bool bRecurse)
+ {
+ if (IsWow64()) return x64.hlFolderGetFileCount(pItem, bRecurse); else return x86.hlFolderGetFileCount(pItem, bRecurse);
+ }
+
+ //
+ // Directory File
+ //
+
+ public static uint hlFileGetExtractable(IntPtr pItem)
+ {
+ if (IsWow64()) return x64.hlFileGetExtractable(pItem); else return x86.hlFileGetExtractable(pItem);
+ }
+ public static HLValidation hlFileGetValidation(IntPtr pItem)
+ {
+ if (IsWow64()) return x64.hlFileGetValidation(pItem); else return x86.hlFileGetValidation(pItem);
+ }
+ public static uint hlFileGetSize(IntPtr pItem)
+ {
+ if (IsWow64()) return x64.hlFileGetSize(pItem); else return x86.hlFileGetSize(pItem);
+ }
+ public static uint hlFileGetSizeOnDisk(IntPtr pItem)
+ {
+ if (IsWow64()) return x64.hlFileGetSizeOnDisk(pItem); else return x86.hlFileGetSizeOnDisk(pItem);
+ }
+
+ public static bool hlFileCreateStream(IntPtr pItem, out IntPtr pStream)
+ {
+ if (IsWow64()) return x64.hlFileCreateStream(pItem, out pStream); else return x86.hlFileCreateStream(pItem, out pStream);
+ }
+ public static void hlFileReleaseStream(IntPtr pItem, IntPtr pStream)
+ {
+ if (IsWow64()) x64.hlFileReleaseStream(pItem, pStream); else x86.hlFileReleaseStream(pItem, pStream);
+ }
+
+ //
+ // Stream
+ //
+
+ public static HLStreamType hlStreamGetType(IntPtr pStream)
+ {
+ if (IsWow64()) return x64.hlStreamGetType(pStream); else return x86.hlStreamGetType(pStream);
+ }
+
+ public static bool hlStreamGetOpened(IntPtr pStream)
+ {
+ if (IsWow64()) return x64.hlStreamGetOpened(pStream); else return x86.hlStreamGetOpened(pStream);
+ }
+ public static uint hlStreamGetMode(IntPtr pStream)
+ {
+ if (IsWow64()) return x64.hlStreamGetMode(pStream); else return x86.hlStreamGetMode(pStream);
+ }
+
+ public static bool hlStreamOpen(IntPtr pStream, uint uiMode)
+ {
+ if (IsWow64()) return x64.hlStreamOpen(pStream, uiMode); else return x86.hlStreamOpen(pStream, uiMode);
+ }
+ public static void hlStreamClose(IntPtr pStream)
+ {
+ if (IsWow64()) x64.hlStreamClose(pStream); else x86.hlStreamClose(pStream);
+ }
+
+ public static uint hlStreamGetStreamSize(IntPtr pStream)
+ {
+ if (IsWow64()) return x64.hlStreamGetStreamSize(pStream); else return x86.hlStreamGetStreamSize(pStream);
+ }
+ public static ulong hlStreamGetStreamSizeEx(IntPtr pStream)
+ {
+ if (IsWow64()) return x64.hlStreamGetStreamSizeEx(pStream); else return x86.hlStreamGetStreamSizeEx(pStream);
+ }
+ public static uint hlStreamGetStreamPointer(IntPtr pStream)
+ {
+ if (IsWow64()) return x64.hlStreamGetStreamPointer(pStream); else return x86.hlStreamGetStreamPointer(pStream);
+ }
+ public static ulong hlStreamGetStreamPointerEx(IntPtr pStream)
+ {
+ if (IsWow64()) return x64.hlStreamGetStreamPointerEx(pStream); else return x86.hlStreamGetStreamPointerEx(pStream);
+ }
+
+ public static uint hlStreamSeek(IntPtr pStream, long iOffset, HLSeekMode eSeekMode)
+ {
+ if (IsWow64()) return x64.hlStreamSeek(pStream, iOffset, eSeekMode); else return x86.hlStreamSeek(pStream, iOffset, eSeekMode);
+ }
+ public static ulong hlStreamSeekEx(IntPtr pStream, long iOffset, HLSeekMode eSeekMode)
+ {
+ if (IsWow64()) return x64.hlStreamSeekEx(pStream, iOffset, eSeekMode); else return x86.hlStreamSeekEx(pStream, iOffset, eSeekMode);
+ }
+
+ public static bool hlStreamReadChar(IntPtr pStream, out char pChar)
+ {
+ if (IsWow64()) return x64.hlStreamReadChar(pStream, out pChar); else return x86.hlStreamReadChar(pStream, out pChar);
+ }
+ public static uint hlStreamRead(IntPtr pStream, IntPtr lpData, uint uiBytes)
+ {
+ if (IsWow64()) return x64.hlStreamRead(pStream, lpData, uiBytes); else return x86.hlStreamRead(pStream, lpData, uiBytes);
+ }
+
+ public static bool hlStreamWriteChar(IntPtr pStream, char iChar)
+ {
+ if (IsWow64()) return x64.hlStreamWriteChar(pStream, iChar); else return x86.hlStreamWriteChar(pStream, iChar);
+ }
+ public static uint hlStreamWrite(IntPtr pStream, IntPtr lpData, uint uiBytes)
+ {
+ if (IsWow64()) return x64.hlStreamWrite(pStream, lpData, uiBytes); else return x86.hlStreamWrite(pStream, lpData, uiBytes);
+ }
+
+ //
+ // Package
+ //
+
+ public static bool hlBindPackage(uint uiPackage)
+ {
+ if (IsWow64()) return x64.hlBindPackage(uiPackage); else return x86.hlBindPackage(uiPackage);
+ }
+
+ public static HLPackageType hlGetPackageTypeFromName(string lpName)
+ {
+ if (IsWow64()) return x64.hlGetPackageTypeFromName(lpName); else return x86.hlGetPackageTypeFromName(lpName);
+ }
+ public static HLPackageType hlGetPackageTypeFromMemory(IntPtr lpBuffer, uint uiBufferSize)
+ {
+ if (IsWow64()) return x64.hlGetPackageTypeFromMemory(lpBuffer, uiBufferSize); else return x86.hlGetPackageTypeFromMemory(lpBuffer, uiBufferSize);
+ }
+ public static HLPackageType hlGetPackageTypeFromStream(IntPtr pStream)
+ {
+ if (IsWow64()) return x64.hlGetPackageTypeFromStream(pStream); else return x86.hlGetPackageTypeFromStream(pStream);
+ }
+
+ public static bool hlCreatePackage(HLPackageType ePackageType, out uint uiPackage)
+ {
+ if (IsWow64()) return x64.hlCreatePackage(ePackageType, out uiPackage); else return x86.hlCreatePackage(ePackageType, out uiPackage);
+ }
+ public static void hlDeletePackage(uint uiPackage)
+ {
+ if (IsWow64()) x64.hlDeletePackage(uiPackage); else x86.hlDeletePackage(uiPackage);
+ }
+
+ public static HLPackageType hlPackageGetType()
+ {
+ if (IsWow64()) return x64.hlPackageGetType(); else return x86.hlPackageGetType();
+ }
+ public static string hlPackageGetExtension()
+ {
+ IntPtr lpString;
+ if (IsWow64()) lpString = x64.hlPackageGetExtension(); else lpString = x86.hlPackageGetExtension();
+ return lpString == IntPtr.Zero ? string.Empty : Marshal.PtrToStringAnsi(lpString);
+ }
+ public static string hlPackageGetDescription()
+ {
+ IntPtr lpString;
+ if (IsWow64()) lpString = x64.hlPackageGetDescription(); else lpString = x86.hlPackageGetDescription();
+ return lpString == IntPtr.Zero ? string.Empty : Marshal.PtrToStringAnsi(lpString);
+ }
+
+ public static bool hlPackageGetOpened()
+ {
+ if (IsWow64()) return x64.hlPackageGetOpened(); else return x86.hlPackageGetOpened();
+ }
+
+ public static bool hlPackageOpenFile(string lpFileName, uint uiMode)
+ {
+ if (IsWow64()) return x64.hlPackageOpenFile(lpFileName, uiMode); else return x86.hlPackageOpenFile(lpFileName, uiMode);
+ }
+ public static bool hlPackageOpenMemory(IntPtr lpData, uint uiBufferSize, uint uiMode)
+ {
+ if (IsWow64()) return x64.hlPackageOpenMemory(lpData, uiBufferSize, uiMode); else return x86.hlPackageOpenMemory(lpData, uiBufferSize, uiMode);
+ }
+ public static bool hlPackageOpenProc(IntPtr pUserData, uint uiMode)
+ {
+ if (IsWow64()) return x64.hlPackageOpenProc(pUserData, uiMode); else return x86.hlPackageOpenProc(pUserData, uiMode);
+ }
+ public static bool hlPackageOpenStream(IntPtr pStream, uint uiMode)
+ {
+ if (IsWow64()) return x64.hlPackageOpenStream(pStream, uiMode); else return x86.hlPackageOpenStream(pStream, uiMode);
+ }
+ public static void hlPackageClose()
+ {
+ if (IsWow64()) x64.hlPackageClose(); else x86.hlPackageClose();
+ }
+
+ public static bool hlPackageDefragment()
+ {
+ if (IsWow64()) return x64.hlPackageDefragment(); else return x86.hlPackageDefragment();
+ }
+
+ public static IntPtr hlPackageGetRoot()
+ {
+ if (IsWow64()) return x64.hlPackageGetRoot(); else return x86.hlPackageGetRoot();
+ }
+
+ public static uint hlPackageGetAttributeCount()
+ {
+ if (IsWow64()) return x64.hlPackageGetAttributeCount(); else return x86.hlPackageGetAttributeCount();
+ }
+ public static string hlPackageGetAttributeName(HLPackageAttribute eAttribute)
+ {
+ IntPtr lpString;
+ if (IsWow64()) lpString = x64.hlPackageGetAttributeName(eAttribute); else lpString = x86.hlPackageGetAttributeName(eAttribute);
+ return lpString == IntPtr.Zero ? string.Empty : Marshal.PtrToStringAnsi(lpString);
+ }
+ public static bool hlPackageGetAttribute(HLPackageAttribute eAttribute, out HLAttribute pAttribute)
+ {
+ if (IsWow64()) return x64.hlPackageGetAttribute(eAttribute, out pAttribute); else return x86.hlPackageGetAttribute(eAttribute, out pAttribute);
+ }
+
+ public static uint hlPackageGetItemAttributeCount()
+ {
+ if (IsWow64()) return x64.hlPackageGetItemAttributeCount(); else return x86.hlPackageGetItemAttributeCount();
+ }
+ public static string hlPackageGetItemAttributeName(HLPackageAttribute eAttribute)
+ {
+ IntPtr lpString;
+ if (IsWow64()) lpString = x64.hlPackageGetItemAttributeName(eAttribute); else lpString = x86.hlPackageGetItemAttributeName(eAttribute);
+ return lpString == IntPtr.Zero ? string.Empty : Marshal.PtrToStringAnsi(lpString);
+ }
+ public static bool hlPackageGetItemAttribute(IntPtr pItem, HLPackageAttribute eAttribute, out HLAttribute pAttribute)
+ {
+ if (IsWow64()) return x64.hlPackageGetItemAttribute(pItem, eAttribute, out pAttribute); else return x86.hlPackageGetItemAttribute(pItem, eAttribute, out pAttribute);
+ }
+
+ public static bool hlPackageGetExtractable(IntPtr pItem, out bool pExtractable)
+ {
+ if (IsWow64()) return x64.hlPackageGetExtractable(pItem, out pExtractable); else return x86.hlPackageGetExtractable(pItem, out pExtractable);
+ }
+ public static bool hlPackageGetFileSize(IntPtr pItem, out uint pSize)
+ {
+ if (IsWow64()) return x64.hlPackageGetFileSize(pItem, out pSize); else return x86.hlPackageGetFileSize(pItem, out pSize);
+ }
+ public static bool hlPackageGetFileSizeOnDisk(IntPtr pItem, out uint pSize)
+ {
+ if (IsWow64()) return x64.hlPackageGetFileSizeOnDisk(pItem, out pSize); else return x86.hlPackageGetFileSizeOnDisk(pItem, out pSize);
+ }
+ public static bool hlPackageCreateStream(IntPtr pItem, out IntPtr pStream)
+ {
+ if (IsWow64()) return x64.hlPackageCreateStream(pItem, out pStream); else return x86.hlPackageCreateStream(pItem, out pStream);
+ }
+ public static void hlPackageReleaseStream(IntPtr pStream)
+ {
+ if (IsWow64()) x64.hlPackageReleaseStream(pStream); else x86.hlPackageReleaseStream(pStream);
+ }
+
+ public static string hlNCFFileGetRootPath()
+ {
+ IntPtr lpString;
+ if (IsWow64()) lpString = x64.hlNCFFileGetRootPath(); else lpString = x86.hlNCFFileGetRootPath();
+ return lpString == IntPtr.Zero ? string.Empty : Marshal.PtrToStringAnsi(lpString);
+ }
+ public static void hlNCFFileSetRootPath(string lpRootPath)
+ {
+ if (IsWow64()) x64.hlNCFFileSetRootPath(lpRootPath); else x86.hlNCFFileSetRootPath(lpRootPath);
+ }
+
+ public static bool hlWADFileGetImageSizePaletted(IntPtr pItem, out uint uiPaletteDataSize, out uint uiPixelDataSize)
+ {
+ if (IsWow64()) return x64.hlWADFileGetImageSizePaletted(pItem, out uiPaletteDataSize, out uiPixelDataSize); else return x86.hlWADFileGetImageSizePaletted(pItem, out uiPaletteDataSize, out uiPixelDataSize);
+ }
+ public static bool hlWADFileGetImageDataPaletted(IntPtr pItem, out uint uiWidth, out uint uiHeight, out IntPtr lpPaletteData, out IntPtr lpPixelData)
+ {
+ if (IsWow64()) return x64.hlWADFileGetImageDataPaletted(pItem, out uiWidth, out uiHeight, out lpPaletteData, out lpPixelData); else return x86.hlWADFileGetImageDataPaletted(pItem, out uiWidth, out uiHeight, out lpPaletteData, out lpPixelData);
+ }
+ public static bool hlWADFileGetImageSize(IntPtr pItem, out uint uiPixelDataSize)
+ {
+ if (IsWow64()) return x64.hlWADFileGetImageSize(pItem, out uiPixelDataSize); else return x86.hlWADFileGetImageSize(pItem, out uiPixelDataSize);
+ }
+ public static bool hlWADFileGetImageData(IntPtr pItem, out uint uiWidth, out uint uiHeight, out IntPtr lpPixelData)
+ {
+ if (IsWow64()) return x64.hlWADFileGetImageData(pItem, out uiWidth, out uiHeight, out lpPixelData); else return x86.hlWADFileGetImageData(pItem, out uiWidth, out uiHeight, out lpPixelData);
+ }
+
+ private static class x86
+ {
+ //
+ // VTFLib
+ //
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlInitialize();
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlShutdown();
+
+ //
+ // Get/Set
+ //
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetBoolean(HLOption eOption);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetBooleanValidate(HLOption eOption, [MarshalAs(UnmanagedType.U1)]out bool pValue);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlSetBoolean(HLOption eOption, [MarshalAs(UnmanagedType.U1)]bool bValue);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern int hlGetInteger(HLOption eOption);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetIntegerValidate(HLOption eOption, out int pValue);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlSetInteger(HLOption eOption, int iValue);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlGetUnsignedInteger(HLOption eOption);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetUnsignedIntegerValidate(HLOption eOption, out uint pValue);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlSetUnsignedInteger(HLOption eOption, uint uiValue);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "hlGetLongLong")]
+ public static extern long hlGetLong(HLOption eOption);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "hlGetLongLongValidate")]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetLongValidate(HLOption eOption, out long pValue);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "hlSetLongLong")]
+ public static extern void hlSetLong(HLOption eOption, long iValue);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "hlGetUnsignedLongLong")]
+ public static extern ulong hlGetUnsignedLong(HLOption eOption);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "hlGetUnsignedLongLongValidate")]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetUnsignedLongValidate(HLOption eOption, out ulong pValue);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "hlSetUnsignedLongLong")]
+ public static extern void hlSetUnsignedLong(HLOption eOption, ulong uiValue);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern float hlGetFloat(HLOption eOption);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetFloatValidate(HLOption eOption, out float pValue);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlSetFloat(HLOption eOption, float pValue);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlGetString(HLOption eOption);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetStringValidate(HLOption eOption, out string pValue);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlSetString(HLOption eOption, [MarshalAs(UnmanagedType.LPStr)]string lpValue);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlGetVoid(HLOption eOption);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetVoidValidate(HLOption eOption, out IntPtr pValue);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlSetVoid(HLOption eOption, IntPtr lpValue);
+
+ //
+ // Attributes
+ //
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlAttributeGetBoolean(ref HLAttribute pAttribute);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlAttributeSetBoolean(ref HLAttribute pAttribute, [MarshalAs(UnmanagedType.LPStr)]string lpName, [MarshalAs(UnmanagedType.U1)]bool bValue);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern int hlAttributeGetInteger(ref HLAttribute pAttribute);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlAttributeSetInteger(ref HLAttribute pAttribute, [MarshalAs(UnmanagedType.LPStr)]string lpName, int iValue);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlAttributeGetUnsignedInteger(ref HLAttribute pAttribute);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlAttributeSetUnsignedInteger(ref HLAttribute pAttribute, [MarshalAs(UnmanagedType.LPStr)]string lpName, uint uiValue, [MarshalAs(UnmanagedType.U1)]bool bHexadecimal);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern float hlAttributeGetFloat(ref HLAttribute pAttribute);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlAttributeSetFloat(ref HLAttribute pAttribute, [MarshalAs(UnmanagedType.LPStr)]string lpName, float fValue);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlAttributeGetString(ref HLAttribute pAttribute);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlAttributeSetString(ref HLAttribute pAttribute, [MarshalAs(UnmanagedType.LPStr)]string lpName, [MarshalAs(UnmanagedType.LPStr)]string lpValue);
+
+ //
+ // Directory Item
+ //
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern HLDirectoryItemType hlItemGetType(IntPtr pItem);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ //[return: MarshalAs(UnmanagedType.LPStr)]
+ public static extern IntPtr hlItemGetName(IntPtr pItem);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlItemGetID(IntPtr pItem);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlItemGetData(IntPtr pItem);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlItemGetPackage(IntPtr pItem);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlItemGetParent(IntPtr pItem);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlItemGetSize(IntPtr pItem, out uint pSize);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlItemGetSizeEx(IntPtr pItem, out UInt64 pSize);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlItemGetSizeOnDisk(IntPtr pItem, out uint pSize);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlItemGetSizeOnDiskEx(IntPtr pItem, out UInt64 pSize);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlItemGetPath(IntPtr pItem, IntPtr lpPath, uint uiPathSize);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlItemExtract(IntPtr pItem, [MarshalAs(UnmanagedType.LPStr)]string lpPath);
+
+ //
+ // Directory Folder
+ //
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFolderGetCount(IntPtr pItem);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlFolderGetItem(IntPtr pItem, uint uiIndex);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlFolderGetItemByName(IntPtr pItem, [MarshalAs(UnmanagedType.LPStr)]string lpName, HLFindType eFind);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlFolderGetItemByPath(IntPtr pItem, [MarshalAs(UnmanagedType.LPStr)]string lpPath, HLFindType eFind);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlFolderSort(IntPtr pItem, HLSortField eField, HLSortOrder eOrder, [MarshalAs(UnmanagedType.U1)]bool bRecurse);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlFolderFindFirst(IntPtr pFolder, [MarshalAs(UnmanagedType.LPStr)]string lpSearch, HLFindType eFind);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlFolderFindNext(IntPtr pFolder, IntPtr pItem, [MarshalAs(UnmanagedType.LPStr)]string lpSearch, HLFindType eFind);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFolderGetSize(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]bool bRecurse);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern UInt64 hlFolderGetSizeEx(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]bool bRecurse);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFolderGetSizeOnDisk(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]bool bRecurse);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern UInt64 hlFolderGetSizeOnDiskEx(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]bool bRecurse);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFolderGetFolderCount(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]bool bRecurse);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFolderGetFileCount(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]bool bRecurse);
+
+ //
+ // Directory File
+ //
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFileGetExtractable(IntPtr pItem);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern HLValidation hlFileGetValidation(IntPtr pItem);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFileGetSize(IntPtr pItem);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFileGetSizeOnDisk(IntPtr pItem);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlFileCreateStream(IntPtr pItem, out IntPtr pStream);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlFileReleaseStream(IntPtr pItem, IntPtr pStream);
+
+ //
+ // Stream
+ //
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern HLStreamType hlStreamGetType(IntPtr pStream);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlStreamGetOpened(IntPtr pStream);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlStreamGetMode(IntPtr pStream);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlStreamOpen(IntPtr pStream, uint uiMode);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlStreamClose(IntPtr pStream);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlStreamGetStreamSize(IntPtr pStream);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern ulong hlStreamGetStreamSizeEx(IntPtr pStream);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlStreamGetStreamPointer(IntPtr pStream);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern ulong hlStreamGetStreamPointerEx(IntPtr pStream);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlStreamSeek(IntPtr pStream, long iOffset, HLSeekMode eSeekMode);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern ulong hlStreamSeekEx(IntPtr pStream, long iOffset, HLSeekMode eSeekMode);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlStreamReadChar(IntPtr pStream, out char pChar);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlStreamRead(IntPtr pStream, IntPtr lpData, uint uiBytes);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlStreamWriteChar(IntPtr pStream, char iChar);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlStreamWrite(IntPtr pStream, IntPtr lpData, uint uiBytes);
+
+ //
+ // Package
+ //
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlBindPackage(uint uiPackage);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern HLPackageType hlGetPackageTypeFromName([MarshalAs(UnmanagedType.LPStr)]string lpName);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern HLPackageType hlGetPackageTypeFromMemory(IntPtr lpBuffer, uint uiBufferSize);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern HLPackageType hlGetPackageTypeFromStream(IntPtr pStream);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlCreatePackage(HLPackageType ePackageType, out uint uiPackage);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlDeletePackage(uint uiPackage);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern HLPackageType hlPackageGetType();
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlPackageGetExtension();
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlPackageGetDescription();
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageGetOpened();
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageOpenFile([MarshalAs(UnmanagedType.LPStr)]string lpFileName, uint uiMode);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageOpenMemory(IntPtr lpData, uint uiBufferSize, uint uiMode);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageOpenProc(IntPtr pUserData, uint uiMode);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageOpenStream(IntPtr pStream, uint uiMode);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlPackageClose();
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageDefragment();
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlPackageGetRoot();
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlPackageGetAttributeCount();
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlPackageGetAttributeName(HLPackageAttribute eAttribute);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageGetAttribute(HLPackageAttribute eAttribute, out HLAttribute pAttribute);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlPackageGetItemAttributeCount();
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlPackageGetItemAttributeName(HLPackageAttribute eAttribute);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageGetItemAttribute(IntPtr pItem, HLPackageAttribute eAttribute, out HLAttribute pAttribute);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageGetExtractable(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]out bool pExtractable);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageGetFileSize(IntPtr pItem, out uint pSize);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageGetFileSizeOnDisk(IntPtr pItem, out uint pSize);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageCreateStream(IntPtr pItem, out IntPtr pStream);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlPackageReleaseStream(IntPtr pStream);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlNCFFileGetRootPath();
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlNCFFileSetRootPath([MarshalAs(UnmanagedType.LPStr)]string lpRootPath);
+
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlWADFileGetImageSizePaletted(IntPtr pItem, out uint uiPaletteDataSize, out uint uiPixelDataSize);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlWADFileGetImageDataPaletted(IntPtr pItemm, out uint uiWidth, out uint uiHeight, out IntPtr lpPaletteData, out IntPtr lpPixelData);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlWADFileGetImageSize(IntPtr pItem, out uint uiPixelDataSize);
+ [DllImport("HLLib.x86.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlWADFileGetImageData(IntPtr pItem, out uint uiWidth, out uint uiHeight, out IntPtr lpPixelData);
+ }
+
+ private static class x64
+ {
+ //
+ // VTFLib
+ //
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlInitialize();
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlShutdown();
+
+ //
+ // Get/Set
+ //
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetBoolean(HLOption eOption);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetBooleanValidate(HLOption eOption, [MarshalAs(UnmanagedType.U1)]out bool pValue);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlSetBoolean(HLOption eOption, [MarshalAs(UnmanagedType.U1)]bool bValue);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern int hlGetInteger(HLOption eOption);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetIntegerValidate(HLOption eOption, out int pValue);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlSetInteger(HLOption eOption, int iValue);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlGetUnsignedInteger(HLOption eOption);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetUnsignedIntegerValidate(HLOption eOption, out uint pValue);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlSetUnsignedInteger(HLOption eOption, uint uiValue);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "hlGetLongLong")]
+ public static extern long hlGetLong(HLOption eOption);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "hlGetLongLongValidate")]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetLongValidate(HLOption eOption, out long pValue);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "hlSetLongLong")]
+ public static extern void hlSetLong(HLOption eOption, long iValue);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "hlGetUnsignedLongLong")]
+ public static extern ulong hlGetUnsignedLong(HLOption eOption);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "hlGetUnsignedLongLongValidate")]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetUnsignedLongValidate(HLOption eOption, out ulong pValue);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi, EntryPoint = "hlSetUnsignedLongLong")]
+ public static extern void hlSetUnsignedLong(HLOption eOption, ulong uiValue);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern float hlGetFloat(HLOption eOption);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetFloatValidate(HLOption eOption, out float pValue);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlSetFloat(HLOption eOption, float pValue);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlGetString(HLOption eOption);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetStringValidate(HLOption eOption, out string pValue);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlSetString(HLOption eOption, [MarshalAs(UnmanagedType.LPStr)]string lpValue);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlGetVoid(HLOption eOption);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlGetVoidValidate(HLOption eOption, out IntPtr pValue);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlSetVoid(HLOption eOption, IntPtr lpValue);
+
+ //
+ // Attributes
+ //
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlAttributeGetBoolean(ref HLAttribute pAttribute);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlAttributeSetBoolean(ref HLAttribute pAttribute, [MarshalAs(UnmanagedType.LPStr)]string lpName, [MarshalAs(UnmanagedType.U1)]bool bValue);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern int hlAttributeGetInteger(ref HLAttribute pAttribute);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlAttributeSetInteger(ref HLAttribute pAttribute, [MarshalAs(UnmanagedType.LPStr)]string lpName, int iValue);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlAttributeGetUnsignedInteger(ref HLAttribute pAttribute);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlAttributeSetUnsignedInteger(ref HLAttribute pAttribute, [MarshalAs(UnmanagedType.LPStr)]string lpName, uint uiValue, [MarshalAs(UnmanagedType.U1)]bool bHexadecimal);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern float hlAttributeGetFloat(ref HLAttribute pAttribute);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlAttributeSetFloat(ref HLAttribute pAttribute, [MarshalAs(UnmanagedType.LPStr)]string lpName, float fValue);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlAttributeGetString(ref HLAttribute pAttribute);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlAttributeSetString(ref HLAttribute pAttribute, [MarshalAs(UnmanagedType.LPStr)]string lpName, [MarshalAs(UnmanagedType.LPStr)]string lpValue);
+
+ //
+ // Directory Item
+ //
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern HLDirectoryItemType hlItemGetType(IntPtr pItem);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ //[return: MarshalAs(UnmanagedType.LPStr)]
+ public static extern IntPtr hlItemGetName(IntPtr pItem);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlItemGetID(IntPtr pItem);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlItemGetData(IntPtr pItem);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlItemGetPackage(IntPtr pItem);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlItemGetParent(IntPtr pItem);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlItemGetSize(IntPtr pItem, out uint pSize);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlItemGetSizeEx(IntPtr pItem, out UInt64 pSize);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlItemGetSizeOnDisk(IntPtr pItem, out uint pSize);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlItemGetSizeOnDiskEx(IntPtr pItem, out UInt64 pSize);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlItemGetPath(IntPtr pItem, IntPtr lpPath, uint uiPathSize);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlItemExtract(IntPtr pItem, [MarshalAs(UnmanagedType.LPStr)]string lpPath);
+
+ //
+ // Directory Folder
+ //
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFolderGetCount(IntPtr pItem);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlFolderGetItem(IntPtr pItem, uint uiIndex);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlFolderGetItemByName(IntPtr pItem, [MarshalAs(UnmanagedType.LPStr)]string lpName, HLFindType eFind);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlFolderGetItemByPath(IntPtr pItem, [MarshalAs(UnmanagedType.LPStr)]string lpPath, HLFindType eFind);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlFolderSort(IntPtr pItem, HLSortField eField, HLSortOrder eOrder, [MarshalAs(UnmanagedType.U1)]bool bRecurse);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlFolderFindFirst(IntPtr pFolder, [MarshalAs(UnmanagedType.LPStr)]string lpSearch, HLFindType eFind);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlFolderFindNext(IntPtr pFolder, IntPtr pItem, [MarshalAs(UnmanagedType.LPStr)]string lpSearch, HLFindType eFind);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFolderGetSize(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]bool bRecurse);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern UInt64 hlFolderGetSizeEx(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]bool bRecurse);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFolderGetSizeOnDisk(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]bool bRecurse);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern UInt64 hlFolderGetSizeOnDiskEx(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]bool bRecurse);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFolderGetFolderCount(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]bool bRecurse);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFolderGetFileCount(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]bool bRecurse);
+
+ //
+ // Directory File
+ //
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFileGetExtractable(IntPtr pItem);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern HLValidation hlFileGetValidation(IntPtr pItem);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFileGetSize(IntPtr pItem);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlFileGetSizeOnDisk(IntPtr pItem);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlFileCreateStream(IntPtr pItem, out IntPtr pStream);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlFileReleaseStream(IntPtr pItem, IntPtr pStream);
+
+ //
+ // Stream
+ //
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern HLStreamType hlStreamGetType(IntPtr pStream);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlStreamGetOpened(IntPtr pStream);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlStreamGetMode(IntPtr pStream);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlStreamOpen(IntPtr pStream, uint uiMode);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlStreamClose(IntPtr pStream);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlStreamGetStreamSize(IntPtr pStream);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern ulong hlStreamGetStreamSizeEx(IntPtr pStream);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlStreamGetStreamPointer(IntPtr pStream);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern ulong hlStreamGetStreamPointerEx(IntPtr pStream);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlStreamSeek(IntPtr pStream, long iOffset, HLSeekMode eSeekMode);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern ulong hlStreamSeekEx(IntPtr pStream, long iOffset, HLSeekMode eSeekMode);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlStreamReadChar(IntPtr pStream, out char pChar);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlStreamRead(IntPtr pStream, IntPtr lpData, uint uiBytes);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlStreamWriteChar(IntPtr pStream, char iChar);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlStreamWrite(IntPtr pStream, IntPtr lpData, uint uiBytes);
+
+ //
+ // Package
+ //
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlBindPackage(uint uiPackage);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern HLPackageType hlGetPackageTypeFromName([MarshalAs(UnmanagedType.LPStr)]string lpName);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern HLPackageType hlGetPackageTypeFromMemory(IntPtr lpBuffer, uint uiBufferSize);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern HLPackageType hlGetPackageTypeFromStream(IntPtr pStream);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlCreatePackage(HLPackageType ePackageType, out uint uiPackage);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlDeletePackage(uint uiPackage);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern HLPackageType hlPackageGetType();
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlPackageGetExtension();
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlPackageGetDescription();
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageGetOpened();
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageOpenFile([MarshalAs(UnmanagedType.LPStr)]string lpFileName, uint uiMode);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageOpenMemory(IntPtr lpData, uint uiBufferSize, uint uiMode);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageOpenProc(IntPtr pUserData, uint uiMode);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageOpenStream(IntPtr pStream, uint uiMode);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlPackageClose();
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageDefragment();
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlPackageGetRoot();
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlPackageGetAttributeCount();
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlPackageGetAttributeName(HLPackageAttribute eAttribute);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageGetAttribute(HLPackageAttribute eAttribute, out HLAttribute pAttribute);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern uint hlPackageGetItemAttributeCount();
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlPackageGetItemAttributeName(HLPackageAttribute eAttribute);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageGetItemAttribute(IntPtr pItem, HLPackageAttribute eAttribute, out HLAttribute pAttribute);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageGetExtractable(IntPtr pItem, [MarshalAs(UnmanagedType.U1)]out bool pExtractable);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageGetFileSize(IntPtr pItem, out uint pSize);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageGetFileSizeOnDisk(IntPtr pItem, out uint pSize);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlPackageCreateStream(IntPtr pItem, out IntPtr pStream);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlPackageReleaseStream(IntPtr pStream);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern IntPtr hlNCFFileGetRootPath();
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ public static extern void hlNCFFileSetRootPath([MarshalAs(UnmanagedType.LPStr)]string lpRootPath);
+
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlWADFileGetImageSizePaletted(IntPtr pItem, out uint uiPaletteDataSize, out uint uiPixelDataSize);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlWADFileGetImageDataPaletted(IntPtr pItemm, out uint uiWidth, out uint uiHeight, out IntPtr lpPaletteData, out IntPtr lpPixelData);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlWADFileGetImageSize(IntPtr pItem, out uint uiPixelDataSize);
+ [DllImport("HLLib.x64.dll", CallingConvention = CallingConvention.Cdecl, CharSet = CharSet.Ansi)]
+ [return: MarshalAs(UnmanagedType.U1)]
+ public static extern bool hlWADFileGetImageData(IntPtr pItem, out uint uiWidth, out uint uiHeight, out IntPtr lpPixelData);
+ }
+ #endregion
+}
diff --git a/BurnOutSharp/External/HLLib/HLExtract.Net/Program.cs b/BurnOutSharp/External/HLLib/HLExtract.Net/Program.cs
new file mode 100644
index 00000000..9be92f8e
--- /dev/null
+++ b/BurnOutSharp/External/HLLib/HLExtract.Net/Program.cs
@@ -0,0 +1,1158 @@
+/*
+ * HLExtract.Net
+ * Copyright (C) 2008-2010 Ryan Gregg
+
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ */
+
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Runtime.InteropServices;
+
+namespace HLExtract.Net
+{
+ public class HLExtractProgram
+ {
+ static bool bSilent = false;
+ static bool bPause = true;
+ static string sDestination = string.Empty;
+
+ public static int Process(string[] args)
+ {
+ // Arguments.
+ string sPackage = string.Empty;
+ List Commands = new List();
+ string sNCFRootPath = string.Empty;
+
+ bool bFileMapping = false;
+ bool bQuickFileMapping = false;
+ bool bVolatileAccess = false;
+ bool bWriteAccess = false;
+ bool bOverwriteFiles = true;
+
+ // Package stuff.
+ HLLib.HLPackageType ePackageType = HLLib.HLPackageType.HL_PACKAGE_NONE;
+ uint uiPackage = HLLib.HL_ID_INVALID;
+ uint uiMode = (uint)HLLib.HLFileMode.HL_MODE_INVALID;
+
+ if(HLLib.hlGetUnsignedInteger(HLLib.HLOption.HL_VERSION) < HLLib.HL_VERSION_NUMBER)
+ {
+ //Console.WriteLine("Wrong HLLib version: v{0}.", HLLib.hlGetString(HLLib.HLOption.HL_VERSION));
+ return 1;
+ }
+
+ // Process switches.
+ if(args.Length == 1)
+ {
+ sPackage = args[0];
+ }
+ else
+ {
+ for(int i = 0; i < args.Length; i++)
+ {
+ if(string.Equals(args[i], "-p", StringComparison.CurrentCultureIgnoreCase) || string.Equals(args[i], "--package", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if(sPackage.Length == 0 && i + 1 < args.Length)
+ {
+ sPackage = args[++i];
+ }
+ else
+ {
+ PrintUsage();
+ return 2;
+ }
+ }
+ else if(string.Equals(args[i], "-d", StringComparison.CurrentCultureIgnoreCase) || string.Equals(args[i], "--dest", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if(sDestination.Length == 0 && i + 1 < args.Length)
+ {
+ sDestination = args[++i];
+ }
+ else
+ {
+ PrintUsage();
+ return 2;
+ }
+ }
+ else if(string.Equals(args[i], "-x", StringComparison.CurrentCultureIgnoreCase) || string.Equals(args[i], "--execute", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if(sDestination.Length == 0 && i + 1 < args.Length)
+ {
+ Commands.Add(args[++i]);
+ }
+ else
+ {
+ PrintUsage();
+ return 2;
+ }
+ }
+ else if(string.Equals(args[i], "-n", StringComparison.CurrentCultureIgnoreCase) || string.Equals(args[i], "--ncfroot", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if(sNCFRootPath.Length == 0 && i + 1 < args.Length)
+ {
+ sNCFRootPath = args[++i];
+ }
+ else
+ {
+ PrintUsage();
+ return 2;
+ }
+ }
+ else if(string.Equals(args[i], "-s", StringComparison.CurrentCultureIgnoreCase) || string.Equals(args[i], "--silent", StringComparison.CurrentCultureIgnoreCase))
+ {
+ bSilent = true;
+ }
+ else if(string.Equals(args[i], "-u", StringComparison.CurrentCultureIgnoreCase) || string.Equals(args[i], "--no-pause", StringComparison.CurrentCultureIgnoreCase))
+ {
+ bPause = false;
+ }
+ else if(string.Equals(args[i], "-m", StringComparison.CurrentCultureIgnoreCase) || string.Equals(args[i], "--filemapping", StringComparison.CurrentCultureIgnoreCase))
+ {
+ bFileMapping = true;
+ }
+ else if(string.Equals(args[i], "-q", StringComparison.CurrentCultureIgnoreCase) || string.Equals(args[i], "--quick-filemapping", StringComparison.CurrentCultureIgnoreCase))
+ {
+ bFileMapping = true;
+ bQuickFileMapping = true;
+ }
+ else if(string.Equals(args[i], "-v", StringComparison.CurrentCultureIgnoreCase) || string.Equals(args[i], "--volatile", StringComparison.CurrentCultureIgnoreCase))
+ {
+ bVolatileAccess = true;
+ }
+ else if(string.Equals(args[i], "-w", StringComparison.CurrentCultureIgnoreCase) || string.Equals(args[i], "--write", StringComparison.CurrentCultureIgnoreCase))
+ {
+ bWriteAccess = true;
+ }
+ else if(string.Equals(args[i], "-o", StringComparison.CurrentCultureIgnoreCase) || string.Equals(args[i], "--no-overwrite", StringComparison.CurrentCultureIgnoreCase))
+ {
+ bOverwriteFiles = false;
+ }
+ else
+ {
+ PrintUsage();
+ return 2;
+ }
+ }
+ }
+
+ // Make sure we have something to do.
+ if(sPackage.Length == 0)
+ {
+ PrintUsage();
+ return 2;
+ }
+
+ // If the destination directory is not specified, make it the input directory.
+ if(sDestination.Length == 0)
+ {
+ int iIndex = sPackage.LastIndexOfAny(new char[]{'\\', '/'});
+ if(iIndex != -1)
+ {
+ sDestination = sPackage.Substring(0, iIndex + 1);
+ }
+ }
+
+ HLLib.hlInitialize();
+
+ // Keep the delegates alive so they don't get garbage collected.
+ HLLib.HLExtractItemStartProc HLExtractItemStartProc = new HLLib.HLExtractItemStartProc(ExtractItemStartCallback);
+ HLLib.HLExtractItemEndProc HLExtractItemEndProc = new HLLib.HLExtractItemEndProc(ExtractItemEndCallback);
+ HLLib.HLExtractFileProgressProc HLExtractFileProgressProc = new HLLib.HLExtractFileProgressProc(FileProgressCallback);
+ HLLib.HLValidateFileProgressProc HLValidateFileProgressProc = new HLLib.HLValidateFileProgressProc(FileProgressCallback);
+ HLLib.HLDefragmentFileProgressExProc HLDefragmentFileProgressProc = new HLLib.HLDefragmentFileProgressExProc(DefragmentProgressCallback);
+
+ HLLib.hlSetBoolean(HLLib.HLOption.HL_OVERWRITE_FILES, bOverwriteFiles);
+ HLLib.hlSetVoid(HLLib.HLOption.HL_PROC_EXTRACT_ITEM_START, Marshal.GetFunctionPointerForDelegate(HLExtractItemStartProc));
+ HLLib.hlSetVoid(HLLib.HLOption.HL_PROC_EXTRACT_ITEM_END, Marshal.GetFunctionPointerForDelegate(HLExtractItemEndProc));
+ HLLib.hlSetVoid(HLLib.HLOption.HL_PROC_EXTRACT_FILE_PROGRESS, Marshal.GetFunctionPointerForDelegate(HLExtractFileProgressProc));
+ HLLib.hlSetVoid(HLLib.HLOption.HL_PROC_VALIDATE_FILE_PROGRESS, Marshal.GetFunctionPointerForDelegate(HLValidateFileProgressProc));
+ HLLib.hlSetVoid(HLLib.HLOption.HL_PROC_DEFRAGMENT_PROGRESS_EX, Marshal.GetFunctionPointerForDelegate(HLDefragmentFileProgressProc));
+
+ // Get the package type from the filename extension.
+ ePackageType = HLLib.hlGetPackageTypeFromName(sPackage);
+
+ // If the above fails, try getting the package type from the data at the start of the file.
+ if(ePackageType == HLLib.HLPackageType.HL_PACKAGE_NONE && File.Exists(sPackage))
+ {
+ FileStream Reader = null;
+ try
+ {
+ byte[] lpBuffer = new byte[HLLib.HL_DEFAULT_PACKAGE_TEST_BUFFER_SIZE];
+ Reader = new FileStream(sPackage, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
+ int iBytesRead = Reader.Read(lpBuffer, 0, lpBuffer.Length);
+ if(iBytesRead > 0)
+ {
+ IntPtr lpBytesRead = Marshal.AllocHGlobal(iBytesRead);
+ try
+ {
+ Marshal.Copy(lpBuffer, 0, lpBytesRead, iBytesRead);
+ ePackageType = HLLib.hlGetPackageTypeFromMemory(lpBytesRead, (uint)iBytesRead);
+ }
+ finally
+ {
+ Marshal.FreeHGlobal(lpBytesRead);
+ }
+ }
+ }
+ finally
+ {
+ if(Reader != null)
+ {
+ Reader.Close();
+ }
+ }
+ }
+
+ if(ePackageType == HLLib.HLPackageType.HL_PACKAGE_NONE)
+ {
+ //Console.WriteLine("Error loading {0}:", sPackage);
+ //Console.WriteLine("Unsupported package type.");
+
+ HLLib.hlShutdown();
+ Pause();
+ return 3;
+ }
+
+ // Create a package element, the element is allocated by the library and cleaned
+ // up by the library. An ID is generated which must be bound to apply operations
+ // to the package.
+ if(!HLLib.hlCreatePackage(ePackageType, out uiPackage))
+ {
+ //Console.WriteLine("Error loading {0}:", sPackage);
+ //Console.WriteLine(HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
+
+ HLLib. hlShutdown();
+ Pause();
+ return 3;
+ }
+
+ HLLib.hlBindPackage(uiPackage);
+
+ uiMode = (uint)HLLib.HLFileMode.HL_MODE_READ;
+ uiMode |= !bFileMapping ? (uint)HLLib.HLFileMode.HL_MODE_NO_FILEMAPPING : 0;
+ uiMode |= bQuickFileMapping ? (uint)HLLib.HLFileMode.HL_MODE_QUICK_FILEMAPPING : 0;
+ uiMode |= bVolatileAccess ? (uint)HLLib.HLFileMode.HL_MODE_VOLATILE : 0;
+ uiMode |= bWriteAccess ? (uint)HLLib.HLFileMode.HL_MODE_WRITE : 0;
+
+ // Open the package.
+ // Of the above modes, only HL_MODE_READ is required. HL_MODE_WRITE is present
+ // only for future use. File mapping is recommended as an efficient way to load
+ // packages. Quick file mapping maps the entire file (instead of bits as they are
+ // needed) and thus should only be used in Windows 2000 and up (older versions of
+ // Windows have poor virtual memory management which means large files won't be able
+ // to find a continues block and will fail to load). Volatile access allows HLLib
+ // to share files with other applications that have those file open for writing.
+ // This is useful for, say, loading .gcf files while Steam is running.
+ if(!HLLib.hlPackageOpenFile(sPackage, uiMode))
+ {
+ //Console.WriteLine("Error loading {0}:", sPackage);
+ //Console.WriteLine(HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
+
+ HLLib. hlShutdown();
+ Pause();
+ return 3;
+ }
+
+ // If we have a .ncf file, the package file data is stored externally. In order to
+ // validate the file data etc., HLLib needs to know where to look. Tell it where.
+ if(ePackageType == HLLib.HLPackageType.HL_PACKAGE_NCF && sNCFRootPath.Length > 0)
+ {
+ HLLib.hlNCFFileSetRootPath(sNCFRootPath);
+ }
+
+ if(!bSilent)
+ //Console.WriteLine("{0} opened.", sPackage);
+
+ // Interactive console mode.
+ EnterConsole(uiPackage, Commands);
+
+ // Close the package.
+ HLLib.hlPackageClose();
+
+ if(!bSilent)
+ //Console.WriteLine("{0} closed.", sPackage);
+
+ // Free up the allocated memory.
+ HLLib.hlDeletePackage(uiPackage);
+
+ HLLib.hlShutdown();
+
+ return 0;
+ }
+
+ static void Pause()
+ {
+ if(bPause)
+ {
+ //Console.Write("Press any key to continue . . . ");
+ //Console.ReadKey(true);
+ }
+ }
+
+ static void PrintUsage()
+ {
+ System.Reflection.AssemblyName Name = System.Reflection.Assembly.GetExecutingAssembly().GetName();
+
+ //Console.WriteLine("HLExtract.Net v{0}.{1}.{2} using HLLib v{3}", Name.Version.Major, Name.Version.Minor, Name.Version.Build, HLLib.hlGetString(HLLib.HLOption.HL_VERSION));
+ //Console.WriteLine();
+ //Console.WriteLine("Correct HLExtract.Net usage:");
+ //Console.WriteLine(" -p (Package to load.)");
+ //Console.WriteLine(" -d (Destination extraction directory.)");
+ //Console.WriteLine(" -x (Execute console command.)");
+ //Console.WriteLine(" -s (Silent mode.)");
+ //Console.WriteLine(" -u (Don't pause on error..)");
+ //Console.WriteLine(" -m (Use file mapping.)");
+ //Console.WriteLine(" -q (Use quick file mapping.)");
+ //Console.WriteLine(" -v (Allow volatile access.)");
+ //Console.WriteLine(" -w (Allow write access.)");
+ //Console.WriteLine(" -o (Don't overwrite files.)");
+ //Console.WriteLine(" -n (NCF file's root path.)");
+ //Console.WriteLine();
+ //Console.WriteLine("Example HLExtract.Net usage:");
+ //Console.WriteLine("HLExtract.Net.exe -p \"C:\\half-life.gcf\" -d \"C:\\backup\"");
+ //Console.WriteLine("HLExtract.Net.exe -p \"C:\\half-life.gcf\" -m -v");
+ //Console.WriteLine("HLExtract.Net.exe -p \"C:\\half-life.gcf\" -w -x defragment -x exit");
+ //Console.WriteLine();
+ //Console.WriteLine("Batching HLExtract.Net:");
+ //Console.WriteLine("for %%F in (*.gcf) do HLExtract.Net.exe -p \"%%F\" -u -v -x \"info .\" -x exit");
+ //Console.WriteLine("for %%F in (*.gcf) do HLExtract.Net.exe -p \"%%F\" -s -u -x \"validate .\" -x exit");
+ //Console.WriteLine("for %%F in (*.gcf) do HLExtract.Net.exe -p \"%%F\" -s -u -w -x defragment -x exit");
+
+ Pause();
+ }
+
+ static readonly uint MAX_PATH_SIZE = 512;
+
+ static string GetPath(IntPtr pItem)
+ {
+ string sPath = string.Empty;
+ IntPtr lpPath = IntPtr.Zero;
+ try
+ {
+ lpPath = Marshal.AllocHGlobal((int)MAX_PATH_SIZE);
+ HLLib.hlItemGetPath(pItem, lpPath, MAX_PATH_SIZE);
+ sPath = Marshal.PtrToStringAnsi(lpPath);
+ }
+ finally
+ {
+ if(lpPath != IntPtr.Zero)
+ {
+ Marshal.FreeHGlobal(lpPath);
+ }
+ }
+ return sPath;
+ }
+
+#region Progress Callbacks
+ static uint uiProgressLast;
+
+ static void ProgressStart()
+ {
+ uiProgressLast = 0;
+ //Console.Write("0%");
+ }
+
+ static void ProgressUpdate(UInt64 uiBytesDone, UInt64 uiBytesTotal)
+ {
+ if(!bSilent)
+ {
+ uint uiProgress = uiBytesTotal == 0 ? 100 : (uint)(uiBytesDone * 100 / uiBytesTotal);
+ while(uiProgress >= uiProgressLast + 10)
+ {
+ uiProgressLast += 10;
+ if(uiProgressLast == 100)
+ {
+ //Console.Write("100% ");
+ }
+ else if(uiProgressLast == 50)
+ {
+ //Console.Write("50%");
+ }
+ else
+ {
+ //Console.Write(".");
+ }
+ }
+ }
+ }
+
+ static void ExtractItemStartCallback(IntPtr pItem)
+ {
+ if(!bSilent)
+ {
+ if(HLLib.hlItemGetType(pItem) == HLLib.HLDirectoryItemType.HL_ITEM_FILE)
+ {
+ //Console.Write(" Extracting {0}: ", HLLib.hlItemGetName(pItem));
+ ProgressStart();
+ }
+ else
+ {
+ //Console.WriteLine(" Extracting {0}:", HLLib.hlItemGetName(pItem));
+ }
+ }
+ }
+
+ static void FileProgressCallback(IntPtr pFile, uint uiBytesExtracted, uint uiBytesTotal, ref bool pCancel)
+ {
+ ProgressUpdate((UInt64)uiBytesExtracted, (UInt64)uiBytesTotal);
+ }
+
+ static void ExtractItemEndCallback(IntPtr pItem, bool bSuccess)
+ {
+ if(bSuccess)
+ {
+ if(!bSilent)
+ {
+ uint uiSize = 0;
+ HLLib.hlItemGetSize(pItem, out uiSize);
+ if(HLLib.hlItemGetType(pItem) == HLLib.HLDirectoryItemType.HL_ITEM_FILE)
+ {
+ //Console.WriteLine("OK ({0} B)", uiSize);
+ }
+ else
+ {
+ //Console.WriteLine(" Done {0}: OK ({1} B)", HLLib.hlItemGetName(pItem), uiSize);
+ }
+ }
+ }
+ else
+ {
+ if(!bSilent)
+ {
+ if(HLLib.hlItemGetType(pItem) == HLLib.HLDirectoryItemType.HL_ITEM_FILE)
+ {
+ //Console.WriteLine("Errored");
+ //Console.WriteLine(" {0}", HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
+ }
+ else
+ {
+ //Console.WriteLine(" Done {0}: Errored", HLLib.hlItemGetName(pItem));
+ }
+ }
+ else
+ {
+ if(HLLib.hlItemGetType(pItem) == HLLib.HLDirectoryItemType.HL_ITEM_FILE)
+ {
+ //Console.WriteLine(" Error extracting {0}:", GetPath(pItem));
+ //Console.WriteLine(" {0}", HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
+ }
+ else
+ {
+ //Console.WriteLine(" Error extracting {0}.", GetPath(pItem));
+ }
+ }
+ }
+ }
+
+ static void DefragmentProgressCallback(IntPtr pFile, uint uiFilesDefragmented, uint uiFilesTotal, UInt64 uiBytesDefragmented, UInt64 uiBytesTotal, ref bool pCancel)
+ {
+ ProgressUpdate(uiBytesDefragmented, uiBytesTotal);
+ }
+#endregion
+
+ static readonly string[] ValidationNames = new string[] { "OK", "Assumed OK", "Incomplete", "Corrupt", "Canceled", "Error" };
+
+ static string GetValidation(HLLib.HLValidation eValidation)
+ {
+ if(eValidation >= HLLib.HLValidation.HL_VALIDATES_OK && eValidation <= HLLib.HLValidation.HL_VALIDATES_ERROR)
+ {
+ return ValidationNames[(uint)eValidation];
+ }
+ return string.Empty;
+ }
+
+ static HLLib.HLValidation Validate(IntPtr pItem)
+ {
+ HLLib.HLValidation eValidation = HLLib.HLValidation.HL_VALIDATES_OK, eTest;
+
+ switch(HLLib.hlItemGetType(pItem))
+ {
+ case HLLib.HLDirectoryItemType.HL_ITEM_FOLDER:
+ if(!bSilent)
+ {
+ //Console.WriteLine(" Validating {0}:", HLLib.hlItemGetName(pItem));
+ }
+
+ uint uiItemCount = HLLib.hlFolderGetCount(pItem);
+ for(uint i = 0; i < uiItemCount; i++)
+ {
+ eTest = Validate(HLLib.hlFolderGetItem(pItem, i));
+ if(eTest > eValidation)
+ {
+ eValidation = eTest;
+ }
+ }
+
+ if(!bSilent)
+ {
+ //Console.WriteLine(" Done {0}: {1}", HLLib.hlItemGetName(pItem), GetValidation(eValidation));
+ }
+ break;
+ case HLLib.HLDirectoryItemType.HL_ITEM_FILE:
+ if(!bSilent)
+ {
+ //Console.Write(" Validating {0}: ", HLLib.hlItemGetName(pItem));
+ ProgressStart();
+ }
+
+ eValidation = HLLib.hlFileGetValidation(pItem);
+
+ if(bSilent)
+ {
+ switch(eValidation)
+ {
+ case HLLib.HLValidation.HL_VALIDATES_INCOMPLETE:
+ case HLLib.HLValidation.HL_VALIDATES_CORRUPT:
+ //Console.WriteLine(" Validating {0}: {1}", GetPath(pItem), GetValidation(eValidation));
+ break;
+ }
+ }
+ else
+ {
+ //Console.WriteLine(GetValidation(eValidation));
+ }
+ break;
+ }
+
+ return eValidation;
+ }
+
+ static void EnterConsole(uint uiPackage, List Commands)
+ {
+ IntPtr pItem = HLLib.hlPackageGetRoot();
+
+ while(true)
+ {
+ string sLine = null;
+ if(Commands.Count > 0)
+ {
+ sLine = Commands[0].Trim().Trim('\'');
+
+ //Console.WriteLine("{0}>{1}", HLLib.hlItemGetName(pItem), sLine);
+ Commands.RemoveAt(0);
+ }
+ else
+ {
+ // Command prompt.
+ //Console.Write("{0}>", HLLib.hlItemGetName(pItem));
+
+ // Get and parse line.
+ //sLine = Console.ReadLine().Trim();
+ }
+ if(sLine == null)
+ {
+ break;
+ }
+
+ int iIndex;
+ for(iIndex = 0; iIndex < sLine.Length; iIndex++)
+ {
+ if(!Char.IsLetter(sLine[iIndex]))
+ {
+ break;
+ }
+ }
+
+ string sCommand, sArgument;
+ if(iIndex == sLine.Length)
+ {
+ sCommand = sLine;
+ sArgument = string.Empty;
+ }
+ else
+ {
+ sCommand = sLine.Substring(0, iIndex).TrimEnd();
+ sArgument = sLine.Substring(iIndex).TrimStart();
+ }
+
+ // Cycle through commands.
+
+ //
+ // Directory listing.
+ // Good example of CDirectoryItem::GetType().
+ //
+ if(String.Equals(sCommand, "dir", StringComparison.CurrentCultureIgnoreCase))
+ {
+ uint uiItemCount = HLLib.hlFolderGetCount(pItem);
+ uint uiFolderCount = 0, uiFileCount = 0;
+
+ //Console.WriteLine("Directory of {0}:", GetPath(pItem));
+
+ //Console.WriteLine();
+
+ if(sArgument.Length == 0)
+ {
+ // List all items in the current folder.
+ for(uint i = 0; i < uiItemCount; i++)
+ {
+ IntPtr pSubItem = HLLib.hlFolderGetItem(pItem, i);
+ if(HLLib.hlItemGetType(pSubItem) == HLLib.HLDirectoryItemType.HL_ITEM_FOLDER)
+ {
+ uiFolderCount++;
+ //Console.WriteLine(" <{0}>", HLLib.hlItemGetName(pSubItem));
+ }
+ else if(HLLib.hlItemGetType(pSubItem) == HLLib.HLDirectoryItemType.HL_ITEM_FILE)
+ {
+ uiFileCount++;
+ //Console.WriteLine(" {0}", HLLib.hlItemGetName(pSubItem));
+ }
+ }
+ }
+ else
+ {
+ IntPtr pSubItem = HLLib.hlFolderFindFirst(pItem, sArgument, HLLib.HLFindType.HL_FIND_ALL | HLLib.HLFindType.HL_FIND_NO_RECURSE);
+ while(pSubItem != IntPtr.Zero)
+ {
+ if(HLLib.hlItemGetType(pSubItem) == HLLib.HLDirectoryItemType.HL_ITEM_FOLDER)
+ {
+ uiFolderCount++;
+ //Console.WriteLine(" <{0}>", HLLib.hlItemGetName(pSubItem));
+ }
+ else if(HLLib.hlItemGetType(pSubItem) == HLLib.HLDirectoryItemType.HL_ITEM_FILE)
+ {
+ uiFileCount++;
+ //Console.WriteLine(" {0}", HLLib.hlItemGetName(pSubItem));
+ }
+
+ pSubItem = HLLib.hlFolderFindNext(pItem, pSubItem, sArgument, HLLib.HLFindType.HL_FIND_ALL | HLLib.HLFindType.HL_FIND_NO_RECURSE);
+ }
+ }
+
+ //Console.WriteLine();
+
+ // Could also have used hlFolderGetFolderCount() and
+ // hlFolderGetFileCount().
+
+ //Console.WriteLine("Summary:");
+ //Console.WriteLine();
+ //Console.WriteLine(" {0} Folder{1}.", uiFolderCount, uiFolderCount != 1 ? "s" : "");
+ //Console.WriteLine(" {0} File{1}.", uiFileCount, uiFileCount != 1 ? "s" : "");
+ //Console.WriteLine();
+ }
+ //
+ // Change directory.
+ // Good example of CDirectoryFolder::GetParent() and item casting.
+ //
+ else if(String.Equals(sCommand, "cd", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if(sArgument.Length == 0)
+ {
+ //Console.WriteLine("No argument for command cd supplied.");
+ }
+ else
+ {
+ if(String.Equals(sArgument, ".", StringComparison.CurrentCultureIgnoreCase))
+ {
+
+ }
+ else if(String.Equals(sArgument, "..", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if(HLLib.hlItemGetParent(pItem) != IntPtr.Zero)
+ {
+ pItem = HLLib.hlItemGetParent(pItem);
+ }
+ else
+ {
+ //Console.WriteLine("Folder does not have a parent.");
+ }
+ }
+ else
+ {
+ bool bFound = false;
+ uint uiItemCount = HLLib.hlFolderGetCount(pItem);
+ for(uint i = 0; i < uiItemCount; i++)
+ {
+ IntPtr pSubItem = HLLib.hlFolderGetItem(pItem, i);
+ if(HLLib.hlItemGetType(pSubItem) == HLLib.HLDirectoryItemType.HL_ITEM_FOLDER && String.Equals(sArgument, HLLib.hlItemGetName(pSubItem), StringComparison.CurrentCultureIgnoreCase))
+ {
+ bFound = true;
+ pItem = pSubItem;
+ break;
+ }
+ }
+
+ if(!bFound)
+ {
+ //Console.WriteLine("{0} not found.", sArgument);
+ }
+ }
+ }
+ }
+ //
+ // Go to the root folder.
+ //
+ else if(String.Equals(sCommand, "root", StringComparison.CurrentCultureIgnoreCase))
+ {
+ pItem = HLLib.hlPackageGetRoot();
+ }
+ //
+ // Item information.
+ // Good example of CPackageUtility helper functions.
+ //
+ else if(String.Equals(sCommand, "info", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if(sArgument.Length == 0)
+ {
+ //Console.WriteLine("No argument for command info supplied.");
+ }
+ else
+ {
+ IntPtr pSubItem = HLLib.hlFolderGetItemByPath(pItem, sArgument, HLLib.HLFindType.HL_FIND_ALL);
+
+ if(pSubItem != IntPtr.Zero)
+ {
+ //Console.WriteLine("Information for {0}:", GetPath(pSubItem));
+ //Console.WriteLine();
+
+ switch(HLLib.hlItemGetType(pSubItem))
+ {
+ case HLLib.HLDirectoryItemType.HL_ITEM_FOLDER:
+ //Console.WriteLine(" Type: Folder");
+ //Console.WriteLine(" Size: {0} B", HLLib.hlFolderGetSizeEx(pSubItem, true));
+ //Console.WriteLine(" Size On Disk: {0} B", HLLib.hlFolderGetSizeOnDiskEx(pSubItem, true));
+ //Console.WriteLine(" Folders: {0}", HLLib.hlFolderGetFolderCount(pSubItem, true));
+ //Console.WriteLine(" Files: {0}", HLLib.hlFolderGetFileCount(pSubItem, true));
+ break;
+ case HLLib.HLDirectoryItemType.HL_ITEM_FILE:
+ //Console.WriteLine(" Type: File");
+ //Console.WriteLine(" Extractable: {0}", HLLib.hlFileGetExtractable(pSubItem) != 0 ? "True" : "False");
+ ////Console.WriteLine(" Validates: {0}", HLLib.hlFileGetValidates(pSubItem) ? "True" : "False");
+ //Console.WriteLine(" Size: {0} B", HLLib.hlFileGetSize(pSubItem));
+ //Console.WriteLine(" Size On Disk: {0} B", HLLib.hlFileGetSizeOnDisk(pSubItem));
+ break;
+ }
+
+ uint uiAttributeCount = HLLib.hlPackageGetItemAttributeCount();
+ for(uint i = 0; i < uiAttributeCount; i++)
+ {
+ HLLib.HLAttribute Attribute;
+ if(HLLib.hlPackageGetItemAttribute(pSubItem, (HLLib.HLPackageAttribute)i, out Attribute))
+ {
+ if(Attribute.eAttributeType != HLLib.HLAttributeType.HL_ATTRIBUTE_INVALID)
+ {
+ //Console.WriteLine(" {0}: {1}", Attribute.GetName(), Attribute.ToString());
+ }
+ }
+ }
+
+ //Console.WriteLine();
+ }
+ else
+ {
+ //Console.WriteLine("{0} not found.", sArgument);
+ }
+ }
+ }
+ //
+ // Extract item.
+ // Good example of CPackageUtility extract functions.
+ //
+ else if(String.Equals(sCommand, "extract", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if(sArgument.Length == 0)
+ {
+ //Console.WriteLine("No argument for command extract supplied.");
+ }
+ else
+ {
+ IntPtr pSubItem;
+ if(String.Equals(sArgument, ".", StringComparison.CurrentCultureIgnoreCase))
+ {
+ pSubItem = pItem;
+ }
+ else
+ {
+ pSubItem = HLLib.hlFolderGetItemByName(pItem, sArgument, HLLib.HLFindType.HL_FIND_ALL);
+ }
+
+ if(pSubItem != IntPtr.Zero)
+ {
+ // Extract the item.
+ // Item is extracted to cDestination\Item->GetName().
+ if(!bSilent)
+ {
+ //Console.WriteLine("Extracting {0}...", HLLib.hlItemGetName(pSubItem));
+ //Console.WriteLine();
+ }
+
+ HLLib.hlItemExtract(pSubItem, sDestination);
+
+ if(!bSilent)
+ {
+ //Console.WriteLine("");
+ //Console.WriteLine("Done.");
+ }
+ }
+ else
+ {
+ //Console.WriteLine("{0} not found.", sArgument);
+ }
+ }
+ }
+ //
+ // Validate item.
+ // Validates the checksums of each item.
+ //
+ else if(String.Equals(sCommand, "validate", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if(sArgument.Length == 0)
+ {
+ //Console.WriteLine("No argument for command extract supplied.");
+ }
+ else
+ {
+ IntPtr pSubItem;
+ if(String.Equals(sArgument, ".", StringComparison.CurrentCultureIgnoreCase))
+ {
+ pSubItem = pItem;
+ }
+ else
+ {
+ pSubItem = HLLib.hlFolderGetItemByName(pItem, sArgument, HLLib.HLFindType.HL_FIND_ALL);
+ }
+
+ if(pSubItem != IntPtr.Zero)
+ {
+ if(!bSilent)
+ {
+ //Console.WriteLine("Validating {0}...", HLLib.hlItemGetName(pSubItem));
+ //Console.WriteLine();
+ }
+
+ Validate(pSubItem);
+
+ if(!bSilent)
+ {
+ //Console.WriteLine();
+ //Console.WriteLine("Done.");
+ }
+ }
+ else
+ {
+ //Console.WriteLine("{0} not found.", sArgument);
+ }
+ }
+ }
+ //
+ // Defragment package.
+ // Validates the checksums of each item.
+ //
+ else if(String.Equals(sCommand, "defragment", StringComparison.CurrentCultureIgnoreCase))
+ {
+ bool bForceDefragment = false;
+ if(sArgument.Length != 0)
+ {
+ try
+ {
+ bForceDefragment = Convert.ToBoolean(sArgument);
+ }
+ catch
+ {
+ }
+ }
+
+ if(!bSilent)
+ {
+ //Console.WriteLine("Defragmenting...");
+ //Console.WriteLine();
+ }
+
+ HLLib.hlSetBoolean(HLLib.HLOption.HL_FORCE_DEFRAGMENT, bForceDefragment);
+
+ //Console.Write(" Progress: ");
+ ProgressStart();
+ if(!HLLib.hlPackageDefragment())
+ {
+ //Console.Write(" {0}", HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
+ }
+
+ if(!bSilent)
+ {
+ //Console.WriteLine();
+
+ //Console.WriteLine();
+ //Console.WriteLine("Done.");
+ }
+ }
+ //
+ // Find items.
+ // Good example of recursive directory navigation (Search() function).
+ //
+ else if(String.Equals(sCommand, "find", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if(sArgument.Length == 0)
+ {
+ //Console.WriteLine("No argument for command find supplied.");
+ }
+ else
+ {
+ // Search for the requested items.
+ if(!bSilent)
+ {
+ //Console.WriteLine("Searching for {0}...", sArgument);
+ //Console.WriteLine();
+ }
+
+ uint uiFolderCount = 0, uiFileCount = 0;
+ IntPtr pSubItem = HLLib.hlFolderFindFirst(pItem, sArgument, HLLib.HLFindType.HL_FIND_ALL);
+ while(pSubItem != IntPtr.Zero)
+ {
+ switch(HLLib.hlItemGetType(pSubItem))
+ {
+ case HLLib.HLDirectoryItemType.HL_ITEM_FOLDER:
+ uiFolderCount++;
+
+ //Console.WriteLine(" Found folder: {0}", GetPath(pSubItem));
+ break;
+ case HLLib.HLDirectoryItemType.HL_ITEM_FILE:
+ uiFileCount++;
+
+ //Console.WriteLine(" Found file: {0}", GetPath(pSubItem));
+ break;
+ }
+
+ pSubItem = HLLib.hlFolderFindNext(pItem, pSubItem, sArgument, HLLib.HLFindType.HL_FIND_ALL);
+ }
+
+ if(!bSilent)
+ {
+ if(uiFolderCount != 0 || uiFileCount != 0)
+ {
+ //Console.WriteLine();
+ }
+
+ //Console.WriteLine(" {0} folder{1} and {2} file{3} found.", uiFolderCount, uiFolderCount != 1 ? "s" : "", uiFileCount, uiFileCount != 1 ? "s" : "");
+ //Console.WriteLine();
+ }
+ }
+ }
+ //
+ // Type files.
+ // Good example of reading files into memory.
+ //
+ else if(String.Equals(sCommand, "type", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if(sArgument.Length == 0)
+ {
+ //Console.WriteLine("No argument for command type supplied.");
+ }
+ else
+ {
+ IntPtr pSubItem = HLLib.hlFolderGetItemByName(pItem, sArgument, HLLib.HLFindType.HL_FIND_FILES);
+
+ if(pSubItem != IntPtr.Zero)
+ {
+ if(!bSilent)
+ {
+ //Console.WriteLine("Type for {0}:", GetPath(pSubItem));
+ //Console.WriteLine();
+ }
+
+ IntPtr pStream;
+ if(HLLib.hlFileCreateStream(pSubItem, out pStream))
+ {
+ if(HLLib.hlStreamOpen(pStream, (uint)HLLib.HLFileMode.HL_MODE_READ))
+ {
+ char iChar;
+ while(HLLib.hlStreamReadChar(pStream, out iChar))
+ {
+ if((iChar >= ' ' && iChar <= '~') || iChar == '\n' || iChar == '\t')
+ {
+ //Console.Write(iChar);
+ }
+ }
+
+ HLLib.hlStreamClose(pStream);
+ }
+ else
+ {
+ //Console.WriteLine("Error typing {0}:", HLLib.hlItemGetName(pSubItem));
+ //Console.WriteLine(HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
+ }
+
+ HLLib.hlFileReleaseStream(pSubItem, pStream);
+ }
+ else
+ {
+ //Console.WriteLine("Error typing {0}:", HLLib.hlItemGetName(pSubItem));
+ //Console.WriteLine(HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
+ }
+
+ if(!bSilent)
+ {
+ //Console.WriteLine();
+ //Console.WriteLine("Done.");
+ }
+ }
+ else
+ {
+ //Console.WriteLine("{0} not found.", sArgument);
+ }
+ }
+ }
+ //
+ // Open item.
+ // Good example of opening packages inside packages.
+ //
+ else if(String.Equals(sCommand, "open", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if(sArgument.Length == 0)
+ {
+ //Console.WriteLine("No argument for command open supplied.");
+ }
+ else
+ {
+ IntPtr pSubItem = HLLib.hlFolderGetItemByName(pItem, sArgument, HLLib.HLFindType.HL_FIND_FILES);
+
+ if(pSubItem != IntPtr.Zero)
+ {
+ IntPtr pStream;
+ if(HLLib.hlFileCreateStream(pSubItem, out pStream))
+ {
+ if(HLLib.hlStreamOpen(pStream, (uint)HLLib.HLFileMode.HL_MODE_READ))
+ {
+ HLLib.HLPackageType ePackageType = HLLib.hlGetPackageTypeFromStream(pStream);
+
+ uint uiSubPackage;
+ if(HLLib.hlCreatePackage(ePackageType, out uiSubPackage))
+ {
+ HLLib.hlBindPackage(uiSubPackage);
+ if(HLLib.hlPackageOpenStream(pStream, (uint)HLLib.HLFileMode.HL_MODE_READ))
+ {
+ if(!bSilent)
+ //Console.WriteLine("{0} opened.", HLLib.hlItemGetName(pSubItem));
+
+ EnterConsole(uiSubPackage, Commands);
+
+ HLLib.hlPackageClose();
+
+ if (!bSilent)
+ {
+ //Console.WriteLine("{0} closed.", HLLib.hlItemGetName(pSubItem));
+ }
+ }
+ else
+ {
+ //Console.WriteLine("Error opening {0}:", HLLib.hlItemGetName(pSubItem));
+ //Console.WriteLine(HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
+ }
+
+ HLLib.hlDeletePackage(uiSubPackage);
+
+ HLLib.hlBindPackage(uiPackage);
+ }
+ else
+ {
+ //Console.WriteLine("Error opening {0}:", HLLib.hlItemGetName(pSubItem));
+ //Console.WriteLine(HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
+ }
+
+ HLLib.hlStreamClose(pStream);
+ }
+ else
+ {
+ //Console.WriteLine("Error opening {0}:", HLLib.hlItemGetName(pSubItem));
+ //Console.WriteLine(HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
+ }
+
+ HLLib.hlFileReleaseStream(pSubItem, pStream);
+ }
+ else
+ {
+ //Console.WriteLine("Error opening {0}:", HLLib.hlItemGetName(pSubItem));
+ //Console.WriteLine(HLLib.hlGetString(HLLib.HLOption.HL_ERROR_SHORT_FORMATED));
+ }
+ }
+ else
+ {
+ //Console.WriteLine("{0} not found.", sArgument);
+ }
+ }
+ }
+ //
+ // Clear screen.
+ //
+ else if(String.Equals(sCommand, "status", StringComparison.CurrentCultureIgnoreCase))
+ {
+ //Console.WriteLine("Total size: {0} B", HLLib.hlGetUnsignedLong(HLLib.HLOption.HL_PACKAGE_SIZE));
+ //Console.WriteLine("Total mapping allocations: {0}", HLLib.hlGetUnsignedInteger(HLLib.HLOption.HL_PACKAGE_TOTAL_ALLOCATIONS));
+ //Console.WriteLine("Total mapping memory allocated: {0} B", HLLib.hlGetUnsignedLong(HLLib.HLOption.HL_PACKAGE_TOTAL_MEMORY_ALLOCATED));
+ //Console.WriteLine("Total mapping memory used: {0} B", HLLib.hlGetUnsignedLong(HLLib.HLOption.HL_PACKAGE_TOTAL_MEMORY_USED));
+
+ uint uiAttributeCount = HLLib.hlPackageGetAttributeCount();
+ for(uint i = 0; i < uiAttributeCount; i++)
+ {
+ HLLib.HLAttribute Attribute;
+ if(HLLib.hlPackageGetAttribute((HLLib.HLPackageAttribute)i, out Attribute))
+ {
+ if(Attribute.eAttributeType != HLLib.HLAttributeType.HL_ATTRIBUTE_INVALID)
+ {
+ //Console.WriteLine("{0}: {1}", Attribute.GetName(), Attribute.ToString());
+ }
+ }
+ }
+ }
+ else if(String.Equals(sCommand, "exec", StringComparison.CurrentCultureIgnoreCase) || String.Equals(sCommand, "execute", StringComparison.CurrentCultureIgnoreCase))
+ {
+ if(sArgument.Length == 0)
+ {
+ //Console.WriteLine("No argument for command open supplied.");
+ }
+ else
+ {
+ string[] NewCommands = sArgument.Split(new char[] { '|' });
+ Commands.AddRange(NewCommands);
+ }
+ }
+ else if(String.Equals(sCommand, "cls", StringComparison.CurrentCultureIgnoreCase))
+ {
+ try
+ {
+ Console.Clear();
+ }
+ catch
+ {
+ }
+ }
+ else if(String.Equals(sCommand, "help", StringComparison.CurrentCultureIgnoreCase))
+ {
+ //Console.WriteLine("Valid commands:");
+ //Console.WriteLine();
+ //Console.WriteLine("dir (Directory list.)");
+ //Console.WriteLine("cd (Change directroy.)");
+ //Console.WriteLine("info - (Item information.)");
+ //Console.WriteLine("extract
- (Extract item.)");
+ //Console.WriteLine("validate
- (Validate item.)");
+ //Console.WriteLine("defragment [force] (Defragment package.)");
+ //Console.WriteLine("find (Find item.)");
+ //Console.WriteLine("type (Type a file.)");
+ //Console.WriteLine("open (Open a nested package.)");
+ //Console.WriteLine("root (Go to the root folder.)");
+ //Console.WriteLine("status (Package information.)");
+ //Console.WriteLine("execute |... (Execute 1 or more pipe delimited commands.)");
+ //Console.WriteLine("cls (Clear the screen.)");
+ //Console.WriteLine("help (Program help.)");
+ //Console.WriteLine("exit (Quit program.)");
+ //Console.WriteLine();
+ }
+ else if(String.Equals(sCommand, "exit", StringComparison.CurrentCultureIgnoreCase))
+ {
+ break;
+ }
+ else
+ {
+ //Console.WriteLine("Unkown command: {0}", sCommand);
+ }
+ }
+ }
+ }
+}
diff --git a/BurnOutSharp/External/StormLibSharp/MpqArchive.cs b/BurnOutSharp/External/StormLibSharp/MpqArchive.cs
new file mode 100644
index 00000000..4585dc50
--- /dev/null
+++ b/BurnOutSharp/External/StormLibSharp/MpqArchive.cs
@@ -0,0 +1,414 @@
+using StormLibSharp.Native;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Globalization;
+using System.IO;
+using System.IO.MemoryMappedFiles;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace StormLibSharp
+{
+ public class MpqArchive : IDisposable
+ {
+ private MpqArchiveSafeHandle _handle;
+ private List _openFiles = new List();
+ private FileAccess _accessType;
+ private List _compactCallbacks = new List();
+ private SFILE_COMPACT_CALLBACK _compactCallback;
+
+ #region Constructors / Factories
+ public MpqArchive(string filePath, FileAccess accessType)
+ {
+ _accessType = accessType;
+ SFileOpenArchiveFlags flags = SFileOpenArchiveFlags.TypeIsFile;
+ if (accessType == FileAccess.Read)
+ flags |= SFileOpenArchiveFlags.AccessReadOnly;
+ else
+ flags |= SFileOpenArchiveFlags.AccessReadWriteShare;
+
+ // constant 2 = SFILE_OPEN_HARD_DISK_FILE
+ if (!NativeMethods.SFileOpenArchive(filePath, 2, flags, out _handle))
+ throw new Win32Exception(); // Implicitly calls GetLastError
+ }
+
+ public MpqArchive(MemoryMappedFile file, FileAccess accessType)
+ {
+ _accessType = accessType;
+ string fileName = Win32Methods.GetFileNameOfMemoryMappedFile(file);
+ if (fileName == null)
+ throw new ArgumentException("Could not retrieve the name of the file to initialize.");
+
+ SFileOpenArchiveFlags flags = SFileOpenArchiveFlags.TypeIsMemoryMapped;
+ if (accessType == FileAccess.Read)
+ flags |= SFileOpenArchiveFlags.AccessReadOnly;
+ else
+ flags |= SFileOpenArchiveFlags.AccessReadWriteShare;
+
+ // constant 2 = SFILE_OPEN_HARD_DISK_FILE
+ if (!NativeMethods.SFileOpenArchive(fileName, 2, flags, out _handle))
+ throw new Win32Exception(); // Implicitly calls GetLastError
+ }
+
+ private MpqArchive(string filePath, MpqArchiveVersion version, MpqFileStreamAttributes listfileAttributes, MpqFileStreamAttributes attributesFileAttributes, int maxFileCount)
+ {
+ if (maxFileCount < 0)
+ throw new ArgumentException("maxFileCount");
+
+ SFileOpenArchiveFlags flags = SFileOpenArchiveFlags.TypeIsFile | SFileOpenArchiveFlags.AccessReadWriteShare;
+ flags |= (SFileOpenArchiveFlags)version;
+
+ //SFILE_CREATE_MPQ create = new SFILE_CREATE_MPQ()
+ //{
+ // cbSize = unchecked((uint)Marshal.SizeOf(typeof(SFILE_CREATE_MPQ))),
+ // dwMaxFileCount = unchecked((uint)maxFileCount),
+ // dwMpqVersion = (uint)version,
+ // dwFileFlags1 = (uint)listfileAttributes,
+ // dwFileFlags2 = (uint)attributesFileAttributes,
+ // dwStreamFlags = (uint)flags,
+ //};
+
+ //if (!NativeMethods.SFileCreateArchive2(filePath, ref create, out _handle))
+ // throw new Win32Exception();
+ if (!NativeMethods.SFileCreateArchive(filePath, (uint)flags, int.MaxValue, out _handle))
+ throw new Win32Exception();
+ }
+
+ public static MpqArchive CreateNew(string mpqPath, MpqArchiveVersion version)
+ {
+ return CreateNew(mpqPath, version, MpqFileStreamAttributes.None, MpqFileStreamAttributes.None, int.MaxValue);
+ }
+
+ public static MpqArchive CreateNew(string mpqPath, MpqArchiveVersion version, MpqFileStreamAttributes listfileAttributes,
+ MpqFileStreamAttributes attributesFileAttributes, int maxFileCount)
+ {
+ return new MpqArchive(mpqPath, version, listfileAttributes, attributesFileAttributes, maxFileCount);
+ }
+ #endregion
+
+ #region Properties
+ // TODO: Move to common location.
+ // This is a global setting, not per-archive setting.
+
+ //public int Locale
+ //{
+ // get
+ // {
+ // throw new NotImplementedException();
+ // }
+ // set
+ // {
+ // throw new NotImplementedException();
+ // }
+ //}
+
+ public long MaxFileCount
+ {
+ get
+ {
+ VerifyHandle();
+ return NativeMethods.SFileGetMaxFileCount(_handle);
+ }
+ set
+ {
+ if (value < 0 || value > uint.MaxValue)
+ throw new ArgumentException("value");
+ VerifyHandle();
+
+ if (!NativeMethods.SFileSetMaxFileCount(_handle, unchecked((uint)value)))
+ throw new Win32Exception();
+ }
+ }
+
+ private void VerifyHandle()
+ {
+ if (_handle == null || _handle.IsInvalid)
+ throw new ObjectDisposedException("MpqArchive");
+ }
+
+ public bool IsPatchedArchive
+ {
+ get
+ {
+ VerifyHandle();
+ return NativeMethods.SFileIsPatchedArchive(_handle);
+ }
+ }
+ #endregion
+
+ public void Flush()
+ {
+ VerifyHandle();
+ if (!NativeMethods.SFileFlushArchive(_handle))
+ throw new Win32Exception();
+ }
+
+ public int AddListFile(string listfileContents)
+ {
+ VerifyHandle();
+ return NativeMethods.SFileAddListFile(_handle, listfileContents);
+ }
+
+ public void AddFileFromDisk(string filePath, string archiveName)
+ {
+ VerifyHandle();
+
+ if (!NativeMethods.SFileAddFile(_handle, filePath, archiveName, 0))
+ throw new Win32Exception();
+ }
+
+ public void Compact(string listfile)
+ {
+ VerifyHandle();
+ if (!NativeMethods.SFileCompactArchive(_handle, listfile, false))
+ throw new Win32Exception();
+ }
+
+ private void _OnCompact(IntPtr pvUserData, uint dwWorkType, ulong bytesProcessed, ulong totalBytes)
+ {
+ MpqArchiveCompactingEventArgs args = new MpqArchiveCompactingEventArgs(dwWorkType, bytesProcessed, totalBytes);
+ OnCompacting(args);
+ }
+
+ protected virtual void OnCompacting(MpqArchiveCompactingEventArgs e)
+ {
+ foreach (var cb in _compactCallbacks)
+ {
+ cb(this, e);
+ }
+ }
+
+ public event MpqArchiveCompactingEventHandler Compacting
+ {
+ add
+ {
+ VerifyHandle();
+ _compactCallback = _OnCompact;
+ if (!NativeMethods.SFileSetCompactCallback(_handle, _compactCallback, IntPtr.Zero))
+ throw new Win32Exception();
+
+ _compactCallbacks.Add(value);
+ }
+ remove
+ {
+ _compactCallbacks.Remove(value);
+
+ VerifyHandle();
+ if (_compactCallbacks.Count == 0)
+ {
+ if (!NativeMethods.SFileSetCompactCallback(_handle, null, IntPtr.Zero))
+ {
+ // Don't do anything here. Remove shouldn't fail hard.
+ }
+ }
+ }
+ }
+
+ // TODO: Determine if SFileGetAttributes/SFileSetAttributes/SFileUpdateFileAttributes deserves a projection.
+ // It's unclear - these seem to affect the (attributes) file but I can't figure out exactly what that means.
+
+ public void AddPatchArchive(string patchPath)
+ {
+ VerifyHandle();
+
+ if (!NativeMethods.SFileOpenPatchArchive(_handle, patchPath, null, 0))
+ throw new Win32Exception();
+ }
+
+ public void AddPatchArchives(IEnumerable patchPaths)
+ {
+ if (patchPaths == null)
+ throw new ArgumentNullException("patchPaths");
+
+ VerifyHandle();
+
+ foreach (string path in patchPaths)
+ {
+ // Don't sublet to AddPatchArchive to avoid having to repeatedly call VerifyHandle()
+ if (!NativeMethods.SFileOpenPatchArchive(_handle, path, null, 0))
+ throw new Win32Exception();
+ }
+ }
+
+ public bool HasFile(string fileToFind)
+ {
+ VerifyHandle();
+
+ return NativeMethods.SFileHasFile(_handle, fileToFind);
+ }
+
+ public MpqFileStream OpenFile(string fileName)
+ {
+ VerifyHandle();
+
+ MpqFileSafeHandle fileHandle;
+ if (!NativeMethods.SFileOpenFileEx(_handle, fileName, 0, out fileHandle))
+ throw new Win32Exception();
+
+ MpqFileStream fs = new MpqFileStream(fileHandle, _accessType, this);
+ _openFiles.Add(fs);
+ return fs;
+ }
+
+ public void ExtractFile(string fileToExtract, string destinationPath)
+ {
+ VerifyHandle();
+
+ if (!NativeMethods.SFileExtractFile(_handle, fileToExtract, destinationPath, 0))
+ throw new Win32Exception();
+ }
+
+ public MpqFileVerificationResults VerifyFile(string fileToVerify)
+ {
+ VerifyHandle();
+
+ return (MpqFileVerificationResults)NativeMethods.SFileVerifyFile(_handle, fileToVerify, 0);
+ }
+
+ // TODO: Consider SFileVerifyRawData
+
+ public MpqArchiveVerificationResult VerifyArchive()
+ {
+ VerifyHandle();
+
+ return (MpqArchiveVerificationResult)NativeMethods.SFileVerifyArchive(_handle);
+ }
+
+
+ #region IDisposable implementation
+ public void Dispose()
+ {
+ Dispose(true);
+ }
+
+ ~MpqArchive()
+ {
+ Dispose(false);
+ }
+
+ protected virtual void Dispose(bool disposing)
+ {
+ if (disposing)
+ {
+ // Release owned files first.
+ if (_openFiles != null)
+ {
+ foreach (var file in _openFiles)
+ {
+ file.Dispose();
+ }
+
+ _openFiles.Clear();
+ _openFiles = null;
+ }
+
+ // Release
+ if (_handle != null && !_handle.IsInvalid)
+ {
+ _handle.Close();
+ _handle = null;
+ }
+ }
+ }
+
+ internal void RemoveOwnedFile(MpqFileStream file)
+ {
+ _openFiles.Remove(file);
+ }
+
+ #endregion
+ }
+
+ public enum MpqArchiveVersion
+ {
+ Version1 = 0,
+ Version2 = 0x01000000,
+ Version3 = 0x02000000,
+ Version4 = 0x03000000,
+ }
+
+ [Flags]
+ public enum MpqFileStreamAttributes
+ {
+ None = 0x0,
+ }
+
+ [Flags]
+ public enum MpqFileVerificationResults
+ {
+ ///
+ /// There were no errors with the file.
+ ///
+ Verified = 0,
+ ///
+ /// Failed to open the file
+ ///
+ Error = 0x1,
+ ///
+ /// Failed to read all data from the file
+ ///
+ ReadError = 0x2,
+ ///
+ /// File has sector CRC
+ ///
+ HasSectorCrc = 0x4,
+ ///
+ /// Sector CRC check failed
+ ///
+ SectorCrcError = 0x8,
+ ///
+ /// File has CRC32
+ ///
+ HasChecksum = 0x10,
+ ///
+ /// CRC32 check failed
+ ///
+ ChecksumError = 0x20,
+ ///
+ /// File has data MD5
+ ///
+ HasMd5 = 0x40,
+ ///
+ /// MD5 check failed
+ ///
+ Md5Error = 0x80,
+ ///
+ /// File has raw data MD5
+ ///
+ HasRawMd5 = 0x100,
+ ///
+ /// Raw MD5 check failed
+ ///
+ RawMd5Error = 0x200,
+ }
+
+ public enum MpqArchiveVerificationResult
+ {
+ ///
+ /// There is no signature in the MPQ
+ ///
+ NoSignature = 0,
+ ///
+ /// There was an error during verifying signature (like no memory)
+ ///
+ VerificationFailed = 1,
+ ///
+ /// There is a weak signature and sign check passed
+ ///
+ WeakSignatureVerified = 2,
+ ///
+ /// There is a weak signature but sign check failed
+ ///
+ WeakSignatureFailed = 3,
+ ///
+ /// There is a strong signature and sign check passed
+ ///
+ StrongSignatureVerified = 4,
+ ///
+ /// There is a strong signature but sign check failed
+ ///
+ StrongSignatureFailed = 5,
+ }
+}
diff --git a/BurnOutSharp/External/StormLibSharp/MpqArchiveCompactingEventArgs.cs b/BurnOutSharp/External/StormLibSharp/MpqArchiveCompactingEventArgs.cs
new file mode 100644
index 00000000..c2a2ee7b
--- /dev/null
+++ b/BurnOutSharp/External/StormLibSharp/MpqArchiveCompactingEventArgs.cs
@@ -0,0 +1,49 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace StormLibSharp
+{
+ public delegate void MpqArchiveCompactingEventHandler(MpqArchive sender, MpqArchiveCompactingEventArgs e);
+
+ public class MpqArchiveCompactingEventArgs : EventArgs
+ {
+ internal MpqArchiveCompactingEventArgs(uint dwWorkType, ulong processed, ulong total)
+ {
+ unchecked
+ {
+ WorkType = (MpqCompactingWorkType)dwWorkType;
+ BytesProcessed = (long)processed;
+ TotalBytes = (long)total;
+ }
+ }
+
+ public MpqCompactingWorkType WorkType
+ {
+ get;
+ private set;
+ }
+
+ public long BytesProcessed
+ {
+ get;
+ private set;
+ }
+
+ public long TotalBytes
+ {
+ get;
+ private set;
+ }
+ }
+
+ public enum MpqCompactingWorkType
+ {
+ CheckingFiles = 1,
+ CheckingHashTable = 2,
+ CopyingNonMpqData = 3,
+ CompactingFiles = 4,
+ ClosingArchive = 5,
+ }
+}
diff --git a/BurnOutSharp/External/StormLibSharp/MpqFileStream.cs b/BurnOutSharp/External/StormLibSharp/MpqFileStream.cs
new file mode 100644
index 00000000..18f6de25
--- /dev/null
+++ b/BurnOutSharp/External/StormLibSharp/MpqFileStream.cs
@@ -0,0 +1,185 @@
+using StormLibSharp.Native;
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.IO;
+using System.Linq;
+using System.Text;
+using System.Threading;
+
+namespace StormLibSharp
+{
+ public class MpqFileStream : Stream
+ {
+ private MpqFileSafeHandle _handle;
+ private FileAccess _accessType;
+ private MpqArchive _owner;
+
+ internal MpqFileStream(MpqFileSafeHandle handle, FileAccess accessType, MpqArchive owner)
+ {
+ _handle = handle;
+ _accessType = accessType;
+ _owner = owner;
+ }
+
+ private void VerifyHandle()
+ {
+ if (_handle == null || _handle.IsInvalid || _handle.IsClosed)
+ throw new ObjectDisposedException("MpqFileStream");
+ }
+
+ public override bool CanRead
+ {
+ get { VerifyHandle(); return true; }
+ }
+
+ public override bool CanSeek
+ {
+ get { VerifyHandle(); return true; }
+ }
+
+ public override bool CanWrite
+ {
+ get { VerifyHandle(); return _accessType != FileAccess.Read; }
+ }
+
+ public override void Flush()
+ {
+ VerifyHandle();
+
+ _owner.Flush();
+ }
+
+ public override long Length
+ {
+ get
+ {
+ VerifyHandle();
+
+ uint high = 0;
+ uint low = NativeMethods.SFileGetFileSize(_handle, ref high);
+
+ ulong val = (high << 32) | low;
+ return unchecked((long)val);
+ }
+ }
+
+ public override long Position
+ {
+ get
+ {
+ VerifyHandle();
+
+ return NativeMethods.SFileGetFilePointer(_handle);
+ }
+ set
+ {
+ Seek(value, SeekOrigin.Begin);
+ }
+ }
+
+ public override unsafe int Read(byte[] buffer, int offset, int count)
+ {
+ if (buffer == null)
+ throw new ArgumentNullException("buffer");
+ if (offset > buffer.Length || (offset + count) > buffer.Length)
+ throw new ArgumentException();
+ if (count < 0)
+ throw new ArgumentOutOfRangeException("count");
+
+ VerifyHandle();
+
+ bool success;
+ uint read;
+ fixed (byte* pb = &buffer[offset])
+ {
+ NativeOverlapped overlapped = default(NativeOverlapped);
+ success = NativeMethods.SFileReadFile(_handle, new IntPtr(pb), unchecked((uint)count), out read, ref overlapped);
+ }
+
+ if (!success)
+ {
+ int lastError = Win32Methods.GetLastError();
+ if (lastError != 38) // EOF
+ throw new Win32Exception(lastError);
+ }
+
+ return unchecked((int)read);
+ }
+
+ public override long Seek(long offset, SeekOrigin origin)
+ {
+ VerifyHandle();
+
+ uint low, high;
+ low = unchecked((uint)(offset & 0xffffffffu));
+ high = unchecked((uint)(offset >> 32));
+ return NativeMethods.SFileSetFilePointer(_handle, low, ref high, (uint)origin);
+ }
+
+ public override void SetLength(long value)
+ {
+ throw new NotSupportedException();
+ }
+
+ public override unsafe void Write(byte[] buffer, int offset, int count)
+ {
+ VerifyHandle();
+
+ if (buffer == null)
+ throw new ArgumentNullException("buffer");
+ if (offset > buffer.Length || (offset + count) > buffer.Length)
+ throw new ArgumentException();
+ if (count < 0)
+ throw new ArgumentOutOfRangeException("count");
+
+ VerifyHandle();
+
+ bool success;
+ fixed (byte* pb = &buffer[offset])
+ {
+ success = NativeMethods.SFileWriteFile(_handle, new IntPtr(pb), unchecked((uint)count), 0u);
+ }
+
+ if (!success)
+ throw new Win32Exception();
+ }
+
+ protected override void Dispose(bool disposing)
+ {
+ base.Dispose(disposing);
+
+ if (disposing)
+ {
+ if (_handle != null && !_handle.IsInvalid)
+ {
+ _handle.Close();
+ _handle = null;
+ }
+
+ if (_owner != null)
+ {
+ _owner.RemoveOwnedFile(this);
+ _owner = null;
+ }
+ }
+ }
+
+ // TODO: Seems like the right place for SFileGetFileInfo, but will need to determine
+ // what value add these features have except for sophisticated debugging purposes
+ // (like in Ladis' MPQ Editor app).
+
+ public int ChecksumCrc32
+ {
+ get
+ {
+ throw new NotImplementedException();
+ }
+ }
+
+ public byte[] GetMd5Hash()
+ {
+ throw new NotImplementedException();
+ }
+ }
+}
diff --git a/BurnOutSharp/External/StormLibSharp/Native/Callbacks.cs b/BurnOutSharp/External/StormLibSharp/Native/Callbacks.cs
new file mode 100644
index 00000000..58e7fa5e
--- /dev/null
+++ b/BurnOutSharp/External/StormLibSharp/Native/Callbacks.cs
@@ -0,0 +1,17 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace StormLibSharp.Native
+{
+ [UnmanagedFunctionPointer(CallingConvention.Winapi)]
+ internal delegate void SFILE_DOWNLOAD_CALLBACK(IntPtr pvUserData, ulong byteOffset, uint dwTotalBytes);
+
+ [UnmanagedFunctionPointer(CallingConvention.Winapi)]
+ internal delegate void SFILE_COMPACT_CALLBACK(IntPtr pvUserData, uint dwWorkType, ulong bytesProcessed, ulong totalBytes);
+
+ [UnmanagedFunctionPointer(CallingConvention.Winapi)]
+ internal delegate void SFILE_ADDFILE_CALLBACK(IntPtr pvUserData, uint dwBytesWritte, uint dwTotalBytes, bool bFinalCall);
+}
diff --git a/BurnOutSharp/External/StormLibSharp/Native/MpqArchiveSafeHandle.cs b/BurnOutSharp/External/StormLibSharp/Native/MpqArchiveSafeHandle.cs
new file mode 100644
index 00000000..5e2df9c4
--- /dev/null
+++ b/BurnOutSharp/External/StormLibSharp/Native/MpqArchiveSafeHandle.cs
@@ -0,0 +1,26 @@
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace StormLibSharp.Native
+{
+ internal sealed class MpqArchiveSafeHandle : SafeHandleZeroOrMinusOneIsInvalid
+ {
+ public MpqArchiveSafeHandle(IntPtr handle)
+ : base(true)
+ {
+ this.SetHandle(handle);
+ }
+
+ public MpqArchiveSafeHandle()
+ : base(true) { }
+
+ protected override bool ReleaseHandle()
+ {
+ return NativeMethods.SFileCloseArchive(this.handle);
+ }
+ }
+}
diff --git a/BurnOutSharp/External/StormLibSharp/Native/MpqFileSafeHandle.cs b/BurnOutSharp/External/StormLibSharp/Native/MpqFileSafeHandle.cs
new file mode 100644
index 00000000..495dd129
--- /dev/null
+++ b/BurnOutSharp/External/StormLibSharp/Native/MpqFileSafeHandle.cs
@@ -0,0 +1,27 @@
+using Microsoft.Win32.SafeHandles;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace StormLibSharp.Native
+{
+ internal sealed class MpqFileSafeHandle : SafeHandleZeroOrMinusOneIsInvalid
+ {
+ public MpqFileSafeHandle(IntPtr handle)
+ : base(true)
+ {
+ this.SetHandle(handle);
+ }
+
+ public MpqFileSafeHandle()
+ : base(true)
+ {
+ }
+
+ protected override bool ReleaseHandle()
+ {
+ return NativeMethods.SFileCloseFile(this.handle);
+ }
+ }
+}
diff --git a/BurnOutSharp/External/StormLibSharp/Native/NativeMethods.cs b/BurnOutSharp/External/StormLibSharp/Native/NativeMethods.cs
new file mode 100644
index 00000000..acef5fbc
--- /dev/null
+++ b/BurnOutSharp/External/StormLibSharp/Native/NativeMethods.cs
@@ -0,0 +1,497 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace StormLibSharp.Native
+{
+ internal static class NativeMethods
+ {
+ private const string STORMLIB = "stormlib.dll";
+
+ #region Functions for manipulation with StormLib global flags
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern uint SFileGetLocale();
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern uint SFileSetLocale(uint lcNewLocale);
+ #endregion
+
+ #region Functions for archive manipulation
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileOpenArchive(
+ [MarshalAs(UnmanagedType.LPTStr)] string szMpqName,
+ uint dwPriority,
+ SFileOpenArchiveFlags dwFlags,
+ out MpqArchiveSafeHandle phMpq
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileCreateArchive(
+ [MarshalAs(UnmanagedType.LPTStr)] string szMpqName,
+ uint dwCreateFlags,
+ uint dwMaxFileCount,
+ out MpqArchiveSafeHandle phMpq
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileCreateArchive2(
+ [MarshalAs(UnmanagedType.LPTStr)] string szMpqName,
+ ref SFILE_CREATE_MPQ pCreateInfo,
+ out MpqArchiveSafeHandle phMpq
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileSetDownloadCallback(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.FunctionPtr)] SFILE_DOWNLOAD_CALLBACK pfnCallback,
+ IntPtr pvUserData
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileFlushArchive(MpqArchiveSafeHandle hMpq);
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileCloseArchive(IntPtr hMpq);
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileCloseArchive(MpqArchiveSafeHandle hMpq);
+ #endregion
+
+ #region Adds another listfile into MPQ.
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern int SFileAddListFile(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPStr)] string szListFile
+ );
+ #endregion
+
+ #region Archive compacting
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileSetCompactCallback(
+ MpqArchiveSafeHandle hMpq,
+ SFILE_COMPACT_CALLBACK compactCB,
+ IntPtr pvUserData
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileCompactArchive(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPStr)] string szListFile,
+ bool bReserved
+ );
+ #endregion
+
+ #region Maximum file count
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern uint SFileGetMaxFileCount(MpqArchiveSafeHandle hMpq);
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileSetMaxFileCount(MpqArchiveSafeHandle hMpq, uint dwMaxFileCount);
+ #endregion
+
+ #region Changing (attributes) file
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern uint SFileGetAttributes(MpqArchiveSafeHandle hMpq);
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileSetAttributes(MpqArchiveSafeHandle hMpq, uint dwFlags);
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileUpdateFileAttributes(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPStr)] string szFileName
+ );
+ #endregion
+
+ #region Functions for manipulation with patch archives
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileOpenPatchArchive(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPTStr)] string szPatchMpqName,
+ [MarshalAs(UnmanagedType.LPStr)] string szPatchPathPrefix,
+ uint dwFlags
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileIsPatchedArchive(MpqArchiveSafeHandle hMpq);
+ #endregion
+
+ #region Functions for file manipulation
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileHasFile(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPStr)] string szFileName
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileOpenFileEx(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPStr)] string szFileName,
+ uint dwSearchScope,
+ out MpqFileSafeHandle phFile
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern uint SFileGetFileSize(MpqFileSafeHandle hFile, ref uint pdwFileSizeHigh);
+
+ public static unsafe uint SFileGetFilePointer(
+ MpqFileSafeHandle hFile
+ )
+ {
+ if (hFile.IsInvalid || hFile.IsClosed)
+ throw new InvalidOperationException();
+
+ IntPtr handle = hFile.DangerousGetHandle();
+ _TMPQFileHeader* header = (_TMPQFileHeader*)handle.ToPointer();
+ return header->dwFilePos;
+ }
+
+ //public static unsafe uint SFileGetFileSize(
+ // MpqFileSafeHandle hFile
+ // )
+ //{
+ // if (hFile.IsInvalid || hFile.IsClosed)
+ // throw new InvalidOperationException();
+
+ // IntPtr handle = hFile.DangerousGetHandle();
+ // _TMPQFileHeader* header = (_TMPQFileHeader*)handle.ToPointer();
+ // return header->pFileEntry->dwFileSize;
+ //}
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern uint SFileSetFilePointer(
+ MpqFileSafeHandle hFile,
+ uint lFilePos,
+ ref uint plFilePosHigh,
+ uint dwMoveMethod
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileReadFile(
+ MpqFileSafeHandle hFile,
+ IntPtr lpBuffer,
+ uint dwToRead,
+ out uint pdwRead,
+ ref System.Threading.NativeOverlapped lpOverlapped
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileCloseFile(IntPtr hFile);
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileCloseFile(MpqFileSafeHandle hFile);
+
+ #region Retrieving info about a file in the archive
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileGetFileInfo(
+ IntPtr hMpqOrFile,
+ SFileInfoClass InfoClass,
+ IntPtr pvFileInfo,
+ uint cbFileInfoSize,
+ out uint pcbLengthNeeded
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileGetFileInfo(
+ MpqArchiveSafeHandle hMpqOrFile,
+ SFileInfoClass InfoClass,
+ IntPtr pvFileInfo,
+ uint cbFileInfoSize,
+ out uint pcbLengthNeeded
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileGetFileInfo(
+ MpqFileSafeHandle hMpqOrFile,
+ SFileInfoClass InfoClass,
+ IntPtr pvFileInfo,
+ uint cbFileInfoSize,
+ out uint pcbLengthNeeded
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileGetFileName(
+ MpqFileSafeHandle hFile,
+ [MarshalAs(UnmanagedType.LPStr)] out string szFileName
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileFreeFileInfo(
+ IntPtr pvFileInfo,
+ SFileInfoClass infoClass
+ );
+ #endregion
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileExtractFile(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPStr)] string szToExtract,
+ [MarshalAs(UnmanagedType.LPTStr)] string szExtracted,
+ uint dwSearchScope
+ );
+
+ #endregion
+
+ #region Functions for file and archive verification
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileGetFileChecksums(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPStr)] string szFileName,
+ out uint pdwCrc32,
+ IntPtr pMD5
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern uint SFileVerifyFile(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPStr)] string szFileName,
+ uint dwFlags
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern int SFileVerifyRawData(
+ MpqArchiveSafeHandle hMpq,
+ uint dwWhatToVerify,
+ [MarshalAs(UnmanagedType.LPStr)] string szFileName
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern uint SFileVerifyArchive(MpqArchiveSafeHandle hMpq);
+ #endregion
+
+ #region Functions for file searching
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern IntPtr SFileFindFirstFile(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPStr)] string szMask,
+ out _SFILE_FIND_DATA lpFindFileData,
+ [MarshalAs(UnmanagedType.LPStr)] string szListFile
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileFindNextFile(
+ IntPtr hFind,
+ [In, Out] ref _SFILE_FIND_DATA lpFindFileData
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileFindClose(IntPtr hFind);
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern IntPtr SListFileFindFirstFile(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPStr)] string szListFile,
+ [MarshalAs(UnmanagedType.LPStr)] string szMask,
+ [In, Out] ref _SFILE_FIND_DATA lpFindFileData
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SListFileFindNextFile(
+ IntPtr hFind,
+ [In, Out] ref _SFILE_FIND_DATA lpFindFileData
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SListFileFindClose(IntPtr hFind);
+ #endregion
+
+ #region Locale support
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern int SFileEnumLocales(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPStr)] string szFileName,
+ IntPtr plcLocales,
+ ref uint pdwMaxLocales,
+ uint dwSearchScope
+ );
+ #endregion
+
+ #region Support for adding files to the MPQ
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileCreateFile(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPStr)] string szArchiveName,
+ ulong fileTime,
+ uint dwFileSize,
+ uint lcLocale,
+ uint dwFlags,
+ out IntPtr phFile
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileWriteFile(
+ MpqFileSafeHandle hFile,
+ IntPtr pvData,
+ uint dwSize,
+ uint dwCompression
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileFinishFile(MpqFileSafeHandle hFile);
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileAddFileEx(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPTStr)] string szFileName,
+ [MarshalAs(UnmanagedType.LPStr)] string szArchivedName,
+ uint dwFlags,
+ uint dwCompression,
+ uint dwCompressionNext
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileAddFile(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPTStr)] string szFileName,
+ [MarshalAs(UnmanagedType.LPStr)] string szArchivedName,
+ uint dwFlags
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileAddWave(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPTStr)] string szFileName,
+ [MarshalAs(UnmanagedType.LPStr)] string szArchivedName,
+ uint dwFlags,
+ uint dwQuality
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileRemoveFile(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPStr)] string szFileName,
+ uint dwSearchScope
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileRenameFile(
+ MpqArchiveSafeHandle hMpq,
+ [MarshalAs(UnmanagedType.LPStr)] string szOldFileName,
+ [MarshalAs(UnmanagedType.LPStr)] string szNewFileName
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileSetFileLocale(
+ MpqFileSafeHandle hFile,
+ uint lcNewLocale
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileSetDataCompression(uint DataCompression);
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern bool SFileSetAddFileCallback(
+ MpqArchiveSafeHandle hMpq,
+ SFILE_ADDFILE_CALLBACK AddFileCB,
+ IntPtr pvUserData
+ );
+ #endregion
+
+ #region Compression and decompression
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern int SCompImplode(
+ IntPtr pvOutBuffer,
+ ref int pcbOutBuffer,
+ IntPtr pvInBuffer,
+ int cbInBuffer
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern int SCompExplode(
+ IntPtr pvOutBuffer,
+ ref int pcbOutBuffer,
+ IntPtr pvInBuffer,
+ int cbInBuffer
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern int SCompCompress(
+ IntPtr pvOutBuffer,
+ ref int pcbOutBuffer,
+ IntPtr pvInBuffer,
+ int cbInBuffer,
+ uint uCompressionMask,
+ int nCmpType,
+ int nCmpLevel
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern int SCompDecompress(
+ IntPtr pvOutBuffer,
+ ref int pcbOutBuffer,
+ IntPtr pvInBuffer,
+ int cbInBuffer
+ );
+
+ [DllImport(STORMLIB, CallingConvention = CallingConvention.Winapi, ExactSpelling = true, PreserveSig = true, SetLastError = true, ThrowOnUnmappableChar = false)]
+ public static extern int SCompDecompress2(
+ IntPtr pvOutBuffer,
+ ref int pcbOutBuffer,
+ IntPtr pvInBuffer,
+ int cbInBuffer
+ );
+
+
+ #endregion
+ }
+
+#pragma warning disable 0169,0649
+ internal struct SFILE_CREATE_MPQ
+ {
+ public uint cbSize;
+ public uint dwMpqVersion;
+ private IntPtr pvUserData;
+ private uint cbUserData;
+ public uint dwStreamFlags;
+ public uint dwFileFlags1;
+ public uint dwFileFlags2;
+ public uint dwAttrFlags;
+ public uint dwSectorSize;
+ public uint dwRawChunkSize;
+ public uint dwMaxFileCount;
+ }
+
+ internal unsafe struct _SFILE_FIND_DATA
+ {
+ public fixed char cFileName[260]; // Full name of the found file
+
+ public IntPtr szPlainName; // Plain name of the found file
+ public uint dwHashIndex; // Hash table index for the file
+ public uint dwBlockIndex; // Block table index for the file
+ public uint dwFileSize; // File size in bytes
+ public uint dwFileFlags; // MPQ file flags
+ public uint dwCompSize; // Compressed file size
+ public uint dwFileTimeLo; // Low 32-bits of the file time (0 if not present)
+ public uint dwFileTimeHi; // High 32-bits of the file time (0 if not present)
+ public uint lcLocale; // Locale version
+ }
+
+ internal unsafe struct _TFileEntry
+ {
+ public ulong FileNameHash;
+ public ulong ByteOffset;
+ public ulong FileTime;
+ public uint dwHashIndex;
+ public uint dwFileSize;
+ public uint dwCmpSize;
+ public uint dwFlags;
+ public ushort lcLocale;
+ public ushort wPlatform;
+ public uint dwCrc32;
+ public fixed byte md5[16];
+ public IntPtr szFileName;
+ }
+
+ // Provides enough of _TMPQFile to get to the file size and current position.
+ internal unsafe struct _TMPQFileHeader
+ {
+ public IntPtr pStream;
+ public IntPtr ha;
+ public _TFileEntry* pFileEntry;
+ public uint dwFileKey;
+ public uint dwFilePos;
+ }
+#pragma warning restore 0169,0649
+
+}
diff --git a/BurnOutSharp/External/StormLibSharp/Native/SFileInfoClass.cs b/BurnOutSharp/External/StormLibSharp/Native/SFileInfoClass.cs
new file mode 100644
index 00000000..f8ef7a92
--- /dev/null
+++ b/BurnOutSharp/External/StormLibSharp/Native/SFileInfoClass.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace StormLibSharp.Native
+{
+ internal enum SFileInfoClass
+ {
+ // Info classes for archives
+ SFileMpqFileName, // Name of the archive file (TCHAR [])
+ SFileMpqStreamBitmap, // Array of bits, each bit means availability of one block (BYTE [])
+ SFileMpqUserDataOffset, // Offset of the user data header (ULONGLONG)
+ SFileMpqUserDataHeader, // Raw (unfixed) user data header (TMPQUserData)
+ SFileMpqUserData, // MPQ USer data, without the header (BYTE [])
+ SFileMpqHeaderOffset, // Offset of the MPQ header (ULONGLONG)
+ SFileMpqHeaderSize, // Fixed size of the MPQ header
+ SFileMpqHeader, // Raw (unfixed) archive header (TMPQHeader)
+ SFileMpqHetTableOffset, // Offset of the HET table, relative to MPQ header (ULONGLONG)
+ SFileMpqHetTableSize, // Compressed size of the HET table (ULONGLONG)
+ SFileMpqHetHeader, // HET table header (TMPQHetHeader)
+ SFileMpqHetTable, // HET table as pointer. Must be freed using SFileFreeFileInfo
+ SFileMpqBetTableOffset, // Offset of the BET table, relative to MPQ header (ULONGLONG)
+ SFileMpqBetTableSize, // Compressed size of the BET table (ULONGLONG)
+ SFileMpqBetHeader, // BET table header, followed by the flags (TMPQBetHeader + DWORD[])
+ SFileMpqBetTable, // BET table as pointer. Must be freed using SFileFreeFileInfo
+ SFileMpqHashTableOffset, // Hash table offset, relative to MPQ header (ULONGLONG)
+ SFileMpqHashTableSize64, // Compressed size of the hash table (ULONGLONG)
+ SFileMpqHashTableSize, // Size of the hash table, in entries (DWORD)
+ SFileMpqHashTable, // Raw (unfixed) hash table (TMPQBlock [])
+ SFileMpqBlockTableOffset, // Block table offset, relative to MPQ header (ULONGLONG)
+ SFileMpqBlockTableSize64, // Compressed size of the block table (ULONGLONG)
+ SFileMpqBlockTableSize, // Size of the block table, in entries (DWORD)
+ SFileMpqBlockTable, // Raw (unfixed) block table (TMPQBlock [])
+ SFileMpqHiBlockTableOffset, // Hi-block table offset, relative to MPQ header (ULONGLONG)
+ SFileMpqHiBlockTableSize64, // Compressed size of the hi-block table (ULONGLONG)
+ SFileMpqHiBlockTable, // The hi-block table (USHORT [])
+ SFileMpqSignatures, // Signatures present in the MPQ (DWORD)
+ SFileMpqStrongSignatureOffset, // Byte offset of the strong signature, relative to begin of the file (ULONGLONG)
+ SFileMpqStrongSignatureSize, // Size of the strong signature (DWORD)
+ SFileMpqStrongSignature, // The strong signature (BYTE [])
+ SFileMpqArchiveSize64, // Archive size from the header (ULONGLONG)
+ SFileMpqArchiveSize, // Archive size from the header (DWORD)
+ SFileMpqMaxFileCount, // Max number of files in the archive (DWORD)
+ SFileMpqFileTableSize, // Number of entries in the file table (DWORD)
+ SFileMpqSectorSize, // Sector size (DWORD)
+ SFileMpqNumberOfFiles, // Number of files (DWORD)
+ SFileMpqRawChunkSize, // Size of the raw data chunk for MD5
+ SFileMpqStreamFlags, // Stream flags (DWORD)
+ SFileMpqIsReadOnly, // Nonzero if the MPQ is read only (DWORD)
+
+ // Info classes for files
+ SFileInfoPatchChain, // Chain of patches where the file is (TCHAR [])
+ SFileInfoFileEntry, // The file entry for the file (TFileEntry)
+ SFileInfoHashEntry, // Hash table entry for the file (TMPQHash)
+ SFileInfoHashIndex, // Index of the hash table entry (DWORD)
+ SFileInfoNameHash1, // The first name hash in the hash table (DWORD)
+ SFileInfoNameHash2, // The second name hash in the hash table (DWORD)
+ SFileInfoNameHash3, // 64-bit file name hash for the HET/BET tables (ULONGLONG)
+ SFileInfoLocale, // File locale (DWORD)
+ SFileInfoFileIndex, // Block index (DWORD)
+ SFileInfoByteOffset, // File position in the archive (ULONGLONG)
+ SFileInfoFileTime, // File time (ULONGLONG)
+ SFileInfoFileSize, // Size of the file (DWORD)
+ SFileInfoCompressedSize, // Compressed file size (DWORD)
+ SFileInfoFlags, // File flags from (DWORD)
+ SFileInfoEncryptionKey, // File encryption key
+ SFileInfoEncryptionKeyRaw, // Unfixed value of the file key
+ }
+}
diff --git a/BurnOutSharp/External/StormLibSharp/Native/SFileOpenArchiveFlags.cs b/BurnOutSharp/External/StormLibSharp/Native/SFileOpenArchiveFlags.cs
new file mode 100644
index 00000000..d444f2be
--- /dev/null
+++ b/BurnOutSharp/External/StormLibSharp/Native/SFileOpenArchiveFlags.cs
@@ -0,0 +1,26 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+
+namespace StormLibSharp.Native
+{
+ [Flags]
+ internal enum SFileOpenArchiveFlags : uint
+ {
+ None = 0,
+ TypeIsFile = None,
+ TypeIsMemoryMapped = 1,
+ TypeIsHttp = 2,
+
+ AccessReadOnly = 0x100,
+ AccessReadWriteShare = 0x200,
+ AccessUseBitmap = 0x400,
+
+ DontOpenListfile = 0x10000,
+ DontOpenAttributes = 0x20000,
+ DontSearchHeader = 0x40000,
+ ForceVersion1 = 0x80000,
+ CheckSectorCRC = 0x100000,
+ }
+}
diff --git a/BurnOutSharp/External/StormLibSharp/Native/Win32Methods.cs b/BurnOutSharp/External/StormLibSharp/Native/Win32Methods.cs
new file mode 100644
index 00000000..15596c07
--- /dev/null
+++ b/BurnOutSharp/External/StormLibSharp/Native/Win32Methods.cs
@@ -0,0 +1,60 @@
+using System;
+using System.Collections.Generic;
+using System.ComponentModel;
+using System.Diagnostics;
+using System.IO.MemoryMappedFiles;
+using System.Linq;
+using System.Runtime.InteropServices;
+using System.Text;
+
+namespace StormLibSharp.Native
+{
+ internal static class Win32Methods
+ {
+ [DllImport("kernel32", ExactSpelling = false, SetLastError = true)]
+ public static extern uint GetMappedFileName(
+ IntPtr hProcess,
+ IntPtr fileHandle,
+ IntPtr lpFilename,
+ uint nSize
+ );
+
+ [DllImport("kernel32", ExactSpelling = false, SetLastError = true)]
+ public static extern uint GetFinalPathNameByHandle(
+ IntPtr hFile,
+ IntPtr lpszFilePath,
+ uint cchFilePath,
+ uint dwFlags
+ );
+
+ [DllImport("kernel32", SetLastError = false, ExactSpelling = false)]
+ public static extern int GetLastError();
+
+ public static string GetFileNameOfMemoryMappedFile(MemoryMappedFile file)
+ {
+ const uint size = 522;
+ IntPtr path = Marshal.AllocCoTaskMem(unchecked((int)size)); // MAX_PATH + 1 char
+
+ string result = null;
+ try
+ {
+ // constant 0x2 = VOLUME_NAME_NT
+ uint test = GetFinalPathNameByHandle(file.SafeMemoryMappedFileHandle.DangerousGetHandle(), path, size, 0x2);
+ if (test != 0)
+ throw new Win32Exception();
+
+ result = Marshal.PtrToStringAuto(path);
+ }
+ catch
+ {
+ uint test = GetMappedFileName(Process.GetCurrentProcess().Handle, file.SafeMemoryMappedFileHandle.DangerousGetHandle(), path, size);
+ if (test != 0)
+ throw new Win32Exception();
+
+ result = Marshal.PtrToStringAuto(path);
+ }
+
+ return result;
+ }
+ }
+}
diff --git a/BurnOutSharp/External/psxt001z/LibCrypt.cs b/BurnOutSharp/External/psxt001z/LibCrypt.cs
index cb0fde77..fc5874d6 100644
--- a/BurnOutSharp/External/psxt001z/LibCrypt.cs
+++ b/BurnOutSharp/External/psxt001z/LibCrypt.cs
@@ -63,7 +63,7 @@ namespace BurnOutSharp.External.psxt001z
{
subfile.Seek(12, SeekOrigin.Current);
if (subfile.Read(buffer, 0, 12) == 0)
- return true;
+ return modifiedSectors != 0;
subfile.Seek(72, SeekOrigin.Current);
@@ -128,7 +128,7 @@ namespace BurnOutSharp.External.psxt001z
}
Console.WriteLine($"Number of modified sectors: {modifiedSectors}");
- return true;
+ return modifiedSectors != 0;
}
private static byte btoi(byte b)
diff --git a/BurnOutSharp/FileType/BFPK.cs b/BurnOutSharp/FileType/BFPK.cs
new file mode 100644
index 00000000..4b32f1e9
--- /dev/null
+++ b/BurnOutSharp/FileType/BFPK.cs
@@ -0,0 +1,122 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using SharpCompress.Compressors;
+using SharpCompress.Compressors.Deflate;
+
+namespace BurnOutSharp.FileType
+{
+ internal class BFPK
+ {
+ public static bool ShouldScan(byte[] magic)
+ {
+ if (magic.StartsWith(new byte[] { 0x42, 0x46, 0x50, 0x4b }))
+ return true;
+
+ return false;
+ }
+
+ public static List Scan(Stream stream)
+ {
+ List protections = new List();
+
+ // If the BFPK file itself fails
+ try
+ {
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
+ {
+ br.ReadBytes(4); // Skip magic number
+
+ int version = br.ReadInt32();
+ int files = br.ReadInt32();
+ long current = br.BaseStream.Position;
+
+ for (int i = 0; i < files; i++)
+ {
+ br.BaseStream.Seek(current, SeekOrigin.Begin);
+
+ int nameSize = br.ReadInt32();
+ string name = new string(br.ReadChars(nameSize));
+
+ uint uncompressedSize = br.ReadUInt32();
+ int offset = br.ReadInt32();
+
+ current = br.BaseStream.Position;
+
+ br.BaseStream.Seek(offset, SeekOrigin.Begin);
+ uint compressedSize = br.ReadUInt32();
+
+ // Some files can lack the length prefix
+ if (compressedSize > br.BaseStream.Length)
+ {
+ br.BaseStream.Seek(-4, SeekOrigin.Current);
+ compressedSize = uncompressedSize;
+ }
+
+ // If an individual entry fails
+ try
+ {
+ string tempFile = Path.Combine(tempPath, name);
+ if (!Directory.Exists(Path.GetDirectoryName(tempFile)))
+ Directory.CreateDirectory(Path.GetDirectoryName(tempFile));
+
+ if (compressedSize == uncompressedSize)
+ {
+ using (FileStream fs = File.OpenWrite(tempFile))
+ {
+ fs.Write(br.ReadBytes((int)uncompressedSize), 0, (int)uncompressedSize);
+ }
+ }
+ else
+ {
+ using (FileStream fs = File.OpenWrite(tempFile))
+ {
+ try
+ {
+ ZlibStream zs = new ZlibStream(br.BaseStream, CompressionMode.Decompress);
+ zs.CopyTo(fs);
+ }
+ catch (ZlibException)
+ {
+ br.BaseStream.Seek(offset + 4, SeekOrigin.Begin);
+ fs.Write(br.ReadBytes((int)compressedSize), 0, (int)compressedSize);
+ }
+ }
+ }
+
+ string protection = ProtectionFind.ScanContent(tempFile);
+
+ // If tempfile cleanup fails
+ try
+ {
+ File.Delete(tempFile);
+ }
+ catch { }
+
+ if (!string.IsNullOrEmpty(protection))
+ protections.Add(tempFile);
+ }
+ catch { }
+
+
+ br.BaseStream.Seek(current, SeekOrigin.Begin);
+ }
+ }
+
+ // If temp directory cleanup fails
+ try
+ {
+ Directory.Delete(tempPath, true);
+ }
+ catch { }
+ }
+ catch { }
+
+ return protections;
+ }
+ }
+}
diff --git a/BurnOutSharp/FileType/BZip2.cs b/BurnOutSharp/FileType/BZip2.cs
new file mode 100644
index 00000000..50130b39
--- /dev/null
+++ b/BurnOutSharp/FileType/BZip2.cs
@@ -0,0 +1,67 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using SharpCompress.Compressors;
+using SharpCompress.Compressors.BZip2;
+
+namespace BurnOutSharp.FileType
+{
+ internal class BZip2
+ {
+ public static bool ShouldScan(byte[] magic)
+ {
+ if (magic.StartsWith(new byte[] { 0x42, 0x52, 0x68 }))
+ return true;
+
+ return false;
+ }
+
+ public static List Scan(Stream stream)
+ {
+ List protections = new List();
+
+ // If the 7-zip file itself fails
+ try
+ {
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (BZip2Stream bz2File = new BZip2Stream(stream, CompressionMode.Decompress, true))
+ {
+ // If an individual entry fails
+ try
+ {
+ string tempfile = Path.Combine(tempPath, Guid.NewGuid().ToString());
+ using (FileStream fs = File.OpenWrite(tempfile))
+ {
+ bz2File.CopyTo(fs);
+ }
+
+ string protection = ProtectionFind.ScanContent(tempfile);
+
+ // If tempfile cleanup fails
+ try
+ {
+ File.Delete(tempfile);
+ }
+ catch { }
+
+ if (!string.IsNullOrEmpty(protection))
+ protections.Add($"\r\n{protection}");
+ }
+ catch { }
+
+ // If temp directory cleanup fails
+ try
+ {
+ Directory.Delete(tempPath, true);
+ }
+ catch { }
+ }
+ }
+ catch { }
+
+ return protections;
+ }
+ }
+}
diff --git a/BurnOutSharp/FileType/Executable.cs b/BurnOutSharp/FileType/Executable.cs
new file mode 100644
index 00000000..9e780a33
--- /dev/null
+++ b/BurnOutSharp/FileType/Executable.cs
@@ -0,0 +1,254 @@
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+using BurnOutSharp.ProtectionType;
+
+namespace BurnOutSharp.FileType
+{
+ internal class Executable
+ {
+ public static bool ShouldScan(byte[] magic)
+ {
+ // DOS MZ executable file format (and descendants)
+ if (magic.StartsWith(new byte[] { 0x4d, 0x5a }))
+ return true;
+
+ // Executable and Linkable Format
+ if (magic.StartsWith(new byte[] { 0x7f, 0x45, 0x4c, 0x46 }))
+ return true;
+
+ // Mach-O binary (32-bit)
+ if (magic.StartsWith(new byte[] { 0xfe, 0xed, 0xfa, 0xce }))
+ return true;
+
+ // Mach-O binary (32-bit, reverse byte ordering scheme)
+ if (magic.StartsWith(new byte[] { 0xce, 0xfa, 0xed, 0xfe }))
+ return true;
+
+ // Mach-O binary (64-bit)
+ if (magic.StartsWith(new byte[] { 0xfe, 0xed, 0xfa, 0xcf }))
+ return true;
+
+ // Mach-O binary (64-bit, reverse byte ordering scheme)
+ if (magic.StartsWith(new byte[] { 0xcf, 0xfa, 0xed, 0xfe }))
+ return true;
+
+ // Prefrred Executable File Format
+ if (magic.StartsWith(new byte[] { 0x4a, 0x6f, 0x79, 0x21, 0x70, 0x65, 0x66, 0x66 }))
+ return true;
+
+ return false;
+ }
+
+ public static List Scan(Stream stream, string file)
+ {
+ // Load the current file content
+ byte[] fileContent = null;
+ using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
+ {
+ fileContent = br.ReadBytes((int)stream.Length);
+ }
+
+ // If we can, seek to the beginning of the stream
+ if (stream.CanSeek)
+ stream.Seek(0, SeekOrigin.Begin);
+
+ // Files can be protected in multiple ways
+ List protections = new List();
+ List subProtections = new List();
+ string protection;
+
+ // 3PLock
+ protection = ThreePLock.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // ActiveMARK
+ protection = ActiveMARK.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // Alpha-ROM
+ protection = AlphaROM.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // Armadillo
+ protection = Armadillo.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // CD-Cops
+ protection = CDCops.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // CD-Lock
+ protection = CDLock.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // CDSHiELD SE
+ protection = CDSHiELDSE.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // CD Check
+ protection = CDCheck.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // Cenega ProtectDVD
+ protection = CengaProtectDVD.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // Code Lock
+ protection = CodeLock.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // CopyKiller
+ protection = CopyKiller.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // Cucko (EA Custom)
+ protection = Cucko.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // dotFuscator
+ protection = dotFuscator.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // DVD-Cops
+ protection = DVDCops.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // EA CdKey Registration Module
+ protection = EACdKey.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // EXE Stealth
+ protection = EXEStealth.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // Games for Windows - Live
+ protection = GFWL.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // Impulse Reactor
+ protection = ImpulseReactor.CheckContents(file, fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // Inno Setup
+ protection = InnoSetup.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // JoWooD X-Prot
+ protection = JoWooDXProt.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // Key-Lock (Dongle)
+ protection = KeyLock.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // LaserLock
+ protection = LaserLock.CheckContents(file, fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // PE Compact
+ protection = PECompact.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // ProtectDisc
+ protection = ProtectDisc.CheckContents(file, fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // Ring PROTECH
+ protection = RingPROTECH.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // SafeDisc / SafeCast
+ protection = SafeDisc.CheckContents(file, fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // SafeLock
+ protection = SafeLock.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // SecuROM
+ protection = SecuROM.CheckContents(file, fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // SmartE
+ protection = SmartE.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // SolidShield
+ protection = SolidShield.CheckContents(file, fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // StarForce
+ protection = StarForce.CheckContents(file, fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // SVK Protector
+ protection = SVKProtector.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // Sysiphus / Sysiphus DVD
+ protection = Sysiphus.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // TAGES
+ protection = Tages.CheckContents(file, fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // VOB ProtectCD/DVD
+ protection = VOBProtectCDDVD.CheckContents(file, fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // Wise Installer
+ subProtections = WiseInstaller.CheckContents(file, fileContent);
+ if (subProtections != null && subProtections.Count > 0)
+ protections.AddRange(subProtections);
+
+ // WTM CD Protect
+ protection = WTMCDProtect.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ // Xtreme-Protector
+ protection = XtremeProtector.CheckContents(fileContent);
+ if (!string.IsNullOrWhiteSpace(protection))
+ protections.Add(protection);
+
+ return protections;
+ }
+ }
+}
diff --git a/BurnOutSharp/FileType/GZIP.cs b/BurnOutSharp/FileType/GZIP.cs
new file mode 100644
index 00000000..f22f5257
--- /dev/null
+++ b/BurnOutSharp/FileType/GZIP.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using SharpCompress.Archives;
+using SharpCompress.Archives.GZip;
+
+namespace BurnOutSharp.FileType
+{
+ internal class GZIP
+ {
+ public static bool ShouldScan(byte[] magic)
+ {
+ if (magic.StartsWith(new byte[] { 0x1f, 0x8b }))
+ return true;
+
+ return false;
+ }
+
+ public static List Scan(Stream stream)
+ {
+ List protections = new List();
+
+ // If the gzip file itself fails
+ try
+ {
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (GZipArchive zipFile = GZipArchive.Open(stream))
+ {
+ foreach (var entry in zipFile.Entries)
+ {
+ // If an individual entry fails
+ try
+ {
+ // If we have a directory, skip it
+ if (entry.IsDirectory)
+ continue;
+
+ string tempfile = Path.Combine(tempPath, entry.Key);
+ entry.WriteToFile(tempfile);
+ string protection = ProtectionFind.ScanContent(tempfile);
+
+ // If tempfile cleanup fails
+ try
+ {
+ File.Delete(tempfile);
+ }
+ catch { }
+
+ if (!string.IsNullOrEmpty(protection))
+ protections.Add($"\r\n{entry.Key} - {protection}");
+ }
+ catch { }
+ }
+
+ // If temp directory cleanup fails
+ try
+ {
+ Directory.Delete(tempPath, true);
+ }
+ catch { }
+ }
+ }
+ catch { }
+
+ return protections;
+ }
+ }
+}
diff --git a/BurnOutSharp/FileType/InstallShieldCAB.cs b/BurnOutSharp/FileType/InstallShieldCAB.cs
new file mode 100644
index 00000000..0bce7e1d
--- /dev/null
+++ b/BurnOutSharp/FileType/InstallShieldCAB.cs
@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text.RegularExpressions;
+using UnshieldSharp;
+
+namespace BurnOutSharp.FileType
+{
+ internal class InstallShieldCAB
+ {
+ public static bool ShouldScan(byte[] magic)
+ {
+ if (magic.StartsWith(new byte[] { 0x49, 0x53, 0x63 }))
+ return true;
+
+ return false;
+ }
+
+ // TODO: Add stream opening support
+ public static List Scan(string file)
+ {
+ List protections = new List();
+
+ // Get the name of the first cabinet file or header
+ string directory = Path.GetDirectoryName(file);
+ string noExtension = Path.GetFileNameWithoutExtension(file);
+ string filenamePattern = Path.Combine(directory, noExtension);
+ filenamePattern = new Regex(@"\d+$").Replace(filenamePattern, string.Empty);
+
+ bool cabinetHeaderExists = File.Exists(Path.Combine(directory, filenamePattern + "1.hdr"));
+ bool shouldScanCabinet = cabinetHeaderExists
+ ? file.Equals(Path.Combine(directory, filenamePattern + "1.hdr"), StringComparison.OrdinalIgnoreCase)
+ : file.Equals(Path.Combine(directory, filenamePattern + "1.cab"), StringComparison.OrdinalIgnoreCase);
+
+ // If we have the first file
+ if (shouldScanCabinet)
+ {
+ // If the cab file itself fails
+ try
+ {
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ UnshieldCabinet cabfile = UnshieldCabinet.Open(file);
+ for (int i = 0; i < cabfile.FileCount; i++)
+ {
+ // If an individual entry fails
+ try
+ {
+ string tempFile = Path.Combine(tempPath, cabfile.FileName(i));
+ if (cabfile.FileSave(i, tempFile))
+ {
+ string protection = ProtectionFind.ScanContent(tempFile);
+
+ // If tempfile cleanup fails
+ try
+ {
+ File.Delete(tempFile);
+ }
+ catch { }
+
+ if (!string.IsNullOrEmpty(protection))
+ protections.Add($"\r\n{cabfile.FileName(i)} - {protection}");
+ }
+ }
+ catch { }
+ }
+
+ // If temp directory cleanup fails
+ try
+ {
+ Directory.Delete(tempPath, true);
+ }
+ catch { }
+ }
+ catch { }
+ }
+
+ return protections;
+ }
+ }
+}
diff --git a/BurnOutSharp/FileType/MPQ.cs b/BurnOutSharp/FileType/MPQ.cs
new file mode 100644
index 00000000..3bf198c6
--- /dev/null
+++ b/BurnOutSharp/FileType/MPQ.cs
@@ -0,0 +1,78 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using StormLibSharp;
+
+namespace BurnOutSharp.FileType
+{
+ internal class MPQ
+ {
+ public static bool ShouldScan(byte[] magic)
+ {
+ if (magic.StartsWith(new byte[] { 0x4d, 0x50, 0x51, 0x1a }))
+ return true;
+
+ return false;
+ }
+
+ // TODO: Add stream opening support
+ public static List Scan(string file)
+ {
+ List protections = new List();
+
+ // If the mpq file itself fails
+ try
+ {
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (MpqArchive mpqArchive = new MpqArchive(file, FileAccess.Read))
+ {
+ string listfile = null;
+ MpqFileStream listStream = mpqArchive.OpenFile("(listfile)");
+ bool canRead = listStream.CanRead;
+
+ using (StreamReader sr = new StreamReader(listStream))
+ {
+ listfile = sr.ReadToEnd();
+ Console.WriteLine(listfile);
+ }
+
+ string sub = string.Empty;
+ while ((sub = listfile) != null)
+ {
+ // If an individual entry fails
+ try
+ {
+ string tempfile = Path.Combine(tempPath, sub);
+ Directory.CreateDirectory(Path.GetDirectoryName(tempfile));
+ mpqArchive.ExtractFile(sub, tempfile);
+ string protection = ProtectionFind.ScanContent(tempfile);
+
+ // If tempfile cleanup fails
+ try
+ {
+ File.Delete(tempfile);
+ }
+ catch { }
+
+ if (!string.IsNullOrEmpty(protection))
+ protections.Add($"\r\n{sub} - {protection}");
+ }
+ catch { }
+ }
+
+ // If temp directory cleanup fails
+ try
+ {
+ Directory.Delete(tempPath, true);
+ }
+ catch { }
+ }
+ }
+ catch { }
+
+ return protections;
+ }
+ }
+}
diff --git a/BurnOutSharp/FileType/MicrosoftCAB.cs b/BurnOutSharp/FileType/MicrosoftCAB.cs
new file mode 100644
index 00000000..0bd44e1f
--- /dev/null
+++ b/BurnOutSharp/FileType/MicrosoftCAB.cs
@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using LibMSPackN;
+
+namespace BurnOutSharp.FileType
+{
+ internal class MicrosoftCAB
+ {
+ public static bool ShouldScan(byte[] magic)
+ {
+ if (magic.StartsWith(new byte[] { 0x4d, 0x53, 0x43, 0x46 }))
+ return true;
+
+ return false;
+ }
+
+ // TODO: Add stream opening support
+ public static List Scan(string file)
+ {
+ List protections = new List();
+
+ // If the cab file itself fails
+ try
+ {
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (MSCabinet cabfile = new MSCabinet(file))
+ {
+ foreach (var sub in cabfile.GetFiles())
+ {
+ // If an individual entry fails
+ try
+ {
+ string tempfile = Path.Combine(tempPath, sub.Filename);
+ sub.ExtractTo(tempfile);
+ string protection = ProtectionFind.ScanContent(tempfile);
+
+ // If tempfile cleanup fails
+ try
+ {
+ File.Delete(tempfile);
+ }
+ catch { }
+
+ if (!string.IsNullOrEmpty(protection))
+ protections.Add($"\r\n{sub.Filename} - {protection}");
+ }
+ catch { }
+ }
+
+ // If temp directory cleanup fails
+ try
+ {
+ Directory.Delete(tempPath, true);
+ }
+ catch { }
+ }
+ }
+ catch { }
+
+ return protections;
+ }
+ }
+}
diff --git a/BurnOutSharp/FileType/PKZIP.cs b/BurnOutSharp/FileType/PKZIP.cs
new file mode 100644
index 00000000..41f520dd
--- /dev/null
+++ b/BurnOutSharp/FileType/PKZIP.cs
@@ -0,0 +1,79 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using SharpCompress.Archives;
+using SharpCompress.Archives.Zip;
+
+namespace BurnOutSharp.FileType
+{
+ internal class PKZIP
+ {
+ public static bool ShouldScan(byte[] magic)
+ {
+ // PKZIP
+ if (magic.StartsWith(new byte[] { 0x50, 0x4b, 0x03, 0x04 }))
+ return true;
+
+ // PKZIP (Empty Archive)
+ if (magic.StartsWith(new byte[] { 0x50, 0x4b, 0x05, 0x06 }))
+ return true;
+
+ // PKZIP (Spanned Archive)
+ if (magic.StartsWith(new byte[] { 0x50, 0x4b, 0x07, 0x08 }))
+ return true;
+
+ return false;
+ }
+
+ public static List Scan(Stream stream)
+ {
+ List protections = new List();
+
+ // If the zip file itself fails
+ try
+ {
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (ZipArchive zipFile = ZipArchive.Open(stream))
+ {
+ foreach (var entry in zipFile.Entries)
+ {
+ // If an individual entry fails
+ try
+ {
+ // If we have a directory, skip it
+ if (entry.IsDirectory)
+ continue;
+
+ string tempfile = Path.Combine(tempPath, entry.Key);
+ entry.WriteToFile(tempfile);
+ string protection = ProtectionFind.ScanContent(tempfile);
+
+ // If tempfile cleanup fails
+ try
+ {
+ File.Delete(tempfile);
+ }
+ catch { }
+
+ if (!string.IsNullOrEmpty(protection))
+ protections.Add($"\r\n{entry.Key} - {protection}");
+ }
+ catch { }
+ }
+
+ // If temp directory cleanup fails
+ try
+ {
+ Directory.Delete(tempPath, true);
+ }
+ catch { }
+ }
+ }
+ catch { }
+
+ return protections;
+ }
+ }
+}
diff --git a/BurnOutSharp/FileType/RAR.cs b/BurnOutSharp/FileType/RAR.cs
new file mode 100644
index 00000000..6ae00055
--- /dev/null
+++ b/BurnOutSharp/FileType/RAR.cs
@@ -0,0 +1,75 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using SharpCompress.Archives;
+using SharpCompress.Archives.Rar;
+
+namespace BurnOutSharp.FileType
+{
+ internal class RAR
+ {
+ public static bool ShouldScan(byte[] magic)
+ {
+ // RAR archive version 1.50 onwards
+ if (magic.StartsWith(new byte[] { 0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x00 }))
+ return true;
+
+ // RAR archive version 5.0 onwards
+ if (magic.StartsWith(new byte[] { 0x52, 0x61, 0x72, 0x21, 0x1a, 0x07, 0x01, 0x00 }))
+ return true;
+
+ return false;
+ }
+
+ public static List Scan(Stream stream)
+ {
+ List protections = new List();
+
+ // If the rar file itself fails
+ try
+ {
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (RarArchive zipFile = RarArchive.Open(stream))
+ {
+ foreach (var entry in zipFile.Entries)
+ {
+ // If an individual entry fails
+ try
+ {
+ // If we have a directory, skip it
+ if (entry.IsDirectory)
+ continue;
+
+ string tempfile = Path.Combine(tempPath, entry.Key);
+ entry.WriteToFile(tempfile);
+ string protection = ProtectionFind.ScanContent(tempfile);
+
+ // If tempfile cleanup fails
+ try
+ {
+ File.Delete(tempfile);
+ }
+ catch { }
+
+ if (!string.IsNullOrEmpty(protection))
+ protections.Add($"\r\n{entry.Key} - {protection}");
+ }
+ catch { }
+ }
+
+ // If temp directory cleanup fails
+ try
+ {
+ Directory.Delete(tempPath, true);
+ }
+ catch { }
+ }
+ }
+ catch { }
+
+ return protections;
+ }
+ }
+}
diff --git a/BurnOutSharp/FileType/SevenZip.cs b/BurnOutSharp/FileType/SevenZip.cs
new file mode 100644
index 00000000..76c520a4
--- /dev/null
+++ b/BurnOutSharp/FileType/SevenZip.cs
@@ -0,0 +1,70 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using SharpCompress.Archives;
+using SharpCompress.Archives.SevenZip;
+
+namespace BurnOutSharp.FileType
+{
+ internal class SevenZip
+ {
+ public static bool ShouldScan(byte[] magic)
+ {
+ if (magic.StartsWith(new byte[] { 0x37, 0x7a, 0xbc, 0xaf, 0x27, 0x1c }))
+ return true;
+
+ return false;
+ }
+
+ public static List Scan(Stream stream)
+ {
+ List protections = new List();
+
+ // If the 7-zip file itself fails
+ try
+ {
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (SevenZipArchive sevenZipFile = SevenZipArchive.Open(stream))
+ {
+ foreach (var entry in sevenZipFile.Entries)
+ {
+ // If an individual entry fails
+ try
+ {
+ // If we have a directory, skip it
+ if (entry.IsDirectory)
+ continue;
+
+ string tempfile = Path.Combine(tempPath, entry.Key);
+ entry.WriteToFile(tempfile);
+ string protection = ProtectionFind.ScanContent(tempfile);
+
+ // If tempfile cleanup fails
+ try
+ {
+ File.Delete(tempfile);
+ }
+ catch { }
+
+ if (!string.IsNullOrEmpty(protection))
+ protections.Add($"\r\n{entry.Key} - {protection}");
+ }
+ catch { }
+ }
+
+ // If temp directory cleanup fails
+ try
+ {
+ Directory.Delete(tempPath, true);
+ }
+ catch { }
+ }
+ }
+ catch { }
+
+ return protections;
+ }
+ }
+}
diff --git a/BurnOutSharp/FileType/TapeArchive.cs b/BurnOutSharp/FileType/TapeArchive.cs
new file mode 100644
index 00000000..667f38be
--- /dev/null
+++ b/BurnOutSharp/FileType/TapeArchive.cs
@@ -0,0 +1,73 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using SharpCompress.Archives;
+using SharpCompress.Archives.Tar;
+
+namespace BurnOutSharp.FileType
+{
+ internal class TapeArchive
+ {
+ public static bool ShouldScan(byte[] magic)
+ {
+ if (magic.StartsWith(new byte[] { 0x75, 0x73, 0x74, 0x61, 0x72, 0x00, 0x30, 0x30 }))
+ return true;
+
+ if (magic.StartsWith(new byte[] { 0x75, 0x73, 0x74, 0x61, 0x72, 0x20, 0x20, 0x00 }))
+ return true;
+
+ return false;
+ }
+
+ public static List Scan(Stream stream)
+ {
+ List protections = new List();
+
+ // If the tar file itself fails
+ try
+ {
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (TarArchive tarFile = TarArchive.Open(stream))
+ {
+ foreach (var entry in tarFile.Entries)
+ {
+ // If an individual entry fails
+ try
+ {
+ // If we have a directory, skip it
+ if (entry.IsDirectory)
+ continue;
+
+ string tempfile = Path.Combine(tempPath, entry.Key);
+ entry.WriteToFile(tempfile);
+ string protection = ProtectionFind.ScanContent(tempfile);
+
+ // If tempfile cleanup fails
+ try
+ {
+ File.Delete(tempfile);
+ }
+ catch { }
+
+ if (!string.IsNullOrEmpty(protection))
+ protections.Add($"\r\n{entry.Key} - {protection}");
+ }
+ catch { }
+ }
+
+ // If temp directory cleanup fails
+ try
+ {
+ Directory.Delete(tempPath, true);
+ }
+ catch { }
+ }
+ }
+ catch { }
+
+ return protections;
+ }
+ }
+}
diff --git a/BurnOutSharp/FileType/Textfile.cs b/BurnOutSharp/FileType/Textfile.cs
new file mode 100644
index 00000000..5c8c9c41
--- /dev/null
+++ b/BurnOutSharp/FileType/Textfile.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using System.Text;
+
+namespace BurnOutSharp.FileType
+{
+ internal class Textfile
+ {
+ public static bool ShouldScan(byte[] magic, string extension)
+ {
+ // Rich Text File
+ if (magic.StartsWith(new byte[] { 0x7b, 0x5c, 0x72, 0x74, 0x66, 0x31 }))
+ return true;
+
+ // HTML
+ if (magic.StartsWith(new byte[] { 0x3c, 0x68, 0x74, 0x6d, 0x6c }))
+ return true;
+
+ // HTML and XML
+ if (magic.StartsWith(new byte[] { 0x3c, 0x21, 0x44, 0x4f, 0x43, 0x54, 0x59, 0x50, 0x45 }))
+ return true;
+
+ // Microsoft Office File (old)
+ if (magic.StartsWith(new byte[] { 0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1 }))
+ return true;
+
+ // Generic textfile (no header)
+ if (string.Equals(extension, "txt", StringComparison.OrdinalIgnoreCase))
+ return true;
+
+ return false;
+ }
+
+ public static List Scan(Stream stream)
+ {
+ List protections = new List();
+
+ try
+ {
+ // Load the current file content
+ string fileContent = null;
+ using (StreamReader sr = new StreamReader(stream, Encoding.Default, false, 1024 * 1024, true))
+ {
+ fileContent = sr.ReadToEnd();
+ }
+
+ // CD-Key
+ if (fileContent.Contains("a valid serial number is required")
+ || fileContent.Contains("serial number is located"))
+ {
+ protections.Add("CD-Key / Serial");
+ }
+ }
+ catch
+ {
+ // We don't care what the error was
+ }
+
+ return protections;
+ }
+ }
+}
diff --git a/BurnOutSharp/FileType/Valve.cs b/BurnOutSharp/FileType/Valve.cs
new file mode 100644
index 00000000..ab8acd51
--- /dev/null
+++ b/BurnOutSharp/FileType/Valve.cs
@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using HLExtract.Net;
+
+namespace BurnOutSharp.FileType
+{
+ internal class Valve
+ {
+ public static bool ShouldScan(byte[] magic)
+ {
+ // GCF
+ if (magic.StartsWith(new byte[] { 0x01, 0x00, 0x00, 0x00 }))
+ return true;
+
+ // PAK
+ if (magic.StartsWith(new byte[] { 0x50, 0x41, 0x43, 0x4b }))
+ return true;
+
+ // SGA
+ if (magic.StartsWith(new byte[] { 0x5f, 0x41, 0x52, 0x43, 0x48, 0x49, 0x56, 0x45 }))
+ return true;
+
+ // VPK
+ if (magic.StartsWith(new byte[] { 0x55, 0xaa, 0x12, 0x34 }))
+ return true;
+
+ // WAD
+ if (magic.StartsWith(new byte[] { 0x57, 0x41, 0x44, 0x33 }))
+ return true;
+
+ return false;
+ }
+
+ // TODO: Add stream opening support
+ public static List Scan(string file)
+ {
+ List protections = new List();
+
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ string[] args = new string[]
+ {
+ "-p", file,
+ "-x", "root",
+ "-x", "'extract .'",
+ "-x", "exit",
+ "-d", tempPath,
+ };
+
+ HLExtractProgram.Process(args);
+
+ if (Directory.Exists(tempPath))
+ {
+ foreach (string tempFile in Directory.EnumerateFiles(tempPath, "*", SearchOption.AllDirectories))
+ {
+ string protection = ProtectionFind.ScanContent(tempFile);
+
+ // If tempfile cleanup fails
+ try
+ {
+ File.Delete(tempFile);
+ }
+ catch { }
+
+ if (!string.IsNullOrEmpty(protection))
+ protections.Add(tempFile);
+ }
+ }
+
+ // If temp directory cleanup fails
+ try
+ {
+ Directory.Delete(tempPath, true);
+ }
+ catch { }
+
+ return protections;
+ }
+ }
+}
diff --git a/BurnOutSharp/FileType/XZ.cs b/BurnOutSharp/FileType/XZ.cs
new file mode 100644
index 00000000..9adbd845
--- /dev/null
+++ b/BurnOutSharp/FileType/XZ.cs
@@ -0,0 +1,66 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using SharpCompress.Compressors.Xz;
+
+namespace BurnOutSharp.FileType
+{
+ internal class XZ
+ {
+ public static bool ShouldScan(byte[] magic)
+ {
+ if (magic.StartsWith(new byte[] { 0xfd, 0x37, 0x7a, 0x58, 0x5a, 0x00 }))
+ return true;
+
+ return false;
+ }
+
+ public static List Scan(Stream stream)
+ {
+ List protections = new List();
+
+ // If the 7-zip file itself fails
+ try
+ {
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ using (XZStream xzFile = new XZStream(stream))
+ {
+ // If an individual entry fails
+ try
+ {
+ string tempfile = Path.Combine(tempPath, Guid.NewGuid().ToString());
+ using (FileStream fs = File.OpenWrite(tempfile))
+ {
+ xzFile.CopyTo(fs);
+ }
+
+ string protection = ProtectionFind.ScanContent(tempfile);
+
+ // If tempfile cleanup fails
+ try
+ {
+ File.Delete(tempfile);
+ }
+ catch { }
+
+ if (!string.IsNullOrEmpty(protection))
+ protections.Add($"\r\n{protection}");
+ }
+ catch { }
+
+ // If temp directory cleanup fails
+ try
+ {
+ Directory.Delete(tempPath, true);
+ }
+ catch { }
+ }
+ }
+ catch { }
+
+ return protections;
+ }
+ }
+}
diff --git a/BurnOutSharp/HLLib.x64.dll b/BurnOutSharp/HLLib.x64.dll
new file mode 100644
index 00000000..e1cf3fa1
Binary files /dev/null and b/BurnOutSharp/HLLib.x64.dll differ
diff --git a/BurnOutSharp/HLLib.x86.dll b/BurnOutSharp/HLLib.x86.dll
new file mode 100644
index 00000000..087a5416
Binary files /dev/null and b/BurnOutSharp/HLLib.x86.dll differ
diff --git a/BurnOutSharp/ProtectionFind.cs b/BurnOutSharp/ProtectionFind.cs
index e77e189f..815b5df5 100644
--- a/BurnOutSharp/ProtectionFind.cs
+++ b/BurnOutSharp/ProtectionFind.cs
@@ -20,12 +20,9 @@ using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
-using System.Text;
-using System.Text.RegularExpressions;
using System.Threading;
+using BurnOutSharp.FileType;
using BurnOutSharp.ProtectionType;
-using LibMSPackN;
-using UnshieldSharp;
namespace BurnOutSharp
{
@@ -53,7 +50,7 @@ namespace BurnOutSharp
protections[path] = fileProtection;
// Now check to see if the file contains any additional information
- string contentProtection = ScanInFile(path)?.Replace("" + (char)0x00, "");
+ string contentProtection = ScanContent(path)?.Replace("" + (char)0x00, "");
if (!string.IsNullOrWhiteSpace(contentProtection))
{
if (protections.ContainsKey(path))
@@ -88,7 +85,7 @@ namespace BurnOutSharp
protections[file] = fileProtection;
// Now check to see if the file contains any additional information
- string contentProtection = ScanInFile(file)?.Replace("" + (char)0x00, "");
+ string contentProtection = ScanContent(file)?.Replace("" + (char)0x00, "");
if (!string.IsNullOrWhiteSpace(contentProtection))
{
if (protections.ContainsKey(file))
@@ -350,190 +347,12 @@ namespace BurnOutSharp
/// Scan an individual file for copy protection
///
/// File path for scanning
- public static string ScanInFile(string file)
+ public static string ScanContent(string file)
{
- // Get the extension for certain checks
- string extension = Path.GetExtension(file).ToLower().TrimStart('.');
-
- // Read the first 8 bytes to get the file type
- string magic = "";
- try
+ using (FileStream fs = File.OpenRead(file))
{
- using (BinaryReader br = new BinaryReader(File.OpenRead(file)))
- {
- magic = new string(br.ReadChars(8));
- }
+ return ScanContent(fs, file);
}
- catch
- {
- // We don't care what the issue was, we can't open the file
- return null;
- }
-
- // Files can be protected in multiple ways
- List protections = new List();
-
- #region Executable Content Checks
-
- if (magic.StartsWith("MZ") // Windows Executable and DLL
- || magic.StartsWith((char)0x7f + "ELF") // Unix binaries
- || magic.StartsWith("" + (char)0xfe + (char)0xed + (char)0xfa + (char)0xce) // Macintosh
- || magic.StartsWith("" + (char)0xce + (char)0xfa + (char)0xed + (char)0xfe) // Macintosh
- || magic.StartsWith("Joy!peff")) // Macintosh
- {
- try
- {
- // Load the current file content
- string fileContent = null;
- using (StreamReader sr = new StreamReader(file, Encoding.Default))
- {
- fileContent = sr.ReadToEnd();
- }
-
- protections.AddRange(ScanFileContent(file, fileContent));
- }
- catch { }
- }
-
- #endregion
-
- #region Textfile Content Checks
-
- if (magic.StartsWith("{\rtf") // Rich Text File
- || magic.StartsWith("" + (char)0xd0 + (char)0xcf + (char)0x11 + (char)0xe0 + (char)0xa1 + (char)0xb1 + (char)0x1a + (char)0xe1) // Microsoft Office File (old)
- || extension == "txt") // Generic textfile (no header)
- {
- try
- {
- StreamReader sr = File.OpenText(file);
- string FileContent = sr.ReadToEnd().ToLower();
- sr.Close();
-
- // CD-Key
- if (FileContent.Contains("a valid serial number is required")
- || FileContent.Contains("serial number is located"))
- {
- protections.Add("CD-Key / Serial");
- }
- }
- catch
- {
- // We don't care what the error was
- }
- }
-
- #endregion
-
- #region Archive Content Checks
-
- // 7-zip
- if (magic.StartsWith("7z" + (char)0xbc + (char)0xaf + (char)0x27 + (char)0x1c))
- {
- // No-op
- }
-
- // InstallShield CAB
- else if (magic.StartsWith("ISc"))
- {
- // Get the name of the first cabinet file or header
- string directory = Path.GetDirectoryName(file);
- string noExtension = Path.GetFileNameWithoutExtension(file);
- string filenamePattern = Path.Combine(directory, noExtension);
- filenamePattern = new Regex(@"\d+$").Replace(filenamePattern, string.Empty);
-
- bool cabinetHeaderExists = File.Exists(Path.Combine(directory, filenamePattern + "1.hdr"));
- bool shouldScanCabinet = cabinetHeaderExists
- ? file.Equals(Path.Combine(directory, filenamePattern + "1.hdr"), StringComparison.OrdinalIgnoreCase)
- : file.Equals(Path.Combine(directory, filenamePattern + "1.cab"), StringComparison.OrdinalIgnoreCase);
-
- // If we have the first file
- if (shouldScanCabinet)
- {
- try
- {
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- UnshieldCabinet cabfile = UnshieldCabinet.Open(file);
- for (int i = 0; i < cabfile.FileCount; i++)
- {
- string tempFileName = Path.Combine(tempPath, cabfile.FileName(i));
- if (cabfile.FileSave(i, tempFileName))
- {
- string protection = ScanInFile(tempFileName);
- try
- {
- File.Delete(tempFileName);
- }
- catch { }
-
- if (!string.IsNullOrEmpty(protection))
- protections.Add(protection);
- }
- }
-
- try
- {
- Directory.Delete(tempPath, true);
- }
- catch { }
- }
- catch { }
- }
- }
-
- // Microsoft CAB
- else if (magic.StartsWith("MSCF"))
- {
- try
- {
- string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(tempPath);
-
- using (MSCabinet cabfile = new MSCabinet(file))
- {
- foreach (var sub in cabfile.GetFiles())
- {
- string tempfile = Path.Combine(tempPath, sub.Filename);
- sub.ExtractTo(tempfile);
- string protection = ScanInFile(tempfile);
- File.Delete(tempfile);
-
- if (!string.IsNullOrEmpty(protection))
- protections.Add(protection);
- }
-
- try
- {
- Directory.Delete(tempPath, true);
- }
- catch { }
- }
- }
- catch { }
- }
-
- // PKZIP
- else if (magic.StartsWith("PK" + (char)03 + (char)04)
- || magic.StartsWith("PK" + (char)05 + (char)06)
- || magic.StartsWith("PK" + (char)07 + (char)08))
- {
- // No-op
- }
-
- // RAR
- else if (magic.StartsWith("Rar!"))
- {
- // No-op
- }
-
- #endregion
-
- // Return blank if nothing found, or comma-separated list of protections
- if (protections.Count() == 0)
- return string.Empty;
- else
- return string.Join(", ", protections);
}
///
@@ -541,115 +360,82 @@ namespace BurnOutSharp
///
/// Generic stream to scan
/// File path to be used for name checks (optional)
- public static string ScanInFile(Stream stream, string file = null)
+ public static string ScanContent(Stream stream, string file = null)
{
+ // Get the extension for certain checks
+ string extension = Path.GetExtension(file).ToLower().TrimStart('.');
+
// Assume the first part of the stream is the start of a file
- string magic = "";
+ byte[] magic = new byte[16];
try
{
- using (BinaryReader br = new BinaryReader(stream, Encoding.Default, true))
- {
- magic = new string(br.ReadChars(8));
- }
+ stream.Read(magic, 0, 16);
+ stream.Seek(-16, SeekOrigin.Current);
}
catch
{
- // We don't care what the issue was, we can't open the file
+ // We don't care what the issue was, we can't read or seek the file
return null;
}
- // If we can, seek to the beginning of the stream
- if (stream.CanSeek)
- stream.Seek(0, SeekOrigin.Begin);
-
// Files can be protected in multiple ways
List protections = new List();
- #region Executable Content Checks
+ // 7-Zip archive
+ if (SevenZip.ShouldScan(magic))
+ protections.AddRange(SevenZip.Scan(stream));
- // Windows Executable and DLL
- if (magic.StartsWith("MZ"))
- {
- try
- {
- // Load the current file content
- string fileContent = null;
- using (StreamReader sr = new StreamReader(stream, Encoding.Default))
- {
- fileContent = sr.ReadToEnd();
- }
+ // BFPK archive
+ if (BFPK.ShouldScan(magic))
+ protections.AddRange(BFPK.Scan(stream));
- protections.AddRange(ScanFileContent(file, fileContent));
- }
- catch { }
- }
+ // BZip2
+ if (BZip2.ShouldScan(magic))
+ protections.AddRange(BZip2.Scan(stream));
- #endregion
+ // Executable
+ if (Executable.ShouldScan(magic))
+ protections.AddRange(Executable.Scan(stream, file));
- #region Textfile Content Checks
+ // GZIP
+ if (GZIP.ShouldScan(magic))
+ protections.AddRange(GZIP.Scan(stream));
- if (magic.StartsWith("{\rtf") // Rich Text File
- || magic.StartsWith("" + (char)0xd0 + (char)0xcf + (char)0x11 + (char)0xe0 + (char)0xa1 + (char)0xb1 + (char)0x1a + (char)0xe1)) // Microsoft Office File (old)
- {
- try
- {
- // Load the current file content
- string fileContent = null;
- using (StreamReader sr = new StreamReader(stream))
- {
- fileContent = sr.ReadToEnd();
- }
+ // InstallShield Cabinet
+ if (file != null && InstallShieldCAB.ShouldScan(magic))
+ protections.AddRange(InstallShieldCAB.Scan(file));
- // CD-Key
- if (fileContent.Contains("a valid serial number is required")
- || fileContent.Contains("serial number is located"))
- {
- protections.Add("CD-Key / Serial");
- }
- }
- catch
- {
- // We don't care what the error was
- }
- }
+ // Microsoft Cabinet
+ if (file != null && MicrosoftCAB.ShouldScan(magic))
+ protections.AddRange(MicrosoftCAB.Scan(file));
- #endregion
+ // MPQ archive
+ if (file != null && MPQ.ShouldScan(magic))
+ protections.AddRange(MPQ.Scan(file));
- #region Archive Content Checks
+ // PKZIP archive (and derivatives)
+ if (PKZIP.ShouldScan(magic))
+ protections.AddRange(PKZIP.Scan(stream));
- // 7-zip
- if (magic.StartsWith("7z" + (char)0xbc + (char)0xaf + (char)0x27 + (char)0x1c))
- {
- // No-op
- }
+ // RAR archive
+ if (RAR.ShouldScan(magic))
+ protections.AddRange(RAR.Scan(stream));
- // InstallShield CAB
- else if (magic.StartsWith("ISc"))
- {
- // TODO: Update UnshieldSharp to include generic stream support
- }
+ // Tape Archive
+ if (TapeArchive.ShouldScan(magic))
+ protections.AddRange(TapeArchive.Scan(stream));
- // Microsoft CAB
- else if (magic.StartsWith("MSCF"))
- {
- // TODO: See if LibMSPackN can use generic streams
- }
+ // Text-based files
+ if (Textfile.ShouldScan(magic, extension))
+ protections.AddRange(Textfile.Scan(stream));
- // PKZIP
- else if (magic.StartsWith("PK" + (char)03 + (char)04)
- || magic.StartsWith("PK" + (char)05 + (char)06)
- || magic.StartsWith("PK" + (char)07 + (char)08))
- {
- // No-op
- }
+ // Valve archive formats
+ if (file != null && Valve.ShouldScan(magic))
+ protections.AddRange(Valve.Scan(file));
- // RAR
- else if (magic.StartsWith("Rar!"))
- {
- // No-op
- }
-
- #endregion
+ // XZ
+ if (XZ.ShouldScan(magic))
+ protections.AddRange(XZ.Scan(stream));
// Return blank if nothing found, or comma-separated list of protections
if (protections.Count() == 0)
@@ -658,204 +444,6 @@ namespace BurnOutSharp
return string.Join(", ", protections);
}
- ///
- /// Scan the contents of a file for protection
- ///
- /// TODO: This needs to work on a byte array of file content instead of string
- private static List ScanFileContent(string file, string fileContent)
- {
- // Files can be protected in multiple ways
- List protections = new List();
- string protection;
-
- // 3PLock
- protection = ThreePLock.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // ActiveMARK
- protection = ActiveMARK.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // Alpha-ROM
- protection = AlphaROM.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // Armadillo
- protection = Armadillo.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // CD-Cops
- protection = CDCops.CheckContents(file, fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // CD-Lock
- protection = CDLock.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // CDSHiELD SE
- protection = CDSHiELDSE.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // CD Check
- protection = CDCheck.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // Cenega ProtectDVD
- protection = CengaProtectDVD.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // Code Lock
- protection = CodeLock.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // CopyKiller
- protection = CopyKiller.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // Cucko (EA Custom)
- protection = Cucko.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // dotFuscator
- protection = dotFuscator.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // DVD-Cops
- protection = DVDCops.CheckContents(file, fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // EA CdKey Registration Module
- protection = EACdKey.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // EXE Stealth
- protection = EXEStealth.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // Games for Windows - Live
- protection = GFWL.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // Impulse Reactor
- protection = ImpulseReactor.CheckContents(file, fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // Inno Setup
- protection = InnoSetup.CheckContents(file, fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // JoWooD X-Prot
- protection = JoWooDXProt.CheckContents(file, fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // Key-Lock (Dongle)
- protection = KeyLock.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // LaserLock
- protection = LaserLock.CheckContents(file, fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // PE Compact
- protection = PECompact.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // ProtectDisc
- protection = ProtectDisc.CheckContents(file, fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // Ring PROTECH
- protection = RingPROTECH.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // SafeDisc / SafeCast
- protection = SafeDisc.CheckContents(file, fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // SafeLock
- protection = SafeLock.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // SecuROM
- protection = SecuROM.CheckContents(file, fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // SmartE
- protection = SmartE.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // SolidShield
- protection = SolidShield.CheckContents(file, fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // StarForce
- protection = StarForce.CheckContents(file, fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // SVK Protector
- protection = SVKProtector.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // Sysiphus / Sysiphus DVD
- protection = Sysiphus.CheckContents(file, fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // TAGES
- protection = Tages.CheckContents(file, fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // VOB ProtectCD/DVD
- protection = VOBProtectCDDVD.CheckContents(file, fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // WTM CD Protect
- protection = WTMCDProtect.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- // Xtreme-Protector
- protection = XtremeProtector.CheckContents(fileContent);
- if (!string.IsNullOrWhiteSpace(protection))
- protections.Add(protection);
-
- return protections;
- }
-
///
/// Scan a disc sector by sector for protection
///
diff --git a/BurnOutSharp/ProtectionType/ActiveMARK.cs b/BurnOutSharp/ProtectionType/ActiveMARK.cs
index 8c59cf45..cf9231c4 100644
--- a/BurnOutSharp/ProtectionType/ActiveMARK.cs
+++ b/BurnOutSharp/ProtectionType/ActiveMARK.cs
@@ -2,17 +2,17 @@
{
public class ActiveMARK
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("TMSAMVOF"))
- return "ActiveMARK";
+ // "TMSAMVOF"
+ byte[] check = new byte[] { 0x54, 0x4D, 0x53, 0x41, 0x4D, 0x56, 0x4F, 0x46 };
+ if (fileContent.Contains(check, out int position))
+ return $"ActiveMARK (Index {position})";
- if (fileContent.Contains(" " + (char)0xC2 + (char)0x16 + (char)0x00 + (char)0xA8 + (char)0xC1 + (char)0x16
- + (char)0x00 + (char)0xB8 + (char)0xC1 + (char)0x16 + (char)0x00 + (char)0x86 + (char)0xC8 + (char)0x16 + (char)0x0
- + (char)0x9A + (char)0xC1 + (char)0x16 + (char)0x00 + (char)0x10 + (char)0xC2 + (char)0x16 + (char)0x00))
- {
- return "ActiveMARK 5";
- }
+ // " " + (char)0xC2 + (char)0x16 + (char)0x00 + (char)0xA8 + (char)0xC1 + (char)0x16 + (char)0x00 + (char)0xB8 + (char)0xC1 + (char)0x16 + (char)0x00 + (char)0x86 + (char)0xC8 + (char)0x16 + (char)0x0 + (char)0x9A + (char)0xC1 + (char)0x16 + (char)0x00 + (char)0x10 + (char)0xC2 + (char)0x16 + (char)0x00
+ check = new byte[] { 0x20, 0xC2, 0x16, 0x00, 0xA8, 0xC1, 0x16, 0x00, 0xB8, 0xC1, 0x16, 0x00, 0x86, 0xC8, 0x16, 0x0, 0x9A, 0xC1, 0x16, 0x00, 0x10, 0xC2, 0x16, 0x00 };
+ if (fileContent.Contains(check, out position))
+ return $"ActiveMARK 5 (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/AlphaROM.cs b/BurnOutSharp/ProtectionType/AlphaROM.cs
index b6d6292d..1d32ae1c 100644
--- a/BurnOutSharp/ProtectionType/AlphaROM.cs
+++ b/BurnOutSharp/ProtectionType/AlphaROM.cs
@@ -2,10 +2,12 @@
{
public class AlphaROM
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("SETTEC"))
- return "Alpha-ROM";
+ // "SETTEC"
+ byte[] check = new byte[] { 0x53, 0x45, 0x54, 0x54, 0x45, 0x43 };
+ if (fileContent.Contains(check, out int position))
+ return $"Alpha-ROM (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/Armadillo.cs b/BurnOutSharp/ProtectionType/Armadillo.cs
index 39aaa58a..61d10f08 100644
--- a/BurnOutSharp/ProtectionType/Armadillo.cs
+++ b/BurnOutSharp/ProtectionType/Armadillo.cs
@@ -2,11 +2,17 @@
{
public class Armadillo
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains(".nicode" + (char)0x00)
- || fileContent.Contains("ARMDEBUG"))
- return "Armadillo";
+ // ".nicode" + (char)0x00
+ byte[] check = new byte[] { 0x2E, 0x6E, 0x69, 0x63, 0x6F, 0x64, 0x65, 0x00 };
+ if (fileContent.Contains(check, out int position))
+ return $"Armadillo (Index {position})";
+
+ // "ARMDEBUG"
+ check = new byte[] { 0x41, 0x52, 0x4D, 0x44, 0x45, 0x42, 0x55, 0x47 };
+ if (fileContent.Contains(check, out position))
+ return $"Armadillo (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/CDCheck.cs b/BurnOutSharp/ProtectionType/CDCheck.cs
index 4a18b340..c0ce056f 100644
--- a/BurnOutSharp/ProtectionType/CDCheck.cs
+++ b/BurnOutSharp/ProtectionType/CDCheck.cs
@@ -2,11 +2,17 @@
{
public class CDCheck
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("GetDriveType")
- || fileContent.Contains("GetVolumeInformation"))
- return "CD Check";
+ // "GetDriveType"
+ byte[] check = new byte[] { 0x47, 0x65, 0x74, 0x44, 0x72, 0x69, 0x76, 0x65, 0x54, 0x79, 0x70, 0x65 };
+ if (fileContent.Contains(check, out int position))
+ return $"CD Check (Index {position})";
+
+ // "GetVolumeInformation"
+ check = new byte[] { 0x47, 0x65, 0x74, 0x56, 0x6F, 0x6C, 0x75, 0x6D, 0x65, 0x49, 0x6E, 0x66, 0x6F, 0x72, 0x6D, 0x61, 0x74, 0x69, 0x6F, 0x6E };
+ if (fileContent.Contains(check, out position))
+ return $"CD Check (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/CDCops.cs b/BurnOutSharp/ProtectionType/CDCops.cs
index ad70618d..6f39ef2e 100644
--- a/BurnOutSharp/ProtectionType/CDCops.cs
+++ b/BurnOutSharp/ProtectionType/CDCops.cs
@@ -7,14 +7,17 @@ namespace BurnOutSharp.ProtectionType
{
public class CDCops
{
- public static string CheckContents(string file, string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- int position;
- if ((position = fileContent.IndexOf("CD-Cops, ver. ")) > -1)
- return "CD-Cops " + GetVersion(file, position);
+ // "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))
+ return $"CD-Cops {GetVersion(fileContent, position)} (Index {position})";
- if (fileContent.Contains(".grand" + (char)0x00))
- return "CD-Cops";
+ // ".grand" + (char)0x00
+ check = new byte[] { 0x2E, 0x67, 0x72, 0x61, 0x6E, 0x64, 0x00};
+ if (fileContent.Contains(check, out position))
+ return $"CD-Cops (Index {position})";
return null;
}
@@ -47,21 +50,13 @@ namespace BurnOutSharp.ProtectionType
return null;
}
- private static string GetVersion(string file, int position)
+ private static string GetVersion(byte[] fileContent, int position)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
+ char[] version = new ArraySegment(fileContent, position + 15, 4).Select(b => (char)b).ToArray();
+ if (version[0] == 0x00)
+ return "";
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
- {
- br.BaseStream.Seek(position + 15, SeekOrigin.Begin); // Begin reading after "CD-Cops, ver."
- char[] version = br.ReadChars(4);
- if (version[0] == 0x00)
- return "";
-
- return new string(version);
- }
+ return new string(version);
}
}
}
diff --git a/BurnOutSharp/ProtectionType/CDLock.cs b/BurnOutSharp/ProtectionType/CDLock.cs
index 06bbae10..68c1733d 100644
--- a/BurnOutSharp/ProtectionType/CDLock.cs
+++ b/BurnOutSharp/ProtectionType/CDLock.cs
@@ -7,14 +7,12 @@ namespace BurnOutSharp.ProtectionType
{
public class CDLock
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("2" + (char)0xF2 + (char)0x02 + (char)0x82 + (char)0xC3 + (char)0xBC + (char)0x0B
- + "$" + (char)0x99 + (char)0xAD + "'C" + (char)0xE4 + (char)0x9D + "st"
- + (char)0x99 + (char)0xFA + "2$" + (char)0x9D + ")4" + (char)0xFF + "t"))
- {
- return "CD-Lock";
- }
+ // "2" + (char)0xF2 + (char)0x02 + (char)0x82 + (char)0xC3 + (char)0xBC + (char)0x0B + "$" + (char)0x99 + (char)0xAD + "'C" + (char)0xE4 + (char)0x9D + "st" + (char)0x99 + (char)0xFA + "2$" + (char)0x9D + ")4" + (char)0xFF + "t"
+ byte[] check = new byte[] { 0x32, 0xF2, 0x02, 0x82, 0xC3, 0xBC, 0x0B, 0x24, 0x99, 0xAD, 0x27, 0x43, 0xE4, 0x9D, 0x73, 0x74, 0x99, 0xFA, 0x32, 0x24, 0x9D, 0x29, 0x34, 0xFF, 0x74 };
+ if (fileContent.Contains(check, out int position))
+ return $"CD-Lock (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/CDSHiELDSE.cs b/BurnOutSharp/ProtectionType/CDSHiELDSE.cs
index 31d27ca7..258dea06 100644
--- a/BurnOutSharp/ProtectionType/CDSHiELDSE.cs
+++ b/BurnOutSharp/ProtectionType/CDSHiELDSE.cs
@@ -2,10 +2,12 @@
{
public class CDSHiELDSE
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("~0017.tmp"))
- return "CDSHiELD SE";
+ // "~0017.tmp"
+ byte[] check = new byte[] { 0x7E, 0x30, 0x30, 0x31, 0x37, 0x2E, 0x74, 0x6D, 0x70 };
+ if (fileContent.Contains(check, out int position))
+ return $"CDSHiELD SE (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/CengaProtectDVD.cs b/BurnOutSharp/ProtectionType/CengaProtectDVD.cs
index a4161587..860a8aeb 100644
--- a/BurnOutSharp/ProtectionType/CengaProtectDVD.cs
+++ b/BurnOutSharp/ProtectionType/CengaProtectDVD.cs
@@ -2,10 +2,12 @@
{
public class CengaProtectDVD
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains(".cenega"))
- return "Cenega ProtectDVD";
+ // ".cenega"
+ byte[] check = new byte[] { 0x2E, 0x63, 0x65, 0x6E, 0x65, 0x67, 0x61 };
+ if (fileContent.Contains(check, out int position))
+ return $"Cenega ProtectDVD (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/CodeLock.cs b/BurnOutSharp/ProtectionType/CodeLock.cs
index ad66e48f..6baae3f1 100644
--- a/BurnOutSharp/ProtectionType/CodeLock.cs
+++ b/BurnOutSharp/ProtectionType/CodeLock.cs
@@ -2,15 +2,23 @@
{
public class CodeLock
{
- public static string CheckContents(string fileContent)
+ // TODO: Verify if these are OR or AND
+ public static string CheckContents(byte[] fileContent)
{
- // TODO: Verify if these are OR or AND
- if (fileContent.Contains("icd1" + (char)0x00)
- || fileContent.Contains("icd2" + (char)0x00)
- || fileContent.Contains("CODE-LOCK.OCX"))
- {
- return "Code Lock";
- }
+ // "icd1" + (char)0x00
+ byte[] check = new byte[] { 0x69, 0x63, 0x64, 0x31, 0x00 };
+ if (fileContent.Contains(check, out int position))
+ return $"Code Lock (Index {position})";
+
+ // "icd2" + (char)0x00
+ check = new byte[] { 0x69, 0x63, 0x64, 0x32, 0x00 };
+ if (fileContent.Contains(check, out position))
+ return $"Code Lock (Index {position})";
+
+ // "CODE-LOCK.OCX"
+ check = new byte[] { 0x43, 0x4F, 0x44, 0x45, 0x2D, 0x4C, 0x4F, 0x43, 0x4B, 0x2E, 0x4F, 0x43, 0x58 };
+ if (fileContent.Contains(check, out position))
+ return $"Code Lock (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/CopyKiller.cs b/BurnOutSharp/ProtectionType/CopyKiller.cs
index b21aba12..34a6ed54 100644
--- a/BurnOutSharp/ProtectionType/CopyKiller.cs
+++ b/BurnOutSharp/ProtectionType/CopyKiller.cs
@@ -7,10 +7,12 @@ namespace BurnOutSharp.ProtectionType
{
public class CopyKiller
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("Tom Commander"))
- return "CopyKiller";
+ // "Tom Commander"
+ byte[] check = new byte[] { 0x54, 0x6F, 0x6D, 0x20, 0x43, 0x6F, 0x6D, 0x6D, 0x61, 0x6E, 0x64, 0x65, 0x72 };
+ if (fileContent.Contains(check, out int position))
+ return $"CopyKiller (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/Cucko.cs b/BurnOutSharp/ProtectionType/Cucko.cs
index 56d5588c..6b91ed46 100644
--- a/BurnOutSharp/ProtectionType/Cucko.cs
+++ b/BurnOutSharp/ProtectionType/Cucko.cs
@@ -2,11 +2,13 @@
{
public class Cucko
{
- public static string CheckContents(string fileContent)
+ // TODO: Verify this doesn't over-match
+ public static string CheckContents(byte[] fileContent)
{
- // TODO: Verify this doesn't over-match
- if (fileContent.Contains("EASTL"))
- return "Cucko (EA Custom)";
+ // "EASTL"
+ byte[] check = new byte[] { 0x45, 0x41, 0x53, 0x54, 0x4C };
+ if (fileContent.Contains(check, out int position))
+ return $"Cucko (EA Custom) (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/DVDCops.cs b/BurnOutSharp/ProtectionType/DVDCops.cs
index ed80c3fc..4566bb71 100644
--- a/BurnOutSharp/ProtectionType/DVDCops.cs
+++ b/BurnOutSharp/ProtectionType/DVDCops.cs
@@ -1,33 +1,27 @@
-using System.IO;
+using System;
+using System.Linq;
namespace BurnOutSharp.ProtectionType
{
public class DVDCops
{
- public static string CheckContents(string file, string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- int position;
- if ((position = fileContent.IndexOf("DVD-Cops, ver. ")) > -1)
- return "DVD-Cops " + GetVersion(file, position);
+ // "DVD-Cops, ver. "
+ byte[] check = new byte[] { 0x44, 0x56, 0x44, 0x2D, 0x43, 0x6F, 0x70, 0x73, 0x2C, 0x20, 0x20, 0x76, 0x65, 0x72, 0x2E, 0x20 };
+ if (fileContent.Contains(check, out int position))
+ return $"DVD-Cops {GetVersion(fileContent, position)} (Index {position})";
return null;
}
- private static string GetVersion(string file, int position)
+ private static string GetVersion(byte[] fileContent, int position)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
+ char[] version = new ArraySegment(fileContent, position + 15, 4).Select(b => (char)b).ToArray();
+ if (version[0] == 0x00)
+ return "";
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
- {
- br.BaseStream.Seek(position + 15, SeekOrigin.Begin); // Begin reading after "CD-Cops, ver."
- char[] version = br.ReadChars(4);
- if (version[0] == 0x00)
- return "";
-
- return new string(version);
- }
+ return new string(version);
}
}
}
diff --git a/BurnOutSharp/ProtectionType/EACdKey.cs b/BurnOutSharp/ProtectionType/EACdKey.cs
index fd196f2f..d4c4a8e9 100644
--- a/BurnOutSharp/ProtectionType/EACdKey.cs
+++ b/BurnOutSharp/ProtectionType/EACdKey.cs
@@ -2,10 +2,12 @@
{
public class EACdKey
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("ereg.ea-europe.com"))
- return "EA CdKey Registration Module";
+ // "ereg.ea-europe.com"
+ byte[] check = new byte[] { 0x65, 0x72, 0x65, 0x67, 0x2E, 0x65, 0x61, 0x2D, 0x65, 0x75, 0x72, 0x6F, 0x70, 0x65, 0x2E, 0x63, 0x6F, 0x6D };
+ if (fileContent.Contains(check, out int position))
+ return $"EA CdKey Registration Module (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/EXEStealth.cs b/BurnOutSharp/ProtectionType/EXEStealth.cs
index fe03597c..962b1919 100644
--- a/BurnOutSharp/ProtectionType/EXEStealth.cs
+++ b/BurnOutSharp/ProtectionType/EXEStealth.cs
@@ -2,14 +2,12 @@
{
public class EXEStealth
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("??[[__[[_" + (char)0x00 + "{{" + (char)0x0
- + (char)0x00 + "{{" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x0
- + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + "?;??;??"))
- {
- return "EXE Stealth";
- }
+ // "??[[__[[_" + (char)0x00 + "{{" + (char)0x0 + (char)0x00 + "{{" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x0 + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + "?;??;??"
+ byte[] check = new byte[] { 0x3F, 0x3F, 0x5B, 0x5B, 0x5F, 0x5F, 0x5B, 0x5B, 0x5F, 0x00, 0x7B, 0x7B, 0x00, 0x00, 0x7B, 0x7B, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x3F, 0x3B, 0x3F, 0x3F, 0x3B, 0x3F, 0x3F };
+ if (fileContent.Contains(check, out int position))
+ return $"EXE Stealth (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/GFWL.cs b/BurnOutSharp/ProtectionType/GFWL.cs
index 8424e22b..4dc0076d 100644
--- a/BurnOutSharp/ProtectionType/GFWL.cs
+++ b/BurnOutSharp/ProtectionType/GFWL.cs
@@ -7,10 +7,12 @@ namespace BurnOutSharp.ProtectionType
{
public class GFWL
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("xlive.dll"))
- return "Games for Windows - Live";
+ // "xlive.dll"
+ byte[] check = new byte[] { 0x78, 0x6C, 0x69, 0x76, 0x65, 0x2E, 0x64, 0x6C, 0x6C };
+ if (fileContent.Contains(check, out int position))
+ return $"Games for Windows - Live (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/ImpulseReactor.cs b/BurnOutSharp/ProtectionType/ImpulseReactor.cs
index ca414984..6602fabc 100644
--- a/BurnOutSharp/ProtectionType/ImpulseReactor.cs
+++ b/BurnOutSharp/ProtectionType/ImpulseReactor.cs
@@ -7,22 +7,18 @@ namespace BurnOutSharp.ProtectionType
{
public class ImpulseReactor
{
- public static string CheckContents(string file, string fileContent)
+ public static string CheckContents(string file, byte[] fileContent)
{
- if (fileContent.Contains("CVPInitializeClient"))
+ // "CVPInitializeClient"
+ byte[] check = new byte[] { 0x43, 0x56, 0x50, 0x49, 0x6E, 0x69, 0x74, 0x69, 0x61, 0x6C, 0x69, 0x7A, 0x65, 0x43, 0x6C, 0x69, 0x65, 0x6E, 0x74 };
+ if (fileContent.Contains(check, out int position))
{
- if (fileContent.Contains("A" + (char)0x00 + "T" + (char)0x00 + "T" + (char)0x00 + "L" + (char)0x00 + "I"
- + (char)0x00 + "S" + (char)0x00 + "T" + (char)0x00 + (char)0x00 + (char)0x00 + "E" + (char)0x00 + "L"
- + (char)0x00 + "E" + (char)0x00 + "M" + (char)0x00 + "E" + (char)0x00 + "N" + (char)0x00 + "T" + (char)0x00
- + (char)0x00 + (char)0x00 + "N" + (char)0x00 + "O" + (char)0x00 + "T" + (char)0x00 + "A" + (char)0x00 + "T"
- + (char)0x00 + "I" + (char)0x00 + "O" + (char)0x00 + "N"))
- {
- return "Impulse Reactor " + Utilities.GetFileVersion(file);
- }
+ // "A" + (char)0x00 + "T" + (char)0x00 + "T" + (char)0x00 + "L" + (char)0x00 + "I" + (char)0x00 + "S" + (char)0x00 + "T" + (char)0x00 + (char)0x00 + (char)0x00 + "E" + (char)0x00 + "L" + (char)0x00 + "E" + (char)0x00 + "M" + (char)0x00 + "E" + (char)0x00 + "N" + (char)0x00 + "T" + (char)0x00 + (char)0x00 + (char)0x00 + "N" + (char)0x00 + "O" + (char)0x00 + "T" + (char)0x00 + "A" + (char)0x00 + "T" + (char)0x00 + "I" + (char)0x00 + "O" + (char)0x00 + "N"
+ byte[] check2 = new byte[] { 0x41, 0x00, 0x54, 0x00, 0x54, 0x00, 0x4C, 0x00, 0x49, 0x00, 0x53, 0x00, 0x54, 0x00, 0x00, 0x00, 0x45, 0x00, 0x4C, 0x00, 0x45, 0x00, 0x4D, 0x00, 0x45, 0x00, 0x4E, 0x00, 0x54, 0x00, 0x00, 0x00, 0x4E, 0x00, 0x4F, 0x00, 0x54, 0x00, 0x41, 0x00, 0x54, 0x00, 0x49, 0x00, 0x4F, 0x00, 0x4E };
+ if (fileContent.Contains(check2, out int position2))
+ return $"Impulse Reactor {Utilities.GetFileVersion(file)} (Index {position}, {position2}";
else
- {
- return "Impulse Reactor";
- }
+ return $"Impulse Reactor (Index {position})";
}
return null;
diff --git a/BurnOutSharp/ProtectionType/InnoSetup.cs b/BurnOutSharp/ProtectionType/InnoSetup.cs
index bda474e5..c259f8f2 100644
--- a/BurnOutSharp/ProtectionType/InnoSetup.cs
+++ b/BurnOutSharp/ProtectionType/InnoSetup.cs
@@ -1,48 +1,55 @@
-using System.IO;
+using System;
+using System.Linq;
namespace BurnOutSharp.ProtectionType
{
public class InnoSetup
{
- public static string CheckContents(string file, string fileContent)
+ // TOOO: Add Inno Setup extraction
+ // https://github.com/dscharrer/InnoExtract
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.IndexOf("Inno") == 0x30)
- {
- // TOOO: Add Inno Setup extraction
- return "Inno Setup " + GetVersion(file);
- }
+ // "Inno"
+ byte[] check = new byte[] { 0x49, 0x6E, 0x6E, 0x6F };
+ if (fileContent.Contains(check, out int position) && position == 0x30)
+ return $"Inno Setup {GetVersion(fileContent)} (Index {position})";
return null;
}
- private static string GetVersion(string file)
+ private static string GetVersion(byte[] fileContent)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
+ byte[] signature = new ArraySegment(fileContent, 0x30, 12).ToArray();
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
- {
- br.BaseStream.Seek(0x30, SeekOrigin.Begin);
- string signature = new string(br.ReadChars(12));
+ // "rDlPtS02" + (char)0x87 + "eVx"
+ if (signature.SequenceEqual( new byte[] { 0x72, 0x44, 0x6C, 0x50, 0x74, 0x53, 0x30, 0x32, 0x87, 0x65, 0x56, 0x78 }))
+ return "1.2.10";
- if (signature == "rDlPtS02" + (char)0x87 + "eVx")
- return "1.2.10";
- else if (signature == "rDlPtS04" + (char)0x87 + "eVx")
- return "4.0.0";
- else if (signature == "rDlPtS05" + (char)0x87 + "eVx")
- return "4.0.3";
- else if (signature == "rDlPtS06" + (char)0x87 + "eVx")
- return "4.0.10";
- else if (signature == "rDlPtS07" + (char)0x87 + "eVx")
- return "4.1.6";
- else if (signature == "rDlPtS" + (char)0xcd + (char)0xe6 + (char)0xd7 + "{" + (char)0x0b + "*")
- return "5.1.5";
- else if (signature == "nS5W7dT" + (char)0x83 + (char)0xaa + (char)0x1b + (char)0x0f + "j")
- return "5.1.5";
+ // "rDlPtS04" + (char)0x87 + "eVx"
+ else if (signature.SequenceEqual(new byte[] { 0x72, 0x44, 0x6C, 0x50, 0x74, 0x53, 0x30, 0x34, 0x87, 0x65, 0x56, 0x78 }))
+ return "4.0.0";
- return string.Empty;
- }
+ // "rDlPtS05" + (char)0x87 + "eVx"
+ else if (signature.SequenceEqual(new byte[] { 0x72, 0x44, 0x6C, 0x50, 0x74, 0x53, 0x30, 0x35, 0x87, 0x65, 0x56, 0x78 }))
+ return "4.0.3";
+
+ // "rDlPtS06" + (char)0x87 + "eVx"
+ else if (signature.SequenceEqual(new byte[] { 0x72, 0x44, 0x6C, 0x50, 0x74, 0x53, 0x30, 0x36, 0x87, 0x65, 0x56, 0x78 }))
+ return "4.0.10";
+
+ // "rDlPtS07" + (char)0x87 + "eVx"
+ else if (signature.SequenceEqual(new byte[] { 0x72, 0x44, 0x6C, 0x50, 0x74, 0x53, 0x30, 0x37, 0x87, 0x65, 0x56, 0x78 }))
+ return "4.1.6";
+
+ // "rDlPtS" + (char)0xcd + (char)0xe6 + (char)0xd7 + "{" + (char)0x0b + "*"
+ else if (signature.SequenceEqual(new byte[] { 0x72, 0x44, 0x6C, 0x50, 0x74, 0x53, 0xCD, 0xE6, 0xD7, 0x7B, 0x0b, 0x2A }))
+ return "5.1.5";
+
+ // "nS5W7dT" + (char)0x83 + (char)0xaa + (char)0x1b + (char)0x0f + "j"
+ else if (signature.SequenceEqual(new byte[] { 0x6E, 0x53, 0x35, 0x57, 0x37, 0x64, 0x54, 0x83, 0xAA, 0x1B, 0x0F, 0x6A }))
+ return "5.1.5";
+
+ return string.Empty;
}
}
}
diff --git a/BurnOutSharp/ProtectionType/JoWooDXProt.cs b/BurnOutSharp/ProtectionType/JoWooDXProt.cs
index ac1c4a26..9d88f744 100644
--- a/BurnOutSharp/ProtectionType/JoWooDXProt.cs
+++ b/BurnOutSharp/ProtectionType/JoWooDXProt.cs
@@ -1,51 +1,36 @@
-using System.IO;
+using System;
+using System.Linq;
namespace BurnOutSharp.ProtectionType
{
public class JoWooDXProt
{
- public static string CheckContents(string file, string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- int position;
- if (fileContent.Contains(".ext "))
+ // ".ext "
+ byte[] check = new byte[] { 0x2E, 0x65, 0x78, 0x74, 0x20, 0x20, 0x20, 0x20 };
+ if (fileContent.Contains(check, out int position))
{
- if ((position = fileContent.IndexOf("kernel32.dll" + (char)0x00 + (char)0x00 + (char)0x00 + "VirtualProtect")) > -1)
- {
- return "JoWooD X-Prot " + GetVersion(file, --position);
- }
+ // "kernel32.dll" + (char)0x00 + (char)0x00 + (char)0x00 + "VirtualProtect"
+ byte[] check2 = new byte[] { 0x6B, 0x65, 0x72, 0x6E, 0x65, 0x6C, 0x33, 0x32, 0x2E, 0x64, 0x6C, 0x6C, 0x00, 0x00, 0x00, 0x56, 0x69, 0x72, 0x74, 0x75, 0x61, 0x6C, 0x50, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74 };
+ if (fileContent.Contains(check2, out int position2))
+ return $"JoWooD X-Prot {GetVersion(fileContent, --position2)} (Index {position}, {position2})";
else
- {
- return "JoWooD X-Prot v1";
- }
+ return $"JoWooD X-Prot v1 (Index {position})";
}
- if (fileContent.Contains("@HC09 "))
- return "JoWooD X-Prot v2";
+ // "@HC09 "
+ check = new byte[] { 0x40, 0x48, 0x43, 0x30, 0x39, 0x20, 0x20, 0x20, 0x20 };
+ if (fileContent.Contains(check, out position))
+ return $"JoWooD X-Prot v2 (Index {position})";
return null;
}
- private static string GetVersion(string file, int position)
+ private static string GetVersion(byte[] fileContent, int position)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
-
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
- {
- char[] version = new char[5];
- br.BaseStream.Seek(position + 67, SeekOrigin.Begin);
- version[0] = br.ReadChar();
- br.ReadByte();
- version[1] = br.ReadChar();
- br.ReadByte();
- version[2] = br.ReadChar();
- br.ReadByte();
- version[3] = br.ReadChar();
- version[4] = br.ReadChar();
-
- return version[0] + "." + version[1] + "." + version[2] + "." + version[3] + version[4];
- }
+ char[] version = new ArraySegment(fileContent, position + 67, 8).Select(b => (char)b).ToArray();
+ return $"{version[0]}.{version[2]}.{version[4]}.{version[6]}{version[7]}";
}
}
}
diff --git a/BurnOutSharp/ProtectionType/KeyLock.cs b/BurnOutSharp/ProtectionType/KeyLock.cs
index 802db143..ddaba068 100644
--- a/BurnOutSharp/ProtectionType/KeyLock.cs
+++ b/BurnOutSharp/ProtectionType/KeyLock.cs
@@ -2,10 +2,12 @@
{
public class KeyLock
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("KEY-LOCK COMMAND"))
- return "Key-Lock (Dongle)";
+ // "KEY-LOCK COMMAND"
+ byte[] check = new byte[] { 0x4B, 0x45, 0x59, 0x2D, 0x4C, 0x4F, 0x43, 0x4B, 0x20, 0x43, 0x4F, 0x4D, 0x4D, 0x41, 0x4E, 0x44 };
+ if (fileContent.Contains(check, out int position))
+ return $"Key-Lock (Dongle) (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/LaserLock.cs b/BurnOutSharp/ProtectionType/LaserLock.cs
index 2a3d2ba8..860ee6de 100644
--- a/BurnOutSharp/ProtectionType/LaserLock.cs
+++ b/BurnOutSharp/ProtectionType/LaserLock.cs
@@ -7,38 +7,35 @@ namespace BurnOutSharp.ProtectionType
{
public class LaserLock
{
- public static string CheckContents(string file, string fileContent)
+ public static string CheckContents(string file, byte[] fileContent)
{
- int position;
- if (fileContent.Contains("Packed by SPEEnc V2 Asterios Parlamentas.PE")
- && (position = fileContent.IndexOf("GetModuleHandleA" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00
- + "GetProcAddress" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + "LoadLibraryA" + (char)0x00 + (char)0x00
- + "KERNEL32.dll" + (char)0x00 + "ëy" + (char)0x01 + "SNIF")) > -1)
- {
- return "LaserLock " + GetVersion(fileContent, position) + " " + GetBuild(fileContent, true);
- }
+ // "Packed by SPEEnc V2 Asterios Parlamentas.PE"
+ byte[] check = new byte[] { 0x50, 0x61, 0x63, 0x6B, 0x65, 0x64, 0x20, 0x62, 0x79, 0x20, 0x53, 0x50, 0x45, 0x45, 0x6E, 0x63, 0x20, 0x56, 0x32, 0x20, 0x41, 0x73, 0x74, 0x65, 0x72, 0x69, 0x6F, 0x73, 0x20, 0x50, 0x61, 0x72, 0x6C, 0x61, 0x6D, 0x65, 0x6E, 0x74, 0x61, 0x73, 0x2E, 0x50, 0x45 };
+ bool containsCheck = fileContent.Contains(check, out int position);
- if (fileContent.Contains("Packed by SPEEnc V2 Asterios Parlamentas.PE"))
- return "LaserLock Marathon " + GetBuild(fileContent, false);
+ // "GetModuleHandleA" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + "GetProcAddress" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + "LoadLibraryA" + (char)0x00 + (char)0x00 + "KERNEL32.dll" + (char)0x00 + "ëy" + (char)0x01 + "SNIF"
+ byte[] check2 = { 0x47, 0x65, 0x74, 0x4D, 0x6F, 0x64, 0x75, 0x6C, 0x65, 0x48, 0x61, 0x6E, 0x64, 0x6C, 0x65, 0x41, 0x00, 0x00, 0x00, 0x00, 0x47, 0x65, 0x74, 0x50, 0x72, 0x6F, 0x63, 0x41, 0x64, 0x64, 0x72, 0x65, 0x73, 0x73, 0x00, 0x00, 0x00, 0x00, 0x4C, 0x6F, 0x61, 0x64, 0x4C, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79, 0x41, 0x00, 0x00, 0x4B, 0x45, 0x52, 0x4E, 0x45, 0x4C, 0x33, 0x32, 0x2E, 0x64, 0x6C, 0x6C, 0x00, 0xEB, 0x79, 0x01, 0x53, 0x4E, 0x49, 0x46 };
+ bool containsCheck2 = fileContent.Contains(check2, out int position2);
- if ((position = fileContent.IndexOf("GetModuleHandleA" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00
- + "GetProcAddress" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + "LoadLibraryA" + (char)0x00 + (char)0x00
- + "KERNEL32.dll" + (char)0x00 + "ëy" + (char)0x01 + "SNIF")) > -1)
- {
- return "LaserLock " + GetVersion(fileContent, --position) + " " + GetBuild(fileContent, false);
- }
+ if (containsCheck && containsCheck2)
+ return $"LaserLock {GetVersion(fileContent, position2)} {GetBuild(fileContent, true)} (Index {position}, {position2})";
+ else if (containsCheck && !containsCheck2)
+ return $"LaserLock Marathon {GetBuild(fileContent, false)} (Index {position})";
+ else if (!containsCheck && containsCheck2)
+ return $"LaserLock {GetVersion(fileContent, --position2)} {GetBuild(fileContent, false)} (Index {position2})";
- if (file != null && Path.GetFileName(file) == "NOMOUSE.SP")
- return "LaserLock " + GetVersion16Bit(file);
+ if (file != null && string.Equals(Path.GetFileName(file), "NOMOUSE.SP", StringComparison.OrdinalIgnoreCase))
+ return $"LaserLock {GetVersion16Bit(fileContent)} (Index 71)";
- if (fileContent.Contains(":\\LASERLOK\\LASERLOK.IN" + (char)0x00 + "C:\\NOMOUSE.SP"))
- return "LaserLock 3";
+ // ":\\LASERLOK\\LASERLOK.IN" + (char)0x00 + "C:\\NOMOUSE.SP"
+ check = new byte[] { 0x3A, 0x5C, 0x5C, 0x4C, 0x41, 0x53, 0x45, 0x52, 0x4C, 0x4F, 0x4B, 0x5C, 0x5C, 0x4C, 0x41, 0x53, 0x45, 0x52, 0x4C, 0x4F, 0x4B, 0x2E, 0x49, 0x4E, 0x00, 0x43, 0x3A, 0x5C, 0x5C, 0x4E, 0x4F, 0x4D, 0x4F, 0x55, 0x53, 0x45, 0x2E, 0x53, 0x50 };
+ if (fileContent.Contains(check, out position))
+ return $"LaserLock 3 (Index {position})";
- if (fileContent.Contains("LASERLOK_INIT" + (char)0xC + "LASERLOK_RUN" + (char)0xE + "LASERLOK_CHECK"
- + (char)0xF + "LASERLOK_CHECK2" + (char)0xF + "LASERLOK_CHECK3"))
- {
- return "LaserLock 5";
- }
+ // "LASERLOK_INIT" + (char)0xC + "LASERLOK_RUN" + (char)0xE + "LASERLOK_CHECK" + (char)0xF + "LASERLOK_CHECK2" + (char)0xF + "LASERLOK_CHECK3"
+ check = new byte[] { 0x4C, 0x41, 0x53, 0x45, 0x52, 0x4C, 0x4F, 0x4B, 0x5F, 0x49, 0x4E, 0x49, 0x54, 0x0C, 0x4C, 0x41, 0x53, 0x45, 0x52, 0x4C, 0x4F, 0x4B, 0x5F, 0x52, 0x55, 0x4E, 0x0E, 0x4C, 0x41, 0x53, 0x45, 0x52, 0x4C, 0x4F, 0x4B, 0x5F, 0x43, 0x48, 0x45, 0x43, 0x4B, 0x0F, 0x4C, 0x41, 0x53, 0x45, 0x52, 0x4C, 0x4F, 0x4B, 0x5F, 0x43, 0x48, 0x45, 0x43, 0x4B, 0x32, 0x0F, 0x4C, 0x41, 0x53, 0x45, 0x52, 0x4C, 0x4F, 0x4B, 0x5F, 0x43, 0x48, 0x45, 0x43, 0x4B, 0x33 };
+ if (fileContent.Contains(check, out position))
+ return $"LaserLock 5 (Index {position})";
return null;
}
@@ -65,6 +62,9 @@ namespace BurnOutSharp.ProtectionType
}
else
{
+ if (path != null && string.Equals(Path.GetFileName(path), "NOMOUSE.SP", StringComparison.OrdinalIgnoreCase))
+ return $"LaserLock {GetVersion16Bit(path)}";
+
if (Path.GetFileName(path).Equals("NOMOUSE.SP", StringComparison.OrdinalIgnoreCase)
|| Path.GetFileName(path).Equals("NOMOUSE.COM", StringComparison.OrdinalIgnoreCase)
|| Path.GetFileName(path).Equals("l16dll.dll", StringComparison.OrdinalIgnoreCase)
@@ -79,30 +79,37 @@ namespace BurnOutSharp.ProtectionType
return null;
}
- private static string GetBuild(string fileContent, bool versionTwo)
+ private static string GetBuild(byte[] fileContent, bool versionTwo)
{
- // TODO: Is this supposed to be "Unknown"?
- int position = fileContent.IndexOf("Unkown" + (char)0 + "Unkown");
+ // "Unkown" + (char)0x00 + "Unkown" // TODO: Is this supposed to be "Unknown"?
+ byte[] check = new byte[] { 0x55, 0x6E, 0x6B, 0x6F, 0x77, 0x6E, 0x00, 0x55, 0x6E, 0x6B, 0x6F, 0x77, 0x6E };
+ fileContent.Contains(check, out int position);
string year, month, day;
if (versionTwo)
{
- day = fileContent.Substring(position + 14, 2);
- month = fileContent.Substring(position + 14 + 3, 2);
- year = "20" + fileContent.Substring(position + 14 + 6, 2);
+ int index = position + 14;
+ day = new string(new ArraySegment(fileContent, index, 2).Select(b => (char)b).ToArray());
+ index += 3;
+ month = new string(new ArraySegment(fileContent, index, 2).Select(b => (char)b).ToArray());
+ index += 3;
+ year = "20" + new string(new ArraySegment(fileContent, index, 2).Select(b => (char)b).ToArray());
}
else
{
- day = fileContent.Substring(position + 13, 2);
- month = fileContent.Substring(position + 13 + 3, 2);
- year = "20" + fileContent.Substring(position + 13 + 6, 2);
+ int index = position + 13;
+ day = new string(new ArraySegment(fileContent, index, 2).Select(b => (char)b).ToArray());
+ index += 3;
+ month = new string(new ArraySegment(fileContent, index, 2).Select(b => (char)b).ToArray());
+ index += 3;
+ year = "20" + new string(new ArraySegment(fileContent, index, 2).Select(b => (char)b).ToArray());
}
- return "(Build " + year + "-" + month + "-" + day + ")";
+ return $"(Build {year}-{month}-{day})";
}
- private static string GetVersion(string FileContent, int position)
+ private static string GetVersion(byte[] fileContent, int position)
{
- return FileContent.Substring(position + 76, 4);
+ return new string(new ArraySegment(fileContent, position + 76, 4).Select(b => (char)b).ToArray());
}
private static string GetVersion16Bit(string file)
@@ -110,18 +117,17 @@ namespace BurnOutSharp.ProtectionType
using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
using (var br = new BinaryReader(fs))
{
- char[] version = new char[3];
- br.BaseStream.Seek(71, SeekOrigin.Begin);
- version[0] = br.ReadChar();
- br.ReadByte();
- version[1] = br.ReadChar();
- version[2] = br.ReadChar();
-
- if (char.IsNumber(version[0]) && char.IsNumber(version[1]) && char.IsNumber(version[2]))
- return version[0] + "." + version[1] + version[2];
-
- return "";
+ return GetVersion16Bit(br.ReadBytes((int)fs.Length));
}
}
+
+ private static string GetVersion16Bit(byte[] fileContent)
+ {
+ char[] version = new ArraySegment(fileContent, 71, 4).Select(b => (char)b).ToArray();
+ if (char.IsNumber(version[0]) && char.IsNumber(version[2]) && char.IsNumber(version[3]))
+ return $"{version[0]}.{version[2]}{version[3]}";
+
+ return "";
+ }
}
}
diff --git a/BurnOutSharp/ProtectionType/PECompact.cs b/BurnOutSharp/ProtectionType/PECompact.cs
index a38d2af5..427e6356 100644
--- a/BurnOutSharp/ProtectionType/PECompact.cs
+++ b/BurnOutSharp/ProtectionType/PECompact.cs
@@ -2,10 +2,12 @@
{
public class PECompact
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("PEC2"))
- return "PE Compact 2";
+ // "PEC2"
+ byte[] check = new byte[] { 0x50, 0x45, 0x43, 0x32 };
+ if (fileContent.Contains(check, out int position))
+ return $"PE Compact 2 (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/PSXAntiModchip.cs b/BurnOutSharp/ProtectionType/PSXAntiModchip.cs
index ad240724..82e7190c 100644
--- a/BurnOutSharp/ProtectionType/PSXAntiModchip.cs
+++ b/BurnOutSharp/ProtectionType/PSXAntiModchip.cs
@@ -3,14 +3,18 @@
public class PSXAntiModchip
{
// TODO: Figure out PSX binary header so this can be checked explicitly
- public static string CheckContents(string file, string fileContent)
+ // TODO: Detect Red Hand protection
+ public static string CheckContents(byte[] fileContent)
{
- // TODO: Detect Red Hand protection
- if (fileContent.Contains(" SOFTWARE TERMINATED\nCONSOLE MAY HAVE BEEN MODIFIED\n CALL 1-888-780-7690"))
- return "PlayStation Anti-modchip (English)";
+ // " SOFTWARE TERMINATED\nCONSOLE MAY HAVE BEEN MODIFIED\n CALL 1-888-780-7690"
+ byte[] check = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x53, 0x4F, 0x46, 0x54, 0x57, 0x41, 0x52, 0x45, 0x20, 0x54, 0x45, 0x52, 0x4D, 0x49, 0x4E, 0x41, 0x54, 0x45, 0x44, 0x5C, 0x6E, 0x43, 0x4F, 0x4E, 0x53, 0x4F, 0x4C, 0x45, 0x20, 0x4D, 0x41, 0x59, 0x20, 0x48, 0x41, 0x56, 0x45, 0x20, 0x42, 0x45, 0x45, 0x4E, 0x20, 0x4D, 0x4F, 0x44, 0x49, 0x46, 0x49, 0x45, 0x44, 0x5C, 0x6E, 0x20, 0x20, 0x20, 0x20, 0x20, 0x43, 0x41, 0x4C, 0x4C, 0x20, 0x31, 0x2D, 0x38, 0x38, 0x38, 0x2D, 0x37, 0x38, 0x30, 0x2D, 0x37, 0x36, 0x39, 0x30 };
+ if (fileContent.Contains(check, out int position))
+ return $"PlayStation Anti-modchip (English) (Index {position})";
- if (fileContent.Contains("強制終了しました。\n本体が改造されている\nおそれがあります。"))
- return "PlayStation Anti-modchip (Japanese)";
+ // "強制終了しました。\n本体が改造されている\nおそれがあります。"
+ check = new byte[] { 0x5F, 0x37, 0x52, 0x36, 0x7D, 0x42, 0x4E, 0x86, 0x30, 0x57, 0x30, 0x7E, 0x30, 0x57, 0x30, 0x5F, 0x30, 0x02, 0x5C, 0x6E, 0x67, 0x2C, 0x4F, 0x53, 0x30, 0x4C, 0x65, 0x39, 0x90, 0x20, 0x30, 0x55, 0x30, 0x8C, 0x30, 0x66, 0x30, 0x44, 0x30, 0x8B, 0x5C, 0x6E, 0x30, 0x4A, 0x30, 0x5D, 0x30, 0x8C, 0x30, 0x4C, 0x30, 0x42, 0x30, 0x8A, 0x30, 0x7E, 0x30, 0x59, 0x30, 0x02 };
+ if (fileContent.Contains(check, out position))
+ return $"PlayStation Anti-modchip (Japanese) (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/ProtectDisc.cs b/BurnOutSharp/ProtectionType/ProtectDisc.cs
index 552363fd..f820493c 100644
--- a/BurnOutSharp/ProtectionType/ProtectDisc.cs
+++ b/BurnOutSharp/ProtectionType/ProtectDisc.cs
@@ -1,164 +1,172 @@
using System;
-using System.IO;
+using System.Linq;
namespace BurnOutSharp.ProtectionType
{
public class ProtectDisc
{
- public static string CheckContents(string file, string fileContent)
+ public static string CheckContents(string file, byte[] fileContent)
{
- int position;
- if ((position = fileContent.IndexOf("HúMETINF")) > -1)
+ // "HúMETINF"
+ byte[] check = new byte[] { 0x48, 0xFA, 0x4D, 0x45, 0x54, 0x49, 0x4E, 0x46 };
+ if (fileContent.Contains(check, out int position))
{
- string version = EVORE.SearchProtectDiscVersion(file);
+ string version = EVORE.SearchProtectDiscVersion(file, fileContent);
if (version.Length > 0)
{
string[] astrVersionArray = version.Split('.');
if (astrVersionArray[0] == "9")
{
- if (GetVersionBuild76till10(file, position, out int ibuild).Length > 0)
- return "ProtectDisc " + astrVersionArray[0] + "." + astrVersionArray[1] + astrVersionArray[2] + "." + astrVersionArray[3] + " (Build " + ibuild + ")";
+ if (GetVersionBuild76till10(fileContent, position, out int ibuild).Length > 0)
+ return $"ProtectDisc {astrVersionArray[0]}.{astrVersionArray[1]}{astrVersionArray[2]}.{astrVersionArray[3]} (Build {ibuild}) (Index {position})";
}
else
- return "ProtectDisc " + astrVersionArray[0] + "." + astrVersionArray[1] + "." + astrVersionArray[2] + " (Build " + astrVersionArray[3] + ")";
+ {
+ return $"ProtectDisc {astrVersionArray[0]}.{astrVersionArray[1]}.{astrVersionArray[2]} (Build {astrVersionArray[3]}) (Index {position})";
+ }
}
}
- if ((position = fileContent.IndexOf("ACE-PCD")) > -1)
+ // "ACE-PCD"
+ check = new byte[] { 0x41, 0x43, 0x45, 0x2D, 0x50, 0x43, 0x44 };
+ if (fileContent.Contains(check, out position))
{
- string version = EVORE.SearchProtectDiscVersion(file);
+ string version = EVORE.SearchProtectDiscVersion(file, fileContent);
if (version.Length > 0)
{
string[] astrVersionArray = version.Split('.');
- return "ProtectDisc " + astrVersionArray[0] + "." + astrVersionArray[1] + "." + astrVersionArray[2] + " (Build " + astrVersionArray[3] + ")";
+ return $"ProtectDisc {astrVersionArray[0]}.{astrVersionArray[1]}.{astrVersionArray[2]} (Build {astrVersionArray[3]}) (Index {position})";
}
- return "ProtectDisc " + GetVersionBuild6till8(file, position);
+ return $"ProtectDisc {GetVersionBuild6till8(fileContent, position)} (Index {position})";
}
return null;
}
- private static string GetVersionBuild6till8(string file, int position)
+ private static string GetVersionBuild6till8(byte[] fileContent, int position)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
+ string version;
+ string strBuild;
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
+ int index = position - 12;
+ if (new ArraySegment(fileContent, index, 4).SequenceEqual(new byte[] { 0x0A, 0x0D, 0x0A, 0x0D })) // ProtectDisc 6-7 with Build Number in plain text
{
- string version;
- string strBuild;
+ index = position - 12 - 6;
- br.BaseStream.Seek(position - 12, SeekOrigin.Begin);
- if (br.ReadByte() == 0xA && br.ReadByte() == 0xD && br.ReadByte() == 0xA && br.ReadByte() == 0xD) // ProtectDisc 6-7 with Build Number in plain text
+ // ProtectDisc 7
+ if (new string(new ArraySegment(fileContent, index, 6).Select(b => (char)b).ToArray()) == "Henrik")
{
- br.BaseStream.Seek(position - 12 - 6, SeekOrigin.Begin);
- if (new string(br.ReadChars(6)) == "Henrik") // ProtectDisc 7
- {
- version = "7.1-7.5";
- br.BaseStream.Seek(position - 12 - 6 - 6, SeekOrigin.Begin);
- }
- else // ProtectDisc 6
- {
- version = "6";
- br.BaseStream.Seek(position - 12 - 10, SeekOrigin.Begin);
- while (true) //search for e.g. "Build 050913 - September 2005"
- {
- if (Char.IsNumber(br.ReadChar()))
- break;
- br.BaseStream.Seek(-2, SeekOrigin.Current); //search upwards
- }
-
- br.BaseStream.Seek(-5, SeekOrigin.Current);
- }
+ version = "7.1-7.5";
+ index = position - 12 - 6 - 6;
}
+
+ // ProtectDisc 6
else
{
- br.BaseStream.Seek(position + 28, SeekOrigin.Begin);
- if (br.ReadByte() == 0xFB)
+ version = "6";
+ index = position - 12 - 10;
+ while (true) //search for e.g. "Build 050913 - September 2005"
{
- return "7.6-7.x";
- }
- else
- {
- return "8.0";
+ if (Char.IsNumber((char)fileContent[index]))
+ break;
+
+ index -= 1; //search upwards
}
+
+ index -= 5;
}
- strBuild = "" + br.ReadChar() + br.ReadChar() + br.ReadChar() + br.ReadChar() + br.ReadChar();
- return version + " (Build " + strBuild + ")";
}
+ else
+ {
+ index = position + 28;
+ if (fileContent[index] == 0xFB)
+ return "7.6-7.x";
+ else
+ return "8.0";
+ }
+
+ strBuild = new string(new ArraySegment(fileContent, index, 5).Select(b => (char)b).ToArray());
+ return $"{version} (Build {strBuild})";
}
- private static string GetVersionBuild76till10(string file, int position, out int irefBuild)
+ private static string GetVersionBuild76till10(byte[] fileContent, int position, out int irefBuild)
{
- irefBuild = 0;
- if (file == null || !File.Exists(file))
- return string.Empty;
+ int index = position + 37;
+ byte subversion = fileContent[index];
+ index++;
+ index++;
+ byte version = fileContent[index];
+ index = position + 49;
+ irefBuild = BitConverter.ToInt32(fileContent, index);
+ index = position + 53;
+ byte versionindicatorPD9 = fileContent[index];
+ index = position + 0x40;
+ byte subsubversionPD9x = fileContent[index];
+ index++;
+ byte subversionPD9x2 = fileContent[index];
+ index++;
+ byte subversionPD9x1 = fileContent[index];
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
+ // version 7
+ if (version == 0xAC)
+ return $"7.{subversion ^ 0x43} (Build {irefBuild})";
+
+ // version 8
+ else if (version == 0xA2)
{
- br.BaseStream.Seek(position + 37, SeekOrigin.Begin);
- byte subversion = br.ReadByte();
- br.ReadByte();
- byte version = br.ReadByte();
- br.BaseStream.Seek(position + 49, SeekOrigin.Begin);
- irefBuild = br.ReadInt32();
- br.BaseStream.Seek(position + 53, SeekOrigin.Begin);
- byte versionindicatorPD9 = br.ReadByte();
- br.BaseStream.Seek(position + 0x40, SeekOrigin.Begin);
- byte subsubversionPD9x = br.ReadByte();
- byte subversionPD9x2 = br.ReadByte();
- byte subversionPD9x1 = br.ReadByte();
-
- // version 7
- if (version == 0xAC)
- return "7." + (subversion ^ 0x43) + " (Build " + irefBuild + ")";
- // version 8
- else if (version == 0xA2)
+ if (subversion == 0x46)
{
- if (subversion == 0x46)
- {
- if ((irefBuild & 0x3A00) == 0x3A00)
- return "8.2" + " (Build " + irefBuild + ")";
- else
- return "8.1" + " (Build " + irefBuild + ")";
- }
- return "8." + (subversion ^ 0x47) + " (Build " + irefBuild + ")";
- }
- // version 9
- else if (version == 0xA3)
- {
- // version removed or not given
- if ((subversionPD9x2 == 0x5F && subversionPD9x1 == 0x61) || (subversionPD9x1 == 0 && subversionPD9x2 == 0))
- {
- if (versionindicatorPD9 == 0xB)
- return "9.0-9.4" + " (Build " + irefBuild + ")";
- else if (versionindicatorPD9 == 0xC)
- {
- if (subversionPD9x2 == 0x5F && subversionPD9x1 == 0x61)
- return "9.5-9.11" + " (Build " + irefBuild + ")";
- else if (subversionPD9x1 == 0 && subversionPD9x2 == 0)
- return "9.11-9.20" + " (Build " + irefBuild + ")";
- }
- else
- return "9." + subversionPD9x1 + subversionPD9x2 + "." + subsubversionPD9x + " (Build " + irefBuild + ")";
- }
- }
- else if (version == 0xA0)
- {
- // version removed
- if (subversionPD9x1 != 0 || subversionPD9x2 != 0)
- return "10." + subversionPD9x1 + "." + subsubversionPD9x + " (Build " + irefBuild + ")";
+ if ((irefBuild & 0x3A00) == 0x3A00)
+ return $"8.2 (Build {irefBuild})";
else
- return "10.x (Build " + irefBuild + ")";
+ return $"8.1 (Build {irefBuild})";
}
- else
- return "7.6-10.x (Build " + irefBuild + ")";
- return "";
+ return $"8.{subversion ^ 0x47} (Build {irefBuild})";
}
+
+ // version 9
+ else if (version == 0xA3)
+ {
+ // version removed or not given
+ if ((subversionPD9x2 == 0x5F && subversionPD9x1 == 0x61) || (subversionPD9x1 == 0 && subversionPD9x2 == 0))
+ {
+ if (versionindicatorPD9 == 0xB)
+ {
+ return $"9.0-9.4 (Build {irefBuild})";
+ }
+ else if (versionindicatorPD9 == 0xC)
+ {
+ if (subversionPD9x2 == 0x5F && subversionPD9x1 == 0x61)
+ return $"9.5-9.11 (Build {irefBuild})";
+ else if (subversionPD9x1 == 0 && subversionPD9x2 == 0)
+ return $"9.11-9.20 (Build {irefBuild})";
+ }
+ else
+ {
+ return $"9.{subversionPD9x1}{subversionPD9x2}.{subsubversionPD9x} (Build {irefBuild})";
+ }
+ }
+ }
+
+ // version 10
+ else if (version == 0xA0)
+ {
+ // version removed
+ if (subversionPD9x1 != 0 || subversionPD9x2 != 0)
+ return $"10.{subversionPD9x1}.{subsubversionPD9x} (Build {irefBuild})";
+ else
+ return $"10.x (Build {irefBuild})";
+ }
+
+ // unknown version
+ else
+ {
+ return $"7.6-10.x (Build {irefBuild})";
+ }
+
+ return "";
}
}
}
diff --git a/BurnOutSharp/ProtectionType/RingPROTECH.cs b/BurnOutSharp/ProtectionType/RingPROTECH.cs
index ffa50b12..bb94aea4 100644
--- a/BurnOutSharp/ProtectionType/RingPROTECH.cs
+++ b/BurnOutSharp/ProtectionType/RingPROTECH.cs
@@ -2,10 +2,12 @@
{
public class RingPROTECH
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains((char)0x00 + "Allocator" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00))
- return "Ring PROTECH";
+ // (char)0x00 + "Allocator" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00
+ byte[] check = new byte[] { 0x00, 0x41, 0x6C, 0x6C, 0x6F, 0x63, 0x61, 0x74, 0x6F, 0x72, 0x00, 0x00, 0x00, 0x00 };
+ if (fileContent.Contains(check, out int position))
+ return $"Ring PROTECH (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/SVKProtector.cs b/BurnOutSharp/ProtectionType/SVKProtector.cs
index 0dbb00c8..3d14a1e0 100644
--- a/BurnOutSharp/ProtectionType/SVKProtector.cs
+++ b/BurnOutSharp/ProtectionType/SVKProtector.cs
@@ -2,10 +2,12 @@
{
public class SVKProtector
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("?SVKP" + (char)0x00 + (char)0x00))
- return "SVK Protector";
+ // "?SVKP" + (char)0x00 + (char)0x00
+ byte[] check = new byte[] { 0x3F, 0x53, 0x56, 0x4B, 0x50, 0x00, 0x00 };
+ if (fileContent.Contains(check, out int position))
+ return $"SVK Protector (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/SafeDisc.cs b/BurnOutSharp/ProtectionType/SafeDisc.cs
index d62dd015..79b58670 100644
--- a/BurnOutSharp/ProtectionType/SafeDisc.cs
+++ b/BurnOutSharp/ProtectionType/SafeDisc.cs
@@ -7,26 +7,51 @@ namespace BurnOutSharp.ProtectionType
{
public class SafeDisc
{
- public static string CheckContents(string file, string fileContent)
+ public static string CheckContents(string file, byte[] fileContent)
{
- int position;
- if ((position = fileContent.IndexOf("BoG_ *90.0&!! Yy>")) > -1)
+ // "BoG_ *90.0&!! Yy>"
+ byte[] check = new byte[] { 0x42, 0x6F, 0x47, 0x5F, 0x20, 0x2A, 0x39, 0x30, 0x2E, 0x30, 0x26, 0x21, 0x21, 0x20, 0x20, 0x59, 0x79, 0x3E };
+ if (fileContent.Contains(check, out int position))
{
- if (fileContent.IndexOf("product activation library") > 0)
- return "SafeCast " + GetVersion(file, position);
+ // "product activation library"
+ byte[] check2 = new byte[] { 0x70, 0x72, 0x6F, 0x64, 0x75, 0x63, 0x74, 0x20, 0x61, 0x63, 0x74, 0x69, 0x76, 0x61, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x6C, 0x69, 0x62, 0x72, 0x61, 0x72, 0x79 };
+ if (fileContent.Contains(check2, out int position2))
+ return $"SafeCast {GetVersion(fileContent, position)} (Index {position}, {position2})";
else
- return "SafeDisc " + GetVersion(file, position);
+ return $"SafeDisc {GetVersion(fileContent, position)} (Index {position})";
}
- if (fileContent.Contains((char)0x00 + (char)0x00 + "BoG_")
- || fileContent.Contains("stxt774")
- || fileContent.Contains("stxt371"))
+ // (char)0x00 + (char)0x00 + "BoG_"
+ check = new byte[] { 0x00, 0x00, 0x42, 0x6F, 0x47, 0x5F };
+ if (fileContent.Contains(check, out position))
{
- string version = EVORE.SearchSafeDiscVersion(file);
+ string version = EVORE.SearchSafeDiscVersion(file, fileContent);
if (version.Length > 0)
- return "SafeDisc " + version;
+ return $"SafeDisc {version} (Index {position})";
- return "SafeDisc 3.20-4.xx (version removed)";
+ return $"SafeDisc 3.20-4.xx (version removed) (Index {position})";
+ }
+
+ // "stxt774"
+ check = new byte[] { 0x73, 0x74, 0x78, 0x74, 0x37, 0x37, 0x34 };
+ if (fileContent.Contains(check, out position))
+ {
+ string version = EVORE.SearchSafeDiscVersion(file, fileContent);
+ if (version.Length > 0)
+ return $"SafeDisc {version} (Index {position})";
+
+ return $"SafeDisc 3.20-4.xx (version removed) (Index {position})";
+ }
+
+ // "stxt371"
+ check = new byte[] { 0x73, 0x74, 0x78, 0x74, 0x33, 0x37, 0x31 };
+ if (fileContent.Contains(check, out position))
+ {
+ string version = EVORE.SearchSafeDiscVersion(file, fileContent);
+ if (version.Length > 0)
+ return $"SafeDisc {version} (Index {position})";
+
+ return $"SafeDisc 3.20-4.xx (version removed) (Index {position})";
}
return null;
@@ -192,32 +217,29 @@ namespace BurnOutSharp.ProtectionType
return "SafeDisc 2 or greater";
}
- private static string GetVersion(string file, int position)
+ private static string GetVersion(byte[] fileContent, int position)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
+ int index = position + 20; // Begin reading after "BoG_ *90.0&!! Yy>" for old SafeDisc
+ int version = BitConverter.ToInt32(fileContent, index);
+ index += 4;
+ int subVersion = BitConverter.ToInt32(fileContent, index);
+ index += 4;
+ int subsubVersion = BitConverter.ToInt32(fileContent, index);
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
- {
- br.BaseStream.Seek(position + 20, SeekOrigin.Begin); // Begin reading after "BoG_ *90.0&!! Yy>" for old SafeDisc
- int version = br.ReadInt32();
- int subVersion = br.ReadInt32();
- int subsubVersion = br.ReadInt32();
+ if (version != 0)
+ return $"{version}.{subVersion:00}.{subsubVersion:000}";
- if (version != 0)
- return version + "." + subVersion.ToString("00") + "." + subsubVersion.ToString("000");
+ index = position + 18 + 14; // Begin reading after "BoG_ *90.0&!! Yy>" for newer SafeDisc
+ version = BitConverter.ToInt32(fileContent, index);
+ index += 4;
+ subVersion = BitConverter.ToInt32(fileContent, index);
+ index += 4;
+ subsubVersion = BitConverter.ToInt32(fileContent, index);
- br.BaseStream.Seek(position + 18 + 14, SeekOrigin.Begin); // Begin reading after "BoG_ *90.0&!! Yy>" for newer SafeDisc
- version = br.ReadInt32();
- subVersion = br.ReadInt32();
- subsubVersion = br.ReadInt32();
+ if (version == 0)
+ return "";
- if (version == 0)
- return "";
-
- return version + "." + subVersion.ToString("00") + "." + subsubVersion.ToString("000");
- }
+ return $"{version}.{subVersion:00}.{subsubVersion:000}";
}
}
}
diff --git a/BurnOutSharp/ProtectionType/SafeLock.cs b/BurnOutSharp/ProtectionType/SafeLock.cs
index 39d2c04e..71b344e7 100644
--- a/BurnOutSharp/ProtectionType/SafeLock.cs
+++ b/BurnOutSharp/ProtectionType/SafeLock.cs
@@ -7,10 +7,12 @@ namespace BurnOutSharp.ProtectionType
{
public class SafeLock
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("SafeLock"))
- return "SafeLock";
+ // "SafeLock"
+ byte[] check = new byte[] { 0x53, 0x61, 0x66, 0x65, 0x4C, 0x6F, 0x63, 0x6B };
+ if (fileContent.Contains(check, out int position))
+ return $"SafeLock (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/SecuROM.cs b/BurnOutSharp/ProtectionType/SecuROM.cs
index 98bce334..f9a4dac9 100644
--- a/BurnOutSharp/ProtectionType/SecuROM.cs
+++ b/BurnOutSharp/ProtectionType/SecuROM.cs
@@ -7,32 +7,42 @@ namespace BurnOutSharp.ProtectionType
{
public class SecuROM
{
- public static string CheckContents(string file, string fileContent)
+ public static string CheckContents(string file, byte[] fileContent)
{
- int position;
- if ((position = fileContent.IndexOf("AddD" + (char)0x03 + (char)0x00 + (char)0x00 + (char)0x00)) > -1)
- return "SecuROM " + GetV4Version(file, position);
+ // "AddD" + (char)0x03 + (char)0x00 + (char)0x00 + (char)0x00)
+ byte[] check = new byte[] { 0x41, 0x64, 0x64, 0x44, 0x03, 0x00, 0x00, 0x00 };
+ if (fileContent.Contains(check, out int position))
+ return $"SecuROM {GetV4Version(fileContent, position)} (Index {position})";
- if ((position = fileContent.IndexOf("" + (char)0xCA + (char)0xDD + (char)0xDD + (char)0xAC + (char)0x03)) > -1)
- return "SecuROM " + GetV5Version(file, position);
+ // (char)0xCA + (char)0xDD + (char)0xDD + (char)0xAC + (char)0x03
+ check = new byte[] { 0xCA, 0xDD, 0xDD, 0xAC, 0x03 };
+ if (fileContent.Contains(check, out position))
+ return $"SecuROM {GetV5Version(fileContent, position)} (Index {position})";
- if (fileContent.Contains(".securom")
- || fileContent.StartsWith(".securom" + (char)0xE0 + (char)0xC0))
- {
- return "SecuROM " + GetV7Version(file);
- }
+ // ".securom" + (char)0xE0 + (char)0xC0
+ check = new byte[] { 0x2E, 0x73, 0x65, 0x63, 0x75, 0x72, 0x6F, 0x6D, 0xE0, 0xC0 };
+ if (fileContent.Contains(check, out position) && position == 0)
+ return $"SecuROM {GetV7Version(fileContent)} (Index {position})";
- if (fileContent.Contains("_and_play.dll" + (char)0x00 + "drm_pagui_doit"))
- return "SecuROM Product Activation " + Utilities.GetFileVersion(file);
+ // ".securom"
+ check = new byte[] { 0x2E, 0x73, 0x65, 0x63, 0x75, 0x72, 0x6F, 0x6D };
+ if (fileContent.Contains(check, out position))
+ return $"SecuROM {GetV7Version(fileContent)} (Index {position})";
- if (fileContent.Contains("_and_play.dll" + (char)0x00 + "drm_pagui_doit"))
- return "SecuROM Product Activation " + Utilities.GetFileVersion(file);
+ // "_and_play.dll" + (char)0x00 + "drm_pagui_doit"
+ check = new byte[] { 0x5F, 0x61, 0x6E, 0x64, 0x5F, 0x70, 0x6C, 0x61, 0x79, 0x2E, 0x64, 0x6C, 0x6C, 0x00, 0x64, 0x72, 0x6D, 0x5F, 0x70, 0x61, 0x67, 0x75, 0x69, 0x5F, 0x64, 0x6F, 0x69, 0x74 };
+ if (fileContent.Contains(check, out position))
+ return $"SecuROM Product Activation {Utilities.GetFileVersion(file)} (Index {position})";
- if (fileContent.Contains(".cms_t" + (char)0x00)
- || fileContent.Contains(".cms_d" + (char)0x00))
- {
- return "SecuROM 1-3";
- }
+ // ".cms_t" + (char)0x00
+ check = new byte[] { 0x2E, 0x63, 0x6D, 0x73, 0x5F, 0x74, 0x00 };
+ if (fileContent.Contains(check, out position))
+ return $"SecuROM 1-3 (Index {position})";
+
+ // ".cms_d" + (char)0x00
+ check = new byte[] { 0x2E, 0x63, 0x6D, 0x73, 0x5F, 0x64, 0x00 };
+ if (fileContent.Contains(check, out position))
+ return $"SecuROM 1-3 (Index {position})";
return null;
}
@@ -78,84 +88,76 @@ namespace BurnOutSharp.ProtectionType
return null;
}
- private static string GetV4Version(string file, int position)
+ private static string GetV4Version(byte[] fileContent, int position)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
+ int index = position + 8; // Begin reading after "AddD"
+ char version = (char)fileContent[index];
+ index += 2;
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
- {
- br.BaseStream.Seek(position + 8, SeekOrigin.Begin); // Begin reading after "AddD"
- char version = br.ReadChar();
- br.ReadByte();
- char subVersion1 = br.ReadChar();
- char subVersion2 = br.ReadChar();
- br.ReadByte();
- char subsubVersion1 = br.ReadChar();
- char subsubVersion2 = br.ReadChar();
- br.ReadByte();
- char subsubsubVersion1 = br.ReadChar();
- char subsubsubVersion2 = br.ReadChar();
- char subsubsubVersion3 = br.ReadChar();
- char subsubsubVersion4 = br.ReadChar();
+ string subVersion = new string(new ArraySegment(fileContent, index, 2).Select(b => (char)b).ToArray());
+ index += 3;
- return version + "." + subVersion1 + subVersion2 + "." + subsubVersion1 + subsubVersion2 + "." + subsubsubVersion1 + subsubsubVersion2 + subsubsubVersion3 + subsubsubVersion4;
- }
+ string subSubVersion = new string(new ArraySegment(fileContent, index, 2).Select(b => (char)b).ToArray());
+ index += 3;
+
+ string subSubSubVersion = new string(new ArraySegment(fileContent, index, 4).Select(b => (char)b).ToArray());
+
+ if (!char.IsNumber(version))
+ return "(very old, v3 or less)";
+
+ return $"{version}.{subVersion}.{subSubVersion}.{subSubSubVersion}";
}
- private static string GetV5Version(string file, int position)
+ private static string GetV5Version(byte[] fileContent, int position)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
+ int index = position + 8; // Begin reading after "ÊÝݬ"
+ byte version = (byte)(fileContent[index] & 0x0F);
+ index += 2;
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
- {
- br.BaseStream.Seek(position + 8, SeekOrigin.Begin); // Begin reading after "ÊÝݬ"
- byte version = (byte)(br.ReadByte() & 0xF);
- br.ReadByte();
- byte subVersion1 = (byte)(br.ReadByte() ^ 36);
- byte subVersion2 = (byte)(br.ReadByte() ^ 28);
- br.ReadByte();
- byte subsubVersion1 = (byte)(br.ReadByte() ^ 42);
- byte subsubVersion2 = (byte)(br.ReadByte() ^ 8);
- br.ReadByte();
- byte subsubsubVersion1 = (byte)(br.ReadByte() ^ 16);
- byte subsubsubVersion2 = (byte)(br.ReadByte() ^ 116);
- byte subsubsubVersion3 = (byte)(br.ReadByte() ^ 34);
- byte subsubsubVersion4 = (byte)(br.ReadByte() ^ 22);
+ byte[] subVersion = new byte[2];
+ subVersion[0] = (byte)(fileContent[index] ^ 36);
+ index++;
+ subVersion[1] = (byte)(fileContent[index] ^ 28);
+ index += 2;
- if (version == 0 || version > 9)
- return "";
+ byte[] subSubVersion = new byte[2];
+ subSubVersion[0] = (byte)(fileContent[index] ^ 42);
+ index++;
+ subSubVersion[0] = (byte)(fileContent[index] ^ 8);
+ index += 2;
- return version + "." + subVersion1 + subVersion2 + "." + subsubVersion1 + subsubVersion2 + "." + subsubsubVersion1 + subsubsubVersion2 + subsubsubVersion3 + subsubsubVersion4;
- }
+ byte[] subSubSubVersion = new byte[4];
+ subSubSubVersion[0] = (byte)(fileContent[index] ^ 16);
+ index++;
+ subSubSubVersion[1] = (byte)(fileContent[index] ^ 116);
+ index++;
+ subSubSubVersion[2] = (byte)(fileContent[index] ^ 34);
+ index++;
+ subSubSubVersion[3] = (byte)(fileContent[index] ^ 22);
+
+ if (version == 0 || version > 9)
+ return "";
+
+ return $"{version}.{subVersion[0]}{subVersion[1]}.{subSubVersion[0]}{subSubVersion[1]}.{subSubSubVersion[0]}{subSubSubVersion[1]}{subSubSubVersion[2]}{subSubSubVersion[3]}";
}
- private static string GetV7Version(string file)
+ private static string GetV7Version(byte[] fileContent)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
-
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
+ int index = 236;
+ byte[] bytes = new ArraySegment(fileContent, index, 4).ToArray();
+
+ //SecuROM 7 new and 8
+ if (bytes[3] == 0x5C) // if (bytes[0] == 0xED && bytes[3] == 0x5C {
{
- br.BaseStream.Seek(236, SeekOrigin.Begin);
- byte[] bytes = br.ReadBytes(4);
- // if (bytes[0] == 0xED && bytes[3] == 0x5C {
- if (bytes[3] == 0x5C)
- {
- //SecuROM 7 new and 8
- return (bytes[0] ^ 0xEA).ToString() + "." + (bytes[1] ^ 0x2C).ToString("00") + "." + (bytes[2] ^ 0x8).ToString("0000");
- }
- else // SecuROM 7 old
- {
- br.BaseStream.Seek(122, SeekOrigin.Begin);
- bytes = br.ReadBytes(2);
- return "7." + (bytes[0] ^ 0x10).ToString("00") + "." + (bytes[1] ^ 0x10).ToString("0000");
- //return "7.01-7.10"
- }
+ return $"{bytes[0] ^ 0xEA}.{bytes[1] ^ 0x2C:00}.{bytes[2] ^ 0x8:0000}";
+ }
+
+ // SecuROM 7 old
+ else
+ {
+ index = 122;
+ bytes = new ArraySegment(fileContent, index, 2).ToArray();
+ return $"7.{bytes[0] ^ 0x10:00}.{bytes[1] ^ 0x10:0000}"; //return "7.01-7.10"
}
}
}
diff --git a/BurnOutSharp/ProtectionType/SmartE.cs b/BurnOutSharp/ProtectionType/SmartE.cs
index 4bb6c554..b1d41b45 100644
--- a/BurnOutSharp/ProtectionType/SmartE.cs
+++ b/BurnOutSharp/ProtectionType/SmartE.cs
@@ -7,10 +7,12 @@ namespace BurnOutSharp.ProtectionType
{
public class SmartE
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("BITARTS"))
- return "SmartE";
+ // "BITARTS"
+ byte[] check = new byte[] { 0x42, 0x49, 0x54, 0x41, 0x52, 0x54, 0x53 };
+ if (fileContent.Contains(check, out int position))
+ return $"SmartE (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/SolidShield.cs b/BurnOutSharp/ProtectionType/SolidShield.cs
index c0a69264..427be003 100644
--- a/BurnOutSharp/ProtectionType/SolidShield.cs
+++ b/BurnOutSharp/ProtectionType/SolidShield.cs
@@ -8,96 +8,101 @@ namespace BurnOutSharp.ProtectionType
{
public class SolidShield
{
- public static string CheckContents(string file, string fileContent)
+ public static string CheckContents(string file, byte[] fileContent)
{
- int position;
- if (fileContent.Contains("D" + (char)0x00 + "V" + (char)0x00 + "M" + (char)0x00 + " " + (char)0x00 + "L" + (char)0x00
- + "i" + (char)0x00 + "b" + (char)0x00 + "r" + (char)0x00 + "a" + (char)0x00 + "r" + (char)0x00 + "y"))
- {
- return "SolidShield " + Utilities.GetFileVersion(file);
- }
+ // "D" + (char)0x00 + "V" + (char)0x00 + "M" + (char)0x00 + " " + (char)0x00 + "L" + (char)0x00 + "i" + (char)0x00 + "b" + (char)0x00 + "r" + (char)0x00 + "a" + (char)0x00 + "r" + (char)0x00 + "y"
+ byte[] check = new byte[] { 0x44, 0x00, 0x56, 0x00, 0x4D, 0x00, 0x20, 0x00, 0x4C, 0x00, 0x69, 0x00, 0x62, 0x00, 0x72, 0x00, 0x61, 0x00, 0x72, 0x00, 0x79 };
+ if (fileContent.Contains(check, out int position))
+ return $"SolidShield {Utilities.GetFileVersion(file)} (Index {position})";
- if (fileContent.Contains("S" + (char)0x00 + "o" + (char)0x00 + "l" + (char)0x00 + "i" + (char)0x00 + "d" + (char)0x00
- + "s" + (char)0x00 + "h" + (char)0x00 + "i" + (char)0x00 + "e" + (char)0x00 + "l" + (char)0x00 + "d" + (char)0x00
- + " " + (char)0x00 + "L" + (char)0x00 + "i" + (char)0x00 + "b" + (char)0x00 + "r" + (char)0x00 + "a" + (char)0x00
- + "r" + (char)0x00 + "y")
- || fileContent.Contains("S" + (char)0x00 + "o" + (char)0x00 + "l" + (char)0x00 + "i" + (char)0x00 + "d" + (char)0x00
- + "s" + (char)0x00 + "h" + (char)0x00 + "i" + (char)0x00 + "e" + (char)0x00 + "l" + (char)0x00 + "d" + (char)0x00
- + " " + (char)0x00 + "A" + (char)0x00 + "c" + (char)0x00 + "t" + (char)0x00 + "i" + (char)0x00 + "v" + (char)0x00
- + "a" + (char)0x00 + "t" + (char)0x00 + "i" + (char)0x00 + "o" + (char)0x00 + "n" + (char)0x00 + " " + (char)0x00
- + "L" + (char)0x00 + "i" + (char)0x00 + "b" + (char)0x00 + "r" + (char)0x00 + "a" + (char)0x00 + "r" + (char)0x00 + "y"))
+ // "S" + (char)0x00 + "o" + (char)0x00 + "l" + (char)0x00 + "i" + (char)0x00 + "d" + (char)0x00 + "s" + (char)0x00 + "h" + (char)0x00 + "i" + (char)0x00 + "e" + (char)0x00 + "l" + (char)0x00 + "d" + (char)0x00 + " " + (char)0x00 + "L" + (char)0x00 + "i" + (char)0x00 + "b" + (char)0x00 + "r" + (char)0x00 + "a" + (char)0x00 + "r" + (char)0x00 + "y"
+ check = new byte[] { 0x53, 0x00, 0x6F, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x64, 0x00, 0x73, 0x00, 0x68, 0x00, 0x69, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x64, 0x00, 0x20, 0x00, 0x4C, 0x00, 0x69, 0x00, 0x62, 0x00, 0x72, 0x00, 0x61, 0x00, 0x72, 0x00, 0x79 };
+ if (fileContent.Contains(check, out position))
{
string companyName = string.Empty;
if (file != null)
companyName = FileVersionInfo.GetVersionInfo(file).CompanyName.ToLower();
if (companyName.Contains("solidshield") || companyName.Contains("tages"))
- return "SolidShield Core.dll " + Utilities.GetFileVersion(file);
+ return $"SolidShield Core.dll {Utilities.GetFileVersion(file)} (Index {position})";
}
- if ((position = fileContent.IndexOf("" + (char)0xEF + (char)0xBE + (char)0xAD + (char)0xDE)) > -1)
- {
- var id1 = fileContent.Substring(position + 5, 3);
- var id2 = fileContent.Substring(position + 16, 4);
-
- if (id1 == "" + (char)0x00 + (char)0x00 + (char)0x00 && id2 == "" + (char)0x00 + (char)0x10 + (char)0x00 + (char)0x00)
- return "SolidShield 1 (SolidShield EXE Wrapper)";
- else if (id1 == ".o&" && id2 == "ÛÅ›¹")
- return "SolidShield 2 (SolidShield v2 EXE Wrapper)"; // TODO: Verify against other SolidShield 2 discs
- }
-
- if (fileContent.Contains("A" + (char)0x00 + "c" + (char)0x00 + "t" + (char)0x00 + "i" + (char)0x00 + "v" + (char)0x00
- + "a" + (char)0x00 + "t" + (char)0x00 + "i" + (char)0x00 + "o" + (char)0x00 + "n" + (char)0x00 + " " + (char)0x00
- + "M" + (char)0x00 + "a" + (char)0x00 + "n" + (char)0x00 + "a" + (char)0x00 + "g" + (char)0x00 + "e" + (char)0x00 + "r"))
+ // "S" + (char)0x00 + "o" + (char)0x00 + "l" + (char)0x00 + "i" + (char)0x00 + "d" + (char)0x00 + "s" + (char)0x00 + "h" + (char)0x00 + "i" + (char)0x00 + "e" + (char)0x00 + "l" + (char)0x00 + "d" + (char)0x00 + " " + (char)0x00 + "A" + (char)0x00 + "c" + (char)0x00 + "t" + (char)0x00 + "i" + (char)0x00 + "v" + (char)0x00 + "a" + (char)0x00 + "t" + (char)0x00 + "i" + (char)0x00 + "o" + (char)0x00 + "n" + (char)0x00 + " " + (char)0x00 + "L" + (char)0x00 + "i" + (char)0x00 + "b" + (char)0x00 + "r" + (char)0x00 + "a" + (char)0x00 + "r" + (char)0x00 + "y"
+ check = new byte[] { 0x53, 0x00, 0x6F, 0x00, 0x6C, 0x00, 0x69, 0x00, 0x64, 0x00, 0x73, 0x00, 0x68, 0x00, 0x69, 0x00, 0x65, 0x00, 0x6C, 0x00, 0x64, 0x00, 0x20, 0x00, 0x41, 0x00, 0x63, 0x00, 0x74, 0x00, 0x69, 0x00, 0x76, 0x00, 0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x20, 0x00, 0x4C, 0x00, 0x69, 0x00, 0x62, 0x00, 0x72, 0x00, 0x61, 0x00, 0x72, 0x00, 0x79 };
+ if (fileContent.Contains(check, out position))
{
string companyName = string.Empty;
if (file != null)
companyName = FileVersionInfo.GetVersionInfo(file).CompanyName.ToLower();
if (companyName.Contains("solidshield") || companyName.Contains("tages"))
- return "SolidShield Activation Manager Module " + Utilities.GetFileVersion(file);
+ return $"SolidShield Core.dll {Utilities.GetFileVersion(file)} (Index {position})";
}
- if ((position = fileContent.IndexOf("" + (char)0xAD + (char)0xDE + (char)0xFE + (char)0xCA)) > -1)
+ // (char)0xEF + (char)0xBE + (char)0xAD + (char)0xDE
+ check = new byte[] { };
+ if (fileContent.Contains(check, out position))
{
- if ((fileContent[position + 3] == (char)0x04 || fileContent[position + 3] == (char)0x05)
- && fileContent.Substring(position + 4, 3) == "" + (char)0x00 + (char)0x00 + (char)0x00
- && fileContent.Substring(position + 15, 4) == "" + (char)0x00 + (char)0x10 + (char)0x00 + (char)0x00)
+ var id1 = new ArraySegment(fileContent, position + 5, 3);
+ var id2 = new ArraySegment(fileContent, position + 16, 4);
+
+ if (id1.SequenceEqual(new byte[] { 0x00, 0x00, 0x00 }) && id2.SequenceEqual(new byte[] { 0x00, 0x10, 0x00, 0x00 }))
+ return $"SolidShield 1 (SolidShield EXE Wrapper) (Index {position})";
+ else if (id1.SequenceEqual(new byte[] { 0x2E, 0x6F, 0x26 }) && id2.SequenceEqual(new byte[] { 0xDB, 0xC5, 0x20, 0x3A, 0xB9 }))
+ return $"SolidShield 2 (SolidShield v2 EXE Wrapper) (Index {position})"; // TODO: Verify against other SolidShield 2 discs
+ }
+
+ // "A" + (char)0x00 + "c" + (char)0x00 + "t" + (char)0x00 + "i" + (char)0x00 + "v" + (char)0x00 + "a" + (char)0x00 + "t" + (char)0x00 + "i" + (char)0x00 + "o" + (char)0x00 + "n" + (char)0x00 + " " + (char)0x00 + "M" + (char)0x00 + "a" + (char)0x00 + "n" + (char)0x00 + "a" + (char)0x00 + "g" + (char)0x00 + "e" + (char)0x00 + "r"
+ check = new byte[] { 0x41, 0x00, 0x63, 0x00, 0x74, 0x00, 0x69, 0x00, 0x76, 0x00, 0x61, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6f, 0x00, 0x6e, 0x00, 0x20, 0x00, 0x4d, 0x00, 0x61, 0x00, 0x6e, 0x00, 0x61, 0x00, 0x67, 0x00, 0x65, 0x00, 0x72 };
+ if (fileContent.Contains(check, out position))
+ {
+ string companyName = string.Empty;
+ if (file != null)
+ companyName = FileVersionInfo.GetVersionInfo(file).CompanyName.ToLower();
+
+ if (companyName.Contains("solidshield") || companyName.Contains("tages"))
+ return $"SolidShield Activation Manager Module {Utilities.GetFileVersion(file)} (Index {position})";
+ }
+
+ // (char)0xAD + (char)0xDE + (char)0xFE + (char)0xCA
+ check = new byte[] { 0xAD, 0xDE, 0xFE, 0xCA };
+ if (fileContent.Contains(check, out position))
+ {
+ var id1 = new ArraySegment(fileContent, position + 4, 3);
+ var id2 = new ArraySegment(fileContent, position + 15, 4);
+
+ if ((fileContent[position + 3] == 0x04 || fileContent[position + 3] == 0x05)
+ && id1.SequenceEqual(new byte[] { 0x00, 0x00, 0x00 })
+ && id2.SequenceEqual(new byte[] { 0x00, 0x10, 0x00, 0x00 }))
{
- return "SolidShield 2 (SolidShield v2 EXE Wrapper)";
+ return $"SolidShield 2 (SolidShield v2 EXE Wrapper) (Index {position})";
}
- else if (fileContent.Substring(position + 4, 3) == "" + (char)0x00 + (char)0x00 + (char)0x00
- && fileContent.Substring(position + 15, 4) == "" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00)
+ else if (id1.SequenceEqual(new byte[] { 0x00, 0x00, 0x00 })
+ && id2.SequenceEqual(new byte[] { 0x00, 0x00, 0x00, 0x00 }))
{
- position = fileContent.IndexOf("T" + (char)0x00 + "a" + (char)0x00 + "g" + (char)0x00 + "e" + (char)0x00 + "s"
- + (char)0x00 + "S" + (char)0x00 + "e" + (char)0x00 + "t" + (char)0x00 + "u" + (char)0x00 + "p"
- + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + "0" + (char)0x00 + (char)0x8
- + (char)0x00 + (char)0x1 + (char)0x0 + "F" + (char)0x00 + "i" + (char)0x00 + "l" + (char)0x00 + "e"
- + (char)0x00 + "V" + (char)0x00 + "e" + (char)0x00 + "r" + (char)0x00 + "s" + (char)0x00 + "i" + (char)0x00
- + "o" + (char)0x00 + "n" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00);
- if (position > -1)
+ // "T" + (char)0x00 + "a" + (char)0x00 + "g" + (char)0x00 + "e" + (char)0x00 + "s" + (char)0x00 + "S" + (char)0x00 + "e" + (char)0x00 + "t" + (char)0x00 + "u" + (char)0x00 + "p" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00 + "0" + (char)0x00 + (char)0x8 + (char)0x00 + (char)0x1 + (char)0x0 + "F" + (char)0x00 + "i" + (char)0x00 + "l" + (char)0x00 + "e" + (char)0x00 + "V" + (char)0x00 + "e" + (char)0x00 + "r" + (char)0x00 + "s" + (char)0x00 + "i" + (char)0x00 + "o" + (char)0x00 + "n" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0x00
+ byte[] check2 = new byte[] { 0x54, 0x61, 0x67, 0x65, 0x73, 0x53, 0x65, 0x74, 0x75, 0x70, 0x30, 0x08, 0x01, 0x00, 0x46, 0x69, 0x6C, 0x65, 0x56, 0x65, 0x72, 0x73, 0x69, 0x6F, 0x6E, 0x00, 0x00, 0x00, 0x00 };
+ if (fileContent.Contains(check2, out int position2))
{
- position--; // TODO: Verify this subtract
- return "SolidShield 2 + Tagès " + fileContent.Substring(position + 0x38, 1) + "." + fileContent.Substring(position + 0x38 + 4, 1) + "." + fileContent.Substring(position + 0x38 + 8, 1) + "." + fileContent.Substring(position + 0x38 + 12, 1);
+ position2--; // TODO: Verify this subtract
+ return $"SolidShield 2 + Tagès {fileContent[position2 + 0x38]}.{fileContent[position2 + 0x38 + 4]}.{fileContent[position2 + 0x38 + 8]}.{fileContent[position + 0x38 + 12]} (Index {position}, {position2})";
}
else
{
- return "SolidShield 2 (SolidShield v2 EXE Wrapper)";
+ return $"SolidShield 2 (SolidShield v2 EXE Wrapper) (Index {position})";
}
}
}
- if ((position = fileContent.IndexOf("Solidshield")) > 0)
- {
- return "SolidShield " + GetVersion(file, position);
- }
+ // "Solidshield"
+ check = new byte[] { 0x53, 0x6F, 0x6C, 0x69, 0x64, 0x73, 0x68, 0x69, 0x65, 0x6C, 0x64 };
+ if (fileContent.Contains(check, out position))
+ return $"SolidShield {GetVersion(fileContent, position)} (Index {position})";
- if (fileContent.Contains("B" + (char)0x00 + "I" + (char)0x00 + "N" + (char)0x00 + (char)0x7 + (char)0x00 +
- "I" + (char)0x00 + "D" + (char)0x00 + "R" + (char)0x00 + "_" + (char)0x00 +
- "S" + (char)0x00 + "G" + (char)0x00 + "T" + (char)0x0))
- {
- return "SolidShield";
- }
+ // "B" + (char)0x00 + "I" + (char)0x00 + "N" + (char)0x00 + (char)0x7 + (char)0x00 + "I" + (char)0x00 + "D" + (char)0x00 + "R" + (char)0x00 + "_" + (char)0x00 + "S" + (char)0x00 + "G" + (char)0x00 + "T" + (char)0x0
+ check = new byte[] { 0x42, 0x00, 0x49, 0x00, 0x4E, 0x00, 0x07, 0x00, 0x49, 0x00, 0x44, 0x00, 0x52, 0x00, 0x5F, 0x00, 0x53, 0x00, 0x47, 0x00, 0x54, 0x00 };
+ if (fileContent.Contains(check, out position))
+ return $"SolidShield (Index {position})";
return null;
}
@@ -129,24 +134,21 @@ namespace BurnOutSharp.ProtectionType
return null;
}
- private static string GetVersion(string file, int position)
+ private static string GetVersion(byte[] fileContent, int position)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
-
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
- {
- br.BaseStream.Seek(position + 12, SeekOrigin.Begin); // Begin reading after "Solidshield"
- char version = br.ReadChar();
- br.ReadByte();
- char subVersion = br.ReadChar();
- br.ReadByte();
- char subsubVersion = br.ReadChar();
- br.ReadByte();
- char subsubsubVersion = br.ReadChar();
- return version + "." + subVersion + "." + subsubVersion + "." + subsubsubVersion;
- }
+ int index = position + 12; // Begin reading after "Solidshield"
+ char version = (char)fileContent[index];
+ index++;
+ index++;
+ char subVersion = (char)fileContent[index];
+ index++;
+ index++;
+ char subSubVersion = (char)fileContent[index];
+ index++;
+ index++;
+ char subSubSubVersion = (char)fileContent[index];
+
+ return $"{version}.{subVersion}.{subSubVersion}.{subSubSubVersion}";
}
}
}
diff --git a/BurnOutSharp/ProtectionType/StarForce.cs b/BurnOutSharp/ProtectionType/StarForce.cs
index 6017bbc8..1e63511d 100644
--- a/BurnOutSharp/ProtectionType/StarForce.cs
+++ b/BurnOutSharp/ProtectionType/StarForce.cs
@@ -7,37 +7,58 @@ namespace BurnOutSharp.ProtectionType
{
public class StarForce
{
- public static string CheckContents(string file, string fileContent)
+ public static string CheckContents(string file, byte[] fileContent)
{
- int position;
- if (fileContent.Contains("(" + (char)0x00 + "c" + (char)0x00 + ")" + (char)0x00 + " " + (char)0x00 + "P" + (char)0x00
- + "r" + (char)0x00 + "o" + (char)0x00 + "t" + (char)0x00 + "e" + (char)0x00 + "c" + (char)0x00 + "t" + (char)0x00
- + "i" + (char)0x00 + "o" + (char)0x00 + "n" + (char)0x00 + " " + (char)0x00 + "T" + (char)0x00 + "e" + (char)0x00
- + "c" + (char)0x00 + "h" + (char)0x00 + "n" + (char)0x00 + "o" + (char)0x00 + "l" + (char)0x00 + "o" + (char)0x00
- + "g" + (char)0x00 + "y" + (char)0x00)
- || fileContent.Contains("Protection Technology, Ltd."))
+ // "(" + (char)0x00 + "c" + (char)0x00 + ")" + (char)0x00 + " " + (char)0x00 + "P" + (char)0x00 + "r" + (char)0x00 + "o" + (char)0x00 + "t" + (char)0x00 + "e" + (char)0x00 + "c" + (char)0x00 + "t" + (char)0x00 + "i" + (char)0x00 + "o" + (char)0x00 + "n" + (char)0x00 + " " + (char)0x00 + "T" + (char)0x00 + "e" + (char)0x00 + "c" + (char)0x00 + "h" + (char)0x00 + "n" + (char)0x00 + "o" + (char)0x00 + "l" + (char)0x00 + "o" + (char)0x00 + "g" + (char)0x00 + "y" + (char)0x00
+ byte[] check = new byte[] { 0x28, 0x00, 0x63, 0x00, 0x29, 0x00, 0x20, 0x00, 0x50, 0x00, 0x72, 0x00, 0x6F, 0x00, 0x74, 0x00, 0x65, 0x00, 0x63, 0x00, 0x74, 0x00, 0x69, 0x00, 0x6F, 0x00, 0x6E, 0x00, 0x20, 0x00, 0x54, 0x00, 0x65, 0x00, 0x63, 0x00, 0x68, 0x00, 0x6E, 0x00, 0x6F, 0x00, 0x6C, 0x00, 0x6F, 0x00, 0x67, 0x00, 0x79, 0x00 };
+ if (fileContent.Contains(check, out int position))
{
- //if (FileContent.Contains("PSA_GetDiscLabel")
- //if (FileContent.Contains("(c) Protection Technology")
- position = fileContent.IndexOf("TradeName") - 1;
- if (position != -1 && position != -2)
- return "StarForce " + Utilities.GetFileVersion(file) + " (" + fileContent.Substring(position + 22, 30).Split((char)0x00)[0] + ")";
+ // "PSA_GetDiscLabel"
+ // byte[] check2 = new byte[] { 0x50, 0x53, 0x41, 0x5F, 0x47, 0x65, 0x74, 0x44, 0x69, 0x73, 0x63, 0x4C, 0x61, 0x62, 0x65, 0x6C };
+
+ // "(c) Protection Technology"
+ // byte[] check2 = new byte[] { 0x28, 0x63, 0x29, 0x20, 0x50, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x79 };
+
+ // "TradeName"
+ byte[] check2 = new byte[] { 0x54, 0x72, 0x61, 0x64, 0x65, 0x4E, 0x61, 0x6D, 0x65 };
+ if (fileContent.Contains(check2, out int position2) && position2 != 0)
+ return $"StarForce {Utilities.GetFileVersion(file)} ({fileContent.Skip(position2 + 22).TakeWhile(c => c != 0x00)}) (Index {position}, {position2})";
else
- return "StarForce " + Utilities.GetFileVersion(file);
+ return $"StarForce {Utilities.GetFileVersion(file)} (Index {position}, {position2})";
}
- if (fileContent.Contains(".sforce")
- || fileContent.Contains(".brick"))
+ // "Protection Technology, Ltd."
+ check = new byte[] { 0x50, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x79, 0x2C, 0x20, 0x4C, 0x74, 0x64, 0x2E };
+ if (fileContent.Contains(check, out position))
{
- return "StarForce 3-5";
+ // "PSA_GetDiscLabel"
+ // byte[] check2 = new byte[] { 0x50, 0x53, 0x41, 0x5F, 0x47, 0x65, 0x74, 0x44, 0x69, 0x73, 0x63, 0x4C, 0x61, 0x62, 0x65, 0x6C };
+
+ // "(c) Protection Technology"
+ // byte[] check2 = new byte[] { 0x28, 0x63, 0x29, 0x20, 0x50, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x20, 0x54, 0x65, 0x63, 0x68, 0x6E, 0x6F, 0x6C, 0x6F, 0x67, 0x79 };
+
+ // "TradeName"
+ byte[] check2 = new byte[] { 0x54, 0x72, 0x61, 0x64, 0x65, 0x4E, 0x61, 0x6D, 0x65 };
+ if (fileContent.Contains(check2, out int position2) && position2 != 0)
+ return $"StarForce {Utilities.GetFileVersion(file)} ({fileContent.Skip(position2 + 22).TakeWhile(c => c != 0x00)}) (Index {position}, {position2})";
+ else
+ return $"StarForce {Utilities.GetFileVersion(file)} (Index {position}, {position2})";
}
- if (fileContent.Contains("P" + (char)0x00 + "r" + (char)0x00 + "o" + (char)0x00 + "t" + (char)0x00 + "e" + (char)0x00
- + "c" + (char)0x00 + "t" + (char)0x00 + "e" + (char)0x00 + "d" + (char)0x00 + " " + (char)0x00 + "M" + (char)0x00
- + "o" + (char)0x00 + "d" + (char)0x00 + "u" + (char)0x00 + "l" + (char)0x00 + "e"))
- {
- return "StarForce 5";
- }
+ // ".sforce"
+ check = new byte[] { 0x2E, 0x73, 0x66, 0x6F, 0x72, 0x63, 0x65 };
+ if (fileContent.Contains(check, out position))
+ return $"StarForce 3-5 (Index {position})";
+
+ // ".brick"
+ check = new byte[] { 0x2E, 0x62, 0x72, 0x69, 0x63, 0x6B };
+ if (fileContent.Contains(check, out position))
+ return $"StarForce 3-5 (Index {position})";
+
+ // "P" + (char)0x00 + "r" + (char)0x00 + "o" + (char)0x00 + "t" + (char)0x00 + "e" + (char)0x00 + "c" + (char)0x00 + "t" + (char)0x00 + "e" + (char)0x00 + "d" + (char)0x00 + " " + (char)0x00 + "M" + (char)0x00 + "o" + (char)0x00 + "d" + (char)0x00 + "u" + (char)0x00 + "l" + (char)0x00 + "e"
+ check = new byte[] { 0x50, 0x00, 0x72, 0x00, 0x6f, 0x00, 0x74, 0x00, 0x65, 0x00, 0x63, 0x00, 0x74, 0x00, 0x65, 0x00, 0x64, 0x00, 0x20, 0x00, 0x4d, 0x00, 0x6f, 0x00, 0x64, 0x00, 0x75, 0x00, 0x6c, 0x00, 0x65 };
+ if (fileContent.Contains(check, out position))
+ return $"StarForce 5 (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/Sysiphus.cs b/BurnOutSharp/ProtectionType/Sysiphus.cs
index f7ba6b0a..b489de1c 100644
--- a/BurnOutSharp/ProtectionType/Sysiphus.cs
+++ b/BurnOutSharp/ProtectionType/Sysiphus.cs
@@ -1,39 +1,34 @@
-using System.IO;
-
-namespace BurnOutSharp.ProtectionType
+namespace BurnOutSharp.ProtectionType
{
public class Sysiphus
{
- public static string CheckContents(string file, string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- int position;
- if ((position = fileContent.IndexOf("V SUHPISYSDVD")) > -1)
- return "Sysiphus DVD " + GetVersion(file, position);
+ // "V SUHPISYSDVD"
+ byte[] check = new byte[] { 0x56, 0x20, 0x53, 0x55, 0x48, 0x50, 0x49, 0x53, 0x59, 0x53, 0x44, 0x56, 0x44 };
+ if (fileContent.Contains(check, out int position))
+ return $"Sysiphus DVD {GetVersion(fileContent, position)} (Index {position})";
- if ((position = fileContent.IndexOf("V SUHPISYS")) > -1)
- return "Sysiphus " + GetVersion(file, position);
+ // "V SUHPISYS"
+ check = new byte[] { 0x56, 0x20, 0x53, 0x55, 0x48, 0x50, 0x49, 0x53, 0x59, 0x53 };
+ if (fileContent.Contains(check, out position))
+ return $"Sysiphus {GetVersion(fileContent, position)} (Index {position})";
return null;
}
- private static string GetVersion(string file, int position)
+ private static string GetVersion(byte[] fileContent, int position)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
+ int index = position - 3;
+ char subVersion = (char)fileContent[index];
+ index++;
+ index++;
+ char version = (char)fileContent[index];
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
- {
- br.BaseStream.Seek(position - 3, SeekOrigin.Begin);
- char subVersion = br.ReadChar();
- br.ReadChar();
- char version = br.ReadChar();
-
- if (char.IsNumber(version) && char.IsNumber(subVersion))
- return version + "." + subVersion;
- else
- return "";
- }
+ if (char.IsNumber(version) && char.IsNumber(subVersion))
+ return $"{version}.{subVersion}";
+ else
+ return "";
}
}
}
diff --git a/BurnOutSharp/ProtectionType/Tages.cs b/BurnOutSharp/ProtectionType/Tages.cs
index 34807dff..70ff48fe 100644
--- a/BurnOutSharp/ProtectionType/Tages.cs
+++ b/BurnOutSharp/ProtectionType/Tages.cs
@@ -7,16 +7,26 @@ namespace BurnOutSharp.ProtectionType
{
public class Tages
{
- public static string CheckContents(string file, string fileContent)
+ public static string CheckContents(string file, byte[] fileContent)
{
- int position;
- if (fileContent.Contains("protected-tages-runtime.exe") ||
- fileContent.Contains("tagesprotection.com"))
- return "TAGES " + Utilities.GetFileVersion(file);
+ // "protected-tages-runtime.exe"
+ byte[] check = new byte[] { 0x70, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74, 0x65, 0x64, 0x2D, 0x74, 0x61, 0x67, 0x65, 0x73, 0x2D, 0x72, 0x75, 0x6E, 0x74, 0x69, 0x6D, 0x65, 0x2E, 0x65, 0x78, 0x65 };
+ if (fileContent.Contains(check, out int position))
+ return $"TAGES {Utilities.GetFileVersion(file)} (Index {position})";
- if ((position = fileContent.IndexOf("" + (char)0xE8 + "u" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0xE8)) > -1
- && fileContent.Substring(--position + 8, 3) == "" + (char)0xFF + (char)0xFF + "h") // TODO: Verify this subtract
- return "TAGES " + GetVersion(file, position);
+ // "tagesprotection.com"
+ check = new byte[] { 0x74, 0x61, 0x67, 0x65, 0x73, 0x70, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74, 0x69, 0x6F, 0x6E, 0x2E, 0x63, 0x6F, 0x6D };
+ if (fileContent.Contains(check, out position))
+ return $"TAGES {Utilities.GetFileVersion(file)} (Index {position})";
+
+ // (char)0xE8 + "u" + (char)0x00 + (char)0x00 + (char)0x00 + (char)0xE8
+ check = new byte[] { 0xE8, 0x75, 0x00, 0x00, 0x00, 0xE8 };
+ if (fileContent.Contains(check, out position))
+ {
+ // (char)0xFF + (char)0xFF + "h"
+ if (new ArraySegment(fileContent, --position + 8, 3).SequenceEqual(new byte[] { 0xFF, 0xFF, 0x68 })) // TODO: Verify this subtract
+ return $"TAGES {GetVersion(fileContent, position)} (Index {position})";
+ }
return null;
}
@@ -78,27 +88,19 @@ namespace BurnOutSharp.ProtectionType
return null;
}
- private static string GetVersion(string file, int position)
+ private static string GetVersion(byte[] fileContent, int position)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
-
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
+ switch (fileContent[position + 7])
{
- br.BaseStream.Seek(position + 7, SeekOrigin.Begin);
- byte bVersion = br.ReadByte();
- switch (bVersion)
- {
- case 0x1B:
- return "5.3-5.4";
- case 0x14:
- return "5.5.0";
- case 0x4:
- return "5.5.2";
- }
- return "";
+ case 0x1B:
+ return "5.3-5.4";
+ case 0x14:
+ return "5.5.0";
+ case 0x4:
+ return "5.5.2";
}
+
+ return "";
}
}
}
diff --git a/BurnOutSharp/ProtectionType/ThreePLock.cs b/BurnOutSharp/ProtectionType/ThreePLock.cs
index dd22e49a..2df5cc4a 100644
--- a/BurnOutSharp/ProtectionType/ThreePLock.cs
+++ b/BurnOutSharp/ProtectionType/ThreePLock.cs
@@ -2,14 +2,22 @@
{
public class ThreePLock
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains(".ldr")
- || fileContent.Contains(".ldt"))
- // || fileContent.Contains("Y" + (char)0xC3 + "U" + (char)0x8B + (char)0xEC + (char)0x83 + (char)0xEC + "0SVW")
- {
- return "3PLock";
- }
+ // ".ldr"
+ byte[] check = new byte[] { 0x2E, 0x6C, 0x64, 0x72 };
+ if (fileContent.Contains(check, out int position))
+ return $"3PLock (Index {position})";
+
+ // ".ldt"
+ check = new byte[] { 0x2E, 0x6C, 0x64, 0x74 };
+ if (fileContent.Contains(check, out position))
+ return $"3PLock (Index {position})";
+
+ // "Y" + (char)0xC3 + "U" + (char)0x8B + (char)0xEC + (char)0x83 + (char)0xEC + "0SVW"
+ // check = new byte[] { 0x59, 0xC3, 0x55, 0x8B, 0xEC, 0x83, 0xEC, 0x30, 0x53, 0x56, 0x57 };
+ //if (fileContent.Contains(check, out position))
+ // return $"3PLock (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/VOBProtectCDDVD.cs b/BurnOutSharp/ProtectionType/VOBProtectCDDVD.cs
index fa7b4c54..3f1705c2 100644
--- a/BurnOutSharp/ProtectionType/VOBProtectCDDVD.cs
+++ b/BurnOutSharp/ProtectionType/VOBProtectCDDVD.cs
@@ -7,35 +7,37 @@ namespace BurnOutSharp.ProtectionType
{
public class VOBProtectCDDVD
{
- public static string CheckContents(string file, string fileContent)
+ public static string CheckContents(string file, byte[] fileContent)
{
- int position;
- if ((position = fileContent.IndexOf("VOB ProtectCD")) > -1)
- return "VOB ProtectCD/DVD " + GetOldVersion(file, --position); // TODO: Verify this subtract
+ // "VOB ProtectCD"
+ byte[] check = new byte[] { 0x56, 0x4F, 0x42, 0x20, 0x50, 0x72, 0x6F, 0x74, 0x65, 0x63, 0x74, 0x43, 0x44 };
+ if (fileContent.Contains(check, out int position))
+ return $"VOB ProtectCD/DVD {GetOldVersion(fileContent, --position)} (Index {position})"; // TODO: Verify this subtract
- if ((position = fileContent.IndexOf("DCP-BOV" + (char)0x00 + (char)0x00)) > -1)
+ // "DCP-BOV" + (char)0x00 + (char)0x00
+ check = new byte[] { 0x44, 0x43, 0x50, 0x2D, 0x42, 0x4F, 0x56, 0x00, 0x00 };
+ if (fileContent.Contains(check, out position))
{
- string version = GetVersion(file, --position); // TODO: Verify this subtract
+ string version = GetVersion(fileContent, --position); // TODO: Verify this subtract
if (version.Length > 0)
- {
- return "VOB ProtectCD/DVD " + version;
- }
+ return $"VOB ProtectCD/DVD {version} (Index {position})";
- version = EVORE.SearchProtectDiscVersion(file);
+ version = EVORE.SearchProtectDiscVersion(file, fileContent);
if (version.Length > 0)
{
if (version.StartsWith("2"))
- {
- version = "6" + version.Substring(1);
- }
- return "VOB ProtectCD/DVD " + version;
+ version = $"6{version.Substring(1)}";
+
+ return $"VOB ProtectCD/DVD {version} (Index {position})";
}
- return "VOB ProtectCD/DVD 5.9-6.0" + GetBuild(file, position);
+ return $"VOB ProtectCD/DVD 5.9-6.0 {GetBuild(fileContent, position)} (Index {position})";
}
- if (fileContent.Contains(".vob.pcd"))
- return "VOB ProtectCD";
+ // ".vob.pcd"
+ check = new byte[] { 0x2E, 0x76, 0x6F, 0x62, 0x2E, 0x70, 0x63, 0x64 };
+ if (fileContent.Contains(check, out position))
+ return $"VOB ProtectCD (Index {position})";
return null;
}
@@ -56,68 +58,36 @@ namespace BurnOutSharp.ProtectionType
return null;
}
- private static string GetBuild(string file, int position)
+ private static string GetBuild(byte[] fileContent, int position)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
+ if (!char.IsNumber((char)fileContent[position - 13]))
+ return ""; //Build info removed
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
- {
- br.BaseStream.Seek(position - 13, SeekOrigin.Begin);
- if (!char.IsNumber(br.ReadChar()))
- return ""; //Build info removed
-
- br.BaseStream.Seek(position - 4, SeekOrigin.Begin);
- int build = br.ReadInt16();
- return " (Build " + build + ")";
- }
+ int build = BitConverter.ToInt16(fileContent, position - 4); // Check if this is supposed to be a 4-byte read
+ return $" (Build {build})";
}
- private static string GetOldVersion(string file, int position)
+ private static string GetOldVersion(byte[] fileContent, int position)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
+ char[] version = new ArraySegment(fileContent, position + 16, 4).Select(b => (char)b).ToArray(); // Begin reading after "VOB ProtectCD"
+ if (char.IsNumber(version[0]) && char.IsNumber(version[2]) && char.IsNumber(version[3]))
+ return $"{version[0]}.{version[2]}{version[3]}";
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
- {
- char[] version = new char[3];
- br.BaseStream.Seek(position + 16, SeekOrigin.Begin); // Begin reading after "VOB ProtectCD"
- version[0] = br.ReadChar();
- br.ReadByte();
- version[1] = br.ReadChar();
- version[2] = br.ReadChar();
-
- if (char.IsNumber(version[0]) && char.IsNumber(version[1]) && char.IsNumber(version[2]))
- return version[0] + "." + version[1] + version[2];
-
- return "old";
- }
+ return "old";
}
- private static string GetVersion(string file, int position)
+ private static string GetVersion(byte[] fileContent, int position)
{
- if (file == null || !File.Exists(file))
- return string.Empty;
-
- using (var fs = File.Open(file, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
- using (var br = new BinaryReader(fs))
+ if (fileContent[position - 2] == 5)
{
- br.BaseStream.Seek(position - 2, SeekOrigin.Begin);
- byte version = br.ReadByte();
- if (version == 5)
- {
- br.BaseStream.Seek(position - 4, SeekOrigin.Begin);
- byte subsubVersion = (byte)((br.ReadByte() & 0xF0) >> 4);
- byte subVersion = (byte)((br.ReadByte() & 0xF0) >> 4);
- return version + "." + subVersion + "." + subsubVersion;
- }
- else
- {
- return "";
- }
+ int index = position - 4;
+ byte subsubVersion = (byte)((fileContent[index] & 0xF0) >> 4);
+ index++;
+ byte subVersion = (byte)((fileContent[index] & 0xF0) >> 4);
+ return $"5.{subVersion}.{subsubVersion}";
}
+
+ return "";
}
}
}
diff --git a/BurnOutSharp/ProtectionType/WTMCDProtect.cs b/BurnOutSharp/ProtectionType/WTMCDProtect.cs
index 906b865e..9ce234ea 100644
--- a/BurnOutSharp/ProtectionType/WTMCDProtect.cs
+++ b/BurnOutSharp/ProtectionType/WTMCDProtect.cs
@@ -7,10 +7,12 @@ namespace BurnOutSharp.ProtectionType
{
public class WTMCDProtect
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("WTM76545"))
- return "WTM CD Protect";
+ // "WTM76545"
+ byte[] check = new byte[] { 0x57, 0x54, 0x4D, 0x37, 0x36, 0x35, 0x34, 0x35 };
+ if (fileContent.Contains(check, out int position))
+ return $"WTM CD Protect (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/WiseInstaller.cs b/BurnOutSharp/ProtectionType/WiseInstaller.cs
new file mode 100644
index 00000000..7a2e0c02
--- /dev/null
+++ b/BurnOutSharp/ProtectionType/WiseInstaller.cs
@@ -0,0 +1,63 @@
+using System;
+using System.Collections.Generic;
+using System.IO;
+using Wise = WiseUnpacker.WiseUnpacker;
+
+namespace BurnOutSharp.ProtectionType
+{
+ public class WiseInstaller
+ {
+ public static List CheckContents(string file, byte[] fileContent)
+ {
+ // "WiseMain"
+ byte[] check = new byte[] { 0x57, 0x69, 0x73, 0x65, 0x4D, 0x61, 0x69, 0x6E };
+ if (fileContent.Contains(check, out int position))
+ {
+ List protections = new List { $"Wise Installation Wizard Module (Index {position})" };
+
+ if (!File.Exists(file))
+ return protections;
+
+ protections.AddRange(WiseInstaller.Scan(file));
+
+ return protections;
+ }
+
+ return null;
+ }
+
+ public static List Scan(string file)
+ {
+ List protections = new List();
+
+ // If the installer file itself fails
+ try
+ {
+ string tempPath = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+ Directory.CreateDirectory(tempPath);
+
+ Wise unpacker = new Wise();
+ unpacker.ExtractTo(file, tempPath);
+
+ foreach (string tempFile in Directory.EnumerateFiles(tempPath, "*", SearchOption.AllDirectories))
+ {
+ string protection = ProtectionFind.ScanContent(tempFile);
+
+ // If tempfile cleanup fails
+ try
+ {
+ File.Delete(tempFile);
+ }
+ catch { }
+
+ if (!string.IsNullOrEmpty(protection))
+ protections.Add($"\r\n{tempFile.Substring(tempPath.Length)} - {protection}");
+ }
+ }
+ catch { }
+
+ return protections;
+ }
+
+ }
+}
diff --git a/BurnOutSharp/ProtectionType/XtremeProtector.cs b/BurnOutSharp/ProtectionType/XtremeProtector.cs
index 03893d1b..56baf8e0 100644
--- a/BurnOutSharp/ProtectionType/XtremeProtector.cs
+++ b/BurnOutSharp/ProtectionType/XtremeProtector.cs
@@ -2,10 +2,12 @@
{
public class XtremeProtector
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("XPROT "))
- return "Xtreme-Protector";
+ // "XPROT "
+ byte[] check = new byte[] { 0x58, 0x50, 0x52, 0x4F, 0x54, 0x20, 0x20, 0x20 };
+ if (fileContent.Contains(check, out int position))
+ return $"Xtreme-Protector (Index {position})";
return null;
}
diff --git a/BurnOutSharp/ProtectionType/dotFuscator.cs b/BurnOutSharp/ProtectionType/dotFuscator.cs
index c8ac53cd..0d5a4d84 100644
--- a/BurnOutSharp/ProtectionType/dotFuscator.cs
+++ b/BurnOutSharp/ProtectionType/dotFuscator.cs
@@ -2,10 +2,12 @@
{
public class dotFuscator
{
- public static string CheckContents(string fileContent)
+ public static string CheckContents(byte[] fileContent)
{
- if (fileContent.Contains("DotfuscatorAttribute"))
- return "dotFuscator";
+ // "DotfuscatorAttribute"
+ byte[] check = new byte[] { 0x44, 0x6F, 0x74, 0x66, 0x75, 0x73, 0x63, 0x61, 0x74, 0x6F, 0x72, 0x41, 0x74, 0x74, 0x72, 0x69, 0x62, 0x75, 0x74, 0x65 };
+ if (fileContent.Contains(check, out int position))
+ return $"dotFuscator (Index {position})";
return null;
}
diff --git a/BurnOutSharp/StormLib.dll b/BurnOutSharp/StormLib.dll
new file mode 100644
index 00000000..f8777341
Binary files /dev/null and b/BurnOutSharp/StormLib.dll differ
diff --git a/BurnOutSharp/Utilities.cs b/BurnOutSharp/Utilities.cs
index e4e55fcb..035db71a 100644
--- a/BurnOutSharp/Utilities.cs
+++ b/BurnOutSharp/Utilities.cs
@@ -9,6 +9,66 @@ namespace BurnOutSharp
{
public static class Utilities
{
+ ///
+ /// Search for a byte array in another array
+ ///
+ public static bool Contains(this byte[] stack, byte[] needle, out int position, int start = 0, int end = -1)
+ {
+ // Initialize the found position to -1
+ position = -1;
+
+ // If either array is null or empty, we can't do anything
+ if (stack == null || stack.Length == 0 || needle == null || needle.Length == 0)
+ return false;
+
+ // If the needle array is larger than the stack array, it can't be contained within
+ if (needle.Length > stack.Length)
+ return false;
+
+ // If start or end are not set properly, set them to defaults
+ if (start < 0)
+ start = 0;
+ if (end < 0)
+ end = stack.Length - needle.Length;
+
+ for (int i = start; i < end; i++)
+ {
+ if (stack.EqualAt(needle, i))
+ {
+ position = i;
+ return true;
+ }
+ }
+
+ return false;
+ }
+
+ ///
+ /// See if a byte array starts with another
+ ///
+ public static bool StartsWith(this byte[] stack, byte[] needle)
+ {
+ return stack.Contains(needle, out int _, start: 0, end: 1);
+ }
+
+ ///
+ /// Get if a stack at a certain index is equal to a needle
+ ///
+ private static bool EqualAt(this byte[] stack, byte[] needle, int index)
+ {
+ // If we're too close to the end of the stack, return false
+ if (needle.Length >= stack.Length - index)
+ return false;
+
+ for (int i = 0; i < needle.Length; i++)
+ {
+ if (stack[i + index] != needle[i])
+ return false;
+ }
+
+ return true;
+ }
+
///
/// Get the file version as reported by the filesystem
///
diff --git a/LICENSE b/LICENSE
index dbbe3558..e72bfdda 100644
--- a/LICENSE
+++ b/LICENSE
@@ -1,21 +1,23 @@
- GNU AFFERO GENERAL PUBLIC LICENSE
- Version 3, 19 November 2007
+ GNU GENERAL PUBLIC LICENSE
+ Version 3, 29 June 2007
- Copyright (C) 2007 Free Software Foundation, Inc.
+ Copyright (C) 2007 Free Software Foundation, Inc.
Everyone is permitted to copy and distribute verbatim copies
of this license document, but changing it is not allowed.
Preamble
- The GNU Affero General Public License is a free, copyleft license for
-software and other kinds of works, specifically designed to ensure
-cooperation with the community in the case of network server software.
+ The GNU General Public License is a free, copyleft license for
+software and other kinds of works.
The licenses for most software and other practical works are designed
to take away your freedom to share and change the works. By contrast,
-our General Public Licenses are intended to guarantee your freedom to
+the GNU General Public License is intended to guarantee your freedom to
share and change all versions of a program--to make sure it remains free
-software for all its users.
+software for all its users. We, the Free Software Foundation, use the
+GNU General Public License for most of our software; it applies also to
+any other work released this way by its authors. You can apply it to
+your programs, too.
When we speak of free software, we are referring to freedom, not
price. Our General Public Licenses are designed to make sure that you
@@ -24,34 +26,44 @@ them if you wish), that you receive source code or can get it if you
want it, that you can change the software or use pieces of it in new
free programs, and that you know you can do these things.
- Developers that use our General Public Licenses protect your rights
-with two steps: (1) assert copyright on the software, and (2) offer
-you this License which gives you legal permission to copy, distribute
-and/or modify the software.
+ To protect your rights, we need to prevent others from denying you
+these rights or asking you to surrender the rights. Therefore, you have
+certain responsibilities if you distribute copies of the software, or if
+you modify it: responsibilities to respect the freedom of others.
- A secondary benefit of defending all users' freedom is that
-improvements made in alternate versions of the program, if they
-receive widespread use, become available for other developers to
-incorporate. Many developers of free software are heartened and
-encouraged by the resulting cooperation. However, in the case of
-software used on network servers, this result may fail to come about.
-The GNU General Public License permits making a modified version and
-letting the public access it on a server without ever releasing its
-source code to the public.
+ For example, if you distribute copies of such a program, whether
+gratis or for a fee, you must pass on to the recipients the same
+freedoms that you received. You must make sure that they, too, receive
+or can get the source code. And you must show them these terms so they
+know their rights.
- The GNU Affero General Public License is designed specifically to
-ensure that, in such cases, the modified source code becomes available
-to the community. It requires the operator of a network server to
-provide the source code of the modified version running there to the
-users of that server. Therefore, public use of a modified version, on
-a publicly accessible server, gives the public access to the source
-code of the modified version.
+ Developers that use the GNU GPL protect your rights with two steps:
+(1) assert copyright on the software, and (2) offer you this License
+giving you legal permission to copy, distribute and/or modify it.
- An older license, called the Affero General Public License and
-published by Affero, was designed to accomplish similar goals. This is
-a different license, not a version of the Affero GPL, but Affero has
-released a new version of the Affero GPL which permits relicensing under
-this license.
+ For the developers' and authors' protection, the GPL clearly explains
+that there is no warranty for this free software. For both users' and
+authors' sake, the GPL requires that modified versions be marked as
+changed, so that their problems will not be attributed erroneously to
+authors of previous versions.
+
+ Some devices are designed to deny users access to install or run
+modified versions of the software inside them, although the manufacturer
+can do so. This is fundamentally incompatible with the aim of
+protecting users' freedom to change the software. The systematic
+pattern of such abuse occurs in the area of products for individuals to
+use, which is precisely where it is most unacceptable. Therefore, we
+have designed this version of the GPL to prohibit the practice for those
+products. If such problems arise substantially in other domains, we
+stand ready to extend this provision to those domains in future versions
+of the GPL, as needed to protect the freedom of users.
+
+ Finally, every program is threatened constantly by software patents.
+States should not allow patents to restrict development and use of
+software on general-purpose computers, but in those that do, we wish to
+avoid the special danger that patents applied to a free program could
+make it effectively proprietary. To prevent this, the GPL assures that
+patents cannot be used to render the program non-free.
The precise terms and conditions for copying, distribution and
modification follow.
@@ -60,7 +72,7 @@ modification follow.
0. Definitions.
- "This License" refers to version 3 of the GNU Affero General Public License.
+ "This License" refers to version 3 of the GNU General Public License.
"Copyright" also means copyright-like laws that apply to other kinds of
works, such as semiconductor masks.
@@ -537,45 +549,35 @@ to collect a royalty for further conveying from those to whom you convey
the Program, the only way you could satisfy both those terms and this
License would be to refrain entirely from conveying the Program.
- 13. Remote Network Interaction; Use with the GNU General Public License.
-
- Notwithstanding any other provision of this License, if you modify the
-Program, your modified version must prominently offer all users
-interacting with it remotely through a computer network (if your version
-supports such interaction) an opportunity to receive the Corresponding
-Source of your version by providing access to the Corresponding Source
-from a network server at no charge, through some standard or customary
-means of facilitating copying of software. This Corresponding Source
-shall include the Corresponding Source for any work covered by version 3
-of the GNU General Public License that is incorporated pursuant to the
-following paragraph.
+ 13. Use with the GNU Affero General Public License.
Notwithstanding any other provision of this License, you have
permission to link or combine any covered work with a work licensed
-under version 3 of the GNU General Public License into a single
+under version 3 of the GNU Affero General Public License into a single
combined work, and to convey the resulting work. The terms of this
License will continue to apply to the part which is the covered work,
-but the work with which it is combined will remain governed by version
-3 of the GNU General Public License.
+but the special requirements of the GNU Affero General Public License,
+section 13, concerning interaction through a network will apply to the
+combination as such.
14. Revised Versions of this License.
The Free Software Foundation may publish revised and/or new versions of
-the GNU Affero General Public License from time to time. Such new versions
-will be similar in spirit to the present version, but may differ in detail to
+the GNU General Public License from time to time. Such new versions will
+be similar in spirit to the present version, but may differ in detail to
address new problems or concerns.
Each version is given a distinguishing version number. If the
-Program specifies that a certain numbered version of the GNU Affero General
+Program specifies that a certain numbered version of the GNU General
Public License "or any later version" applies to it, you have the
option of following the terms and conditions either of that numbered
version or of any later version published by the Free Software
Foundation. If the Program does not specify a version number of the
-GNU Affero General Public License, you may choose any version ever published
+GNU General Public License, you may choose any version ever published
by the Free Software Foundation.
If the Program specifies that a proxy can decide which future
-versions of the GNU Affero General Public License can be used, that proxy's
+versions of the GNU General Public License can be used, that proxy's
public statement of acceptance of a version permanently authorizes you
to choose that version for the Program.
@@ -633,29 +635,40 @@ the "copyright" line and a pointer to where the full notice is found.
Copyright (C)
This program is free software: you can redistribute it and/or modify
- it under the terms of the GNU Affero General Public License as published
- by the Free Software Foundation, either version 3 of the License, or
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- GNU Affero General Public License for more details.
+ GNU General Public License for more details.
- You should have received a copy of the GNU Affero General Public License
- along with this program. If not, see .
+ You should have received a copy of the GNU General Public License
+ along with this program. If not, see .
Also add information on how to contact you by electronic and paper mail.
- If your software can interact with users remotely through a computer
-network, you should also make sure that it provides a way for users to
-get its source. For example, if your program is a web application, its
-interface could display a "Source" link that leads users to an archive
-of the code. There are many ways you could offer source, and different
-solutions will be better for different programs; see section 13 for the
-specific requirements.
+ If the program does terminal interaction, make it output a short
+notice like this when it starts in an interactive mode:
+
+ Copyright (C)
+ This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
+ This is free software, and you are welcome to redistribute it
+ under certain conditions; type `show c' for details.
+
+The hypothetical commands `show w' and `show c' should show the appropriate
+parts of the General Public License. Of course, your program's commands
+might be different; for a GUI interface, you would use an "about box".
You should also get your employer (if you work as a programmer) or school,
if any, to sign a "copyright disclaimer" for the program, if necessary.
-For more information on this, and how to apply and follow the GNU AGPL, see
-.
+For more information on this, and how to apply and follow the GNU GPL, see
+.
+
+ The GNU General Public License does not permit incorporating your program
+into proprietary programs. If your program is a subroutine library, you
+may consider it more useful to permit linking proprietary applications with
+the library. If this is what you want to do, use the GNU Lesser General
+Public License instead of this License. But first, please read
+.
\ No newline at end of file
diff --git a/README.md b/README.md
index 41d93d48..6a0fdc56 100644
--- a/README.md
+++ b/README.md
@@ -4,7 +4,16 @@
C# port of the protection scanning ability of [BurnOut](http://burnout.sourceforge.net/) plus numerous updates and additions. This currently compiles as a library so it can be used in any C# application. For an example of usage, see [DICUI](https://github.com/reignstumble/DICUI).
-In addition to the original BurnOut code, this port adds the ability to scan inside of Microsoft CAB files (courtesy of [libmspack4n](https://github.com/activescott/libmspack4n)) and InstallShield CAB files (courtesy of [UnshieldSharp](https://github.com/mnadareski/UnshieldSharp)).
+In addition to the original BurnOut code, the following libraries (or ports thereof) are used for file handling:
+
+- [HLExtract](https://github.com/Rupan/HLLib) - Various Valve archive format extraction
+- [libmspack4n](https://github.com/activescott/libmspack4n) - Microsoft CAB extraction
+- [psxt001z](https://github.com/Dremora/psxt001z) - PS1 LibCrypt detection
+- [SharpCompress](https://github.com/adamhathcock/sharpcompress) - 7zip/GZip/RAR/PKZIP extraction
+- [StormLib](https://github.com/ladislav-zezula/StormLib) - MPQ extraction
+- [StormLibSharp](https://github.com/robpaveza/stormlibsharp) - MPQ extraction
+- [UnshieldSharp](https://github.com/mnadareski/UnshieldSharp) - InstallShield CAB extraction
+- [WiseUnpacker](https://github.com/mnadareski/WiseUnpacker) - Wise Installer extraction
## Protections Detected
@@ -38,6 +47,7 @@ Below is a list of the protections that can be detected using this code:
- Hexalock Autolock
- Impulse Reactor
- IndyVCD
+- Inno Setup
- JoWooD X-Prot (v1/v2)
- Key2Audio XS
- Key-Lock (Dongle)
@@ -66,6 +76,7 @@ Below is a list of the protections that can be detected using this code:
- Uplay (partial)
- VOB ProtectCD/DVD
- Winlock
+- WISE Installer
- WTM CD Protect
- WTM Copy Protection
- XCP
diff --git a/Test/Program.cs b/Test/Program.cs
index ea0f9f71..b0978055 100644
--- a/Test/Program.cs
+++ b/Test/Program.cs
@@ -1,4 +1,5 @@
using System;
+using System.IO;
using System.Linq;
using BurnOutSharp;
@@ -12,9 +13,15 @@ namespace Test
p.ProgressChanged += Changed;
foreach (string arg in args)
{
- Console.WriteLine(String.Join("\r\n", ProtectionFind.Scan(arg, p).Select(kvp => kvp.Key + ": " + kvp.Value)));
+ string protections = String.Join("\r\n", ProtectionFind.Scan(arg, p).Select(kvp => kvp.Key + ": " + kvp.Value.TrimEnd()));
+ Console.WriteLine(protections);
+ using (StreamWriter sw = new StreamWriter(File.OpenWrite($"{DateTime.Now:yyyy-MM-dd_HHmmss}.txt")))
+ {
+ sw.WriteLine(protections);
+ }
}
+ Console.WriteLine("Press any button to close...");
Console.ReadLine();
//ProtectionFind.ScanSectors('D', 2048);