public void ExtractParts(string imageFilename) { string extractDir = Path.GetDirectoryName(imageFilename); using (FileStream imageStream = File.Open(imageFilename, FileMode.Open)) { using (FileStream kernelStream = File.Create(Path.Combine(extractDir, "vmlinux.gz"))) { Misc.CopyStream(imageStream, kernelStream, 0x4343C, 0); kernelStream.Seek(0, SeekOrigin.Begin); using (GZipStream compKernelStream = new GZipStream(kernelStream, CompressionMode.Decompress)) { using (FileStream uncompKernelStream = File.Create(Path.Combine(extractDir, "vmlinux"))) { compKernelStream.CopyTo(uncompKernelStream); } } } int squashIndex = FileStringSearcher.FindInFile(imageStream, "hsqs"); if (squashIndex != ~imageStream.Length) { using (FileStream rootfsStream = File.Create(Path.Combine(extractDir, "filesystem.squashfs.bin"))) { Misc.CopyStream(imageStream, rootfsStream, squashIndex, imageStream.Length - squashIndex); } string appDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); //if (Directory.Exists(Path.Combine(extractDir, "rootfs"))) Directory.Delete(Path.Combine(extractDir, "rootfs")); Process unsquashProcess = new Process(); unsquashProcess.StartInfo.FileName = Path.Combine(appDir, "unsquashfs.exe"); unsquashProcess.StartInfo.Arguments = string.Format("-d \"{0}\" \"{1}\"", Path.Combine(extractDir, "rootfs"), Path.Combine(extractDir, "filesystem.squashfs.bin")); unsquashProcess.Start(); unsquashProcess.WaitForExit(); if (File.Exists(Path.Combine(extractDir, @"rootfs\NDS\config\bsysconfig.bin"))) { BinaryConfigReader reader = new BinaryConfigReader(Path.Combine(extractDir, @"rootfs\NDS\config\bsysconfig.bin"), false); Directory.CreateDirectory(Path.Combine(extractDir, "config")); reader.SaveAsINI(Path.Combine(extractDir, "config")); } } } }
public void ExtractParts(string imageFilename) { string extractDir = Path.GetDirectoryName(imageFilename); using (FileStream imageStream = File.Open(imageFilename, FileMode.Open)) { using (FileStream cfeStream = File.Create(Path.Combine(extractDir, "cfe.bin"))) { Misc.CopyStream(imageStream, cfeStream, 0x7630, 0x189AC); } using (FileStream kernelStream = File.Create(Path.Combine(extractDir, "vmlinux.gz"))) { Misc.CopyStream(imageStream, kernelStream, 0x1FFDC, 0); kernelStream.Seek(0, SeekOrigin.Begin); using (GZipStream compKernelStream = new GZipStream(kernelStream, CompressionMode.Decompress)) { using (FileStream uncompKernelStream = File.Create(Path.Combine(extractDir, "vmlinux"))) { compKernelStream.CopyTo(uncompKernelStream); // Now we want to try and find the lzma'd cpio filesystem int cpioIndex = FileStringSearcher.FindInFile(uncompKernelStream, Encoding.ASCII.GetString(new byte[] { 0x5D, 0x00, 0x00, 0x00, 0x02, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF })); if (cpioIndex != ~uncompKernelStream.Length) { using (FileStream rootFsLzmaStream = File.Create(Path.Combine(extractDir, "filesystem.lzma"))) { Misc.CopyStream(uncompKernelStream, rootFsLzmaStream, cpioIndex, 0); } string appDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); Process unlzmaProcess = new Process(); unlzmaProcess.StartInfo.FileName = Path.Combine(appDir, "lzma.exe"); unlzmaProcess.StartInfo.Arguments = string.Format("d \"{0}\" \"{1}\"", Path.Combine(extractDir, "filesystem.lzma"), Path.Combine(extractDir, "filesystem.bin")); unlzmaProcess.Start(); unlzmaProcess.WaitForExit(); if (File.Exists(Path.Combine(extractDir, "filesystem.bin"))) { Directory.CreateDirectory(Path.Combine(extractDir, "rootfs")); Process cpioProcess = new Process(); cpioProcess.StartInfo.FileName = Path.Combine(appDir, "extract_fs.cmd"); cpioProcess.StartInfo.Arguments = string.Format("\"{0}\" \"{1}\" \"{2}\"", Path.Combine(extractDir, "rootfs"), Path.Combine(appDir, "cpio.exe"), Path.Combine(extractDir, "filesystem.bin")); cpioProcess.Start(); cpioProcess.WaitForExit(); if (File.Exists(Path.Combine(extractDir, @"rootfs\NDS\config\bsysconfig.bin"))) { BinaryConfigReader reader = new BinaryConfigReader(Path.Combine(extractDir, @"rootfs\NDS\config\bsysconfig.bin"), false); Directory.CreateDirectory(Path.Combine(extractDir, "config")); reader.SaveAsINI(Path.Combine(extractDir, "config")); } else if (File.Exists(Path.Combine(extractDir, @"rootfs\NDS\config\version.cfg"))) { Directory.CreateDirectory(Path.Combine(extractDir, "config")); foreach (string fileName in Directory.EnumerateFiles(Path.Combine(extractDir, @"rootfs\NDS\config"), "*.cfg")) { File.Copy(fileName, Path.Combine(extractDir, "config", Path.GetFileName(fileName)), true); } } } } } } } } }
public void ExtractParts(string imageFilename) { string extractDir = Path.GetDirectoryName(imageFilename); using (FileStream imageStream = File.Open(imageFilename, FileMode.Open)) { using (FileStream kernelStream = File.Create(Path.Combine(extractDir, "vmlinux.gz"))) { Misc.CopyStream(imageStream, kernelStream, 0x4343C, 0); kernelStream.Seek(0, SeekOrigin.Begin); using (GZipStream compKernelStream = new GZipStream(kernelStream, CompressionMode.Decompress)) { using (FileStream uncompKernelStream = File.Create(Path.Combine(extractDir, "vmlinux"))) { compKernelStream.CopyTo(uncompKernelStream); } } } int squashIndex = FileStringSearcher.FindInFile(imageStream, "hsqs"); if (squashIndex != ~imageStream.Length) { using (FileStream rootfsStream = File.Create(Path.Combine(extractDir, "filesystem.squashfs.bin"))) { Misc.CopyStream(imageStream, rootfsStream, squashIndex, imageStream.Length - squashIndex); } string appDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); //if (Directory.Exists(Path.Combine(extractDir, "rootfs"))) Directory.Delete(Path.Combine(extractDir, "rootfs")); Process unsquashProcess = new Process(); unsquashProcess.StartInfo.FileName = Path.Combine(appDir, "unsquashfs.exe"); unsquashProcess.StartInfo.Arguments = string.Format("-d \"{0}\" \"{1}\"", Path.Combine(extractDir, "rootfs"), Path.Combine(extractDir, "filesystem.squashfs.bin")); unsquashProcess.Start(); unsquashProcess.WaitForExit(); if (File.Exists(Path.Combine(extractDir, @"rootfs\NDS\config\bsysconfig.bin"))) { BinaryConfigReader reader = new BinaryConfigReader(Path.Combine(extractDir, @"rootfs\NDS\config\bsysconfig.bin"), false); Directory.CreateDirectory(Path.Combine(extractDir, "config")); reader.SaveAsINI(Path.Combine(extractDir, "config")); } } } }
public void ExtractParts(string imageFilename) { string extractDir = Path.GetDirectoryName(imageFilename); using (FileStream imageStream = File.Open(imageFilename, FileMode.Open)) { using (FileStream kernelStream = File.Create(Path.Combine(extractDir, "vmlinux.gz"))) { Misc.CopyStream(imageStream, kernelStream, 0x2BDC, 0); kernelStream.Seek(0, SeekOrigin.Begin); using (GZipStream compKernelStream = new GZipStream(kernelStream, CompressionMode.Decompress)) { using (FileStream uncompKernelStream = File.Create(Path.Combine(extractDir, "vmlinux"))) { compKernelStream.CopyTo(uncompKernelStream); // Now we want to try and find the lzma'd cpio filesystem int cpioIndex = FileStringSearcher.FindInFile(uncompKernelStream, Encoding.ASCII.GetString(new byte[] { 0x5D, 0x00, 0x00, 0x00, 0x02, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF })); if (cpioIndex != ~uncompKernelStream.Length) { using(FileStream rootFsLzmaStream = File.Create(Path.Combine(extractDir, "filesystem.lzma"))) { Misc.CopyStream(uncompKernelStream, rootFsLzmaStream, cpioIndex, 0); } string appDir = System.IO.Path.GetDirectoryName(System.Reflection.Assembly.GetExecutingAssembly().Location); Process unlzmaProcess = new Process(); unlzmaProcess.StartInfo.FileName = Path.Combine(appDir, "lzma.exe"); unlzmaProcess.StartInfo.Arguments = string.Format("d \"{0}\" \"{1}\"", Path.Combine(extractDir, "filesystem.lzma"), Path.Combine(extractDir, "filesystem.bin")); unlzmaProcess.Start(); unlzmaProcess.WaitForExit(); if (File.Exists(Path.Combine(extractDir, "filesystem.bin"))) { Directory.CreateDirectory(Path.Combine(extractDir, "rootfs")); Process cpioProcess = new Process(); cpioProcess.StartInfo.FileName = Path.Combine(appDir, "extract_fs.cmd"); cpioProcess.StartInfo.Arguments = string.Format("\"{0}\" \"{1}\" \"{2}\"", Path.Combine(extractDir, "rootfs"), Path.Combine(appDir, "cpio.exe"), Path.Combine(extractDir, "filesystem.bin")); cpioProcess.Start(); cpioProcess.WaitForExit(); if (File.Exists(Path.Combine(extractDir, @"rootfs\NDS\config\bsysconfig.bin"))) { BinaryConfigReader reader = new BinaryConfigReader(Path.Combine(extractDir, @"rootfs\NDS\config\bsysconfig.bin"), false); Directory.CreateDirectory(Path.Combine(extractDir, "config")); reader.SaveAsINI(Path.Combine(extractDir, "config")); } } } } } } } }