make it use 'replace patterns'

This commit is contained in:
Li 2022-05-13 13:15:06 +12:00
parent ea888fcb74
commit 091ba4da79
8 changed files with 267 additions and 232 deletions

View File

BIN
.vs/CXMLCli/v17/.suo Normal file

Binary file not shown.

View File

@ -1,112 +1,113 @@
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BE72E673-25FF-47AB-AF5B-9448B69E3990}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>CXMLDecompiler</RootNamespace>
<AssemblyName>CXMLDecompiler</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>cxml.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="DotNetZip, Version=1.13.3.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.13.3\lib\net40\DotNetZip.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CXMLReader.cs" />
<Compile Include="CXMLBuilder.cs" />
<Compile Include="GimConv.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tools.cs" />
<Compile Include="VAG.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="cxml.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProjectGuid>{BE72E673-25FF-47AB-AF5B-9448B69E3990}</ProjectGuid>
<OutputType>Exe</OutputType>
<RootNamespace>CXMLDecompiler</RootNamespace>
<AssemblyName>CXMLDecompiler</AssemblyName>
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
<Deterministic>true</Deterministic>
<TargetFrameworkProfile />
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<PlatformTarget>AnyCPU</PlatformTarget>
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<Prefer32Bit>false</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x64\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
<OutputPath>bin\x64\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x64</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
<DebugSymbols>true</DebugSymbols>
<OutputPath>bin\x86\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<DebugType>full</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
<OutputPath>bin\x86\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<Optimize>true</Optimize>
<DebugType>pdbonly</DebugType>
<PlatformTarget>x86</PlatformTarget>
<ErrorReport>prompt</ErrorReport>
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
<Prefer32Bit>true</Prefer32Bit>
</PropertyGroup>
<PropertyGroup>
<ApplicationIcon>cxml.ico</ApplicationIcon>
</PropertyGroup>
<ItemGroup>
<Reference Include="DotNetZip, Version=1.13.3.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
<HintPath>..\packages\DotNetZip.1.13.3\lib\net40\DotNetZip.dll</HintPath>
</Reference>
<Reference Include="System" />
<Reference Include="System.Core" />
<Reference Include="System.Drawing" />
<Reference Include="System.Xml.Linq" />
<Reference Include="System.Data.DataSetExtensions" />
<Reference Include="Microsoft.CSharp" />
<Reference Include="System.Data" />
<Reference Include="System.Net.Http" />
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="CXMLReader.cs" />
<Compile Include="CXMLBuilder.cs" />
<Compile Include="GimConv.cs" />
<Compile Include="LoopbackHandler.cs" />
<Compile Include="Program.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="Tools.cs" />
<Compile Include="VAG.cs" />
</ItemGroup>
<ItemGroup>
<None Include="App.config" />
<None Include="packages.config" />
</ItemGroup>
<ItemGroup>
<Content Include="cxml.ico" />
</ItemGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
</Project>

View File

