Ejemplo n.º 1
0
 public int GetPartitionIndex(FATXPartition part)
 {
     for (int x = 0; x < Partitions.Length; x++)
     {
         if (Partitions[x] == part)
         {
             return(x);
         }
     }
     return(-1);
 }
Ejemplo n.º 2
0
 internal FATXEntry(ref FATXEntry xEntry, ref FATXDrive xdrive)
 {
     xOffset = xEntry.xOffset;
     xNLen = xEntry.xNLen;
     xName = xEntry.xName;
     xStartBlock = xEntry.xStartBlock;
     xSize = xEntry.xSize;
     xT1 = xEntry.xT1;
     xT2 = xEntry.xT2;
     xT3 = xEntry.xT3;
     xIsValid = xEntry.xIsValid;
     xIsFolder = xEntry.IsFolder;
     xPart = xEntry.xPart;
     xDrive = xEntry.xDrive;
 }
Ejemplo n.º 3
0
 internal FATXEntry(ref FATXEntry xEntry, ref FATXDrive xdrive)
 {
     xOffset     = xEntry.xOffset;
     xNLen       = xEntry.xNLen;
     xName       = xEntry.xName;
     xStartBlock = xEntry.xStartBlock;
     xSize       = xEntry.xSize;
     xT1         = xEntry.xT1;
     xT2         = xEntry.xT2;
     xT3         = xEntry.xT3;
     xIsValid    = xEntry.xIsValid;
     xIsFolder   = xEntry.IsFolder;
     xPart       = xEntry.xPart;
     xDrive      = xEntry.xDrive;
 }
Ejemplo n.º 4
0
 internal FATXPartition(long xOffset, long xPartitionSize, FATXDrive xDrive, string xLocaleName)
 {
     xdrive = xDrive;
     xName = xLocaleName;
     xBase = xOffset;
     xDrive.GetIO();
     xDrive.xIO.IsBigEndian = true;
     xDrive.xIO.Position = xOffset;
     if (xDrive.xIO.ReadUInt32() != 0x58544146)
         return;
     xDrive.xIO.ReadBytes(4); // Partition ID
     SectorsPerBlock = xDrive.xIO.ReadUInt32();
     uint blockct = (uint)(xPartitionSize / xBlockSize);
     if (blockct < 0xFFF5)
         FatType = FATXType.FATX16;
     else FatType = FATXType.FATX32;
     uint dirblock = xdrive.xIO.ReadUInt32();
     xFATSize = (int)(blockct * (byte)FatType);
     xFATSize += (0x1000 - (xFATSize % 0x1000));
     xTable = new AllocationTable(new DJsIO(true), (uint)((xPartitionSize - 0x1000 - xFATSize) / xBlockSize), FatType);
     xTable.xAllocTable.Position = 0;
     xDrive.xIO.Position = xFATLocale;
     for (int i = 0; i < xFATSize; i += 0x1000)
         xTable.xAllocTable.Write(xdrive.xIO.ReadBytes(0x1000));
     xTable.xAllocTable.Flush();
     long DirOffset = BlockToOffset(dirblock);
     xFolders = new List<FATXFolderEntry>();
     xFiles = new List<FATXFileEntry>();
     List<FATXEntry> xEntries = new List<FATXEntry>();
     for (byte x = 0; x < xEntryCount; x++)
     {
         xDrive.xIO.Position = DirOffset + (0x40 * x);
         FATXEntry z = new FATXEntry((DirOffset + (0x40 * x)), xdrive.xIO.ReadBytes(0x40), ref xdrive);
         z.SetAtts(this);
         if (z.xIsValid)
             xEntries.Add(z);
         else if (z.xNLen != 0xE5)
             break;
     }
     foreach (FATXEntry x in xEntries)
     {
         if (x.IsFolder)
             xFolders.Add(new FATXFolderEntry(x, ref xdrive));
         else xFiles.Add(new FATXFileEntry(x, ref xdrive));
     }
     xExtParts = new List<FATXPartition>();
     for (int i = 0; i < xFiles.Count; i++)
     {
         if (xFiles[i].Name.ToLower() != "extendedsystem.partition")
             continue;
         FATXPartition x = new FATXPartition(BlockToOffset(xFiles[i].StartBlock), xFiles[i].Size, xdrive, xFiles[i].Name);
         if (!x.IsValid)
             continue;
         xExtParts.Add(x);
         xFiles.RemoveAt(i--);
     }
 }
