Skip to content

Commit

Permalink
Improve deobfuscation by preprocessing sources with Google Closure Co…
Browse files Browse the repository at this point in the history
…mpiler.
  • Loading branch information
KOLANICH committed Mar 6, 2023
1 parent 74306b0 commit 862164e
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions opener/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
code. [default: {1}]
-a --ast Output a JSON representation of the AST instead of JS.
-v --verbose Output additional messages to standard error.
--use-closure-compiler Use Google Closure Compiler to optimize source. Eliminates some of obfuscations.
""".format(os.path.basename(sys.argv[0]), DEFAULT_TEMP_PREFIX)


Expand All @@ -58,6 +59,7 @@ def main():
temp_prefix = DEFAULT_TEMP_PREFIX
emit_ast = False
verbose = False
use_closure_compiler = False

args = []
for arg in sys.argv[1:]:
Expand Down Expand Up @@ -95,6 +97,8 @@ def main():
emit_ast = True
elif arg in ["-v", "--verbose"]:
verbose = True
elif arg in ["--use-closure-compiler"]:
use_closure_compiler = True
else:
print(f"Unrecognized option: {arg}", file=sys.stderr)
usage(exit=True, error=True)
Expand All @@ -106,6 +110,15 @@ def main():
source = f.read()

_import()

if use_closure_compiler:
from ClosureCompiler import Compiler, createCompilerOptions, CompilationLevel
c = Compiler(createCompilerOptions(level=CompilationLevel.ADVANCED_OPTIMIZATIONS))
clcomp_res = c({
"index.js": source,
})
source = clcomp_res.js

if verbose:
print("Parsing...", file=sys.stderr)
ast = esprima.parseScript(source)
Expand Down

0 comments on commit 862164e

Please sign in to comment.