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 c0ff41e
Show file tree
Hide file tree
Showing 2 changed files with 17 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
4 changes: 4 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,10 @@ classifiers = [
"Operating System :: OS Independent",
"Topic :: Software Development :: Libraries :: Python Modules",
]

[project.dependencies]
"Closure-Compiler" = ["ClosureCompiler"] # @ git+https://github.com/KOLANICH-libs/ClosureCompiler.py

[project.urls]
Homepage = "https://github.com/taylordotfish/opener"

Expand Down

0 comments on commit c0ff41e

Please sign in to comment.