void b2() { listView2.Items.Clear(); Log("Writing to package"); RSAParams x = null; if (radioButton1.Checked) { x = KV; } else if (radioButton2.Checked) { x = new RSAParams(StrongSigned.LIVE); } else if (radioButton3.Checked) { x = new RSAParams(StrongSigned.PIRS); } if (checkBoxX4.Checked) { xPackage.FlushPackage(x); } else { xPackage.UpdateHeader(x); } Log("Package fixed"); }
/// <summary> /// Writes and signs the header /// </summary> /// <param name="xParams"></param> /// <returns></returns> public bool WriteHeader(RSAParams xParams) { if (!xParams.Valid || !ActiveCheck()) { return(false); } return(xWriteHeader(xParams) & !(xActive = false)); }
/// <summary> /// Will only work wif your own KV, possibly strong signed /// </summary> /// <param name="xParams"></param> /// <returns></returns> public bool FixPackage(RSAParams xParams) { if (!xParams.Valid || !dataloaded || !ActiveCheck()) { return(false); } return((RehashPackage() && WriteHeader(xParams)) & !(xActive = false)); }
public MainForm() { CheckForIllegalCrossThreadCalls = false; string proc = Process.GetCurrentProcess().ProcessName; int id = Process.GetCurrentProcess().Id; Process[] lst = Process.GetProcesses(); foreach (Process p in lst) { if (p.ProcessName != proc || p.Id == id) { continue; } MessageBox.Show("This program is already open"); Process.GetCurrentProcess().Kill(); return; } InitializeComponent(); VariousFunctions.DeleteFile(Application.StartupPath + "/LFLiveUpdater.exe"); bool devmode = AssemblyFunctions.GrabParentProcessName() == "devenv"; Thread y = new Thread(new ParameterizedThreadStart(upd)); y.Start(devmode); Thread x = new Thread(new ParameterizedThreadStart(startss)); x.Start(devmode); VariousFunctions.DeleteTempFiles(); Thread z = new Thread(new ThreadStart(readrss)); z.Start(); PublicKV = new RSAParams(Application.StartupPath + "/KV.bin"); if (!PublicKV.Valid) { MessageBox.Show("Cannot load KV"); Process.GetCurrentProcess().Kill(); return; } XAbout.WriteLegalLocally(); while (x.IsAlive) { Application.DoEvents(); } Show(); while (y.IsAlive) { Application.DoEvents(); } Enabled = true; Select(); Focus(); if (!devmode) { updr.Dispose(); updr = null; } checkForUpdatesToolStripMenuItem.Enabled = true; }
bool xWriteHeader(RSAParams xParams) { try { DJsIO xio = new DJsIO(true); xHeaderData.Write(ref xio); xio.SetLength(0xB000); xio.Position = 0x340; xio.Write((uint)0xAD0E); xio.Position = 0x379; xio.Write(new byte[] { 0x24, 5, 5, 0x11 }); IO.Position = 0x37D; xio.Write(IO.ReadBytes(20)); xio.Write((byte)((xIsShifted ? 1 : 0) << 6)); xio.WriteUInt24(xBlockCount); xio.Write(xDeviation); xio.Flush(); xio.Position = 0x344; byte[] xHash = SHA1Quick.ComputeHash(xio.ReadBytes((int)(xio.Length - 0x344))); xio.Position = 0x32C; xio.Write(xHash); xio.Flush(); xio.Position = 0x22C; xHash = SHA1Quick.ComputeHash(xio.ReadBytes(0x118)); xio.Position = 4; if (xParams.Type == PackageMagic.CON) { xio.Write(xParams.Certificate); xio.Write(ScrambleMethods.StockScramble(RSAQuick.SignatureGenerate(xParams.RSAKeys, xHash), true)); } else { xio.Write(ScrambleMethods.DevScramble(RSAQuick.SignatureGenerate(xParams.RSAKeys, xHash))); xio.Write(new byte[0x128]); } xio.IsBigEndian = true; xio.Position = 0; xio.Write(((uint)xParams.Type)); xio.Flush(); xHeaderData.xMagic = xParams.Type; IO.Position = 0; IO.Write(xio.ReadStream()); IO.Flush(); xio.Dispose(); return(true); } catch { return(false); } }
public MainForm() { CheckForIllegalCrossThreadCalls = false; string proc = Process.GetCurrentProcess().ProcessName; int id = Process.GetCurrentProcess().Id; Process[] lst = Process.GetProcesses(); foreach (Process p in lst) { if (p.ProcessName != proc || p.Id == id) continue; MessageBox.Show("This program is already open"); Process.GetCurrentProcess().Kill(); return; } InitializeComponent(); VariousFunctions.DeleteFile(Application.StartupPath + "/LFLiveUpdater.exe"); bool devmode = AssemblyFunctions.GrabParentProcessName() == "devenv"; Thread y = new Thread(new ParameterizedThreadStart(upd)); y.Start(devmode); Thread x = new Thread(new ParameterizedThreadStart(startss)); x.Start(devmode); VariousFunctions.DeleteTempFiles(); Thread z = new Thread(new ThreadStart(readrss)); z.Start(); PublicKV = new RSAParams(Application.StartupPath + "/KV.bin"); if (!PublicKV.Valid) { MessageBox.Show("Cannot load KV"); Process.GetCurrentProcess().Kill(); return; } XAbout.WriteLegalLocally(); while (x.IsAlive) Application.DoEvents(); Show(); while (y.IsAlive) Application.DoEvents(); Enabled = true; Select(); Focus(); if (!devmode) { updr.Dispose(); updr = null; } checkForUpdatesToolStripMenuItem.Enabled = true; }
private bool PackageCreate(string con, CreateSTFS xsession) { var signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin"); try { xsession.HeaderData.Title_Display = artistSongTool.Checked ? (SongArtist + " - " + SongTitle) : ("\"" + SongTitle + "\"" + (songByArtistTool.Checked ? " by " + SongArtist : "")); xsession.HeaderData.Description = "Converted to CON using C3 CON Tools"; var xy = new STFSPackage(xsession, signature, con); xy.CloseIO(); return(true); } catch (Exception) { return(false); } }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { xsession.HeaderData.ContentImageBinary = picContent.Image.ImageToBytes(ImageFormat.Png); xsession.HeaderData.PackageImageBinary = picPackage.Image.ImageToBytes(ImageFormat.Png); switch (GameIndex) { case 0: xsession.HeaderData.TitleID = 0x45410829; break; case 1: xsession.HeaderData.TitleID = 0x45410869; break; case 2: xsession.HeaderData.TitleID = 0x45410914; break; } xsession.HeaderData.Publisher = ""; xsession.HeaderData.Title_Package = "Rock Band " + (GameIndex + 1); xsession.HeaderData.SetLanguage(Languages.English); xsession.HeaderData.Title_Display = Title; xsession.HeaderData.Description = Description; xsession.STFSType = STFSType.Type0; xsession.HeaderData.MakeAnonymous(); xsession.HeaderData.ThisType = radioCON.Checked ? PackageType.SavedGame : PackageType.MarketPlace; signature = radioCON.Checked ? new RSAParams(Application.StartupPath + "\\bin\\KV.bin") : new RSAParams(StrongSigned.LIVE); var xy = new STFSPackage(xsession, signature, xOut); xy.CloseIO(); //now open and unlock if (!Tools.UnlockCON(xOut)) { MessageBox.Show("There was an error unlocking CON file\nCan't finish", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); return; } //convert to CON if button checked, if not, leave as LIVE if (!radioCON.Checked) { return; } if (!Tools.SignCON(xOut)) { MessageBox.Show("There was an error signing CON file\nCan't finish", Text, MessageBoxButtons.OK, MessageBoxIcon.Error); } }
private bool buildPackage() { bool success; try { var signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin"); var bigpack = new STFSPackage(packfiles, signature, xOut); var count1 = bigpack.xFileDirectory.Count; bigpack.CloseIO(); var pack = new STFSPackage(xOut); var count2 = pack.xFileDirectory.Count; pack.CloseIO(); if (count1 == count2) { Log("Awesome ... looks like everything went smoothly"); success = true; } else { MessageBox.Show("Sorry, it looks like there was a problem creating your pack\nThere should be a total of " + count1 + " files but the pack is only reporting " + count2 + " files\n\nThis is caused by a nasty bug in the X360 library " + "we thought we had fixed!\n\nClick 'View Package' to open pack in CON Explorer and start checking each song's folder, " + "whenever you find the first song that has only a .mid file in its folder, that's likely the file causing the problem\nRemove that " + "file and try building the pack again\n\nDO NOT PUT THIS PACK IN YOUR GAME", Text + " - Big Bad Bug", MessageBoxButtons.OK, MessageBoxIcon.Error); sOpenPackage = xOut; Log("Pack creation failed ... remove problem file and try again"); success = false; } } catch { Log("There was an error building CON file"); success = false; } return(success); }
/// <summary> /// Writes and signs the header /// </summary> /// <param name="xParams"></param> /// <returns></returns> public bool WriteHeader(RSAParams xParams) { if (!xParams.Valid || !ActiveCheck()) return false; return (xWriteHeader(xParams) & !(xActive = false)); }
/// <summary> /// Fixes the hashes of the file /// </summary> /// <param name="SignTypeOrNull"></param> /// <returns></returns> public bool FixHashes(RSAParams SignTypeOrNull) { if (SignTypeOrNull != null && !SignTypeOrNull.Valid) throw CryptoExcepts.ParamError; if (!xPackage.ActiveCheck()) return false; if (!Opened && !ReadBlocks()) return (xPackage.xActive = false); try { // Fixes each hash associated with each block for each Level List<uint> x1 = new List<uint>(); foreach (BlockRecord x in xBlocks) { xPackage.AddToLog("Fixing Level 0"); xPackage.XTakeHash(xPackage.GenerateDataOffset(x.ThisBlock), xPackage.GenerateHashOffset(x.ThisBlock, TreeLevel.L0), 0x1000); if (!x1.Contains(x.ThisBlock / Constants.BlockLevel[0])) x1.Add(x.ThisBlock / Constants.BlockLevel[0]); } if (xPackage.xSTFSStruct.BlockCount >= Constants.BlockLevel[0]) { xPackage.AddToLog("Fixing Level 1"); List<uint> x2 = new List<uint>(); foreach (uint x in x1) { xPackage.XTakeHash(xPackage.GenerateBaseOffset((x * Constants.BlockLevel[0]), TreeLevel.L0), xPackage.GenerateHashOffset((x * Constants.BlockLevel[0]), TreeLevel.L1), 0x1000); if (!x2.Contains(x / Constants.BlockLevel[0])) x2.Add(x / Constants.BlockLevel[0]); } if (xPackage.xSTFSStruct.BlockCount > 0x70E4) { xPackage.AddToLog("Fixing Level 2"); foreach (uint x in x2) xPackage.XTakeHash(xPackage.GenerateBaseOffset((x * Constants.BlockLevel[1]), TreeLevel.L1), xPackage.GenerateHashOffset((x * Constants.BlockLevel[1]), TreeLevel.L2), 0x1000); } } if (SignTypeOrNull != null) xPackage.xWriteHeader(SignTypeOrNull); ClearBlocks(); return !(xPackage.xActive = false); } catch { ClearBlocks(); return (xPackage.xActive = false); } }
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { Tools.CurrentFolder = Path.GetDirectoryName(con); Log("Reading CON file " + Path.GetFileName(con)); var dta = Path.GetTempPath() + "temp_dta.txt"; var backup = con + "_backup"; Tools.DeleteFile(backup); if (!Parser.ExtractDTA(con))//grab byte[] content of DTA { Log("Error extracting DTA file"); ErrorOut(); return; } if (!Parser.WriteDTAToFile(dta)) //write it out to file { Log("Error extracting DTA file"); ErrorOut(); return; } var song = new STFSPackage(con); if (backUpCONFile.Checked) { Log("Found songs.dta file, making a backup of your file before starting"); Log("THIS STEP MAY TAKE A WHILE. DON'T CLOSE ME DOWN!"); song.CloseIO(); File.Copy(con, backup); song = new STFSPackage(con); } var xDTA = song.GetFile("/songs/songs.dta"); Log("Opening DTA file..."); var process = Process.Start(dta); Log("DTA file is being edited by the user ... waiting..."); do { //wait while user has DTA file opened } while (!process.HasExited); process.Dispose(); Log("DTA file closed by user, continuing..."); Log("Replacing old DTA file with modified DTA file"); Log("THIS STEP MAY TAKE A WHILE. DON'T CLOSE ME DOWN!"); if (!xDTA.Replace(dta)) { Log("Error replacing DTA file with modified one"); Tools.DeleteFile(backup); ErrorOut(); return; } Log("Replaced DTA file successfully"); song.Header.MakeAnonymous(); song.Header.ThisType = PackageType.SavedGame; var success = false; try { Log("Saving changes to pack ... sit tight"); Log("THIS STEP MAY TAKE A WHILE. DON'T CLOSE ME DOWN!"); signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin"); song.RebuildPackage(signature); song.FlushPackage(signature); song.CloseIO(); success = true; } catch (Exception ex) { Log("There was an error: " + ex.Message); song.CloseIO(); } if (success) { Log("Trying to unlock CON file"); if (Tools.UnlockCON(con)) { Log("Unlocked CON file successfully"); } else { Log("Error unlocking CON file"); success = false; } } if (success) { if (Tools.SignCON(con)) { Log("CON file signed successfully"); } else { Log("Error signing CON file"); success = false; } } Tools.DeleteFile(dta); Log(success ? "Process completed successfully!" : "Something went wrong along the way, sorry!"); if (success) { return; } if (!backUpCONFile.Checked) { return; } Log("Restoring backup file"); Tools.DeleteFile(con); Log(Tools.MoveFile(backup, con) ? "Backup file restored successfully, nothing was lost" : "Sorry, there was an error restoring the backup file"); }
bool xWriteHeader(RSAParams xParams) { try { DJsIO xio = new DJsIO(true); xHeaderData.Write(ref xio); xio.SetLength(0xB000); xio.Position = 0x340; xio.Write((uint)0xAD0E); xio.Position = 0x379; xio.Write(new byte[] { 0x24, 5, 5, 0x11 }); IO.Position = 0x37D; xio.Write(IO.ReadBytes(20)); xio.Write((byte)((xIsShifted ? 1 : 0) << 6)); xio.WriteUInt24(xBlockCount); xio.Write(xDeviation); xio.Flush(); xio.Position = 0x344; byte[] xHash = SHA1Quick.ComputeHash(xio.ReadBytes((int)(xio.Length - 0x344))); xio.Position = 0x32C; xio.Write(xHash); xio.Flush(); xio.Position = 0x22C; xHash = SHA1Quick.ComputeHash(xio.ReadBytes(0x118)); xio.Position = 4; if (xParams.Type == PackageMagic.CON) { xio.Write(xParams.Certificate); xio.Write(ScrambleMethods.StockScramble(RSAQuick.SignatureGenerate(xParams.RSAKeys, xHash), true)); } else { xio.Write(ScrambleMethods.DevScramble(RSAQuick.SignatureGenerate(xParams.RSAKeys, xHash))); xio.Write(new byte[0x128]); } xio.IsBigEndian = true; xio.Position = 0; xio.Write(((uint)xParams.Type)); xio.Flush(); xHeaderData.xMagic = xParams.Type; IO.Position = 0; IO.Write(xio.ReadStream()); IO.Flush(); xio.Dispose(); return true; } catch { return false; } }
/// <summary> /// Writes header to the file /// </summary> /// <param name="xParams"></param> /// <returns></returns> internal bool xWriteHeader(RSAParams xParams) { if (!xParams.Valid) throw CryptoExcepts.ParamError; // Writes, hashes, and signs data to a temp file AddToLog("Writing Header values"); DJsIO x = new DJsIO(true); if (!x.Accessed) return false; if (!xHeader.Write(ref x)) { x.Close(); return false; } xHeader.SetSize(xIO.Length - xSTFSStruct.BaseBlock); x.Position = 0x340; if (xSTFSStruct.ThisType == STFSType.Type0) x.Write((int)0xAD0E); else x.Write((int)0x971A); // Fills to bottom of header x.Position = x.Length; x.Write(new byte[(0x8E6 + (xSTFSStruct.BaseBlock - 0xA000))]); x.Position = 0x379; xWriteDescriptor(ref x); AddToLog("Writing Master hash"); long xLocale = 0; if (xSTFSStruct.xBlockCount <= Constants.BlockLevel[0]) xLocale = GenerateBaseOffset(0, TreeLevel.L0); else if (xSTFSStruct.xBlockCount <= Constants.BlockLevel[1]) xLocale = GenerateBaseOffset(0, TreeLevel.L1); else xLocale = GenerateBaseOffset(0, TreeLevel.L2); XTakeHash(ref xIO, xLocale, 0x381, 0x1000, ref x); AddToLog("Writing Header hash"); int xSize = 0; if (xSTFSStruct.BaseBlock == 0xA000) xSize = 0x9CBC; else xSize = 0xACBC; // b000 XTakeHash(0x344, 0x32C, xSize, ref x); AddToLog("Signing Header"); x.Position = 0x22C; byte[] xHash = SHA1Quick.ComputeHash(x.ReadBytes(0x118)); x.Position = 4; if (xParams.Type == PackageMagic.CON) { x.Write(xParams.Certificate); x.Write(ScrambleMethods.StockScramble(RSAQuick.SignatureGenerate(xParams.RSAKeys, xHash), true)); } else { x.Write(ScrambleMethods.DevScramble(RSAQuick.SignatureGenerate(xParams.RSAKeys, xHash))); x.Write(new byte[0x128]); } x.IsBigEndian = true; x.Position = 0; x.Write(((uint)xParams.Type)); x.Flush(); xHeader.xMagic = xParams.Type; // Writes header to Package just incase of a emergency close, the Package still attains original strucure AddToLog("Writing Header to Package"); xIO.Position = 0; xIO.Write(x.ReadStream()); xIO.Flush(); // Flush all the unused blocks to say they are written and now perm wif the new STFS Descriptor /*switched0.Clear(); switched1.Clear(); switched2 = false;*/ x.Close(); VariousFunctions.DeleteFile(x.FileNameLong); return true; }
/// <summary> /// Builds the package /// </summary> /// <param name="xParams"></param> /// <param name="ContentType"></param> /// <returns></returns> public bool Create(RSAParams xParams, PackageType ContentType) { if (BaseImage == null) { throw new Exception("No image"); } if (!xParams.Valid) { throw CryptoExcepts.ParamError; } if (ContentType != PackageType.HDDInstalledGame && ContentType != PackageType.OriginalXboxGame && ContentType != PackageType.GamesOnDemand && ContentType != PackageType.SocialTitle) { return(false); } if (xActive) { return(false); } xActive = true; DJsIO x = null; DJsIO h = null; try { string outlocale = OutLocation.Replace('\\', '/'); if (outlocale[outlocale.Length - 1] == '/') { outlocale = outlocale.Substring(0, outlocale.Length - 1); } outlocale += '/' + ((uint)ContentType).ToString("X8"); string DataFolder = outlocale + "/" + xHeader.TitleID.ToString("X8") + ".data"; if (!VariousFunctions.xCheckDirectory(OutLocation)) { throw IOExcepts.CreateError; } if (!VariousFunctions.xCheckDirectory(DataFolder)) { throw IOExcepts.CreateError; } uint xBlockCount = 0; uint xDataFileCount = 0; long xDataLength = 0; BaseImage.xIO.Position = BaseImage.baseoffset; while (BaseImage.xIO.Position < BaseImage.xIO.Length) { if ((xBlockCount % Constants.SVODBL[1]) == 0) { if (x != null) { for (int i = 0; i < 0xCB; i++) { x.Position = SVODFuncs.GenerateHashOffset((uint)(i * Constants.SVODBL[0]), 0); byte[] Data1 = SHA1Quick.ComputeHash(x.ReadBytes(0x1000)); x.Position = SVODFuncs.GenerateHashOffset((uint)(i * Constants.SVODBL[0]), 1); x.Write(Data1); } x.Flush(); xDataLength += x.Length; x.Close(); } x = new DJsIO(DataFolder + SVODFuncs.formatstring(xDataFileCount), DJFileMode.Create, true); xDataFileCount++; } x.Position = SVODFuncs.GenerateDataOffset(xBlockCount); byte[] Data = BaseImage.xIO.ReadBytes(0x1000); x.Write(Data); x.Position = SVODFuncs.GenerateHashOffset(xBlockCount, 0); x.Write(SHA1Quick.ComputeHash(Data)); xBlockCount++; } if (xBlockCount == 0) { x.Close(); return(xActive = false); } x.Flush(); xDataLength += x.Length; int lvlct = (int)((((xBlockCount % Constants.SVODBL[1]) - 1) / Constants.SVODBL[0]) + 1); for (int i = 0; i < lvlct; i++) { x.Position = SVODFuncs.GenerateHashOffset((uint)(i * Constants.SVODBL[0]), 0); byte[] Data1 = SHA1Quick.ComputeHash(x.ReadBytes(0x1000)); x.Position = SVODFuncs.GenerateHashOffset((uint)(i * Constants.SVODBL[0]), 1); x.Write(Data1); } x.Flush(); x.Close(); byte[] Hash = null; for (int i = (int)(xDataFileCount - 1); i >= 0; i--) { x = new DJsIO(DataFolder + SVODFuncs.formatstring((uint)i), DJFileMode.Open, true); if (Hash != null) { x.Position = 0xFF0; x.Write(Hash); x.Flush(); } x.Position = 0; Hash = SHA1Quick.ComputeHash(x.ReadBytes(0x1000)); } xHeader.DataFileSize = xDataLength; xHeader.DataFileCount = xDataFileCount; xHeader.xThisType = ContentType; h = new DJsIO(outlocale + "/" + xHeader.TitleID.ToString("X8"), DJFileMode.Create, true); xHeader.Write(ref h); h.SetLength(0xB000); h.Position = 0x340; h.Write((uint)0xAD0E); h.Position = 0x379; h.Write(new byte[] { 0x24, 5, 5, 0x11 }); h.Write(Hash); h.Write((byte)((Deviation == 0) ? 0 : 0x40)); h.WriteUInt24(xBlockCount); h.Write(Deviation, false); h.Position = 0x344; byte[] xHash = SHA1Quick.ComputeHash(h.ReadBytes((int)(h.Length - 0x344))); h.Position = 0x32C; h.Write(xHash); h.Flush(); h.Position = 0x22C; xHash = SHA1Quick.ComputeHash(h.ReadBytes(0x118)); h.Position = 4; if (xParams.Type == PackageMagic.CON) { h.Write(xParams.Certificate); h.Write(ScrambleMethods.StockScramble(RSAQuick.SignatureGenerate(xParams.RSAKeys, xHash), true)); } else { h.Write(ScrambleMethods.DevScramble(RSAQuick.SignatureGenerate(xParams.RSAKeys, xHash))); h.Write(new byte[0x128]); } h.IsBigEndian = true; h.Position = 0; h.Write(((uint)xParams.Type)); xHeader.xMagic = xParams.Type; h.Flush(); h.Close(); return(!(xActive = false)); } catch { if (x != null) { x.Close(); } if (h != null) { h.Close(); } return(xActive = false); } }
/// <summary> /// Create an STFS Package /// </summary> /// <param name="xSession"></param> /// <param name="xSigning"></param> /// <param name="xOutPath"></param> /// <param name="LogIn"></param> public STFSPackage(CreateSTFS xSession, RSAParams xSigning, out byte[] ret, LogRecord LogIn) { ret = null; xActive = true; if (!xSigning.Valid) throw CryptoExcepts.ParamError; if (xSession.xFileDirectory.Count == 0) throw new Exception(); ////try { //AddToLog("Setting Package variables"); xroot = new FolderEntry("", 0, 0xFFFF, 0xFFFF, this); if (xSession.HeaderData.ThisType == PackageType.GamesOnDemand || xSession.HeaderData.ThisType == PackageType.HDDInstalledGame || xSession.HeaderData.ThisType == PackageType.OriginalXboxGame || xSession.HeaderData.ThisType == PackageType.SocialTitle) throw STFSExcepts.Game; xLog = LogIn; xHeader = xSession.HeaderData; xSTFSStruct = new STFSDescriptor(xSession.STFSType, 0); xIO = new DJsIO(); var DirectoryBlockz = new List<BlockRecord>(); // switched2 = true; uint xcurblock = 0; for (ushort i = 0; i < xSession.GetDirectoryCount; i++) { DirectoryBlockz.Add(new BlockRecord()); DirectoryBlockz[DirectoryBlockz.Count - 1].ThisBlock = xcurblock++; } xFileBlocks = DirectoryBlockz.ToArray(); xWriteChain(xFileBlocks); xSTFSStruct.xDirectoryBlockCount = (ushort)xFileBlocks.Length; ushort xCurID = 0; xSession.xFolderDirectory.Sort(new Comparison<CFolderEntry>(sortpathct)); foreach (var x in xSession.xFolderDirectory) { ushort pointer = 0xFFFF; if (x.xthispath.xPathCount() > 1) pointer = xGetParentFolder(x.Path).EntryID; xFolderDirectory.Add(new FolderEntry(x.Name, 0, xCurID++, pointer, this)); xFolderDirectory[xFolderDirectory.Count - 1].xFixOffset(); } foreach (CFileEntry x in xSession.xFileDirectory) { ushort pointer = 0xFFFF; if (x.xthispath.xPathCount() > 1) pointer = xGetParentFolder(x.Path).EntryID; xFileDirectory.Add(new FileEntry(x.Name, (int)x.GetLength(), false, xCurID++, pointer, this)); var xAlloc = new List<BlockRecord>(); for (uint i = 0; i < x.BlockCount(); i++) { xAlloc.Add(new BlockRecord()); xAlloc[xAlloc.Count - 1].ThisBlock = xcurblock++; } xFileDirectory[xFileDirectory.Count - 1].xBlockCount = (uint)xAlloc.Count; xFileDirectory[xFileDirectory.Count - 1].xStartBlock = xAlloc[0].ThisBlock; xFileDirectory[xFileDirectory.Count - 1].xPackage = this; xFileDirectory[xFileDirectory.Count - 1].xFixOffset(); xWriteChain(xAlloc.ToArray()); } //AddToLog("Writing Entry Table"); DJsIO xent; if (!xEntriesToFile(out xent)) throw new Exception(); xWriteTo(ref xent, xFileBlocks); xent.Close(); //VariousFunctions.DeleteFile(xent.FileNameLong); //AddToLog("Writing Files"); uint curblck = xSession.GetDirectoryCount; foreach (var z in xSession.xFileDirectory) { var w = new List<BlockRecord>(); uint ct = z.BlockCount(); for (uint y = 0; y < ct; y++) { w.Add(new BlockRecord()); w[w.Count - 1].ThisBlock = curblck++; } DJsIO x = null; //try { x = new DJsIO(z.FileData, true); xWriteTo(ref x, w.ToArray()); } //catch { } if (x != null) x.Dispose(); } xWriteTables(); xWriteHeader(xSigning); ret = xIO.GetBytes(); xIO.Close(); //VariousFunctions.MoveFile(xIO.FileNameLong, xOutPath); xActive = false; } ////catch (Exception x) { xFileDirectory = null; xFolderDirectory = null; xIO.Dispose(); throw x; } }
/// <summary> /// Will only work wif your own KV, possibly strong signed /// </summary> /// <param name="xParams"></param> /// <returns></returns> public bool FixPackage(RSAParams xParams) { if (!xParams.Valid || !dataloaded || !ActiveCheck()) return false; return ((RehashPackage() && WriteHeader(xParams)) & !(xActive = false)); }
public byte[] RebuildPackageInMemory(RSAParams xParams) { if (!CanRead) { OpenAgain(); } var cstfs = new CreateSTFS(); cstfs.HeaderData.Description = xHeader.Description; cstfs.HeaderData.DeviceID = xHeader.DeviceID; cstfs.HeaderData.ProfileID = xHeader.ProfileID; cstfs.HeaderData.Publisher = xHeader.Publisher; cstfs.HeaderData.SaveConsoleID = xHeader.SaveConsoleID; cstfs.HeaderData.Title_Package = xHeader.Title_Package; cstfs.HeaderData.Title_Display = xHeader.Title_Display; cstfs.HeaderData.ThisType = xHeader.ThisType; cstfs.HeaderData.SaveGameID = xHeader.SaveGameID; cstfs.HeaderData.DataFileCount = xHeader.DataFileCount; cstfs.HeaderData.DataFileSize = xHeader.DataFileSize; cstfs.HeaderData.MediaID = xHeader.MediaID; cstfs.HeaderData.TitleID = xHeader.TitleID; cstfs.HeaderData.Version_ = xHeader.Version_; cstfs.HeaderData.Version_Base = xHeader.Version_Base; cstfs.HeaderData.MetaDataVersion = xHeader.MetaDataVersion; cstfs.HeaderData.Platform = xHeader.Platform; cstfs.HeaderData.SeasonNumber = xHeader.SeasonNumber; cstfs.STFSType = xSTFSStruct.ThisType; // Populate foreach (var y in xFolderDirectory) cstfs.AddFolder(y.GetPath()); foreach (var y in xFileDirectory) { cstfs.AddFile(y.ExtractBytes(true), y.GetPath()); } byte[] ret; var xreturn = new STFSPackage(cstfs, xParams, out ret, xLog); if (xreturn.ParseSuccess) { return ret; } xreturn.xIO.Close(); return null; }
static void Main(string[] args) { BassNet.Registration(user + "@" + domain + ".com", bKey); bool result; var mutex = new System.Threading.Mutex(true, "UniqueAppId", out result); if (!result) { MessageBox.Show("There's already another instance of " + APP_NAME + " running!\n\nYou should only have one instance running at any given time to avoid file access conflicts and possible crashes.\n\nProceed with caution.", APP_NAME, MessageBoxButtons.OK, MessageBoxIcon.Stop); } AppDomain.CurrentDomain.UnhandledException += CurrentDomain_UnhandledException; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); var binFolder = Application.StartupPath + "\\bin\\"; if (!Directory.Exists(binFolder)) { Directory.CreateDirectory(binFolder); } if (!File.Exists(Application.StartupPath + "\\bin\\KV.bin")) { MessageBox.Show("Required file 'KV.bin' was not found in the \bin subdirectory\n" + APP_NAME + " can't work without it ...", "Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Process.GetCurrentProcess().Kill(); } var kv = new RSAParams(Application.StartupPath + "\\bin\\KV.bin"); if (!kv.Valid) { MessageBox.Show("Required file 'KV.bin' was found in the \bin subdirectory but it is not valid\n" + APP_NAME + " can't work without it ...", "Critical Error", MessageBoxButtons.OK, MessageBoxIcon.Error); Process.GetCurrentProcess().Kill(); } var con = ""; var argument = args.Aggregate("", (current, arg) => current + " " + arg).ToLowerInvariant().Trim(); if (string.IsNullOrWhiteSpace(argument)) { Application.Run(new MainForm()); } else if (argument.Contains("-concreator")) { Application.Run(new CONCreator(Color.FromArgb(34, 169, 31), Color.White)); } else if (argument.Contains("-packcreator")) { Application.Run(new PackCreator(null, Color.FromArgb(34, 169, 31), Color.White)); } else if (argument.Contains("-quickpack")) { Application.Run(new QuickPackEditor(null, Color.FromArgb(34, 169, 31), Color.White)); } else if (argument.Contains("-quickdta")) { Application.Run(new QuickDTAEditor()); } else if (argument.Contains("-extractor")) { Application.Run(new BatchExtractor(Color.FromArgb(197, 34, 35), Color.White)); } else if (argument.Contains("-renamer")) { Application.Run(new BatchRenamer(Color.FromArgb(197, 34, 35), Color.White)); } else if (argument.Contains("-indexer")) { Application.Run(new FileIndexer(Color.FromArgb(197, 34, 35), Color.White)); } else if (argument.Contains("-manager")) { Application.Run(new SetlistManager(Color.FromArgb(197, 34, 35), Color.White)); } else if (argument.EndsWith(".setlist", StringComparison.Ordinal)) { var file = argument.Trim(); string setlist; if (File.Exists(file)) { setlist = file; } else if (File.Exists(Application.StartupPath + "\\setlist\\" + file)) { setlist = Application.StartupPath + "\\setlist\\" + file; } else { setlist = ""; } Application.Run(new SetlistManager(Color.FromArgb(197, 34, 35), Color.White, setlist)); } else if (argument.Contains("-event")) { Application.Run(new EventManager()); } else if (argument.Contains("-visualizer")) { try { var file = argument.Replace("-visualizer -", "").Replace("-visualizer", "").Trim(); if (file != "") { if (File.Exists(file)) { con = file; } } } catch { con = ""; } Application.Run(new Visualizer(Color.FromArgb(230, 215, 0), Color.White, con)); } else if (argument.Contains("-save")) { Application.Run(new SaveFileImageEditor(Color.FromArgb(230, 215, 0), Color.White)); } else if (argument.Contains("-analyzer")) { Application.Run(new SongAnalyzer("")); } else if (argument.Contains("-audioa")) { Application.Run(new AudioAnalyzer("")); } else if (argument.EndsWith(".mid", StringComparison.Ordinal)) { var midi = ""; var doclean = argument.Contains("-cleaner"); if (doclean) { argument = argument.Replace("-cleaner", "").Trim(); } if (File.Exists(argument)) { midi = argument; } else if (File.Exists(Application.StartupPath + "\\" + argument)) { midi = Application.StartupPath + "\\" + argument; } if (string.IsNullOrWhiteSpace(midi)) { Application.Run(new MainForm()); } else { if (doclean) { Application.Run(new MIDICleaner(midi, Color.FromArgb(230, 215, 0), Color.White)); } else { Application.Run(new MIDISelector(midi)); } } } else if (argument.Contains("-cleaner")) { Application.Run(new MIDICleaner("", Color.FromArgb(230, 215, 0), Color.White)); } else if (argument.Contains("-probundler")) { Application.Run(new ProUpgradeBundler(Color.FromArgb(230, 215, 0), Color.White)); } else if (argument.Contains("-artconverter")) { Application.Run(new AdvancedArtConverter("", Color.FromArgb(37, 89, 201), Color.White)); } else if (argument.Contains("-wii")) { try { var file = argument.Replace("-wii -", "").Trim(); con = ""; if (file != "") { if (Directory.Exists(file)) { con = file; } } } catch { con = ""; } Application.Run(new WiiConverter(Color.FromArgb(37, 89, 201), Color.White, con)); } else if (argument.Contains("-ps3")) { Application.Run(new PS3Converter(null, Color.FromArgb(37, 89, 201), Color.White)); } else if (argument.Contains("-phaseshift")) { Application.Run(new PhaseShiftConverter(Color.FromArgb(37, 89, 201), Color.White)); } else if (argument.Contains("-rba")) { Application.Run(new RBAConverter(Color.FromArgb(37, 89, 201), Color.White)); } else if (argument.Contains("-usb")) { Application.Run(new USBnator()); } else if (argument.Contains("-video")) { Application.Run(new VideoPreparer(Color.FromArgb(240, 104, 4), Color.White)); } else { try { if (VariousFunctions.ReadFileType(argument) == XboxFileType.STFS) { var xExplorer = new CONExplorer(Color.FromArgb(34, 169, 31), Color.White, true); xExplorer.LoadCON(argument); Application.Run(xExplorer); } } catch (Exception) { Application.Run(new MainForm()); } } GC.KeepAlive(mutex); }
private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e) { foreach (var file in FilesToConvert) { if (backgroundWorker1.CancellationPending) { return; } var replaced = 0; try { var xFile = new STFSPackage(file); if (!xFile.ParseSuccess) { ProblemFiles.Add(file); continue; } var xent = xFile.GetFile("/songs/songs.dta"); if (xent == null) { xFile.CloseIO(); ProblemFiles.Add(file); continue; } var dta1 = Application.StartupPath + "\\bin\\dta1.txt"; Tools.DeleteFile(dta1); if (!xent.Extract(dta1)) { xFile.CloseIO(); ProblemFiles.Add(file); continue; } var dta2 = Application.StartupPath + "\\bin\\dta2.txt"; Tools.DeleteFile(dta2); var sr = new StreamReader(dta1, Encoding.Default); var sw = new StreamWriter(dta2, false, Encoding.Default); while (sr.Peek() >= 0) { var line = sr.ReadLine(); if (string.IsNullOrEmpty(line.Trim())) { continue; } if (line.Contains(";ORIG_ID=")) { if (DoReverseBatch) { var id = line.Replace(";", "").Replace("ORIG_ID=", "").Trim(); sw.WriteLine(" ('song_id' " + id + ")"); sr.ReadLine();//skip the old song_id line line = sr.ReadLine(); TotalSongs++; replaced++; } else { sw.WriteLine(line); line = sr.ReadLine(); sw.WriteLine(line); line = sr.ReadLine(); } } else if (line.Contains("song_id") && !DoReverseBatch) { if (!Parser.IsNumericID(line)) { line = ";ORIG_ID=" + Parser.GetSongID(line); sw.WriteLine(line); line = " ('song_id' " + mMainForm.GetNumericID() + ")"; TotalSongs++; replaced++; } else { SkippedFiles.Add(file); } } if (!string.IsNullOrEmpty(line.Trim())) { sw.WriteLine(line); } } sr.Dispose(); sw.Dispose(); if (replaced == 0) //don't modify this CON file if nothing is edited in this DTA file { if (!SkippedFiles.Contains(file)) { SkippedFiles.Add(file); } xFile.CloseIO(); continue; } if (backgroundWorker1.CancellationPending) { xFile.CloseIO(); return; } if (!xent.Replace(dta2)) { xFile.CloseIO(); ProblemFiles.Add(file); continue; } Tools.DeleteFile(dta1); Tools.DeleteFile(dta2); xFile.Header.MakeAnonymous(); xFile.Header.ThisType = PackageType.SavedGame; var signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin"); xFile.RebuildPackage(signature); xFile.FlushPackage(signature); xFile.CloseIO(); Tools.UnlockCON(file); Tools.SignCON(file); xFile.CloseIO(); } catch (Exception) { ProblemFiles.Add(file); } } }
private void button1_Click(object sender, EventArgs e) { RSAParams xParams; string xOut = null; if (xtype == PackType.STFS) { xOut = VariousFunctions.GetUserFileLocale("Save to where?", "", false); if (xOut == null) { return; } } else { if (ximg == null) { MessageBox.Show("Please select an image"); return; } string y = VariousFunctions.GetUserFolderLocale("Select a save location"); if (y == null) { return; } xOut = y; } if (radioButton1.Checked) { xParams = xparent.PublicKV; } else if (radioButton2.Checked) { xParams = new RSAParams(StrongSigned.LIVE); } else { xParams = new RSAParams(StrongSigned.PIRS); } if (xtype == PackType.STFS) { LogRecord rec = new LogRecord(); STFSPackage xy = new STFSPackage(xsession, xParams, xOut, rec); PackageExplorer z = new PackageExplorer(xparent); z.set(ref xy); z.listBox4.Items.AddRange(rec.Log); this.Close(); z.Show(); } else { CreateSVOD z = new CreateSVOD(ximg, xOut, xhead); if (z.Create(xParams, (PackageType)comboBoxEx2.SelectedItem)) { MessageBox.Show("Completed successfully"); } else { MessageBox.Show("Unsuccessful build"); } } this.Dispose(); }
static void Main(string[] args) { string serverResponse = ""; string clientInstruction = ""; string[] message; int numberOfLines = 0; RSAParams rsaParams = new RSAParams(); // setting up link to server ACW_Interface_ServiceClient ACW_Client = new ACW_Interface_ServiceClient(); // read in first line - number of lines to follow numberOfLines = int.Parse(Console.ReadLine()); // read in following lines - instructions for server for (int i = 0; i < numberOfLines; i++) { // read in instruction clientInstruction = Console.ReadLine(); // split by space char message = clientInstruction.Split(new[] { ' ' }, 2); try { // HELLO message if (message[0].Equals("HELLO", StringComparison.CurrentCultureIgnoreCase)) { serverResponse = ACW_Client.HELLOMessage(message[1]); Console.Write(serverResponse + "\r\n"); } // PUBKEY message else if (message[0].Equals("PUBKEY", StringComparison.CurrentCultureIgnoreCase)) { serverResponse = ACW_Client.PUBKEYMessage(message[0]); Console.Write(serverResponse + "\r\n"); string[] responseSplit = serverResponse.Split(new string[] { Environment.NewLine }, StringSplitOptions.None); // update public key rsaParams.ExponentHEX = responseSplit[0]; rsaParams.ModulusHEX = responseSplit[1]; } // SORT message else if (message[0].Equals("SORT", StringComparison.CurrentCultureIgnoreCase)) { serverResponse = ACW_Client.SORTMessage(message[1]); Console.Write("Sorted values:\r\n" + serverResponse + "\r\n"); } // Encrpyt message else if (message[0].Equals("ENC", StringComparison.CurrentCultureIgnoreCase)) { // exit if not public key if (rsaParams.ExponentHEX == null && rsaParams.ModulusHEX == null) { Console.Write("No public key.\r\n"); } // encrypt message and send to server else { RSAParameters encryptParams = new RSAParameters(); encryptParams.Exponent = StringToByteArray(rsaParams.ExponentHEX); encryptParams.Modulus = StringToByteArray(rsaParams.ModulusHEX); RSACryptoServiceProvider RSA = new RSACryptoServiceProvider(); RSA.ImportParameters(encryptParams); //TestEmail(clientInstruction); byte[] asciiByteMessage = System.Text.Encoding.ASCII.GetBytes(message[1]); byte[] encryptedByteMessage; encryptedByteMessage = RSAEncrypt(asciiByteMessage, RSA.ExportParameters(false)); if (encryptedByteMessage != null) { ACW_Client.ENCMessage(encryptedByteMessage); Console.Write("Encrypted message sent.\r\n"); } } } // SHA1 message else if (message[0].Equals("SHA1", StringComparison.CurrentCultureIgnoreCase)) { serverResponse = ACW_Client.SHA1Message(message[1]); Console.Write(serverResponse + "\r\n"); } // SHA256 message else if (message[0].Equals("SHA256", StringComparison.CurrentCultureIgnoreCase)) { serverResponse = ACW_Client.SHA256Message(message[1]); Console.Write(serverResponse + "\r\n"); } // SIGN message else if (message[0].Equals("SIGN", StringComparison.CurrentCultureIgnoreCase)) { serverResponse = ACW_Client.SIGNMessage(message[1]); Console.Write(serverResponse + "\r\n"); } } catch (Exception e) { //TestEmail(clientInstruction); //SendEmail(e); Environment.Exit(0); } } //Console.ReadLine(); }
/// <summary> /// Builds the package /// </summary> /// <param name="xParams"></param> /// <param name="ContentType"></param> /// <returns></returns> public bool Create(RSAParams xParams, PackageType ContentType) { if (BaseImage == null) throw new Exception("No image"); if (!xParams.Valid) throw CryptoExcepts.ParamError; if (ContentType != PackageType.HDDInstalledGame && ContentType != PackageType.OriginalXboxGame && ContentType != PackageType.GamesOnDemand && ContentType != PackageType.SocialTitle) return false; if (xActive) return false; xActive = true; DJsIO x = null; DJsIO h = null; try { string outlocale = OutLocation.Replace('\\', '/'); if (outlocale[outlocale.Length - 1] == '/') outlocale = outlocale.Substring(0, outlocale.Length - 1); outlocale += '/' + ((uint)ContentType).ToString("X8"); string DataFolder = outlocale + "/" + xHeader.TitleID.ToString("X8") + ".data"; if (!VariousFunctions.xCheckDirectory(OutLocation)) throw IOExcepts.CreateError; if (!VariousFunctions.xCheckDirectory(DataFolder)) throw IOExcepts.CreateError; uint xBlockCount = 0; uint xDataFileCount = 0; long xDataLength = 0; BaseImage.xIO.Position = BaseImage.baseoffset; while (BaseImage.xIO.Position < BaseImage.xIO.Length) { if ((xBlockCount % Constants.SVODBL[1]) == 0) { if (x != null) { for (int i = 0; i < 0xCB; i++) { x.Position = SVODFuncs.GenerateHashOffset((uint)(i * Constants.SVODBL[0]), 0); byte[] Data1 = SHA1Quick.ComputeHash(x.ReadBytes(0x1000)); x.Position = SVODFuncs.GenerateHashOffset((uint)(i * Constants.SVODBL[0]), 1); x.Write(Data1); } x.Flush(); xDataLength += x.Length; x.Close(); } x = new DJsIO(DataFolder + SVODFuncs.formatstring(xDataFileCount), DJFileMode.Create, true); xDataFileCount++; } x.Position = SVODFuncs.GenerateDataOffset(xBlockCount); byte[] Data = BaseImage.xIO.ReadBytes(0x1000); x.Write(Data); x.Position = SVODFuncs.GenerateHashOffset(xBlockCount, 0); x.Write(SHA1Quick.ComputeHash(Data)); xBlockCount++; } if (xBlockCount == 0) { x.Close(); return (xActive = false); } x.Flush(); xDataLength += x.Length; int lvlct = (int)((((xBlockCount % Constants.SVODBL[1]) - 1) / Constants.SVODBL[0]) + 1); for (int i = 0; i < lvlct; i++) { x.Position = SVODFuncs.GenerateHashOffset((uint)(i * Constants.SVODBL[0]), 0); byte[] Data1 = SHA1Quick.ComputeHash(x.ReadBytes(0x1000)); x.Position = SVODFuncs.GenerateHashOffset((uint)(i * Constants.SVODBL[0]), 1); x.Write(Data1); } x.Flush(); x.Close(); byte[] Hash = null; for (int i = (int)(xDataFileCount - 1); i >= 0; i--) { x = new DJsIO(DataFolder + SVODFuncs.formatstring((uint)i), DJFileMode.Open, true); if (Hash != null) { x.Position = 0xFF0; x.Write(Hash); x.Flush(); } x.Position = 0; Hash = SHA1Quick.ComputeHash(x.ReadBytes(0x1000)); } xHeader.DataFileSize = xDataLength; xHeader.DataFileCount = xDataFileCount; xHeader.xThisType = ContentType; h = new DJsIO(outlocale + "/" + xHeader.TitleID.ToString("X8"), DJFileMode.Create, true); xHeader.Write(ref h); h.SetLength(0xB000); h.Position = 0x340; h.Write((uint)0xAD0E); h.Position = 0x379; h.Write(new byte[] { 0x24, 5, 5, 0x11 }); h.Write(Hash); h.Write((byte)((Deviation == 0) ? 0 : 0x40)); h.WriteUInt24(xBlockCount); h.Write(Deviation, false); h.Position = 0x344; byte[] xHash = SHA1Quick.ComputeHash(h.ReadBytes((int)(h.Length - 0x344))); h.Position = 0x32C; h.Write(xHash); h.Flush(); h.Position = 0x22C; xHash = SHA1Quick.ComputeHash(h.ReadBytes(0x118)); h.Position = 4; if (xParams.Type == PackageMagic.CON) { h.Write(xParams.Certificate); h.Write(ScrambleMethods.StockScramble(RSAQuick.SignatureGenerate(xParams.RSAKeys, xHash), true)); } else { h.Write(ScrambleMethods.DevScramble(RSAQuick.SignatureGenerate(xParams.RSAKeys, xHash))); h.Write(new byte[0x128]); } h.IsBigEndian = true; h.Position = 0; h.Write(((uint)xParams.Type)); xHeader.xMagic = xParams.Type; h.Flush(); h.Close(); return !(xActive = false); } catch { if (x != null) x.Close(); if (h != null) h.Close(); return (xActive = false); } }
/// <summary> /// Create an STFS Package /// </summary> /// <param name="xSession"></param> /// <param name="xSigning"></param> /// <param name="xOutPath"></param> /// <param name="LogIn"></param> public STFSPackage(CreateSTFS xSession, RSAParams xSigning, string xOutPath, LogRecord LogIn) { xActive = true; if (!xSigning.Valid) throw CryptoExcepts.ParamError; if (xSession.xFileDirectory.Count == 0) throw new Exception(); try { AddToLog("Setting Package variables"); new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(System.DLLIdentify.PrivilegeCheck)).Start(System.Threading.Thread.CurrentThread); xroot = new FolderEntry("", 0, 0xFFFF, 0xFFFF, this); if (xSession.HeaderData.ThisType == PackageType.ThematicSkin) { DJsIO x1 = new DJsIO(true); DJsIO x2 = new DJsIO(true); x1.Write((int)xSession.ThemeSettings.StyleType); x1.Flush(); x1.Close(); if (!xSession.AddFile(x1.FileNameLong, "DashStyle")) throw STFSExcepts.ThemeError; x2.Write("SphereColor=" + ((byte)xSession.ThemeSettings.Sphere).ToString().PadRight(2, '\0')); x2.Write(new byte[] { 0xD, 0xA }); x2.Write("AvatarLightingDirectional=" + xSession.ThemeSettings.AvatarLightingDirectional0.ToString("#0.0") + "," + xSession.ThemeSettings.AvatarLightingDirectional1.ToString("#0.0000") + "," + xSession.ThemeSettings.AvatarLightingDirectional2.ToString("#0.0") + ",0x" + xSession.ThemeSettings.AvatarLightingDirectional3.ToString("X")); x2.Write(new byte[] { 0xD, 0xA }); x2.Write("AvatarLightingAmbient=0x" + xSession.ThemeSettings.AvatarLightingAmbient.ToString("X")); x2.Write(new byte[] { 0xD, 0xA }); x2.Flush(); x2.Close(); if (!xSession.AddFile(x2.FileNameLong, "parameters.ini")) throw STFSExcepts.ThemeError; } else if (xSession.HeaderData.ThisType == PackageType.GamesOnDemand || xSession.HeaderData.ThisType == PackageType.HDDInstalledGame || xSession.HeaderData.ThisType == PackageType.OriginalXboxGame || xSession.HeaderData.ThisType == PackageType.SocialTitle) throw STFSExcepts.Game; xLog = LogIn; xHeader = xSession.HeaderData; xSTFSStruct = new STFSDescriptor(xSession.STFSType, 0); xIO = new DJsIO(true); List<BlockRecord> DirectoryBlockz = new List<BlockRecord>(); // switched2 = true; uint xcurblock = 0; for (ushort i = 0; i < xSession.GetDirectoryCount; i++) { DirectoryBlockz.Add(new BlockRecord()); DirectoryBlockz[DirectoryBlockz.Count - 1].ThisBlock = xcurblock++; /*if (!switched0.Contains((int)(xcurblock / Constants.BlockLevel[0]))) switched0.Add((int)(xcurblock / Constants.BlockLevel[0])); if (!switched1.Contains((int)(xcurblock / Constants.BlockLevel[1]))) switched1.Add((int)(xcurblock / Constants.BlockLevel[1]));*/ } xFileBlocks = DirectoryBlockz.ToArray(); xWriteChain(xFileBlocks); xSTFSStruct.xDirectoryBlockCount = (ushort)xFileBlocks.Length; ushort xCurID = 0; xSession.xFolderDirectory.Sort(new Comparison<CFolderEntry>(sortpathct)); foreach (CFolderEntry x in xSession.xFolderDirectory) { ushort pointer = 0xFFFF; if (x.xthispath.xPathCount() > 1) pointer = xGetParentFolder(x.Path).EntryID; xFolderDirectory.Add(new FolderEntry(x.Name, 0, xCurID++, pointer, this)); xFolderDirectory[xFolderDirectory.Count - 1].xFixOffset(); } foreach (CFileEntry x in xSession.xFileDirectory) { ushort pointer = 0xFFFF; if (x.xthispath.xPathCount() > 1) pointer = xGetParentFolder(x.Path).EntryID; xFileDirectory.Add(new FileEntry(x.Name, (int)x.GetLength(), false,xCurID++, pointer, this)); List<BlockRecord> xAlloc = new List<BlockRecord>(); for (uint i = 0; i < x.BlockCount(); i++) { xAlloc.Add(new BlockRecord()); xAlloc[xAlloc.Count - 1].ThisBlock = xcurblock++; /*if (!switched0.Contains((int)(xcurblock / Constants.BlockLevel[0]))) switched0.Add((int)(xcurblock / Constants.BlockLevel[0])); if (!switched1.Contains((int)(xcurblock / Constants.BlockLevel[1]))) switched1.Add((int)(xcurblock / Constants.BlockLevel[1]));*/ } xFileDirectory[xFileDirectory.Count - 1].xBlockCount = (uint)xAlloc.Count; xFileDirectory[xFileDirectory.Count - 1].xStartBlock = xAlloc[0].ThisBlock; xFileDirectory[xFileDirectory.Count - 1].xPackage = this; xFileDirectory[xFileDirectory.Count - 1].xFixOffset(); xWriteChain(xAlloc.ToArray()); } AddToLog("Writing Entry Table"); DJsIO xent; if (!xEntriesToFile(out xent)) throw new Exception(); xWriteTo(ref xent, xFileBlocks); xent.Close(); VariousFunctions.DeleteFile(xent.FileNameLong); AddToLog("Writing Files"); uint curblck = xSession.GetDirectoryCount; foreach (CFileEntry z in xSession.xFileDirectory) { List<BlockRecord> w = new List<BlockRecord>(); uint ct = z.BlockCount(); for (uint y = 0; y < ct; y++) { w.Add(new BlockRecord()); w[w.Count - 1].ThisBlock = curblck++; } DJsIO x = null; try { x = new DJsIO(z.FileLocale, DJFileMode.Open, true); xWriteTo(ref x, w.ToArray()); } catch { } if (x != null) x.Dispose(); } xWriteTables(); xWriteHeader(xSigning); xIO.Close(); VariousFunctions.MoveFile(xIO.FileNameLong, xOutPath); xIO = new DJsIO(xOutPath, DJFileMode.Open, true); xActive = false; } catch (Exception x) { xFileDirectory = null; xFolderDirectory = null; xIO.Dispose(); throw x; } }
private void button1_Click(object sender, EventArgs e) { RSAParams xParams; string xOut = null; if (xtype == PackType.STFS) { xOut = VariousFunctions.GetUserFileLocale("Save to where?", "", false); if (xOut == null) return; } else { if (ximg == null) { MessageBox.Show("Please select an image"); return; } string y = VariousFunctions.GetUserFolderLocale("Select a save location"); if (y == null) return; xOut = y; } if (radioButton1.Checked) xParams = xparent.PublicKV; else if (radioButton2.Checked) xParams = new RSAParams(StrongSigned.LIVE); else xParams = new RSAParams(StrongSigned.PIRS); if (xtype == PackType.STFS) { LogRecord rec = new LogRecord(); STFSPackage xy = new STFSPackage(xsession, xParams, xOut, rec); PackageExplorer z = new PackageExplorer(xparent); z.set(ref xy); z.listBox4.Items.AddRange(rec.Log); this.Close(); z.Show(); } else { CreateSVOD z = new CreateSVOD(ximg, xOut, xhead); if (z.Create(xParams, (PackageType)comboBoxEx2.SelectedItem)) MessageBox.Show("Completed successfully"); else MessageBox.Show("Unsuccessful build"); } this.Dispose(); }
/// <summary> /// Writes Tables and updates Header /// </summary> /// <param name="xParams"></param> /// <returns></returns> public bool FlushPackage(RSAParams xParams) { if (!ActiveCheck()) return false; try { bool xsucceeded = (xWriteTables() && xWriteHeader(xParams)); xActive = false; return xsucceeded; } catch (Exception x) { xActive = false; throw x; } }
void b2() { listView2.Items.Clear(); Log("Writing to package"); RSAParams x = null; if (radioButton1.Checked) x = KV; else if (radioButton2.Checked) x = new RSAParams(StrongSigned.LIVE); else if (radioButton3.Checked) x = new RSAParams(StrongSigned.PIRS); if (checkBoxX4.Checked) xPackage.FlushPackage(x); else xPackage.UpdateHeader(x); Log("Package fixed"); }
/// <summary> /// Rebuilds the package using package creation /// </summary> /// <param name="xParams"></param> /// <returns></returns> public bool RebuildPackage(RSAParams xParams) { if (!ActiveCheck()) return false; if (!xParams.Valid) return (xActive = false); CreateSTFS x = new CreateSTFS(); x.HeaderData = xHeader; x.STFSType = xSTFSStruct.ThisType; // Populate foreach (FolderEntry y in xFolderDirectory) x.AddFolder(y.GetPath()); foreach (FileEntry y in xFileDirectory) { DJsIO io = y.xGetTempIO(true); if (io != null && io.Accessed) { io.Close(); x.AddFile(io.FileNameLong, y.GetPath()); } } STFSPackage xreturn = new STFSPackage(x, xParams, VariousFunctions.GetTempFileLocale(), xLog); if (xreturn.ParseSuccess) { xIO.Close(); xreturn.xIO.Close(); if (!VariousFunctions.MoveFile(xreturn.xIO.FileNameLong, xIO.FileNameLong)) return (xActive = false); xreturn.xIO = xIO; SetSamePackage(ref xreturn); xIO.OpenAgain(); return !(xActive = false); } xreturn.xIO.Close(); VariousFunctions.DeleteFile(xreturn.xIO.FileNameLong); return (xActive = false); }
private void backgroundWorker1_DoWork(object sender, System.ComponentModel.DoWorkEventArgs e) { if (!File.Exists(orig_con)) { Log("CON file " + Path.GetFileName(orig_con) + " seems to have been deleted, can't continue without it"); return; } var BundleFile = orig_con + " (bundled)"; Tools.DeleteFile(BundleFile); File.Copy(orig_con, BundleFile); var xPackage = new STFSPackage(BundleFile); if (!xPackage.ParseSuccess) { Log("There was an error parsing CON file to bundle"); xPackage.CloseIO(); return; } var xent = xPackage.GetFile("/songs/songs.dta"); if (xent != null) { if (xent.Replace(newDTA)) { Log("Bundled DTA file successfully"); } } xent = xPackage.GetFile("/songs/" + Path.GetFileNameWithoutExtension(orig_midi) + "/" + Path.GetFileName(orig_midi)); if (xent != null) { if (xent.Replace(newMIDI)) { Log("Bundled MIDI file successfully"); } } xPackage.Header.MakeAnonymous(); xPackage.Header.ThisType = PackageType.SavedGame; var success = false; try { Log("Rebuilding CON file ... this might take a little while"); signature = new RSAParams(Application.StartupPath + "\\bin\\KV.bin"); if (ChangeGameID.Checked) { xPackage.Header.TitleID = 0x45410914; xPackage.Header.Title_Package = "Rock Band 3"; xPackage.Header.ContentImageBinary = Resources.RB3.ImageToBytes(ImageFormat.Png); } xPackage.RebuildPackage(signature); xPackage.FlushPackage(signature); xPackage.CloseIO(); success = true; } catch (Exception ex) { Log("There was an error: " + ex.Message); xPackage.CloseIO(); } if (success) { Log("Trying to unlock CON file"); if (Tools.UnlockCON(BundleFile)) { Log("Unlocked CON file successfully"); } else { Log("Error unlocking CON file"); success = false; } } if (success) { Log("Trying to sign CON file"); if (Tools.SignCON(BundleFile)) { Log("CON file signed successfully"); } else { Log("Error signing CON file"); success = false; } } Log(success ? "Your files were bundled successfully!" : "Something went wrong along the way, sorry!"); if (!cleanUpAfterBundlingFiles.Checked) { return; } Log("Cleaning up"); CleanUp(); }
/* Structure Fixing */ /// <summary> /// Updates the information in the header /// </summary> /// <returns></returns> public bool UpdateHeader(RSAParams xParams) { if (!ActiveCheck()) return false; try { bool xSuccess = xWriteHeader(xParams); xActive = false; return xSuccess; } catch (Exception x) { xActive = false; throw x; } }