コード例 #1
0
        public bool AddFile(string FileName, byte[] fileData, AddType xType)
        {
            if (!VariousFunctions.IsValidXboxName(FileName))
                return false;

            if (xDrive.ActiveCheck())
                return false;

            DJsIO xIOIn = null;
            byte[] b = fileData;
            xIOIn = new DJsIO(b, true);

            try
            {
                FATXReadContents xconts = xRead();
                foreach (FATXFileEntry x in xconts.xfiles)
                {
                    if (string.Compare(x.Name, FileName, true) == 0)
                    {
                        bool xreturn = false;
                        if (xType == AddType.NoOverWrite)
                        {
                            xIOIn.Close();
                            return (xDrive.xActive = false);
                        }
                        else if (xType == AddType.Inject)
                        {
                            xreturn = x.xInject(xIOIn);
                        }
                        else
                        {
                            xreturn = x.xReplace(xIOIn);
                        }
                        xIOIn.Close();
                        return (xreturn & !(xDrive.xActive = false));
                    }
                }
                uint xnew = 0;
                long xpos = GetNewEntryPos(out xnew);
                if (xpos == -1)
                    return (xDrive.xActive = false);

                var count = xIOIn.BlockCountFATX(Partition);

                uint[] blocks = Partition.xTable.GetNewBlockChain(count, xnew + 1);

                if (blocks.Length == 0)
                    return (xDrive.xActive = false);

                if (!Partition.WriteFile(blocks, ref xIOIn))
                    return (xDrive.xActive = false);

                FATXEntry y = new FATXEntry(this,
                    FileName,
                    blocks[0], (int)xIOIn.Length,
                    xpos, false, ref xDrive);

                if (!y.xWriteEntry())
                    return (xDrive.xActive = false);

                if (xnew > 0)
                {
                    var filebx = Partition.xTable.GetBlocks(xStartBlock);
                    List<uint> fileblocks = new List<uint>(filebx);

                    fileblocks.Add(xnew);

                    uint[] xtemp = fileblocks.ToArray();

                    if (!Partition.xTable.WriteChain(ref xtemp))
                        return (xDrive.xActive = false);
                }

                if (!Partition.xTable.WriteChain(ref blocks))
                    return (xDrive.xActive = false);

                if (Partition.WriteAllocTable())
                    return !(xDrive.xActive = false);

                return (xDrive.xActive = false);
            }
            catch { xIOIn.Close(); return (xDrive.xActive = false); }
        }
コード例 #2
0
        public byte[] xExtractBytes()
        {
            byte[] ret = null;

            var xIO = new DJsIO(true);
            try
            {
                if (xExtract(ref xIO))
                {
                    xIO.Position = 0;
                    ret = xIO.GetBytes();
                }
            }
            catch
            {
                ret = null;
            }
            xIO.Close();

            return ret;
        }
コード例 #3
0
 internal bool IncreaseXDBFCount()
 {
     DJsIO xtemp = new DJsIO(true);
     try
     {
         xtemp.Position = (HeaderSize + (0xFF * 0x12));
         xIO.Position = HeaderSize;
         int len = (int)(xIO.Length - xIO.Position);
         for (int i = 0; i < len; i++)
             xtemp.Write(xIO.ReadByte());
         xtemp.Position = 0;
         xtemp.Write((uint)AllMagic.XDBF);
         xtemp.Write((int)0x10000);
         xEntryMax += 0xFF;
         xtemp.Write((int)xEntryMax);
         xtemp.Write((int)xEntryCurrent);
         xtemp.Write((int)xFreeCurrent);
         xtemp.Write((int)xFreeMax);
         List<XDBFEntry> xEntries = GetEntries();
         foreach (XDBFEntry x in xEntries)
         {
             xtemp.Write((ushort)x.NS);
             xtemp.Write(x.ID);
             xtemp.Write(x.xOffset);
             xtemp.Write(x.Size);
         }
         xtemp.Write(new byte[0x12 * (xEntryMax - xEntries.Count)]);
         foreach (FreeSpaceEntry x in xFreeEnts)
         {
             if (x.Size != 0)
             {
                 xtemp.Write(x.offset);
                 xtemp.Write(x.Size);
             }
         }
         int xdatasize = (int)(xtemp.Length - HeaderSize);
         xtemp.Write(xdatasize);
         xtemp.Write((int)(((-1) - xdatasize)));
         xtemp.Write(new byte[0x8 * (xFreeMax - (xFreeEnts.Count + 1))]);
         xtemp.Flush();
         xtemp.Close();
         xIO.Close();
         VariousFunctions.MoveFile(xtemp.FileNameLong, xIO.FileNameLong);
         xIO = new DJsIO(xIO.FileNameLong, DJFileMode.Open, true);
         return true;
     }
     catch { xtemp.Dispose(true); return false; }
 }
