Пример #1
0
        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);
        }
Пример #2
0
        /// <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);
        }
Пример #3
0
        /// <summary>
        /// Reads a GPD from the Titles Played index of the User GPD
        /// </summary>
        /// <param name="ID"></param>
        /// <param name="xEntry"></param>
        /// <returns></returns>
        public GameGPD ReadGame(uint ID, out FileEntry xEntry)
        {
            xEntry = null;
            if (!ParseCheck())
            {
                return(null);
            }
            if (UserGPD == null)
            {
                return(null);
            }
            FileEntry x = GetFile(ID.ToString("X") + ".gpd");

            if (x == null)
            {
                return(null);
            }
            DJsIO y = x.GetTempIO(true);

            if (y == null || !y.Accessed)
            {
                y.Close();
                VariousFunctions.DeleteFile(y.FileNameLong);
                return(null);
            }
            y.Close();
            GameGPD z = new GameGPD(y.FileNameLong, ID);

            if (z.IsValid)
            {
                xEntry = x;
                return(z);
            }
            return(null);
        }
Пример #4
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) { }
            }
        }
Пример #5
0
        /// <summary>
        /// Special scramble method
        /// </summary>
        /// <param name="xPiece"></param>
        /// <returns></returns>
        public static byte[] DJScramble(byte[] xPiece)
        {
            if ((xPiece.Length % 8) != 0)
            {
                throw new Exception("Input not divisible by 8");
            }
            int xSpot = 5, xCurrent;
            var xStream = new DJsIO(xPiece, true)
            {
                Position = 0
            };
            var xHalf1 = xStream.ReadBytes((xPiece.Length / 2));
            var xHalf2 = xStream.ReadBytes((xPiece.Length / 2));

            xStream.Position = 0;
            xStream.Write(xHalf2);
            xStream.Write(xHalf1);
            xStream.Flush();
            xStream.Close();
            for (var i = 0; i < xPiece.Length; i += xCurrent)
            {
                Array.Reverse(xPiece, i, xSpot);
                xCurrent = xSpot;
                xSpot    = xSpot == 5 ? 3 : 5;
            }
            return(xPiece);
        }
Пример #6
0
 internal void GetIO()
 {
     if (IsDriveIO && xType != DriveTypes.USBFlashDrive)
     {
         // Close previous handle
         if (xIO != null)
         {
             xIO.Close();
             // Make a new handle to a drive
             xIO.OpenAgain();
         }
         else
         {
             xIO = new DriveIO(ref xDrive, true);
         }
     }
     else if (xType == DriveTypes.USBFlashDrive && xIO == null || !xIO.Accessed)
     {
         List <string> files = new List <string>();
         for (int i = 0; i <= 9999; i++)
         {
             string file = xDrive.DeviceName + @"\Xbox360\Data" + i.ToString("000#");
             if (File.Exists(file))
             {
                 files.Add(file);
             }
             else
             {
                 break;
             }
         }
         xIO = new MultiFileIO(files.ToArray(), true);
     }
 }
Пример #7
0
 /// <summary>
 /// Close the Image IO
 /// </summary>
 /// <returns></returns>
 public bool Close()
 {
     if (!ActiveCheck())
     {
         return(false);
     }
     xIO.Close();
     return(true);
 }
Пример #8
0
        /// <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));
        }
Пример #9
0
        /// <summary>
        /// Impor RSA attributes from an Xbox360 Keyvault location for Con
        /// </summary>
        /// <param name="xKVLocation"></param>
        public RSAParams(string xKVLocation)
        {
            var xKV = new DJsIO(xKVLocation, DJFileMode.Open, true);

            if (!xKV.Accessed)
            {
                throw STFSExcepts.IOAccess;
            }
            XLoadCON(xKV);
            xKV.Close();
        }
Пример #10
0
        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());
        }
Пример #11
0
        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); }
        }
Пример #12
0
 /// <summary>
 /// Close IO's
 /// </summary>
 /// <returns></returns>
 public bool Close()
 {
     if (!ActiveCheck())
     {
         return(false);
     }
     IO.Close();
     if (dataloaded)
     {
         foreach (DJsIO x in xDataFiles)
         {
             x.Close();
         }
     }
     return(true);
 }
Пример #13
0
        private void UpdateSTFS(STFSPackage package, byte[] kvData)
        {
            if (package != null)
            {
                // Inject the new mmiof.bmf
                X360.STFS.FileEntry file = package.GetFile(_rawFileName);
                file.Inject(_rawPath);

                if (kvData != null)
                {
                    // Resign the package using the KV data
                    DJsIO kvStream = new DJsIO(kvData, true);
                    package.FlushPackage(new X360.STFS.RSAParams(kvStream));
                    kvStream.Close();
                }
            }
        }
