예제 #1
0
 public bool CreateNewEntry(EntryData Edata)
 {
     FATX_Browser.FATX.IOReader br = ourDrive.GetIO();
     //Set our position so that we can read the entry location
     br.BaseStream.Position = m.DownToNearest200(Edata.EntryOffset);
     byte[] buffer = br.ReadBytes(0x200);
     br.Close();
     //Create our binary writer
     FATX_Browser.FATX.IOWriter bw = new FATX_Browser.FATX.IOWriter(new System.IO.MemoryStream(buffer));
     //Set our position to where the entry is
     long EntryOffset = Edata.EntryOffset - m.DownToNearest200(Edata.EntryOffset);
     bw.BaseStream.Position = EntryOffset;
     //Write our entry
     bw.Write(Edata.FileNameSize);
     bw.Write(Edata.Flags);
     bw.Write(Encoding.ASCII.GetBytes(Edata.FileName));
     bw.BaseStream.Position = EntryOffset + 0x2C;
     //Right here, we need to make everything a byte array, as it feels like writing
     //everything in little endian for some reason...
     byte[] StartingCluster = BitConverter.GetBytes(Edata.StartingCluster);
     Array.Reverse(StartingCluster);
     bw.Write(StartingCluster);
     byte[] Size = BitConverter.GetBytes(Edata.Size);
     Array.Reverse(Size);
     bw.Write(Size);
     //Write out the creation date 6 times
     byte[] CreationDate = BitConverter.GetBytes(Edata.CreationDate);
     byte[] CreationTime = BitConverter.GetBytes(Edata.CreationTime);
     Array.Reverse(CreationDate);
     Array.Reverse(CreationTime);
     for (int i = 0; i < 3; i++)
     {
         bw.Write(CreationDate);
         bw.Write(CreationTime);
     }
     //Close our writer
     bw.Close();
     //Get our IO
     bw = ourDrive.GetWriterIO();
     bw.BaseStream.Position = m.DownToNearest200(Edata.EntryOffset);
     //Write out our buffer
     bw.Write(buffer);
     return true;
 }
예제 #2
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;
 }
예제 #3
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;
        }
예제 #4
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;
 }
예제 #5
0
 private bool Rename(long entryOffset, string newName)
 {
     if (m.CheckFileName(newName))
     {
         //Create our binary reader/writer
         FATX_Browser.FATX.IOReader br = ourDrive.GetIO();
         //Round our offset down to the nearest 0x200 boundary so we can read
         //the entry
         //Set our reader to do the same thing
         br.BaseStream.Position = m.DownToNearest200(entryOffset);
         //Split the difference so we can see how far in to our buffer
         //we need to be
         long offsetInBuffer = entryOffset - (m.DownToNearest200(entryOffset));
         //Create our buffer
         byte[] buffer = br.ReadBytes(0x200);
         //Close our reader - we don't need it any more
         br.Close();
         //Create a new binary reader that reads the buffer in memory
         FATX_Browser.FATX.IOWriter memWriter = new FATX_Browser.FATX.IOWriter(new System.IO.MemoryStream(buffer));
         //Set our position to the entry position
         memWriter.BaseStream.Position = offsetInBuffer;
         //Write the file name size
         memWriter.Write((byte)newName.Length);
         //Jump forward one byte and clear the old name
         memWriter.BaseStream.Position++;
         for (int i = 0; i < 0x2A; i++)
         {
             memWriter.Write((byte)0xFF);
         }
         //Go back to where the file name is
         memWriter.BaseStream.Position = offsetInBuffer + 0x2;
         //Write the new name
         memWriter.Write((byte[])Encoding.ASCII.GetBytes(newName));
         memWriter.Close();
         //Open / set our writer's stuff
         FATX_Browser.FATX.IOWriter bw = ourDrive.GetWriterIO();
         bw.BaseStream.Position = m.DownToNearest200(entryOffset);
         //Write our edited buffer to the drive
         bw.Write((byte[])buffer);
         bw.Close();
         return true;
     }
     else
     {
         throw new Exception("File name not valid");
     }
 }
예제 #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;
 }
예제 #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;
 }
예제 #8
0
파일: Read.cs 프로젝트: madforumz/XbxEditor
 /// <summary>
 /// Extracts your file to the specified path
 /// </summary>
 /// <param name="f">File to extract</param>
 /// <param name="path">Path to extract the file to</param>
 /// <param name="sizeWritten">Used for updating progress on the file(not necessary)</param>
 /// <param name="maxVal">Used for updating the file size (not necessary)</param>
 public bool ExtractFile(File f, string path, ref long sizeWritten, ref long maxVal)
 {
     //try
        // {
         Misc m = new Misc();
         //Create our binary writer
         FATX_Browser.FATX.IOWriter bw = new FATX_Browser.FATX.IOWriter(new System.IO.FileStream(path, System.IO.FileMode.Create));
         //Set our maxVal
         maxVal = f.Block;
         sizeWritten = 0;
         return ExtractFileInternal(f, bw, ref sizeWritten, ref maxVal);
        // }
     //catch { return false; }
 }