1
0
Fork 0
mirror of https://github.com/Ryujinx/Ryujinx.git synced 2024-11-30 20:02:02 +00:00

prepo: Silent error while parsing report (#837)

Due to a guessed parsing implementation of the report, sometime it throw an error, since the data isn't really useful, it's better to silent possible exceptions with a message.
This commit is contained in:
Ac_K 2019-11-29 05:42:44 +01:00 committed by jduncanator
parent da4e0856c9
commit bb7600e215

View file

@ -93,94 +93,101 @@ namespace Ryujinx.HLE.HOS.Services.Prepo
sb.AppendLine($" Room: {room}"); sb.AppendLine($" Room: {room}");
using (MemoryStream stream = new MemoryStream(buffer)) try
using (BinaryReader reader = new BinaryReader(stream))
{ {
byte unknown1 = reader.ReadByte(); // Version ? using (MemoryStream stream = new MemoryStream(buffer))
short unknown2 = reader.ReadInt16(); // Size ? using (BinaryReader reader = new BinaryReader(stream))
bool isValue = false;
string fieldStr = string.Empty;
while (stream.Position != stream.Length)
{ {
byte descriptor = reader.ReadByte(); byte unknown1 = reader.ReadByte(); // Version ?
short unknown2 = reader.ReadInt16(); // Size ?
if (!isValue) bool isValue = false;
string fieldStr = string.Empty;
while (stream.Position != stream.Length)
{ {
byte[] key = reader.ReadBytes(descriptor - 0xA0); byte descriptor = reader.ReadByte();
fieldStr = $" Key: {Encoding.ASCII.GetString(key)}"; if (!isValue)
isValue = true;
}
else
{
if (descriptor > 0xD0) // Int value.
{ {
if (descriptor - 0xD0 == 1) byte[] key = reader.ReadBytes(descriptor - 0xA0);
{
fieldStr += $", Value: {BinaryPrimitives.ReverseEndianness(reader.ReadUInt16())}"; fieldStr = $" Key: {Encoding.ASCII.GetString(key)}";
}
else if (descriptor - 0xD0 == 2) isValue = true;
{
fieldStr += $", Value: {BinaryPrimitives.ReverseEndianness(reader.ReadInt32())}";
}
else if (descriptor - 0xD0 == 4)
{
fieldStr += $", Value: {BinaryPrimitives.ReverseEndianness(reader.ReadInt64())}";
}
else
{
// Unknown.
break;
}
} }
else if (descriptor > 0xA0 && descriptor < 0xD0) // String value, max size = 0x20 bytes ? else
{ {
int size = descriptor - 0xA0; if (descriptor > 0xD0) // Int value.
string value = string.Empty;
byte[] rawValues = new byte[0];
for (int i = 0; i < size; i++)
{ {
byte chr = reader.ReadByte(); if (descriptor - 0xD0 == 1)
if (chr >= 0x20 && chr < 0x7f)
{ {
value += (char)chr; fieldStr += $", Value: {BinaryPrimitives.ReverseEndianness(reader.ReadUInt16())}";
}
else if (descriptor - 0xD0 == 2)
{
fieldStr += $", Value: {BinaryPrimitives.ReverseEndianness(reader.ReadInt32())}";
}
else if (descriptor - 0xD0 == 4)
{
fieldStr += $", Value: {BinaryPrimitives.ReverseEndianness(reader.ReadInt64())}";
} }
else else
{ {
Array.Resize(ref rawValues, rawValues.Length + 1); // Unknown.
break;
rawValues[rawValues.Length - 1] = chr;
} }
} }
else if (descriptor > 0xA0 && descriptor < 0xD0) // String value, max size = 0x20 bytes ?
if (value != string.Empty)
{
fieldStr += $", Value: {value}";
}
// TODO(Ac_K): Determine why there are non-alphanumeric values sometimes.
if (rawValues.Length > 0)
{ {
fieldStr += $", RawValue: 0x{BitConverter.ToString(rawValues).Replace("-", "")}"; int size = descriptor - 0xA0;
string value = string.Empty;
byte[] rawValues = new byte[0];
for (int i = 0; i < size; i++)
{
byte chr = reader.ReadByte();
if (chr >= 0x20 && chr < 0x7f)
{
value += (char)chr;
}
else
{
Array.Resize(ref rawValues, rawValues.Length + 1);
rawValues[rawValues.Length - 1] = chr;
}
}
if (value != string.Empty)
{
fieldStr += $", Value: {value}";
}
// TODO(Ac_K): Determine why there are non-alphanumeric values sometimes.
if (rawValues.Length > 0)
{
fieldStr += $", RawValue: 0x{BitConverter.ToString(rawValues).Replace("-", "")}";
}
}
else // Byte value.
{
fieldStr += $", Value: {descriptor}";
} }
}
else // Byte value.
{
fieldStr += $", Value: {descriptor}";
}
sb.AppendLine(fieldStr); sb.AppendLine(fieldStr);
isValue = false; isValue = false;
}
} }
} }
} }
catch (Exception)
{
sb.AppendLine(" Error while parsing the report buffer.");
}
return sb.ToString(); return sb.ToString();
} }