ILogger.cs 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586
  1. using Ryujinx.Common.Logging;
  2. using System.IO;
  3. using System.Text;
  4. namespace Ryujinx.HLE.HOS.Services.Lm.LogService
  5. {
  6. class ILogger : IpcService
  7. {
  8. public ILogger() { }
  9. [Command(0)]
  10. // Log(buffer<unknown, 0x21>)
  11. public ResultCode Log(ServiceCtx context)
  12. {
  13. (long bufPos, long bufSize) = context.Request.GetBufferType0x21();
  14. byte[] logBuffer = context.Memory.ReadBytes(bufPos, bufSize);
  15. using (MemoryStream ms = new MemoryStream(logBuffer))
  16. {
  17. BinaryReader reader = new BinaryReader(ms);
  18. long pid = reader.ReadInt64();
  19. long threadContext = reader.ReadInt64();
  20. short flags = reader.ReadInt16();
  21. byte level = reader.ReadByte();
  22. byte verbosity = reader.ReadByte();
  23. int payloadLength = reader.ReadInt32();
  24. StringBuilder sb = new StringBuilder();
  25. sb.AppendLine("Guest log:");
  26. sb.AppendLine($" Log level: {(LmLogLevel)level}");
  27. while (ms.Position < ms.Length)
  28. {
  29. byte type = reader.ReadByte();
  30. byte size = reader.ReadByte();
  31. LmLogField field = (LmLogField)type;
  32. string fieldStr = string.Empty;
  33. if (field == LmLogField.Start)
  34. {
  35. reader.ReadBytes(size);
  36. continue;
  37. }
  38. else if (field == LmLogField.Stop)
  39. {
  40. break;
  41. }
  42. else if (field == LmLogField.Line)
  43. {
  44. fieldStr = $"{field}: {reader.ReadInt32()}";
  45. }
  46. else if (field == LmLogField.DropCount)
  47. {
  48. fieldStr = $"{field}: {reader.ReadInt64()}";
  49. }
  50. else if (field == LmLogField.Time)
  51. {
  52. fieldStr = $"{field}: {reader.ReadInt64()}s";
  53. }
  54. else if (field < LmLogField.Count)
  55. {
  56. fieldStr = $"{field}: '{Encoding.UTF8.GetString(reader.ReadBytes(size)).TrimEnd()}'";
  57. }
  58. else
  59. {
  60. fieldStr = $"Field{field}: '{Encoding.UTF8.GetString(reader.ReadBytes(size)).TrimEnd()}'";
  61. }
  62. sb.AppendLine(" " + fieldStr);
  63. }
  64. string text = sb.ToString();
  65. Logger.PrintGuest(LogClass.ServiceLm, text);
  66. }
  67. return ResultCode.Success;
  68. }
  69. }
  70. }