Exemplo n.º 1
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 void SetAtts(FATXPartition Part)
 {
     xPart = Part;
     fatType = xPart.FatType;
 }
Exemplo n.º 3
0
 public AllocationTable(DJsIO xIOIn, uint xCount, FATXType xType)
 {
     xAllocTable = xIOIn;
     BlockCount = xCount;
     PartitionType = xType;
 }
        public FATXEntry(FATXType fatType, long Pos, byte[] xData, ref FATXDrive xdrive)
        {
            FatEntry = new FATXEntry64(xData);

            this.fatType = fatType;
            this.xDrive = xdrive;
            this.xIsFolder = FatEntry.Attribute != 0xFF && ((FatEntry.Attribute & 0x10) == 0x10);
            this.xName = FatEntry.FileNameStr;
            this.xNLen = FatEntry.FileNameSize;

            this.xStartBlock = FatEntry.FirstCluster;
            this.xSize = FatEntry.FileSize;

            this.xT1 = FatEntry.ModDate;
            this.xT2 = FatEntry.CreateDate;
            this.xT3 = FatEntry.AccessedDate;

            this.fatType = fatType;
            xDrive = xdrive;
            xOffset = Pos;
            xIsValid = this.FatEntry.IsValid;
            /*
            try
            {
                DJsIO xIO = new DJsIO(xData, true);
                xNLen = xIO.ReadByte();
                if (xNLen == 0xE5 || xNLen == 0xFF || xNLen == 0 || xNLen > 0x2A)
                    return;
                byte xatt = (byte)((xIO.ReadByte() >> 4) & 1);
                byte xLen = (byte)(xNLen & 0x3F);
                xName = xIO.ReadString(StringForm.ASCII, xLen);
                xName.IsValidXboxName();
                xIO.Position = 0x2C;
                xStartBlock = xIO.ReadUInt32();
                if (fatType == FATXType.FATX32)
                {
                    if (xStartBlock == Constants.FATX32End)
                        return;
                }else if (fatType == FATXType.FATX16)
                {
                    if (xStartBlock == Constants.FATX16End)
                        return;
                }
                xSize = xIO.ReadInt32();
                xT1 = xIO.ReadInt32();
                xT2 = xIO.ReadInt32();
                xT3 = xIO.ReadInt32();
                if (xatt == 1)
                    xIsFolder = true;
                else if (xSize == 0)
                    return;
                xIsValid = true;
            }
            catch { xIsValid = false; }*/
        }
 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;
 }
        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--);
            }
        }
Exemplo n.º 7
0
 public AllocationTable(DJsIO xIOIn, uint xCount, FATXType xType)
 {
     xAllocTable   = xIOIn;
     BlockCount    = xCount;
     PartitionType = xType;
 }
Exemplo n.º 8
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--);
            }
        }