From e7f60f09c634acd27e46c5d6a5f96e65de8c5479 Mon Sep 17 00:00:00 2001 From: Bluzume <39113159+KuromeSan@users.noreply.github.com> Date: Sat, 14 Aug 2021 06:18:59 +1200 Subject: [PATCH] Fix more more bugs --- .vs/AppInfoParser/v16/.suo | Bin 91136 -> 90624 bytes AppInfoCli/CXMLBuilder.cs | 35 +++++++++++++++++++++++++++++------ AppInfoCli/CXMLReader.cs | 31 +++++++++++++++++++++++++++++++ AppInfoCli/GimConv.cs | 2 ++ AppInfoCli/Program.cs | 4 ++++ AppInfoCli/Tools.cs | 5 ++++- 6 files changed, 70 insertions(+), 7 deletions(-) diff --git a/.vs/AppInfoParser/v16/.suo b/.vs/AppInfoParser/v16/.suo index 096991b12ee2cc1c87c850440f1e5cb120848cae..0e9234fd670f461baf1ff4bd6234d677f9a4eb23 100644 GIT binary patch delta 2352 zcmd5+drXs86#vfcgBDsSZw4q2%R_A8qb-zzXhnv~q61?#Msdu| z$~9b_k6|;}qRs(#(v2;%6WyGPk6_%~ViscNA0z6bv(x#YyC0No$`ZHzwVV8Me&?R^ zopbIz=YICn68lMsgU6jq#Pr?9jN@e;rJrH~a&jTX6@0mwEyl0T8ZH zH6j4|tEyil8?6MFs?@FVVtOwuUKG~MLT_adLbmuM)zj+R32&Xa?4K5`Zy=OW}RM6JcO;G%WK&EQ-v?Y3@{ z`u9>_3#SgTMclMrF z{noo_P(#14*d9UEXVZYrY3&v{>k%$^ z#YSyyJ4M*pm_vuYISqLA;pI4XLoEFa7ohI?Tv7K1e}o4Py0PQqC>pzAyxeIQa#!K4{yxJ>0hbn%F}J4k!sFuiBVd(RcsWCxD}j@tDxRKHWB=(m4XxC zxj(O^Yp=J6oVUf!o5*<|VRULMK6ge%ciq1wPBH4sElZbVW^1#{bM#t6PPtWUTFNtK z&C->dEJjNOZ<27kNU#D*uCH^rHWooO&8$RRbHf*C@t zB1j`uNsJ493m(%qQko21#GV3nxt`B5WE&0ZWuzp9Wmv2RKbJWb>>^T-0#gL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b/AppInfoCli/CXMLBuilder.cs @@ -1,7 +1,9 @@ using CXML; using General; +using Ionic.Zlib; using System; using System.Collections.Generic; +using System.Globalization; using System.IO; using System.Linq; using System.Text; @@ -13,7 +15,6 @@ namespace CXMLDecompiler { String MainDir = ""; String XMLFilename = ""; - String CXMLFilename = ""; String MagicNumber = ""; Int32 Version; FileStream InfoFile; @@ -29,6 +30,7 @@ namespace CXMLDecompiler MemoryStream FileTable; Boolean IsInitalized = false; + public Boolean HashStrings = false; BinaryWriter bInfoFile; BinaryWriter bTreeTable; @@ -64,8 +66,7 @@ namespace CXMLDecompiler bIntArrayTable = new BinaryWriter(IntArrayTable); bHashIDTable = new BinaryWriter(HashIDTable); bStringIDTable = new BinaryWriter(StringIDTable); - - CXMLFilename = CxmlFile; + XMLFilename = XMLFile; MainDir = Path.GetDirectoryName(XMLFilename); @@ -377,7 +378,12 @@ namespace CXMLDecompiler Console.WriteLine("Char: " + attribute.Value); break; case AttributeType.TYPE_HASH_ID: - int HashTableOffset = AddGetHashIdTable(Int32.Parse(attribute.Value, System.Globalization.NumberStyles.HexNumber)); + int hashId = int.Parse(attribute.Value, NumberStyles.HexNumber); + + if (HashStrings) + hashId = int.Parse(Tools.GenerateShortHash(Encoding.UTF8.GetBytes(attribute.Value)), NumberStyles.HexNumber); + + int HashTableOffset = AddGetHashIdTable(hashId); int HashTableSize = 4; bWorkRam.Write(HashTableOffset); bWorkRam.Write(HashTableSize); @@ -432,14 +438,21 @@ namespace CXMLDecompiler Console.WriteLine("ID String: " + StringIdTableOffset + " sz: 0"); break; case AttributeType.TYPE_ID_INT_LOOPBACK: - int IntIdTableOffset = AddGetIntIdTable(int.Parse(attribute.Value, System.Globalization.NumberStyles.HexNumber), Convert.ToInt32(TreeTable.Position)); + int hash = int.Parse(attribute.Value, NumberStyles.HexNumber); + if (HashStrings) + hash = int.Parse(Tools.GenerateShortHash(Encoding.UTF8.GetBytes(attribute.Value)), NumberStyles.HexNumber); + int IntIdTableOffset = AddGetIntIdTable(hash, Convert.ToInt32(TreeTable.Position)); bWorkRam.Write(IntIdTableOffset); bWorkRam.Write((int)0x00); Console.WriteLine("Int Loopback: " + ElementName + " " + TreeTable.Position.ToString("X") + " (" + TreeTable.Position.ToString("X") + ")"); Console.WriteLine("Loopback ID Int: " + IntIdTableOffset + " sz: 0"); break; case AttributeType.TYPE_ID_INT: - IntIdTableOffset = AddGetIntIdTable(int.Parse(attribute.Value, System.Globalization.NumberStyles.HexNumber), -1); + hash = int.Parse(attribute.Value, NumberStyles.HexNumber); + if (HashStrings) + hash = int.Parse(Tools.GenerateShortHash(Encoding.UTF8.GetBytes(attribute.Value)), NumberStyles.HexNumber); + IntIdTableOffset = AddGetIntIdTable(hash, -1); + bWorkRam.Write(IntIdTableOffset); bWorkRam.Write((int)0x00); Console.WriteLine("Int Id: " + IntIdTableOffset + " sz: 0"); @@ -635,6 +648,16 @@ namespace CXMLDecompiler FileTable.Seek(0x00, SeekOrigin.Begin); FileTable.CopyTo(InfoFile); + string excessData = GetTypingInformation("EXCESS"); + if (excessData != "0") + { + Console.WriteLine("Excess Data Found, Writing to end."); + byte[] ExcessData = Convert.FromBase64String(excessData.Replace("*", "=")); + InfoFile.Read(ExcessData, 0x00, ExcessData.Length); + byte[] UnCompressed = ZlibStream.UncompressBuffer(ExcessData); + InfoFile.Write(UnCompressed, 0x00, UnCompressed.Length); + } + InfoFile.Seek(0x8, SeekOrigin.Begin); bInfoFile.Write(TreeTableOffset); bInfoFile.Write(TreeTableSize); diff --git a/AppInfoCli/CXMLReader.cs b/AppInfoCli/CXMLReader.cs index 66a7fa6..bc1d153 100644 --- a/AppInfoCli/CXMLReader.cs +++ b/AppInfoCli/CXMLReader.cs @@ -364,6 +364,26 @@ namespace CXML typingInfo.value = value.ToString(); SilicaTypingInformationList.Add(typingInfo); } + public void Align(Stream s, int align) + { + + int size = Convert.ToInt32(s.Position); + if (size % align != 0) + { + int totalAlign = (align - (size % align)); + for (int i = 0; i < totalAlign; i++) + { + s.Seek(0x1, SeekOrigin.Current); + } + } + } + public void GotoEnd() + { + InfoFile.Seek(GetFileTableOffset(), SeekOrigin.Begin); + InfoFile.Seek(GetFileTableSize(), SeekOrigin.Current); + Align(InfoFile, 0x10); + } + public void DecompileCXML(String CXMLFile, bool force = false) { @@ -390,6 +410,17 @@ namespace CXML XMLFile.Flush(); XMLFile.Close(); + GotoEnd(); + int bytesRemaining = Convert.ToInt32(InfoFile.Length - InfoFile.Position); + if (bytesRemaining > 0) // Some RCS files have unexplainable random XML Data at the end of them, Dont ask me. im just the messanger + { + Console.WriteLine(bytesRemaining.ToString("X8") + " Excess Bytes Found, Shoving it in SilicaTypingInformation."); + byte[] ExcessData = new byte[bytesRemaining]; + InfoFile.Read(ExcessData, 0x00, bytesRemaining); + byte[] Compressed = ZlibStream.CompressBuffer(ExcessData); + string base64 = Convert.ToBase64String(Compressed).Replace("=", "*"); + AddTypingInfo("EXCESS", base64); + } for(int i = 0; i < SilicaTypingInformationList.Count; i++) { TypingInformation tinfo = SilicaTypingInformationList[i]; diff --git a/AppInfoCli/GimConv.cs b/AppInfoCli/GimConv.cs index 8d3ce37..e05aaf1 100644 --- a/AppInfoCli/GimConv.cs +++ b/AppInfoCli/GimConv.cs @@ -54,6 +54,8 @@ namespace CXMLDecompiler } zip.Dispose(); zipStream.Dispose(); + + File.AppendAllText("GimConv\\GimConv.cfg", "option -psvindex8 {\r\n format_endian = little\r\n format_style = psp\r\n image_format = index8\r\n pixel_order = normal\r\n pixel_channel = rgba\r\n limit_image_width = 4096\r\n limit_image_height = 4096\r\n}"); DownloadCompleted = true; } diff --git a/AppInfoCli/Program.cs b/AppInfoCli/Program.cs index f7308e1..e04364e 100644 --- a/AppInfoCli/Program.cs +++ b/AppInfoCli/Program.cs @@ -56,6 +56,7 @@ namespace CXMLCli Console.WriteLine("\t-w --wait-exit Wait for keypress before exiting"); Console.WriteLine("\t-d --decompile Decompile CXML to XML."); Console.WriteLine("\t-c --compile Compile XML to CXML"); + Console.WriteLine("\t-h --hash-string When Compiling, Generate new hashes"); Console.WriteLine("Example Decompile: " + Path.GetFileName(Assembly.GetEntryAssembly().Location) + " app.info -d -p"); Console.WriteLine("Example Compile: " + Path.GetFileName(Assembly.GetEntryAssembly().Location) + " app.xml app.info -c"); Console.WriteLine("Default functonality is to Decompile,\nThis is canceled if any other arguments passed."); @@ -200,6 +201,9 @@ namespace CXMLCli { Console.WriteLine("Compiling: " + path); CXMLBuilder builder = new CXMLBuilder(); + if (HasArg(ArgsFull, "-h") || HasArg(ArgsFull, "----hash-string")) + builder.HashStrings = true; + builder.Init(path, args[1]); builder.BuildCXML(path, args[1]); Console.WriteLine("\n\nCOMPILATION COMPLETE!"); diff --git a/AppInfoCli/Tools.cs b/AppInfoCli/Tools.cs index ec91f48..230a829 100644 --- a/AppInfoCli/Tools.cs +++ b/AppInfoCli/Tools.cs @@ -2,6 +2,7 @@ using System.Collections.Generic; using System.Drawing; using System.Drawing.Imaging; +using System.Globalization; using System.IO; using System.Linq; using System.Security.Cryptography; @@ -258,7 +259,9 @@ namespace General public static string GenerateShortHash(byte[] Data) { - return GenerateHash(Data).Substring(0, 8); + SHA1 sha = SHA1.Create(); + byte[] ShaBytes = sha.ComputeHash(Data); + return BitConverter.ToInt32(ShaBytes, 0).ToString("X8"); } public static String ReadString(Stream ms, int limit = -1)