Last active
March 13, 2017 02:07
-
-
Save jfmherokiller/7dec19ac47adb5ec63247a22ceb08f3c to your computer and use it in GitHub Desktop.
movable.sed parser
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using System; | |
| using System.Collections.Generic; | |
| using System.Linq; | |
| using System.Text; | |
| namespace movablesedtest | |
| { | |
| //refrenced from here https://www.3dbrew.org/wiki/Nand/private/movable.sed | |
| /*Offset Size Description | |
| *0x0 0x4 Magic "SEED" | |
| * | |
| *0x4 0x4 When u8[1] is non-zero, this indicates that the additional 0x20-bytes AES-MAC block at the end of movable.sed exists. | |
| * If u8[1] is zero, then u8 [0], [2], and [3] must be zero as well. | |
| * | |
| *0x8 0x110 Copied from Nandrw/sys/LocalFriendCodeSeed_B (or LocalFriendCodeSeed_A if it exists) | |
| * | |
| *0x118 0x8 AES engine high keyY for 3 keyslots | |
| * | |
| *0x120 0x20 This data is written to the file when doing a System Format. | |
| * The original movable.sed from the factory is only 0x120-bytes. | |
| * The last 0x10-bytes in this block is an AES-MAC over a SHA256 hash, using the same keyslot used for NAND dbs. | |
| * This hash is calculated over the first 0x130-bytes of movable.sed. | |
| * This AES-MAC is verified is during movable.sed verification(before RSA verification). | |
| */ | |
| class moveable_sed | |
| { | |
| public List<byte> magic_seed; //size 4 bytes | |
| public List<byte> aes_check_block; //size 4 bytes | |
| public List<byte> friend_code_seed_block; //size 272 bytes | |
| public List<byte> aes_keyy_high_slots; //size 8 bytes | |
| public List<byte> unknown_data; //size 32 bytes | |
| public moveable_sed(byte[] filedata) | |
| { | |
| magic_seed = filedata.Take(4).ToList(); | |
| aes_check_block = filedata.Skip(4).Take(4).ToList(); | |
| if (aes_check_block[1] == 0x01) | |
| friend_code_seed_block = filedata.Skip(8).Take(272).ToList(); | |
| aes_keyy_high_slots = filedata.Skip(280).Take(8).ToList(); | |
| if (aes_check_block[1] == 0x01) | |
| { | |
| unknown_data = filedata.Skip(288).Take(32).ToList(); | |
| } | |
| } | |
| } | |
| class Program | |
| { | |
| static public String MemoryDisplay(byte[] mem) | |
| { | |
| StringBuilder sb = new StringBuilder(); | |
| for (int i = 0; i < mem.Length; i += 32) | |
| { | |
| byte[] line = mem.Skip(i).Take(32).ToArray(); | |
| String s = String.Format("{0,-96}{1}", | |
| String.Join(" ", line.Select(e => e.ToString("x2")).ToArray()), | |
| new String(line.Select(e => 32 <= e && e <= 127 ? (Char)e : '.').ToArray())); | |
| sb.AppendLine(s); | |
| } | |
| return sb.ToString(); | |
| } | |
| static void Main(string[] args) | |
| { | |
| var filedata = System.IO.File.ReadAllBytes("movable.sed"); | |
| var moveable_sed_data = new moveable_sed(filedata); | |
| Console.WriteLine("Magic seed:\n" + MemoryDisplay(moveable_sed_data.magic_seed.ToArray())); | |
| Console.WriteLine("aes check block:\n" + MemoryDisplay(moveable_sed_data.aes_check_block.ToArray())); | |
| Console.WriteLine("friend code block:\n" + MemoryDisplay(moveable_sed_data.friend_code_seed_block.ToArray())); | |
| Console.WriteLine("aes high y block:\n" + MemoryDisplay(moveable_sed_data.aes_keyy_high_slots.ToArray())); | |
| Console.WriteLine("unknown data:\n" + MemoryDisplay(moveable_sed_data.unknown_data.ToArray())); | |
| Console.Read(); | |
| } | |
| } | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment