static public string GetFATXPath(string PackagePath) { // Check the header... Streams.Reader io = new Streams.Reader(new System.IO.FileStream(PackagePath, System.IO.FileMode.Open)); if (io.BaseStream.Length > 4) { uint header = io.ReadUInt32(); if (header == 0x434F4E20 || header == 0x4C495645 || header == 0x50495253) { // Get the type io.BaseStream.Position = 0x344; byte[] Type = io.ReadBytes(0x4); // Get the profile ID io.BaseStream.Position = 0x371; byte[] ID = io.ReadBytes(0x8); // Get the title ID io.BaseStream.Position = 0x360; byte[] TitleID = io.ReadBytes(0x4); // NOW LET'S DO THIS SHIT return(string.Format("Content\\{0}\\{1}\\{2}", ID.ToHexString(), TitleID.ToHexString(), Type.ToHexString())); } } throw new Exception(PackagePath + " is not a valid package!"); }
public static uint Sectors() { Streams.Reader r = Drive.Reader(); r.BaseStream.Position = 0x2058; uint Value = r.ReadUInt32(); return(Value); }
public static uint Magic() { Streams.Reader r = Drive.Reader(); r.BaseStream.Position = 0x800; uint Value = r.ReadUInt32(); return(Value); }
public static uint SecondPlayedGame() { Streams.Reader r = Drive.Reader(); r.BaseStream.Position = 0xA80; uint Value = r.ReadUInt32(); return(Value); }
public static System.Drawing.Image MicrosoftLogo() { Streams.Reader r = Drive.Reader(); r.BaseStream.Position = 0x2200; uint Length = r.ReadUInt32(); System.Drawing.Image Value = System.Drawing.Image.FromStream(new System.IO.MemoryStream(r.ReadBytes((int)Length))); return(Value); }
public uint Magic() { if (magic != 0) { return(magic); } Streams.Reader br = FATXDrive.Reader(); br.BaseStream.Position = Partition.Offset; //Read the header magic = br.ReadUInt32(); return(magic); }
public static uint[] FooterInts() { Streams.Reader r = Drive.Reader(); r.BaseStream.Position = 0xA70; List <uint> R = new List <uint>(); for (int i = 0; i < 3; i++) { R.Add(r.ReadUInt32()); } return(R.ToArray()); }
public bool DriveHasJoshSector() { if (DriveType == DriveType.USB) { return(false); } Streams.Reader r = Reader(); r.BaseStream.Position = 0x800; if (r.ReadUInt32() == 0x4A6F7368) { return(true); } return(false); }
/// <summary> /// Partition ID /// </summary> public uint PartitionID() { uint rVal = 0; //Open our binary reader Streams.Reader br = FATXDrive.Reader(); //Seek to the data partition offset br.BaseStream.Position = Partition.Offset; //Read our buffer Streams.Reader mem = new Streams.Reader(new System.IO.MemoryStream(br.ReadBytes(0x200))); mem.BaseStream.Position = 0x4; rVal = mem.ReadUInt32(); mem.Close(); return(rVal); }
/// <summary> /// Number of File Allocation Tables /// </summary> public uint FATCopies() { uint rVal = 0; //Open our binary reader Streams.Reader br = FATXDrive.Reader(); //Seek to the data partition offset + 0xC (where the FATCopies int is) br.BaseStream.Position = Partition.Offset; //Create our mem reader / buffer Streams.Reader mem = new Streams.Reader(new System.IO.MemoryStream(br.ReadBytes(0x200))); mem.BaseStream.Position = 0xC; //Get our value (uses outside class for bigendian) rVal = mem.ReadUInt32(); mem.Close(); return(rVal); }
public uint RootDirectoryCluster() { // Open our IO Streams.Reader io = FATXDrive.Reader(); // Set the IO position... io.BaseStream.Position = Partition.Offset; // Read our buffer byte[] buffer = io.ReadBytes(0x200); // Re-open the IO in to a memory stream io = new Streams.Reader(new System.IO.MemoryStream(buffer)); // Go to the offset that the root dir is located; 0xC io.BaseStream.Position = 0xC; // Read and return the int there uint rVal = io.ReadUInt32(); io.Close(); return(rVal); }
public static string GetFATXPath(string PackagePath) { // Check the header... Streams.Reader io = new Streams.Reader(new System.IO.FileStream(PackagePath, System.IO.FileMode.Open)); if (io.BaseStream.Length > 4) { uint header = io.ReadUInt32(); if (header == 0x434F4E20 || header == 0x4C495645 || header == 0x50495253) { // Get the type io.BaseStream.Position = 0x344; byte[] Type = io.ReadBytes(0x4); // Get the profile ID io.BaseStream.Position = 0x371; byte[] ID = io.ReadBytes(0x8); // Get the title ID io.BaseStream.Position = 0x360; byte[] TitleID = io.ReadBytes(0x4); // NOW LET'S DO THIS SHIT return string.Format("Content\\{0}\\{1}\\{2}", ID.ToHexString(), TitleID.ToHexString(), Type.ToHexString()); } } throw new Exception(PackagePath + " is not a valid package!"); }
/// <summary> /// Partition ID /// </summary> public uint PartitionID() { uint rVal = 0; //Open our binary reader Streams.Reader br = FATXDrive.Reader(); //Seek to the data partition offset br.BaseStream.Position = Partition.Offset; //Read our buffer Streams.Reader mem = new Streams.Reader(new System.IO.MemoryStream(br.ReadBytes(0x200))); mem.BaseStream.Position = 0x4; rVal = mem.ReadUInt32(); mem.Close(); return rVal; }
//uint dicks(ref uint r3, ref uint r4, ref uint r6, ref uint r7, ref uint r8, ref uint r9, ref uint r10) //{ //} public ulong GetFreeSpace() { // Our return ulong Return = 0; ulong ClusterSize = (ulong)this.ClusterSize(); // Get our position long positionya = FATOffset; // Get our end point long toBeLessThan = FATOffset + RealFATSize(); // Get our IO Streams.Reader io = FATXDrive.Reader(); // Set the position io.BaseStream.Position = positionya; // Start reading! for (long dick = io.BaseStream.Position; dick < toBeLessThan; dick += 0x200) { bool BreakAndShit = false; // Set the position io.BaseStream.Position = dick; // Read our buffer byte[] Buffer = null; if ((dick - FATOffset).DownToNearest200() == (toBeLessThan - FATOffset).DownToNearest200()) { byte[] Temp = io.ReadBytes(0x200); Buffer = new byte[(toBeLessThan - FATOffset) - (dick - FATOffset).DownToNearest200()]; Array.Copy(Temp, 0, Buffer, 0, Buffer.Length); } else { Buffer = io.ReadBytes(0x200); } // Length to loop for (used for the end so we can read ONLY usable partitions) long Length = Buffer.Length; if (dick == VariousFunctions.DownToNearest200(toBeLessThan)) { Length = toBeLessThan - VariousFunctions.DownToNearest200(toBeLessThan); BreakAndShit = true; } // Check the values Streams.Reader ioya = new Streams.Reader(new System.IO.MemoryStream(Buffer)); for (int i = 0; i < Length; i+= EntrySize) { // This size will be off by a few megabytes, no big deal in my opinion if (EntrySize == 2) { ushort Value = ioya.ReadUInt16(); if (Value == 0) { Return += ClusterSize; } } else { if (ioya.ReadUInt32() == 0) { Return += ClusterSize; } } } ioya.Close(); if (BreakAndShit) { break; } } return Return; }
/// <summary> /// Number of File Allocation Tables /// </summary> public uint FATCopies() { uint rVal = 0; //Open our binary reader Streams.Reader br = FATXDrive.Reader(); //Seek to the data partition offset + 0xC (where the FATCopies int is) br.BaseStream.Position = Partition.Offset; //Create our mem reader / buffer Streams.Reader mem = new Streams.Reader(new System.IO.MemoryStream(br.ReadBytes(0x200))); mem.BaseStream.Position = 0xC; //Get our value (uses outside class for bigendian) rVal = mem.ReadUInt32(); mem.Close(); return rVal; }
public uint RootDirectoryCluster() { // Open our IO Streams.Reader io = FATXDrive.Reader(); // Set the IO position... io.BaseStream.Position = Partition.Offset; // Read our buffer byte[] buffer = io.ReadBytes(0x200); // Re-open the IO in to a memory stream io = new Streams.Reader(new System.IO.MemoryStream(buffer)); // Go to the offset that the root dir is located; 0xC io.BaseStream.Position = 0xC; // Read and return the int there uint rVal = io.ReadUInt32(); io.Close(); return rVal; }
/// <summary> /// TOTAL size (includes padding) of the File Allocation Table (in bytes) /// FOR REAL SIZE, CALL TO RealFATSize(); /// </summary> public long FATSize() { if (fatsize != 0) { if (!SizeChecked) { Streams.Reader r = FATXDrive.Reader(); r.BaseStream.Position = Partition.Offset + fatsize + 0x1000; while (true) { if (r.ReadUInt32() == 0x0) { fatsize += 0x1000; r.BaseStream.Position += 0x1000 - 0x4; } else { break; } } SizeChecked = true; } return(fatsize); } if (Partition.Offset == (long)Geometry.HDDOffsets.System_Extended) { return(0x5000); } else if (Partition.Offset == (long)Geometry.HDDOffsets.System_Cache) { return(0x7000); } #region old //long size = 0; //if (Partition.Offset == 0x20000000 && FATXDrive.IsUSB) //{ // System.IO.FileInfo fi = new System.IO.FileInfo(FATXDrive.DumpPath + "\\Data0001"); // size = fi.Length - 0x1000; // //Return the size. // return size; //} //else //{ // //This gets the size // size = ((PartitionSize() / ClusterSize()) * EntrySize); // //We need to round up to the nearest 0x1000 byte boundary. // long sizeToAdd = (0x1000 - (size % 0x1000)); // if (!FATXDrive.IsUSB) // { // size += sizeToAdd; // } // //Return the size. // return size; //} #endregion //Code that rounds up to nearest cluster... long size = 0; #region shit //if (Partition.Offset == 0x20000000 && FATXDrive.IsUSB) //{ // System.IO.FileInfo fi = new System.IO.FileInfo(FATXDrive.DumpPath + "\\Data0001"); // size = fi.Length - 0x1000; // //Ghetto // Streams.Reader ir = FATXDrive.Reader(); // //Return the size. // return size; //} //else //{ #endregion //This gets the size size = (((PartitionSize() / ClusterSize())) * EntrySize); //We need to round up to the nearest blabhlabhalkhdflkasdf byte boundary. size = VariousFunctions.UpToNearestCluster(size + 0x1000, ClusterSize() / EntrySize) - 0x1000; //long sizeToAdd = (0x1000 - (size % 0x1000)); //size += sizeToAdd; //Return the size. return(size); //uint r24 = 0, r3, r6, r23, r10, r11, r27, r22, r25, r26, r28, r29, r30, r31; //if (Partition.Size == 0) //{ //} //else //{ // r11 = r27 & 0xFF; // if (r11 == 2) // { // r11 = r22; // r10 = r11 + r29; // r11--; // r10--; // r29 = r10 & (~r11); // r30 = r29; // } // else // { // // break here // } // r10 = 1; // r3 = dicks(ref r28, ref r26, ref r27, ref r25, ref r31, ref r24, ref r10); //} }
/// <summary> /// Checks to see if the drive is a valid FATX drive /// </summary> /// <returns> /// True for valid /// False for invalid /// </returns> public bool IsFATXDrive() { switch (DriveType) { case DriveType.HardDisk: // Create our reader... try { Streams.Reader r = Reader(); // Check to see if it's a dev drive first r.BaseStream.Position = 0; if (r.ReadUInt32() == 0x00020000) // dev magic { DevPartitionRegions[] regions = DevPartitions(); r.BaseStream.Position = (long)regions[0].Sector * 0x200; if (r.ReadUInt32() == 0x58544146 /*XTAF*/) { return(IsDev = true); } } else { // Seek to the data position r.BaseStream.Position = (long)Geometry.HDDOffsets.Data; // Read the magic if (r.ReadUInt32() == 0x58544146 /*XTAF*/) { return(true); } } } catch { } break; case DriveType.USB: try { Streams.Reader r2 = Reader(); // Seek to the data offset r2.BaseStream.Position = (long)Geometry.USBOffsets.Data; if (r2.ReadUInt32() == 0x58544146 /*XTAF*/) { return(true); } } catch (Exception e) { break; } break; case DriveType.Backup: try { Streams.Reader r1 = Reader(); // Check to see if it's a dev drive r1.BaseStream.Position = 0; if (r1.ReadUInt32() == 0x00020000) // dev magic { DevPartitionRegions[] regions = DevPartitions(); r1.BaseStream.Position = (long)regions[0].Sector * 0x200; if (r1.ReadUInt32() == 0x58544146 /*XTAF*/) { return(IsDev = true); } return(IsDev = true); } if (Length > (long)Geometry.HDDOffsets.Data) { // Seek to the data position r1.BaseStream.Position = (long)Geometry.HDDOffsets.Data; } // Read the magic if (r1.ReadUInt32() == 0x58544146 /*XTAF*/) { return(true); } } catch { } break; } return(false); }
//uint dicks(ref uint r3, ref uint r4, ref uint r6, ref uint r7, ref uint r8, ref uint r9, ref uint r10) //{ //} public ulong GetFreeSpace() { // Our return ulong Return = 0; ulong ClusterSize = (ulong)this.ClusterSize(); // Get our position long positionya = FATOffset; // Get our end point long toBeLessThan = FATOffset + RealFATSize(); // Get our IO Streams.Reader io = FATXDrive.Reader(); // Set the position io.BaseStream.Position = positionya; // Start reading! for (long dick = io.BaseStream.Position; dick < toBeLessThan; dick += 0x200) { bool BreakAndShit = false; // Set the position io.BaseStream.Position = dick; // Read our buffer byte[] Buffer = null; if ((dick - FATOffset).DownToNearest200() == (toBeLessThan - FATOffset).DownToNearest200()) { byte[] Temp = io.ReadBytes(0x200); Buffer = new byte[(toBeLessThan - FATOffset) - (dick - FATOffset).DownToNearest200()]; Array.Copy(Temp, 0, Buffer, 0, Buffer.Length); } else { Buffer = io.ReadBytes(0x200); } // Length to loop for (used for the end so we can read ONLY usable partitions) long Length = Buffer.Length; if (dick == VariousFunctions.DownToNearest200(toBeLessThan)) { Length = toBeLessThan - VariousFunctions.DownToNearest200(toBeLessThan); BreakAndShit = true; } // Check the values Streams.Reader ioya = new Streams.Reader(new System.IO.MemoryStream(Buffer)); for (int i = 0; i < Length; i += EntrySize) { // This size will be off by a few megabytes, no big deal in my opinion if (EntrySize == 2) { ushort Value = ioya.ReadUInt16(); if (Value == 0) { Return += ClusterSize; } } else { if (ioya.ReadUInt32() == 0) { Return += ClusterSize; } } } ioya.Close(); if (BreakAndShit) { break; } } return(Return); }