From 6e95321bba50fd52fa0058d5fe0a3a2cbd4d6684 Mon Sep 17 00:00:00 2001 From: Skick Date: Sun, 15 Dec 2024 15:54:26 +0700 Subject: [PATCH] fix: update decipher regexps --- lib/sig.js | 56 ++++++++++++++++++++++-------------------------------- 1 file changed, 23 insertions(+), 33 deletions(-) diff --git a/lib/sig.js b/lib/sig.js index 320ac4bb..17783404 100644 --- a/lib/sig.js +++ b/lib/sig.js @@ -35,17 +35,17 @@ const VARIABLE_PART_DEFINE = `\\"?${VARIABLE_PART}\\"?`; const BEFORE_ACCESS = '(?:\\[\\"|\\.)'; const AFTER_ACCESS = '(?:\\"\\]|)'; const VARIABLE_PART_ACCESS = BEFORE_ACCESS + VARIABLE_PART + AFTER_ACCESS; -const REVERSE_PART = ":function\\(a\\)\\{(?:return )?a\\.reverse\\(\\)\\}"; -const SLICE_PART = ":function\\(a,b\\)\\{return a\\.slice\\(b\\)\\}"; -const SPLICE_PART = ":function\\(a,b\\)\\{a\\.splice\\(0,b\\)\\}"; +const REVERSE_PART = ":function\\(\\w\\)\\{(?:return )?\\w\\.reverse\\(\\)\\}"; +const SLICE_PART = ":function\\(\\w,\\w\\)\\{return \\w\\.slice\\(\\w\\)\\}"; +const SPLICE_PART = ":function\\(\\w,\\w\\)\\{\\w\\.splice\\(0,\\w\\)\\}"; const SWAP_PART = - ":function\\(a,b\\)\\{" + "var c=a\\[0\\];a\\[0\\]=a\\[b%a\\.length\\];a\\[b(?:%a.length|)\\]=c(?:;return a)?\\}"; + ":function\\(\\w,\\w\\)\\{var \\w=\\w\\[0\\];\\w\\[0\\]=\\w\\[\\w%\\w\\.length\\];\\w\\[\\w(?:%\\w.length|)\\]=\\w(?:;return \\w)?\\}"; const DECIPHER_REGEXP = - `function(?: ${VARIABLE_PART})?\\(a\\)\\{` + - `a=a\\.split\\(""\\);\\s*` + - `((?:(?:a=)?${VARIABLE_PART}${VARIABLE_PART_ACCESS}\\(a,\\d+\\);)+)` + - `return a\\.join\\(""\\)` + + `function(?: ${VARIABLE_PART})?\\(([a-zA-Z])\\)\\{` + + '\\1=\\1\\.split\\(""\\);\\s*' + + `((?:(?:\\1=)?${VARIABLE_PART}${VARIABLE_PART_ACCESS}\\(\\1,\\d+\\);)+)` + + 'return \\1\\.join\\(""\\)' + `\\}`; const HELPER_REGEXP = `var (${VARIABLE_PART})=\\{((?:(?:${VARIABLE_PART_DEFINE}${REVERSE_PART}|${ @@ -57,21 +57,12 @@ const MCR = `${SCVR}+`; const AAR = "\\[(\\d+)]"; const N_TRANSFORM_NAME_REGEXPS = [ // NewPipeExtractor regexps - `${SCVR}="nn"\\[\\+${MCR}\\.${MCR}],${MCR}\\(${MCR}\\),${MCR}=${MCR}\\.${MCR}\\[${MCR}]\\|\\|null\\).+\\|\\|(${ - MCR - })\\(""\\)`, - `${SCVR}="nn"\\[\\+${MCR}\\.${MCR}],${MCR}\\(${MCR}\\),${MCR}=${MCR}\\.${MCR}\\[${MCR}]\\|\\|null\\)&&\\(${MCR}=(${ - MCR - })${AAR}`, + `${SCVR}="nn"\\[\\+${MCR}\\.${MCR}],${MCR}\\(${MCR}\\),${MCR}=${MCR}\\.${MCR}\\[${MCR}]\\|\\|null\\).+\\|\\|(${MCR})\\(""\\)`, + `${SCVR}="nn"\\[\\+${MCR}\\.${MCR}],${MCR}\\(${MCR}\\),${MCR}=${MCR}\\.${MCR}\\[${MCR}]\\|\\|null\\)&&\\(${MCR}=(${MCR})${AAR}`, `${SCVR}="nn"\\[\\+${MCR}\\.${MCR}],${MCR}=${MCR}\\.get\\(${MCR}\\)\\).+\\|\\|(${MCR})\\(""\\)`, `${SCVR}="nn"\\[\\+${MCR}\\.${MCR}],${MCR}=${MCR}\\.get\\(${MCR}\\)\\)&&\\(${MCR}=(${MCR})\\[(\\d+)]`, - `\\(${SCVR}=String\\.fromCharCode\\(110\\),${SCVR}=${SCVR}\\.get\\(${SCVR}\\)\\)&&\\(${SCVR}=(${MCR})(?:${AAR})?\\(${ - SCVR - }\\)`, + `\\(${SCVR}=String\\.fromCharCode\\(110\\),${SCVR}=${SCVR}\\.get\\(${SCVR}\\)\\)&&\\(${SCVR}=(${MCR})(?:${AAR})?\\(${SCVR}\\)`, `\\.get\\("n"\\)\\)&&\\(${SCVR}=(${MCR})(?:${AAR})?\\(${SCVR}\\)`, - // Skick regexps - '(\\w+).length\\|\\|\\w+\\(""\\)', - '\\w+.length\\|\\|(\\w+)\\(""\\)', ]; // LavaPlayer regexps @@ -80,7 +71,7 @@ const N_TRANSFORM_REGEXP = "var\\s*(\\w+)=(?:\\1\\.split\\(.*?\\)|String\\.prototype\\.split\\.call\\(\\1,.*?\\))," + "\\s*(\\w+)=(\\[.*?]);\\s*\\3\\[\\d+]" + "(.*?try)(\\{.*?})catch\\(\\s*(\\w+)\\s*\\)\\s*\\{" + - '\\s*return"enhanced_except_([A-z0-9-]+)"\\s*\\+\\s*\\1\\s*}' + + '\\s*return"[\\w-]+([A-z0-9-]+)"\\s*\\+\\s*\\1\\s*}' + '\\s*return\\s*(\\2\\.join\\(""\\)|Array\\.prototype\\.join\\.call\\(\\2,.*?\\))};'; const DECIPHER_ARGUMENT = "sig"; @@ -88,6 +79,7 @@ const N_ARGUMENT = "ncode"; const matchRegex = (regex, str) => { const match = str.match(new RegExp(regex, "s")); + console.log(match) if (!match) throw new Error(`Could not match ${regex}`); return match; }; @@ -116,7 +108,7 @@ const getFuncName = (body, regexps) => { }; const DECIPHER_FUNC_NAME = "DisTubeDecipherFunc"; -const extractDecipherFunc = body => { +const extractDecipherFunc = (exports.d1 = body => { try { const helperObject = matchFirst(HELPER_REGEXP, body); const decipherFunc = matchFirst(DECIPHER_REGEXP, body); @@ -126,9 +118,9 @@ const extractDecipherFunc = body => { } catch (e) { return null; } -}; +}); -const extractDecipherWithName = body => { +const extractDecipherWithName = (exports.d2 = body => { try { const decipherFuncName = getFuncName(body, DECIPHER_NAME_REGEXPS); const funcPattern = `(${decipherFuncName.replace(/\$/g, "\\$")}=function\\([a-zA-Z0-9_]+\\)\\{.+?\\})`; @@ -141,7 +133,7 @@ const extractDecipherWithName = body => { } catch (e) { return null; } -}; +}); const getExtractFunctions = (extractFunctions, body) => { for (const extractFunction of extractFunctions) { @@ -175,7 +167,7 @@ const extractDecipher = body => { }; const N_TRANSFORM_FUNC_NAME = "DisTubeNTransformFunc"; -const extractNTransformFunc = body => { +const extractNTransformFunc = (exports.n1 = body => { try { const nFunc = matchFirst(N_TRANSFORM_REGEXP, body); const resultFunc = `var ${N_TRANSFORM_FUNC_NAME}=${nFunc}`; @@ -184,22 +176,20 @@ const extractNTransformFunc = body => { } catch (e) { return null; } -}; +}); -const extractNTransformWithName = body => { +const extractNTransformWithName = (exports.n2 = body => { try { const nFuncName = getFuncName(body, N_TRANSFORM_NAME_REGEXPS); - const funcPattern = `(${ - nFuncName.replace(/\$/g, "\\$") - // eslint-disable-next-line max-len - }=\\s*function([\\S\\s]*?\\}\\s*return (([\\w$]+?\\.join\\(""\\))|(Array\\.prototype\\.join\\.call\\([\\w$]+?,[\\n\\s]*(("")|(\\("",""\\)))\\)))\\s*\\}))`; + console.log(nFuncName); + const funcPattern = `(${nFuncName.replace(/\$/g, "\\$")}=function\\([a-zA-Z0-9_]+\\)\\{.+?\\})`; const nTransformFunc = `var ${matchGroup1(funcPattern, body)};`; const callerFunc = `${nFuncName}(${N_ARGUMENT});`; return nTransformFunc + callerFunc; } catch (e) { return null; } -}; +}); let nTransformWarning = false; const extractNTransform = body => {