From 220cd1638092114c59a748012521f34c13d36d55 Mon Sep 17 00:00:00 2001 From: emmaus Date: Sun, 4 Nov 2018 18:02:00 +0000 Subject: [PATCH] read system firmware version from nand --- .../HOS/Services/FspSrv/IFileSystemProxy.cs | 2 +- .../HOS/Services/Set/ISystemSettingsServer.cs | 60 +++++++++++++++++++ .../PublishProfiles/FolderProfile.pubxml | 14 +++++ 3 files changed, 75 insertions(+), 1 deletion(-) create mode 100644 Ryujinx/Properties/PublishProfiles/FolderProfile.pubxml diff --git a/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs b/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs index 82277bb68b..2db56c1ff3 100644 --- a/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs +++ b/Ryujinx.HLE/HOS/Services/FspSrv/IFileSystemProxy.cs @@ -23,8 +23,8 @@ namespace Ryujinx.HLE.HOS.Services.FspSrv m_Commands = new Dictionary() { { 1, SetCurrentProcess }, - { 11, OpenBisFileSystem }, { 8, OpenFileSystemWithId }, + { 11, OpenBisFileSystem }, { 18, OpenSdCardFileSystem }, { 51, OpenSaveDataFileSystem }, { 52, OpenSaveDataFileSystemBySystemSaveDataId }, diff --git a/Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs b/Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs index 070a4d5e4d..eb5adfc2af 100644 --- a/Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs +++ b/Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs @@ -5,6 +5,8 @@ using System; using System.Collections.Generic; using System.IO; using System.Text; +using LibHac; +using Ryujinx.HLE.FileSystem; namespace Ryujinx.HLE.HOS.Services.Set { @@ -18,6 +20,7 @@ namespace Ryujinx.HLE.HOS.Services.Set { m_Commands = new Dictionary() { + { 3, GetFirmwareVersion }, { 4, GetFirmwareVersion2 }, { 23, GetColorSetId }, { 24, SetColorSetId }, @@ -25,11 +28,25 @@ namespace Ryujinx.HLE.HOS.Services.Set }; } + public static long GetFirmwareVersion(ServiceCtx Context) + { + return GetFirmwareVersion2(Context); + } + public static long GetFirmwareVersion2(ServiceCtx Context) { long ReplyPos = Context.Request.RecvListBuff[0].Position; long ReplySize = Context.Request.RecvListBuff[0].Size; + byte[] FirmwareData = GetFirmwareData(Context.Device); + + if (FirmwareData != null) + { + Context.Memory.WriteBytes(ReplyPos, FirmwareData); + + return 0; + } + const byte MajorFWVersion = 0x03; const byte MinorFWVersion = 0x00; const byte MicroFWVersion = 0x00; @@ -148,5 +165,48 @@ namespace Ryujinx.HLE.HOS.Services.Set return 0; } + + public static byte[] GetFirmwareData(Switch Device) + { + byte[] Data = null; + + long TitleId = 0x0100000000000809; + + string Path = Device.System.ContentManager.GetInstalledPath(TitleId, ContentType.Data, StorageId.NandSystem); + + if(string.IsNullOrWhiteSpace(Path)) + { + return null; + } + + FileStream FirmwareStream = File.Open(Path, FileMode.Open, FileAccess.Read); + + Nca FirmwareContent = new Nca(Device.System.KeySet, FirmwareStream, false); + + Stream RomFsStream = FirmwareContent.OpenSection(0, false, Device.System.FsIntegrityCheckLevel); + + if(RomFsStream == null) + { + return null; + } + + Romfs FirmwareRomFs = new Romfs(RomFsStream); + + using(MemoryStream MemoryStream = new MemoryStream()) + { + using (Stream FirmwareFile = FirmwareRomFs.OpenFile("/file")) + { + FirmwareFile.CopyTo(MemoryStream); + } + + Data = MemoryStream.ToArray(); + } + + FirmwareContent.Dispose(); + + FirmwareStream.Dispose(); + + return Data; + } } } diff --git a/Ryujinx/Properties/PublishProfiles/FolderProfile.pubxml b/Ryujinx/Properties/PublishProfiles/FolderProfile.pubxml new file mode 100644 index 0000000000..8efb51d463 --- /dev/null +++ b/Ryujinx/Properties/PublishProfiles/FolderProfile.pubxml @@ -0,0 +1,14 @@ + + + + + FileSystem + Release + Any CPU + netcoreapp2.1 + bin\Release\netcoreapp2.1\publish\ + win10-x64 + + \ No newline at end of file