Exemplo n.º 1
0
 /// <summary>
 /// Used for quickly reading bytes for a length that is not a multiple of 0x200
 /// </summary>
 internal byte[] ReadBytes(ref FATX_Browser.FATX.IOReader br, long length)
 {
     Misc m = new Misc();
     m.UpToNearest200(length);
     byte[] buffer = br.ReadBytes((int)length);
     List<byte> bl = buffer.ToList<byte>();
     bl.RemoveRange((int)(length - 1), (int)(buffer.Length - length));
     buffer = bl.ToArray();
     return buffer;
 }
Exemplo n.º 2
0
 /// <summary>
 /// ReadUInt32 (big endian)
 /// </summary>
 public uint ReadUInt32(ref FATX_Browser.FATX.IOReader br)
 {
     byte[] bytes = br.ReadBytes(0x4);
     Array.Reverse(bytes);
     return BitConverter.ToUInt32(bytes, 0x0);
 }
Exemplo n.º 3
0
 /// <summary>
 /// Returns EntryData for an entry in a block
 /// </summary>
 /// <param name="br">The binary reader to use</param>
 /// <param name="EntryBlock">The entry in the block to read</param>
 /// <param name="Block">The block to read from</param>
 internal EntryData GetEData(long originalOffset, FATX_Browser.FATX.IOReader br, uint EntryBlock, uint Block)
 {
     Misc r = new Misc();
     //br.BaseStream.Position = 0x131229000;//(r.GetBlockOffset(Block, Partition, DeviceID)) + (0x40 * EntryBlock);
     //Create our return
     EntryData data = new EntryData();
     //Read our variables
     data.EntryOffset = originalOffset + br.BaseStream.Position;
     data.FileNameSize = br.ReadByte();
     data.Flags = br.ReadByte();
     data.FileName = Encoding.ASCII.GetString(br.ReadBytes((int)data.FileNameSize));
     //Go to the end of the name to continue reading the variables
     br.BaseStream.Position += (0x2A - (int)data.FileNameSize);
     data.StartingCluster = r.ReadUInt32(ref br);
     data.Size = r.ReadUInt32(ref br);
     data.CreationDate = r.ReadUInt16(ref br);
     data.CreationTime = r.ReadUInt16(ref br);
     data.AccessDate = r.ReadUInt16(ref br);
     data.AccessTime = r.ReadUInt16(ref br);
     data.ModifiedDate = r.ReadUInt16(ref br);
     data.ModifiedTime = r.ReadUInt16(ref br);
     //br.BaseStream.Position += 0xC;
     br.Close();
     return data;
     //TODO: Datetime conversion from FAT to DateTime
 }
Exemplo n.º 4
0
 public short ReadInt16(ref FATX_Browser.FATX.IOReader br)
 {
     byte[] bytes = br.ReadBytes(0x2);
     Array.Reverse(bytes);
     return BitConverter.ToInt16(bytes, 0x0);
 }
Exemplo n.º 5
0
 internal bool ExtractFileInternal(File f, FATX_Browser.FATX.IOWriter outIO, ref long sizeWritten, ref long maxVal)
 {
     //Create our binaryreader
     FATX_Browser.FATX.IOReader br;
     try
     {
         //Create our new misc class
         Misc m = new Misc();
         //Create our blocks occupied list to speed some things up if the
         //blocks haven't been loaded yet
         System.Diagnostics.Stopwatch s = new System.Diagnostics.Stopwatch();
         s.Start();
         List<uint> BlocksOccupied = f.BlocksOccupied.ToList<uint>();
         maxVal = BlocksOccupied.Count;
         if (BlocksOccupied.Count >= 1)
         {
             //Get our IO...
             br = xDrive.GetIO();
             //For each loop increase our sizewritten, and keep looping
             //until we've reached the block BEFORE the final (size may not
             //be 0x4000 bytes)
             for (int i = 0; i < BlocksOccupied.Count - 1; i++, sizeWritten++)
             {
                 //Get and set our reader position
                 long position = m.GetBlockOffset(BlocksOccupied.ToArray()[i], f.PartInfo);
                 br.BaseStream.Position = position;
                 //Write to our output file what we just read
                 outIO.Write(br.ReadBytes((int)f.PartInfo.ClusterSize));
                 br.BaseStream.Flush();
                 outIO.BaseStream.Flush();
             }
             //KAY, now we've reached the final block in the series
             br.BaseStream.Position = m.GetBlockOffset(BlocksOccupied.ToArray()[BlocksOccupied.Count - 1], f);
             //Right here, we read the remaining data, and write it all
             //in one swoop
             outIO.Write(m.ReadBytes(ref br, m.RemainingData(f)));
             br.BaseStream.Flush();
             outIO.BaseStream.Flush();
             //Close our IO's
             br.Close();
             outIO.Close();
             sizeWritten++;
             return true;
         }
         return false;
     }
     catch (Exception e) { outIO.Close(); throw e; }
 }