Skip to content

Commit

Permalink
fix: improve sig extraction (#183)
Browse files Browse the repository at this point in the history
* dev: improve sig decipher code extraction

* chore(deps): update Jinter to 0.2.0
  • Loading branch information
LuanRT authored Sep 13, 2022
1 parent 89794d6 commit 3a7da21
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 41 deletions.
40 changes: 7 additions & 33 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 3 additions & 3 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -39,16 +39,16 @@
"license": "MIT",
"dependencies": {
"@protobuf-ts/runtime": "^2.7.0",
"jintr": "^0.1.9",
"jintr": "^0.2.0",
"linkedom": "^0.14.12",
"undici": "^5.7.0"
},
"devDependencies": {
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"@protobuf-ts/plugin": "^2.7.0",
"@types/jest": "^28.1.7",
"@types/node": "^17.0.45",
"@typescript-eslint/eslint-plugin": "^5.30.6",
"@typescript-eslint/parser": "^5.30.6",
"esbuild": "^0.14.49",
"eslint": "^8.19.0",
"eslint-plugin-tsdoc": "^0.2.16",
Expand Down
11 changes: 6 additions & 5 deletions src/core/Player.ts
Original file line number Diff line number Diff line change
Expand Up @@ -166,20 +166,21 @@ export default class Player {
}

static extractSigSourceCode(data: string) {
const funcs = getStringBetweenStrings(data, 'this.audioTracks};var', '};');
const calls = getStringBetweenStrings(data, 'function(a){a=a.split("")', 'return a.join("")}');
const obj_name = calls?.split('.')?.[0]?.replace(';', '');
const functions = getStringBetweenStrings(data, `var ${obj_name}=`, '};');

if (!funcs || !calls)
throw new PlayerError('Failed to extract signature decipher algorithm');
if (!functions || !calls)
console.warn(new PlayerError('Failed to extract signature decipher algorithm'));

return `function descramble_sig(a) { a = a.split(""); ${funcs}}${calls} return a.join("") } descramble_sig(sig);`;
return `function descramble_sig(a) { a = a.split(""); let ${obj_name}=${functions}}${calls} return a.join("") } descramble_sig(sig);`;
}

static extractNSigSourceCode(data: string) {
const sc = `function descramble_nsig(a) { let b=a.split("")${getStringBetweenStrings(data, 'b=a.split("")', '}return b.join("")}')}} return b.join(""); } descramble_nsig(nsig)`;

if (!sc)
throw new PlayerError('Failed to extract n-token decipher algorithm');
console.warn(new PlayerError('Failed to extract n-token decipher algorithm'));

return sc;
}
Expand Down

0 comments on commit 3a7da21

Please sign in to comment.