コード例 #4
0
ファイル: Create.cs プロジェクト: VictorOverX/X360
 /// <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);
     }
 }
コード例 #5
0
ファイル: Entries.cs プロジェクト: VictorOverX/X360
 /// <summary>
 /// Adds a file
 /// </summary>
 /// <param name="FileName"></param>
 /// <param name="FileLocation"></param>
 /// <param name="xType"></param>
 /// <returns></returns>
 public bool AddFile(string FileName, string FileLocation, AddType xType)
 {
     FileName.IsValidXboxName();
     if (xDrive.ActiveCheck())
         return false;
     DJsIO xIOIn = null;
     try { xIOIn = new DJsIO(FileLocation, DJFileMode.Open, true); }
     catch { return (xDrive.xActive = false); }
     try
     {
         FATXReadContents xconts = xRead();
         foreach (FATXFileEntry x in xconts.xfiles)
         {
             if (x.Name == FileName)
             {
                 bool xreturn = false;
                 if (xType == AddType.NoOverWrite)
                      return (xDrive.xActive = false);
                 else if (xType == AddType.Inject)
                     xreturn = x.xInject(xIOIn);
                 else xreturn = x.xReplace(xIOIn);
                 return (xreturn & !(xDrive.xActive = false));
             }
         }
         uint xnew = 0;
         long xpos = GetNewEntryPos(out xnew);
         if (xpos == -1)
             return (xDrive.xActive = false);
         uint[] blocks = Partition.xTable.GetNewBlockChain(xIOIn.BlockCountFATX(Partition), xnew + 1);
         if (blocks.Length == 0)
             return (xDrive.xActive = false);
         if (!Partition.WriteFile(blocks, ref xIOIn))
             return (xDrive.xActive = false);
         FATXEntry y = new FATXEntry(FileName, blocks[0], (int)xIOIn.Length, xpos, false, ref xDrive);
         if (!y.xWriteEntry())
             return (xDrive.xActive = false);
         if (xnew > 0)
         {
             List<uint> fileblocks = new List<uint>(Partition.xTable.GetBlocks(xStartBlock));
             fileblocks.Add(xnew);
             uint[] xtemp = fileblocks.ToArray();
             if (!Partition.xTable.WriteChain(ref xtemp))
                 return (xDrive.xActive = false);
         }
         if (!Partition.xTable.WriteChain(ref blocks))
             return (xDrive.xActive = false);
         if (Partition.WriteAllocTable())
             return !(xDrive.xActive = false);
         return (xDrive.xActive = false);
     }
     catch { xIOIn.Close(); return (xDrive.xActive = false); }
 }
コード例 #6
0
ファイル: PackageExplorer.cs プロジェクト: VictorOverX/X360
 private void addFileToolStripMenuItem_Click(object sender, EventArgs e)
 {
     DJsIO x = new DJsIO(DJFileMode.Open, "Open", "", true);
     if (!x.Accessed)
         return;
     Renamer rename = new Renamer(x.FileNameShort, true);
     if (rename.ShowDialog() != DialogResult.OK)
     {
         x.Close();
         return;
     }
     xPackage.MakeFile(rename.FileName, x, ((FolderEntry)advTree1.SelectedNode.DataKey).EntryID, AddType.NoOverWrite);
     Log("Done adding");
 }
コード例 #7
0
 /// <summary>
 /// Extracts entry to a location
 /// </summary>
 /// <param name="FileOut"></param>
 /// <returns></returns>
 public bool Extract(string FileOut)
 {
     if (!xPackage.ActiveCheck())
         return false;
     bool xReturn = false;
     DJsIO xIO = new DJsIO(true);
     try
     {
         xReturn = xExtract(xIO);
         xIO.Close();
         if (xReturn)
         {
             if (!VariousFunctions.MoveFile(xIO.FileNameLong, FileOut))
                 throw new Exception();
         }
     }
     catch
     {
         xReturn = false;
         xIO.Close();
     }
     VariousFunctions.DeleteFile(xIO.FileNameLong);
     xPackage.xActive = false;
     return xReturn;
 }
コード例 #8
0
ファイル: Entries.cs プロジェクト: VictorOverX/X360
 internal bool xInject(DJsIO xIOIn)
 {
     List<uint> blocks = new List<uint>(Partition.xTable.GetBlocks(xStartBlock));
     if (blocks.Count == 0)
         throw new Exception();
     uint xct = xIOIn.BlockCountFATX(Partition);
     if (blocks.Count < xct)
     {
         uint[] blocks2 = Partition.xTable.GetNewBlockChain((uint)(xct - blocks.Count), 1);
         if (blocks2.Length == 0)
             throw new Exception();
         blocks.AddRange(blocks2);
         uint[] x = blocks.ToArray();
         if (!Partition.xTable.WriteChain(ref x))
             throw new Exception();
     }
     else if (blocks.Count > xct)
     {
         uint[] xUnneeded = new uint[blocks.Count - xct];
         for (uint i = xct; i < blocks.Count; i++)
         {
             xUnneeded[(int)i] = i;
             blocks.RemoveAt((int)i--);
         }
         if (!Partition.xTable.DC(ref xUnneeded))
             throw new Exception();
     }
     xIOIn.Position = 0;
     xDrive.GetIO();
     foreach (uint i in blocks)
     {
         xDrive.xIO.Position = Partition.BlockToOffset(i);
         xDrive.xIO.Write(xIOIn.ReadBytes(Partition.xBlockSize));
     }
     if ((xSize == 0 || (uint)(((xSize - 1) / Partition.xBlockSize) + 1) != xct) &&
         !Partition.WriteAllocTable())
         throw new Exception();
     xSize = (int)xIOIn.Length;
     xIOIn.Close();
     return xWriteEntry();
 }
コード例 #9
0
 /// <summary>
 /// Verifies the Header signature
 /// </summary>
 /// <param name="xDev"></param>
 /// <returns></returns>
 Verified VerifySignature(bool xDev)
 {
     try
     {
         AddToLog("Verifying Signature");
         RSAParameters xRSAKeyz = new RSAParameters();
         short xSigSpot = 0;
         switch (xHeader.Magic)
         {
             case PackageMagic.CON: // signature is the same way for both Dev and Stock
                 {
                     xSigSpot = 0x1AC;
                     xIO.Position = 0x28;
                     xRSAKeyz.Exponent = xIO.ReadBytes(4);
                     xRSAKeyz.Modulus = ScrambleMethods.StockScramble(xIO.ReadBytes(0x80), false);
                 }
                 break;
             case PackageMagic.LIVE:
                 {
                     xSigSpot = 4;
                     if (!xDev)
                     {
                         xRSAKeyz.Exponent = new byte[] { 0, 1, 0, 1 };
                         xRSAKeyz.Modulus = global::X360.Properties.Resources.XK1;
                     }
                     else
                     {
                         xRSAKeyz.Exponent = new byte[] { 0, 0, 0, 3 };
                         DJsIO xLK = new DJsIO(global::X360.Properties.Resources.XK4, true);
                         xRSAKeyz.Modulus = xLK.ReadBytes(0x100);
                         xLK.Close();
                     }
                 }
                 break;
             case PackageMagic.PIRS:
                 {
                     xSigSpot = 4;
                     if (!xDev)
                     {
                         xRSAKeyz.Exponent = new byte[] { 0, 0, 0, 3 };
                         xRSAKeyz.Modulus = global::X360.Properties.Resources.XK2;
                     }
                     else
                     {
                         xRSAKeyz.Exponent = new byte[] { 0, 0, 0, 3 };
                         DJsIO xPK = new DJsIO(global::X360.Properties.Resources.XK5, true);
                         xRSAKeyz.Modulus = xPK.ReadBytes(0x100);
                         xPK.Close();
                     }
                 }
                 break;
         }
         xIO.Position = xSigSpot;
         byte[] xSiggy = ScrambleMethods.StockScramble(xIO.ReadBytes(xRSAKeyz.Modulus.Length), true);
         xIO.Position = 0x22C;
         byte[] xHeadr = xIO.ReadBytes(0x118);
         return new Verified(ItemType.Signature, RSAQuick.SignatureVerify(xRSAKeyz, SHA1Quick.ComputeHash(xHeadr), xSiggy), 0x22C, xSigSpot);
     }
     catch { throw CryptoExcepts.CryptoVeri; }
 }