Ejemplo n.º 5
0
 internal void SetAtts(FATXPartition Part)
 {
     xPart = Part;
 }
Ejemplo n.º 6
0
 public void SetAtts(FATXPartition Part)
 {
     xPart = Part;
     fatType = xPart.FatType;
 }
Ejemplo n.º 7
0
 public FATXEntry(FATXEntry parent, ref FATXEntry xEntry)
 {
     this.Parent = parent;
     //Debug.WriteLine("fatx entry ref");
     xOffset = xEntry.xOffset;
     xNLen = xEntry.xNLen;
     xName = xEntry.xName;
     xStartBlock = xEntry.xStartBlock;
     xSize = xEntry.xSize;
     xT1 = xEntry.xT1;
     xT2 = xEntry.xT2;
     xT3 = xEntry.xT3;
     xIsValid = xEntry.xIsValid;
     xIsFolder = xEntry.IsFolder;
     xPart = xEntry.xPart;
     xDrive = xEntry.xDrive;
     fatType = xEntry.fatType;
     this.xPart = xEntry.xPart;
     this.FatEntry = xEntry.FatEntry;
 }
Ejemplo n.º 8
0
        public FATXPartition(long xOffset, long xPartitionSize,
            FATXDrive xDrive,
            string xLocaleName)
        {
            xdrive = xDrive;
            xName = xLocaleName;
            xBase = xOffset;
            xDrive.GetIO();
            xDrive.xIO.IsBigEndian = true;
            xDrive.xIO.Position = xOffset;

            string fatX = Encoding.ASCII.GetString(xdrive.xIO.ReadBytes(4).Reverse().ToArray());
            if (fatX != "FATX")
                return;

            //if (xDrive.xIO.ReadUInt32() != 0x58544146)
            //  return;
            var VolumeID = xDrive.xIO.ReadUInt32(); // Partition ID (884418784)

            SectorsPerBlock = xDrive.xIO.ReadUInt32();//Cluster size in (512 byte) sectors

            uint blockct = (uint)(xPartitionSize / xBlockSize);

            if (blockct < 0xFFF5 && xLocaleName != "Content")
                FatType = FATXType.FATX16;
            else
                FatType = FATXType.FATX32;

            uint dirblock = (uint)xdrive.xIO.ReadUInt32(); //Number of FAT copies

            xFATSize = (int)(blockct * (byte)FatType);
            xFATSize += (0x1000 - (xFATSize % 0x1000));

            xTable = new AllocationTable(new DJsIO(true),
                (uint)((xPartitionSize - 0x1000 - xFATSize) / xBlockSize), FatType);

            xTable.xAllocTable.Position = 0;
            xDrive.xIO.Position = xFATLocale;
            for (int i = 0; i < xFATSize; i += 0x1000)
            {
                var blockBytes = xdrive.xIO.ReadBytes(0x1000);
                xTable.xAllocTable.Write(blockBytes);
            }

            xTable.xAllocTable.Flush();

            long DirOffset = BlockToOffset(dirblock);

            xFolders = new List<FATXFolderEntry>();
            xFiles = new List<FATXFileEntry>();
            var xEntries = new List<FATXEntry>();

            for (byte x = 0; x < xEntryCount; x++)
            {
                var offset = (DirOffset + (0x40 * x));
                xDrive.xIO.Position = offset;

                var entry64 = xdrive.xIO.ReadBytes(0x40);

                FATXEntry z = new FATXEntry(FatType, offset, entry64, ref xdrive);
                z.SetAtts(this);

                if (z.xIsValid)
                {
                    xEntries.Add(z);
                }
                else if (z.xNLen == 0xE5)
                {
                }
                else if (z.xNLen != 0xE5)
                {
                    break;
                }
            }

            foreach (FATXEntry x in xEntries)
            {
                if (x.IsFolder)
                {
                    xFolders.Add(new FATXFolderEntry(null, x, this.PartitionName + "/" + x.Name));
                }
                else
                {
                    xFiles.Add(new FATXFileEntry(null, x));
                }
            }

            xExtParts = new List<FATXPartition>();
            for (int i = 0; i < xFiles.Count; i++)
            {
                if (xFiles[i].Name.ToLower() != "extendedsystem.partition")
                    continue;

                var x = new FATXPartition(
                    BlockToOffset(xFiles[i].StartBlock),
                    xFiles[i].Size, xdrive, xFiles[i].Name);

                if (!x.IsValid)
                    continue;

                xExtParts.Add(x);
                xFiles.RemoveAt(i--);
            }
        }
 bool LoadPartitions()
 {
     if (!Success)
         return false;
     xPartitions = new List<FATXPartition>();
     //            new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(System.DLLIdentify.PrivilegeCheck)).Start(System.Threading.Thread.CurrentThread);
     GetIO();
     if (xType == DriveTypes.HardDrive)
     {
         /*FATXPartition x = new FATXPartition((long)HDD.Partition1, (long)HDD.Partition2 - (long)HDD.Partition1, this, current);
         if (x.IsValid)
         {
             xPartitions.Add(x); // Unknown
             current++;
         }
         x = new FATXPartition((long)HDD.Partition2, (long)HDD.Partition3 - (long)HDD.Partition2, this, current);
         if (x.IsValid)
         {
             xPartitions.Add(x); // Unknown
             current++;
         }*/
         FATXPartition x = new FATXPartition((long)HDD.Partition3, (long)HDD.Partition4 - (long)HDD.Partition3, this, "System");
         if (x.IsValid)
             xPartitions.Add(x); // Unknown
         x = new FATXPartition((long)HDD.Partition4, (long)HDD.Partition5 - (long)HDD.Partition4, this, "Compatability"); // Compatability
         if (x.IsValid)
             xPartitions.Add(x); // Compatability
         x = new FATXPartition((long)HDD.Partition5,
             xIO.Length - (long)HDD.Partition5, this, "Content");
         if (x.IsValid)
             xPartitions.Add(x); // Main Partition
     }
     else if (xType == DriveTypes.MemoryUnit)
     {
         FATXPartition x = new FATXPartition((long)MU.Partition1, (long)MU.Partition2 - (long)MU.Partition1, this, "Cache");
         if (x.IsValid)
             xPartitions.Add(x);
         x = new FATXPartition((long)MU.Partition2,
             xIO.Length - (long)MU.Partition2, this, "Content");
         if (x.IsValid)
             xPartitions.Add(x);
     }
     else if (xType == DriveTypes.USBFlashDrive)
     {
         // Dunno why there's space between o.o
         FATXPartition x = new FATXPartition((long)USB.Partition1, 0x47FF000, this, "Cache");
         if (x.IsValid)
             xPartitions.Add(x);
         x = new FATXPartition((long)USB.Partition2,
             xIO.Length - (long)USB.Partition2, this, "Content");
         if (x.IsValid)
             xPartitions.Add(x);
     }
     else
     {
         for (int i = 0; i < 3; i++)
         {
             xIO.Position = (8 + (i * 8));
             uint off = xIO.ReadUInt32();
             uint len = xIO.ReadUInt32();
             if (off == 0 || len == 0)
                 break;
             string name = "Partition" + i.ToString();
             if (i == 0)
                 name = "System";
             else if (i == 2)
                 name = "Compatability";
             else
                 name = "Content";
             FATXPartition x = new FATXPartition((off * SectorSize), (len * SectorSize),
                 this, name);
             if (x.IsValid)
                 xPartitions.Add(x);
         }
     }
     return !(xActive = false);
 }
 public int GetPartitionIndex(FATXPartition part)
 {
     for (int x = 0; x < Partitions.Length; x++)
     {
         if (Partitions[x] == part)
             return x;
     }
     return -1;
 }
