Пример #1
0
        List <DevPartitionRegions> dP;/*enetration*/

        /// <summary>
        ///
        /// </summary>
        /// <returns></returns>
        DevPartitionRegions[] DevPartitions()
        {
            if (dP == null)
            {
                dP = new List <DevPartitionRegions>();

                // Load the regions
                Streams.Reader sReader = Reader();
                sReader.BaseStream.Position = 0;
                byte[] Buffer = sReader.ReadBytes(0x200);
                sReader = new Streams.Reader(new MemoryStream(Buffer));
                sReader.BaseStream.Position = 0x8; // data

                dP.Add(new DevPartitionRegions()
                {
                    RegionName    = "Content",
                    Sector        = sReader.ReadUInt32(),
                    PartitionSize = sReader.ReadUInt32() * 0x200,
                });
                dP.Add(new DevPartitionRegions()
                {
                    RegionName    = "Xbox 360 Dashboard Volume",
                    Sector        = sReader.ReadUInt32(),
                    PartitionSize = sReader.ReadUInt32() * 0x200,
                });
            }
            return(dP.ToArray());
        }
Пример #2
0
        static public string GetFATXPath(string PackagePath)
        {
            // Check the header...
            Streams.Reader io = new Streams.Reader(new System.IO.FileStream(PackagePath, System.IO.FileMode.Open));
            if (io.BaseStream.Length > 4)
            {
                uint header = io.ReadUInt32();
                if (header == 0x434F4E20 || header == 0x4C495645 || header == 0x50495253)
                {
                    // Get the type
                    io.BaseStream.Position = 0x344;
                    byte[] Type = io.ReadBytes(0x4);

                    // Get the profile ID
                    io.BaseStream.Position = 0x371;
                    byte[] ID = io.ReadBytes(0x8);

                    // Get the title ID
                    io.BaseStream.Position = 0x360;
                    byte[] TitleID = io.ReadBytes(0x4);

                    // NOW LET'S DO THIS SHIT
                    return(string.Format("Content\\{0}\\{1}\\{2}", ID.ToHexString(), TitleID.ToHexString(), Type.ToHexString()));
                }
            }

            throw new Exception(PackagePath + " is not a valid package!");
        }
Пример #3
0
            public static uint SecondPlayedGame()
            {
                Streams.Reader r = Drive.Reader();
                r.BaseStream.Position = 0xA80;
                uint Value = r.ReadUInt32();

                return(Value);
            }
Пример #4
0
            public static uint Magic()
            {
                Streams.Reader r = Drive.Reader();
                r.BaseStream.Position = 0x800;
                uint Value = r.ReadUInt32();

                return(Value);
            }
Пример #5
0
            public static uint Sectors()
            {
                Streams.Reader r = Drive.Reader();
                r.BaseStream.Position = 0x2058;
                uint Value = r.ReadUInt32();

                return(Value);
            }
Пример #6
0
            public static System.Drawing.Image MicrosoftLogo()
            {
                Streams.Reader r = Drive.Reader();
                r.BaseStream.Position = 0x2200;
                uint Length = r.ReadUInt32();

                System.Drawing.Image Value = System.Drawing.Image.FromStream(new System.IO.MemoryStream(r.ReadBytes((int)Length)));
                return(Value);
            }
Пример #7
0
 public uint Magic()
 {
     if (magic != 0)
     {
         return(magic);
     }
     Streams.Reader br = FATXDrive.Reader();
     br.BaseStream.Position = Partition.Offset;
     //Read the header
     magic = br.ReadUInt32();
     return(magic);
 }
Пример #8
0
            public static uint[] FooterInts()
            {
                Streams.Reader r = Drive.Reader();
                r.BaseStream.Position = 0xA70;
                List <uint> R = new List <uint>();

                for (int i = 0; i < 3; i++)
                {
                    R.Add(r.ReadUInt32());
                }
                return(R.ToArray());
            }