コード例 #10
0
 internal DJsIO xGetTempIO(bool BigEndian)
 {
     if (!Opened && !ReadBlocks())
         return null;
     DJsIO xIO = new DJsIO(BigEndian);
     if (!xExtract(xIO))
     {
         xIO.Close();
         VariousFunctions.DeleteFile(xIO.FileNameLong);
         xIO = null;
     }
     ClearBlocks();
     return xIO;
 }
コード例 #11
0
 /// <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;
 }
コード例 #12
0
 /// <summary>
 /// Returns a real time STFS file stream
 /// </summary>
 /// <param name="MakeCopy"></param>
 /// <param name="BigEndian"></param>
 /// <returns></returns>
 public DJsIO GrabSTFSStream(bool MakeCopy, bool BigEndian)
 {
     try
     {
         if (RealStream != null)
             return RealStream;
         if (!xPackage.ActiveCheck())
             return null;
         if (MakeCopy)
         {
             DJsIO xtemp = new DJsIO(true);
             if (!xExtract(xtemp))
             {
                 xtemp.Close();
                 VariousFunctions.DeleteFile(xtemp.FileNameLong);
                 return null;
             }
             bool success = xReplace(xtemp);
             xtemp.Close();
             VariousFunctions.DeleteFile(xtemp.FileNameLong);
             if (!success)
                 return null;
         }
         if (!Opened && !ReadBlocks())
             return null;
         return (RealStream = new STFSStreamIO(this, BigEndian));
     }
     catch { RealStream = null; xPackage.xActive = false; return null; }
 }
コード例 #13
0
 /// <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; }
 }
コード例 #14
0
ファイル: Entries.cs プロジェクト: VictorOverX/X360
 /// <summary>
 /// Extract the file
 /// </summary>
 /// <param name="OutLocation"></param>
 /// <returns></returns>
 public bool Extract(string OutLocation)
 {
     if (xDrive.ActiveCheck())
         return false;
     bool xReturn = false;
     DJsIO xIO = new DJsIO(true);
     try
     {
         xReturn = xExtract(ref xIO);
         xIO.Close();
         if (xReturn)
             xReturn = VariousFunctions.MoveFile(xIO.FileNameLong, OutLocation);
     }
     catch
     {
         xIO.Close();
         xReturn = false;
     }
     VariousFunctions.DeleteFile(xIO.FileNameLong);
     xDrive.xActive = false;
     return xReturn;
 }
コード例 #15
0
ファイル: GDFImage.cs プロジェクト: VictorOverX/X360
 /// <summary>
 /// Extract a file
 /// </summary>
 /// <param name="OutLocale"></param>
 /// <returns></returns>
 public bool Extract(string OutLocale)
 {
     if (!xref.ActiveCheck())
         return false;
     DJsIO xIO = new DJsIO(true);
     if (!xExtract(xIO))
     {
         xIO.Close();
         VariousFunctions.DeleteFile(xIO.FileNameLong);
         return (xref.xActive = false);
     }
     xIO.Close();
     bool xSuccess = VariousFunctions.MoveFile(xIO.FileNameLong, OutLocale);
     VariousFunctions.DeleteFile(xIO.FileNameLong);
     return (xSuccess & !(xref.xActive = false));
 }
