From fe8fbb6fb9b85a528ddfa4848ec8e35fd9a5e9a5 Mon Sep 17 00:00:00 2001 From: emmauss Date: Sun, 18 Nov 2018 21:37:41 +0200 Subject: Implement ContentManager and related services (#438) * Implement contentmanager and related services * small changes * read system firmware version from nand * add pfs support, write directoryentry info for romfs files * add file check in fsp-srv:8 * add support for open fs of internal files * fix filename when accessing pfs * use switch style paths for contentpath * close nca after verifying type * removed publishing profiles, align directory entry * fix style * lots of style fixes * yasf(yet another style fix) * yasf(yet another style fix) plus symbols * enforce path check on every fs access * change enum type to default * fix typo --- .../HOS/Services/Set/ISystemSettingsServer.cs | 61 ++++++++++++++++++++++ 1 file changed, 61 insertions(+) (limited to 'Ryujinx.HLE/HOS/Services/Set') diff --git a/Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs b/Ryujinx.HLE/HOS/Services/Set/ISystemSettingsServer.cs index 070a4d5e..416ea1fb 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,27 @@ namespace Ryujinx.HLE.HOS.Services.Set }; } + // GetFirmwareVersion() -> buffer + public static long GetFirmwareVersion(ServiceCtx Context) + { + return GetFirmwareVersion2(Context); + } + + // GetFirmwareVersion2() -> buffer 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; @@ -74,6 +93,7 @@ namespace Ryujinx.HLE.HOS.Services.Set return 0; } + // GetColorSetId() -> i32 public static long GetColorSetId(ServiceCtx Context) { Context.ResponseData.Write((int)Context.Device.System.State.ThemeColor); @@ -81,6 +101,7 @@ namespace Ryujinx.HLE.HOS.Services.Set return 0; } + // GetColorSetId() -> i32 public static long SetColorSetId(ServiceCtx Context) { int ColorSetId = Context.RequestData.ReadInt32(); @@ -90,6 +111,7 @@ namespace Ryujinx.HLE.HOS.Services.Set return 0; } + // GetSettingsItemValue(buffer, buffer) -> (u64, buffer) public static long GetSettingsItemValue(ServiceCtx Context) { long ClassPos = Context.Request.PtrBuff[0].Position; @@ -148,5 +170,44 @@ namespace Ryujinx.HLE.HOS.Services.Set return 0; } + + public static byte[] GetFirmwareData(Switch Device) + { + byte[] Data = null; + long TitleId = 0x0100000000000809; + string ContentPath = Device.System.ContentManager.GetInstalledContentPath(TitleId, StorageId.NandSystem, ContentType.Data); + + if(string.IsNullOrWhiteSpace(ContentPath)) + { + return null; + } + + string FirmwareTitlePath = Device.FileSystem.SwitchPathToSystemPath(ContentPath); + FileStream FirmwareStream = File.Open(FirmwareTitlePath, 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; + } } } -- cgit v1.2.3