Skip to content

Commit 3ea2815

Browse files
authored
fix(Player): Fix global variable extraction in the deciphering code (#1029)
1 parent 0181594 commit 3ea2815

File tree

2 files changed

+10
-12
lines changed

2 files changed

+10
-12
lines changed

src/core/Player.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ export default class Player {
286286
if (!functions || !var_name)
287287
Log.warn(TAG, 'Failed to extract signature decipher algorithm.');
288288

289-
return `${global_variable?.result || ''} function descramble_sig(${var_name}) { let ${obj_name}={${functions}}; ${match[2]} } descramble_sig(sig);`;
289+
return `${global_variable?.result ? `var ${global_variable.result};` : ''} function descramble_sig(${var_name}) { let ${obj_name}={${functions}}; ${match[2]} } descramble_sig(sig);`;
290290
}
291291

292292
static extractNSigSourceCode(data: string, ast?: ReturnType<typeof Jinter.parseScript>, global_variable?: ASTLookupResult): string | undefined {
@@ -303,7 +303,7 @@ export default class Player {
303303
nsig_function = findFunction(data, { includes: '.reverse().forEach(function', ast });
304304

305305
if (nsig_function)
306-
return `${global_variable.result} var ${nsig_function.result} ${nsig_function.name}(nsig);`;
306+
return `var ${global_variable.result}; var ${nsig_function.result} ${nsig_function.name}(nsig);`;
307307
}
308308

309309
// This is the suffix of the error tag.

src/utils/Utils.ts

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -353,7 +353,7 @@ export function findFunction(source: string, args: ASTLookupArgs): ASTLookupResu
353353
}
354354

355355
/**
356-
* Searches for a variable declaration in the given code based on specified criteria.
356+
* Searches for a variable declarator in the given code based on specified criteria.
357357
*
358358
* @example
359359
* ```ts
@@ -381,23 +381,21 @@ export function findVariable(code: string, options: ASTLookupArgs): ASTLookupRes
381381
function walk(node: Node): void {
382382
if (found) return;
383383

384-
if (node.type === 'VariableDeclaration') {
384+
if (node.type === 'VariableDeclarator') {
385385
const [ start, end ] = node.range!;
386386
const node_source = code.slice(start, end);
387387

388-
for (const declarator of node.declarations) {
389-
if (declarator.id.type === 'Identifier') {
390-
const var_name = declarator.id.name;
391-
if (options.name && var_name === options.name) {
392-
found = { start, end, name: var_name, node, result: node_source };
393-
return;
394-
}
388+
if (node.id.type === 'Identifier') {
389+
const var_name = node.id.name;
390+
if (options.name && var_name === options.name) {
391+
found = { start, end, name: var_name, node, result: node_source };
392+
return;
395393
}
396394
}
397395
if (
398396
(options.includes && node_source.includes(options.includes)) ||
399397
(options.regexp && options.regexp.test(node_source))) {
400-
found = { start, end, name: (node.declarations?.[0]?.id as any)?.name, node, result: node_source };
398+
found = { start, end, name: (node?.id as any)?.name, node, result: node_source };
401399
return;
402400
}
403401
}

0 commit comments

Comments
 (0)