From 7f1eeb6b5bbae72d455609e8fd972ad936a69e27 Mon Sep 17 00:00:00 2001 From: Luan Date: Wed, 23 Apr 2025 09:28:42 -0300 Subject: [PATCH] fix(Player): Use global var to find signature algorithm (#953) * chore: Update jintr to version 3.3.1 * fix(Player): Use global var to find signature algorithm This change allows matching code such as: ``` // "Y" is the global var. r = r[Y[14]](Y[19]); q3[Y[8]](r, 30); q3[Y[8]](r, 65); q3[Y[8]](r, 2); ``` TODO: Maybe consider removing the regex (it's too fragile) and instead use the AST walker, like we already do for `nsig` and the global lookup variable. --- package-lock.json | 8 ++++---- package.json | 2 +- src/core/Player.ts | 13 ++++++++++++- 3 files changed, 17 insertions(+), 6 deletions(-) diff --git a/package-lock.json b/package-lock.json index 813901da..10c7e8f6 100644 --- a/package-lock.json +++ b/package-lock.json @@ -13,7 +13,7 @@ "license": "MIT", "dependencies": { "@bufbuild/protobuf": "^2.0.0", - "jintr": "^3.3.0", + "jintr": "^3.3.1", "tslib": "^2.5.0", "undici": "^5.19.1" }, @@ -6155,9 +6155,9 @@ } }, "node_modules/jintr": { - "version": "3.3.0", - "resolved": "https://registry.npmjs.org/jintr/-/jintr-3.3.0.tgz", - "integrity": "sha512-ZsaajJ4Hr5XR0tSPhOZOTjFhxA0qscKNSOs41NRjx7ZOGwpfdp8NKIBEUtvUPbA37JXyv1sJlgeOOZHjr3h76Q==", + "version": "3.3.1", + "resolved": "https://registry.npmjs.org/jintr/-/jintr-3.3.1.tgz", + "integrity": "sha512-nnOzyhf0SLpbWuZ270Omwbj5LcXUkTcZkVnK8/veJXtSZOiATM5gMZMdmzN75FmTyj+NVgrGaPdH12zIJ24oIA==", "funding": [ "https://github.com/sponsors/LuanRT" ], diff --git a/package.json b/package.json index d006d5ac..ebd85c8a 100644 --- a/package.json +++ b/package.json @@ -103,7 +103,7 @@ "license": "MIT", "dependencies": { "@bufbuild/protobuf": "^2.0.0", - "jintr": "^3.3.0", + "jintr": "^3.3.1", "tslib": "^2.5.0", "undici": "^5.19.1" }, diff --git a/src/core/Player.ts b/src/core/Player.ts index 6d3cec21..987d7a8e 100644 --- a/src/core/Player.ts +++ b/src/core/Player.ts @@ -258,7 +258,18 @@ export default class Player { } static extractSigSourceCode(data: string, global_variable?: ASTLookupResult): string | undefined { - const match = data.match(/function\(([A-Za-z_0-9]+)\)\{([A-Za-z_0-9]+=[A-Za-z_0-9]+\.split\((?:[^)]+)\)(.+?)\.join\((?:[^)]+)\))\}/); + // Classic static split/join. + const split_join_regex = /function\(([A-Za-z_0-9]+)\)\{([A-Za-z_0-9]+=[A-Za-z_0-9]+\.split\((?:[^)]+)\)(.+?)\.join\((?:[^)]+)\))\}/; + + // Using the global lookup variable. + const lookup_var = global_variable?.name?.replace(/[$^\\.*+?()[\]{}|]/g, '\\$&'); + const lookup_regex = lookup_var + ? new RegExp( + `function\\(([A-Za-z_0-9]+)\\)\\{([A-Za-z_0-9]+=[A-Za-z_0-9]+\\[${lookup_var}\\[\\d+\\]\\]\\([^)]*\\)([\\s\\S]+?)\\[${lookup_var}\\[\\d+\\]\\]\\([^)]*\\))\\}` + ) + : null; + + const match = data.match(split_join_regex) || (lookup_regex ? data.match(lookup_regex) : null); if (!match) { Log.warn(TAG, 'Failed to extract signature decipher algorithm.');