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

[ctrtool] support more prototype CXIs #154

Merged
merged 1 commit into from
Dec 28, 2024
Merged

Conversation

Wack0
Copy link

@Wack0 Wack0 commented Dec 23, 2024

SDK 0.10-era CXIs specify the full exheader size of 0x800 in the NCCH header, so allow that.

@jakcron
Copy link
Collaborator

jakcron commented Dec 24, 2024

Hi Wack0, good find.

Happy to bring in this change, but can we make the logic clearer?

e.g. from this:

bool is_proto_exhdr_size = mHeader.header.format_version.unwrap() == ntd::n3ds::NcchCommonHeader::FormatVersion_CXI_PROTOTYPE && mHeader.header.exhdr_size.unwrap() == (sizeof(ntd::n3ds::ExtendedHeader) + sizeof(ntd::n3ds::AccessDescriptor));
if (mHeader.header.exhdr_size.unwrap() != 0 && mHeader.header.exhdr_size.unwrap() != sizeof(ntd::n3ds::ExtendedHeader) && !is_proto_exhdr_size)
{
	throw tc::InvalidOperationException(mModuleLabel, fmt::format("NcchHeader has invalid ExHeader size. (0x{:02x})", mHeader.header.exhdr_size.unwrap()));
}

to this:

// validate exheader size
size_t expected_exhdr_size = sizeof(ntd::n3ds::ExtendedHeader); // default for modern CXI is 0x400 (sizeof(ntd::n3ds::ExtendedHeader))
if (mHeader.header.format_version.unwrap() == ntd::n3ds::NcchCommonHeader::FormatVersion_CXI_PROTOTYPE)
{
	expected_exhdr_size = sizeof(ntd::n3ds::ExtendedHeader) + sizeof(ntd::n3ds::AccessDescriptor); // for some 0.10.x prototype CXI this is 0x800 (sizeof(ntd::n3ds::ExtendedHeader) + sizeof(ntd::n3ds::AccessDescriptor))
}

if (mHeader.header.exhdr_size.unwrap() != 0 && mHeader.header.exhdr_size.unwrap() != expected_exhdr_size)
{
	throw tc::InvalidOperationException(mModuleLabel, fmt::format("NcchHeader has invalid ExHeader size. (0x{:02x})", mHeader.header.exhdr_size.unwrap()));
}

What do you think?

@Wack0
Copy link
Author

Wack0 commented Dec 24, 2024

There may be some later CXIs that use v1 format version but with exheader size 0x400, so the proposed change may not be correct.

@MisterSheeple
Copy link

Are there any further changes that need to be made? I'd like to see to it that this gets merged as soon as humanly possible. There will be users who need this feature in a matter of days.

@Wack0
Copy link
Author

Wack0 commented Dec 28, 2024

There may be some later CXIs that use v1 format version but with exheader size 0x400, so the proposed change may not be correct.

I can confirm that at some point (SDK 0.10.1 or 0.10.2), exheader size changed to 0x400 with the NCCH format version still being v1.

Therefore the proposed change is indeed not correct.

@jakcron
Copy link
Collaborator

jakcron commented Dec 28, 2024

@Wack0 thanks for confirming. Then can you just add a comment above bool is_proto_exhdr_size explaining why it's necessary so we don't forget later what the check is permitting. You could just put your PR description "SDK 0.10-era CXIs specify the full exheader size of 0x800 in the NCCH header, so allow that."

I'd be happy to merge it and release it after that.

SDK 0.10-era CXIs specify the full exheader size of 0x800 in the NCCH header, so allow that.
@jakcron jakcron merged commit f5f2d9c into 3DSGuy:master Dec 28, 2024
0 of 9 checks passed
@jakcron
Copy link
Collaborator

jakcron commented Dec 28, 2024

@Wack0 Wack0 deleted the fix-proto-ncch branch December 28, 2024 16:04
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants