2018-11-18 20:37:41 +01:00
|
|
|
|
using System.IO;
|
|
|
|
|
|
|
|
|
|
namespace Ryujinx.HLE.Utilities
|
|
|
|
|
{
|
|
|
|
|
public static class FontUtils
|
|
|
|
|
{
|
|
|
|
|
private static readonly uint FontKey = 0x06186249;
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
public static byte[] DecryptFont(Stream bfttfStream)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2020-04-20 23:59:59 +02:00
|
|
|
|
uint KXor(uint In) => In ^ FontKey;
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
using (BinaryReader reader = new BinaryReader(bfttfStream))
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
using (MemoryStream ttfStream = new MemoryStream())
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
using (BinaryWriter output = new BinaryWriter(ttfStream))
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
if (KXor(reader.ReadUInt32()) != 0x18029a7f)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
|
|
|
|
throw new InvalidDataException("Error: Input file is not in BFTTF format!");
|
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
bfttfStream.Position += 4;
|
2018-11-18 20:37:41 +01:00
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
for (int i = 0; i < (bfttfStream.Length - 8) / 4; i++)
|
2018-11-18 20:37:41 +01:00
|
|
|
|
{
|
2018-12-06 12:16:24 +01:00
|
|
|
|
output.Write(KXor(reader.ReadUInt32()));
|
2018-11-18 20:37:41 +01:00
|
|
|
|
}
|
|
|
|
|
|
2018-12-06 12:16:24 +01:00
|
|
|
|
return ttfStream.ToArray();
|
2018-11-18 20:37:41 +01:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|