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