/// <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);
        }
        /// <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);
        }
        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);
        }
Пример #4
0
 /// <summary>
 /// Returns an array of free blocks based off of the number of blocks needed
 /// </summary>
 public uint[] GetFreeBlocks(Folder Partition, int blocksNeeded, uint StartBlock, long end, bool SecondLoop)
 {
     int Clustersize = 0x10000;
     uint Block = StartBlock;
     if (end == 0)
     {
         end = Partition.PartitionInfo.FATOffset + Partition.PartitionInfo.FATSize;
     }
     List<uint> BlockList = new List<uint>();
     // Create our reader for the drive
     Streams.Reader br = Reader();
     // Create our reader for the memory stream
     Streams.Reader mr = null;
     for (long i = VariousFunctions.DownToNearest200(VariousFunctions.BlockToFATOffset(StartBlock, Partition)); i < end; i += Clustersize)
     {
         //Set our position to i
         br.BaseStream.Position = i;
         byte[] buffer = new byte[0];
         if ((end - i) < Clustersize)
         {
             buffer = VariousFunctions.ReadBytes(ref br, end - i);
         }
         else
         {
             //Read our buffer
             buffer = br.ReadBytes(Clustersize);
         }
         try
         {
             mr.Close();
         }
         catch { }
         mr = new Streams.Reader(new System.IO.MemoryStream(buffer));
         //Re-open our binary reader using the buffer/memory stream
         for (int j = 0; j < buffer.Length; j += (int)Partition.PartitionInfo.EntrySize, Block += (uint)Partition.PartitionInfo.EntrySize)
         {
             mr.BaseStream.Position = j;
             //If we've gotten all of our requested blocks...
             if (BlockList.Count == blocksNeeded)
             {
                 //Close our reader -> break the loop
                 mr.Close();
                 break;
             }
             //Read the next block entry
             byte[] reading = mr.ReadBytes((int)Partition.PartitionInfo.EntrySize);
             //For each byte in our reading
             for (int k = 0; k < reading.Length; k++)
             {
                 //If the byte isn't null (if the block isn't open)
                 if (reading[k] != 0x00)
                 {
                     //Break
                     break;
                 }
                 //If we've reached the end of the array, and the last byte
                 //is 0x00, then the block is free
                 if (k == reading.Length - 1 && reading[k] == 0x00)
                 {
                     //Do some maths to get the block numbah
                     long fOff = Partition.PartitionInfo.FATOffset;
                     long blockPosition = (long)i + j;
                     uint block = (uint)(blockPosition - fOff) / (uint)Partition.PartitionInfo.EntrySize;
                     BlockList.Add(block);
                 }
             }
         }
         //We're putting in one last check so that we don't loop more than we need to
         if (BlockList.Count == blocksNeeded)
         {
             break;
         }
     }
     //If we found the required amount of free blocks - return our list
     if (BlockList.Count == blocksNeeded)
     {
         return BlockList.ToArray();
     }
     //If we didn't find the amount of blocks required, but we started from a
     //block other than the first one...
     if (BlockList.Count < blocksNeeded && SecondLoop == false)
     {
         BlockList.AddRange(GetFreeBlocks(Partition, blocksNeeded - BlockList.Count, 1, VariousFunctions.DownToNearest200(VariousFunctions.BlockToFATOffset(StartBlock, Partition)), true));
         return BlockList.ToArray();
     }
     //We didn't find the amount of free blocks required, meaning we're ref of
     //disk space
     if (BlockList.Count != blocksNeeded)
     {
         throw new Exception("Out of Xbox 360 hard disk space");
     }
     return BlockList.ToArray();
 }
Пример #5
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;
 }
Пример #6
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 ulong GetFreeSpace()
        {
            // Our return
            ulong Return = 0;
            ulong ClusterSize = (ulong)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;
        }
Пример #7
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;
 }
Пример #8
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;
 }
