update stuff
This commit is contained in:
parent
8a0a46867d
commit
ab1f4954e0
|
@ -1,2 +1,2 @@
|
||||||
*bin/*
|
*bin*
|
||||||
*obj/*
|
*obj*
|
Binary file not shown.
|
@ -35,6 +35,7 @@ namespace CXML
|
||||||
{
|
{
|
||||||
|
|
||||||
String Magic = Tools.ReadStringAt(InfoFile, 0x00);
|
String Magic = Tools.ReadStringAt(InfoFile, 0x00);
|
||||||
|
MagicNumber = Magic.Substring(0,4);
|
||||||
|
|
||||||
if (Magic.StartsWith("PSMA"))
|
if (Magic.StartsWith("PSMA"))
|
||||||
{
|
{
|
||||||
|
@ -58,7 +59,7 @@ namespace CXML
|
||||||
String MainDir = "";
|
String MainDir = "";
|
||||||
String FileDir = "";
|
String FileDir = "";
|
||||||
String XMLFilename = "";
|
String XMLFilename = "";
|
||||||
|
String MagicNumber = "";
|
||||||
|
|
||||||
FileStream InfoFile;
|
FileStream InfoFile;
|
||||||
|
|
||||||
|
@ -98,9 +99,10 @@ namespace CXML
|
||||||
public void Init(string path, bool CheckMagic = true)
|
public void Init(string path, bool CheckMagic = true)
|
||||||
{
|
{
|
||||||
InfoFile = File.Open(path, FileMode.Open, FileAccess.Read);
|
InfoFile = File.Open(path, FileMode.Open, FileAccess.Read);
|
||||||
if(CheckMagic)
|
bool MagicValid = _checkMagicNumber();
|
||||||
|
if (CheckMagic)
|
||||||
{
|
{
|
||||||
if (!_checkMagicNumber())
|
if (!MagicValid)
|
||||||
{
|
{
|
||||||
throw new Exception("Incorrect magic number.");
|
throw new Exception("Incorrect magic number.");
|
||||||
}
|
}
|
||||||
|
@ -335,7 +337,6 @@ namespace CXML
|
||||||
InfoFile.Read(FileTable, 0x00, DataLength);
|
InfoFile.Read(FileTable, 0x00, DataLength);
|
||||||
return FileTable;
|
return FileTable;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void DecompileCXML(String CXMLFile, bool force = false)
|
public void DecompileCXML(String CXMLFile, bool force = false)
|
||||||
{
|
{
|
||||||
|
|
||||||
|
@ -354,7 +355,7 @@ namespace CXML
|
||||||
string XMLPath = Path.Combine(MainDir, XMLFilename);
|
string XMLPath = Path.Combine(MainDir, XMLFilename);
|
||||||
XMLFile = XmlWriter.Create(XMLPath, XMLSettings);
|
XMLFile = XmlWriter.Create(XMLPath, XMLSettings);
|
||||||
XMLFile.WriteStartDocument();
|
XMLFile.WriteStartDocument();
|
||||||
|
XMLFile.WriteComment("Decompiled with CXML Decompiler v6 By SilicaAndPina (Magic: \"" + MagicNumber + "\")");
|
||||||
ReadElements();
|
ReadElements();
|
||||||
|
|
||||||
XMLFile.WriteEndDocument();
|
XMLFile.WriteEndDocument();
|
||||||
|
@ -367,11 +368,29 @@ namespace CXML
|
||||||
{
|
{
|
||||||
if(lpHandler.OldFileName != null)
|
if(lpHandler.OldFileName != null)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Replacing: " + lpHandler.OldFileName + " With " + lpHandler.FileName);
|
if(lpHandler.FileName != null)
|
||||||
XmlData = XmlData.Replace(lpHandler.OldFileName, lpHandler.FileName);
|
{
|
||||||
|
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);
|
||||||
|
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("Generated Filename used for " + lpHandler.OldFileName);
|
||||||
|
if (ProcessFiles)
|
||||||
|
ProcessFile(lpHandler.OldFileName);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
if(ProcessFiles)
|
|
||||||
ProcessFile(Path.Combine(MainDir, lpHandler.FileName));
|
|
||||||
}
|
}
|
||||||
File.WriteAllText(XMLPath, XmlData);
|
File.WriteAllText(XMLPath, XmlData);
|
||||||
|
|
||||||
|
@ -457,25 +476,40 @@ namespace CXML
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ChangeFilename(Int64 ElementPtr, String NewName)
|
public void ChangeFilename(Int64 ElementPtr, String NewName, Boolean FileEntry)
|
||||||
{
|
{
|
||||||
Console.WriteLine("Correcting for Loopback: 0x" + ElementPtr.ToString("X8") + " (" + NewName + ")");
|
Console.WriteLine("Adding Entry for Loopback: 0x" + ElementPtr.ToString("X8") + " (" + NewName + ")");
|
||||||
for(int i = 0; i < FileList.Count; i++)
|
for(int i = 0; i < FileList.Count; i++)
|
||||||
{
|
{
|
||||||
if(FileList[i].FilePointer == ElementPtr)
|
if(FileList[i].FilePointer == ElementPtr)
|
||||||
{
|
{
|
||||||
string oldName = FileList[i].FileName;
|
if (FileEntry)
|
||||||
string extension = Path.GetExtension(oldName);
|
{
|
||||||
string folderPath = Path.GetDirectoryName(FileList[i].FileName);
|
if (FileList[i].OldFileName != null)
|
||||||
string newPath = Path.ChangeExtension(Path.Combine(folderPath, NewName), extension);
|
break;
|
||||||
Console.WriteLine("Changed " + Path.Combine(MainDir, oldName) + " => " + Path.Combine(MainDir, newPath));
|
FileList[i].OldFileName = NewName;
|
||||||
File.Move(Path.Combine(MainDir, oldName), Path.Combine(MainDir, newPath));
|
return;
|
||||||
FileList[i].FileName = newPath;
|
}
|
||||||
FileList[i].OldFileName = oldName;
|
else
|
||||||
return;
|
{
|
||||||
|
FileList[i].FileName = NewName;
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Console.WriteLine("Nothing to correct!");
|
|
||||||
|
LoopbackHandler lpHandler = new LoopbackHandler();
|
||||||
|
if (FileEntry)
|
||||||
|
{
|
||||||
|
lpHandler.OldFileName = NewName;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
lpHandler.FileName = NewName;
|
||||||
|
}
|
||||||
|
lpHandler.FilePointer = ElementPtr;
|
||||||
|
FileList.Add(lpHandler);
|
||||||
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
public void ReadAttribute(String ElementName = "", Int64 ElementPtr = 0)
|
public void ReadAttribute(String ElementName = "", Int64 ElementPtr = 0)
|
||||||
|
@ -495,12 +529,12 @@ namespace CXML
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_INT:
|
case AttributeType.TYPE_INT:
|
||||||
AttributeValue = bTreeTable.ReadInt32();
|
AttributeValue = bTreeTable.ReadInt32();
|
||||||
TreeTable.Seek(4, SeekOrigin.Current);
|
Console.WriteLine("Int - Value: " + AttributeValue.ToString() + " sz:" + bTreeTable.ReadInt32());
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_FLOAT:
|
case AttributeType.TYPE_FLOAT:
|
||||||
float FloatValue = bTreeTable.ReadSingle();
|
float FloatValue = bTreeTable.ReadSingle();
|
||||||
AttributeValue = FloatValue.ToString()+"f";
|
AttributeValue = FloatValue.ToString()+"f";
|
||||||
TreeTable.Seek(4, SeekOrigin.Current);
|
Console.WriteLine("Float - Value: " + AttributeValue.ToString() + " sz:" + bTreeTable.ReadInt32());
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_STRING:
|
case AttributeType.TYPE_STRING:
|
||||||
int StringOffset = bTreeTable.ReadInt32();
|
int StringOffset = bTreeTable.ReadInt32();
|
||||||
|
@ -525,10 +559,13 @@ namespace CXML
|
||||||
case AttributeType.TYPE_HASH_ID:
|
case AttributeType.TYPE_HASH_ID:
|
||||||
int HashTableOffset = bTreeTable.ReadInt32();
|
int HashTableOffset = bTreeTable.ReadInt32();
|
||||||
int HashTableSize = bTreeTable.ReadInt32();
|
int HashTableSize = bTreeTable.ReadInt32();
|
||||||
HashIDTable.Seek(HashTableOffset*4, SeekOrigin.Begin);
|
HashIDTable.Seek(HashTableOffset * 4, SeekOrigin.Begin);
|
||||||
|
Console.WriteLine("Hash ID Offset:" + HashTableOffset.ToString() + " size: " + HashTableSize);
|
||||||
|
|
||||||
|
int HashId = bHashIDTable.ReadInt32();
|
||||||
|
|
||||||
|
AttributeValue = "@"+HashId.ToString("X8");
|
||||||
|
|
||||||
int HashID = bHashIDTable.ReadInt32();
|
|
||||||
AttributeValue = HashID.ToString("X8");
|
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_INTEGER_ARRAY:
|
case AttributeType.TYPE_INTEGER_ARRAY:
|
||||||
int IntArrayOffset = bTreeTable.ReadInt32();
|
int IntArrayOffset = bTreeTable.ReadInt32();
|
||||||
|
@ -571,7 +608,6 @@ namespace CXML
|
||||||
|
|
||||||
String Extension = Tools.GetFileExtension(FileData);
|
String Extension = Tools.GetFileExtension(FileData);
|
||||||
String FileName = Path.Combine(FileDir, ElementName, FileHash + Extension);
|
String FileName = Path.Combine(FileDir, ElementName, FileHash + Extension);
|
||||||
String finalName = Path.Combine(Path.GetFileName(FileDir), ElementName, FileHash + Extension);
|
|
||||||
if (!File.Exists(FileName))
|
if (!File.Exists(FileName))
|
||||||
{
|
{
|
||||||
Console.WriteLine("Writing: " + FileName);
|
Console.WriteLine("Writing: " + FileName);
|
||||||
|
@ -580,18 +616,15 @@ namespace CXML
|
||||||
Directory.CreateDirectory(Path.GetDirectoryName(FileName));
|
Directory.CreateDirectory(Path.GetDirectoryName(FileName));
|
||||||
|
|
||||||
File.WriteAllBytes(FileName, FileData);
|
File.WriteAllBytes(FileName, FileData);
|
||||||
LoopbackHandler lpHandler = new LoopbackHandler();
|
ChangeFilename(ElementPtr, FileName, true);
|
||||||
lpHandler.FileName = finalName;
|
|
||||||
lpHandler.OldFileName = null;
|
|
||||||
lpHandler.FilePointer = ElementPtr;
|
|
||||||
FileList.Add(lpHandler);
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Console.WriteLine("File allready extracted \n(theres a VERY low chance that it acturally is a different file that has the same hash.)");
|
Console.WriteLine("File allready extracted \n(theres a VERY low chance that it acturally is a different file that has the same hash.)");
|
||||||
}
|
}
|
||||||
|
|
||||||
AttributeValue = finalName;
|
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();
|
||||||
|
@ -604,9 +637,9 @@ namespace CXML
|
||||||
Console.WriteLine("Loopback: " + LoopbackAttribute +" "+ LoopbackPtr.ToString("X")+" ("+ElementPtr.ToString("X")+")");
|
Console.WriteLine("Loopback: " + LoopbackAttribute +" "+ LoopbackPtr.ToString("X")+" ("+ElementPtr.ToString("X")+")");
|
||||||
|
|
||||||
AttributeValue = Tools.ReadString(StringIDTable);
|
AttributeValue = Tools.ReadString(StringIDTable);
|
||||||
ChangeFilename(LoopbackPtr, AttributeValue.ToString());
|
ChangeFilename(LoopbackPtr, AttributeValue.ToString(), false);
|
||||||
|
|
||||||
TreeTable.Seek(4, SeekOrigin.Current);
|
Console.WriteLine("Loopback String: " + StringIdTableOffset + " sz: " + bTreeTable.ReadInt32());
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_ID_STRING:
|
case AttributeType.TYPE_ID_STRING:
|
||||||
Console.WriteLine("UNSUPPORTED TYPE @ " + TreeTable.Position);
|
Console.WriteLine("UNSUPPORTED TYPE @ " + TreeTable.Position);
|
||||||
|
@ -624,18 +657,18 @@ namespace CXML
|
||||||
LoopbackAttribute = Tools.ReadStringAt(StringTable, StringPtr);
|
LoopbackAttribute = Tools.ReadStringAt(StringTable, StringPtr);
|
||||||
Console.WriteLine("Loopback: " + LoopbackAttribute + " " + LoopbackPtr.ToString("X") + " (" + ElementPtr.ToString("X") + ")");
|
Console.WriteLine("Loopback: " + LoopbackAttribute + " " + LoopbackPtr.ToString("X") + " (" + ElementPtr.ToString("X") + ")");
|
||||||
|
|
||||||
AttributeValue = IDValue.ToString("X8");
|
AttributeValue = "$"+IDValue.ToString("X8");
|
||||||
ChangeFilename(LoopbackPtr, AttributeValue.ToString());
|
ChangeFilename(LoopbackPtr, IDValue.ToString("X8"), false);
|
||||||
|
|
||||||
TreeTable.Seek(4, SeekOrigin.Current);
|
Console.WriteLine("Loopback Int: " + IntIdTableOffset + " sz: " + bTreeTable.ReadInt32());
|
||||||
break;
|
break;
|
||||||
case AttributeType.TYPE_ID_INT:
|
case AttributeType.TYPE_ID_INT:
|
||||||
IntIdTableOffset = bTreeTable.ReadInt32();
|
IntIdTableOffset = bTreeTable.ReadInt32();
|
||||||
IntIDTable.Seek(IntIdTableOffset + 4, SeekOrigin.Begin);
|
IntIDTable.Seek(IntIdTableOffset + 4, SeekOrigin.Begin);
|
||||||
IDValue = bIntIDTable.ReadInt32();
|
IDValue = bIntIDTable.ReadInt32();
|
||||||
|
|
||||||
AttributeValue = IDValue.ToString("X8");
|
AttributeValue = "#"+IDValue.ToString("X8");
|
||||||
TreeTable.Seek(4, SeekOrigin.Current);
|
Console.WriteLine("Int Id: " + IntIdTableOffset + " sz: " + bTreeTable.ReadInt32());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
Console.WriteLine("UNKNOWN TYPE @ " + TreeTable.Position);
|
Console.WriteLine("UNKNOWN TYPE @ " + TreeTable.Position);
|
||||||
|
|
|
@ -36,7 +36,7 @@ namespace CXMLCli
|
||||||
Console.WriteLine("\t-w --wait-exit Wait for keypress before exiting");
|
Console.WriteLine("\t-w --wait-exit Wait for keypress before exiting");
|
||||||
Console.WriteLine("\t-d --decompile Decompile CXML.");
|
Console.WriteLine("\t-d --decompile Decompile CXML.");
|
||||||
Console.WriteLine("Example: " + Path.GetFileName(Assembly.GetEntryAssembly().Location) + " app.info -f -s -t -f -d");
|
Console.WriteLine("Example: " + Path.GetFileName(Assembly.GetEntryAssembly().Location) + " app.info -f -s -t -f -d");
|
||||||
Console.WriteLine("Default functonality is to Decompile,\ntThis is canceled if any other arguments passed.");
|
Console.WriteLine("Default functonality is to Decompile,\nThis is canceled if any other arguments passed.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -147,6 +147,7 @@ namespace CXMLCli
|
||||||
if(cxmlParser.WaitExit)
|
if(cxmlParser.WaitExit)
|
||||||
Console.ReadKey();
|
Console.ReadKey();
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Drawing;
|
using System.Drawing;
|
||||||
|
using System.Drawing.Imaging;
|
||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
|
@ -38,7 +39,29 @@ namespace General
|
||||||
{
|
{
|
||||||
if (IsImage(Bytes))
|
if (IsImage(Bytes))
|
||||||
{
|
{
|
||||||
return ".png";
|
using (Bitmap bmp = GetBitmap(Bytes))
|
||||||
|
{
|
||||||
|
if (bmp.RawFormat.Equals(ImageFormat.Jpeg))
|
||||||
|
return ".jpeg";
|
||||||
|
else if (bmp.RawFormat.Equals(ImageFormat.Bmp))
|
||||||
|
return ".bmp";
|
||||||
|
else if (bmp.RawFormat.Equals(ImageFormat.Gif))
|
||||||
|
return ".gif";
|
||||||
|
else if (bmp.RawFormat.Equals(ImageFormat.Png))
|
||||||
|
return ".png";
|
||||||
|
else if (bmp.RawFormat.Equals(ImageFormat.Tiff))
|
||||||
|
return ".tiff";
|
||||||
|
else if (bmp.RawFormat.Equals(ImageFormat.Icon))
|
||||||
|
return ".ico";
|
||||||
|
else if (bmp.RawFormat.Equals(ImageFormat.Exif))
|
||||||
|
return ".exif";
|
||||||
|
else if (bmp.RawFormat.Equals(ImageFormat.Emf))
|
||||||
|
return ".emf";
|
||||||
|
else if (bmp.RawFormat.Equals(ImageFormat.Wmf))
|
||||||
|
return ".wmf";
|
||||||
|
else
|
||||||
|
return ".raw";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else if (IsZlib(Bytes))
|
else if (IsZlib(Bytes))
|
||||||
{
|
{
|
||||||
|
@ -60,6 +83,10 @@ namespace General
|
||||||
{
|
{
|
||||||
return ".gim";
|
return ".gim";
|
||||||
}
|
}
|
||||||
|
else if(!HasBinaryContent(Encoding.UTF8.GetString(Bytes)))
|
||||||
|
{
|
||||||
|
return ".txt";
|
||||||
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
return ".bin";
|
return ".bin";
|
||||||
|
@ -178,7 +205,10 @@ namespace General
|
||||||
ms.Seek(ogPos, SeekOrigin.Begin);
|
ms.Seek(ogPos, SeekOrigin.Begin);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
public static bool HasBinaryContent(string content)
|
||||||
|
{
|
||||||
|
return content.Any(ch => char.IsControl(ch) && ch != '\r' && ch != '\n');
|
||||||
|
}
|
||||||
public static int ReadInt(Stream ms)
|
public static int ReadInt(Stream ms)
|
||||||
{
|
{
|
||||||
BinaryReader BinReader = new BinaryReader(ms);
|
BinaryReader BinReader = new BinaryReader(ms);
|
||||||
|
@ -203,6 +233,17 @@ namespace General
|
||||||
int i = BitConverter.ToInt32(IntBytes, 0x00);
|
int i = BitConverter.ToInt32(IntBytes, 0x00);
|
||||||
return i;
|
return i;
|
||||||
}
|
}
|
||||||
|
public static String GetRootFolder(string path)
|
||||||
|
{
|
||||||
|
while (true)
|
||||||
|
{
|
||||||
|
string temp = Path.GetDirectoryName(path);
|
||||||
|
if (String.IsNullOrEmpty(temp))
|
||||||
|
break;
|
||||||
|
path = temp;
|
||||||
|
}
|
||||||
|
return path;
|
||||||
|
}
|
||||||
|
|
||||||
public static String GenerateHash(byte[] Data)
|
public static String GenerateHash(byte[] Data)
|
||||||
{
|
{
|
||||||
|
|
Loading…
Reference in New Issue