Example #1
0
 public bool ClearFATChain(uint[] Blocks, Entry e)
 {
     for (int i = 0; i < Blocks.Length; i++)
     {
         //Open our binary reader to read our buffer
         FATX_Browser.FATX.IOReader br = ourDrive.GetIO();
         //Get the position we should be at for our buffer
         long BufferOffset = m.DownToNearest200(m.BlockToFATOffset(Blocks[i], e));
         //Set our position to the buffer offset
         br.BaseStream.Position = BufferOffset;
         //Read our buffer
         byte[] Buffer = br.ReadBytes(0x200);
         //Close our reader -- we don't need it any more
         br.Close();
         //Open our binary writer in to a memory stream
         FATX_Browser.FATX.IOWriter bw = new FATX_Browser.FATX.IOWriter(new System.IO.MemoryStream(Buffer));
         //Set our position in the buffer to where the actual block is
         bw.BaseStream.Position = m.BlockToFATOffset(Blocks[i], e) - BufferOffset;
         //Write out free block
         if (e.PartInfo.EntrySize == Info.PartitionBit.FATX16)
         {
             bw.Write(new byte[] { 0x00, 0x00 });
         }
         else
         {
             bw.Write(new byte[] { 0x00, 0x00 });
         }
         //Close our binary writer
         bw.Close();
         //Check to see if we can write out more blocks from within the buffer, so we
         //don't have to re-read what we already have
         i += CheckWriteBuffDel(ref Buffer, BufferOffset, Blocks, i + 1, e);
         //Re-open our binary writer, on the drive
         bw = ourDrive.GetWriterIO();
         //Set the position
         bw.BaseStream.Position = BufferOffset;
         //Write out the buffer
         bw.Write(Buffer);
         bw.Close();
     }
     return true;
 }
Example #2
0
 public long BlockToFATOffset(uint BaseBlock, Entry e)
 {
     return BlockToFATOffset(BaseBlock, e.PartInfo);
 }
Example #3
0
 /// <summary>
 /// Converts cluster (block) number to offset
 /// </summary>
 public long GetBlockOffset(uint block, Entry e)
 {
     return GetBlockOffset(block, e.PartInfo);
 }
Example #4
0
        private bool WriteFATChain(uint[] blocksOccupied, Entry e)
        {
            //Foreach block in our blocks occupied
            for (int i = 0; i < blocksOccupied.Length; i++)
            {
                //Get the value of the block
                uint block = blocksOccupied[i];
                //Create our byte array for our pointer to the next block
                byte[] Bytes = new byte[0];
                //If we have reached the last block in the array...
                if (i == blocksOccupied.Length - 1)
                {
                    //We need to write out that it's the last block, so we do so by writing 0xFF (in accordance to entry size)
                    if (e.PartInfo.EntrySize == Info.PartitionBit.FATX16)
                    {
                        //EOB (end of blocks) for FATX16...
                        Bytes = new byte[] { 0xFF, 0xFF };
                    }
                    else
                    {
                        //EOB for FATX32
                        Bytes = new byte[] { 0xFF, 0xFF, 0xFF, 0xFF };
                    }
                }
                //We have not reached the end block
                else
                {
                    Bytes = BitConverter.GetBytes(blocksOccupied[i + 1]);
                    //Reverse the array so that it will be big endian
                    Array.Reverse(Bytes);
                }

                #region Bascially the WriteBlock Function, modified to check for the next block within the same buffer
                //Write out our next block's byte array at the block's position in the FAT
                //Create our binary reader
                FATX_Browser.FATX.IOReader br = ourDrive.GetIO();
                //Set our position to the block offset in the FAT
                br.BaseStream.Position = m.DownToNearest200(m.BlockToFATOffset(block, e));
                //Get our position in the buffer
                long OffsetInBuffer = m.BlockToFATOffset(block, e) - br.BaseStream.Position;
                //Read our buffer
                byte[] buffer = br.ReadBytes(0x200);
                //Close our binary reader - we're done with it for the drive for now
                br.Close();
                //Create our binary writer for writing to the buffer
                FATX_Browser.FATX.IOWriter bw = new FATX_Browser.FATX.IOWriter(new System.IO.MemoryStream(buffer));
                //Set our position
                bw.BaseStream.Position = OffsetInBuffer;
                //Write our block
                bw.Write(Bytes);
                bw.Close();
                if (!m.EOF(Bytes, false))
                {
                    i += CheckWriteBuff(ref buffer, m.DownToNearest200(m.BlockToFATOffset(block, e)), blocksOccupied, i + 1, e);
                }
                //Re-open our binary writer in the drive
                bw = ourDrive.GetWriterIO();
                //Set our position
                bw.BaseStream.Position = m.DownToNearest200(m.BlockToFATOffset(block, e));
                //Write our buffer
                bw.Write(buffer);
            #endregion
            }
            return true;
        }
