Esempio n. 1
0
 internal bool WriteFile(uint[] xChain, ref DJsIO xIOIn)
 {
     try
     {
         xdrive.GetIO();
         for (int i = 0; i < xChain.Length; i++)
         {
             xdrive.xIO.Position = BlockToOffset(xChain[i]);
             xIOIn.Position      = (i * xBlockSize);
             xdrive.xIO.Write(xIOIn.ReadBytes(xBlockSize));
             xdrive.xIO.Flush();
         }
         return(true);
     }
     catch { return(false); }
 }
Esempio n. 2
0
 internal bool xWriteEntry()
 {
     try
     {
         byte[] xdata = GetData();
         xDrive.GetIO();
         xDrive.xIO.Position = xOffset;
         xDrive.xIO.Write(xdata);
         return(true);
     }
     catch { return(false); }
 }
Esempio n. 3
0
        void rstthrd(object drv)
        {
            FATXDrive xImageDrive = (FATXDrive)drv;

            xImageDrive.GetIO();
            GetIO();
            xIO.Position = xImageDrive.xIO.Position = 0;
            for (long i = 0; i < xIO.Length && i < xImageDrive.xIO.Length; i += 0x1000)
            {
                xIO.unbufferedwrite(xImageDrive.xIO.ReadBytes(0x1000));
            }
        }
Esempio 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--);
     }
 }
        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--);
            }
        }
Esempio n. 6
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--);
            }
        }