mirror of
https://github.com/RPCS3/rpcs3.git
synced 2025-01-06 00:59:18 +00:00
[Crypto] Edat cleanup
This commit is contained in:
parent
5f26c2fc8f
commit
16d7eb4f55
@ -767,7 +767,7 @@ std::array<u8, 0x10> GetEdatRifKeyFromRapFile(const fs::file& rap_file)
|
||||
return rifkey;
|
||||
}
|
||||
|
||||
bool VerifyEDATHeaderWithKLicense(const fs::file& input, const std::string& input_file_name, const std::array<u8, 0x10>& custom_klic)
|
||||
bool VerifyEDATHeaderWithKLicense(const fs::file& input, const std::string& input_file_name, const std::array<u8, 0x10>& custom_klic, std::string* contentID)
|
||||
{
|
||||
// Setup NPD and EDAT/SDAT structs.
|
||||
NPD_HEADER NPD;
|
||||
@ -801,6 +801,8 @@ bool VerifyEDATHeaderWithKLicense(const fs::file& input, const std::string& inpu
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
*contentID = std::string(reinterpret_cast<const char*>(NPD.content_id));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -44,7 +44,7 @@ struct EDAT_HEADER
|
||||
// Decrypts full file, or null/empty file
|
||||
extern fs::file DecryptEDAT(const fs::file& input, const std::string& input_file_name, int mode, const std::string& rap_file_name, u8 *custom_klic, bool verbose);
|
||||
|
||||
extern bool VerifyEDATHeaderWithKLicense(const fs::file& input, const std::string& input_file_name, const std::array<u8,0x10>& custom_klic);
|
||||
extern bool VerifyEDATHeaderWithKLicense(const fs::file& input, const std::string& input_file_name, const std::array<u8,0x10>& custom_klic, std::string* contentID);
|
||||
|
||||
extern std::array<u8, 0x10> GetEdatRifKeyFromRapFile(const fs::file& rap_file);
|
||||
|
||||
|
@ -1088,12 +1088,7 @@ bool SELFDecrypter::DecryptNPDRM(u8 *metadata, u32 metadata_size)
|
||||
u8 klicensee_key[0x10];
|
||||
memcpy(klicensee_key, key_v.GetKlicenseeKey(), 0x10);
|
||||
|
||||
// Use klicensee if available.
|
||||
if (memcmp(klicensee_key, std::array<u8, 0x10>{0}.data(), 0x10))
|
||||
{
|
||||
memcpy(npdrm_key, klicensee_key, 0x10);
|
||||
}
|
||||
else if (ctrl->npdrm.license == 1) // Network license.
|
||||
if (ctrl->npdrm.license == 1) // Network license.
|
||||
{
|
||||
LOG_ERROR(LOADER, "SELF: Can't decrypt network NPDRM!");
|
||||
return false;
|
||||
@ -1109,8 +1104,11 @@ bool SELFDecrypter::DecryptNPDRM(u8 *metadata, u32 metadata_size)
|
||||
}
|
||||
else if (ctrl->npdrm.license == 3) // Free license.
|
||||
{
|
||||
// Use the NP_KLIC_FREE.
|
||||
memcpy(npdrm_key, NP_KLIC_FREE, 0x10);
|
||||
// Use klicensee if available.
|
||||
if (memcmp(klicensee_key, std::array<u8, 0x10>{0}.data(), 0x10))
|
||||
memcpy(npdrm_key, klicensee_key, 0x10);
|
||||
else
|
||||
memcpy(npdrm_key, NP_KLIC_FREE, 0x10);
|
||||
}
|
||||
else
|
||||
{
|
||||
|
@ -62,35 +62,13 @@ s32 npDrmIsAvailable(vm::cptr<u8> k_licensee_addr, vm::cptr<char> drm_path)
|
||||
sceNp.notice("npDrmIsAvailable(): KLicense key %s", k_licensee_str);
|
||||
}
|
||||
|
||||
sceNp.warning("npDrmIsAvailable(): Found DRM license file at %s", enc_drm_path);
|
||||
|
||||
// TODO: Make more explicit what this actually does (currently it copies "XXXXXXXX" from drm_path (== "/dev_hdd0/game/XXXXXXXXX/*" assumed)
|
||||
const std::string& drm_file_dir = enc_drm_path.substr(15);
|
||||
const std::string& title_id = drm_file_dir.substr(0, drm_file_dir.find_first_of('/'));
|
||||
|
||||
std::string rap_lpath = vfs::get("/dev_hdd0/home/00000001/exdata/"); // TODO: Allow multiple profiles. Use default for now.
|
||||
|
||||
// Search for a compatible RAP file.
|
||||
for (const auto& entry : fs::dir(rap_lpath))
|
||||
{
|
||||
if (entry.name.find(title_id) != -1)
|
||||
{
|
||||
rap_lpath += entry.name;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
auto npdrmkeys = fxm::get_always<LoadedNpdrmKeys_t>();
|
||||
|
||||
npdrmkeys->devKlic.fill(0);
|
||||
npdrmkeys->rifKey.fill(0);
|
||||
|
||||
if (rap_lpath.back() == '/')
|
||||
{
|
||||
sceNp.warning("npDrmIsAvailable(): Can't find RAP file for %s", enc_drm_path);
|
||||
}
|
||||
else
|
||||
npdrmkeys->rifKey = GetEdatRifKeyFromRapFile(fs::file{ rap_lpath });
|
||||
// todo: profile for rap_dir_path
|
||||
std::string rap_dir_path = "/dev_hdd0/home/00000001/exdata/";
|
||||
|
||||
const std::string& enc_drm_path_local = vfs::get(enc_drm_path);
|
||||
const fs::file enc_file(enc_drm_path_local);
|
||||
@ -117,9 +95,17 @@ s32 npDrmIsAvailable(vm::cptr<u8> k_licensee_addr, vm::cptr<char> drm_path)
|
||||
{
|
||||
// edata / sdata files
|
||||
|
||||
if (VerifyEDATHeaderWithKLicense(enc_file, enc_drm_path_local, k_licensee))
|
||||
std::string contentID;
|
||||
|
||||
if (VerifyEDATHeaderWithKLicense(enc_file, enc_drm_path_local, k_licensee, &contentID))
|
||||
{
|
||||
const std::string rap_file = rap_dir_path + contentID + ".rap";
|
||||
npdrmkeys->devKlic = std::move(k_licensee);
|
||||
|
||||
if (fs::is_file(vfs::get(rap_file)))
|
||||
npdrmkeys->rifKey = GetEdatRifKeyFromRapFile(fs::file{ vfs::get(rap_file) });
|
||||
else
|
||||
sceNp.warning("npDrmIsAvailable(): Rap file not found: %s", rap_file.c_str());
|
||||
}
|
||||
else
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user