mirror of
https://github.com/Dark98/threeSD.git
synced 2026-07-03 00:38:58 +00:00
Add CIABuildType to CIABuilder; Add legit ticket handling
This commit is contained in:
@@ -693,7 +693,7 @@ bool SDMCImporter::BuildCIA(const ContentSpecifier& specifier, std::string desti
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
const bool ret = cia_builder->Init(destination, tmd, config,
|
const bool ret = cia_builder->Init(CIABuildType::Standard, destination, tmd, config,
|
||||||
FileUtil::GetDirectoryTreeSize(physical_path), callback);
|
FileUtil::GetDirectoryTreeSize(physical_path), callback);
|
||||||
if (!ret) {
|
if (!ret) {
|
||||||
FileUtil::Delete(destination);
|
FileUtil::Delete(destination);
|
||||||
|
|||||||
@@ -48,9 +48,11 @@ private:
|
|||||||
CIABuilder::CIABuilder() = default;
|
CIABuilder::CIABuilder() = default;
|
||||||
CIABuilder::~CIABuilder() = default;
|
CIABuilder::~CIABuilder() = default;
|
||||||
|
|
||||||
bool CIABuilder::Init(const std::string& destination, TitleMetadata tmd_, const Config& config,
|
bool CIABuilder::Init(CIABuildType type_, const std::string& destination, TitleMetadata tmd_,
|
||||||
std::size_t total_size_, const Common::ProgressCallback& callback_) {
|
const Config& config, std::size_t total_size_,
|
||||||
|
const Common::ProgressCallback& callback_) {
|
||||||
|
|
||||||
|
type = type_;
|
||||||
header = {};
|
header = {};
|
||||||
meta = {};
|
meta = {};
|
||||||
|
|
||||||
@@ -119,9 +121,19 @@ bool CIABuilder::WriteCert(const std::string& certs_db_path) {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CIABuilder::WriteTicket(const std::string& ticket_db_path,
|
static bool FindLegitTicket(Ticket& out, u64 title_id, const std::string& ticket_db_path) {
|
||||||
|
TicketDB ticket_db(ticket_db_path);
|
||||||
|
if (ticket_db.IsGood() && ticket_db.tickets.count(title_id)) {
|
||||||
|
out = ticket_db.tickets.at(title_id);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
LOG_ERROR(Core, "Could not find legit ticket for {:016x}", title_id);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
static Ticket BuildStandardTicket(u64 title_id, const std::string& ticket_db_path,
|
||||||
const std::string& enc_title_keys_bin_path) {
|
const std::string& enc_title_keys_bin_path) {
|
||||||
const auto title_id = tmd.GetTitleID();
|
|
||||||
Ticket ticket = BuildFakeTicket(title_id);
|
Ticket ticket = BuildFakeTicket(title_id);
|
||||||
|
|
||||||
// Fill in common_key_index and title_key from either ticket.db (installed tickets)
|
// Fill in common_key_index and title_key from either ticket.db (installed tickets)
|
||||||
@@ -143,6 +155,22 @@ bool CIABuilder::WriteTicket(const std::string& ticket_db_path,
|
|||||||
} else {
|
} else {
|
||||||
LOG_WARNING(Core, "Could not find title key for {:016x}", title_id);
|
LOG_WARNING(Core, "Could not find title key for {:016x}", title_id);
|
||||||
}
|
}
|
||||||
|
return ticket;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool CIABuilder::WriteTicket(const std::string& ticket_db_path,
|
||||||
|
const std::string& enc_title_keys_bin_path) {
|
||||||
|
|
||||||
|
const auto title_id = tmd.GetTitleID();
|
||||||
|
|
||||||
|
Ticket ticket;
|
||||||
|
if (type == CIABuildType::Legit) {
|
||||||
|
if (!FindLegitTicket(ticket, title_id, ticket_db_path)) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
ticket = BuildStandardTicket(title_id, ticket_db_path, enc_title_keys_bin_path);
|
||||||
|
}
|
||||||
|
|
||||||
header.tik_size = ticket.GetSize();
|
header.tik_size = ticket.GetSize();
|
||||||
|
|
||||||
|
|||||||
@@ -25,6 +25,12 @@ constexpr std::size_t CIA_METADATA_SIZE = 0x3AC0;
|
|||||||
struct Config;
|
struct Config;
|
||||||
class HashedFile;
|
class HashedFile;
|
||||||
|
|
||||||
|
enum class CIABuildType {
|
||||||
|
Standard, /// Decrypted CIA with generalized ticket
|
||||||
|
PirateLegit, /// Uses legit TMD and encryption, but with generalized ticket
|
||||||
|
Legit, /// Fully legit, with personal ticket containing console ID and eshop account
|
||||||
|
};
|
||||||
|
|
||||||
class CIABuilder {
|
class CIABuilder {
|
||||||
public:
|
public:
|
||||||
explicit CIABuilder();
|
explicit CIABuilder();
|
||||||
@@ -34,8 +40,9 @@ public:
|
|||||||
* Initializes the building of the CIA.
|
* Initializes the building of the CIA.
|
||||||
* @return true on success, false otherwise
|
* @return true on success, false otherwise
|
||||||
*/
|
*/
|
||||||
bool Init(const std::string& destination, TitleMetadata tmd, const Config& config,
|
bool Init(CIABuildType type, const std::string& destination, TitleMetadata tmd,
|
||||||
std::size_t total_size, const Common::ProgressCallback& callback);
|
const Config& config, std::size_t total_size,
|
||||||
|
const Common::ProgressCallback& callback);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Adds an NCCH content to the CIA.
|
* Adds an NCCH content to the CIA.
|
||||||
@@ -93,6 +100,8 @@ private:
|
|||||||
bool WriteCert(const std::string& certs_db_path);
|
bool WriteCert(const std::string& certs_db_path);
|
||||||
bool WriteTicket(const std::string& ticket_db_path, const std::string& enc_title_keys_bin_path);
|
bool WriteTicket(const std::string& ticket_db_path, const std::string& enc_title_keys_bin_path);
|
||||||
|
|
||||||
|
CIABuildType type;
|
||||||
|
|
||||||
Header header{};
|
Header header{};
|
||||||
Metadata meta{};
|
Metadata meta{};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user