DRM: Search all user directories for rap files

This commit is contained in:
Megamouse 2021-04-07 22:37:32 +02:00
parent d2b761b7de
commit d10584ac6c
4 changed files with 30 additions and 21 deletions

View File

@ -1321,7 +1321,7 @@ bool SELFDecrypter::GetKeyFromRap(u8* content_id, u8* npdrm_key)
// Try to find a matching RAP file under exdata folder.
const std::string ci_str = reinterpret_cast<const char*>(content_id);
const std::string rap_path = Emulator::GetHddDir() + "/home/" + Emu.GetUsr() + "/exdata/" + ci_str + ".rap";
const std::string rap_path = Emulator::GetRapFilePath(ci_str);
// Open the RAP file and read the key.
const fs::file rap_file(rap_path);
@ -1329,8 +1329,8 @@ bool SELFDecrypter::GetKeyFromRap(u8* content_id, u8* npdrm_key)
if (!rap_file)
{
self_log.fatal("Failed to locate the game license file: %s."
"\nEnsure the .rap license file is placed in the dev_hdd0/home/00000001/exdata folder with a lowercase file extension."
"\nIf you need assistance on dumping the license file from your PS3, read our quickstart guide: https://rpcs3.net/quickstart", rap_path);
"\nEnsure the .rap license file is placed in the dev_hdd0/home/%s/exdata folder with a lowercase file extension."
"\nIf you need assistance on dumping the license file from your PS3, read our quickstart guide: https://rpcs3.net/quickstart", rap_path, Emu.GetUsr());
return false;
}

View File

@ -475,8 +475,6 @@ error_code npDrmIsAvailable(vm::cptr<u8> k_licensee_addr, vm::cptr<char> drm_pat
auto& npdrmkeys = g_fxo->get<loaded_npdrm_keys>();
std::string rap_dir_path = "/dev_hdd0/home/" + Emu.GetUsr() + "/exdata/";
const std::string& enc_drm_path_local = vfs::get(enc_drm_path);
const fs::file enc_file(enc_drm_path_local);
@ -508,7 +506,7 @@ error_code npDrmIsAvailable(vm::cptr<u8> k_licensee_addr, vm::cptr<char> drm_pat
if (VerifyEDATHeaderWithKLicense(enc_file, enc_drm_path_local, reinterpret_cast<u8*>(&k_licensee), &contentID))
{
const std::string rap_file = rap_dir_path + contentID + ".rap";
const std::string rap_file = Emulator::GetRapFilePath(contentID);
npdrmkeys.devKlic = k_licensee;
if (fs::is_file(vfs::get(rap_file)))
@ -554,10 +552,11 @@ error_code sceNpDrmVerifyUpgradeLicense(vm::cptr<char> content_id)
}
const std::string content_str(content_id.get_ptr(), std::find(content_id.get_ptr(), content_id.get_ptr() + 0x2f, '\0'));
const std::string rap_file = Emulator::GetRapFilePath(content_str);
sceNp.warning(u8"sceNpDrmVerifyUpgradeLicense(): content_id=“%s”", content_id);
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)
if (fs::stat_t s{}; !fs::stat(rap_file, 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;
@ -577,10 +576,11 @@ error_code sceNpDrmVerifyUpgradeLicense2(vm::cptr<char> content_id)
}
const std::string content_str(content_id.get_ptr(), std::find(content_id.get_ptr(), content_id.get_ptr() + 0x2f, '\0'));
const std::string rap_file = Emulator::GetRapFilePath(content_str);
sceNp.warning(u8"sceNpDrmVerifyUpgradeLicense2(): content_id=“%s”", content_id);
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)
if (fs::stat_t s{}; !fs::stat(rap_file, 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;

View File

@ -916,10 +916,10 @@ std::string Emulator::GetSfoDirFromGamePath(const std::string& game_path, const
if (category == "HG" && !content_id.empty())
{
// This is a trial game. Check if the user has a RAP file to unlock it.
const std::string rap_path = GetHddDir() + "home/" + user + "/exdata/" + content_id + ".rap";
if (fs::is_file(rap_path) && fs::is_file(game_path + "/C00/PARAM.SFO"))
if (fs::is_file(game_path + "/C00/PARAM.SFO") && fs::is_file(GetRapFilePath(content_id)))
{
// Load full game data.
sys_log.notice("Found RAP file %s.rap for trial game %s", content_id, title_id);
return game_path + "/C00";
}
}
@ -927,6 +927,25 @@ std::string Emulator::GetSfoDirFromGamePath(const std::string& game_path, const
return game_path;
}
std::string Emulator::GetRapFilePath(const std::string& rap)
{
const std::string home_dir = GetHddDir() + "/home";
for (auto&& entry : fs::dir(home_dir))
{
if (entry.is_directory && CheckUsr(entry.name))
{
std::string rap_path = fmt::format("%s/%s/exdata/%s.rap", home_dir, entry.name, rap);
if (fs::is_file(rap_path))
{
return rap_path;
}
}
}
return {};
}
std::string Emulator::GetCustomConfigDir()
{
#ifdef _WIN32

View File

@ -231,6 +231,7 @@ public:
static std::string GetHdd1Dir();
static std::string GetCacheDir();
static std::string GetSfoDirFromGamePath(const std::string& game_path, const std::string& user, const std::string& title_id = "");
static std::string GetRapFilePath(const std::string& rap);
static std::string GetCustomConfigDir();
static std::string GetCustomConfigPath(const std::string& title_id, bool get_deprecated_path = false);
@ -270,17 +271,6 @@ public:
std::set<std::string> GetGameDirs() const;
u64 GetEmulationCounter() const
{
return m_stop_ctr;
}
void WaitEmulationCounter(u64 old = -1) const
{
if (old == umax) old = m_stop_ctr; // Use current if not specified
if (m_stop_ctr == old) m_stop_ctr.wait(old);
}
private:
void LimitCacheSize();
};