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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

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.

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.

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