Add Red Bee scheme

Merge pull request #8 from FoxRefire/features/RedBee
This commit is contained in:
FoxRefire 2024-04-28 06:00:11 +09:00 committed by GitHub
commit f8eb491607
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
6 changed files with 68 additions and 2 deletions

View File

@ -1,15 +1,19 @@
let psshs=[];
let requests=[];
let bodys=[];
let pageURL="";
function convertHeaders(obj){
return JSON.stringify(Object.fromEntries(obj.map(header => [header.name, header.value])))
}
//Get URL and headers from POST requests
chrome.webRequest.onBeforeSendHeaders.addListener(
function(details) {
if (details.method === "POST") {
requests.push({
url:details.url,
headers:convertHeaders(details.requestHeaders)
headers:convertHeaders(details.requestHeaders),
body:bodys.find((b) => b.id == details.requestId).body
});
}
},
@ -17,6 +21,20 @@ chrome.webRequest.onBeforeSendHeaders.addListener(
["requestHeaders"]
);
//Get requestBody from POST requests
chrome.webRequest.onBeforeRequest.addListener(
function(details) {
if (details.method === "POST") {
bodys.push({
body:btoa(String.fromCharCode(...new Uint8Array(details.requestBody.raw[0]['bytes']))),
id:details.requestId
});
}
},
{urls: ["<all_urls>"]},
["requestBody"]
);
//Receive PSSH from content.js
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
@ -24,6 +42,7 @@ chrome.runtime.onMessage.addListener(
case "RESET":
psshs=[];
requests=[];
bodys=[];
break;
case "PSSH":
psshs.push(request.text)

View File

@ -17,3 +17,22 @@ document.addEventListener('pssh', (e) => {
pageURL: document.URL
},null);
});
//Fetch from original origin
chrome.runtime.onMessage.addListener(
function (request, sender, sendResponse) {
if(request.type=="FETCH"){
console.log("DEBUG:"+JSON.stringify(request))
let res = fetch(request.u, {
method: request.m,
headers: request.h,
body: request.b
}).then((r)=>r.arrayBuffer()).then((r)=>{
sendResponse(
btoa(String.fromCharCode(...new Uint8Array(r)))
);
})
}
return true
}
);

View File

@ -11,7 +11,8 @@
"<all_urls>",
"activeTab",
"windows",
"storage"
"storage",
"tabs"
],
"background": {
"scripts": ["background.js"],

View File

@ -27,6 +27,7 @@
<select id="scheme">
<option value="CommonWV">CommonWV</option>
<option value="DRMToday">DRMToday</option>
<option value="RedBee">Red Bee Media</option>
</select><br>
<input type="button" id="guess" value="Guess!"><br>

View File

@ -11,6 +11,7 @@ async function guess(){
let vars=`pssh="${document.getElementById('pssh').value}"\n`
vars+=`licUrl="${requests[userInputs['license']]['url']}"\n`
vars+=`licHeaders='${requests[userInputs['license']]['headers'].replace(/\\/g, "\\\\")}'\n`
vars+=`licBody="${requests[userInputs['license']]['body']}"\n`
let pre=await fetch('python/pre.py').then(res=>res.text())
let after=await fetch('python/after.py').then(res=>res.text())
let scheme=await fetch(`python/schemes/${document.getElementById("scheme").value}.py`).then(res=>res.text())
@ -32,6 +33,16 @@ function copyResult(){
navigator.clipboard.writeText(this.value);
}
window.corsFetch = (u, m, h, b) => {
return new Promise((resolve, reject) => {
chrome.tabs.query({ url:pageURL }, (tabs) => {
chrome.tabs.sendMessage(tabs[0].id, {type:"FETCH", u:u, m:m, h:h, b:b}, (res) => {
resolve(res)
})
})
})
}
if(psshs.length!=0){
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('noEME').style.display='none';

15
python/schemes/RedBee.py Normal file
View File

@ -0,0 +1,15 @@
import base64
import js
from pyodide.ffi import to_js
req = json.loads(base64.b64decode(licBody.encode()).decode())
b64challenge = base64.b64encode(challenge).decode()
req['message'] = b64challenge
# res = await (await pyfetch(licUrl,
# method="POST",
# headers=licHeaders,
# body=req
# )).json()
res = await js.corsFetch(licUrl, "POST", to_js(licHeaders), json.dumps(req))
res = json.loads(base64.b64decode(res.encode()).decode())
print(res)
licence = base64.b64decode(res['license'].encode())