コード例 #16
0
ファイル: Entries.cs プロジェクト: VictorOverX/X360
 /// <summary>
 /// Overwrite the file
 /// </summary>
 /// <param name="FileIn"></param>
 /// <returns></returns>
 public bool Inject(string FileIn)
 {
     if (xDrive.ActiveCheck())
         return false;
     DJsIO xIOIn = null;
     try { xIOIn = new DJsIO(FileIn, DJFileMode.Open, true); }
     catch { return (xDrive.xActive = false); }
     if (xIOIn == null || !xIOIn.Accessed)
         return (xDrive.xActive = false);
     try { return xInject(xIOIn) & !(xDrive.xActive = false); }
     catch { xIOIn.Close(); return (xDrive.xActive = false); }
 }
コード例 #17
0
ファイル: GDFImage.cs プロジェクト: VictorOverX/X360
 internal bool xExtract(string OutLocation, bool SubItems)
 {
     if (OutLocation == null || OutLocation == "")
         return false;
     OutLocation = OutLocation.xExtractLegitPath();
     if (!VariousFunctions.xCheckDirectory(OutLocation))
         return false;
     GDFContents xConts = xRead();
     foreach (GDFFile x in xConts.Files)
     {
         DJsIO y = new DJsIO(true);
         try
         {
             if (x.xExtract(y))
             {
                 y.Close();
                 VariousFunctions.MoveFile(y.FileNameLong, OutLocation + "/" + x.Name);
             }
         }
         catch { y.Close(); }
         VariousFunctions.DeleteFile(y.FileNameLong);
     }
     foreach (GDFFolder x in xConts.xFolders)
     {
         try { x.xExtract(OutLocation + "/" + x.Name, SubItems); }
         catch { }
     }
     return true;
 }
コード例 #18
0
ファイル: Entries.cs プロジェクト: VictorOverX/X360
 internal bool xReplace(DJsIO xIOIn)
 {
     uint bu = xStartBlock;
     int size = xSize;
     try
     {
         uint[] curblocks = Partition.xTable.GetBlocks(xStartBlock);
         uint[] blocks = Partition.xTable.GetNewBlockChain(xIOIn.BlockCountFATX(Partition), 1);
         if (blocks.Length == 0)
             throw new Exception();
         if (!Partition.xTable.WriteChain(ref blocks))
             throw new Exception();
         if (!Partition.xTable.DC(ref curblocks))
             throw new Exception();
         xIOIn.Position = 0;
         xDrive.GetIO();
         if (!Partition.WriteFile(blocks, ref xIOIn))
             throw new Exception();
         if (!Partition.WriteAllocTable())
             throw new Exception();
         base.xStartBlock = blocks[0];
         base.xSize = (int)xIOIn.Length;
         xIOIn.Close();
         return xWriteEntry();
     }
     catch { xIOIn.Close(); base.xStartBlock = bu; base.xSize = size; return false; }
 }
