From aff63028d4f493066580fc4727132374eaeeb28f Mon Sep 17 00:00:00 2001 From: Eladash Date: Sat, 13 Mar 2021 08:21:18 +0200 Subject: [PATCH] SCE Decryption: Detect illegal RAP files --- rpcs3/Crypto/unself.cpp | 7 ++++++- rpcs3/Emu/Cell/Modules/sceNp.cpp | 4 ++-- rpcs3/rpcs3qt/main_window.cpp | 2 +- 3 files changed, 9 insertions(+), 4 deletions(-) diff --git a/rpcs3/Crypto/unself.cpp b/rpcs3/Crypto/unself.cpp index 54a70b7615..e8148574dd 100644 --- a/rpcs3/Crypto/unself.cpp +++ b/rpcs3/Crypto/unself.cpp @@ -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); diff --git a/rpcs3/Emu/Cell/Modules/sceNp.cpp b/rpcs3/Emu/Cell/Modules/sceNp.cpp index b4dea9b9bd..b092c11b63 100644 --- a/rpcs3/Emu/Cell/Modules/sceNp.cpp +++ b/rpcs3/Emu/Cell/Modules/sceNp.cpp @@ -557,7 +557,7 @@ error_code sceNpDrmVerifyUpgradeLicense(vm::cptr 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.is_directory || s.size < 0x10) { // Game hasn't been purchased therefore no RAP file present return SCE_NP_DRM_ERROR_LICENSE_NOT_FOUND; @@ -580,7 +580,7 @@ error_code sceNpDrmVerifyUpgradeLicense2(vm::cptr 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.is_directory || s.size < 0x10) { // Game hasn't been purchased therefore no RAP file present return SCE_NP_DRM_ERROR_LICENSE_NOT_FOUND; diff --git a/rpcs3/rpcs3qt/main_window.cpp b/rpcs3/rpcs3qt/main_window.cpp index 292d34d858..d512e8ac71 100644 --- a/rpcs3/rpcs3qt/main_window.cpp +++ b/rpcs3/rpcs3qt/main_window.cpp @@ -2587,7 +2587,7 @@ main_window::drop_type main_window::IsValidFile(const QMimeData& md, QStringList } else if (info.suffix().toLower() == "rap") { - if (drop_type != drop_type::drop_rap && drop_type != drop_type::drop_error) + if (info.size() < 0x10 || (drop_type != drop_type::drop_rap && drop_type != drop_type::drop_error)) { return drop_type::drop_error; }