private void ReadHashSec(string XEXPath) { MojosIO mIO = GetHashSec(XEXPath); int counter = 0; string tem = ""; mIO.Position = 0; while (mIO.Position < mIO.StreamLength) { tem = mIO.ReadCString(); HashSecFiles.Add(tem); HashSecHashes.Add(mIO.ReadBytes(20)); string s = Path.GetDirectoryName(XEXPath) + "\\" + Path.GetFileName(tem); if (!File.Exists(s)) { AddLog(string.Format("File '{0}' not found", Path.GetFileName(tem))); } counter++; } AddLog(string.Format("{0} File Hashes found", counter)); mIO.Close(); }
private MojosIO GetHashSec(string XEXFileName) { MojosIO mIO = new MojosIO(XEXFileName, Endian.Big); if (!mIO.Accessed) { AddLog("Error accessing 'default.xex'"); return(null); } if (mIO.ReadString(4, Encoding.ASCII) == "XEX2") { AddLog("XEX2 Header valid"); mIO.Position = 8; int BaseFileOffset = mIO.ReadInt32(); mIO.Position = 0x10; int SomePointer = mIO.ReadInt32(); mIO.Position = SomePointer + 0x110; uint LoadingAddress = mIO.ReadUInt32(); mIO.Position = SomePointer; int TablePointer = mIO.ReadInt32() + SomePointer; int pos = TablePointer + 4; mIO.Position = pos; uint TableSize = mIO.ReadUInt32(); uint FileAddress; uint FileSize; mIO.Position -= 4; string tem = ""; while (pos < (TableSize + TablePointer)) { tem = mIO.ReadString(8, Encoding.ASCII); FileAddress = mIO.ReadUInt32(); FileSize = mIO.ReadUInt32(); if (tem == "HashSec") { AddLog(string.Format("HashSec Located at Address 0x{0:X}", (uint)((FileAddress - LoadingAddress) + BaseFileOffset))); mIO.Position = ((FileAddress - LoadingAddress) + BaseFileOffset); File.WriteAllBytes(HashSecTemp, mIO.ReadBytes((int)FileSize)); mIO.Close(); return(new MojosIO(HashSecTemp, Endian.Big)); } } } else { mIO.Close(); AddLog("Invalid XEX Header"); return(null); } mIO.Close(); return(null); }
private void PackCoalescedButton_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Mirrors Enge INI Files|*.ini|Deutsch Localization File|*.deu|Español Localization File|*.esn|Français Localization File|*.fra|English Localization File|*.int|Italiano Localization File|*.ita|Russian Localization File|*.rus|All Files | *.*"; if (sfd.ShowDialog() == DialogResult.OK) { FolderBrowserDialog fbd2 = new FolderBrowserDialog(); if (fbd2.ShowDialog() == DialogResult.OK) { try { if (!File.Exists(fbd2.SelectedPath + "\\Files.txt")) { throw new Exception("The file 'Files.txt' dose not exist.\nThis is needed to rebuild the package."); } string[] Entrys = FileToStringArray(fbd2.SelectedPath + "\\Files.txt"); MojosIO mIO = new MojosIO(new FileStream(sfd.FileName, FileMode.Create), Endian.Big); if (!mIO.Accessed) { throw new Exception("There was a problem while acessing the stream."); } AddLog(string.Format("Writing Entry Count of {0}...", (Entrys.Length * 2))); mIO.Write((int)(Entrys.Length * 2)); for (int i = 0; i < Entrys.Length; i++) { mIO.Write((int)(Entrys[i].Length + 1)); mIO.WriteString(Entrys[i], Encoding.ASCII); mIO.Write((byte)0); AddLog(string.Format("Writing {0}...", Path.GetFileName(Entrys[i]))); byte[] Buffer = File.ReadAllBytes(fbd2.SelectedPath + "\\" + Path.GetFileName(Entrys[i])); mIO.Write((int)(Buffer.Length + 1)); mIO.Write(Buffer); mIO.Write((byte)0); } AddLog("Flushing Stream..."); mIO.Flush(); mIO.Close(); AddLog("Done packing files."); } catch (Exception x) { AddLog("ERROR: " + x.Message); } } } }
private void UnpackCoalescedButton_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Mirrors Enge INI Files|*.ini|Deutsch Localization File|*.deu|Español Localization File|*.esn|Français Localization File|*.fra|English Localization File|*.int|Italiano Localization File|*.ita|Russian Localization File|*.rus|All Files | *.*"; if (ofd.ShowDialog() == DialogResult.OK) { FolderBrowserDialog fbd2 = new FolderBrowserDialog(); if (fbd2.ShowDialog() == DialogResult.OK) { try { StreamWriter fw = new StreamWriter(fbd2.SelectedPath + "\\Files.txt"); MojosIO mIO = new MojosIO(ofd.FileName, Endian.Big); if (!mIO.Accessed) { fw.Close(); throw new Exception("There was a problem while acessing the stream."); } int EntryCount = mIO.ReadInt32(); AddLog(string.Format("Total Entrys: {0}", (EntryCount / 2))); for (int i = 0; i < (EntryCount / 2); i++) { int EntryNameLength = mIO.ReadInt32(); string EntryName = mIO.ReadString(EntryNameLength, Encoding.ASCII); int EntrySize = mIO.ReadInt32(); byte[] Entry = mIO.ReadBytes(EntrySize - 1); mIO.Position++; AddLog(string.Format("Writing file {0}", Path.GetFileName(EntryName))); File.WriteAllBytes(fbd2.SelectedPath + "\\" + Path.GetFileName(EntryName), Entry); fw.WriteLine(EntryName); fw.Flush(); } fw.Close(); mIO.Close(); AddLog("Done extracting files!"); } catch (Exception x) { AddLog("ERROR: " + x.Message); } } } }
private void UnpackCoalescedButton_Click(object sender, EventArgs e) { OpenFileDialog ofd = new OpenFileDialog(); ofd.Filter = "Mirrors Enge INI Files|*.ini|Deutsch Localization File|*.deu|Español Localization File|*.esn|Français Localization File|*.fra|English Localization File|*.int|Italiano Localization File|*.ita|Russian Localization File|*.rus|All Files | *.*"; if (ofd.ShowDialog() == DialogResult.OK) { FolderBrowserDialog fbd2 = new FolderBrowserDialog(); if (fbd2.ShowDialog() == DialogResult.OK) { try { StreamWriter fw = new StreamWriter(fbd2.SelectedPath + "\\Files.txt"); MojosIO mIO = new MojosIO(ofd.FileName, Endian.Big); if (!mIO.Accessed) { fw.Close(); throw new Exception("There was a problem while acessing the stream."); } int EntryCount = mIO.ReadInt32(); AddLog(string.Format("Total Entrys: {0}", (EntryCount / 2))); for (int i = 0; i < (EntryCount / 2); i++) { int EntryNameLength = mIO.ReadInt32(); string EntryName = mIO.ReadString(EntryNameLength, Encoding.ASCII); int EntrySize = mIO.ReadInt32(); byte[] Entry = mIO.ReadBytes(EntrySize - 1); mIO.Position++; AddLog(string.Format("Writing file {0}", Path.GetFileName(EntryName))); File.WriteAllBytes(fbd2.SelectedPath + "\\" + Path.GetFileName(EntryName), Entry); fw.WriteLine(EntryName); fw.Flush(); } fw.Close(); mIO.Close(); AddLog("Done extracting files!"); } catch (Exception x) { AddLog("ERROR: " + x.Message); } } } }
private void PackCoalescedButton_Click(object sender, EventArgs e) { SaveFileDialog sfd = new SaveFileDialog(); sfd.Filter = "Mirrors Enge INI Files|*.ini|Deutsch Localization File|*.deu|Español Localization File|*.esn|Français Localization File|*.fra|English Localization File|*.int|Italiano Localization File|*.ita|Russian Localization File|*.rus|All Files | *.*"; if (sfd.ShowDialog() == DialogResult.OK) { FolderBrowserDialog fbd2 = new FolderBrowserDialog(); if (fbd2.ShowDialog() == DialogResult.OK) { try { if (!File.Exists(fbd2.SelectedPath + "\\Files.txt")) throw new Exception("The file 'Files.txt' dose not exist.\nThis is needed to rebuild the package."); string[] Entrys = FileToStringArray(fbd2.SelectedPath + "\\Files.txt"); MojosIO mIO = new MojosIO(new FileStream(sfd.FileName, FileMode.Create), Endian.Big); if (!mIO.Accessed) throw new Exception("There was a problem while acessing the stream."); AddLog(string.Format("Writing Entry Count of {0}...", (Entrys.Length * 2))); mIO.Write((int)(Entrys.Length * 2)); for (int i = 0; i < Entrys.Length; i++) { mIO.Write((int)(Entrys[i].Length + 1)); mIO.WriteString(Entrys[i], Encoding.ASCII); mIO.Write((byte)0); AddLog(string.Format("Writing {0}...", Path.GetFileName(Entrys[i]))); byte[] Buffer = File.ReadAllBytes(fbd2.SelectedPath + "\\" + Path.GetFileName(Entrys[i])); mIO.Write((int)(Buffer.Length + 1)); mIO.Write(Buffer); mIO.Write((byte)0); } AddLog("Flushing Stream..."); mIO.Flush(); mIO.Close(); AddLog("Done packing files."); } catch (Exception x) { AddLog("ERROR: " + x.Message); } } } }
private MojosIO GetHashSec(string XEXFileName) { MojosIO mIO = new MojosIO(XEXFileName, Endian.Big); if (!mIO.Accessed) { AddLog("Error accessing 'default.xex'"); return null; } if (mIO.ReadString(4, Encoding.ASCII) == "XEX2") { AddLog("XEX2 Header valid"); mIO.Position = 8; int BaseFileOffset = mIO.ReadInt32(); mIO.Position = 0x10; int SomePointer = mIO.ReadInt32(); mIO.Position = SomePointer + 0x110; uint LoadingAddress = mIO.ReadUInt32(); mIO.Position = SomePointer; int TablePointer = mIO.ReadInt32() + SomePointer; int pos = TablePointer + 4; mIO.Position = pos; uint TableSize = mIO.ReadUInt32(); uint FileAddress; uint FileSize; mIO.Position -= 4; string tem = ""; while (pos < (TableSize + TablePointer)) { tem = mIO.ReadString(8, Encoding.ASCII); FileAddress = mIO.ReadUInt32(); FileSize = mIO.ReadUInt32(); if (tem == "HashSec") { AddLog(string.Format("HashSec Located at Address 0x{0:X}", (uint)((FileAddress - LoadingAddress) + BaseFileOffset))); mIO.Position = ((FileAddress - LoadingAddress) + BaseFileOffset); File.WriteAllBytes(HashSecTemp, mIO.ReadBytes((int)FileSize)); mIO.Close(); return new MojosIO(HashSecTemp, Endian.Big); } } } else { mIO.Close(); AddLog("Invalid XEX Header"); return null; } mIO.Close(); return null; }
private void ApplyXEXPatchButton_Click(object sender, EventArgs e) { try { if (BackupXEXCheckbox.Checked) { if (!File.Exists(FolderPath + "\\default.xex.bak")) { AddLog("Backing up XEX..."); File.Copy(FolderPath + "\\default.xex", FolderPath + "\\default.xex.bak"); } else { AddLog("Your XEX is already backed up."); } } if (BackupX360TOCCheckbox.Checked) { if (!File.Exists(FolderPath + "\\Xbox360TOC.txt.bak")) { AddLog("Backing up 'Xbox360TOC.txt'..."); File.Copy(FolderPath + "\\Xbox360TOC.txt", FolderPath + "\\Xbox360TOC.txt.bak"); } else { AddLog("'Xbox360TOC.txt' is already backed up."); } } AddLog("Loading 'Xbox360TOC.txt' to memory."); string[] data = FileToStringArray(FolderPath + "\\Xbox360TOC.txt"); StreamWriter tocw = new StreamWriter(FolderPath + "\\Xbox360TOC.txt"); for (int i = 0; i < data.Length; i++) { AddLog(string.Format("Parsing line {0}...", i)); int s = 0; string tem = string.Empty; int p = 0; for (int x = 0; x < data[i].Length; x++) { if (data[i][x] == ' ') { break; } tem += data[i][x]; p++; } s = Convert.ToInt32(tem); tem = string.Empty; if (s == 0) { tocw.WriteLine(data[i]); break; } for (int x = (p + 5); x < data[i].Length; x++) { if (data[i][x] == ' ') { break; } tem += data[i][x]; } if (File.Exists(FolderPath + "\\" + Path.GetFileName(tem))) { int filesize = File.ReadAllBytes(FolderPath + "\\" + Path.GetFileName(tem)).Length; AddLog(string.Format("Writing file size {0} bytes of file '{1}' to line {2}...", filesize, Path.GetFileName(tem), i)); tocw.WriteLine(filesize.ToString() + data[i].Substring(s.ToString().Length)); } else { tocw.WriteLine(data[i]); } } AddLog("Flushing stream..."); tocw.Flush(); tocw.Dispose(); AddLog("Done Repairing 'Xbox360TOC.txt'."); MojosIO mIO = GetHashSec(FolderPath + "\\default.xex"); for (int i = 0; i < HashSecFiles.Count; i++) { mIO.ReadCString(); if (File.Exists(FolderPath + "\\" + Path.GetFileName(HashSecFiles[i]))) { AddLog(string.Format("Fixing '{0}' SHA1 Hash", Path.GetFileName(HashSecFiles[i]))); mIO.Write(CalcSHA1(FolderPath + "\\" + Path.GetFileName(HashSecFiles[i]))); } else { AddLog(string.Format("'{0}' not found", Path.GetFileName(HashSecFiles[i]))); mIO.Position += 20; } } AddLog("Flushing stream..."); mIO.Flush(); mIO.Close(); AddLog("Success, XEX patched!"); } catch (Exception x) { AddLog("ERROR: " + x.Message); } }
/// <summary> /// Searches a Hexagdecimal string from the current IO stream. /// </summary> /// <param name="HexString"></param> /// <param name="Start"></param> /// <param name="StopWhenFound"></param> /// <param name="mIO"></param> /// <returns>Long[]</returns> public static long[] SearchHexString(string HexString, long Start, bool StopWhenFound, MojosIO mIO) { return(SearchByteArray(HexStringToByteArray(HexString), Start, StopWhenFound, mIO)); }
/// <summary> /// Searches a unicode string from the current IO stream. /// </summary> /// <param name="ToSearch"></param> /// <param name="Start"></param> /// <param name="StopWhenFound"></param> /// <param name="mIO"></param> /// <returns></returns> public static long[] SearchUnicodeString(string ToSearch, long Start, bool StopWhenFound, MojosIO mIO) { return(SearchByteArray(Encoding.Unicode.GetBytes(ToSearch), Start, StopWhenFound, mIO)); }
/// <summary> /// Searches a byte array in the current IO stream. /// </summary> /// <param name="ToSearch"></param> /// <param name="Start"></param> /// <param name="StopWhenFound"></param> /// <param name="mIO"></param> /// <returns>Long[]</returns> public static long[] SearchByteArray(byte[] ToSearch, long Start, bool StopWhenFound, MojosIO mIO) { try { List <long> ret = new List <long>(); for (long i = Start; i < mIO.StreamLength - ToSearch.Length; i++) { byte[] tem = mIO.ReadBytes(ToSearch.Length); if (BitConverter.ToString(tem) == BitConverter.ToString(ToSearch)) { ret.Add(i); if (StopWhenFound) { break; } } } return(ret.ToArray()); } catch (Exception ex) { throw ex; } }
/// <summary> /// Searches a unicode string from the current IO stream. /// </summary> /// <param name="ToSearch"></param> /// <param name="Start"></param> /// <param name="StopWhenFound"></param> /// <param name="mIO"></param> /// <returns></returns> public static long[] SearchUnicodeString(string ToSearch, long Start, bool StopWhenFound, MojosIO mIO) { return SearchByteArray(Encoding.Unicode.GetBytes(ToSearch), Start, StopWhenFound, mIO); }
/// <summary> /// Searches a Hexagdecimal string from the current IO stream. /// </summary> /// <param name="HexString"></param> /// <param name="Start"></param> /// <param name="StopWhenFound"></param> /// <param name="mIO"></param> /// <returns>Long[]</returns> public static long[] SearchHexString(string HexString, long Start, bool StopWhenFound, MojosIO mIO) { return SearchByteArray(HexStringToByteArray(HexString), Start, StopWhenFound, mIO); }
/// <summary> /// Searches a byte array in the current IO stream. /// </summary> /// <param name="ToSearch"></param> /// <param name="Start"></param> /// <param name="StopWhenFound"></param> /// <param name="mIO"></param> /// <returns>Long[]</returns> public static long[] SearchByteArray(byte[] ToSearch, long Start, bool StopWhenFound, MojosIO mIO) { try { List<long> ret = new List<long>(); for (long i = Start; i < mIO.StreamLength - ToSearch.Length; i++) { byte[] tem = mIO.ReadBytes(ToSearch.Length); if (BitConverter.ToString(tem) == BitConverter.ToString(ToSearch)) { ret.Add(i); if (StopWhenFound) break; } } return ret.ToArray(); } catch (Exception ex) { throw ex; } }