2018-10-17 17:15:50 +00:00
|
|
|
using Ryujinx.Common.Logging;
|
2018-02-25 18:58:16 +00:00
|
|
|
using System.IO;
|
|
|
|
using System.Text;
|
|
|
|
|
2019-09-19 00:45:11 +00:00
|
|
|
namespace Ryujinx.HLE.HOS.Services.Lm.LogService
|
2018-02-25 18:58:16 +00:00
|
|
|
{
|
2018-03-19 18:58:46 +00:00
|
|
|
class ILogger : IpcService
|
2018-02-25 18:58:16 +00:00
|
|
|
{
|
2019-07-12 01:13:43 +00:00
|
|
|
public ILogger() { }
|
2018-02-25 18:58:16 +00:00
|
|
|
|
2019-12-08 13:35:25 +00:00
|
|
|
private static int ReadEncodedInt(BinaryReader reader)
|
|
|
|
{
|
|
|
|
int result = 0;
|
|
|
|
int position = 0;
|
|
|
|
|
|
|
|
byte encoded;
|
|
|
|
|
|
|
|
do
|
|
|
|
{
|
|
|
|
encoded = reader.ReadByte();
|
|
|
|
|
|
|
|
result += (encoded & 0x7F) << (7 * position);
|
|
|
|
|
|
|
|
position++;
|
|
|
|
|
|
|
|
} while ((encoded & 0x80) != 0);
|
|
|
|
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
2019-07-12 01:13:43 +00:00
|
|
|
[Command(0)]
|
|
|
|
// Log(buffer<unknown, 0x21>)
|
2019-07-14 19:04:38 +00:00
|
|
|
public ResultCode Log(ServiceCtx context)
|
2018-02-25 18:58:16 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
(long bufPos, long bufSize) = context.Request.GetBufferType0x21();
|
2020-05-03 22:54:50 +00:00
|
|
|
|
|
|
|
byte[] logBuffer = new byte[bufSize];
|
|
|
|
|
|
|
|
context.Memory.Read((ulong)bufPos, logBuffer);
|
2018-02-25 18:58:16 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
using (MemoryStream ms = new MemoryStream(logBuffer))
|
2018-04-24 18:57:39 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
BinaryReader reader = new BinaryReader(ms);
|
2018-02-25 18:58:16 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
long pid = reader.ReadInt64();
|
|
|
|
long threadContext = reader.ReadInt64();
|
|
|
|
short flags = reader.ReadInt16();
|
|
|
|
byte level = reader.ReadByte();
|
|
|
|
byte verbosity = reader.ReadByte();
|
|
|
|
int payloadLength = reader.ReadInt32();
|
2018-02-25 18:58:16 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
StringBuilder sb = new StringBuilder();
|
2018-02-25 18:58:16 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
sb.AppendLine("Guest log:");
|
2018-02-25 18:58:16 +00:00
|
|
|
|
2019-06-16 01:31:18 +00:00
|
|
|
sb.AppendLine($" Log level: {(LmLogLevel)level}");
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
while (ms.Position < ms.Length)
|
2018-02-25 18:58:16 +00:00
|
|
|
{
|
2019-12-08 13:35:25 +00:00
|
|
|
int type = ReadEncodedInt(reader);
|
|
|
|
int size = ReadEncodedInt(reader);
|
2018-02-25 18:58:16 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
LmLogField field = (LmLogField)type;
|
2018-02-25 18:58:16 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
string fieldStr = string.Empty;
|
2018-02-25 18:58:16 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
if (field == LmLogField.Start)
|
2018-04-24 18:57:39 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
reader.ReadBytes(size);
|
2018-02-25 18:58:16 +00:00
|
|
|
|
2018-04-24 18:57:39 +00:00
|
|
|
continue;
|
|
|
|
}
|
2018-12-06 11:16:24 +00:00
|
|
|
else if (field == LmLogField.Stop)
|
2018-08-22 21:06:29 +00:00
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
2018-12-06 11:16:24 +00:00
|
|
|
else if (field == LmLogField.Line)
|
2018-04-24 18:57:39 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
fieldStr = $"{field}: {reader.ReadInt32()}";
|
2018-02-25 18:58:16 +00:00
|
|
|
}
|
2018-12-06 11:16:24 +00:00
|
|
|
else if (field == LmLogField.DropCount)
|
2018-08-22 21:06:29 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
fieldStr = $"{field}: {reader.ReadInt64()}";
|
2018-08-22 21:06:29 +00:00
|
|
|
}
|
2018-12-06 11:16:24 +00:00
|
|
|
else if (field == LmLogField.Time)
|
2018-08-22 21:06:29 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
fieldStr = $"{field}: {reader.ReadInt64()}s";
|
2018-08-22 21:06:29 +00:00
|
|
|
}
|
2018-12-06 11:16:24 +00:00
|
|
|
else if (field < LmLogField.Count)
|
2018-04-24 18:57:39 +00:00
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
fieldStr = $"{field}: '{Encoding.UTF8.GetString(reader.ReadBytes(size)).TrimEnd()}'";
|
2018-04-24 18:57:39 +00:00
|
|
|
}
|
2018-08-22 21:06:29 +00:00
|
|
|
else
|
|
|
|
{
|
2018-12-06 11:16:24 +00:00
|
|
|
fieldStr = $"Field{field}: '{Encoding.UTF8.GetString(reader.ReadBytes(size)).TrimEnd()}'";
|
2018-08-22 21:06:29 +00:00
|
|
|
}
|
2018-04-24 18:57:39 +00:00
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
sb.AppendLine(" " + fieldStr);
|
2018-02-25 18:58:16 +00:00
|
|
|
}
|
|
|
|
|
2018-12-06 11:16:24 +00:00
|
|
|
string text = sb.ToString();
|
2018-02-25 18:58:16 +00:00
|
|
|
|
2019-06-16 01:31:18 +00:00
|
|
|
Logger.PrintGuest(LogClass.ServiceLm, text);
|
2018-02-25 18:58:16 +00:00
|
|
|
}
|
|
|
|
|
2019-07-14 19:04:38 +00:00
|
|
|
return ResultCode.Success;
|
2018-02-25 18:58:16 +00:00
|
|
|
}
|
|
|
|
}
|
2019-07-12 01:13:43 +00:00
|
|
|
}
|