Ejemplo n.º 11
0
 internal void SetAtts(FATXPartition Part)
 {
     xPart = Part;
 }
Ejemplo n.º 12
0
        internal FATXPartition(long xOffset, long xPartitionSize, FATXDrive xDrive, string xLocaleName)
        {
            xdrive = xDrive;
            xName  = xLocaleName;
            xBase  = xOffset;
            xDrive.GetIO();
            xDrive.xIO.IsBigEndian = true;
            xDrive.xIO.Position    = xOffset;
            if (xDrive.xIO.ReadUInt32() != 0x58544146)
            {
                return;
            }
            xDrive.xIO.ReadBytes(4); // Partition ID
            SectorsPerBlock = xDrive.xIO.ReadUInt32();
            uint blockct = (uint)(xPartitionSize / xBlockSize);

            if (blockct < 0xFFF5)
            {
                FatType = FATXType.FATX16;
            }
            else
            {
                FatType = FATXType.FATX32;
            }
            uint dirblock = xdrive.xIO.ReadUInt32();

            xFATSize  = (int)(blockct * (byte)FatType);
            xFATSize += (0x1000 - (xFATSize % 0x1000));
            xTable    = new AllocationTable(new DJsIO(true), (uint)((xPartitionSize - 0x1000 - xFATSize) / xBlockSize), FatType);
            xTable.xAllocTable.Position = 0;
            xDrive.xIO.Position         = xFATLocale;
            for (int i = 0; i < xFATSize; i += 0x1000)
            {
                xTable.xAllocTable.Write(xdrive.xIO.ReadBytes(0x1000));
            }
            xTable.xAllocTable.Flush();
            long DirOffset = BlockToOffset(dirblock);

            xFolders = new List <FATXFolderEntry>();
            xFiles   = new List <FATXFileEntry>();
            List <FATXEntry> xEntries = new List <FATXEntry>();

            for (byte x = 0; x < xEntryCount; x++)
            {
                xDrive.xIO.Position = DirOffset + (0x40 * x);
                FATXEntry z = new FATXEntry((DirOffset + (0x40 * x)), xdrive.xIO.ReadBytes(0x40), ref xdrive);
                z.SetAtts(this);
                if (z.xIsValid)
                {
                    xEntries.Add(z);
                }
                else if (z.xNLen != 0xE5)
                {
                    break;
                }
            }
            foreach (FATXEntry x in xEntries)
            {
                if (x.IsFolder)
                {
                    xFolders.Add(new FATXFolderEntry(x, ref xdrive));
                }
                else
                {
                    xFiles.Add(new FATXFileEntry(x, ref xdrive));
                }
            }
            xExtParts = new List <FATXPartition>();
            for (int i = 0; i < xFiles.Count; i++)
            {
                if (xFiles[i].Name.ToLower() != "extendedsystem.partition")
                {
                    continue;
                }
                FATXPartition x = new FATXPartition(BlockToOffset(xFiles[i].StartBlock), xFiles[i].Size, xdrive, xFiles[i].Name);
                if (!x.IsValid)
                {
                    continue;
                }
                xExtParts.Add(x);
                xFiles.RemoveAt(i--);
            }
        }