Пример #9
0
        /// <summary>
        /// Returns an array of free blocks based off of the number of blocks needed
        /// </summary>
        public uint[] GetFreeBlocks(Folder Partition, int blocksNeeded, uint StartBlock, long end, bool SecondLoop)
        {
            int  Clustersize = 0x10000;
            uint Block       = StartBlock;

            if (end == 0)
            {
                end = Partition.PartitionInfo.FATOffset + Partition.PartitionInfo.FATSize;
            }
            List <uint> BlockList = new List <uint>();

            // Create our reader for the drive
            Streams.Reader br = Reader();
            // Create our reader for the memory stream
            Streams.Reader mr = null;
            for (long i = VariousFunctions.DownToNearest200(VariousFunctions.BlockToFATOffset(StartBlock, Partition)); i < end; i += Clustersize)
            {
                //Set our position to i
                br.BaseStream.Position = i;
                byte[] buffer = new byte[0];
                if ((end - i) < Clustersize)
                {
                    buffer = VariousFunctions.ReadBytes(ref br, end - i);
                }
                else
                {
                    //Read our buffer
                    buffer = br.ReadBytes(Clustersize);
                }
                try
                {
                    mr.Close();
                }
                catch { }
                mr = new Streams.Reader(new System.IO.MemoryStream(buffer));
                //Re-open our binary reader using the buffer/memory stream
                for (int j = 0; j < buffer.Length; j += (int)Partition.PartitionInfo.EntrySize, Block += (uint)Partition.PartitionInfo.EntrySize)
                {
                    mr.BaseStream.Position = j;
                    //If we've gotten all of our requested blocks...
                    if (BlockList.Count == blocksNeeded)
                    {
                        //Close our reader -> break the loop
                        mr.Close();
                        break;
                    }
                    //Read the next block entry
                    byte[] reading = mr.ReadBytes((int)Partition.PartitionInfo.EntrySize);
                    //For each byte in our reading
                    for (int k = 0; k < reading.Length; k++)
                    {
                        //If the byte isn't null (if the block isn't open)
                        if (reading[k] != 0x00)
                        {
                            //Break
                            break;
                        }
                        //If we've reached the end of the array, and the last byte
                        //is 0x00, then the block is free
                        if (k == reading.Length - 1 && reading[k] == 0x00)
                        {
                            //Do some maths to get the block numbah
                            long fOff          = Partition.PartitionInfo.FATOffset;
                            long blockPosition = (long)i + j;
                            uint block         = (uint)(blockPosition - fOff) / (uint)Partition.PartitionInfo.EntrySize;
                            BlockList.Add(block);
                        }
                    }
                }
                //We're putting in one last check so that we don't loop more than we need to
                if (BlockList.Count == blocksNeeded)
                {
                    break;
                }
            }
            //If we found the required amount of free blocks - return our list
            if (BlockList.Count == blocksNeeded)
            {
                return(BlockList.ToArray());
            }
            //If we didn't find the amount of blocks required, but we started from a
            //block other than the first one...
            if (BlockList.Count < blocksNeeded && SecondLoop == false)
            {
                BlockList.AddRange(GetFreeBlocks(Partition, blocksNeeded - BlockList.Count, 1, VariousFunctions.DownToNearest200(VariousFunctions.BlockToFATOffset(StartBlock, Partition)), true));
                return(BlockList.ToArray());
            }
            //We didn't find the amount of free blocks required, meaning we're ref of
            //disk space
            if (BlockList.Count != blocksNeeded)
            {
                throw new Exception("Out of Xbox 360 hard disk space");
            }
            return(BlockList.ToArray());
        }
        //uint dicks(ref uint r3, ref uint r4, ref uint r6, ref uint r7, ref uint r8, ref uint r9, ref uint r10)
        //{

        //}

        public ulong GetFreeSpace()
        {
            // Our return
            ulong Return      = 0;
            ulong ClusterSize = (ulong)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);
        }