make it use 'replace patterns'
This commit is contained in:
parent
ea888fcb74
commit
091ba4da79
Binary file not shown.
Binary file not shown.
Binary file not shown.
|
@ -1,112 +1,113 @@
|
||||||
<?xml version="1.0" encoding="utf-8"?>
|
<?xml version="1.0" encoding="utf-8"?>
|
||||||
<Project ToolsVersion="15.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
<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')" />
|
<Import Project="$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props" Condition="Exists('$(MSBuildExtensionsPath)\$(MSBuildToolsVersion)\Microsoft.Common.props')" />
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
|
||||||
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
|
||||||
<ProjectGuid>{BE72E673-25FF-47AB-AF5B-9448B69E3990}</ProjectGuid>
|
<ProjectGuid>{BE72E673-25FF-47AB-AF5B-9448B69E3990}</ProjectGuid>
|
||||||
<OutputType>Exe</OutputType>
|
<OutputType>Exe</OutputType>
|
||||||
<RootNamespace>CXMLDecompiler</RootNamespace>
|
<RootNamespace>CXMLDecompiler</RootNamespace>
|
||||||
<AssemblyName>CXMLDecompiler</AssemblyName>
|
<AssemblyName>CXMLDecompiler</AssemblyName>
|
||||||
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
<TargetFrameworkVersion>v4.6.1</TargetFrameworkVersion>
|
||||||
<FileAlignment>512</FileAlignment>
|
<FileAlignment>512</FileAlignment>
|
||||||
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects>
|
||||||
<Deterministic>true</Deterministic>
|
<Deterministic>true</Deterministic>
|
||||||
<TargetFrameworkProfile />
|
<TargetFrameworkProfile />
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<Optimize>false</Optimize>
|
<Optimize>false</Optimize>
|
||||||
<OutputPath>bin\Debug\</OutputPath>
|
<OutputPath>bin\Debug\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<Prefer32Bit>false</Prefer32Bit>
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
|
||||||
<PlatformTarget>AnyCPU</PlatformTarget>
|
<PlatformTarget>AnyCPU</PlatformTarget>
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<OutputPath>bin\Release\</OutputPath>
|
<OutputPath>bin\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<WarningLevel>4</WarningLevel>
|
<WarningLevel>4</WarningLevel>
|
||||||
<Prefer32Bit>false</Prefer32Bit>
|
<Prefer32Bit>false</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x64'">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<OutputPath>bin\x64\Debug\</OutputPath>
|
<OutputPath>bin\x64\Debug\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
<Prefer32Bit>true</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x64'">
|
||||||
<OutputPath>bin\x64\Release\</OutputPath>
|
<OutputPath>bin\x64\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<PlatformTarget>x64</PlatformTarget>
|
<PlatformTarget>x64</PlatformTarget>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
<Prefer32Bit>true</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Debug|x86'">
|
||||||
<DebugSymbols>true</DebugSymbols>
|
<DebugSymbols>true</DebugSymbols>
|
||||||
<OutputPath>bin\x86\Debug\</OutputPath>
|
<OutputPath>bin\x86\Debug\</OutputPath>
|
||||||
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
<DefineConstants>DEBUG;TRACE</DefineConstants>
|
||||||
<DebugType>full</DebugType>
|
<DebugType>full</DebugType>
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
<Prefer32Bit>true</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
<PropertyGroup Condition="'$(Configuration)|$(Platform)' == 'Release|x86'">
|
||||||
<OutputPath>bin\x86\Release\</OutputPath>
|
<OutputPath>bin\x86\Release\</OutputPath>
|
||||||
<DefineConstants>TRACE</DefineConstants>
|
<DefineConstants>TRACE</DefineConstants>
|
||||||
<Optimize>true</Optimize>
|
<Optimize>true</Optimize>
|
||||||
<DebugType>pdbonly</DebugType>
|
<DebugType>pdbonly</DebugType>
|
||||||
<PlatformTarget>x86</PlatformTarget>
|
<PlatformTarget>x86</PlatformTarget>
|
||||||
<ErrorReport>prompt</ErrorReport>
|
<ErrorReport>prompt</ErrorReport>
|
||||||
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
<CodeAnalysisRuleSet>MinimumRecommendedRules.ruleset</CodeAnalysisRuleSet>
|
||||||
<Prefer32Bit>true</Prefer32Bit>
|
<Prefer32Bit>true</Prefer32Bit>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<PropertyGroup>
|
<PropertyGroup>
|
||||||
<ApplicationIcon>cxml.ico</ApplicationIcon>
|
<ApplicationIcon>cxml.ico</ApplicationIcon>
|
||||||
</PropertyGroup>
|
</PropertyGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Reference Include="DotNetZip, Version=1.13.3.0, Culture=neutral, PublicKeyToken=6583c7c814667745, processorArchitecture=MSIL">
|
<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>
|
<HintPath>..\packages\DotNetZip.1.13.3\lib\net40\DotNetZip.dll</HintPath>
|
||||||
</Reference>
|
</Reference>
|
||||||
<Reference Include="System" />
|
<Reference Include="System" />
|
||||||
<Reference Include="System.Core" />
|
<Reference Include="System.Core" />
|
||||||
<Reference Include="System.Drawing" />
|
<Reference Include="System.Drawing" />
|
||||||
<Reference Include="System.Xml.Linq" />
|
<Reference Include="System.Xml.Linq" />
|
||||||
<Reference Include="System.Data.DataSetExtensions" />
|
<Reference Include="System.Data.DataSetExtensions" />
|
||||||
<Reference Include="Microsoft.CSharp" />
|
<Reference Include="Microsoft.CSharp" />
|
||||||
<Reference Include="System.Data" />
|
<Reference Include="System.Data" />
|
||||||
<Reference Include="System.Net.Http" />
|
<Reference Include="System.Net.Http" />
|
||||||
<Reference Include="System.Xml" />
|
<Reference Include="System.Xml" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Compile Include="CXMLReader.cs" />
|
<Compile Include="CXMLReader.cs" />
|
||||||
<Compile Include="CXMLBuilder.cs" />
|
<Compile Include="CXMLBuilder.cs" />
|
||||||
<Compile Include="GimConv.cs" />
|
<Compile Include="GimConv.cs" />
|
||||||
<Compile Include="Program.cs" />
|
<Compile Include="LoopbackHandler.cs" />
|
||||||
<Compile Include="Properties\AssemblyInfo.cs" />
|
<Compile Include="Program.cs" />
|
||||||
<Compile Include="Tools.cs" />
|
<Compile Include="Properties\AssemblyInfo.cs" />
|
||||||
<Compile Include="VAG.cs" />
|
<Compile Include="Tools.cs" />
|
||||||
</ItemGroup>
|
<Compile Include="VAG.cs" />
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<None Include="App.config" />
|
<ItemGroup>
|
||||||
<None Include="packages.config" />
|
<None Include="App.config" />
|
||||||
</ItemGroup>
|
<None Include="packages.config" />
|
||||||
<ItemGroup>
|
</ItemGroup>
|
||||||
<Content Include="cxml.ico" />
|
<ItemGroup>
|
||||||
</ItemGroup>
|
<Content Include="cxml.ico" />
|
||||||
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
</ItemGroup>
|
||||||
</Project>
|
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
|
||||||
|
</Project>
|
|
@ -1,13 +1,14 @@
|
||||||
using Ionic.Zlib;
|
using Ionic.Zlib;
|
||||||
|
using General;
|
||||||
|
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Diagnostics;
|
using System.Diagnostics;
|
||||||
using General;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Xml;
|
using System.Xml;
|
||||||
using System.Globalization;
|
using System.Globalization;
|
||||||
|
|
||||||
namespace CXML
|
namespace CXML
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -67,6 +68,7 @@ namespace CXML
|
||||||
|
|
||||||
List<TypingInformation> SilicaTypingInformationList = new List<TypingInformation>();
|
List<TypingInformation> SilicaTypingInformationList = new List<TypingInformation>();
|
||||||
|
|
||||||
|
String MagicReplacePattern = Tools.GenerateReplacePattern();
|
||||||
String SilicaTypingInformation = "SilicaTypingInformation{{[[";
|
String SilicaTypingInformation = "SilicaTypingInformation{{[[";
|
||||||
FileStream InfoFile;
|
FileStream InfoFile;
|
||||||
|
|
||||||
|
@ -89,16 +91,9 @@ namespace CXML
|
||||||
BinaryReader bHashIDTable;
|
BinaryReader bHashIDTable;
|
||||||
BinaryReader bStringIDTable;
|
BinaryReader bStringIDTable;
|
||||||
|
|
||||||
public class LoopbackHandler
|
|
||||||
{
|
|
||||||
public String FileName;
|
|
||||||
public String OldFileName;
|
|
||||||
public Int64 FilePointer;
|
|
||||||
}
|
|
||||||
|
|
||||||
List<LoopbackHandler> FileList = new List<LoopbackHandler>();
|
List<LoopbackHandler> FileList = new List<LoopbackHandler>();
|
||||||
|
|
||||||
XmlWriter XMLFile;
|
XmlWriter XMLWriter;
|
||||||
|
|
||||||
public bool ProcessFiles = false;
|
public bool ProcessFiles = false;
|
||||||
public bool WaitExit = false;
|
public bool WaitExit = false;
|
||||||
|
@ -399,16 +394,22 @@ namespace CXML
|
||||||
|
|
||||||
XmlWriterSettings XMLSettings = new XmlWriterSettings();
|
XmlWriterSettings XMLSettings = new XmlWriterSettings();
|
||||||
XMLSettings.Indent = true;
|
XMLSettings.Indent = true;
|
||||||
|
XMLSettings.Encoding = Encoding.UTF8;
|
||||||
|
|
||||||
string XMLPath = Path.Combine(MainDir, XMLFilename);
|
string XMLPath = Path.Combine(MainDir, XMLFilename);
|
||||||
XMLFile = XmlWriter.Create(XMLPath, XMLSettings);
|
|
||||||
XMLFile.WriteStartDocument();
|
StreamWriter sw = new StreamWriter(new MemoryStream(), Encoding.UTF8);
|
||||||
XMLFile.WriteComment("REPLACE_WITH_SILICATOKEN");
|
|
||||||
|
|
||||||
|
XMLWriter = XmlWriter.Create(sw, XMLSettings);
|
||||||
|
XMLWriter.WriteStartDocument();
|
||||||
|
XMLWriter.WriteComment(MagicReplacePattern);
|
||||||
AddTypingInfo("MAGIC", MagicNumber);
|
AddTypingInfo("MAGIC", MagicNumber);
|
||||||
AddTypingInfo("VERSION", ReadVersion());
|
AddTypingInfo("VERSION", ReadVersion());
|
||||||
ReadElements();
|
ReadElements();
|
||||||
XMLFile.WriteEndDocument();
|
XMLWriter.WriteEndDocument();
|
||||||
XMLFile.Flush();
|
XMLWriter.Flush();
|
||||||
XMLFile.Close();
|
XMLWriter.Close();
|
||||||
|
|
||||||
GotoEnd();
|
GotoEnd();
|
||||||
int bytesRemaining = Convert.ToInt32(InfoFile.Length - InfoFile.Position);
|
int bytesRemaining = Convert.ToInt32(InfoFile.Length - InfoFile.Position);
|
||||||
|
@ -432,44 +433,62 @@ namespace CXML
|
||||||
}
|
}
|
||||||
|
|
||||||
SilicaTypingInformation += "]]}}SilicaTypingInformation";
|
SilicaTypingInformation += "]]}}SilicaTypingInformation";
|
||||||
|
byte[] XMLBytes = new byte[sw.BaseStream.Length];
|
||||||
|
|
||||||
// Make corrections
|
sw.Flush();
|
||||||
string XmlData = File.ReadAllText(XMLPath, Encoding.UTF8);
|
sw.BaseStream.Seek(0x00, SeekOrigin.Begin);
|
||||||
XmlData = XmlData.Replace("REPLACE_WITH_SILICATOKEN", SilicaTypingInformation);
|
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)
|
foreach(LoopbackHandler lpHandler in FileList)
|
||||||
{
|
{
|
||||||
if(lpHandler.OldFileName != null)
|
if (lpHandler.ReplacePattern != null && lpHandler.OldFileName != null)
|
||||||
{
|
{
|
||||||
if(lpHandler.FileName != null)
|
|
||||||
{
|
string replacePattern = lpHandler.ReplacePattern;
|
||||||
string oldName = Path.Combine(lpHandler.OldFileName);
|
string oldName = lpHandler.OldFileName;
|
||||||
string extension = Path.GetExtension(oldName);
|
string extension = Path.GetExtension(oldName);
|
||||||
string folderPath = Path.GetDirectoryName(oldName);
|
string folderPath = Path.GetDirectoryName(oldName);
|
||||||
string newPath = Path.ChangeExtension(Path.Combine(folderPath, lpHandler.FileName), extension);
|
byte[] fileData = lpHandler.FileData;
|
||||||
|
|
||||||
if(!File.Exists(newPath))
|
if (lpHandler.FileName != null)
|
||||||
{
|
{
|
||||||
File.Move(oldName, newPath);
|
|
||||||
|
string newPath = Path.ChangeExtension(Path.Combine(folderPath, lpHandler.FileName), extension);
|
||||||
string xmlRelOldPath = oldName.Substring(Tools.GetRootFolder(oldName).Length + 1);
|
|
||||||
string xmlRelNewPath = newPath.Substring(Tools.GetRootFolder(newPath).Length + 1);
|
if (!Directory.Exists(folderPath))
|
||||||
Console.WriteLine("Moved " + xmlRelOldPath + " => " + xmlRelNewPath);
|
Directory.CreateDirectory(folderPath);
|
||||||
XmlData = XmlData.Replace(xmlRelOldPath, xmlRelNewPath);
|
|
||||||
}
|
if (!File.Exists(newPath))
|
||||||
|
{
|
||||||
if (ProcessFiles)
|
File.WriteAllBytes(newPath, fileData);
|
||||||
ProcessFile(newPath);
|
string xmlRelNewPath = newPath.Substring(Tools.GetRootFolder(newPath).Length + 1);
|
||||||
}
|
Console.WriteLine("Resolved " + replacePattern + " => " + xmlRelNewPath);
|
||||||
else
|
XMLData = XMLData.Replace(replacePattern, xmlRelNewPath);
|
||||||
{
|
}
|
||||||
Console.WriteLine("NOT MOVING: " + lpHandler.OldFileName);
|
|
||||||
if (ProcessFiles)
|
if (ProcessFiles)
|
||||||
ProcessFile(lpHandler.OldFileName);
|
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();
|
Term();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -493,7 +512,7 @@ namespace CXML
|
||||||
cxmlParser.Init(FileName);
|
cxmlParser.Init(FileName);
|
||||||
cxmlParser.ProcessFiles = this.ProcessFiles;
|
cxmlParser.ProcessFiles = this.ProcessFiles;
|
||||||
cxmlParser.MainDir = DirectoryName;
|
cxmlParser.MainDir = DirectoryName;
|
||||||
cxmlParser.FileDir = Path.Combine(cxmlParser.MainDir,"files");
|
cxmlParser.FileDir = Path.Combine(cxmlParser.MainDir, "files");
|
||||||
cxmlParser.DecompileCXML(FileName);
|
cxmlParser.DecompileCXML(FileName);
|
||||||
}
|
}
|
||||||
catch (Exception) { };
|
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 + ")");
|
Console.WriteLine("Adding Entry for Loopback: 0x" + ElementPtr.ToString("X8", CultureInfo.InvariantCulture) + " (" + NewName + ")");
|
||||||
for(int i = 0; i < FileList.Count; i++)
|
for(int i = 0; i < FileList.Count; i++)
|
||||||
|
@ -583,6 +602,8 @@ namespace CXML
|
||||||
{
|
{
|
||||||
lpHandler.OldFileName = NewName;
|
lpHandler.OldFileName = NewName;
|
||||||
lpHandler.FileName = IdealName;
|
lpHandler.FileName = IdealName;
|
||||||
|
lpHandler.FileData = FileData;
|
||||||
|
lpHandler.ReplacePattern = ReplacePattern;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -610,12 +631,14 @@ namespace CXML
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_INT:
|
case AttributeType.TYPE_INT:
|
||||||
AttributeValue = bTreeTable.ReadInt32();
|
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;
|
break;
|
||||||
case AttributeType.TYPE_FLOAT:
|
case AttributeType.TYPE_FLOAT:
|
||||||
float FloatValue = bTreeTable.ReadSingle();
|
float FloatValue = bTreeTable.ReadSingle();
|
||||||
AttributeValue = FloatValue.ToString("G9", CultureInfo.InvariantCulture) + "f";
|
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;
|
break;
|
||||||
case AttributeType.TYPE_STRING:
|
case AttributeType.TYPE_STRING:
|
||||||
int StringOffset = bTreeTable.ReadInt32();
|
int StringOffset = bTreeTable.ReadInt32();
|
||||||
|
@ -689,28 +712,18 @@ namespace CXML
|
||||||
Byte[] FileData = new Byte[FileSz];
|
Byte[] FileData = new Byte[FileSz];
|
||||||
FileTable.Seek(FilePtr, SeekOrigin.Begin);
|
FileTable.Seek(FilePtr, SeekOrigin.Begin);
|
||||||
FileTable.Read(FileData, 0, FileSz);
|
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 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;
|
String IdealName = ElementName + "-" + AttributeName + "-" + FileSmallHash + Extension;
|
||||||
if (!File.Exists(FileName))
|
String ReplacePattern = Tools.GenerateReplacePattern();
|
||||||
{
|
|
||||||
Console.WriteLine("Writing: " + FileName);
|
|
||||||
|
|
||||||
if (!Directory.Exists(Path.GetDirectoryName(FileName)))
|
//File.WriteAllBytes(FileName, FileData);
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(FileName));
|
RegisterFile(ElementPtr, FileName, true, ReplacePattern, FileData, IdealName);
|
||||||
|
|
||||||
File.WriteAllBytes(FileName, FileData);
|
AttributeValue = ReplacePattern;
|
||||||
RegisterFile(ElementPtr, FileName, true, IdealName);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
Console.WriteLine("File allready extracted.");
|
|
||||||
}
|
|
||||||
|
|
||||||
string xmlRelPath = FileName.Substring(Tools.GetRootFolder(FileName).Length + 1);
|
|
||||||
AttributeValue = xmlRelPath;
|
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_ID_STRING_LOOPBACK:
|
case AttributeType.TYPE_ID_STRING_LOOPBACK:
|
||||||
int StringIdTableOffset = bTreeTable.ReadInt32();
|
int StringIdTableOffset = bTreeTable.ReadInt32();
|
||||||
|
@ -725,7 +738,9 @@ namespace CXML
|
||||||
AttributeValue = Tools.ReadString(StringIDTable);
|
AttributeValue = Tools.ReadString(StringIDTable);
|
||||||
RegisterFile(LoopbackPtr, AttributeValue.ToString(), false);
|
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;
|
break;
|
||||||
case AttributeType.TYPE_ID_STRING: // This is probably right, tbh
|
case AttributeType.TYPE_ID_STRING: // This is probably right, tbh
|
||||||
StringIdTableOffset = bTreeTable.ReadInt32();
|
StringIdTableOffset = bTreeTable.ReadInt32();
|
||||||
|
@ -733,7 +748,8 @@ namespace CXML
|
||||||
|
|
||||||
AttributeValue = Tools.ReadString(StringIDTable);
|
AttributeValue = Tools.ReadString(StringIDTable);
|
||||||
|
|
||||||
Console.WriteLine("ID String: " + StringIdTableOffset + " sz: " + bTreeTable.ReadInt32());
|
sz = bTreeTable.ReadInt32();
|
||||||
|
Console.WriteLine("ID String: " + StringIdTableOffset + " sz: " + sz);
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_ID_INT_LOOPBACK:
|
case AttributeType.TYPE_ID_INT_LOOPBACK:
|
||||||
int IntIdTableOffset = bTreeTable.ReadInt32();
|
int IntIdTableOffset = bTreeTable.ReadInt32();
|
||||||
|
@ -750,7 +766,8 @@ namespace CXML
|
||||||
AttributeValue = IDValue.ToString("X8", CultureInfo.InvariantCulture);
|
AttributeValue = IDValue.ToString("X8", CultureInfo.InvariantCulture);
|
||||||
RegisterFile(LoopbackPtr, AttributeValue.ToString(), false);
|
RegisterFile(LoopbackPtr, AttributeValue.ToString(), false);
|
||||||
|
|
||||||
Console.WriteLine("Loopback Int: " + IntIdTableOffset + " sz: " + bTreeTable.ReadInt32());
|
sz = bTreeTable.ReadInt32();
|
||||||
|
Console.WriteLine("Loopback Int: " + IntIdTableOffset + " sz: " + sz);
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_ID_INT:
|
case AttributeType.TYPE_ID_INT:
|
||||||
IntIdTableOffset = bTreeTable.ReadInt32();
|
IntIdTableOffset = bTreeTable.ReadInt32();
|
||||||
|
@ -758,7 +775,8 @@ namespace CXML
|
||||||
IDValue = bIntIDTable.ReadInt32();
|
IDValue = bIntIDTable.ReadInt32();
|
||||||
|
|
||||||
AttributeValue = IDValue.ToString("X8", CultureInfo.InvariantCulture);
|
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;
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine("UNKNOWN TYPE @ " + TreeTable.Position);
|
Console.WriteLine("UNKNOWN TYPE @ " + TreeTable.Position);
|
||||||
|
@ -768,8 +786,8 @@ namespace CXML
|
||||||
|
|
||||||
AddTypingInfo(ElementName + ":" + AttributeName, ((int)Type).ToString(CultureInfo.InvariantCulture));
|
AddTypingInfo(ElementName + ":" + AttributeName, ((int)Type).ToString(CultureInfo.InvariantCulture));
|
||||||
Console.WriteLine(AttributeName + "=" + AttributeValue.ToString());
|
Console.WriteLine(AttributeName + "=" + AttributeValue.ToString());
|
||||||
XMLFile.WriteAttributeString(AttributeName, AttributeValue.ToString());
|
XMLWriter.WriteAttributeString(AttributeName, AttributeValue.ToString());
|
||||||
XMLFile.Flush();
|
XMLWriter.Flush();
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReadElements()
|
public void ReadElements()
|
||||||
|
@ -796,7 +814,7 @@ namespace CXML
|
||||||
Console.WriteLine("FirstChild: " + FirstChild);
|
Console.WriteLine("FirstChild: " + FirstChild);
|
||||||
Console.WriteLine("LastChild: " + LastChild);
|
Console.WriteLine("LastChild: " + LastChild);
|
||||||
|
|
||||||
XMLFile.WriteStartElement(ElementName);
|
XMLWriter.WriteStartElement(ElementName);
|
||||||
|
|
||||||
if(NumAttributes > 0)
|
if(NumAttributes > 0)
|
||||||
{
|
{
|
||||||
|
@ -813,8 +831,8 @@ namespace CXML
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
XMLFile.WriteEndElement();
|
XMLWriter.WriteEndElement();
|
||||||
XMLFile.Flush();
|
XMLWriter.Flush();
|
||||||
|
|
||||||
if (NextSibling != -1)
|
if (NextSibling != -1)
|
||||||
{
|
{
|
||||||
|
|
|
@ -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;
|
||||||
|
}
|
||||||
|
}
|
|
@ -1,8 +1,5 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
using System.Drawing.Imaging;
|
|
||||||
using System.Globalization;
|
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
@ -13,14 +10,14 @@ namespace General
|
||||||
class Tools
|
class Tools
|
||||||
{
|
{
|
||||||
|
|
||||||
public static byte[] bmp = Encoding.ASCII.GetBytes("BM"); // BMP
|
public static byte[] bmp = Encoding.ASCII.GetBytes("BM"); // BMP
|
||||||
public static byte[] gif = Encoding.ASCII.GetBytes("GIF"); // GIF
|
public static byte[] gif = Encoding.ASCII.GetBytes("GIF"); // GIF
|
||||||
public static byte[] png = new byte[] { 137, 80, 78, 71 }; // PNG
|
public static byte[] png = new byte[] { 137, 80, 78, 71 }; // PNG
|
||||||
public static byte[] tiff = new byte[] { 73, 73, 42 }; // TIFF
|
public static byte[] tiff = new byte[] { 73, 73, 42 }; // TIFF
|
||||||
public static byte[] tiff2 = new byte[] { 77, 77, 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[] jpeg = new byte[] { 255, 216, 255 }; // jpeg
|
||||||
|
public static Random rng = new Random(Guid.NewGuid().GetHashCode());
|
||||||
|
|
||||||
public static void WriteStringToStream(Stream s, String str)
|
public static void WriteStringToStream(Stream s, String str)
|
||||||
{
|
{
|
||||||
Byte[] bytes = Encoding.UTF8.GetBytes(str);
|
Byte[] bytes = Encoding.UTF8.GetBytes(str);
|
||||||
|
@ -46,34 +43,40 @@ namespace General
|
||||||
stream.Seek(0, SeekOrigin.Begin);
|
stream.Seek(0, SeekOrigin.Begin);
|
||||||
stream.Read(Bytes, 0x00, StreamLen);
|
stream.Read(Bytes, 0x00, StreamLen);
|
||||||
return Bytes;
|
return Bytes;
|
||||||
}
|
}
|
||||||
|
|
||||||
public static string GetFileExtension(byte[] Bytes)
|
public static string GenerateReplacePattern()
|
||||||
{
|
{
|
||||||
if (bmp.SequenceEqual(Bytes.Take(bmp.Length)))
|
byte[] RandomNumber = new byte[0x20];
|
||||||
{
|
rng.NextBytes(RandomNumber);
|
||||||
return ".bmp";
|
return "{{" + BitConverter.ToString(RandomNumber).Replace("-", "") + "}}";
|
||||||
}
|
}
|
||||||
else if (gif.SequenceEqual(Bytes.Take(gif.Length)))
|
public static string GetFileExtension(byte[] Bytes)
|
||||||
{
|
{
|
||||||
return ".gif";
|
if (bmp.SequenceEqual(Bytes.Take(bmp.Length)))
|
||||||
}
|
{
|
||||||
else if (png.SequenceEqual(Bytes.Take(png.Length)))
|
return ".bmp";
|
||||||
{
|
}
|
||||||
return ".png";
|
else if (gif.SequenceEqual(Bytes.Take(gif.Length)))
|
||||||
}
|
{
|
||||||
else if (tiff.SequenceEqual(Bytes.Take(tiff.Length)))
|
return ".gif";
|
||||||
{
|
}
|
||||||
return ".tiff";
|
else if (png.SequenceEqual(Bytes.Take(png.Length)))
|
||||||
}
|
{
|
||||||
else if (tiff2.SequenceEqual(Bytes.Take(tiff2.Length)))
|
return ".png";
|
||||||
{
|
}
|
||||||
return ".tiff";
|
else if (tiff.SequenceEqual(Bytes.Take(tiff.Length)))
|
||||||
}
|
{
|
||||||
else if (jpeg.SequenceEqual(Bytes.Take(jpeg.Length)))
|
return ".tiff";
|
||||||
{
|
}
|
||||||
return ".jpg";
|
else if (tiff2.SequenceEqual(Bytes.Take(tiff2.Length)))
|
||||||
}
|
{
|
||||||
|
return ".tiff";
|
||||||
|
}
|
||||||
|
else if (jpeg.SequenceEqual(Bytes.Take(jpeg.Length)))
|
||||||
|
{
|
||||||
|
return ".jpg";
|
||||||
|
}
|
||||||
else if (IsZlib(Bytes))
|
else if (IsZlib(Bytes))
|
||||||
{
|
{
|
||||||
return ".z";
|
return ".z";
|
||||||
|
@ -94,7 +97,7 @@ namespace General
|
||||||
{
|
{
|
||||||
return ".gim";
|
return ".gim";
|
||||||
}
|
}
|
||||||
else if(!HasBinaryContent(Encoding.UTF8.GetString(Bytes)))
|
else if (!HasBinaryContent(Encoding.UTF8.GetString(Bytes)))
|
||||||
{
|
{
|
||||||
return ".txt";
|
return ".txt";
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue