diff --git a/src/core/Player.ts b/src/core/Player.ts index be49832a..769ed1c8 100644 --- a/src/core/Player.ts +++ b/src/core/Player.ts @@ -286,7 +286,7 @@ export default class Player { if (!functions || !var_name) Log.warn(TAG, 'Failed to extract signature decipher algorithm.'); - return `${global_variable?.result || ''} function descramble_sig(${var_name}) { let ${obj_name}={${functions}}; ${match[2]} } descramble_sig(sig);`; + return `${global_variable?.result ? `var ${global_variable.result};` : ''} function descramble_sig(${var_name}) { let ${obj_name}={${functions}}; ${match[2]} } descramble_sig(sig);`; } static extractNSigSourceCode(data: string, ast?: ReturnType, global_variable?: ASTLookupResult): string | undefined { @@ -303,7 +303,7 @@ export default class Player { nsig_function = findFunction(data, { includes: '.reverse().forEach(function', ast }); if (nsig_function) - return `${global_variable.result} var ${nsig_function.result} ${nsig_function.name}(nsig);`; + return `var ${global_variable.result}; var ${nsig_function.result} ${nsig_function.name}(nsig);`; } // This is the suffix of the error tag. diff --git a/src/utils/Utils.ts b/src/utils/Utils.ts index e0f8c77a..0ddd5059 100644 --- a/src/utils/Utils.ts +++ b/src/utils/Utils.ts @@ -353,7 +353,7 @@ export function findFunction(source: string, args: ASTLookupArgs): ASTLookupResu } /** - * Searches for a variable declaration in the given code based on specified criteria. + * Searches for a variable declarator in the given code based on specified criteria. * * @example * ```ts @@ -381,23 +381,21 @@ export function findVariable(code: string, options: ASTLookupArgs): ASTLookupRes function walk(node: Node): void { if (found) return; - if (node.type === 'VariableDeclaration') { + if (node.type === 'VariableDeclarator') { const [ start, end ] = node.range!; const node_source = code.slice(start, end); - for (const declarator of node.declarations) { - if (declarator.id.type === 'Identifier') { - const var_name = declarator.id.name; - if (options.name && var_name === options.name) { - found = { start, end, name: var_name, node, result: node_source }; - return; - } + if (node.id.type === 'Identifier') { + const var_name = node.id.name; + if (options.name && var_name === options.name) { + found = { start, end, name: var_name, node, result: node_source }; + return; } } if ( (options.includes && node_source.includes(options.includes)) || (options.regexp && options.regexp.test(node_source))) { - found = { start, end, name: (node.declarations?.[0]?.id as any)?.name, node, result: node_source }; + found = { start, end, name: (node?.id as any)?.name, node, result: node_source }; return; } }