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 for NCZ/NSZ cert installs to prevent crash on install #193

Open
mrdude2478 opened this issue Sep 20, 2023 · 2 comments
Open

Fix for NCZ/NSZ cert installs to prevent crash on install #193

mrdude2478 opened this issue Sep 20, 2023 · 2 comments

Comments

@mrdude2478
Copy link

mrdude2478 commented Sep 20, 2023

Currently a random crash happens when installing from NCZ/NSZ files. This is down to the cert file entry in the file entry table having a corrupt file extension name. When the cert tries to install, the filename extension is wrong which causes a crash.

This bug is random, but can be fixed by modding nsp.cpp and xci.cpp to the following,

std::vector<const PFS0FileEntry*> NSP::GetFileEntriesByExtension(std::string extension)
	{
		std::vector<const PFS0FileEntry*> entryList;

		for (unsigned int i = 0; i < this->GetBaseHeader()->numFiles; i++)
		{
			const PFS0FileEntry* fileEntry = this->GetFileEntry(i);
			std::string name(this->GetFileEntryName(fileEntry));
			auto foundExtension = name.substr(name.find(".") + 1);
				
			// fix cert filename extension becoming corrupted when xcz/nsz is installing certs.
			std::string cert ("cert");
			std::size_t found = name.find(cert);
			if (found!=std::string::npos){
				int pos = 0;
				std::string mystr = name;
				pos = mystr.find_last_of('.');
				mystr = mystr.substr(5, pos);
				foundExtension = mystr.substr(mystr.find(".") + 1);
			}

			if (foundExtension == extension)
				entryList.push_back(fileEntry);
		}

		return entryList;
	}

This looks for a file entry with cert in the name and then strips off the excess bytes/chars from the extension so that the filename in the entry table is corrected. This then prevents the crash while trying to install the cert.

Regards.

@Glass109
Copy link

No pull request?

@justindhillon
Copy link

I made a pull request #195 that implements this fix. This has not been tested.

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

No branches or pull requests

3 participants