Skip to content

Commit

Permalink
SCE Decryption: Detect illegal RAP files
Browse files Browse the repository at this point in the history
  • Loading branch information
elad335 committed Mar 13, 2021
1 parent 67bcf08 commit 4abd583
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 3 deletions.
7 changes: 6 additions & 1 deletion rpcs3/Crypto/unself.cpp
Expand Up @@ -1335,7 +1335,12 @@ bool SELFDecrypter::GetKeyFromRap(u8* content_id, u8* npdrm_key)
}

self_log.notice("Loading RAP file %s.rap", ci_str);
rap_file.read(rap_key, 0x10);

if (rap_file.read(rap_key, 0x10) != 0x10)
{
self_log.fatal("Failed to load %s: RAP file exists but is invalid. Try reinstalling it.", rap_path);
return false;
}

// Convert the RAP key.
rap_to_rif(rap_key, npdrm_key);
Expand Down
4 changes: 2 additions & 2 deletions rpcs3/Emu/Cell/Modules/sceNp.cpp
Expand Up @@ -557,7 +557,7 @@ error_code sceNpDrmVerifyUpgradeLicense(vm::cptr<char> content_id)

sceNp.warning(u8"sceNpDrmVerifyUpgradeLicense(): content_id=“%s”", content_id);

if (!fs::is_file(vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/exdata/" + content_str + ".rap")))
if (fs::stat_t s{}; !fs::stat(vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/exdata/" + content_str + ".rap"), s) || s.size < 0x10)
{
// Game hasn't been purchased therefore no RAP file present
return SCE_NP_DRM_ERROR_LICENSE_NOT_FOUND;
Expand All @@ -580,7 +580,7 @@ error_code sceNpDrmVerifyUpgradeLicense2(vm::cptr<char> content_id)

sceNp.warning(u8"sceNpDrmVerifyUpgradeLicense2(): content_id=“%s”", content_id);

if (!fs::is_file(vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/exdata/" + content_str + ".rap")))
if (fs::stat_t s{}; !fs::stat(vfs::get("/dev_hdd0/home/" + Emu.GetUsr() + "/exdata/" + content_str + ".rap"), s) || s.size < 0x10)
{
// Game hasn't been purchased therefore no RAP file present
return SCE_NP_DRM_ERROR_LICENSE_NOT_FOUND;
Expand Down

0 comments on commit 4abd583

Please sign in to comment.