core, frontend: Add 'Dump CXI file' option

Right click on an application in the Select Contents dialog.
This commit is contained in:
zhupengfei
2020-05-02 00:06:46 +08:00
parent 2c4dd84d49
commit 24bdf0a156
12 changed files with 275 additions and 31 deletions
+18 -4
View File
@@ -15,10 +15,10 @@
#include "common/common_types.h"
#include "common/logging/log.h"
#include "core/data_container.h"
#include "core/importer.h"
#include "core/key/key.h"
#include "core/ncch/ncch_container.h"
#include "core/ncch/seed_db.h"
#include "core/quick_decryptor.h"
namespace Core {
@@ -440,10 +440,13 @@ ResultStatus NCCHContainer::DecryptToFile(const std::string& destination,
if (!is_encrypted) {
// Simply copy everything
QuickDecryptor<SDMCFile, FileUtil::IOFile> decryptor;
file->Seek(0, SEEK_SET);
const auto size = file->GetSize();
decryptor.Reset(size);
decryptor.DecryptAndWriteFile(file, size, dest_file, callback);
const bool ret = decryptor.DecryptAndWriteFile(file, size, dest_file, callback);
return ret ? ResultStatus::Success : ResultStatus::Error;
}
// Write NCCH header
@@ -463,7 +466,6 @@ ResultStatus NCCHContainer::DecryptToFile(const std::string& destination,
return ResultStatus::Error;
}
QuickDecryptor<SDMCFile, FileUtil::IOFile> decryptor;
const auto total_size =
file->GetSize() - sizeof(NCCH_Header) - sizeof(ExHeader_Header) - sizeof(ExeFs_Header);
decryptor.Reset(total_size);
@@ -477,12 +479,19 @@ ResultStatus NCCHContainer::DecryptToFile(const std::string& destination,
return true;
}
if (aborted.exchange(false)) {
return false;
}
file->Seek(written, SEEK_SET);
ASSERT_MSG(written <= offset, "Offsets are not in increasing order");
if (!decryptor.DecryptAndWriteFile(file, offset - written, dest_file, callback)) {
LOG_ERROR(Core, "Could not write data before {} to {}", name, destination);
return false;
}
if (aborted.exchange(false)) {
return false;
}
if (!decryptor.DecryptAndWriteFile(file, size, dest_file, callback, decrypt, key, ctr,
aes_seek_pos)) {
LOG_ERROR(Core, "Could not write {} to {}", name, destination);
@@ -536,6 +545,11 @@ ResultStatus NCCHContainer::DecryptToFile(const std::string& destination,
return ResultStatus::Success;
}
void NCCHContainer::AbortDecryptToFile() {
aborted = true;
decryptor.Abort();
}
#pragma pack(push, 1)
struct RomFSIVFCHeader {
u32_le magic;
+11 -1
View File
@@ -13,7 +13,6 @@
#include "common/file_util.h"
#include "common/swap.h"
#include "core/decryptor.h"
#include "core/importer.h"
#include "core/result_status.h"
namespace Core {
@@ -196,6 +195,8 @@ struct ExHeader_Header {
static_assert(sizeof(ExHeader_Header) == 0x800, "ExHeader structure size is wrong");
enum class EncryptionType;
/**
* Helper which implements an interface to deal with NCCH containers which can
* contain ExeFS archives or RomFS archives for games or other applications.
@@ -272,6 +273,11 @@ public:
ResultStatus DecryptToFile(const std::string& destination,
const ProgressCallback& callback = [](std::size_t, std::size_t) {});
/**
* Aborts DecryptToFile. Simply aborts the decryptor.
*/
void AbortDecryptToFile();
NCCH_Header ncch_header;
ExHeader_Header exheader_header;
ExeFs_Header exefs_header;
@@ -298,6 +304,10 @@ private:
std::string filepath;
std::shared_ptr<SDMCFile> file;
std::shared_ptr<SDMCFile> exefs_file;
// Used for DecryptToFile
QuickDecryptor<SDMCFile, FileUtil::IOFile> decryptor;
std::atomic_bool aborted{false};
};
/**