IRandomInterface.cs 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950
  1. using Ryujinx.HLE.OsHle.Ipc;
  2. using System;
  3. using System.Collections.Generic;
  4. using System.Security.Cryptography;
  5. namespace Ryujinx.HLE.OsHle.Services.Spl
  6. {
  7. class IRandomInterface : IpcService, IDisposable
  8. {
  9. private Dictionary<int, ServiceProcessRequest> m_Commands;
  10. public override IReadOnlyDictionary<int, ServiceProcessRequest> Commands => m_Commands;
  11. private RNGCryptoServiceProvider Rng;
  12. public IRandomInterface()
  13. {
  14. m_Commands = new Dictionary<int, ServiceProcessRequest>()
  15. {
  16. { 0, GetRandomBytes }
  17. };
  18. Rng = new RNGCryptoServiceProvider();
  19. }
  20. public long GetRandomBytes(ServiceCtx Context)
  21. {
  22. byte[] RandomBytes = new byte[Context.Request.ReceiveBuff[0].Size];
  23. Rng.GetBytes(RandomBytes);
  24. Context.Memory.WriteBytes(Context.Request.ReceiveBuff[0].Position, RandomBytes);
  25. return 0;
  26. }
  27. public void Dispose()
  28. {
  29. Dispose(true);
  30. }
  31. protected virtual void Dispose(bool Disposing)
  32. {
  33. if (Disposing)
  34. {
  35. Rng.Dispose();
  36. }
  37. }
  38. }
  39. }