From 3bdf9d980509bf018a9c14ef2e4a4583a9e944cd Mon Sep 17 00:00:00 2001 From: merry Date: Sat, 19 Feb 2022 15:16:39 +0000 Subject: [PATCH] Implement binary data escaping --- src/Ryujinx.HLE/Debugger/Debugger.cs | 23 +++++++++++++++++++++-- 1 file changed, 21 insertions(+), 2 deletions(-) diff --git a/src/Ryujinx.HLE/Debugger/Debugger.cs b/src/Ryujinx.HLE/Debugger/Debugger.cs index 7c9815d606..84f04db618 100644 --- a/src/Ryujinx.HLE/Debugger/Debugger.cs +++ b/src/Ryujinx.HLE/Debugger/Debugger.cs @@ -283,12 +283,12 @@ namespace Ryujinx.HLE.Debugger if (len >= (ulong)data.Length - addr) { - Reply("l" + data.Substring((int)addr)); + Reply("l" + ToBinaryFormat(data.Substring((int)addr))); break; } else { - Reply("m" + data.Substring((int)addr, (int)len)); + Reply("m" + ToBinaryFormat(data.Substring((int)addr, (int)len))); break; } } @@ -624,6 +624,25 @@ namespace Ryujinx.HLE.Debugger return ToHex(Encoding.ASCII.GetBytes(str)); } + private string ToBinaryFormat(byte[] bytes) + { + return string.Join("", bytes.Select(x => + x switch + { + (byte)'#' => "}\x03", + (byte)'$' => "}\x04", + (byte)'*' => "}\x0a", + (byte)'}' => "}\x5d", + _ => Convert.ToChar(x).ToString(), + } + )); + } + + private string ToBinaryFormat(string str) + { + return ToBinaryFormat(Encoding.ASCII.GetBytes(str)); + } + public void Dispose() { Dispose(true);