Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GUI: Handle uppercase RAP file extension #9956

Merged
merged 4 commits into from Mar 13, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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.is_directory || 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.is_directory || s.size < 0x10)
{
// Game hasn't been purchased therefore no RAP file present
return SCE_NP_DRM_ERROR_LICENSE_NOT_FOUND;
Expand Down
29 changes: 24 additions & 5 deletions rpcs3/rpcs3qt/main_window.cpp
Expand Up @@ -515,7 +515,26 @@ bool main_window::InstallRapFile(const QString& path, const std::string& filenam
{
return false;
}
return fs::copy_file(sstr(path), Emulator::GetHddDir() + "/home/" + Emu.GetUsr() + "/exdata/" + filename, true);

Megamouse marked this conversation as resolved.
Show resolved Hide resolved
// Copy file atomically with thread/process-safe error checking for file size

fs::pending_file to(Emulator::GetHddDir() + "/home/" + Emu.GetUsr() + "/exdata/" + filename.substr(0, filename.find_last_of('.')) + ".rap");
fs::file from(sstr(path));

if (!to.file || !from)
{
return false;
}

to.file.write(from.to_vector<u8>());

if (to.file.size() < 0x10)
{
// Not a RAP file
return false;
}

return to.commit();
}

void main_window::InstallPackages(QStringList file_paths)
Expand Down Expand Up @@ -585,7 +604,7 @@ void main_window::InstallPackages(QStringList file_paths)
}

// Install rap files if available
for (const auto& rap : file_paths.filter(QRegExp(".*\\.rap")))
for (const auto& rap : file_paths.filter(QRegExp(".*\\.rap", Qt::CaseInsensitive)))
{
const QFileInfo file_info(rap);
const std::string rapname = sstr(file_info.fileName());
Expand Down Expand Up @@ -2548,7 +2567,7 @@ main_window::drop_type main_window::IsValidFile(const QMimeData& md, QStringList

drop_type = drop_type::drop_dir;
}
else if (info.fileName() == "PS3UPDAT.PUP")
else if (info.suffix() == "PUP")
{
if (list.size() != 1)
{
Expand All @@ -2566,9 +2585,9 @@ main_window::drop_type main_window::IsValidFile(const QMimeData& md, QStringList

drop_type = drop_type::drop_pkg;
}
else if (info.suffix() == "rap")
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))
elad335 marked this conversation as resolved.
Show resolved Hide resolved
{
return drop_type::drop_error;
}
Expand Down