summaryrefslogtreecommitdiffstats
path: root/src/core/hle/service/am/applets/web_browser.cpp
diff options
context:
space:
mode:
authorMorph <39850852+Morph1984@users.noreply.github.com>2020-11-29 16:54:09 +0100
committerMorph <39850852+Morph1984@users.noreply.github.com>2020-12-18 16:33:28 +0100
commitd46ca5a0157a5267b4c2ebf0515f1a492434071a (patch)
treea10347483315f757056382b4d552098d32c4e9f8 /src/core/hle/service/am/applets/web_browser.cpp
parentns_vm: Stub NeedsUpdateVulnerability (diff)
downloadyuzu-d46ca5a0157a5267b4c2ebf0515f1a492434071a.tar
yuzu-d46ca5a0157a5267b4c2ebf0515f1a492434071a.tar.gz
yuzu-d46ca5a0157a5267b4c2ebf0515f1a492434071a.tar.bz2
yuzu-d46ca5a0157a5267b4c2ebf0515f1a492434071a.tar.lz
yuzu-d46ca5a0157a5267b4c2ebf0515f1a492434071a.tar.xz
yuzu-d46ca5a0157a5267b4c2ebf0515f1a492434071a.tar.zst
yuzu-d46ca5a0157a5267b4c2ebf0515f1a492434071a.zip
Diffstat (limited to 'src/core/hle/service/am/applets/web_browser.cpp')
-rw-r--r--src/core/hle/service/am/applets/web_browser.cpp86
1 files changed, 86 insertions, 0 deletions
diff --git a/src/core/hle/service/am/applets/web_browser.cpp b/src/core/hle/service/am/applets/web_browser.cpp
index c0c98ad30..02ce9f387 100644
--- a/src/core/hle/service/am/applets/web_browser.cpp
+++ b/src/core/hle/service/am/applets/web_browser.cpp
@@ -16,12 +16,14 @@
#include "core/file_sys/romfs.h"
#include "core/file_sys/system_archive/system_archive.h"
#include "core/file_sys/vfs_types.h"
+#include "core/file_sys/vfs_vector.h"
#include "core/frontend/applets/web_browser.h"
#include "core/hle/kernel/process.h"
#include "core/hle/result.h"
#include "core/hle/service/am/am.h"
#include "core/hle/service/am/applets/web_browser.h"
#include "core/hle/service/filesystem/filesystem.h"
+#include "core/hle/service/ns/pl_u.h"
namespace Service::AM::Applets {
@@ -123,6 +125,88 @@ FileSys::VirtualFile GetOfflineRomFS(Core::System& system, u64 title_id,
}
}
+void ExtractSharedFonts(Core::System& system) {
+ static constexpr std::array<const char*, 7> DECRYPTED_SHARED_FONTS{
+ "FontStandard.ttf",
+ "FontChineseSimplified.ttf",
+ "FontExtendedChineseSimplified.ttf",
+ "FontChineseTraditional.ttf",
+ "FontKorean.ttf",
+ "FontNintendoExtended.ttf",
+ "FontNintendoExtended2.ttf",
+ };
+
+ for (std::size_t i = 0; i < NS::SHARED_FONTS.size(); ++i) {
+ const auto fonts_dir = Common::FS::SanitizePath(
+ fmt::format("{}/fonts", Common::FS::GetUserPath(Common::FS::UserPath::CacheDir)),
+ Common::FS::DirectorySeparator::PlatformDefault);
+
+ const auto font_file_path =
+ Common::FS::SanitizePath(fmt::format("{}/{}", fonts_dir, DECRYPTED_SHARED_FONTS[i]),
+ Common::FS::DirectorySeparator::PlatformDefault);
+
+ if (Common::FS::Exists(font_file_path)) {
+ continue;
+ }
+
+ const auto font = NS::SHARED_FONTS[i];
+ const auto font_title_id = static_cast<u64>(font.first);
+
+ const auto nca = system.GetFileSystemController().GetSystemNANDContents()->GetEntry(
+ font_title_id, FileSys::ContentRecordType::Data);
+
+ FileSys::VirtualFile romfs;
+
+ if (!nca) {
+ romfs = FileSys::SystemArchive::SynthesizeSystemArchive(font_title_id);
+ } else {
+ romfs = nca->GetRomFS();
+ }
+
+ if (!romfs) {
+ LOG_ERROR(Service_AM, "SharedFont RomFS with title_id={:016X} cannot be extracted!",
+ font_title_id);
+ continue;
+ }
+
+ const auto extracted_romfs = FileSys::ExtractRomFS(romfs);
+
+ if (!extracted_romfs) {
+ LOG_ERROR(Service_AM, "SharedFont RomFS with title_id={:016X} failed to extract!",
+ font_title_id);
+ continue;
+ }
+
+ const auto font_file = extracted_romfs->GetFile(font.second);
+
+ if (!font_file) {
+ LOG_ERROR(Service_AM, "SharedFont RomFS with title_id={:016X} has no font file \"{}\"!",
+ font_title_id, font.second);
+ continue;
+ }
+
+ std::vector<u32> font_data_u32(font_file->GetSize() / sizeof(u32));
+ font_file->ReadBytes<u32>(font_data_u32.data(), font_file->GetSize());
+
+ std::transform(font_data_u32.begin(), font_data_u32.end(), font_data_u32.begin(),
+ Common::swap32);
+
+ std::vector<u8> decrypted_data(font_file->GetSize() - 8);
+
+ NS::DecryptSharedFontToTTF(font_data_u32, decrypted_data);
+
+ FileSys::VirtualFile decrypted_font = std::make_shared<FileSys::VectorVfsFile>(
+ std::move(decrypted_data), DECRYPTED_SHARED_FONTS[i]);
+
+ const auto temp_dir =
+ system.GetFilesystem()->CreateDirectory(fonts_dir, FileSys::Mode::ReadWrite);
+
+ const auto out_file = temp_dir->CreateFile(DECRYPTED_SHARED_FONTS[i]);
+
+ FileSys::VfsRawCopy(decrypted_font, out_file);
+ }
+}
+
} // namespace
WebBrowser::WebBrowser(Core::System& system_, const Core::Frontend::WebBrowserApplet& frontend_)
@@ -155,6 +239,8 @@ void WebBrowser::Initialize() {
LOG_DEBUG(Service_AM, "WebArgHeader: total_tlv_entries={}, shim_kind={}",
web_arg_header.total_tlv_entries, web_arg_header.shim_kind);
+ ExtractSharedFonts(system);
+
switch (web_arg_header.shim_kind) {
case ShimKind::Shop:
InitializeShop();