Example #1
0
bool SELFDecrypter::GetKeyFromRap(u8 *content_id, u8 *npdrm_key)
{
	// Set empty RAP key.
	u8 rap_key[0x10];
	memset(rap_key, 0, 0x10);

	// Try to find a matching RAP file under dev_usb000.
	std::string ci_str((const char *)content_id);
	std::string rap_path(fmt::ToUTF8(wxGetCwd()) + "/dev_usb000/" + ci_str + ".rap");

	// Check if we have a valid RAP file.
	if (!wxFile::Exists(fmt::FromUTF8(rap_path)))
	{
		ConLog.Error("This application requires a valid RAP file for decryption!");
		return false;
	}

	// Open the RAP file and read the key.
	wxFile rap_file(fmt::FromUTF8(rap_path), wxFile::read);

	if (!rap_file.IsOpened())
	{
		ConLog.Error("Failed to load RAP file!");
		return false;
	}

	ConLog.Write("Loading RAP file %s", (ci_str + ".rap").c_str());
	rap_file.Read(rap_key, 0x10);
	rap_file.Close();

	// Convert the RAP key.
	rap_to_rif(rap_key, npdrm_key);

	return true;
}
Example #2
0
bool SELFDecrypter::GetKeyFromRap(u8 *content_id, u8 *npdrm_key)
{
	// Set empty RAP key.
	u8 rap_key[0x10];
	memset(rap_key, 0, 0x10);

	// Try to find a matching RAP file under exdata folder.
	std::string ci_str((const char *)content_id);
	std::string pf_str("00000001");  // TODO: Allow multiple profiles. Use default for now.
	std::string rap_path("dev_hdd0/home/" + pf_str + "/exdata/" + ci_str + ".rap");

	// Check if we have a valid RAP file.
	if (!fs::is_file(rap_path))
	{
		LOG_ERROR(LOADER, "This application requires a valid RAP file for decryption!");
		return false;
	}

	// Open the RAP file and read the key.
	fs::file rap_file(rap_path);

	if (!rap_file)
	{
		LOG_ERROR(LOADER, "Failed to load RAP file!");
		return false;
	}

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

	// Convert the RAP key.
	rap_to_rif(rap_key, npdrm_key);

	return true;
}
Example #3
0
bool SELFDecrypter::GetKeyFromRap(u8 *content_id, u8 *npdrm_key)
{
	// Set empty RAP key.
	u8 rap_key[0x10];
	memset(rap_key, 0, 0x10);

	// Try to find a matching RAP file under dev_usb000.
	std::string ci_str((const char *)content_id);
	// TODO: This shouldn't use current dir
	std::string rap_path("./dev_usb000/" + ci_str + ".rap");

	// Check if we have a valid RAP file.
	if (!rExists(rap_path))
	{
		LOG_ERROR(LOADER, "This application requires a valid RAP file for decryption!");
		return false;
	}

	// Open the RAP file and read the key.
	rFile rap_file(rap_path, rFile::read);

	if (!rap_file.IsOpened())
	{
		LOG_ERROR(LOADER, "Failed to load RAP file!");
		return false;
	}

	LOG_NOTICE(LOADER, "Loading RAP file %s", (ci_str + ".rap").c_str());
	rap_file.Read(rap_key, 0x10);
	rap_file.Close();

	// Convert the RAP key.
	rap_to_rif(rap_key, npdrm_key);

	return true;
}
Example #4
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;
}