Update inject.js

This commit is contained in:
TPD94 2025-06-16 01:59:26 -04:00
parent a7b58a0a78
commit b4de9c6d61

View File

@ -462,7 +462,7 @@ MediaKeySession.prototype.generateRequest = function(initDataType, initData) {
remoteCDM = new remotePlayReadyCDM(security_level, host, secret, device_name) remoteCDM = new remotePlayReadyCDM(security_level, host, secret, device_name)
remoteCDM.openSession(); remoteCDM.openSession();
} }
if (remoteCDM) { if (remoteCDM && interceptType === "EME") {
remoteCDM.getChallenge(pssh); remoteCDM.getChallenge(pssh);
} }
if (interceptType === "EME" && remoteCDM) { if (interceptType === "EME" && remoteCDM) {
@ -500,7 +500,7 @@ MediaKeySession.prototype.update = function(response) {
remoteCDM.setServiceCertificate(base64Response); remoteCDM.setServiceCertificate(base64Response);
} }
if (!base64Response.startsWith("CAUS") && pssh) { if (!base64Response.startsWith("CAUS") && pssh) {
if (licenseResponseCounter === 1 && interceptType === "EME" || interceptType === "EME" && foundChallengeInBody) { if (licenseResponseCounter === 1 || foundChallengeInBody) {
remoteCDM.parseLicense(base64Response); remoteCDM.parseLicense(base64Response);
remoteCDM.getKeys(); remoteCDM.getKeys();
remoteCDM.closeSession(); remoteCDM.closeSession();
@ -509,7 +509,7 @@ MediaKeySession.prototype.update = function(response) {
licenseResponseCounter++; licenseResponseCounter++;
} }
const updatePromise = originalUpdate.call(this, response); const updatePromise = originalUpdate.call(this, response);
if (!pssh) { if (!pssh && interceptType !== "DISABLED") {
updatePromise updatePromise
.then(() => { .then(() => {
let clearKeys = getClearkey(response); let clearKeys = getClearkey(response);
@ -566,15 +566,20 @@ MediaKeySession.prototype.update = function(response) {
XMLHttpRequest.prototype.send = function(body) { XMLHttpRequest.prototype.send = function(body) {
if (this._method && this._method.toUpperCase() === 'POST') { if (this._method && this._method.toUpperCase() === 'POST') {
if (body) { if (body) {
if (body instanceof ArrayBuffer) { if (body instanceof ArrayBuffer || body instanceof Uint8Array) {
const buffer = new Uint8Array(body); const buffer = body instanceof Uint8Array ? body : new Uint8Array(body);
const base64Body = window.btoa(String.fromCharCode(...buffer)); const base64Body = window.btoa(String.fromCharCode(...buffer));
console.log("Converted body " + base64Body);
if (base64Body.startsWith("CAES") && base64Body !== remoteCDM.challenge && interceptType === "EME") { if (base64Body.startsWith("CAES") && base64Body !== remoteCDM.challenge && interceptType === "EME") {
foundChallengeInBody = true; foundChallengeInBody = true;
// Block the request // Block the request
return; return;
} }
if (base64Body.startsWith("CAES") && interceptType == "LICENSE") {
foundChallengeInBody = true;
remoteCDM.getChallenge(pssh)
const injectedBody = base64ToUint8Array(remoteCDM.challenge);
return originalSend.call(this, injectedBody);
}
} }
} }
} }