Record the history of key acquisition

This commit is contained in:
FoxRefire
2024-04-25 03:37:31 +09:00
parent 9b64cd4c55
commit 2cd496b45f
8 changed files with 81 additions and 7 deletions

View File

@@ -68,6 +68,11 @@ Only use it for content for which you own the rights and do not use it for pirac
6. User input into UI
7. popup.js calls pywidevine script using pyodide in browser
## Third-party libraries
* Pyodide
* Pywidevine
* json-view
### Big Thanks and inspired by
https://github.com/emarsden/pssh-box-wasm/

View File

@@ -1,5 +1,6 @@
let psshs=[];
let requests=[];
let pageURL="";
function convertHeaders(obj){
return JSON.stringify(Object.fromEntries(obj.map(header => [header.name, header.value])))
}
@@ -26,6 +27,7 @@ chrome.runtime.onMessage.addListener(
break;
case "PSSH":
psshs.push(request.text)
pageURL=request.pageURL
break;
}
}
@@ -45,3 +47,7 @@ window.getPsshs = () => {
window.getRequests = () => {
return requests;
};
window.getPageURL = () => {
return pageURL;
};

View File

@@ -13,6 +13,7 @@ document.addEventListener('pssh', (e) => {
console.log(e.detail);
chrome.runtime.sendMessage({
type: "PSSH",
text: e.detail
text: e.detail,
pageURL: document.URL
},null);
});

1
jsonview.js Normal file

File diff suppressed because one or more lines are too long

View File

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

View File

@@ -2,15 +2,16 @@
<head>
<meta charset="UTF-8">
<title>Widevine L3 Guessor 2024</title>
<style>div{display:none}</style>
<style>.hidden{display:none}</style>
<script src="pyodide/pyodide.js"></script>
</head>
<body>
<div id="noEME" style="display:block">
<div id="noEME">
Widevine content hasn't detected in this page.<br>
Open widevine-protected website and try again!
</div>
<div id="home">
<div id="home" class="hidden">
<button id="historyButton">Show History</button><br><br>
<form id="wvForm">
<label for="pssh">PSSH</label>
<input type="text" id="pssh" disabled/>
@@ -35,15 +36,23 @@
</form>
</div>
<div id="selectPssh">
<div id="selectPssh" class="hidden">
<input type="text" id="psshSearch" placeholder="Search">
<ul id="psshList"></ul>
</div>
<div id="selectRequest">
<div id="selectRequest" class="hidden">
<input type="text" id="requestSearch" placeholder="Search">
<ul id="requestList"></ul>
</div>
<div id="history" class="hidden">
<button id="backHistory">🔙 Back</button>
<button id="saveHistory">💾 Save History</button>
<button id="clearHistory">❌ Clear History</button>
<div id="histDisp"></div>
</div>
</body>
<script src="popup.js" type="module"></script>
<script src="popup_drawList.js"></script>
<script src="jsonview.js"></script>
<script src="popup_showHistory.js"></script>
</html>

View File

@@ -1,5 +1,6 @@
let psshs=chrome.extension.getBackgroundPage().getPsshs();
let requests=chrome.extension.getBackgroundPage().getRequests();
let pageURL=chrome.extension.getBackgroundPage().getPageURL();
function selectPssh(){
document.getElementById('home').style.display='none';
@@ -11,23 +12,44 @@ function selectRequest(){
document.getElementById('selectRequest').style.display='block';
}
function showHistory(){
chrome.storage.local.get(null, ((data) => {
jsonview.renderJSON(JSON.stringify(data), document.getElementById('histDisp'));
}));
document.getElementById('home').style.display='none';
document.getElementById('history').style.display='block';
}
async function guess(){
//Init Pyodide
let pyodide = await loadPyodide();
await pyodide.loadPackage(["certifi-2024.2.2-py3-none-any.whl","charset_normalizer-3.3.2-py3-none-any.whl","construct-2.8.8-py2.py3-none-any.whl","idna-3.6-py3-none-any.whl","packaging-23.2-py3-none-any.whl","protobuf-4.24.4-cp312-cp312-emscripten_3_1_52_wasm32.whl","pycryptodome-3.20.0-cp35-abi3-emscripten_3_1_52_wasm32.whl","pymp4-1.4.0-py3-none-any.whl","pyodide_http-0.2.1-py3-none-any.whl","pywidevine-1.8.0-py3-none-any.whl","requests-2.31.0-py3-none-any.whl","urllib3-2.2.1-py3-none-any.whl"].map(e=>"wheels/"+e))
//Configure Guesser
let vars=`pssh="${document.getElementById('pssh').value}"\n`
vars+=`licUrl="${requests[userInputs['license']]['url']}"\n`
vars+=`licHeaders='${requests[userInputs['license']]['headers'].replace(/\\/g, "\\\\")}'\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())
//Get result
let result = await pyodide.runPythonAsync([vars, pre, scheme, after].join("\n"));
document.getElementById('result').value=result;
//Save history
let historyData={
PSSH: document.getElementById('pssh').value,
KEYS: result.split("\n").slice(0,-1)
}
chrome.storage.local.set({[pageURL]: historyData}, function () {});
}
if(psshs.length!=0){
document.addEventListener('DOMContentLoaded', function() {
document.getElementById('noEME').style.display='none';
document.getElementById('home').style.display='block';
document.getElementById('historyButton').addEventListener("click", showHistory);
document.getElementById('psshButton').addEventListener("click", selectPssh);
document.getElementById('licenseButton').addEventListener("click", selectRequest);
document.getElementById('guess').addEventListener("click", guess);

29
popup_showHistory.js Normal file
View File

@@ -0,0 +1,29 @@
document.getElementById('backHistory').addEventListener("click", backHistory);
function backHistory(){
document.getElementById('histDisp').innerHTML="";
document.getElementById('history').style.display='none';
document.getElementById('home').style.display='block';
}
document.getElementById('saveHistory').addEventListener("click", saveHistory);
function saveHistory(){
chrome.storage.local.get(null, ((data) => {
let blob = new Blob([JSON.stringify(data, null, "\t")], {type: "text/plain"});
let blobLink = URL.createObjectURL(blob);
let a = document.createElement('a');
a.download = 'wvgHistory.json';
a.href = blobLink
document.body.appendChild(a);
a.click();
document.body.removeChild(a);
URL.revokeObjectURL(blobLink);
}));
}
document.getElementById('clearHistory').addEventListener("click", clearHistory);
function clearHistory(){
if(confirm("Do you really want to clear history?")){
chrome.storage.local.clear();
document.getElementById('histDisp').innerHTML="";
}
}