mirror of
https://github.com/Team-Neptune/NSAInstaller.git
synced 2024-11-23 12:49:52 +00:00
fix ncz installation
fix xci from sd installation
This commit is contained in:
parent
fbbda96513
commit
ab7b9eda0e
@ -2,7 +2,7 @@
|
||||
|
||||
#include <switch.h>
|
||||
|
||||
#define NCA_HEADER_SIZE 0xC00
|
||||
#define NCA_HEADER_SIZE 0x4000
|
||||
#define MAGIC_NCA3 0x3341434E /* "NCA3" */
|
||||
namespace tin::install
|
||||
{
|
||||
|
@ -52,6 +52,7 @@ public:
|
||||
bool isOpen() const;
|
||||
bool close();
|
||||
u64 write(const u8* ptr, u64 sz);
|
||||
void flushHeader();
|
||||
|
||||
protected:
|
||||
NcmContentId m_ncaId;
|
||||
|
@ -372,8 +372,7 @@ bool NcaWriter::close()
|
||||
{
|
||||
if(isOpen())
|
||||
{
|
||||
m_contentStorage->CreatePlaceholder(m_ncaId, *(NcmPlaceHolderId*)&m_ncaId, m_buffer.size());
|
||||
m_contentStorage->WritePlaceholder(*(NcmPlaceHolderId*)&m_ncaId, 0, m_buffer.data(), m_buffer.size());
|
||||
flushHeader();
|
||||
}
|
||||
|
||||
m_buffer.resize(0);
|
||||
@ -408,34 +407,7 @@ u64 NcaWriter::write(const u8* ptr, u64 sz)
|
||||
|
||||
if (m_buffer.size() == NCA_HEADER_SIZE)
|
||||
{
|
||||
tin::install::NcaHeader header;
|
||||
memcpy(&header, m_buffer.data(), sizeof(header));
|
||||
Crypto::AesXtr decryptor(Crypto::Keys().headerKey, false);
|
||||
Crypto::AesXtr encryptor(Crypto::Keys().headerKey, true);
|
||||
decryptor.decrypt(&header, &header, sizeof(header), 0, 0x200);
|
||||
|
||||
if (header.magic == MAGIC_NCA3)
|
||||
{
|
||||
if(isOpen())
|
||||
{
|
||||
m_contentStorage->CreatePlaceholder(m_ncaId, *(NcmPlaceHolderId*)&m_ncaId, header.nca_size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw "Invalid NCA magic";
|
||||
}
|
||||
|
||||
if (header.distribution == 1)
|
||||
{
|
||||
header.distribution = 0;
|
||||
}
|
||||
encryptor.encrypt(m_buffer.data(), &header, sizeof(header), 0, 0x200);
|
||||
|
||||
if(isOpen())
|
||||
{
|
||||
m_contentStorage->WritePlaceholder(*(NcmPlaceHolderId*)&m_ncaId, 0, m_buffer.data(), m_buffer.size());
|
||||
}
|
||||
flushHeader();
|
||||
}
|
||||
}
|
||||
|
||||
@ -473,3 +445,34 @@ u64 NcaWriter::write(const u8* ptr, u64 sz)
|
||||
return sz;
|
||||
}
|
||||
|
||||
void NcaWriter::flushHeader()
|
||||
{
|
||||
tin::install::NcaHeader header;
|
||||
memcpy(&header, m_buffer.data(), sizeof(header));
|
||||
Crypto::AesXtr decryptor(Crypto::Keys().headerKey, false);
|
||||
Crypto::AesXtr encryptor(Crypto::Keys().headerKey, true);
|
||||
decryptor.decrypt(&header, &header, sizeof(header), 0, 0x200);
|
||||
|
||||
if (header.magic == MAGIC_NCA3)
|
||||
{
|
||||
if(isOpen())
|
||||
{
|
||||
m_contentStorage->CreatePlaceholder(m_ncaId, *(NcmPlaceHolderId*)&m_ncaId, header.nca_size);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
throw std::runtime_error("Invalid NCA magic");
|
||||
}
|
||||
|
||||
if (header.distribution == 1)
|
||||
{
|
||||
header.distribution = 0;
|
||||
}
|
||||
encryptor.encrypt(m_buffer.data(), &header, sizeof(header), 0, 0x200);
|
||||
|
||||
if(isOpen())
|
||||
{
|
||||
m_contentStorage->WritePlaceholder(*(NcmPlaceHolderId*)&m_ncaId, 0, m_buffer.data(), m_buffer.size());
|
||||
}
|
||||
}
|
||||
|
@ -110,6 +110,9 @@ namespace nspInstStuff {
|
||||
if (ourTitleList[titleItr].extension() == ".xci" || ourTitleList[titleItr].extension() == ".xcz") {
|
||||
auto localXCI = new tin::install::xci::LocalXCI(ourTitleList[titleItr]);
|
||||
installTask = new tin::install::xci::XCIInstallTask(m_destStorageId, inst::config::ignoreReqVers, localXCI);
|
||||
|
||||
installTask->Prepare();
|
||||
installTask->Begin();
|
||||
} else {
|
||||
if (ourTitleList[titleItr].extension() == ".nsz") {
|
||||
oldNamesOfFiles.push_back(ourTitleList[titleItr]);
|
||||
|
Loading…
Reference in New Issue
Block a user