コード例 #19
0
        public IEnumerable<IResult> ReadSave()
        {
            string fileName = null;

            MyOpenFileResult ofr;

            ofr = new MyOpenFileResult()
                .FilterFiles(
                    ffc => ffc.AddFilter("sav", true)
                               .WithDescription("Borderlands 2 Save Files")
                               .AddAllFilesFilter())
                .WithFileDo(s => fileName = s);

            if (string.IsNullOrEmpty(this._SavePath) == false &&
                Directory.Exists(this._SavePath) == true)
            {
                ofr = ofr.In(this._SavePath);
            }

            yield return ofr;
            if (fileName == null)
            {
                yield break;
            }

            ///////////////////////////////////////////
            //SPITFIRE1337 MODS
            ///////////////////////////////////////////

            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            //using (FileStream fs = File.Create(path)) { }
            File.Delete(path + "/mytempsave.sav");
            File.Delete(path + "/savegame.sav");
            File.Copy(fileName, path + "/mytempsave.sav");
            string profileid = "";
            string deviceid = "";
            string consoleid = "";


            Stream input1 = new FileStream(fileName, FileMode.Open);

            // Ensure that the target does not exist.



            //Stream input = new Stream(fs);
            var check = input1.ReadValueU32(Endian.Big);

            input1.Close();

            if (check == 0x434F4E20)
            {
                //MessageBox.Show("This is a xbox save");

                yield return new DelegateResult(() =>
                {
                    DJsIO io = new DJsIO(fileName, DJFileMode.Open, true);

                    io.Position = 0x371;
                    profileid = io.ReadHexString(8); //Profile ID
                    io.Close();
                })
    .Rescue().Execute(
        x =>
        new MyMessageBox("An exception was thrown (press Ctrl+C to copy):\n\n" + x.ToString(),
                         "Error")
            .WithIcon(MessageBoxImage.Error).AsCoroutine());


                STFSPackage xPackage = new STFSPackage(fileName, null);
                FileEntry xent = (FileEntry)xPackage.GetFile("savegame.sav");

                if (!xent.Extract(path + "/savegame.sav"))
                {
                    //MessageBoxEx.Show("Extraction Failed!", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.[Error])
                    //xboxextract.ReportProgress(200, "Extraction Failed");
                    //Thread.Sleep(2000);
                    //Return
                    MessageBox.Show("Could not extract savegame.sav. Please use a program like modio or horizon to extract your savegame.sav");
                }
                else
                {


                    fileName = path + "/savegame.sav";
                    //MessageBox.Show("File extracted");
                    //Thread.Sleep(2000);
                    //MessageBoxEx.Show("Extraction Complete!", "Complete!", MessageBoxButtons.OK, MessageBoxIcon.Information)
                }

            }
            else
            {
                profileid = "0";
                deviceid = "0";
                consoleid = "0";
            }

            yield return new DelegateResult(() =>
            {
                FileFormats.SaveFile saveFile;
                using (var input = File.OpenRead(fileName))
                {
                    saveFile = FileFormats.SaveFile.Deserialize(input, FileFormats.SaveFile.DeserializeSettings.None);
                }

                this.SaveFile = saveFile;
                this.General.ImportData(saveFile.SaveGame, saveFile.Endian, profileid, deviceid, consoleid);
                this.CurrencyOnHand.ImportData(saveFile.SaveGame);
                this.Backpack.ImportData(saveFile.SaveGame);
                this.Bank.ImportData(saveFile.SaveGame);
            })
                .Rescue<DllNotFoundException>().Execute(
                    x => new MyMessageBox("Failed to load save: " + x.Message, "Error")
                             .WithIcon(MessageBoxImage.Error).AsCoroutine())
                .Rescue<FileFormats.SaveFormatException>().Execute(
                    x => new MyMessageBox("Failed to load save: " + x.Message, "Error")
                             .WithIcon(MessageBoxImage.Error).AsCoroutine())
                .Rescue<FileFormats.SaveCorruptionException>().Execute(
                    x => new MyMessageBox("Failed to load save: " + x.Message, "Error")
                             .WithIcon(MessageBoxImage.Error).AsCoroutine())
                .Rescue().Execute(
                    x =>
                    new MyMessageBox("An exception was thrown (press Ctrl+C to copy):\n\n" + x.ToString(),
                                     "Error")
                        .WithIcon(MessageBoxImage.Error).AsCoroutine());
            ///////////////////////////////////////////
            //END SPITFIRE1337 MODS
            ///////////////////////////////////////////
        }
