private void addImageToolStripMenuItem_Click(object sender, EventArgs e) { DJsIO xIO = new DJsIO(DJFileMode.Open, "Open a PNG", "PNG File|*.png", true); if (!xIO.Accessed) return; if (xIO.Length > 0x4000) { MessageBox.Show("Error: Image is too big"); return; } byte[] x = xIO.ReadStream(); try { Image y = x.BytesToImage(); pictureBox1.Image = y; } catch (Exception z) { MessageBox.Show(z.Message); return; } HeaderInfo.ContentImageBinary = x; }
/// <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; }
internal bool xUpdate() { try { int xsize = xpairs.Count * 0x10; if (Size > xsize) { new FreeSpaceEntry(xRef, xOffset + xsize, Size - xsize); xRef.PatchFree(); } else if (Size < xsize) { int off = xRef.AllocateData(xsize); if (off == -1) return false; new FreeSpaceEntry(xRef, xOffset, Size); xRef.PatchFree(); xOffset = off; } DJsIO xbuff = new DJsIO(new byte[xsize], true); xbuff.Position = 0; foreach (SyncPair x in xpairs) { xbuff.Write(x.ID); xbuff.Write(x.Sync); } xbuff.Flush(); xRef.xIO.Position = Offset; xRef.xIO.Write(xbuff.ReadStream()); xRef.xIO.Flush(); if (xsize > xSize) xRef.UpdateHeader(); xSize = xsize; return true; } catch { return false; } }
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; } }
bool xEncrypt(ref DJsIO xNewPayload) { try { if (!xSuccess) return false; if (xIsLive) { byte[] xService = (ThisType == AccountType.Stock ? new byte[] { 0x50, 0x52, 0x4F, 0x44 } : // PROD new byte[] { 0x50, 0x41, 0x53, 0x54 }); // PART xNewPayload.Position = 0x34; xNewPayload.Write(xService); xNewPayload.Flush(); } List<byte> xReturn = new List<byte>(); byte[] xConfounder = xRC4.NewConfounder(8); byte[] NewPay = xNewPayload.ReadStream(); xNewPayload.Dispose(); byte[] xHeaderKey = xComputeHeaderKey(xConfounder, NewPay); xRC4.KeyBinary = xComputeRC4Key(xHeaderKey); xReturn.AddRange(xHeaderKey); xReturn.AddRange(xRC4.KerberosEncrypt(ref xConfounder, ref NewPay)); IO.Position = 0; IO.Write(xReturn.ToArray()); IO.Flush(); return true; } catch { return false; } }
/// <summary> /// Initializes an instance /// </summary> /// <param name="xAcc"></param> /// <param name="xType"></param> /// <param name="CreateBackup"></param> public UserAccount(DJsIO xAcc, AccountType xType, bool CreateBackup) { if (xAcc.Length != 404 || !Enum.IsDefined(typeof(AccountType), xType)) return; IO = xAcc; xHS = new HMACSHA1(); ThisType = xType; DJsIO xfill; if (xDecrypt(out xfill)) { if (CreateBackup) { xBackup = new DJsIO(true); xBackup.Position = 0; xBackup.Write(IO.ReadStream()); } xfill.Position = 0; if (((xfill.ReadByte() >> 5) & 1) == 1) { xIsLive = true; xfill.Position = 0x28; xXUID = xfill.ReadUInt64(); } xSuccess = true; } }