Пример #9
0
 public bool DriveHasJoshSector()
 {
     if (DriveType == DriveType.USB)
     {
         return(false);
     }
     Streams.Reader r = Reader();
     r.BaseStream.Position = 0x800;
     if (r.ReadUInt32() == 0x4A6F7368)
     {
         return(true);
     }
     return(false);
 }
Пример #10
0
        /// <summary>
        /// Partition ID
        /// </summary>
        public uint PartitionID()
        {
            uint rVal = 0;

            //Open our binary reader
            Streams.Reader br = FATXDrive.Reader();
            //Seek to the data partition offset
            br.BaseStream.Position = Partition.Offset;
            //Read our buffer
            Streams.Reader mem = new Streams.Reader(new System.IO.MemoryStream(br.ReadBytes(0x200)));
            mem.BaseStream.Position = 0x4;
            rVal = mem.ReadUInt32();
            mem.Close();
            return(rVal);
        }
Пример #11
0
        /// <summary>
        /// Number of File Allocation Tables
        /// </summary>
        public uint FATCopies()
        {
            uint rVal = 0;

            //Open our binary reader
            Streams.Reader br = FATXDrive.Reader();
            //Seek to the data partition offset + 0xC (where the FATCopies int is)
            br.BaseStream.Position = Partition.Offset;
            //Create our mem reader / buffer
            Streams.Reader mem = new Streams.Reader(new System.IO.MemoryStream(br.ReadBytes(0x200)));
            mem.BaseStream.Position = 0xC;
            //Get our value (uses outside class for bigendian)
            rVal = mem.ReadUInt32();
            mem.Close();
            return(rVal);
        }
Пример #12
0
        public uint RootDirectoryCluster()
        {
            // Open our IO
            Streams.Reader io = FATXDrive.Reader();
            // Set the IO position...
            io.BaseStream.Position = Partition.Offset;
            // Read our buffer
            byte[] buffer = io.ReadBytes(0x200);
            // Re-open the IO in to a memory stream
            io = new Streams.Reader(new System.IO.MemoryStream(buffer));
            // Go to the offset that the root dir is located; 0xC
            io.BaseStream.Position = 0xC;
            // Read and return the int there
            uint rVal = io.ReadUInt32();

            io.Close();
            return(rVal);
        }
Пример #13
0
        /// <summary>
        /// Gets the title names that correspond with title ID's from a file
        /// </summary>
        /// <returns>List of title ID's with their accurate title names</returns>
        private Structs.CachedTitleName[] CachedFromFile(File f)
        {
            List <Structs.CachedTitleName> tnl = new List <Structs.CachedTitleName>();
            int BlockLength = 0x34;

            Streams.Reader r = new Streams.Reader(f.GetStream());
            for (int i = 0, Previous = 0; i < r.BaseStream.Length / BlockLength; i++, Previous += 0x34)
            {
                // Set the position of the stream
                r.BaseStream.Position = Previous;
                // Create the new CachedTitleName struct
                Structs.CachedTitleName TN = new Structs.CachedTitleName();
                // Read the title ID
                TN.ID = r.ReadUInt32();
                // Read the name
                TN.Name = r.ReadCString();
                // Add that to the list
                tnl.Add(TN);
            }
            return(tnl.ToArray());
        }