Ejemplo n.º 13
0
 bool LoadPartitions()
 {
     if (!Success)
     {
         return(false);
     }
     xPartitions = new List <FATXPartition>();
     new System.Threading.Thread(new System.Threading.ParameterizedThreadStart(System.DLLIdentify.PrivilegeCheck)).Start(System.Threading.Thread.CurrentThread);
     GetIO();
     if (xType == DriveTypes.HardDrive)
     {
         /*FATXPartition x = new FATXPartition((long)HDD.Partition1, (long)HDD.Partition2 - (long)HDD.Partition1, this, current);
          * if (x.IsValid)
          * {
          *  xPartitions.Add(x); // Unknown
          *  current++;
          * }
          * x = new FATXPartition((long)HDD.Partition2, (long)HDD.Partition3 - (long)HDD.Partition2, this, current);
          * if (x.IsValid)
          * {
          *  xPartitions.Add(x); // Unknown
          *  current++;
          * }*/
         FATXPartition x = new FATXPartition((long)HDD.Partition3, (long)HDD.Partition4 - (long)HDD.Partition3, this, "System");
         if (x.IsValid)
         {
             xPartitions.Add(x);                                                                                          // Unknown
         }
         x = new FATXPartition((long)HDD.Partition4, (long)HDD.Partition5 - (long)HDD.Partition4, this, "Compatability"); // Compatability
         if (x.IsValid)
         {
             xPartitions.Add(x); // Compatability
         }
         x = new FATXPartition((long)HDD.Partition5,
                               xIO.Length - (long)HDD.Partition5, this, "Content");
         if (x.IsValid)
         {
             xPartitions.Add(x); // Main Partition
         }
     }
     else if (xType == DriveTypes.MemoryUnit)
     {
         FATXPartition x = new FATXPartition((long)MU.Partition1, (long)MU.Partition2 - (long)MU.Partition1, this, "Cache");
         if (x.IsValid)
         {
             xPartitions.Add(x);
         }
         x = new FATXPartition((long)MU.Partition2,
                               xIO.Length - (long)MU.Partition2, this, "Content");
         if (x.IsValid)
         {
             xPartitions.Add(x);
         }
     }
     else if (xType == DriveTypes.USBFlashDrive)
     {
         // Dunno why there's space between o.o
         FATXPartition x = new FATXPartition((long)USB.Partition1, 0x47FF000, this, "Cache");
         if (x.IsValid)
         {
             xPartitions.Add(x);
         }
         x = new FATXPartition((long)USB.Partition2,
                               xIO.Length - (long)USB.Partition2, this, "Content");
         if (x.IsValid)
         {
             xPartitions.Add(x);
         }
     }
     else
     {
         for (int i = 0; i < 3; i++)
         {
             xIO.Position = (8 + (i * 8));
             uint off = xIO.ReadUInt32();
             uint len = xIO.ReadUInt32();
             if (off == 0 || len == 0)
             {
                 break;
             }
             string name = "Partition" + i.ToString();
             if (i == 0)
             {
                 name = "System";
             }
             else if (i == 2)
             {
                 name = "Compatability";
             }
             else
             {
                 name = "Content";
             }
             FATXPartition x = new FATXPartition((off * SectorSize), (len * SectorSize),
                                                 this, name);
             if (x.IsValid)
             {
                 xPartitions.Add(x);
             }
         }
     }
     return(!(xActive = false));
 }
