IStorage.cs 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. using ChocolArm64.Memory;
  2. using Ryujinx.Core.OsHle.Ipc;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. namespace Ryujinx.Core.OsHle.Objects.FspSrv
  6. {
  7. class IStorage : IIpcInterface
  8. {
  9. private Dictionary<int, ServiceProcessRequest> m_Commands;
  10. public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  11. private Stream BaseStream;
  12. public IStorage(Stream BaseStream)
  13. {
  14. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  15. {
  16. { 0, Read }
  17. };
  18. this.BaseStream = BaseStream;
  19. }
  20. public long Read(ServiceCtx Context)
  21. {
  22. long Offset = Context.RequestData.ReadInt64();
  23. long Size = Context.RequestData.ReadInt64();
  24. if (Context.Request.ReceiveBuff.Count > 0)
  25. {
  26. IpcBuffDesc BuffDesc = Context.Request.ReceiveBuff[0];
  27. //Use smaller length to avoid overflows.
  28. if (Size > BuffDesc.Size)
  29. {
  30. Size = BuffDesc.Size;
  31. }
  32. byte[] Data = new byte[Size];
  33. BaseStream.Seek(Offset, SeekOrigin.Begin);
  34. BaseStream.Read(Data, 0, Data.Length);
  35. AMemoryHelper.WriteBytes(Context.Memory, BuffDesc.Position, Data);
  36. }
  37. return 0;
  38. }
  39. }
  40. }