Пример #14
0
        //uint dicks(ref uint r3, ref uint r4, ref uint r6, ref uint r7, ref uint r8, ref uint r9, ref uint r10)
        //{

        //}

        public long GetFreeSpace()
        {
            // Our return
            long Return      = 0;
            long ClusterSize = this.ClusterSize();

            // Get our position
            long positionya = FATOffset;

            // Get our end point
            long toBeLessThan = FATOffset + RealFATSize();

            // Get our IO
            Streams.Reader io = FATXDrive.Reader();
            // Set the position
            io.BaseStream.Position = positionya;

            // Start reading!
            for (long dick = io.BaseStream.Position; dick < toBeLessThan; dick += 0x200)
            {
                bool BreakAndShit = false;
                // Set the position
                io.BaseStream.Position = dick;
                // Read our buffer
                byte[] Buffer = null;
                if ((dick - FATOffset).DownToNearest200() == (toBeLessThan - FATOffset).DownToNearest200())
                {
                    byte[] Temp = io.ReadBytes(0x200);
                    Buffer = new byte[(toBeLessThan - FATOffset) - (dick - FATOffset).DownToNearest200()];
                    Array.Copy(Temp, 0, Buffer, 0, Buffer.Length);
                }
                else
                {
                    Buffer = io.ReadBytes(0x200);
                }
                // Length to loop for (used for the end so we can read ONLY usable partitions)
                long Length = Buffer.Length;
                if (dick == VariousFunctions.DownToNearest200(toBeLessThan))
                {
                    Length       = toBeLessThan - VariousFunctions.DownToNearest200(toBeLessThan);
                    BreakAndShit = true;
                }
                // Check the values
                Streams.Reader ioya = new Streams.Reader(new System.IO.MemoryStream(Buffer));
                for (int i = 0; i < Length; i += EntrySize)
                {
                    // This size will be off by a few megabytes, no big deal in my opinion
                    if (EntrySize == 2)
                    {
                        ushort Value = ioya.ReadUInt16();
                        if (Value == 0)
                        {
                            Return += ClusterSize;
                        }
                    }
                    else
                    {
                        if (ioya.ReadUInt32() == 0)
                        {
                            Return += ClusterSize;
                        }
                    }
                }
                ioya.Close();
                if (BreakAndShit)
                {
                    break;
                }
            }

            return(Return);
        }
Пример #15
0
        /// <summary>
        /// TOTAL size (includes padding) of the File Allocation Table (in bytes)
        /// FOR REAL SIZE, CALL TO RealFATSize();
        /// </summary>
        public long FATSize()
        {
            if (fatsize != 0)
            {
                if (!SizeChecked)
                {
                    Streams.Reader r = FATXDrive.Reader();
                    r.BaseStream.Position = Partition.Offset + fatsize + 0x1000;
                    while (true)
                    {
                        if (r.ReadUInt32() == 0x0)
                        {
                            fatsize += 0x1000;
                            r.BaseStream.Position += 0x1000 - 0x4;
                        }
                        else
                        {
                            break;
                        }
                    }
                    SizeChecked = true;
                }
                return(fatsize);
            }
            if (Partition.Offset == (long)Geometry.HDDOffsets.System_Extended)
            {
                return(0x5000);
            }
            else if (Partition.Offset == (long)Geometry.HDDOffsets.System_Cache)
            {
                return(0x7000);
            }
            #region old
            //long size = 0;
            //if (Partition.Offset == 0x20000000 && FATXDrive.IsUSB)
            //{
            //    System.IO.FileInfo fi = new System.IO.FileInfo(FATXDrive.DumpPath + "\\Data0001");
            //    size = fi.Length - 0x1000;
            //    //Return the size.
            //    return size;
            //}
            //else
            //{
            //    //This gets the size
            //    size = ((PartitionSize() / ClusterSize()) * EntrySize);
            //    //We need to round up to the nearest 0x1000 byte boundary.
            //    long sizeToAdd = (0x1000 - (size % 0x1000));
            //    if (!FATXDrive.IsUSB)
            //    {
            //        size += sizeToAdd;
            //    }
            //    //Return the size.
            //    return size;
            //}
            #endregion
            //Code that rounds up to nearest cluster...
            long size = 0;
            #region shit
            //if (Partition.Offset == 0x20000000 && FATXDrive.IsUSB)
            //{
            //    System.IO.FileInfo fi = new System.IO.FileInfo(FATXDrive.DumpPath + "\\Data0001");
            //    size = fi.Length - 0x1000;
            //    //Ghetto
            //    Streams.Reader ir = FATXDrive.Reader();
            //    //Return the size.
            //    return size;
            //}
            //else
            //{
            #endregion
            //This gets the size
            size = (((PartitionSize() / ClusterSize())) * EntrySize);
            //We need to round up to the nearest blabhlabhalkhdflkasdf byte boundary.
            size = VariousFunctions.UpToNearestCluster(size + 0x1000, ClusterSize() / EntrySize) - 0x1000;
            //long sizeToAdd = (0x1000 - (size % 0x1000));
            //size += sizeToAdd;
            //Return the size.
            return(size);
            //uint r24 = 0, r3, r6, r23, r10, r11, r27, r22, r25, r26, r28, r29, r30, r31;
            //if (Partition.Size == 0)
            //{

            //}
            //else
            //{
            //    r11 = r27 & 0xFF;
            //    if (r11 == 2)
            //    {
            //        r11 = r22;
            //        r10 = r11 + r29;
            //        r11--;
            //        r10--;
            //        r29 = r10 & (~r11);
            //        r30 = r29;
            //    }
            //    else
            //    {
            //        // break here
            //    }
            //    r10 = 1;
            //    r3 = dicks(ref r28, ref r26, ref r27, ref r25, ref r31, ref r24, ref r10);
            //}
        }
