internal byte[] Rebuild() { if (GPTBuffer == null) { TableSize = 0x4200; TableOffset = 0; GPTBuffer = new byte[TableSize]; } else { Array.Clear(GPTBuffer, (int)TableOffset, (int)TableSize); } UInt32 PartitionOffset = TableOffset; foreach (Partition CurrentPartition in Partitions) { ByteOperations.WriteGuid(GPTBuffer, PartitionOffset + 0x00, CurrentPartition.PartitionTypeGuid); ByteOperations.WriteGuid(GPTBuffer, PartitionOffset + 0x10, CurrentPartition.PartitionGuid); ByteOperations.WriteUInt64(GPTBuffer, PartitionOffset + 0x20, CurrentPartition.FirstSector); ByteOperations.WriteUInt64(GPTBuffer, PartitionOffset + 0x28, CurrentPartition.LastSector); ByteOperations.WriteUInt64(GPTBuffer, PartitionOffset + 0x30, CurrentPartition.Attributes); ByteOperations.WriteUnicodeString(GPTBuffer, PartitionOffset + 0x38, CurrentPartition.Name, 0x48); PartitionOffset += PartitionEntrySize; } ByteOperations.WriteUInt32(GPTBuffer, HeaderOffset + 0x58, ByteOperations.CRC32(GPTBuffer, TableOffset, TableSize)); ByteOperations.WriteUInt32(GPTBuffer, HeaderOffset + 0x10, 0); ByteOperations.WriteUInt32(GPTBuffer, HeaderOffset + 0x10, ByteOperations.CRC32(GPTBuffer, HeaderOffset, HeaderSize)); return(GPTBuffer); }
internal static void PatchImg(string dump) { using (var fil = File.Open(dump, FileMode.Open)) { byte[] gptbuffer = new byte[0x4200]; fil.Seek(0x200, SeekOrigin.Begin); fil.Read(gptbuffer, 0, 0x4200); uint BackupLBA = ByteOperations.ReadUInt32(gptbuffer, 0x20); uint LastUsableLBA = ByteOperations.ReadUInt32(gptbuffer, 0x30); LogFile.Log("Previous BackupLBA: " + BackupLBA, LogType.ConsoleOnly); LogFile.Log("Previous LastUsableLBA: " + LastUsableLBA, LogType.ConsoleOnly); uint NewBackupLBA = 62078975u; uint NewLastUsableLBA = 62078942u; ByteOperations.WriteUInt32(gptbuffer, 0x20, NewBackupLBA); ByteOperations.WriteUInt32(gptbuffer, 0x30, NewLastUsableLBA); uint HeaderSize = ByteOperations.ReadUInt32(gptbuffer, 0x0C); uint PrevCRC = ByteOperations.ReadUInt32(gptbuffer, 0x10); LogFile.Log("Previous CRC: " + PrevCRC, LogType.ConsoleOnly); ByteOperations.WriteUInt32(gptbuffer, 0x10, 0); uint NewCRC = ByteOperations.CRC32(gptbuffer, 0, HeaderSize); LogFile.Log("New CRC: " + NewCRC, LogType.ConsoleOnly); ByteOperations.WriteUInt32(gptbuffer, 0x10, NewCRC); LogFile.Log("Writing", LogType.ConsoleOnly); fil.Seek(0x200, SeekOrigin.Begin); fil.Write(gptbuffer, 0, 0x4200); LogFile.Log("Done!", LogType.ConsoleOnly); } }