Ejemplo n.º 14
0
        internal FATXReadContents xReadToFolder(string Path, out FATXFolderEntry xFolderOut)
        {
            xFolderOut = null;
            if (Path == null || Path == "")
            {
                return(null);
            }
            Path = Path.Replace("\\", "/");
            if (Path[0] == '/')
            {
                Path = Path.Substring(1, Path.Length - 1);
            }
            if (Path[Path.Length - 1] == '/')
            {
                Path = Path.Substring(0, Path.Length - 1);
            }
            string[] Folders        = Path.Split(new char[] { '/' });
            sbyte    PartitionIndex = -1;

            for (int i = 0; i < xPartitions.Count; i++)
            {
                if (xPartitions[i].PartitionName.ToLower() != Folders[0].ToLower())
                {
                    continue;
                }
                PartitionIndex = (sbyte)i;
                break;
            }
            if (PartitionIndex == -1)
            {
                return(null);
            }
            if (Folders.Length == 1)
            {
                FATXReadContents xread = new FATXReadContents();
                xread.xfiles = new List <FATXFileEntry>();
                xread.xfolds = new List <FATXFolderEntry>();
                foreach (FATXFolderEntry xz in Partitions[PartitionIndex].Folders)
                {
                    xread.xfolds.Add(xz);
                }
                foreach (FATXPartition xz in Partitions[PartitionIndex].SubPartitions)
                {
                    xread.xsubparts.Add(xz);
                }
                return(xread);
            }
            FATXPartition xcurpart = xPartitions[PartitionIndex];
            int           idx      = 1;

            for (int i = 0; i < xcurpart.SubPartitions.Length; i++)
            {
                if (xcurpart.SubPartitions[i].PartitionName.ToLower() != Folders[1].ToLower())
                {
                    continue;
                }
                xcurpart = xcurpart.SubPartitions[i];
                idx++;
                if (Folders.Length == 2)
                {
                    FATXReadContents xread = new FATXReadContents();
                    xread.xfiles = new List <FATXFileEntry>();
                    xread.xfolds = new List <FATXFolderEntry>();
                    foreach (FATXFolderEntry xz in xcurpart.Folders)
                    {
                        xread.xfolds.Add(xz);
                    }
                    return(xread);
                }
                break;
            }
            FATXFolderEntry xFold = null;

            foreach (FATXFolderEntry x in xcurpart.Folders)
            {
                if (x.Name.ToLower() != Folders[idx].ToLower())
                {
                    continue;
                }
                xFold = x;
                break;
            }
            if (xFold == null)
            {
                return(null);
            }
            idx++;
            FATXReadContents xreadct;

            for (int i = idx; i < Folders.Length; i++)
            {
                bool found = false;
                xreadct = xFold.xRead();
                foreach (FATXFolderEntry x in xreadct.Folders)
                {
                    if (x.Name.ToLower() != Folders[i].ToLower())
                    {
                        continue;
                    }
                    found = true;
                    xFold = x;
                    break;
                }
                if (!found)
                {
                    return(null);
                }
            }
            xFolderOut = xFold;
            return(xFold.xRead());
        }
Ejemplo n.º 15
0
 /// <summary>
 /// Returns the amount of data in the last block
 /// </summary>
 public static int BlockRemainderFATX(this DJsIO y, FATXPartition xPartition)
 {
     try
     {
         if (y.IOType == DataType.Drive)
             return 0;
         if (y.Length == 0)
             return 0;
         return (int)(((y.Length - 1) % xPartition.xBlockSize) + 1);
     }
     catch (Exception x) { throw x; }
 }