update stuff

This commit is contained in:
Bluzume 2021-08-12 01:03:30 +12:00
parent 8a0a46867d
commit ab1f4954e0
5 changed files with 120 additions and 45 deletions

4
.gitignore vendored
View File

@ -1,2 +1,2 @@
*bin/*
*obj/*
*bin*
*obj*

BIN
.vs/AppInfoParser/v16/.suo Normal file

Binary file not shown.

View File

@ -35,6 +35,7 @@ namespace CXML
{
String Magic = Tools.ReadStringAt(InfoFile, 0x00);
MagicNumber = Magic.Substring(0,4);
if (Magic.StartsWith("PSMA"))
{
@ -58,7 +59,7 @@ namespace CXML
String MainDir = "";
String FileDir = "";
String XMLFilename = "";
String MagicNumber = "";
FileStream InfoFile;
@ -98,9 +99,10 @@ namespace CXML
public void Init(string path, bool CheckMagic = true)
{
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.");
}
@ -335,7 +337,6 @@ namespace CXML
InfoFile.Read(FileTable, 0x00, DataLength);
return FileTable;
}
public void DecompileCXML(String CXMLFile, bool force = false)
{
@ -354,7 +355,7 @@ namespace CXML
string XMLPath = Path.Combine(MainDir, XMLFilename);
XMLFile = XmlWriter.Create(XMLPath, XMLSettings);
XMLFile.WriteStartDocument();
XMLFile.WriteComment("Decompiled with CXML Decompiler v6 By SilicaAndPina (Magic: \"" + MagicNumber + "\")");
ReadElements();
XMLFile.WriteEndDocument();
@ -367,11 +368,29 @@ namespace CXML
{
if(lpHandler.OldFileName != null)
{
Console.WriteLine("Replacing: " + lpHandler.OldFileName + " With " + lpHandler.FileName);
XmlData = XmlData.Replace(lpHandler.OldFileName, lpHandler.FileName);
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);
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);
@ -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++)
{
if(FileList[i].FilePointer == ElementPtr)
{
string oldName = FileList[i].FileName;
string extension = Path.GetExtension(oldName);
string folderPath = Path.GetDirectoryName(FileList[i].FileName);
string newPath = Path.ChangeExtension(Path.Combine(folderPath, NewName), extension);
Console.WriteLine("Changed " + Path.Combine(MainDir, oldName) + " => " + Path.Combine(MainDir, newPath));
File.Move(Path.Combine(MainDir, oldName), Path.Combine(MainDir, newPath));
FileList[i].FileName = newPath;
FileList[i].OldFileName = oldName;
return;
if (FileEntry)
{
if (FileList[i].OldFileName != null)
break;
FileList[i].OldFileName = NewName;
return;
}
else
{
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)
@ -495,12 +529,12 @@ namespace CXML
break;
case AttributeType.TYPE_INT:
AttributeValue = bTreeTable.ReadInt32();
TreeTable.Seek(4, SeekOrigin.Current);
Console.WriteLine("Int - Value: " + AttributeValue.ToString() + " sz:" + bTreeTable.ReadInt32());
break;
case AttributeType.TYPE_FLOAT:
float FloatValue = bTreeTable.ReadSingle();
AttributeValue = FloatValue.ToString()+"f";
TreeTable.Seek(4, SeekOrigin.Current);
Console.WriteLine("Float - Value: " + AttributeValue.ToString() + " sz:" + bTreeTable.ReadInt32());
break;
case AttributeType.TYPE_STRING:
int StringOffset = bTreeTable.ReadInt32();
@ -525,10 +559,13 @@ namespace CXML
case AttributeType.TYPE_HASH_ID:
int HashTableOffset = 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;
case AttributeType.TYPE_INTEGER_ARRAY:
int IntArrayOffset = bTreeTable.ReadInt32();
@ -571,7 +608,6 @@ namespace CXML
String Extension = Tools.GetFileExtension(FileData);
String FileName = Path.Combine(FileDir, ElementName, FileHash + Extension);
String finalName = Path.Combine(Path.GetFileName(FileDir), ElementName, FileHash + Extension);
if (!File.Exists(FileName))
{
Console.WriteLine("Writing: " + FileName);
@ -580,18 +616,15 @@ namespace CXML
Directory.CreateDirectory(Path.GetDirectoryName(FileName));
File.WriteAllBytes(FileName, FileData);
LoopbackHandler lpHandler = new LoopbackHandler();
lpHandler.FileName = finalName;
lpHandler.OldFileName = null;
lpHandler.FilePointer = ElementPtr;
FileList.Add(lpHandler);
ChangeFilename(ElementPtr, FileName, true);
}
else
{
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;
case AttributeType.TYPE_ID_STRING_LOOPBACK:
int StringIdTableOffset = bTreeTable.ReadInt32();
@ -604,9 +637,9 @@ namespace CXML
Console.WriteLine("Loopback: " + LoopbackAttribute +" "+ LoopbackPtr.ToString("X")+" ("+ElementPtr.ToString("X")+")");
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;
case AttributeType.TYPE_ID_STRING:
Console.WriteLine("UNSUPPORTED TYPE @ " + TreeTable.Position);
@ -624,18 +657,18 @@ namespace CXML
LoopbackAttribute = Tools.ReadStringAt(StringTable, StringPtr);
Console.WriteLine("Loopback: " + LoopbackAttribute + " " + LoopbackPtr.ToString("X") + " (" + ElementPtr.ToString("X") + ")");
AttributeValue = IDValue.ToString("X8");
ChangeFilename(LoopbackPtr, AttributeValue.ToString());
AttributeValue = "$"+IDValue.ToString("X8");
ChangeFilename(LoopbackPtr, IDValue.ToString("X8"), false);
TreeTable.Seek(4, SeekOrigin.Current);
Console.WriteLine("Loopback Int: " + IntIdTableOffset + " sz: " + bTreeTable.ReadInt32());
break;
case AttributeType.TYPE_ID_INT:
IntIdTableOffset = bTreeTable.ReadInt32();
IntIDTable.Seek(IntIdTableOffset + 4, SeekOrigin.Begin);
IDValue = bIntIDTable.ReadInt32();
AttributeValue = IDValue.ToString("X8");
TreeTable.Seek(4, SeekOrigin.Current);
AttributeValue = "#"+IDValue.ToString("X8");
Console.WriteLine("Int Id: " + IntIdTableOffset + " sz: " + bTreeTable.ReadInt32());
break;
default:
Console.WriteLine("UNKNOWN TYPE @ " + TreeTable.Position);

View File

@ -36,7 +36,7 @@ namespace CXMLCli
Console.WriteLine("\t-w --wait-exit Wait for keypress before exiting");
Console.WriteLine("\t-d --decompile Decompile CXML.");
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;
}
@ -147,6 +147,7 @@ namespace CXMLCli
if(cxmlParser.WaitExit)
Console.ReadKey();
}
return 0;
}
}
}

View File

@ -1,6 +1,7 @@
using System;
using System.Collections.Generic;
using System.Drawing;
using System.Drawing.Imaging;
using System.IO;
using System.Linq;
using System.Security.Cryptography;
@ -38,7 +39,29 @@ namespace General
{
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))
{
@ -60,6 +83,10 @@ namespace General
{
return ".gim";
}
else if(!HasBinaryContent(Encoding.UTF8.GetString(Bytes)))
{
return ".txt";
}
else
{
return ".bin";
@ -178,7 +205,10 @@ namespace General
ms.Seek(ogPos, SeekOrigin.Begin);
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)
{
BinaryReader BinReader = new BinaryReader(ms);
@ -203,6 +233,17 @@ namespace General
int i = BitConverter.ToInt32(IntBytes, 0x00);
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)
{