Update inject.js

This commit is contained in:
TPD94 2025-06-29 02:50:36 -04:00
parent 8a2fc2dfed
commit 388afaa171

View File

@ -409,8 +409,6 @@ function arrayBufferToBase64(uint8array) {
// Challenge generator interceptor
const originalGenerateRequest = MediaKeySession.prototype.generateRequest;
MediaKeySession.prototype.generateRequest = function(initDataType, initData) {
if (!generateRequestCalled) {
generateRequestCalled = true;
const session = this;
let playReadyPssh = getPlayReadyPssh(initData);
if (playReadyPssh) {
@ -496,7 +494,6 @@ MediaKeySession.prototype.generateRequest = function(initDataType, initData) {
console.log("Message interceptor mounted.");
}
return originalGenerateRequest.call(session, initDataType, initData);
}
};
// Message update interceptors
@ -591,7 +588,7 @@ MediaKeySession.prototype.update = function(response) {
if (body instanceof ArrayBuffer || body instanceof Uint8Array) {
const buffer = body instanceof Uint8Array ? body : new Uint8Array(body);
const base64Body = window.btoa(String.fromCharCode(...buffer));
if ((base64EncodedBody.startsWith("CAES") || base64EncodedBody.startsWith("PD94")) && (!remoteCDM || remoteCDM.challenge === null || base64Body !== remoteCDM.challenge) && interceptType === "EME") {
if ((base64Body.startsWith("CAES") || base64Body.startsWith("PD94")) && (!remoteCDM || remoteCDM.challenge === null || base64Body !== remoteCDM.challenge) && interceptType === "EME") {
foundChallengeInBody = true;
window.postMessage({ type: "__LICENSE_URL__", data: this._url }, "*");
// Block the request
@ -601,7 +598,7 @@ MediaKeySession.prototype.update = function(response) {
foundChallengeInBody = true;
window.postMessage({ type: "__LICENSE_URL__", data: this._url }, "*");
if (!remoteCDM) {
if (base64EncodedBody.startsWith("CAES")) {
if (base64Body.startsWith("CAES")) {
const {
device_type, system_id, security_level, host, secret, device_name
} = widevineDeviceInfo;
@ -609,7 +606,7 @@ MediaKeySession.prototype.update = function(response) {
remoteCDM.openSession();
remoteCDM.getChallenge(foundWidevinePssh);
}
if (base64EncodedBody.startsWith("PD94")) {
if (base64Body.startsWith("PD94")) {
const {
security_level, host, secret, device_name
} = playreadyDeviceInfo;
@ -618,12 +615,15 @@ MediaKeySession.prototype.update = function(response) {
remoteCDM.getChallenge(foundPlayreadyPssh);
}
}
const injectedBody = atob(remoteCDM.challenge);
if (remoteCDM) {
remoteCDM.getChallenge(foundWidevinePssh);
}
const injectedBody = base64ToUint8Array(remoteCDM.challenge);
return originalSend.call(this, injectedBody);
}
}
if (typeof body === 'string') {
if (typeof body === 'string' && !isJson(body)) {
const base64EncodedBody = btoa(body);
if ((base64EncodedBody.startsWith("CAES") || base64EncodedBody.startsWith("PD94")) && (!remoteCDM || remoteCDM.challenge === null || base64EncodedBody !== remoteCDM.challenge) && interceptType === "EME") {
foundChallengeInBody = true;
@ -656,15 +656,6 @@ MediaKeySession.prototype.update = function(response) {
return originalSend.call(this, injectedBody);
}
}
if (isJson(body)) {
if (jsonContainsValue(body) && !jsonContainsValue(body, remoteCDM.challenge)) {
foundChallengeInBody = true;
window.postMessage({ type: "__LICENSE_URL__", data: this._url }, "*");
return;
}
}
}
}
return originalSend.apply(this, arguments);