Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix system files setup on MAC and crypto file handling #694

Merged
merged 2 commits into from
Mar 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion src/core/file_sys/ncch_container.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -366,7 +366,12 @@ Loader::ResultStatus NCCHContainer::LoadOverrides() {
is_tainted = true;
has_exefs = true;
} else {
exefs_file = std::make_unique<FileUtil::IOFile>(filepath, "rb");
if (file->IsCrypto()) {
exefs_file = HW::UniqueData::OpenUniqueCryptoFile(
filepath, "rb", HW::UniqueData::UniqueCryptoFileID::NCCH);
} else {
exefs_file = std::make_unique<FileUtil::IOFile>(filepath, "rb");
}
}
} else if (FileUtil::Exists(exefsdir_override) && FileUtil::IsDirectory(exefsdir_override)) {
is_tainted = true;
Expand Down
18 changes: 11 additions & 7 deletions src/core/hle/service/am/am.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -303,11 +303,11 @@ void NCCHCryptoFile::Write(const u8* buffer, std::size_t length) {
}

while (length) {
auto find_closest_region = [this](size_t offset) -> CryptoRegion* {
auto find_closest_region = [this](size_t offset) -> std::optional<CryptoRegion> {
CryptoRegion* closest = nullptr;
for (auto& reg : regions) {
if (offset >= reg.offset && offset < reg.offset + reg.size) {
return &reg;
return reg;
}
if (offset < reg.offset) {
size_t dist = reg.offset - offset;
Expand All @@ -317,11 +317,15 @@ void NCCHCryptoFile::Write(const u8* buffer, std::size_t length) {
}
}
// Return the closest one
return closest;
if (closest) {
return *closest;
} else {
return std::nullopt;
}
};

CryptoRegion* reg = find_closest_region(written);
if (reg == nullptr) {
const auto reg = find_closest_region(written);
if (!reg.has_value()) {
// This file has no encryption
size_t to_write = length;
file->WriteBytes(buffer, to_write);
Expand Down Expand Up @@ -379,8 +383,8 @@ void NCCHCryptoFile::Write(const u8* buffer, std::size_t length) {
for (int i = 0; i < 8; i++) {
if (exefs_header.section[i].size != 0) {
bool is_primary =
strcmp(exefs_header.section[i].name, "icon") == 0 ||
strcmp(exefs_header.section[i].name, "banner") == 0;
memcmp(exefs_header.section[i].name, "icon", 4) == 0 ||
memcmp(exefs_header.section[i].name, "banner", 6) == 0;
regions.push_back(CryptoRegion{
.type = is_primary ? CryptoRegion::EXEFS_PRI
: CryptoRegion::EXEFS_SEC,
Expand Down
Loading