AST based Obfuscator for Python
Project description
# bobskater
An AST based Python obfuscator that robustly mangles names in Python code
### Current limitations:
* DOES NOT SUPPORT: Annotations, evals, templated strings
* No configuration but instead takes a cautious approach in determining what identifiers to mangle. Globals, kwargs, class namespace identifiers, and others are not obfuscated but this should be user selected in the future
* It is only tested with Python v3.5 and might not work with other AST versions
* Scoping for comprehensions are kind of hacky (and basically follows Python 2 comprehension scope leaking methodology)
### Installation
```
pip install bobskater
```
### Usage
```
from bobskater import obfuscateFile, obfuscateString
#Takes a file path and overwrites it with the obfuscated file
obfuscateFile(filePath)
#Takes a string of Python code and obfuscates it, returning the result
output = obfuscateString(open('myfile.py', 'r').read())
```
### Developing
The library is broken up into two parts. The first is `FrameTrackingNodeVisitor` which is an `ast.NodeVisitor` that is used to read an entire file and track all identifier usages and in which scopes they were defined, internally using `FrameTrackingNodeVisitor.Frame` and `FrameTrackingNodeVisitor.FrameEntry`. Public methods then allow querying of this internal representation (TODO: maybe the representation shouldn't be internal to the walker but should output it).
The second part is the `ReleaseObfuscationTransformer` which actually transforms the given AST into the obfuscated AST. It internall creates a `FrameTrackingNodeVisitor` to then query information from.
An AST based Python obfuscator that robustly mangles names in Python code
### Current limitations:
* DOES NOT SUPPORT: Annotations, evals, templated strings
* No configuration but instead takes a cautious approach in determining what identifiers to mangle. Globals, kwargs, class namespace identifiers, and others are not obfuscated but this should be user selected in the future
* It is only tested with Python v3.5 and might not work with other AST versions
* Scoping for comprehensions are kind of hacky (and basically follows Python 2 comprehension scope leaking methodology)
### Installation
```
pip install bobskater
```
### Usage
```
from bobskater import obfuscateFile, obfuscateString
#Takes a file path and overwrites it with the obfuscated file
obfuscateFile(filePath)
#Takes a string of Python code and obfuscates it, returning the result
output = obfuscateString(open('myfile.py', 'r').read())
```
### Developing
The library is broken up into two parts. The first is `FrameTrackingNodeVisitor` which is an `ast.NodeVisitor` that is used to read an entire file and track all identifier usages and in which scopes they were defined, internally using `FrameTrackingNodeVisitor.Frame` and `FrameTrackingNodeVisitor.FrameEntry`. Public methods then allow querying of this internal representation (TODO: maybe the representation shouldn't be internal to the walker but should output it).
The second part is the `ReleaseObfuscationTransformer` which actually transforms the given AST into the obfuscated AST. It internall creates a `FrameTrackingNodeVisitor` to then query information from.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
bobskater-0.0.3.tar.gz
(8.5 kB
view hashes)
Built Distribution
Close
Hashes for bobskater-0.0.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 2ce45b35da4877f8063a8b05275d502b9de38b8f396d14900cec34f96b9ef9dd |
|
MD5 | e98565d6440560299d7907a4b6578208 |
|
BLAKE2b-256 | eff616b61fc2b917802669eb9ad9fab7e416eb6a6ae78446bb0d33506c91d3db |