Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
__pycache__/
*.pyc
*.egg-info/
dist/
.idea/
.nodeenv/
.venv/
uv.lock
tests/resources/jsimplifier
tests/resources/obfuscated-javascript-dataset
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -94,5 +94,6 @@ See [THIRD_PARTY_LICENSES.md](THIRD_PARTY_LICENSES.md) and
[NOTICE](NOTICE) for full attribution.

Test samples include obfuscated JavaScript from the
[JSIMPLIFIER dataset](https://zenodo.org/records/17531662) (GPL-3.0),
[JSIMPLIFIER dataset](https://zenodo.org/records/17531662) (GPL-3.0)
and the [Obfuscated JavaScript Dataset](https://www.kaggle.com/datasets/fanbyprinciple/obfuscated-javascript-dataset),
used solely for evaluation purposes.
25 changes: 17 additions & 8 deletions pyjsclear/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,18 @@
Python package.
"""

from pathlib import Path

from .deobfuscator import Deobfuscator


__version__ = '0.1.4'
__all__ = ['Deobfuscator', 'deobfuscate', 'deobfuscate_file']

__version__ = '0.1.5'


def deobfuscate(code: str, max_iterations: int = 50) -> str:
"""Deobfuscate JavaScript code. Returns cleaned source.
"""Deobfuscate JavaScript code and return cleaned source.

Args:
code: JavaScript source code string.
Expand All @@ -24,7 +28,11 @@ def deobfuscate(code: str, max_iterations: int = 50) -> str:
return Deobfuscator(code, max_iterations=max_iterations).execute()


def deobfuscate_file(input_path: str, output_path: str | None = None, max_iterations: int = 50) -> str | bool:
def deobfuscate_file(
input_path: str | Path,
output_path: str | Path | None = None,
max_iterations: int = 50,
) -> str | bool:
"""Deobfuscate a JavaScript file.

Args:
Expand All @@ -40,8 +48,9 @@ def deobfuscate_file(input_path: str, output_path: str | None = None, max_iterat

result = deobfuscate(code, max_iterations=max_iterations)

if output_path:
with open(output_path, 'w') as output_file:
output_file.write(result)
return result != code
return result
if not output_path:
return result

with open(output_path, 'w') as output_file:
output_file.write(result)
return result != code
1 change: 1 addition & 0 deletions pyjsclear/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@


def main() -> None:
"""Parse CLI arguments and run the deobfuscator."""
parser = argparse.ArgumentParser(description='Deobfuscate JavaScript files.')
parser.add_argument('input', help='Input JS file (use - for stdin)')
parser.add_argument('-o', '--output', help='Output file (default: stdout)')
Expand Down
Loading
Loading