Skip to content

Commit

Permalink
fix: debug-protection outdated scope (#87)
Browse files Browse the repository at this point in the history
  • Loading branch information
j4k0xb committed Jun 4, 2024
1 parent 67918d7 commit e86c35d
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 9 deletions.
3 changes: 1 addition & 2 deletions packages/webcrack/src/ast-utils/transform.ts
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@ export function applyTransform<TOptions>(
ast: Node,
transform: Transform<TOptions>,
options?: TOptions,
noScopeOverride?: boolean,
): TransformState {
logger(`${transform.name}: started`);
const state: TransformState = { changes: 0 };
Expand All @@ -34,7 +33,7 @@ export function applyTransform<TOptions>(
const visitor = transform.visitor(
options,
) as TraverseOptions<TransformState>;
visitor.noScope = noScopeOverride || !transform.scope;
visitor.noScope = !transform.scope;
traverse(ast, visitor, undefined, state);
}

Expand Down
4 changes: 2 additions & 2 deletions packages/webcrack/src/deobfuscate/debug-protection.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,9 @@ export default {

const binding = path.scope.getBinding(
debugProtectionFunctionName.current!,
)!;
);

binding.referencePaths.forEach((ref) => {
binding?.referencePaths.forEach((ref) => {
if (intervalCall.match(ref.parent)) {
findParent(ref, iife)?.remove();
}
Expand Down
9 changes: 4 additions & 5 deletions packages/webcrack/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -137,14 +137,14 @@ export async function webcrack(

const stages = [
() => {
return (ast = parse(code, {
ast = parse(code, {
sourceType: 'unambiguous',
allowReturnOutsideFunction: true,
plugins: ['jsx'],
}));
});
},
() => {
return applyTransforms(
applyTransforms(
ast,
[blockStatements, sequence, splitVariableDeclarations, varFunctions],
{ name: 'prepare' },
Expand All @@ -160,14 +160,13 @@ export async function webcrack(
// TODO: Also merge unminify visitor (breaks selfDefending/debugProtection atm)
(options.deobfuscate || options.jsx) &&
(() => {
return applyTransforms(
applyTransforms(
ast,
[
// Have to run this after unminify to properly detect it
options.deobfuscate ? [selfDefending, debugProtection] : [],
options.jsx ? [jsx, jsxNew] : [],
].flat(),
{ noScope: true },
);
}),
options.deobfuscate && (() => applyTransform(ast, mergeObjectAssignments)),
Expand Down

0 comments on commit e86c35d

Please sign in to comment.