Пример #16
0
        /// <summary>
        /// 检查驱动器是否为合法的FATX驱动器格式
        /// </summary>
        /// <returns>是或者否</returns>
        public bool IsFATXDrive()
        {
            switch (DriveType)
            {
            // HDD类型
            case DriveType.HardDisk:
            {
                try
                {
                    // 创建一个Reader,检查该驱动器类型是否为DEVKIT
                    Streams.Reader sHddReader = Reader();
                    sHddReader.BaseStream.Position = 0;

                    // 如果该驱动器魔数数值为0x00020000,则为DEVKIT类型磁盘
                    if (sHddReader.ReadUInt32() == (uint)DriveMagic.DEVKIT)
                    {
                        // 如果为DEVKIT类型磁盘,计算扇区大小
                        DevPartitionRegions[] regions = DevPartitions();
                        sHddReader.BaseStream.Position = (long)regions[0].Sector * 0x200;

                        // 检查数据分区的魔数数值是否为XTAF
                        if (sHddReader.ReadUInt32() == (uint)DriveMagic.XTAF)
                        {
                            return(IsDev = true);
                        }
                        else
                        {
                        }
                    }
                    else
                    {
                        // 按照偏移量找到数据分区
                        sHddReader.BaseStream.Position = (long)Geometry.HDDOffsets.Data;

                        // 检查数据分区的魔数数值是否为XTAF
                        if (sHddReader.ReadUInt32() == (uint)DriveMagic.XTAF)
                        {
                            return(true);
                        }
                        else
                        {
                        }
                    }
                }
                catch
                {
                    throw new Exception("");
                }
                break;
            }

            case DriveType.USB:
            {
                try
                {
                    // 根据偏移量找到数据分区
                    Streams.Reader sUsbReader = Reader();
                    sUsbReader.BaseStream.Position = (long)Geometry.USBOffsets.Data;

                    // 检查数据分区的魔数数值是否为XTAF
                    if (sUsbReader.ReadUInt32() == (uint)DriveMagic.XTAF)
                    {
                        return(true);
                    }
                    else
                    {
                    }
                }
                catch
                {
                    throw new Exception("");
                }
                break;
            }

            case DriveType.Backup:
            {
                try
                {
                    Streams.Reader sBackupReader = Reader();
                    sBackupReader.BaseStream.Position = 0;

                    if (sBackupReader.ReadUInt32() == (uint)DriveMagic.DEVKIT)
                    {
                        DevPartitionRegions[] regions = DevPartitions();
                        sBackupReader.BaseStream.Position = (long)regions[0].Sector * 0x200;

                        if (sBackupReader.ReadUInt32() == (uint)DriveMagic.XTAF)
                        {
                            return(IsDev = true);
                        }
                        return(IsDev = true);
                    }

                    if (Length > (long)Geometry.HDDOffsets.Data)
                    {
                        // Seek to the data position
                        sBackupReader.BaseStream.Position = (long)Geometry.HDDOffsets.Data;
                    }
                    // Read the magic
                    if (sBackupReader.ReadUInt32() == (uint)DriveMagic.XTAF)
                    {
                        return(true);
                    }
                    else
                    {
                    }
                }
                catch
                {
                    throw new Exception("");
                }
                break;
            }
            }
            return(false);
        }