Example #5
0
 ///We need to make the writing of the blocks and shit little endian so that it will
 ///write it in big endian.  what the f**k.
 //For some reason is the function that writes a FAT chain
 private bool WriteBlock(uint ui, byte[] value, Entry e)
 {
     //Create our binary reader
     FATX_Browser.FATX.IOReader br = ourDrive.GetIO();
     //Set our position to the block offset in the FAT
     br.BaseStream.Position = m.DownToNearest200(m.BlockToFATOffset(ui, e));
     //Get our position in the buffer
     long OffsetInBuffer = m.BlockToFATOffset(ui, e) - br.BaseStream.Position;
     //Read our buffer
     byte[] buffer = br.ReadBytes(0x200);
     //Close our binary reader - we're done with it for the drive for now
     br.Close();
     //Create our binary writer for writing to the buffer
     FATX_Browser.FATX.IOWriter bw = new FATX_Browser.FATX.IOWriter(new System.IO.MemoryStream(buffer));
     //Set our position
     bw.BaseStream.Position = OffsetInBuffer;
     //Write our block
     bw.Write(value);
     bw.Close();
     //Re-open our binary writer in the drive
     bw = ourDrive.GetWriterIO();
     //Set our position
     bw.BaseStream.Position = m.DownToNearest200(m.BlockToFATOffset(ui, e));
     //Write our buffer
     bw.Write(buffer);
     return true;
 }
Example #6
0
 private bool MarkEntryAsDeleted(Entry e)
 {
     FATX_Browser.FATX.IOReader br = ourDrive.GetIO();
     long position = m.DownToNearest200(e.EntryOffset);
     //Get our offset in our buffer
     long OffsetInBuffer = e.EntryOffset - position;
     br.BaseStream.Position = position;
     //Read our buffer
     byte[] buffer = br.ReadBytes(0x200);
     //Close our binary reader - not needed now
     br.Close();
     //Create our binary writer
     FATX_Browser.FATX.IOWriter bw = new FATX_Browser.FATX.IOWriter(new System.IO.MemoryStream(buffer));
     //Seek to the position in the buffer
     bw.BaseStream.Position = OffsetInBuffer;
     //Write the flag
     bw.Write((byte)Info.FileFlags.Deleted);
     //Close our binary writer
     bw.Close();
     //Re-open our binary writer for the drive
     bw = ourDrive.GetWriterIO();
     //Set our position
     bw.BaseStream.Position = m.DownToNearest200(e.EntryOffset);
     //Write out our buffer
     bw.Write(buffer);
     return true;
 }
Example #7
0
 private int CheckWriteBuffDel(ref byte[] Buffer, long BufferOffset, uint[] allBlocks, int index, Entry e)
 {
     //This will be our return value so that we can tell our other function how
     //many blocks were written
     int blocksWritten = 0;
     //If the offset for the next block's buffer is the same as our current buffer's offset
     if (m.DownToNearest200(m.BlockToFATOffset(allBlocks[index], e)) == BufferOffset)
     {
         //Get our offset in our buffer for the block we're writing to
         long OffsetinBuffer = m.BlockToFATOffset(allBlocks[index], e) - BufferOffset;
         //Create our binary writer
         FATX_Browser.FATX.IOWriter bw = new FATX_Browser.FATX.IOWriter(new System.IO.MemoryStream(Buffer));
         //Go to the offset in the buffer
         bw.BaseStream.Position = OffsetinBuffer;
         //Create our byte array (we do new byte[1] just as a placeholder)
         byte[] BlocktoWrite = new byte[1];
         //If we're on a 2-byte block entry
         if (e.PartInfo.EntrySize == Info.PartitionBit.FATX16)
         {
             //Our block to write is the ending block
             BlocktoWrite = new byte[] { 0x00, 0x00 };
         }
         else
         {
             //Our block to write is the ending block
             BlocktoWrite = new byte[] { 0x00, 0x00, 0x00, 0x00 };
         }
         //Write out our array
         bw.Write(BlocktoWrite);
         //Close our writer
         bw.Close();
         //If we didn't just write the last block...
         if (index != allBlocks.Length - 1)
         {
             //Repeat
             blocksWritten += CheckWriteBuff(ref Buffer, BufferOffset, allBlocks, index + blocksWritten, e);
         }
     }
     return blocksWritten;
 }
Example #8
0
 public bool Rename(Entry e, string newName)
 {
     return Rename(e.EntryOffset, newName);
 }
Example #9
0
 public Entries(Entry e)
 {
     Partition = e.PartInfo;
     Holder = e;
     EntrySize =(int) e.PartInfo.EntrySize;
     bit = e.PartInfo.EntrySize;
 }
Example #10
0
 /// <summary>
 /// Provides partition/FAT information
 /// </summary>
 public FATStuff(Entry entry)
 {
     ourDrive = (FATXDrive)entry.Drive;
     Partition = entry.PartInfo;
 }