From 7ba20c52d46d01dcfa193c17a48f2e5eee6de539 Mon Sep 17 00:00:00 2001 From: Alexey Sonkin Date: Mon, 30 Dec 2024 23:45:04 +0300 Subject: [PATCH] Added BMU loading plugin --- NyaImageTool.sln | 15 + NyaImageTool/NyaImageTool.csproj | 2 +- Plugins/NyaFsBmu/Commands/LoadBmu.cs | 287 ++++++++++++++++++++ Plugins/NyaFsBmu/Loader/BmuDevtreeReader.cs | 48 ++++ Plugins/NyaFsBmu/Loader/BmuFsReader.cs | 74 +++++ Plugins/NyaFsBmu/Loader/BmuKernelReader.cs | 46 ++++ Plugins/NyaFsBmu/NyaFsBmu.csproj | 15 + Plugins/NyaFsBmu/NyaFsBmuPlugin.cs | 20 ++ Plugins/NyaFsBmu/Types/BmuImage.cs | 40 +++ Plugins/NyaFsBmu/Types/BmuImageType.cs | 17 ++ Plugins/NyaFsEncrypt/NyaFsEncrypt.csproj | 2 +- Plugins/NyaFsFiles/NyaFsFiles.csproj | 2 +- Plugins/NyaFsLinux/NyaFsLinux.csproj | 2 +- Plugins/NyaFsSftp/NyaFsSftp.csproj | 2 +- Plugins/NyaFsTftp/NyaFsTftp.csproj | 2 +- 15 files changed, 568 insertions(+), 6 deletions(-) create mode 100644 Plugins/NyaFsBmu/Commands/LoadBmu.cs create mode 100644 Plugins/NyaFsBmu/Loader/BmuDevtreeReader.cs create mode 100644 Plugins/NyaFsBmu/Loader/BmuFsReader.cs create mode 100644 Plugins/NyaFsBmu/Loader/BmuKernelReader.cs create mode 100644 Plugins/NyaFsBmu/NyaFsBmu.csproj create mode 100644 Plugins/NyaFsBmu/NyaFsBmuPlugin.cs create mode 100644 Plugins/NyaFsBmu/Types/BmuImage.cs create mode 100644 Plugins/NyaFsBmu/Types/BmuImageType.cs diff --git a/NyaImageTool.sln b/NyaImageTool.sln index f271a4e..77a7c1a 100644 --- a/NyaImageTool.sln +++ b/NyaImageTool.sln @@ -36,6 +36,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Workflow", "Workflow", "{D8 EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NyaFsEncrypt", "Plugins\NyaFsEncrypt\NyaFsEncrypt.csproj", "{C0B57D62-F526-4433-BEAC-2D4772111DA9}" EndProject +Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "NyaFsBmu", "Plugins\NyaFsBmu\NyaFsBmu.csproj", "{FD6063A5-0450-492A-808F-4D27E64E23FF}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -130,6 +132,18 @@ Global {C0B57D62-F526-4433-BEAC-2D4772111DA9}.Release|x64.Build.0 = Release|Any CPU {C0B57D62-F526-4433-BEAC-2D4772111DA9}.Release|x86.ActiveCfg = Release|Any CPU {C0B57D62-F526-4433-BEAC-2D4772111DA9}.Release|x86.Build.0 = Release|Any CPU + {FD6063A5-0450-492A-808F-4D27E64E23FF}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FD6063A5-0450-492A-808F-4D27E64E23FF}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FD6063A5-0450-492A-808F-4D27E64E23FF}.Debug|x64.ActiveCfg = Debug|Any CPU + {FD6063A5-0450-492A-808F-4D27E64E23FF}.Debug|x64.Build.0 = Debug|Any CPU + {FD6063A5-0450-492A-808F-4D27E64E23FF}.Debug|x86.ActiveCfg = Debug|Any CPU + {FD6063A5-0450-492A-808F-4D27E64E23FF}.Debug|x86.Build.0 = Debug|Any CPU + {FD6063A5-0450-492A-808F-4D27E64E23FF}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FD6063A5-0450-492A-808F-4D27E64E23FF}.Release|Any CPU.Build.0 = Release|Any CPU + {FD6063A5-0450-492A-808F-4D27E64E23FF}.Release|x64.ActiveCfg = Release|Any CPU + {FD6063A5-0450-492A-808F-4D27E64E23FF}.Release|x64.Build.0 = Release|Any CPU + {FD6063A5-0450-492A-808F-4D27E64E23FF}.Release|x86.ActiveCfg = Release|Any CPU + {FD6063A5-0450-492A-808F-4D27E64E23FF}.Release|x86.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE @@ -140,6 +154,7 @@ Global {4B64DF0F-CD57-4A68-BEB9-676EA490578A} = {D12DEDB5-FE5C-483B-9AF0-FC9E6C751BEC} {2FFD947D-8EF4-417A-BE85-CDD8A456BDFD} = {D12DEDB5-FE5C-483B-9AF0-FC9E6C751BEC} {C0B57D62-F526-4433-BEAC-2D4772111DA9} = {D12DEDB5-FE5C-483B-9AF0-FC9E6C751BEC} + {FD6063A5-0450-492A-808F-4D27E64E23FF} = {D12DEDB5-FE5C-483B-9AF0-FC9E6C751BEC} EndGlobalSection GlobalSection(ExtensibilityGlobals) = postSolution SolutionGuid = {AB408CED-798C-4B0A-911C-67380FEE10B7} diff --git a/NyaImageTool/NyaImageTool.csproj b/NyaImageTool/NyaImageTool.csproj index 7ace2ce..c5cabd2 100644 --- a/NyaImageTool/NyaImageTool.csproj +++ b/NyaImageTool/NyaImageTool.csproj @@ -6,7 +6,7 @@ - + diff --git a/Plugins/NyaFsBmu/Commands/LoadBmu.cs b/Plugins/NyaFsBmu/Commands/LoadBmu.cs new file mode 100644 index 0000000..2989473 --- /dev/null +++ b/Plugins/NyaFsBmu/Commands/LoadBmu.cs @@ -0,0 +1,287 @@ +using NyaFs; +using NyaFs.Processor; +using NyaFs.Processor.Scripting; +using NyaFsBmu.Loader; +using NyaFsBmu.Types; +using System; +using System.Collections.Generic; +using System.IO; +using System.Text; +using static System.Net.Mime.MediaTypeNames; + +namespace NyaFsBmu.Commands +{ + class LoadBmu : ScriptStepGenerator + { + public LoadBmu() : base("loadbmu") + { + AddConfig(new ScriptArgsConfig(0, new ScriptArgsParam[] { + new NyaFs.Processor.Scripting.Params.FsPathScriptArgsParam() + })); + } + + public override ScriptStep Get(ScriptArgs Args) + { + return new LoadBmuScriptStep(Args.RawArgs[0]); + } + + public class LoadBmuScriptStep : ScriptStep + { + private string Path; + + public LoadBmuScriptStep(string Path) : base("loadbmu") + { + this.Path = Path; + } + + NyaFs.ImageFormat.Types.CPU FindExistArch(NyaFs.ImageFormat.BaseImageBlob Blob) + { + NyaFs.ImageFormat.Types.CPU arch = NyaFs.ImageFormat.Types.CPU.IH_ARCH_INVALID; + if (Blob.IsProvidedKernel) + { + var K = Blob.GetKernel(); + if (K.Info.Architecture != NyaFs.ImageFormat.Types.CPU.IH_ARCH_INVALID) + arch = K.Info.Architecture; + } + if (Blob.IsProvidedFs) + { + var Fs = Blob.GetFilesystem(); + if (Fs.Info.Architecture != NyaFs.ImageFormat.Types.CPU.IH_ARCH_INVALID) + { + if (arch != NyaFs.ImageFormat.Types.CPU.IH_ARCH_INVALID) + { + // Is detected os info differs to kernel + if (arch != Fs.Info.Architecture) + return NyaFs.ImageFormat.Types.CPU.IH_ARCH_INVALID; + } + else + arch = Fs.Info.Architecture; + } + } + if (Blob.IsProvidedDTB) + { + var Dtb = Blob.GetDevTree(); + if (Dtb.Info.Architecture != NyaFs.ImageFormat.Types.CPU.IH_ARCH_INVALID) + { + if (arch != NyaFs.ImageFormat.Types.CPU.IH_ARCH_INVALID) + { + // Is detected os info differs to dtb + if (arch != Dtb.Info.Architecture) + return NyaFs.ImageFormat.Types.CPU.IH_ARCH_INVALID; + } + else + arch = Dtb.Info.Architecture; + } + } + + return arch; + } + + NyaFs.ImageFormat.Types.OS FindExistOS(NyaFs.ImageFormat.BaseImageBlob Blob) + { + NyaFs.ImageFormat.Types.OS os = NyaFs.ImageFormat.Types.OS.IH_OS_INVALID; + if (Blob.IsProvidedKernel) + { + var K = Blob.GetKernel(); + if (K.Info.OperatingSystem != NyaFs.ImageFormat.Types.OS.IH_OS_INVALID) + os = K.Info.OperatingSystem; + } + if (Blob.IsProvidedFs) + { + var Fs = Blob.GetFilesystem(); + if (Fs.Info.OperatingSystem != NyaFs.ImageFormat.Types.OS.IH_OS_INVALID) + { + if (os != NyaFs.ImageFormat.Types.OS.IH_OS_INVALID) + { + // Is FS os info differs to kernel + if (os != Fs.Info.OperatingSystem) + return NyaFs.ImageFormat.Types.OS.IH_OS_INVALID; + } + else + os = Fs.Info.OperatingSystem; + } + } + + return os; + } + + private void AssumeAutoKernelParams(NyaFs.ImageFormat.Elements.Kernel.LinuxKernel Kernel) + { + /*if (Kernel.Info.Architecture == NyaFs.ImageFormat.Types.CPU.IH_ARCH_INVALID) + { + var Type = NyaFs.ImageFormat.Helper.KernelHelper.DetectImageArch(Kernel.Image); + + if (Type != NyaFs.ImageFormat.Types.CPU.IH_ARCH_INVALID) + { + Log.Write(0, $"Assumed kernel architecture: {NyaFs.ImageFormat.Helper.FitHelper.GetCPUArchitecture(Type)}"); + Kernel.Info.Architecture = Type; + } + } + + if (Kernel.Info.OperatingSystem == NyaFs.ImageFormat.Types.OS.IH_OS_INVALID) + { + var Os = Helper.KernelHelper.DetectImageOs(Kernel.Image); + + if (Os != NyaFs.ImageFormat.Types.OS.IH_OS_INVALID) + { + Log.Write(0, $"Assumed kernel OS: {NyaFs.ImageFormat.Helper.FitHelper.GetOperatingSystem(Os)}"); + Kernel.Info.OperatingSystem = Os; + } + }*/ + } + + private void AssumeAutoImageParams(ImageProcessor Processor) + { + var Blob = Processor.GetBlob(); + var Arch = FindExistArch(Blob); + if (Arch != NyaFs.ImageFormat.Types.CPU.IH_ARCH_INVALID) + { + var K = Processor.GetKernel(); + if (K != null) + { + if (K.Info.Architecture == NyaFs.ImageFormat.Types.CPU.IH_ARCH_INVALID) + K.Info.Architecture = Arch; + } + var Fs = Processor.GetFs(); + if (Fs != null) + { + if (Fs.Info.Architecture == NyaFs.ImageFormat.Types.CPU.IH_ARCH_INVALID) + Fs.Info.Architecture = Arch; + } + var Dtb = Processor.GetDevTree(); + if (Dtb != null) + { + if (Dtb.Info.Architecture == NyaFs.ImageFormat.Types.CPU.IH_ARCH_INVALID) + Dtb.Info.Architecture = Arch; + } + } + var Os = FindExistOS(Blob); + if (Os != NyaFs.ImageFormat.Types.OS.IH_OS_INVALID) + { + var K = Processor.GetKernel(); + if (K != null) + { + if (K.Info.OperatingSystem == NyaFs.ImageFormat.Types.OS.IH_OS_INVALID) + K.Info.OperatingSystem = Os; + } + var Fs = Processor.GetFs(); + if (Fs != null) + { + if (Fs.Info.OperatingSystem == NyaFs.ImageFormat.Types.OS.IH_OS_INVALID) + Fs.Info.OperatingSystem = Os; + } + } + } + + public override ScriptStepResult Exec(ImageProcessor Processor) + { + // Проверим наличие локального файла, содержимое которого надо загрузить в ФС + if (!System.IO.File.Exists(Path)) + return new ScriptStepResult(ScriptStepStatus.Error, $"{Path} not found!"); + + var Data = File.ReadAllBytes(Path); + var Image = new BmuImage(Data); + + if (Image.Correct) + { + var FsRes = ReadFs(Processor, Image); + if (FsRes.Status == ScriptStepStatus.Error) + return FsRes; + + var KernelRes = ReadKernel(Processor, Image); + if (FsRes.Status == ScriptStepStatus.Error) + return KernelRes; + + var DevtreeRes = ReadDtb(Processor, Image); + if (FsRes.Status == ScriptStepStatus.Error) + return DevtreeRes; + + return new ScriptStepResult(ScriptStepStatus.Ok, $"BMU is loaded!"); + } + else + return new ScriptStepResult(ScriptStepStatus.Error, $"BMU is invalid image!"); + } + + private ScriptStepResult ReadFs(ImageProcessor Processor, BmuImage Data) + { + var OldLoaded = Processor.GetFs()?.Loaded ?? false; + var Fs = new NyaFs.ImageFormat.Elements.Fs.LinuxFilesystem(); + var FsReader = new NyaFsBmu.Loader.BmuFsReader(Data); + + FsReader.ReadToFs(Fs); + if (Fs.Loaded) + { + Processor.SetFs(Fs); + AssumeAutoImageParams(Processor); + //if (Fs.FilesystemType != ImageFormat.Types.FsType.Cpio) + //{ + // Fs.FilesystemType = ImageFormat.Types.FsType.Cpio; + // Log.Warning(0, "Filesystem is switched to cpio as only supported for packing."); + // if (Fs.Info.Compression == ImageFormat.Types.CompressionType.IH_COMP_NONE) + // { + // Fs.Info.Compression = ImageFormat.Types.CompressionType.IH_COMP_GZIP; + // Log.Warning(0, "Compression is switched to gzip."); + // } + //} + NyaFs.ImageFormat.Helper.LogHelper.RamfsInfo(Fs); + + if (OldLoaded) + return new ScriptStepResult(ScriptStepStatus.Warning, $"BMU image is loaded as filesystem! Old filesystem is replaced by this."); + else + return new ScriptStepResult(ScriptStepStatus.Ok, $"BMU is loaded as filesystem!"); + } + else + return new ScriptStepResult(ScriptStepStatus.Error, $"Unknown fs format!"); + } + + private ScriptStepResult ReadDtb(ImageProcessor Processor, BmuImage Data) + { + var OldLoaded = Processor.GetDevTree()?.Loaded ?? false; + var Dtb = new NyaFs.ImageFormat.Elements.Dtb.DeviceTree(); + var Reader = new NyaFsBmu.Loader.BmuDevtreeReader(Data); + if (Reader != null) + { + Reader.ReadToDevTree(Dtb); + if (Dtb.Loaded) + { + Processor.SetDeviceTree(Dtb); + AssumeAutoImageParams(Processor); + NyaFs.ImageFormat.Helper.LogHelper.DevtreeInfo(Dtb); + return new ScriptStepResult(ScriptStepStatus.Ok, $"Device tree is loaded from BMU file!"); + } + else + return new ScriptStepResult(ScriptStepStatus.Error, $"Device tree is not loaded!"); + } + else + return new ScriptStepResult(ScriptStepStatus.Error, $"Unknown devtree format!"); + } + + private ScriptStepResult ReadKernel(ImageProcessor Processor, BmuImage Data) + { + var OldLoaded = Processor.GetKernel()?.Loaded ?? false; + var Kernel = new NyaFs.ImageFormat.Elements.Kernel.LinuxKernel(); + var Reader = new NyaFsBmu.Loader.BmuKernelReader(Data); + if (Reader != null) + { + Reader.ReadToKernel(Kernel); + if (Kernel.Loaded) + { + Processor.SetKernel(Kernel); + AssumeAutoKernelParams(Kernel); + AssumeAutoImageParams(Processor); + NyaFs.ImageFormat.Helper.LogHelper.KernelInfo(Kernel); + + if (OldLoaded) + return new ScriptStepResult(ScriptStepStatus.Warning, $"BMU kernel image is loaded as kernel! Old kernel is replaced by this."); + else + return new ScriptStepResult(ScriptStepStatus.Ok, $"BMU kernel image is loaded as kernel!"); + } + else + return new ScriptStepResult(ScriptStepStatus.Error, $"Kernel image file is not loaded!"); + } + else + return new ScriptStepResult(ScriptStepStatus.Error, $"Unknown kernel format!"); + } + } + } +} diff --git a/Plugins/NyaFsBmu/Loader/BmuDevtreeReader.cs b/Plugins/NyaFsBmu/Loader/BmuDevtreeReader.cs new file mode 100644 index 0000000..69f7f07 --- /dev/null +++ b/Plugins/NyaFsBmu/Loader/BmuDevtreeReader.cs @@ -0,0 +1,48 @@ +using NyaFs.Processor.Scripting; +using NyaFs.Processor; +using NyaFsBmu.Types; +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Text; +using NyaFs.ImageFormat.Elements.Kernel; +using NyaFs; +using NyaFs.FlattenedDeviceTree; +using NyaFs.ImageFormat.Elements.Dtb; + +namespace NyaFsBmu.Loader +{ + class BmuDevtreeReader : NyaFs.ImageFormat.Elements.Dtb.Reader.Reader + { + BmuImage Image; + + public BmuDevtreeReader(BmuImage Data) + { + Image = Data; + } + + /// + /// Читаем в дерево устройств из внешнего источника + /// + /// + public override void ReadToDevTree(DeviceTree Dst) + { + var Data = Image.GetImageByType(BmuImageType.DEVTREE); + if (Data != null) + { + var Dtb = new NyaFs.FlattenedDeviceTree.Reader.FDTReader(Data); + if (Dtb.Correct) + { + Dst.DevTree = Dtb.Read(); + Dst.Info.Type = NyaFs.ImageFormat.Types.ImageType.IH_TYPE_FLATDT; + Dst.Info.Compression = NyaFs.ImageFormat.Types.CompressionType.IH_COMP_NONE; + } + else + Log.Error(0, $"Invalid dtb header in BMU"); + } + else + Log.Error(0, $"No dtb in BMU"); + } + } +} diff --git a/Plugins/NyaFsBmu/Loader/BmuFsReader.cs b/Plugins/NyaFsBmu/Loader/BmuFsReader.cs new file mode 100644 index 0000000..ffaae2c --- /dev/null +++ b/Plugins/NyaFsBmu/Loader/BmuFsReader.cs @@ -0,0 +1,74 @@ +using NyaFs.Processor.Scripting; +using NyaFs.Processor; +using NyaFsBmu.Types; +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Text; +using NyaFs.ImageFormat.Elements.Kernel; +using NyaFs; +using NyaIO.Data; + +namespace NyaFsBmu.Loader +{ + class BmuFsReader : NyaFs.ImageFormat.Elements.Fs.Reader.Reader + { + BmuImage Image; + + public BmuFsReader(BmuImage Image) + { + this.Image = Image; + } + + /// + /// Читаем в файловую систему + /// + /// + public override void ReadToFs(NyaFs.ImageFormat.Elements.Fs.LinuxFilesystem Dst) + { + if (Image.Correct) + { + var Raw = Image.GetImageByType(BmuImageType.RAMFS); + + /*byte[] Raw = NyaFs.ImageFormat.Helper.FitHelper.GetDecompressedData(Image.Content, Types.CompressionType.IH_COMP_GZIP); + + if (Dst.Info.Type == Types.ImageType.IH_TYPE_INVALID) + Dst.Info.Type = Types.ImageType.IH_TYPE_RAMDISK; + + Dst.Info.Compression = Types.CompressionType.IH_COMP_GZIP;*/ + + if (Raw != null) + { + var Comp = NyaFs.ImageFormat.Helper.FitHelper.DetectCompression(Raw); + if (Comp != NyaFs.ImageFormat.Types.CompressionType.IH_COMP_NONE) + { + byte[] Decompressed = NyaFs.ImageFormat.Helper.FitHelper.GetDecompressedData(Raw, Comp); + + if(DetectAndRead(Dst, Decompressed)) + { + + } + else + Log.Error(0, "Invalid BMU archive: unknown ramfs format"); + } + else + { + var Header = Raw.ReadUInt32(0); + if (Header == 0x56190527) + { + var Reader = new NyaFs.ImageFormat.Elements.Fs.Reader.LegacyReader(Raw); + Reader.ReadToFs(Dst); + } + else + Log.Error(0, "Invalid BMU archive: unknown ramfs format"); + } + } + else + Log.Error(0, "Invalid BMU archive: no ramfs part"); + } + else + Log.Error(0, "Invalid BMU archive"); + } + } +} diff --git a/Plugins/NyaFsBmu/Loader/BmuKernelReader.cs b/Plugins/NyaFsBmu/Loader/BmuKernelReader.cs new file mode 100644 index 0000000..65000ba --- /dev/null +++ b/Plugins/NyaFsBmu/Loader/BmuKernelReader.cs @@ -0,0 +1,46 @@ +using NyaFs.Processor.Scripting; +using NyaFs.Processor; +using NyaFsBmu.Types; +using System; +using System.Collections.Generic; +using System.IO; +using System.IO.Compression; +using System.Text; +using NyaFs.ImageFormat.Elements.Kernel; +using NyaFs; +using NyaIO.Data; + +namespace NyaFsBmu.Loader +{ + class BmuKernelReader : NyaFs.ImageFormat.Elements.Kernel.Reader.Reader + { + BmuImage Image; + + public BmuKernelReader(BmuImage Data) + { + Image = Data; + } + + public override void ReadToKernel(LinuxKernel Dst) + { + if (Image.Correct) + { + var Raw = Image.GetImageByType(BmuImageType.KERNEL); + + if (Raw != null) + { + var Header = Raw.ReadUInt32(0); + if (Header == 0x56190527) + { + var Reader = new NyaFs.ImageFormat.Elements.Kernel.Reader.LegacyReader(Raw); + Reader.ReadToKernel(Dst); + } + else + Log.Error(0, "Invalid BMU archive: unknown ramfs format"); + } + } + else + Log.Error(0, "Invalid BMU archive"); + } + } +} diff --git a/Plugins/NyaFsBmu/NyaFsBmu.csproj b/Plugins/NyaFsBmu/NyaFsBmu.csproj new file mode 100644 index 0000000..6cf205d --- /dev/null +++ b/Plugins/NyaFsBmu/NyaFsBmu.csproj @@ -0,0 +1,15 @@ + + + + netcoreapp3.1 + + + + + + + + + + + diff --git a/Plugins/NyaFsBmu/NyaFsBmuPlugin.cs b/Plugins/NyaFsBmu/NyaFsBmuPlugin.cs new file mode 100644 index 0000000..3be72f9 --- /dev/null +++ b/Plugins/NyaFsBmu/NyaFsBmuPlugin.cs @@ -0,0 +1,20 @@ +using NyaFs.Processor.Scripting; +using System; + +namespace NyaFsBmu +{ + public class NyaFsBmuPlugin : NyaFs.Processor.Scripting.Plugins.CommandPlugin + { + public NyaFsBmuPlugin() : base("bmu") + { + + } + + public override ScriptStepGenerator[] GetGenerators() + { + return new ScriptStepGenerator[] { + new Commands.LoadBmu() + }; + } + } +} diff --git a/Plugins/NyaFsBmu/Types/BmuImage.cs b/Plugins/NyaFsBmu/Types/BmuImage.cs new file mode 100644 index 0000000..dcc19f3 --- /dev/null +++ b/Plugins/NyaFsBmu/Types/BmuImage.cs @@ -0,0 +1,40 @@ +using NyaIO.Data; +using System; +using System.Collections.Generic; +using System.Text; + +namespace NyaFsBmu.Types +{ + internal class BmuImage : RawPacket + { + public BmuImage(byte[] Data) : base(Data) + { + + } + + public int ImagesCount => ReadByte(0x518); + + public byte[] GetImageByType(BmuImageType Type) + { + int Base = 0x51D; + + uint RawOffset = 0x800; + for(int i = 0; i < ImagesCount; i++) + { + int Offset = Base + i * 5; + + int T = ReadByte(Offset); + uint S = ReadUInt32BE(Offset + 1); + + if (T == Convert.ToInt32(Type)) + return ReadArray(RawOffset, S); + + RawOffset += S; + } + + return null; + } + + public bool Correct => (getLength() > 0x800); + } +} diff --git a/Plugins/NyaFsBmu/Types/BmuImageType.cs b/Plugins/NyaFsBmu/Types/BmuImageType.cs new file mode 100644 index 0000000..e011a48 --- /dev/null +++ b/Plugins/NyaFsBmu/Types/BmuImageType.cs @@ -0,0 +1,17 @@ +using System; +using System.Collections.Generic; +using System.Text; + +namespace NyaFsBmu.Types +{ + internal enum BmuImageType + { + UBOOT = 0, + DEVTREE = 1, + KERNEL = 2, + RAMFS = 3, + UNK1 = 4, + UNK2 = 5, + UNK3 = 6 + } +} diff --git a/Plugins/NyaFsEncrypt/NyaFsEncrypt.csproj b/Plugins/NyaFsEncrypt/NyaFsEncrypt.csproj index 1949741..c11dc04 100644 --- a/Plugins/NyaFsEncrypt/NyaFsEncrypt.csproj +++ b/Plugins/NyaFsEncrypt/NyaFsEncrypt.csproj @@ -9,7 +9,7 @@ - + diff --git a/Plugins/NyaFsFiles/NyaFsFiles.csproj b/Plugins/NyaFsFiles/NyaFsFiles.csproj index 1949741..6cf205d 100644 --- a/Plugins/NyaFsFiles/NyaFsFiles.csproj +++ b/Plugins/NyaFsFiles/NyaFsFiles.csproj @@ -9,7 +9,7 @@ - + diff --git a/Plugins/NyaFsLinux/NyaFsLinux.csproj b/Plugins/NyaFsLinux/NyaFsLinux.csproj index e51b94c..ba581ee 100644 --- a/Plugins/NyaFsLinux/NyaFsLinux.csproj +++ b/Plugins/NyaFsLinux/NyaFsLinux.csproj @@ -9,7 +9,7 @@ - + diff --git a/Plugins/NyaFsSftp/NyaFsSftp.csproj b/Plugins/NyaFsSftp/NyaFsSftp.csproj index e51b94c..ba581ee 100644 --- a/Plugins/NyaFsSftp/NyaFsSftp.csproj +++ b/Plugins/NyaFsSftp/NyaFsSftp.csproj @@ -9,7 +9,7 @@ - + diff --git a/Plugins/NyaFsTftp/NyaFsTftp.csproj b/Plugins/NyaFsTftp/NyaFsTftp.csproj index f67c200..4b495e4 100644 --- a/Plugins/NyaFsTftp/NyaFsTftp.csproj +++ b/Plugins/NyaFsTftp/NyaFsTftp.csproj @@ -6,7 +6,7 @@ - +