public Bootloader(byte[] data, BootLoaderTypes type) { Type = type; Data = data; Size = (uint)data.Length; Offset = 0; Build = GetBootloaderVersion(ref data); }
public Bootloader(NANDReader reader, int count = 0, bool readitin = false) { Offset = (uint)(reader.Lba * 0x4000 + reader.Position % 0x4000); StartLba = reader.Lba; var header = reader.ReadBytes(0x10); Type = GetTypeFromHeader(ref header, count); Size = GetBootloaderSize(ref header); Build = GetBootloaderVersion(ref header); if (readitin) { reader.Lba = Offset / 0x4000; if (Offset % 0x4000 > 0) { reader.Seek(Offset % 0x4000, SeekOrigin.Current); } Data = new byte[Size]; var left = Size; var dOffset = 0; for (var i = 0; left > 0; i++) { var toread = (int)BitOperations.GetSmallest(0x4000, left); if (left == Size && reader.Position % 0x4000 > 0) { toread = (int)BitOperations.GetSmallest((0x4000 - (reader.Position % 0x4000)), left); } var tmp = reader.ReadBytes(toread); Buffer.BlockCopy(tmp, 0, Data, dOffset, toread); left -= (uint)toread; dOffset += toread; if (left > 0) // We want to seek to the next block! { reader.Lba = (uint)((Offset / 0x4000) + 1 + i); } } } else { reader.Lba = (Offset + Size) / 0x4000; if ((Offset + Size) % 0x4000 > 0) { reader.Seek((Offset + Size) % 0x4000, SeekOrigin.Current); } } //reader.Seek(Offset + Size, SeekOrigin.Begin); }