IStorageAccessor.cs 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768
  1. using ChocolArm64.Memory;
  2. using Ryujinx.OsHle.Ipc;
  3. using System;
  4. using System.Collections.Generic;
  5. namespace Ryujinx.OsHle.Objects.Am
  6. {
  7. class IStorageAccessor : IIpcInterface
  8. {
  9. private Dictionary<int, ServiceProcessRequest> m_Commands;
  10. public IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  11. public IStorage Storage { get; private set; }
  12. public IStorageAccessor(IStorage Storage)
  13. {
  14. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  15. {
  16. { 0, GetSize },
  17. { 11, Read }
  18. };
  19. this.Storage = Storage;
  20. }
  21. public long GetSize(ServiceCtx Context)
  22. {
  23. IStorageAccessor Accessor = Context.GetObject<IStorageAccessor>();
  24. Context.ResponseData.Write((long)Accessor.Storage.Data.Length);
  25. return 0;
  26. }
  27. public long Read(ServiceCtx Context)
  28. {
  29. IStorageAccessor Accessor = Context.GetObject<IStorageAccessor>();
  30. IStorage Storage = Accessor.Storage;
  31. long ReadPosition = Context.RequestData.ReadInt64();
  32. if (Context.Request.RecvListBuff.Count > 0)
  33. {
  34. long Position = Context.Request.RecvListBuff[0].Position;
  35. short Size = Context.Request.RecvListBuff[0].Size;
  36. byte[] Data;
  37. if (Storage.Data.Length > Size)
  38. {
  39. Data = new byte[Size];
  40. Buffer.BlockCopy(Storage.Data, 0, Data, 0, Size);
  41. }
  42. else
  43. {
  44. Data = Storage.Data;
  45. }
  46. AMemoryHelper.WriteBytes(Context.Memory, Position, Data);
  47. }
  48. return 0;
  49. }
  50. }
  51. }