コード例 #20
0
ファイル: Other.cs プロジェクト: VictorOverX/X360
        /// <summary>
        /// Attempts to find the type of the file
        /// </summary>
        /// <param name="FileLocale"></param>
        /// <returns></returns>
        public static XboxFileType ReadFileType(string FileLocale)
        {
            /* ADD FATX SUPPORT */
            DJsIO xIO = new DJsIO(FileLocale, DJFileMode.Open, true);
            try
            {
                XboxFileType xReturn = XboxFileType.None;
                xIO.Position = 0;
                uint sig = xIO.ReadUInt32();
                switch (sig)
                {
                    case (uint)AllMagic.CON:
                    case (uint)AllMagic.LIVE:
                    case (uint)AllMagic.PIRS:
                        {
                            if (xIO.Length < 0x37C)
                                break;
                            xIO.Position = 0x379;
                            byte[] desc = xIO.ReadBytes(3);
                            if (desc[0] == 0x24 && desc[1] == 0 &&
                                (desc[2] == 0 || desc[2] == 1 || desc[2] == 2))
                                xReturn = XboxFileType.STFS;
                            else if (desc[0] == 0x24 && desc[1] == 5 &&
                                desc[2] == 5)
                                xReturn = XboxFileType.SVOD;
                        }
                        break;

                    case (uint)AllMagic.Music: { xReturn = XboxFileType.Music; } break;

                    case (uint)AllMagic.XDBF: { xReturn = XboxFileType.GPD; } break;

                    case 0:
                        {
                            if (xIO.Length < 0x130EB0004)
                                break;
                            xIO.Position = 0x130EB0000;
                            if (xIO.ReadUInt32() != (uint)AllMagic.FATX)
                                break;
                            xReturn = XboxFileType.FATX;
                        }
                        break;

                    case (uint)AllMagic.XSF: { xReturn = XboxFileType.GDF; } break;

                    default: break;
                }
                if (xReturn == XboxFileType.None)
                {
                    try
                    {
                        xIO.Position = 0;
                        if (xIO.ReadBytes(20).HexString() != GDFX.GDFMagic.XMedia.HexString())
                        {
                            xIO.Position = 0x1FB20;
                            if (xIO.ReadBytes(20).HexString() != GDFX.GDFMagic.XMedia.HexString())
                            {
                                xIO.Position = 0x30600;
                                if (xIO.ReadBytes(20).HexString() != GDFX.GDFMagic.XMedia.HexString())
                                {
                                    xIO.Position = 0x7FF000;
                                    if (xIO.ReadUInt32() != (uint)AllMagic.FATX)
                                    {
                                        xIO.Position = 0xFDA0000;
                                        if (xIO.ReadBytes(20).HexString() != GDFX.GDFMagic.XMedia.HexString())
                                        {
                                            xIO.Position = 0x130EB0000;
                                            if (xIO.ReadUInt32() == (uint)AllMagic.FATX)
                                                xReturn = XboxFileType.FATX;
                                        }
                                        else xReturn = XboxFileType.GDF;
                                    }
                                    else xReturn = XboxFileType.FATX;
                                }
                                else xReturn = XboxFileType.GDF;
                            }
                            else xReturn = XboxFileType.GDF;
                        }
                        else xReturn = XboxFileType.GDF;
                    }
                    catch { }
                }
                xIO.Dispose();
                return xReturn;
            }
            catch (Exception x) { xIO.Close(); throw x; }
        }