@ -1,13 +1,14 @@
using Ionic.Zlib;
using General;
using System;
using System.Collections.Generic;
using System.Diagnostics;
using General;
using System.IO;
using System.Text;
using System.Xml;
using System.Globalization;
namespace CXML
{
@ -67,6 +68,7 @@ namespace CXML
List<TypingInformation> SilicaTypingInformationList = new List<TypingInformation>();
String MagicReplacePattern = Tools.GenerateReplacePattern();
String SilicaTypingInformation = "SilicaTypingInformation{{[[";
FileStream InfoFile;
@ -89,16 +91,9 @@ namespace CXML
BinaryReader bHashIDTable;
BinaryReader bStringIDTable;
public class LoopbackHandler
{
public String FileName;
public String OldFileName;
public Int64 FilePointer;
}
List<LoopbackHandler> FileList = new List<LoopbackHandler>();
XmlWriter XMLFile;
XmlWriter XMLWriter;
public bool ProcessFiles = false;
public bool WaitExit = false;
@ -399,16 +394,22 @@ namespace CXML
XmlWriterSettings XMLSettings = new XmlWriterSettings();
XMLSettings.Indent = true;
XMLSettings.Encoding = Encoding.UTF8;
string XMLPath = Path.Combine(MainDir, XMLFilename);
XMLFile = XmlWriter.Create(XMLPath, XMLSettings);
XMLFile.WriteStartDocument();
XMLFile.WriteComment("REPLACE_WITH_SILICATOKEN");
StreamWriter sw = new StreamWriter(new MemoryStream(), Encoding.UTF8);
XMLWriter = XmlWriter.Create(sw, XMLSettings);
XMLWriter.WriteStartDocument();
XMLWriter.WriteComment(MagicReplacePattern);
AddTypingInfo("MAGIC", MagicNumber);
AddTypingInfo("VERSION", ReadVersion());
ReadElements();
XMLFile.WriteEndDocument();
XMLFile.Flush();
XMLFile.Close();
XMLWriter.WriteEndDocument();
XMLWriter.Flush();
XMLWriter.Close();
GotoEnd();
int bytesRemaining = Convert.ToInt32(InfoFile.Length - InfoFile.Position);
@ -432,44 +433,62 @@ namespace CXML
}
SilicaTypingInformation += "]]}}SilicaTypingInformation";
byte[] XMLBytes = new byte[sw.BaseStream.Length];
// Make corrections
string XmlData = File.ReadAllText(XMLPath, Encoding.UTF8);
XmlData = XmlData.Replace("REPLACE_WITH_SILICATOKEN", SilicaTypingInformation);
sw.Flush();
sw.BaseStream.Seek(0x00, SeekOrigin.Begin);
sw.BaseStream.Read(XMLBytes, 0x00, XMLBytes.Length);
sw.Close();
string XMLData = Encoding.UTF8.GetString(XMLBytes);
// Resolve Replace Patterns
XMLData = XMLData.Replace(MagicReplacePattern, SilicaTypingInformation);
foreach(LoopbackHandler lpHandler in FileList)
{
if(lpHandler.OldFileName != null)
{
if(lpHandler.FileName != null)
{
string oldName = Path.Combine(lpHandler.OldFileName);
string extension = Path.GetExtension(oldName);
string folderPath = Path.GetDirectoryName(oldName);
string newPath = Path.ChangeExtension(Path.Combine(folderPath, lpHandler.FileName), extension);
if(!File.Exists(newPath))
{
File.Move(oldName, newPath);
string xmlRelOldPath = oldName.Substring(Tools.GetRootFolder(oldName).Length + 1);
string xmlRelNewPath = newPath.Substring(Tools.GetRootFolder(newPath).Length + 1);
Console.WriteLine("Moved " + xmlRelOldPath + " => " + xmlRelNewPath);
XmlData = XmlData.Replace(xmlRelOldPath, xmlRelNewPath);
}
if (ProcessFiles)
ProcessFile(newPath);
}
else
{
Console.WriteLine("NOT MOVING: " + lpHandler.OldFileName);
if (ProcessFiles)
ProcessFile(lpHandler.OldFileName);
}
{
if (lpHandler.ReplacePattern != null && lpHandler.OldFileName != null)
{
string replacePattern = lpHandler.ReplacePattern;
string oldName = lpHandler.OldFileName;
string extension = Path.GetExtension(oldName);
string folderPath = Path.GetDirectoryName(oldName);
byte[] fileData = lpHandler.FileData;
if (lpHandler.FileName != null)
{
string newPath = Path.ChangeExtension(Path.Combine(folderPath, lpHandler.FileName), extension);
if (!Directory.Exists(folderPath))
Directory.CreateDirectory(folderPath);
if (!File.Exists(newPath))
{
File.WriteAllBytes(newPath, fileData);
string xmlRelNewPath = newPath.Substring(Tools.GetRootFolder(newPath).Length + 1);
Console.WriteLine("Resolved " + replacePattern + " => " + xmlRelNewPath);
XMLData = XMLData.Replace(replacePattern, xmlRelNewPath);
}
if (ProcessFiles)
ProcessFile(newPath);
}
else
{
Console.WriteLine("Unable to resolve: " + oldName);
if (!File.Exists(oldName))
File.WriteAllBytes(oldName, fileData);
if (ProcessFiles)
ProcessFile(oldName);
}
}
}
File.WriteAllText(XMLPath, XmlData);
File.WriteAllText(XMLPath, XMLData);
Term();
}
@ -493,7 +512,7 @@ namespace CXML
cxmlParser.Init(FileName);
cxmlParser.ProcessFiles = this.ProcessFiles;
cxmlParser.MainDir = DirectoryName;
cxmlParser.FileDir = Path.Combine(cxmlParser.MainDir,"files");
cxmlParser.FileDir = Path.Combine(cxmlParser.MainDir, "files");
cxmlParser.DecompileCXML(FileName);
}
catch (Exception) { };
@ -555,7 +574,7 @@ namespace CXML
}
}
public void RegisterFile(Int64 ElementPtr, String NewName, Boolean FileEntry, String IdealName=null)
public void RegisterFile(Int64 ElementPtr, String NewName, Boolean FileEntry, String ReplacePattern=null, byte[] FileData=null, String IdealName=null)
{
Console.WriteLine("Adding Entry for Loopback: 0x" + ElementPtr.ToString("X8", CultureInfo.InvariantCulture) + " (" + NewName + ")");
for(int i = 0; i < FileList.Count; i++)
@ -583,6 +602,8 @@ namespace CXML
{
lpHandler.OldFileName = NewName;
lpHandler.FileName = IdealName;
lpHandler.FileData = FileData;
lpHandler.ReplacePattern = ReplacePattern;
}
else
{
@ -610,12 +631,14 @@ namespace CXML
break;
case AttributeType.TYPE_INT:
AttributeValue = bTreeTable.ReadInt32();
Console.WriteLine("Int - Value: " + AttributeValue.ToString() + " sz:" + bTreeTable.ReadInt32());
int sz = bTreeTable.ReadInt32();
Console.WriteLine("Int - Value: " + AttributeValue.ToString() + " sz:" + sz);
break;
case AttributeType.TYPE_FLOAT:
float FloatValue = bTreeTable.ReadSingle();
AttributeValue = FloatValue.ToString("G9", CultureInfo.InvariantCulture) + "f";
Console.WriteLine("Float - Value: " + AttributeValue.ToString() + " sz:" + bTreeTable.ReadInt32());
sz = bTreeTable.ReadInt32();
Console.WriteLine("Float - Value: " + AttributeValue.ToString() + " sz:" + sz);
break;
case AttributeType.TYPE_STRING:
int StringOffset = bTreeTable.ReadInt32();
@ -689,28 +712,18 @@ namespace CXML
Byte[] FileData = new Byte[FileSz];
FileTable.Seek(FilePtr, SeekOrigin.Begin);
FileTable.Read(FileData, 0, FileSz);
string FileHash = Tools.GenerateHash(FileData);
string FileSmallHash = Tools.GenerateShortHash(FileData);
String FileHash = Tools.GenerateHash(FileData);
String FileSmallHash = Tools.GenerateShortHash(FileData);
String Extension = Tools.GetFileExtension(FileData);
String FileName = Path.Combine(FileDir, "original", FilePtr.ToString("X", CultureInfo.InvariantCulture) +"-"+FileHash + Extension);
String FileName = Path.Combine(FileDir, "original", FilePtr.ToString("X", CultureInfo.InvariantCulture) + "-" + FileHash + Extension);
String IdealName = ElementName + "-" + AttributeName + "-" + FileSmallHash + Extension;
if (!File.Exists(FileName))
{
Console.WriteLine("Writing: " + FileName);
String ReplacePattern = Tools.GenerateReplacePattern();
if (!Directory.Exists(Path.GetDirectoryName(FileName)))
Directory.CreateDirectory(Path.GetDirectoryName(FileName));
//File.WriteAllBytes(FileName, FileData);
RegisterFile(ElementPtr, FileName, true, ReplacePattern, FileData, IdealName);
File.WriteAllBytes(FileName, FileData);
RegisterFile(ElementPtr, FileName, true, IdealName);
}
else
{
Console.WriteLine("File allready extracted.");
}
string xmlRelPath = FileName.Substring(Tools.GetRootFolder(FileName).Length + 1);
AttributeValue = xmlRelPath;
AttributeValue = ReplacePattern;
break;
case AttributeType.TYPE_ID_STRING_LOOPBACK:
int StringIdTableOffset = bTreeTable.ReadInt32();
@ -725,7 +738,9 @@ namespace CXML
AttributeValue = Tools.ReadString(StringIDTable);
RegisterFile(LoopbackPtr, AttributeValue.ToString(), false);
Console.WriteLine("Loopback ID String: " + StringIdTableOffset + " sz: " + bTreeTable.ReadInt32());
sz = bTreeTable.ReadInt32();
Console.WriteLine("Loopback ID String: " + StringIdTableOffset + " sz: " + sz);
break;
case AttributeType.TYPE_ID_STRING: // This is probably right, tbh
StringIdTableOffset = bTreeTable.ReadInt32();
@ -733,7 +748,8 @@ namespace CXML
AttributeValue = Tools.ReadString(StringIDTable);
Console.WriteLine("ID String: " + StringIdTableOffset + " sz: " + bTreeTable.ReadInt32());
sz = bTreeTable.ReadInt32();
Console.WriteLine("ID String: " + StringIdTableOffset + " sz: " + sz);
break;
case AttributeType.TYPE_ID_INT_LOOPBACK:
int IntIdTableOffset = bTreeTable.ReadInt32();
@ -750,7 +766,8 @@ namespace CXML
AttributeValue = IDValue.ToString("X8", CultureInfo.InvariantCulture);
RegisterFile(LoopbackPtr, AttributeValue.ToString(), false);
Console.WriteLine("Loopback Int: " + IntIdTableOffset + " sz: " + bTreeTable.ReadInt32());
sz = bTreeTable.ReadInt32();
Console.WriteLine("Loopback Int: " + IntIdTableOffset + " sz: " + sz);
break;
case AttributeType.TYPE_ID_INT:
IntIdTableOffset = bTreeTable.ReadInt32();
@ -758,7 +775,8 @@ namespace CXML
IDValue = bIntIDTable.ReadInt32();
AttributeValue = IDValue.ToString("X8", CultureInfo.InvariantCulture);
Console.WriteLine("Int Id: " + IntIdTableOffset + " sz: " + bTreeTable.ReadInt32());
sz = bTreeTable.ReadInt32();
Console.WriteLine("Int Id: " + IntIdTableOffset + " sz: " + sz);
break;
default:
Console.WriteLine("UNKNOWN TYPE @ " + TreeTable.Position);
@ -768,8 +786,8 @@ namespace CXML
AddTypingInfo(ElementName + ":" + AttributeName, ((int)Type).ToString(CultureInfo.InvariantCulture));
Console.WriteLine(AttributeName + "=" + AttributeValue.ToString());
XMLFile.WriteAttributeString(AttributeName, AttributeValue.ToString());
XMLFile.Flush();
XMLWriter.WriteAttributeString(AttributeName, AttributeValue.ToString());
XMLWriter.Flush();
}
public void ReadElements()
@ -796,7 +814,7 @@ namespace CXML
Console.WriteLine("FirstChild: " + FirstChild);
Console.WriteLine("LastChild: " + LastChild);
XMLFile.WriteStartElement(ElementName);
XMLWriter.WriteStartElement(ElementName);
if(NumAttributes > 0)
{
@ -813,8 +831,8 @@ namespace CXML
}
XMLFile.WriteEndElement();
XMLFile.Flush();
XMLWriter.WriteEndElement();
XMLWriter.Flush();
if (NextSibling != -1)
{

View File

@ -0,0 +1,13 @@
using System;
namespace CXML
{
public class LoopbackHandler
{
public String FileName;
public String OldFileName;
public String ReplacePattern;
public byte[] FileData;
public Int64 FilePointer;
}
}

View File

@ -1,8 +1,5 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.Globalization;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
@ -13,14 +10,14 @@ namespace General
class Tools
{
public static byte[] bmp = Encoding.ASCII.GetBytes("BM"); // BMP
public static byte[] gif = Encoding.ASCII.GetBytes("GIF"); // GIF
public static byte[] png = new byte[] { 137, 80, 78, 71 }; // PNG
public static byte[] tiff = new byte[] { 73, 73, 42 }; // TIFF
public static byte[] tiff2 = new byte[] { 77, 77, 42 }; // TIFF
public static byte[] jpeg = new byte[] { 255, 216, 255 }; // jpeg
public static byte[] bmp = Encoding.ASCII.GetBytes("BM"); // BMP
public static byte[] gif = Encoding.ASCII.GetBytes("GIF"); // GIF
public static byte[] png = new byte[] { 137, 80, 78, 71 }; // PNG
public static byte[] tiff = new byte[] { 73, 73, 42 }; // TIFF
public static byte[] tiff2 = new byte[] { 77, 77, 42 }; // TIFF
public static byte[] jpeg = new byte[] { 255, 216, 255 }; // jpeg
public static Random rng = new Random(Guid.NewGuid().GetHashCode());
public static void WriteStringToStream(Stream s, String str)
{
Byte[] bytes = Encoding.UTF8.GetBytes(str);
@ -46,34 +43,40 @@ namespace General
stream.Seek(0, SeekOrigin.Begin);
stream.Read(Bytes, 0x00, StreamLen);
return Bytes;
}
public static string GetFileExtension(byte[] Bytes)
{
if (bmp.SequenceEqual(Bytes.Take(bmp.Length)))
{
return ".bmp";
}
else if (gif.SequenceEqual(Bytes.Take(gif.Length)))
{
return ".gif";
}
else if (png.SequenceEqual(Bytes.Take(png.Length)))
{
return ".png";
}
else if (tiff.SequenceEqual(Bytes.Take(tiff.Length)))
{
return ".tiff";
}
else if (tiff2.SequenceEqual(Bytes.Take(tiff2.Length)))
{
return ".tiff";
}
else if (jpeg.SequenceEqual(Bytes.Take(jpeg.Length)))
{
return ".jpg";
}
}
public static string GenerateReplacePattern()
{
byte[] RandomNumber = new byte[0x20];
rng.NextBytes(RandomNumber);
return "{{" + BitConverter.ToString(RandomNumber).Replace("-", "") + "}}";
}
public static string GetFileExtension(byte[] Bytes)
{
if (bmp.SequenceEqual(Bytes.Take(bmp.Length)))
{
return ".bmp";
}
else if (gif.SequenceEqual(Bytes.Take(gif.Length)))
{
return ".gif";
}
else if (png.SequenceEqual(Bytes.Take(png.Length)))
{
return ".png";
}
else if (tiff.SequenceEqual(Bytes.Take(tiff.Length)))
{
return ".tiff";
}
else if (tiff2.SequenceEqual(Bytes.Take(tiff2.Length)))
{
return ".tiff";
}
else if (jpeg.SequenceEqual(Bytes.Take(jpeg.Length)))
{
return ".jpg";
}
else if (IsZlib(Bytes))
{
return ".z";
@ -94,7 +97,7 @@ namespace General
{
return ".gim";
}
else if(!HasBinaryContent(Encoding.UTF8.GetString(Bytes)))
else if (!HasBinaryContent(Encoding.UTF8.GetString(Bytes)))
{
return ".txt";
}