Пример #14
0
        /// <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); }
        }
Пример #15
0
        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");
        }
Пример #16
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
            ///////////////////////////////////////////
        }
Пример #17
0
        /// <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 */
            var xIO = new DJsIO(FileLocale, DJFileMode.Open, true);

            try
            {
                var xReturn = XboxFileType.None;
                xIO.Position = 0;
                var 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;
                    var 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;
                }
                xIO.Dispose();
                return(xReturn);
            }
            catch (Exception)
            {
                xIO.Close();
                return(XboxFileType.None);
                //throw;
            }
        }
Пример #18
0
        /// <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);
            }
        }
Пример #19
0
 /// <summary>
 /// Special scramble method
 /// </summary>
 /// <param name="xPiece"></param>
 /// <returns></returns>
 public static byte[] DJScramble(byte[] xPiece)
 {
     if ((xPiece.Length % 8) != 0)
         throw new Exception("Input not divisible by 8");
     int xSpot = 5, xCurrent = 5;
     DJsIO xStream = new DJsIO(xPiece, true);
     xStream.Position = 0;
     byte[] xHalf1 = xStream.ReadBytes((xPiece.Length / 2));
     byte[] xHalf2 = xStream.ReadBytes((xPiece.Length / 2));
     xStream.Position = 0;
     xStream.Write(xHalf2);
     xStream.Write(xHalf1);
     xStream.Flush();
     xStream.Close();
     for (int i = 0; i < xPiece.Length; i += xCurrent)
     {
         Array.Reverse(xPiece, i, xSpot);
         xCurrent = xSpot;
         if (xSpot == 5)
             xSpot = 3;
         else xSpot = 5;
     }
     return xPiece;
 }
Пример #20
0
        /// <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); }
        }
Пример #21
0
        /// <summary>
        /// Loads the profile information from the package
        /// </summary>
        /// <param name="xboth"></param>
        /// <returns></returns>
        bool LoadProfile(bool xboth)
        {
            if (!ParseCheck())
            {
                return(false);
            }
            new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(System.DLLIdentify.PrivilegeCheck)).Start(System.Threading.Thread.CurrentThread);
            bool xreturn = true;

            if (xboth)
            {
                FileEntry xacct = GetFile("Account");
                if (xacct != null && xacct.Size == 404)
                {
                    if (HasValidAccount)
                    {
                        xUserFile.IO.Dispose();
                    }
                    AddToLog("Parsing Account file");
                    DJsIO xAcctIO = xacct.GetTempIO(true);
                    if (xAcctIO == null || !xAcctIO.Accessed)
                    {
                        if (xAcctIO != null)
                        {
                            xAcctIO.Dispose();
                            VariousFunctions.DeleteFile(xAcctIO.FileNameLong);
                        }
                    }
                    else
                    {
                        xUserFile = new UserAccount(xAcctIO, AccountType.Stock, true);
                        xreturn   = xUserFile.Success;
                        if (!xUserFile.Success)
                        {
                            xUserFile = new UserAccount(xAcctIO, AccountType.Kits, true);
                            xreturn   = xUserFile.Success;
                            if (!xUserFile.Success)
                            {
                                xUserFile = null;
                            }
                        }
                    }
                }
            }
            FileEntry xdash = GetFile("FFFE07D1.gpd");

            if (xdash != null)
            {
                AddToLog("Parsing User GPD");
                DJsIO xFFIO = xdash.GetTempIO(true);
                if (xFFIO == null || !xFFIO.Accessed)
                {
                    if (xFFIO != null)
                    {
                        VariousFunctions.DeleteFile(xFFIO.FileNameLong);
                    }
                }
                else
                {
                    try
                    {
                        xFFIO.Close();
                        if (HasDashGPD)
                        {
                            xUserGPD.xIO.Dispose();
                        }
                        xUserGPD = new DashGPD(xFFIO.FileNameLong);
                        xreturn &= xUserGPD.IsValid;
                        if (!xUserGPD.IsValid)
                        {
                            xUserGPD = null;
                            xFFIO.Dispose();
                            VariousFunctions.DeleteFile(xFFIO.FileNameLong);
                        }
                    }
                    catch { xUserGPD = null; }
                }
            }
            return(xreturn);
        }
Пример #22
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()));
        }
Пример #23
0
        /// <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; }
        }