コード例 #21
0
        ///////////////////////////////////////////
        //SPITFIRE1337 MODS
        ///////////////////////////////////////////
        public IEnumerable<IResult> WriteSaveXbox()
        {
            if (this.SaveFile == null)
            {
                yield break;
            }

            string path = Environment.GetFolderPath(Environment.SpecialFolder.ApplicationData);
            File.Delete(path + "/savegame.sav");

            //MessageBox.Show("A save file box will now appear, please select a EXISTING XBOX SAVE to overwrite. I can not emphasize this enough, ALWAYS KEEP A WORKING BACKUP. Once you have a backup press ok to continue");

            var saveFile = this.SaveFile;

            yield return new DelegateResult(() =>
            {
                Endian endian;
                this.General.ExportData(saveFile.SaveGame, out endian);
                this.CurrencyOnHand.ExportData(saveFile.SaveGame);
                this.Backpack.ExportData(saveFile.SaveGame);
                this.Bank.ExportData(saveFile.SaveGame);


                using (var output = File.Create(path + "/savegame.sav"))
                {
                    saveFile.Endian = endian;
                    saveFile.Serialize(output);
                }
            }).Rescue().Execute(
    x =>
    new MyMessageBox("An exception was thrown (press Ctrl+C to copy this text):\n\n" + x.ToString(), "Error")
        .WithIcon(MessageBoxImage.Error).AsCoroutine());

            string fileName = null;

            MySaveFileResult ofr;

            ofr = new MySaveFileResult()
                .PromptForOverwrite()
                .FilterFiles(
                    ffc => ffc.AddFilter("sav", true)
                               .WithDescription("Borderlands 2 Save Files")
                               .AddAllFilesFilter())
                .WithFileDo(s => fileName = s);

            if (string.IsNullOrEmpty(this._SavePath) == false &&
                Directory.Exists(this._SavePath) == true)
            {
                ofr = ofr.In(this._SavePath);
            }

            yield return ofr;

            if (fileName == null)
            {
                yield break;
            }
            if (File.Exists(fileName))
            {

                File.WriteAllBytes(fileName, Properties.Resources.Save0001);
            }
            else
            {
                File.Delete(fileName);
                File.WriteAllBytes(fileName, Properties.Resources.Save0001);
            }
            yield return new DelegateResult(() =>
            {


                string profileid = this.General.Profileid;
                DJsIO io = new DJsIO(fileName, DJFileMode.Open, true);

                io.Position = 0x371;
                io.WriteHexString(profileid);
                io.Close();
            }).Rescue().Execute(
                x =>
                new MyMessageBox("An exception was thrown (press Ctrl+C to copy this text):\n\n" + x.ToString(), "Error")
                    .WithIcon(MessageBoxImage.Error).AsCoroutine());
            yield return new DelegateResult(() =>
            {

                STFSPackage stfs = new STFSPackage(fileName, null);
                FileEntry item = stfs.GetFile("savegame.sav"); //Get's the account file



                if (!item.Replace(path + "\\savegame.sav"))
                {
                    //If Not xent.Extract(Application.StartupPath + "\" + "savegame.sav") Then
                    //MessageBoxEx.Show("Extraction Failed!", "Failed!", MessageBoxButtons.OK, MessageBoxIcon.[Error])
                    throw new Exception("Failed to insert save file to xbox save. Please use a program like modio or horizon to insert your save");

                }
                else
                {
                    //MessageBox.Show("File Inserted");

                    //If Not  Then

                    //End If
                    //MessageBoxEx.Show("Extraction Complete!", "Complete!", MessageBoxButtons.OK, MessageBoxIcon.Information)
                }
                if (!File.Exists(path + "/kv.bin"))
                {
                    File.WriteAllBytes(path + "/kv.bin", Properties.Resources.KV);
                }



                stfs.FlushPackage(new RSAParams(path + "/kv.bin"));
                stfs.CloseIO();

            }).Rescue().Execute(
                x =>
                new MyMessageBox("An exception was thrown (press Ctrl+C to copy this text):\n\n" + x.ToString(), "Error")
                    .WithIcon(MessageBoxImage.Error).AsCoroutine());
        }
コード例 #22
0
        public void importfromprofile()
        {
            OpenFileDialog dialog = new OpenFileDialog();
            dialog.Title = "Open a xbox 360 profile";
            dialog.Filter = "Xbox 360 profile|*.*";
            DialogResult result = dialog.ShowDialog();
            if (result == DialogResult.OK) // Test result.
            {

                try
                {
                    DJsIO io = new DJsIO(dialog.FileName, DJFileMode.Open, true);


                    io.Position = 0x371;
                    this.Profileid = io.ReadHexString(8);
                    io.Close();

                    //xPackage3.STFS.Package sts = new xPackage3.STFS.Package(dialog.FileName);

                    STFSPackage stfs = new STFSPackage(dialog.FileName, null);
                    ProfilePackage xFile = new ProfilePackage(ref stfs);
                    string gamertag = xFile.UserFile.GetGamertag();
                    this.ProfileName = gamertag;
                    xFile.CloseIO();
                    stfs.CloseIO();
                    //this.Profileid = stfs.Header.Title_Package;
                }
                catch (Exception e) { }
            }
        }
コード例 #23
0
        /// <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; }
        }