Example #1
0
int sceNpDrmIsAvailable(u32 k_licensee_addr, u32 drm_path_addr)
{
	sceNp.Warning("sceNpDrmIsAvailable(k_licensee_addr=0x%x, drm_path_addr=0x%x)", k_licensee_addr, drm_path_addr);

	wxString drm_path = fmt::FromUTF8(Memory.ReadString(drm_path_addr));
	wxString k_licensee_str;
	u8 k_licensee[0x10];
	for(int i = 0; i < 0x10; i++)
	{
		k_licensee[i] = Memory.Read8(k_licensee_addr + i);
		k_licensee_str += wxString::Format("%02x", k_licensee[i]);
	}

	sceNp.Warning("sceNpDrmIsAvailable: Found DRM license file at %s", fmt::ToUTF8(drm_path).c_str());
	sceNp.Warning("sceNpDrmIsAvailable: Using k_licensee 0x%s", fmt::ToUTF8(k_licensee_str).c_str());

	// Set the necessary file paths.
	wxString drm_file_name = drm_path.AfterLast('/'); 
	wxString titleID = drm_path.AfterFirst('/').AfterFirst('/').AfterFirst('/').BeforeFirst('/'); 

	wxString enc_drm_path = wxGetCwd() + drm_path;
	wxString dec_drm_path = wxGetCwd() + "/dev_hdd1/" + titleID + "/" + drm_file_name;

	wxString rap_dir_path = wxGetCwd() + "/dev_usb000/";
	wxString rap_file_path = rap_dir_path;
	
	// Search dev_usb000 for a compatible RAP file. 
	vfsDir *raps_dir = new vfsDir(fmt::ToUTF8(rap_dir_path));
	if (!raps_dir->IsOpened())
		sceNp.Warning("sceNpDrmIsAvailable: Can't find RAP file for DRM!");
	else
	{
		Array<DirEntryInfo> entries = raps_dir->GetEntries();
		for (unsigned int i = 0; i < entries.GetCount(); i++)
		{
			if (entries[i].name.find(fmt::ToUTF8(titleID)) != std::string::npos )
			{
				rap_file_path += fmt::FromUTF8(entries[i].name);
				break;
			}
		}
	}

	// Create a new directory under dev_hdd1/titleID to hold the decrypted data.
	wxString tmp_dir = wxGetCwd() + "/dev_hdd1/" + titleID;
	if (!wxDir::Exists(tmp_dir))
		wxMkdir(wxGetCwd() + "/dev_hdd1/" + titleID);

	// Decrypt this EDAT using the supplied k_licensee and matching RAP file.
	DecryptEDAT(fmt::ToUTF8(enc_drm_path), fmt::ToUTF8(dec_drm_path), 8, fmt::ToUTF8(rap_file_path), k_licensee, false);

	return CELL_OK;
}
Example #2
0
s32 npDrmIsAvailable(u32 k_licensee_addr, vm::cptr<char> drm_path)
{
	const std::string& enc_drm_path = drm_path.get_ptr();

	if (!fs::is_file(vfs::get(enc_drm_path)))
	{
		sceNp.warning("npDrmIsAvailable(): '%s' not found", enc_drm_path);
		return CELL_ENOENT;
	}

	std::string k_licensee_str = "0";
	u8 k_licensee[0x10];

	if (k_licensee_addr)
	{
		for (s32 i = 0; i < 0x10; i++)
		{
			k_licensee[i] = vm::read8(k_licensee_addr + i);
			k_licensee_str += fmt::format("%02x", k_licensee[i]);
		}
	}

	sceNp.warning("npDrmIsAvailable(): Found DRM license file at %s", enc_drm_path);
	sceNp.warning("npDrmIsAvailable(): Using k_licensee 0x%s", k_licensee_str);

	// Set the necessary file paths.
	const std::string& drm_file_name = enc_drm_path.substr(enc_drm_path.find_last_of('/') + 1);

	// 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('/'));

	const std::string& dec_drm_path = "/dev_hdd1/cache/" + drm_file_name;

	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;
		}
	}

	if (rap_lpath.back() == '/')
	{
		sceNp.warning("npDrmIsAvailable(): Can't find RAP file for %s", enc_drm_path);
		rap_lpath.clear();
	}

	const std::string& enc_drm_path_local = vfs::get(enc_drm_path);
	const std::string& dec_drm_path_local = vfs::get(dec_drm_path);

	if (DecryptEDAT(enc_drm_path_local, dec_drm_path_local, 8, rap_lpath, k_licensee, false) >= 0)
	{
		// If decryption succeeds, replace the encrypted file with it.
		fs::remove_file(enc_drm_path_local);
		fs::rename(dec_drm_path_local, enc_drm_path_local);
	}

	return CELL_OK;
}
Example #3
0
s32 npDrmIsAvailable(u32 k_licensee_addr, vm::cptr<char> drm_path)
{
	if (!Emu.GetVFS().ExistsFile(drm_path.get_ptr()))
	{
		sceNp.Warning("npDrmIsAvailable(): '%s' not found", drm_path.get_ptr());
		return CELL_ENOENT;
	}

	std::string k_licensee_str = "0";
	u8 k_licensee[0x10];

	if (k_licensee_addr)
	{
		for (s32 i = 0; i < 0x10; i++)
		{
			k_licensee[i] = vm::read8(k_licensee_addr + i);
			k_licensee_str += fmt::format("%02x", k_licensee[i]);
		}
	}

	sceNp.Warning("npDrmIsAvailable(): Found DRM license file at %s", drm_path.get_ptr());
	sceNp.Warning("npDrmIsAvailable(): Using k_licensee 0x%s", k_licensee_str.c_str());

	// Set the necessary file paths.
	std::string drm_file_name = fmt::AfterLast(drm_path.get_ptr(), '/');

	// TODO: Make more explicit what this actually does (currently it copies "XXXXXXXX" from drm_path (== "/dev_hdd0/game/XXXXXXXXX/*" assumed)
	std::string titleID(&drm_path[15], 9);

	// TODO: These shouldn't use current dir
	std::string enc_drm_path = drm_path.get_ptr();
	std::string dec_drm_path = "/dev_hdd1/cache/" + drm_file_name;
	std::string pf_str("00000001");  // TODO: Allow multiple profiles. Use default for now.
	std::string rap_path("/dev_hdd0/home/" + pf_str + "/exdata/");

	// Search dev_usb000 for a compatible RAP file. 
	for (const auto entry : vfsDir(rap_path))
	{
		if (entry->name.find(titleID) != std::string::npos)
		{
			rap_path += entry->name;
			break;
		}
	}

	if (rap_path.back() == '/')
	{
		sceNp.Warning("npDrmIsAvailable(): Can't find RAP file for '%s' (titleID='%s')", drm_path.get_ptr(), titleID);
	}

	// Decrypt this EDAT using the supplied k_licensee and matching RAP file.
	std::string enc_drm_path_local, dec_drm_path_local, rap_path_local;
	Emu.GetVFS().GetDevice(enc_drm_path, enc_drm_path_local);
	Emu.GetVFS().GetDevice(dec_drm_path, dec_drm_path_local);
	Emu.GetVFS().GetDevice(rap_path, rap_path_local);

	if (DecryptEDAT(enc_drm_path_local, dec_drm_path_local, 8, rap_path_local, k_licensee, false) >= 0)
	{
		// If decryption succeeds, replace the encrypted file with it.
		fs::remove_file(enc_drm_path_local);
		fs::rename(dec_drm_path_local, enc_drm_path_local);
	}

	return CELL_OK;
}
Example #4
0
int sceNpDrmIsAvailable2(u32 k_licensee_addr, u32 drm_path_addr)
{
	sceNp->Warning("sceNpDrmIsAvailable2(k_licensee_addr=0x%x, drm_path_addr=0x%x)", k_licensee_addr, drm_path_addr);

	std::string drm_path = Memory.ReadString(drm_path_addr);
	if (!Emu.GetVFS().ExistsFile(drm_path))
	{
		sceNp->Warning("sceNpDrmIsAvailable2(): '%s' not found", drm_path.c_str());
		return CELL_ENOENT;
	}

	std::string k_licensee_str = "0";
	u8 k_licensee[0x10];

	if (k_licensee_addr)
	{
		for (int i = 0; i < 0x10; i++)
		{
			k_licensee[i] = Memory.Read8(k_licensee_addr + i);
			k_licensee_str += fmt::Format("%02x", k_licensee[i]);
		}
	}

	sceNp->Warning("sceNpDrmIsAvailable2: Found DRM license file at %s", drm_path.c_str());
	sceNp->Warning("sceNpDrmIsAvailable2: Using k_licensee 0x%s", k_licensee_str.c_str());

	// Set the necessary file paths.
	std::string drm_file_name = fmt::AfterLast(drm_path, '/');

	// TODO: Make more explicit what this actually does (currently it copies "XXXXXXXX" from drm_path (== "/dev_hdd0/game/XXXXXXXXX/*" assumed)
	std::string titleID = drm_path.substr(15, 9);

	// TODO: These shouldn't use current dir
	std::string enc_drm_path = drm_path;
	std::string dec_drm_path = "/dev_hdd1/" + titleID + "/" + drm_file_name;
	std::string rap_path = "/dev_usb000/";

	// Search dev_usb000 for a compatible RAP file. 
	vfsDir *raps_dir = new vfsDir(rap_path);
	if (!raps_dir->IsOpened())
		sceNp->Warning("sceNpDrmIsAvailable2: Can't find RAP file for DRM!");
	else
	{
		const std::vector<DirEntryInfo> &entries = raps_dir->GetEntries();
		for (auto &entry : entries)
		{
			if (entry.name.find(titleID) != std::string::npos)
			{
				rap_path += entry.name;
				break;
			}
		}
	}

	// Create a new directory under dev_hdd1/titleID to hold the decrypted data.
	// TODO: These shouldn't use current dir
	std::string tmp_dir = "./dev_hdd1/" + titleID;
	if (!rExists(tmp_dir))
		rMkdir("./dev_hdd1/" + titleID);

	// Decrypt this EDAT using the supplied k_licensee and matching RAP file.
	std::string enc_drm_path_local, dec_drm_path_local, rap_path_local;
	Emu.GetVFS().GetDevice(enc_drm_path, enc_drm_path_local);
	Emu.GetVFS().GetDevice(dec_drm_path, dec_drm_path_local);
	Emu.GetVFS().GetDevice(rap_path, rap_path_local);

	DecryptEDAT(enc_drm_path_local, dec_drm_path_local, 8, rap_path_local, k_licensee, false);
	return CELL_OK;
}