pl_u: Expose method to encrypt TTF to BFTTF
This commit is contained in:
parent
361a8fa318
commit
ae9604faba
2 changed files with 14 additions and 14 deletions
|
@ -6,13 +6,6 @@
|
||||||
#include <cstring>
|
#include <cstring>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
|
|
||||||
#include <FontChineseSimplified.h>
|
|
||||||
#include <FontChineseTraditional.h>
|
|
||||||
#include <FontExtendedChineseSimplified.h>
|
|
||||||
#include <FontKorean.h>
|
|
||||||
#include <FontNintendoExtended.h>
|
|
||||||
#include <FontStandard.h>
|
|
||||||
|
|
||||||
#include "common/assert.h"
|
#include "common/assert.h"
|
||||||
#include "common/common_paths.h"
|
#include "common/common_paths.h"
|
||||||
#include "common/common_types.h"
|
#include "common/common_types.h"
|
||||||
|
@ -96,13 +89,18 @@ static void DecryptSharedFont(const std::vector<u32>& input, Kernel::PhysicalMem
|
||||||
|
|
||||||
static void EncryptSharedFont(const std::vector<u8>& input, Kernel::PhysicalMemory& output,
|
static void EncryptSharedFont(const std::vector<u8>& input, Kernel::PhysicalMemory& output,
|
||||||
std::size_t& offset) {
|
std::size_t& offset) {
|
||||||
ASSERT_MSG(offset + input.size() + 8 < SHARED_FONT_MEM_SIZE, "Shared fonts exceeds 17mb!");
|
ASSERT_MSG(offset + (input.size() * sizeof(u32)) < SHARED_FONT_MEM_SIZE,
|
||||||
const u32 KEY = EXPECTED_MAGIC ^ EXPECTED_RESULT;
|
"Shared fonts exceeds 17mb!");
|
||||||
std::memcpy(output.data() + offset, &EXPECTED_RESULT, sizeof(u32)); // Magic header
|
|
||||||
const u32 ENC_SIZE = static_cast<u32>(input.size()) ^ KEY;
|
const auto key = Common::swap32(EXPECTED_RESULT ^ EXPECTED_MAGIC);
|
||||||
std::memcpy(output.data() + offset + sizeof(u32), &ENC_SIZE, sizeof(u32));
|
std::vector<u32> transformed_font(input.size() + 2);
|
||||||
std::memcpy(output.data() + offset + (sizeof(u32) * 2), input.data(), input.size());
|
transformed_font[0] = Common::swap32(EXPECTED_MAGIC);
|
||||||
offset += input.size() + (sizeof(u32) * 2);
|
transformed_font[1] = Common::swap32(input.size() * sizeof(u32)) ^ key;
|
||||||
|
std::transform(input.begin(), input.end(), transformed_font.begin() + 2,
|
||||||
|
[key](u32 in) { return in ^ key; });
|
||||||
|
std::memcpy(output.data() + offset, transformed_font.data(),
|
||||||
|
transformed_font.size() * sizeof(u32));
|
||||||
|
offset += transformed_font.size() * sizeof(u32);
|
||||||
}
|
}
|
||||||
|
|
||||||
// Helper function to make BuildSharedFontsRawRegions a bit nicer
|
// Helper function to make BuildSharedFontsRawRegions a bit nicer
|
||||||
|
|
|
@ -9,6 +9,8 @@
|
||||||
|
|
||||||
namespace Service::NS {
|
namespace Service::NS {
|
||||||
|
|
||||||
|
void EncryptSharedFont(const std::vector<u32>& input, std::vector<u8>& output, std::size_t& offset);
|
||||||
|
|
||||||
class PL_U final : public ServiceFramework<PL_U> {
|
class PL_U final : public ServiceFramework<PL_U> {
|
||||||
public:
|
public:
|
||||||
PL_U();
|
PL_U();
|
||||||
|
|
Loading…
Reference in a new issue