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