Automate Python script source code obfuscation & virtualization with a flexible Web API for software developers and programmers.
You can use all of the features of Python Obfuscator via our Web API interface. The Web API is based on POST requests and emits JSON encoded responses.
For faster deployment, installation packages for the Python Obfuscator Web API have been uploaded to popular repositories (Packagist, PyPI, npm, crates.io, NuGet). Source code has also been published on GitHub:
| Repository | Language | Installation | Package | Sources |
|---|---|---|---|---|
![]() |
PHP | Run:
or add the following to |
Packagist | GitHub |
![]() |
Python | pip install python-obfuscator-virtualizer |
PyPI | GitHub |
![]() |
JavaScript | Run:
or add the following to |
npm | GitHub |
![]() |
Rust | Run:
or add the following to |
Crates | GitHub |
![]() |
C# | Run:
or add to your |
NuGet | GitHub |
<?php
/******************************************************************************
* Python Obfuscator WebApi interface usage example.
*
* In this example we will obfuscate sample source with default options.
*
* Version : v1.0
* Language : PHP
* Author : Bartosz Wójcik
* Web page : https://www.pelock.com
*
*****************************************************************************/
//
// include Python Obfuscator class
//
use PELock\PythonObfuscator;
//
// if you don't want to use Composer use include_once
//
//include_once "PythonObfuscator.php";
//
// create Python Obfuscator class instance (we are using our activation key)
//
$myPythonObfuscator = new PELock\PythonObfuscator("ABCD-ABCD-ABCD-ABCD");
//
// source code in Python format
//
$scriptSourceCode = "label = 'SecretKey'
port = 443
def get_sum(a, b):
return a + b
print(label, port)
r = get_sum(11, 31)
print(r)
";
//
// by default all obfuscation options are enabled, so we can just simply call:
//
$result = $myPythonObfuscator->ObfuscateScriptSource($scriptSourceCode);
//
// it's also possible to pass a Python script file path instead of a string e.g.
//
// $result = $myPythonObfuscator->ObfuscateScriptFile("/path/to/project/script.py");
//
// $result[] array holds the obfuscation results as well as other information
//
// $result["error"] - error code
// $result["output"] - obfuscated code
// $result["demo"] - was it used in demo mode (invalid or empty activation key was used)
// $result["license_expiration"] - license end date (Y-m-d), empty if none
// $result["usages_total"] - total obfuscations for this activation code
//
if ($result !== false)
{
// display obfuscated code
if ($result["error"] === \PELock\PythonObfuscator::ERROR_SUCCESS)
{
// format output code for HTML display
echo "<pre>" . htmlentities($result["output"]) . "</pre>";
}
else
{
die("An error occurred, error code: " . $result["error"]);
}
}
else
{
die("Something unexpected happen while trying to obfuscate the code.");
}
?>
#!/usr/bin/env python
###############################################################################
#
# Python Obfuscator WebApi interface usage example.
#
# In this example we will obfuscate sample source with default options.
#
# Version : v1.0.0
# Language : Python
# Author : Bartosz Wójcik
# Web page : https://www.pelock.com
#
###############################################################################
#
# include Python Obfuscator module
#
from pythonobfuscator import PythonObfuscator
#
# if you don't want to use Python module, you can import directly from the file
#
#from pelock.pythonobfuscator import PythonObfuscator
#
# create Python Obfuscator class instance (we are using our activation key)
#
myPythonObfuscator = PythonObfuscator("ABCD-ABCD-ABCD-ABCD")
#
# source code in Python format
#
scriptSourceCode = """label = 'SecretKey'
port = 443
def get_sum(a, b):
return a + b
print(label, port)
r = get_sum(11, 31)
print(r)
"""
#
# by default all obfuscation options are enabled, so we can just simply call
#
result = myPythonObfuscator.obfuscate_script_source(scriptSourceCode)
#
# it's also possible to pass a Python script file path instead of a string with the source e.g.
#
# result = myPythonObfuscator.obfuscate_script_file("/path/to/project/script.py")
#
# result[] array holds the obfuscation results as well as other information
#
# result["error"] - error code
# result["output"] - obfuscated code
# result["demo"] - was it used in demo mode (invalid or empty activation key was used)
# result["license_expiration"] - license end date (Y-m-d), empty if none
# result["usages_total"] - total obfuscations for this activation code
#
if result and "error" in result:
# display obfuscated code
if result["error"] == PythonObfuscator.ERROR_SUCCESS:
# format output code for HTML display
print(result["output"])
else:
print(f'An error occurred, error code: {result["error"]}')
else:
print("Something unexpected happen while trying to obfuscate the code.")
/******************************************************************************
* Python Obfuscator WebApi interface usage example.
*
* In this example we will obfuscate sample source with default options.
*
* Version : v1.0.0
* Language : JavaScript
* Author : Bartosz Wójcik
* Web page : https://www.pelock.com
*
*****************************************************************************/
import PythonObfuscator from "python-obfuscator";
//
// include Python Obfuscator class
//
//
// when developing from a repository clone without installing the package use:
//
// import PythonObfuscator from "../src/python-obfuscator.js";
//
// create Python Obfuscator class instance (we are using our activation key)
//
const myPythonObfuscator = new PythonObfuscator("ABCD-ABCD-ABCD-ABCD");
//
// source code in Python format
//
const scriptSourceCode = `label = 'SecretKey'
port = 443
def get_sum(a, b):
return a + b
print(label, port)
r = get_sum(11, 31)
print(r)
`;
//
// by default all obfuscation options are enabled, so we can just simply call:
//
const result = await myPythonObfuscator.obfuscateScriptSource(scriptSourceCode);
//
// it's also possible to pass a Python script file path instead of a string e.g.
//
// const result = await myPythonObfuscator.obfuscateScriptFile("/path/to/project/script.py");
//
// result object holds the obfuscation results as well as other information
//
// result.error - error code
// result.output - obfuscated code
// result.demo - was it used in demo mode (invalid or empty activation key was used)
// result.license_expiration - license end date (Y-m-d), empty if none
// result.usages_total - total obfuscations for this activation code
//
if (result !== null) {
//
// display obfuscated code
//
if (result.error === PythonObfuscator.ERROR_SUCCESS) {
console.log(result.output);
} else {
throw new Error("An error occurred, error code: " + result.error);
}
} else {
throw new Error("Something unexpected happen while trying to obfuscate the code.");
}
/******************************************************************************
* Python Obfuscator WebApi interface usage example.
*
* In this example we will obfuscate sample source with default options.
*
* Version : v1.0.0
* Language : Rust
* Author : Bartosz Wójcik
* Web page : https://www.pelock.com
*
*****************************************************************************/
use python_obfuscator::{PythonObfuscator, PythonObfuscatorResponse};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
//
// include Python Obfuscator class
//
//
// when developing from a repository clone without installing the package use:
//
// use python_obfuscator::{PythonObfuscator, PythonObfuscatorResponse};
// (path dependency in Cargo.toml pointing to this crate)
//
// create Python Obfuscator class instance (we are using our activation key)
//
let my_python_obfuscator =
PythonObfuscator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));
//
// source code in Python format
//
let script_source_code = r#"label = 'SecretKey'
port = 443
def get_sum(a, b):
return a + b
print(label, port)
r = get_sum(11, 31)
print(r)"#;
//
// by default all obfuscation options are enabled, so we can just simply call:
//
let result = my_python_obfuscator
.obfuscate_script_source(script_source_code, true)
.await;
//
// it's also possible to pass a Python script file path instead of a string e.g.
//
// let result = my_python_obfuscator
// .obfuscate_script_file(std::path::Path::new("/path/to/project/script.py"), true)
// .await;
//
// result object holds the obfuscation results as well as other information
//
// result.error - error code
// result.output - obfuscated code
// result.demo - was it used in demo mode (invalid or empty activation key was used)
// result.license_expiration - license end date (Y-m-d), empty if none
// result.usages_total - total obfuscations for this activation code
//
match result {
Some(PythonObfuscatorResponse::Object(obj)) => {
//
// display obfuscated code
//
if obj.error == PythonObfuscator::ERROR_SUCCESS {
println!("{}", obj.output.unwrap_or_default());
} else {
return Err(
format!("An error occurred, error code: {}", obj.error).into(),
);
}
}
Some(PythonObfuscatorResponse::Json(_)) => {}
None => {
return Err("Something unexpected happen while trying to obfuscate the code.".into());
}
}
Ok(())
}
/******************************************************************************
* Python Obfuscator WebApi interface usage example.
*
* In this example we will obfuscate sample source with default options.
*
* Version : v1.0.0
* Language : C#
* Author : Bartosz Wójcik
* Web page : https://www.pelock.com
*
*****************************************************************************/
using PELock.PythonObfuscator;
//
// create Python Obfuscator class instance (we are using our activation key)
//
var myPythonObfuscator = new PythonObfuscator("ABCD-ABCD-ABCD-ABCD");
//
// source code in Python format
//
const string ScriptSourceCode =
"""
label = 'SecretKey'
port = 443
def get_sum(a, b):
return a + b
print(label, port)
r = get_sum(11, 31)
print(r)
""";
//
// by default all obfuscation options are enabled, so we can just simply call:
//
var result = await myPythonObfuscator.ObfuscateScriptSourceAsync(ScriptSourceCode);
//
// it's also possible to pass a Python script file path instead of a string e.g.
//
// var result = await myPythonObfuscator.ObfuscateScriptFileAsync("/path/to/project/script.py");
//
// result object holds the obfuscation results as well as other information
//
// result?.Error - error code (see PythonObfuscator.Error*)
// result?.Output - obfuscated code
// result?.Demo - was it used in demo mode (invalid or empty activation key was used)
// result?.LicenseExpiration - license end date (Y-m-d), empty if none
// result?.UsagesTotal - total obfuscations for this activation code
//
if (result is not null)
{
//
// display obfuscated code
//
if (result.Error == PythonObfuscator.ErrorSuccess && result.Output is not null)
Console.WriteLine(result.Output);
else
throw new InvalidOperationException("An error occurred, error code: " + result.Error);
}
else
{
throw new InvalidOperationException("Something unexpected happen while trying to obfuscate the code.");
}
<?php
/******************************************************************************
* Python Obfuscator WebApi interface usage example.
*
* In this example we will obfuscate sample source with custom options.
*
* Version : v1.0
* Language : PHP
* Author : Bartosz Wójcik
* Web page : https://www.pelock.com
*
*****************************************************************************/
//
// include Python Obfuscator class
//
use PELock\PythonObfuscator;
use PELock\PythonObfuscator\CodeVirtualization;
//
// if you don't want to use Composer use include_once
//
//include_once "PythonObfuscator.php";
//
// create Python Obfuscator class instance (we are using our activation key)
//
$myPythonObfuscator = new PELock\PythonObfuscator("ABCD-ABCD-ABCD-ABCD");
//
// should the source code be compressed (both input & compressed)
//
$myPythonObfuscator->enableCompression = false;
//
// code virtualization mode (exactly one): VM, FSA, or FLAT
// omit / set to null to skip virtualization
//
$myPythonObfuscator->codeVirtualization = CodeVirtualization::VM;
//
// global obfuscation options
//
// you can disable a particular obfuscation strategy globally if it
// fails or you don't want to use it without modifying the source codes
//
// by default all obfuscation strategies are enabled
//
//
// fixed random seed for reproducible obfuscation output (optional)
//
$myPythonObfuscator->seed = null;
//
// randomization density / intensity (0-100)
//
$myPythonObfuscator->randomizationDensity = null;
//
// identifier renaming style: "il", "homoglyph" or "hex"
//
$myPythonObfuscator->renameStyle = null;
//
// protection against tampering with protected code (integrity verification)
//
$myPythonObfuscator->selfDefending = false;
//
// protection linker (decoy call graph)
//
$myPythonObfuscator->protectionLinker = false;
//
// rename variable names to random string values
//
$myPythonObfuscator->renameVariables = true;
//
// rename parameter names to random string values
//
$myPythonObfuscator->renameParameters = true;
//
// rename function names to random string values
//
$myPythonObfuscator->renameFunctions = true;
//
// rename function call references consistently with renamed functions
//
$myPythonObfuscator->renameFunctionCalls = true;
//
// shuffle function order in the output source
//
$myPythonObfuscator->shuffleFunctions = true;
//
// fold/resolve constant expressions at obfuscation time
//
$myPythonObfuscator->resolveConstants = true;
//
//
// split strings into concatenated chunks
//
$myPythonObfuscator->splitStrings = true;
//
// apply light transformations/mutations to string literals
//
$myPythonObfuscator->modifyStrings = true;
//
// encrypt strings using randomly generated polymorphic encryption algorithms
//
$myPythonObfuscator->encryptStrings = true;
//
// store string fragments in char-code array vaults
//
$myPythonObfuscator->stringCharArrayVault = true;
//
// encrypt integers
//
$myPythonObfuscator->encryptIntegers = true;
//
// encrypt floating point numbers
//
$myPythonObfuscator->encryptFloating = true;
//
// replace binary operators with mixed boolean-arithmetic (MBA) equivalents
//
$myPythonObfuscator->mbaBinops = true;
//
// represent integers via floating-point math
//
$myPythonObfuscator->integersToFloating = true;
//
// move integers to arrays
//
$myPythonObfuscator->integersToArrays = true;
//
// move floats to arrays
//
$myPythonObfuscator->floatsToArrays = true;
//
// apply redundant xor / affine integer masks
//
$myPythonObfuscator->affineIntegerMask = true;
//
// encrypt integer array literals
//
$myPythonObfuscator->arrayIntCrypt = true;
//
// encrypt character array literals
//
$myPythonObfuscator->arrayCharCrypt = true;
//
// encrypt floating-point array literals
//
$myPythonObfuscator->arrayDoubleCrypt = true;
//
// encrypt string array literals
//
$myPythonObfuscator->arrayStringCrypt = true;
//
// insert a shared bucket of random noise values used by other strategies
//
$myPythonObfuscator->insertRandomValueBucket = true;
//
// populate the random value bucket with decoy integers
//
$myPythonObfuscator->randomBucketIntegers = true;
//
// populate the random value bucket with decoy arrays
//
$myPythonObfuscator->randomBucketArrays = true;
//
// populate the random value bucket with decoy functions
//
$myPythonObfuscator->randomBucketFunctions = true;
//
// populate the random value bucket with decoy characters
//
$myPythonObfuscator->randomBucketCharacters = true;
//
// populate the random value bucket with anti-regex decoy noise
//
$myPythonObfuscator->randomBucketAntiRegex = true;
//
// populate the random value bucket with autostart decoy stubs
//
$myPythonObfuscator->randomBucketAutostart = true;
//
// rewrite selected statements using ternary operators
//
$myPythonObfuscator->insertTernaryOperators = true;
//
// replace boolean conditions with equivalent complex expressions
//
$myPythonObfuscator->complexifyBooleans = true;
//
// insert opaque predicate branches
//
$myPythonObfuscator->opaqueBranches = true;
//
// insert opaque mixer chains into control flow
//
$myPythonObfuscator->opaqueMixerChain = true;
//
// insert dead code
//
$myPythonObfuscator->insertDeadCode = true;
//
// wrap code in try/finally blocks with dead noise
//
$myPythonObfuscator->tryFinallyNoise = true;
//
// insert decoy functions
//
$myPythonObfuscator->decoyFunctions = true;
//
// insert decoy lambda expressions
//
$myPythonObfuscator->lambdaDecoys = true;
//
// insert literal padding noise
//
$myPythonObfuscator->literalPadding = true;
//
// insert fake import statement markers
//
$myPythonObfuscator->fakeImportMarkers = true;
//
// use dynamic getattr()-based indirect calls
//
$myPythonObfuscator->dynamicGetattrCalls = true;
//
// rewrite absolute imports into __import__ / getattr
//
$myPythonObfuscator->obfuscateImports = true;
//
// insert dead callback/event registration stubs
//
$myPythonObfuscator->callbackRegistrationStubs = true;
//
// insert anti-debugging detections
//
$myPythonObfuscator->detectDebugger = false;
//
// insert virtual machine (anti-VM) detections
//
$myPythonObfuscator->antiVm = false;
//
// insert anti-sandbox detections
//
$myPythonObfuscator->antiSandbox = false;
//
// insert anti-emulators (CPU) detections
//
$myPythonObfuscator->antiEmulator = false;
//
// strip comments from the output source
//
$myPythonObfuscator->removeComments = true;
//
// source code in Python format
//
$scriptSourceCode = "label = 'SecretKey'
port = 443
def get_sum(a, b):
return a + b
print(label, port)
r = get_sum(11, 31)
print(r)
";
//
// by default all obfuscation options are enabled, so we can just simply call:
//
$result = $myPythonObfuscator->ObfuscateScriptSource($scriptSourceCode);
//
// it's also possible to pass a Python script file path instead of a string e.g.
//
// $result = $myPythonObfuscator->ObfuscateScriptFile("/path/to/project/script.py");
//
// $result[] array holds the obfuscation results as well as other information
//
// $result["error"] - error code
// $result["output"] - obfuscated code
// $result["demo"] - was it used in demo mode (invalid or empty activation key was used)
// $result["license_expiration"] - license end date (Y-m-d), empty if none
// $result["usages_total"] - total obfuscations for this activation code
//
if ($result !== false)
{
// display obfuscated code
if ($result["error"] === \PELock\PythonObfuscator::ERROR_SUCCESS)
{
// format output code for HTML display
echo "<pre>" . htmlentities($result["output"]) . "</pre>";
}
else
{
die("An error occurred, error code: " . $result["error"]);
}
}
else
{
die("Something unexpected happen while trying to obfuscate the code.");
}
?>
#!/usr/bin/env python
###############################################################################
#
# Python Obfuscator WebApi interface usage example.
#
# In this example we will obfuscate sample source with custom options.
#
# Version : v1.0.0
# Language : Python
# Author : Bartosz Wójcik
# Web page : https://www.pelock.com
#
###############################################################################
#
# include Python Obfuscator module
#
from pythonobfuscator import CodeVirtualization, PythonObfuscator
#
# if you don't want to use Python module, you can import directly from the file
#
#from pelock.pythonobfuscator import PythonObfuscator
#
# create Python Obfuscator class instance (we are using our activation key)
#
myPythonObfuscator = PythonObfuscator("ABCD-ABCD-ABCD-ABCD")
#
# should the source code be compressed (both input & compressed)
#
myPythonObfuscator.enable_compression = False
#
# code virtualization mode (exactly one): VM, FSA, or FLAT
# omit / set to None to skip virtualization
#
myPythonObfuscator.code_virtualization = CodeVirtualization.VM
#
# global obfuscation options
#
# you can disable a particular obfuscation strategy globally if it
# fails or you don't want to use it without modifying the source codes
#
# by default all obfuscation strategies are enabled
#
#
# fixed random seed for reproducible obfuscation output (optional)
#
myPythonObfuscator.seed = None
#
# randomization density / intensity (0-100)
#
myPythonObfuscator.randomization_density = None
#
# identifier renaming style: RenameStyle.IL, O0, CONFUSABLE, HEX, HOMOGLYPH, or MANGLED
#
myPythonObfuscator.rename_style = None
#
# protection against tampering with protected code (integrity verification)
#
myPythonObfuscator.self_defending = False
#
# protection linker (decoy call graph)
#
myPythonObfuscator.protection_linker = False
#
# rename variable names to random string values
#
myPythonObfuscator.rename_variables = True
#
# rename parameter names to random string values
#
myPythonObfuscator.rename_parameters = True
#
# rename function names to random string values
#
myPythonObfuscator.rename_functions = True
#
# rename function call references consistently with renamed functions
#
myPythonObfuscator.rename_function_calls = True
#
# shuffle function order in the output source
#
myPythonObfuscator.shuffle_functions = True
#
# fold/resolve constant expressions at obfuscation time
#
myPythonObfuscator.resolve_constants = True
#
# split strings into concatenated chunks
#
myPythonObfuscator.split_strings = True
#
# apply light transformations/mutations to string literals
#
myPythonObfuscator.modify_strings = True
#
# encrypt strings using randomly generated polymorphic encryption algorithms
#
myPythonObfuscator.encrypt_strings = True
#
# store string fragments in char-code array vaults
#
myPythonObfuscator.string_char_array_vault = True
#
# encrypt integers
#
myPythonObfuscator.encrypt_integers = True
#
# encrypt floating point numbers
#
myPythonObfuscator.encrypt_floating = True
#
# replace binary operators with mixed boolean-arithmetic (MBA) equivalents
#
myPythonObfuscator.mba_binops = True
#
# represent integers via floating-point math
#
myPythonObfuscator.integers_to_floating = True
#
# move integers to arrays
#
myPythonObfuscator.integers_to_arrays = True
#
# move floats to arrays
#
myPythonObfuscator.floats_to_arrays = True
#
# apply redundant xor / affine integer masks
#
myPythonObfuscator.affine_integer_mask = True
#
# encrypt integer array literals
#
myPythonObfuscator.array_int_crypt = True
#
# encrypt character array literals
#
myPythonObfuscator.array_char_crypt = True
#
# encrypt floating-point array literals
#
myPythonObfuscator.array_double_crypt = True
#
# encrypt string array literals
#
myPythonObfuscator.array_string_crypt = True
#
# insert a shared bucket of random noise values used by other strategies
#
myPythonObfuscator.insert_random_value_bucket = True
#
# populate the random value bucket with decoy integers
#
myPythonObfuscator.random_bucket_integers = True
#
# populate the random value bucket with decoy arrays
#
myPythonObfuscator.random_bucket_arrays = True
#
# populate the random value bucket with decoy functions
#
myPythonObfuscator.random_bucket_functions = True
#
# populate the random value bucket with decoy characters
#
myPythonObfuscator.random_bucket_characters = True
#
# populate the random value bucket with anti-regex decoy noise
#
myPythonObfuscator.random_bucket_anti_regex = True
#
# populate the random value bucket with autostart decoy stubs
#
myPythonObfuscator.random_bucket_autostart = True
#
# rewrite selected statements using ternary operators
#
myPythonObfuscator.insert_ternary_operators = True
#
# replace boolean conditions with equivalent complex expressions
#
myPythonObfuscator.complexify_booleans = True
#
# insert opaque predicate branches
#
myPythonObfuscator.opaque_branches = True
#
# insert opaque mixer chains into control flow
#
myPythonObfuscator.opaque_mixer_chain = True
#
# insert dead code
#
myPythonObfuscator.insert_dead_code = True
#
# wrap code in try/finally blocks with dead noise
#
myPythonObfuscator.try_finally_noise = True
#
# insert decoy functions
#
myPythonObfuscator.decoy_functions = True
#
# insert decoy lambda expressions
#
myPythonObfuscator.lambda_decoys = True
#
# insert literal padding noise
#
myPythonObfuscator.literal_padding = True
#
# insert fake import statement markers
#
myPythonObfuscator.fake_import_markers = True
#
# use dynamic getattr()-based indirect calls
#
myPythonObfuscator.dynamic_getattr_calls = True
#
# rewrite absolute imports into __import__ / getattr
#
myPythonObfuscator.obfuscate_imports = True
#
# insert dead callback/event registration stubs
#
myPythonObfuscator.callback_registration_stubs = True
#
# insert anti-debugging detections
#
myPythonObfuscator.detect_debugger = False
#
# insert virtual machine (anti-VM) detections
#
myPythonObfuscator.anti_vm = False
#
# insert anti-sandbox detections
#
myPythonObfuscator.anti_sandbox = False
#
# insert anti-emulators (CPU) detections
#
myPythonObfuscator.anti_emulator = False
#
# strip comments from the output source
#
myPythonObfuscator.remove_comments = True
#
# source code in Python format
#
scriptSourceCode = """label = 'SecretKey'
port = 443
def get_sum(a, b):
return a + b
print(label, port)
r = get_sum(11, 31)
print(r)
"""
#
# by default all obfuscation options are enabled, so we can just simply call
#
result = myPythonObfuscator.obfuscate_script_source(scriptSourceCode)
#
# it's also possible to pass a Python script file path instead of a string with the source e.g.
#
# result = myPythonObfuscator.obfuscate_script_file("/path/to/project/script.py")
#
# result[] array holds the obfuscation results as well as other information
#
# result["error"] - error code
# result["output"] - obfuscated code
# result["demo"] - was it used in demo mode (invalid or empty activation key was used)
# result["license_expiration"] - license end date (Y-m-d), empty if none
# result["usages_total"] - total obfuscations for this activation code
#
if result and "error" in result:
# display obfuscated code
if result["error"] == PythonObfuscator.ERROR_SUCCESS:
# format output code for HTML display
print(result["output"])
else:
print(f'An error occurred, error code: {result["error"]}')
else:
print("Something unexpected happen while trying to obfuscate the code.")
/******************************************************************************
* Python Obfuscator WebApi interface usage example.
*
* In this example we will obfuscate sample source with custom options.
*
* Version : v1.0.0
* Language : JavaScript
* Author : Bartosz Wójcik
* Web page : https://www.pelock.com
*
*****************************************************************************/
import PythonObfuscator, { CodeVirtualization } from "python-obfuscator";
//
// include Python Obfuscator class
//
//
// when developing from a repository clone without installing the package use:
//
// import PythonObfuscator from "../src/python-obfuscator.js";
//
// create Python Obfuscator class instance (we are using our activation key)
//
const myPythonObfuscator = new PythonObfuscator("ABCD-ABCD-ABCD-ABCD");
//
// should the source code be compressed (both input & compressed)
//
myPythonObfuscator.enableCompression = false;
//
// code virtualization mode (exactly one): VM, FSA, or FLAT
// omit / set to null to skip virtualization
//
myPythonObfuscator.codeVirtualization = CodeVirtualization.VM;
//
// global obfuscation options
//
// you can disable a particular obfuscation strategy globally if it
// fails or you don't want to use it without modifying the source codes
//
// by default all obfuscation strategies are enabled
//
//
// fixed random seed for reproducible obfuscation output (optional)
//
myPythonObfuscator.seed = null;
//
// randomization density / intensity (0-100)
//
myPythonObfuscator.randomizationDensity = null;
//
// identifier renaming style: "il", "homoglyph" or "hex"
//
myPythonObfuscator.renameStyle = null;
//
// protection against tampering with protected code (integrity verification)
//
myPythonObfuscator.selfDefending = false;
//
// protection linker (decoy call graph)
//
myPythonObfuscator.protectionLinker = false;
//
// rename variable names to random string values
//
myPythonObfuscator.renameVariables = true;
//
// rename parameter names to random string values
//
myPythonObfuscator.renameParameters = true;
//
// rename function names to random string values
//
myPythonObfuscator.renameFunctions = true;
//
// rename function call references consistently with renamed functions
//
myPythonObfuscator.renameFunctionCalls = true;
//
// shuffle function order in the output source
//
myPythonObfuscator.shuffleFunctions = true;
//
// fold/resolve constant expressions at obfuscation time
//
myPythonObfuscator.resolveConstants = true;
//
//
// split strings into concatenated chunks
//
myPythonObfuscator.splitStrings = true;
//
// apply light transformations/mutations to string literals
//
myPythonObfuscator.modifyStrings = true;
//
// encrypt strings using randomly generated polymorphic encryption algorithms
//
myPythonObfuscator.encryptStrings = true;
//
// store string fragments in char-code array vaults
//
myPythonObfuscator.stringCharArrayVault = true;
//
// encrypt integers
//
myPythonObfuscator.encryptIntegers = true;
//
// encrypt floating point numbers
//
myPythonObfuscator.encryptFloating = true;
//
// replace binary operators with mixed boolean-arithmetic (MBA) equivalents
//
myPythonObfuscator.mbaBinops = true;
//
// represent integers via floating-point math
//
myPythonObfuscator.integersToFloating = true;
//
// move integers to arrays
//
myPythonObfuscator.integersToArrays = true;
//
// move floats to arrays
//
myPythonObfuscator.floatsToArrays = true;
//
// apply redundant xor / affine integer masks
//
myPythonObfuscator.affineIntegerMask = true;
//
// encrypt integer array literals
//
myPythonObfuscator.arrayIntCrypt = true;
//
// encrypt character array literals
//
myPythonObfuscator.arrayCharCrypt = true;
//
// encrypt floating-point array literals
//
myPythonObfuscator.arrayDoubleCrypt = true;
//
// encrypt string array literals
//
myPythonObfuscator.arrayStringCrypt = true;
//
// insert a shared bucket of random noise values used by other strategies
//
myPythonObfuscator.insertRandomValueBucket = true;
//
// populate the random value bucket with decoy integers
//
myPythonObfuscator.randomBucketIntegers = true;
//
// populate the random value bucket with decoy arrays
//
myPythonObfuscator.randomBucketArrays = true;
//
// populate the random value bucket with decoy functions
//
myPythonObfuscator.randomBucketFunctions = true;
//
// populate the random value bucket with decoy characters
//
myPythonObfuscator.randomBucketCharacters = true;
//
// populate the random value bucket with anti-regex decoy noise
//
myPythonObfuscator.randomBucketAntiRegex = true;
//
// populate the random value bucket with autostart decoy stubs
//
myPythonObfuscator.randomBucketAutostart = true;
//
// rewrite selected statements using ternary operators
//
myPythonObfuscator.insertTernaryOperators = true;
//
// replace boolean conditions with equivalent complex expressions
//
myPythonObfuscator.complexifyBooleans = true;
//
// insert opaque predicate branches
//
myPythonObfuscator.opaqueBranches = true;
//
// insert opaque mixer chains into control flow
//
myPythonObfuscator.opaqueMixerChain = true;
//
// insert dead code
//
myPythonObfuscator.insertDeadCode = true;
//
// wrap code in try/finally blocks with dead noise
//
myPythonObfuscator.tryFinallyNoise = true;
//
// insert decoy functions
//
myPythonObfuscator.decoyFunctions = true;
//
// insert decoy lambda expressions
//
myPythonObfuscator.lambdaDecoys = true;
//
// insert literal padding noise
//
myPythonObfuscator.literalPadding = true;
//
// insert fake import statement markers
//
myPythonObfuscator.fakeImportMarkers = true;
//
// use dynamic getattr()-based indirect calls
//
myPythonObfuscator.dynamicGetattrCalls = true;
//
// rewrite absolute imports into __import__ / getattr
//
myPythonObfuscator.obfuscateImports = true;
//
// insert dead callback/event registration stubs
//
myPythonObfuscator.callbackRegistrationStubs = true;
//
// insert anti-debugging detections
//
myPythonObfuscator.detectDebugger = false;
//
// insert virtual machine (anti-VM) detections
//
myPythonObfuscator.antiVm = false;
//
// insert anti-sandbox detections
//
myPythonObfuscator.antiSandbox = false;
//
// insert anti-emulators (CPU) detections
//
myPythonObfuscator.antiEmulator = false;
//
// strip comments from the output source
//
myPythonObfuscator.removeComments = true;
//
// source code in Python format
//
const scriptSourceCode = `label = 'SecretKey'
port = 443
def get_sum(a, b):
return a + b
print(label, port)
r = get_sum(11, 31)
print(r)
`;
//
// by default all obfuscation options are enabled, so we can just simply call:
//
const result = await myPythonObfuscator.obfuscateScriptSource(scriptSourceCode);
//
// it's also possible to pass a Python script file path instead of a string e.g.
//
// const result = await myPythonObfuscator.obfuscateScriptFile("/path/to/project/script.py");
//
// result object holds the obfuscation results as well as other information
//
// result.error - error code
// result.output - obfuscated code
// result.demo - was it used in demo mode (invalid or empty activation key was used)
// result.license_expiration - license end date (Y-m-d), empty if none
// result.usages_total - total obfuscations for this activation code
//
if (result !== null) {
//
// display obfuscated code
//
if (result.error === PythonObfuscator.ERROR_SUCCESS) {
console.log(result.output);
} else {
throw new Error("An error occurred, error code: " + result.error);
}
} else {
throw new Error("Something unexpected happen while trying to obfuscate the code.");
}
/******************************************************************************
* Python Obfuscator WebApi interface usage example.
*
* In this example we will obfuscate sample source with custom options.
*
* Version : v1.0.0
* Language : Rust
* Author : Bartosz Wójcik
* Web page : https://www.pelock.com
*
*****************************************************************************/
use python_obfuscator::{CodeVirtualization, PythonObfuscator, PythonObfuscatorResponse};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
//
// include Python Obfuscator class
//
//
// when developing from a repository clone without installing the package use:
//
// use python_obfuscator::{PythonObfuscator, PythonObfuscatorResponse};
// (path dependency in Cargo.toml pointing to this crate)
//
// create Python Obfuscator class instance (we are using our activation key)
//
let mut my_python_obfuscator =
PythonObfuscator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));
//
// should the source code be compressed (both input & compressed)
//
my_python_obfuscator.enable_compression = false;
//
// code virtualization mode (exactly one): Vm, Fsa, or Flat
// omit / set to None to skip virtualization
//
my_python_obfuscator.code_virtualization = CodeVirtualization::Vm;
//
// global obfuscation options
//
// you can disable a particular obfuscation strategy globally if it
// fails or you don't want to use it without modifying the source codes
//
// by default all obfuscation strategies are enabled
//
//
// fixed random seed for reproducible obfuscation output (optional)
//
my_python_obfuscator.seed = None;
//
// randomization density / intensity (0-100)
//
my_python_obfuscator.randomization_density = None;
//
// identifier renaming style: "il", "homoglyph" or "hex"
//
my_python_obfuscator.rename_style = None;
//
// protection against tampering with protected code (integrity verification)
//
my_python_obfuscator.self_defending = false;
//
// protection linker (decoy call graph)
//
my_python_obfuscator.protection_linker = false;
//
// rename variable names to random string values
//
my_python_obfuscator.rename_variables = true;
//
// rename parameter names to random string values
//
my_python_obfuscator.rename_parameters = true;
//
// rename function names to random string values
//
my_python_obfuscator.rename_functions = true;
//
// rename function call references consistently with renamed functions
//
my_python_obfuscator.rename_function_calls = true;
//
// shuffle function order in the output source
//
my_python_obfuscator.shuffle_functions = true;
//
// fold/resolve constant expressions at obfuscation time
//
my_python_obfuscator.resolve_constants = true;
//
//
// split strings into concatenated chunks
//
my_python_obfuscator.split_strings = true;
//
// apply light transformations/mutations to string literals
//
my_python_obfuscator.modify_strings = true;
//
// encrypt strings using randomly generated polymorphic encryption algorithms
//
my_python_obfuscator.encrypt_strings = true;
//
// store string fragments in char-code array vaults
//
my_python_obfuscator.string_char_array_vault = true;
//
// encrypt integers
//
my_python_obfuscator.encrypt_integers = true;
//
// encrypt floating point numbers
//
my_python_obfuscator.encrypt_floating = true;
//
// replace binary operators with mixed boolean-arithmetic (MBA) equivalents
//
my_python_obfuscator.mba_binops = true;
//
// represent integers via floating-point math
//
my_python_obfuscator.integers_to_floating = true;
//
// move integers to arrays
//
my_python_obfuscator.integers_to_arrays = true;
//
// move floats to arrays
//
my_python_obfuscator.floats_to_arrays = true;
//
// apply redundant xor / affine integer masks
//
my_python_obfuscator.affine_integer_mask = true;
//
// encrypt integer array literals
//
my_python_obfuscator.array_int_crypt = true;
//
// encrypt character array literals
//
my_python_obfuscator.array_char_crypt = true;
//
// encrypt floating-point array literals
//
my_python_obfuscator.array_double_crypt = true;
//
// encrypt string array literals
//
my_python_obfuscator.array_string_crypt = true;
//
// insert a shared bucket of random noise values used by other strategies
//
my_python_obfuscator.insert_random_value_bucket = true;
//
// populate the random value bucket with decoy integers
//
my_python_obfuscator.random_bucket_integers = true;
//
// populate the random value bucket with decoy arrays
//
my_python_obfuscator.random_bucket_arrays = true;
//
// populate the random value bucket with decoy functions
//
my_python_obfuscator.random_bucket_functions = true;
//
// populate the random value bucket with decoy characters
//
my_python_obfuscator.random_bucket_characters = true;
//
// populate the random value bucket with anti-regex decoy noise
//
my_python_obfuscator.random_bucket_anti_regex = true;
//
// populate the random value bucket with autostart decoy stubs
//
my_python_obfuscator.random_bucket_autostart = true;
//
// rewrite selected statements using ternary operators
//
my_python_obfuscator.insert_ternary_operators = true;
//
// replace boolean conditions with equivalent complex expressions
//
my_python_obfuscator.complexify_booleans = true;
//
// insert opaque predicate branches
//
my_python_obfuscator.opaque_branches = true;
//
// insert opaque mixer chains into control flow
//
my_python_obfuscator.opaque_mixer_chain = true;
//
// insert dead code
//
my_python_obfuscator.insert_dead_code = true;
//
// wrap code in try/finally blocks with dead noise
//
my_python_obfuscator.try_finally_noise = true;
//
// insert decoy functions
//
my_python_obfuscator.decoy_functions = true;
//
// insert decoy lambda expressions
//
my_python_obfuscator.lambda_decoys = true;
//
// insert literal padding noise
//
my_python_obfuscator.literal_padding = true;
//
// insert fake import statement markers
//
my_python_obfuscator.fake_import_markers = true;
//
// use dynamic getattr()-based indirect calls
//
my_python_obfuscator.dynamic_getattr_calls = true;
//
// rewrite absolute imports into __import__ / getattr
//
my_python_obfuscator.obfuscate_imports = true;
//
// insert dead callback/event registration stubs
//
my_python_obfuscator.callback_registration_stubs = true;
//
// insert anti-debugging detections
//
my_python_obfuscator.detect_debugger = false;
//
// insert virtual machine (anti-VM) detections
//
my_python_obfuscator.anti_vm = false;
//
// insert anti-sandbox detections
//
my_python_obfuscator.anti_sandbox = false;
//
// insert anti-emulators (CPU) detections
//
my_python_obfuscator.anti_emulator = false;
//
// strip comments from the output source
//
my_python_obfuscator.remove_comments = true;
//
// source code in Python format
//
let script_source_code = r#"label = 'SecretKey'
port = 443
def get_sum(a, b):
return a + b
print(label, port)
r = get_sum(11, 31)
print(r)"#;
//
// obfuscate the source code with the options set above
//
let result = my_python_obfuscator
.obfuscate_script_source(script_source_code, true)
.await;
//
// it's also possible to pass a Python script file path instead of a string e.g.
//
// let result = my_python_obfuscator
// .obfuscate_script_file(std::path::Path::new("/path/to/project/script.py"), true)
// .await;
//
// result object holds the obfuscation results as well as other information
//
// result.error - error code
// result.output - obfuscated code
// result.demo - was it used in demo mode (invalid or empty activation key was used)
// result.license_expiration - license end date (Y-m-d), empty if none
// result.usages_total - total obfuscations for this activation code
//
match result {
Some(PythonObfuscatorResponse::Object(obj)) => {
//
// display obfuscated code
//
if obj.error == PythonObfuscator::ERROR_SUCCESS {
println!("{}", obj.output.unwrap_or_default());
} else {
return Err(
format!("An error occurred, error code: {}", obj.error).into(),
);
}
}
Some(PythonObfuscatorResponse::Json(_)) => {}
None => {
return Err("Something unexpected happen while trying to obfuscate the code.".into());
}
}
Ok(())
}
/******************************************************************************
* Python Obfuscator WebApi interface usage example.
*
* In this example we will obfuscate sample source with custom options.
*
* Version : v1.0.0
* Language : C#
* Author : Bartosz Wójcik
* Web page : https://www.pelock.com
*
*****************************************************************************/
using PELock.PythonObfuscator;
//
// create Python Obfuscator class instance (we are using our activation key)
//
var myPythonObfuscator = new PythonObfuscator("ABCD-ABCD-ABCD-ABCD");
//
// should the source code be compressed (both input & compressed)
//
myPythonObfuscator.EnableCompression = false;
//
// code virtualization mode (exactly one): VM, FSA, or FLAT
// omit / set to null to skip virtualization
//
myPythonObfuscator.CodeVirtualization = CodeVirtualization.VM;
//
// global obfuscation options
//
// you can disable a particular obfuscation strategy globally if it
// fails or you don't want to use it without modifying the source codes
//
// by default all obfuscation strategies are enabled
//
//
// fixed random seed for reproducible obfuscation output (optional)
//
myPythonObfuscator.Seed = null;
//
// randomization density / intensity (0-100)
//
myPythonObfuscator.RandomizationDensity = null;
//
// identifier renaming style: "il", "homoglyph" or "hex"
//
myPythonObfuscator.RenameStyle = null;
//
// protection against tampering with protected code (integrity verification)
//
myPythonObfuscator.SelfDefending = false;
//
// protection linker (decoy call graph)
//
myPythonObfuscator.ProtectionLinker = false;
//
// rename variable names to random string values
//
myPythonObfuscator.RenameVariables = true;
//
// rename parameter names to random string values
//
myPythonObfuscator.RenameParameters = true;
//
// rename function names to random string values
//
myPythonObfuscator.RenameFunctions = true;
//
// rename function call references consistently with renamed functions
//
myPythonObfuscator.RenameFunctionCalls = true;
//
// shuffle function order in the output source
//
myPythonObfuscator.ShuffleFunctions = true;
//
// fold/resolve constant expressions at obfuscation time
//
myPythonObfuscator.ResolveConstants = true;
//
//
// split strings into concatenated chunks
//
myPythonObfuscator.SplitStrings = true;
//
// apply light transformations/mutations to string literals
//
myPythonObfuscator.ModifyStrings = true;
//
// encrypt strings using randomly generated polymorphic encryption algorithms
//
myPythonObfuscator.EncryptStrings = true;
//
// store string fragments in char-code array vaults
//
myPythonObfuscator.StringCharArrayVault = true;
//
// encrypt integers
//
myPythonObfuscator.EncryptIntegers = true;
//
// encrypt floating point numbers
//
myPythonObfuscator.EncryptFloating = true;
//
// replace binary operators with mixed boolean-arithmetic (MBA) equivalents
//
myPythonObfuscator.MbaBinops = true;
//
// represent integers via floating-point math
//
myPythonObfuscator.IntegersToFloating = true;
//
// move integers to arrays
//
myPythonObfuscator.IntegersToArrays = true;
//
// move floats to arrays
//
myPythonObfuscator.FloatsToArrays = true;
//
// apply redundant xor / affine integer masks
//
myPythonObfuscator.AffineIntegerMask = true;
//
// encrypt integer array literals
//
myPythonObfuscator.ArrayIntCrypt = true;
//
// encrypt character array literals
//
myPythonObfuscator.ArrayCharCrypt = true;
//
// encrypt floating-point array literals
//
myPythonObfuscator.ArrayDoubleCrypt = true;
//
// encrypt string array literals
//
myPythonObfuscator.ArrayStringCrypt = true;
//
// insert a shared bucket of random noise values used by other strategies
//
myPythonObfuscator.InsertRandomValueBucket = true;
//
// populate the random value bucket with decoy integers
//
myPythonObfuscator.RandomBucketIntegers = true;
//
// populate the random value bucket with decoy arrays
//
myPythonObfuscator.RandomBucketArrays = true;
//
// populate the random value bucket with decoy functions
//
myPythonObfuscator.RandomBucketFunctions = true;
//
// populate the random value bucket with decoy characters
//
myPythonObfuscator.RandomBucketCharacters = true;
//
// populate the random value bucket with anti-regex decoy noise
//
myPythonObfuscator.RandomBucketAntiRegex = true;
//
// populate the random value bucket with autostart decoy stubs
//
myPythonObfuscator.RandomBucketAutostart = true;
//
// rewrite selected statements using ternary operators
//
myPythonObfuscator.InsertTernaryOperators = true;
//
// replace boolean conditions with equivalent complex expressions
//
myPythonObfuscator.ComplexifyBooleans = true;
//
// insert opaque predicate branches
//
myPythonObfuscator.OpaqueBranches = true;
//
// insert opaque mixer chains into control flow
//
myPythonObfuscator.OpaqueMixerChain = true;
//
// insert dead code
//
myPythonObfuscator.InsertDeadCode = true;
//
// wrap code in try/finally blocks with dead noise
//
myPythonObfuscator.TryFinallyNoise = true;
//
// insert decoy functions
//
myPythonObfuscator.DecoyFunctions = true;
//
// insert decoy lambda expressions
//
myPythonObfuscator.LambdaDecoys = true;
//
// insert literal padding noise
//
myPythonObfuscator.LiteralPadding = true;
//
// insert fake import statement markers
//
myPythonObfuscator.FakeImportMarkers = true;
//
// use dynamic getattr()-based indirect calls
//
myPythonObfuscator.DynamicGetattrCalls = true;
//
// rewrite absolute imports into __import__ / getattr
//
myPythonObfuscator.ObfuscateImports = true;
//
// insert dead callback/event registration stubs
//
myPythonObfuscator.CallbackRegistrationStubs = true;
//
// insert anti-debugging detections
//
myPythonObfuscator.DetectDebugger = false;
//
// insert virtual machine (anti-VM) detections
//
myPythonObfuscator.AntiVm = false;
//
// insert anti-sandbox detections
//
myPythonObfuscator.AntiSandbox = false;
//
// insert anti-emulators (CPU) detections
//
myPythonObfuscator.AntiEmulator = false;
//
// strip comments from the output source
//
myPythonObfuscator.RemoveComments = true;
//
// source code in Python format
//
const string ScriptSourceCode =
"""
label = 'SecretKey'
port = 443
def get_sum(a, b):
return a + b
print(label, port)
r = get_sum(11, 31)
print(r)
""";
//
// obfuscate the source code with the options set above
//
var result = await myPythonObfuscator.ObfuscateScriptSourceAsync(ScriptSourceCode);
//
// it's also possible to pass a Python script file path instead of a string e.g.
//
// var result = await myPythonObfuscator.ObfuscateScriptFileAsync("/path/to/project/script.py");
//
// result object holds the obfuscation results as well as other information
//
// result?.Error - error code (see PythonObfuscator.Error*)
// result?.Output - obfuscated code
// result?.Demo - was it used in demo mode (invalid or empty activation key was used)
// result?.LicenseExpiration - license end date (Y-m-d), empty if none
// result?.UsagesTotal - total obfuscations for this activation code
//
if (result is not null)
{
//
// display obfuscated code
//
if (result.Error == PythonObfuscator.ErrorSuccess && result.Output is not null)
Console.WriteLine(result.Output);
else
throw new InvalidOperationException("An error occurred, error code: " + result.Error);
}
else
{
throw new InvalidOperationException("Something unexpected happen while trying to obfuscate the code.");
}
<?php
/******************************************************************************
* Python Obfuscator WebApi interface usage example.
*
* In this example we will verify our activation key status.
*
* Version : v1.0
* Language : PHP
* Author : Bartosz Wójcik
* Web page : https://www.pelock.com
*
*****************************************************************************/
//
// include Python Obfuscator class
//
use PELock\PythonObfuscator;
//
// if you don't want to use Composer use include_once
//
//include_once "PythonObfuscator.php";
//
// create Python Obfuscator class instance (we are using our activation key)
//
$myPythonObfuscator = new PELock\PythonObfuscator("ABCD-ABCD-ABCD-ABCD");
//
// login to the service
//
$result = $myPythonObfuscator->Login();
//
// $result[] array holds the information about the license
//
// $result["demo"] - is it a demo mode (invalid or empty activation key was used)
// $result["license_expiration"] - license end date (Y-m-d), empty if none
// $result["usages_total"] - total obfuscations for this activation code
// $result["string_limit"] - Max. source code size allowed (it's 1000 bytes for demo mode)
//
if ($result !== false)
{
echo "Demo version status - " . ($result["demo"] ? "true" : "false") . "<br>";
echo "License expiration - " . $result["license_expiration"] . "<br>";
echo "Total obfuscations - " . $result["usages_total"] . "<br>";
echo "Max. source code size - " . $result["string_limit"] . "<br>";
}
else
{
die("Something unexpected happen while trying to login to the service.");
}
?>
#!/usr/bin/env python
###############################################################################
#
# Python Obfuscator WebApi interface usage example.
#
# In this example we will verify our activation key status.
#
# Version : v1.0.0
# Language : Python
# Author : Bartosz Wójcik
# Web page : https://www.pelock.com
#
###############################################################################
#
# include Python Obfuscator module
#
from pythonobfuscator import PythonObfuscator
#
# if you don't want to use Python module, you can import directly from the file
#
#from pelock.pythonobfuscator import PythonObfuscator
#
# create Python Obfuscator class instance (we are using our activation key)
#
myPythonObfuscator = PythonObfuscator("ABCD-ABCD-ABCD-ABCD")
#
# login to the service
#
result = myPythonObfuscator.login()
#
# result[] array holds the information about the license
#
# result["demo"] - is it a demo mode (invalid or empty activation key was used)
# result["license_expiration"] - license end date (Y-m-d), empty if none
# result["usages_total"] - total obfuscations for this activation code
# result["string_limit"] - max. source code size allowed (it's 1000 bytes for demo mode)
#
if result:
print(f'Demo version status - {"True" if result["demo"] else "False"}')
print(f'License expiration - {result.get("license_expiration")}')
print(f'Total obfuscations - {result.get("usages_total")}')
print(f'Max. source code size - {result["string_limit"]}')
else:
print("Something unexpected happen while trying to login to the service.")
/******************************************************************************
* Python Obfuscator WebApi interface usage example.
*
* In this example we will verify our activation key status.
*
* Version : v1.0.0
* Language : JavaScript
* Author : Bartosz Wójcik
* Web page : https://www.pelock.com
*
*****************************************************************************/
import PythonObfuscator from "python-obfuscator";
//
// include Python Obfuscator class
//
//
// when developing from a repository clone without installing the package use:
//
// import PythonObfuscator from "../src/python-obfuscator.js";
//
// create Python Obfuscator class instance (we are using our activation key)
//
const myPythonObfuscator = new PythonObfuscator("ABCD-ABCD-ABCD-ABCD");
//
// login to the service
//
const result = await myPythonObfuscator.login();
//
// result object holds the information about the license
//
// result.demo - is it a demo mode (invalid or empty activation key was used)
// result.license_expiration - license end date (Y-m-d), empty if none
// result.usages_total - total obfuscations for this activation code
// result.string_limit - Max. source code size allowed (it's 1000 bytes for demo mode)
//
if (result !== null) {
console.log("Demo version status - " + (result.demo ? "true" : "false"));
console.log("License expiration - " + result.license_expiration);
console.log("Total obfuscations - " + result.usages_total);
console.log("Max. source code size - " + result.string_limit);
} else {
throw new Error("Something unexpected happen while trying to login to the service.");
}
/******************************************************************************
* Python Obfuscator WebApi interface usage example.
*
* In this example we will verify our activation key status.
*
* Version : v1.0.0
* Language : Rust
* Author : Bartosz Wójcik
* Web page : https://www.pelock.com
*
*****************************************************************************/
use python_obfuscator::{PythonObfuscator, PythonObfuscatorResponse};
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
//
// include Python Obfuscator class
//
//
// if you don't want to use crates.io use a path dependency to this crate
//
// [dependencies]
// python-obfuscator = { path = ".." }
//
// create Python Obfuscator class instance (we are using our activation key)
//
let my_python_obfuscator =
PythonObfuscator::new(Some("ABCD-ABCD-ABCD-ABCD".to_string()));
//
// login to the service
//
let result = my_python_obfuscator.login(true).await;
//
// result object holds the information about the license
//
// result.demo - is it a demo mode (invalid or empty activation key was used)
// result.license_expiration - license end date (Y-m-d), empty if none
// result.usages_total - total obfuscations for this activation code
// result.string_limit - max. source code size allowed (it's 1000 bytes for demo mode)
//
match result {
Some(PythonObfuscatorResponse::Object(obj)) => {
println!(
"Demo version status - {}",
if obj.demo.unwrap_or(false) {
"true"
} else {
"false"
}
);
println!(
"License expiration - {:?}",
obj.license_expiration
);
println!(
"Total obfuscations - {}",
obj.usages_total.unwrap_or(0)
);
println!(
"Max. source code size - {}",
obj.string_limit.unwrap_or(0)
);
}
Some(PythonObfuscatorResponse::Json(_)) => {}
None => {
return Err("Something unexpected happen while trying to login to the service.".into());
}
}
Ok(())
}
/******************************************************************************
* Python Obfuscator WebApi interface usage example.
*
* In this example we will verify our activation key status.
*
* Version : v1.0.0
* Language : C#
* Author : Bartosz Wójcik
* Web page : https://www.pelock.com
*
*****************************************************************************/
using PELock.PythonObfuscator;
//
// create Python Obfuscator class instance (we are using our activation key)
//
var myPythonObfuscator = new PythonObfuscator("ABCD-ABCD-ABCD-ABCD");
//
// login to the service
//
var result = await myPythonObfuscator.LoginAsync();
//
// result object holds the information about the license
//
// result?.Demo - is it a demo mode (invalid or empty activation key was used)
// result?.LicenseExpiration - license end date (Y-m-d), empty if none
// result?.UsagesTotal - total obfuscations for this activation code
// result?.StringLimit - Max. source code size allowed (it's 1000 bytes for demo mode)
//
if (result is not null)
{
Console.WriteLine("Demo version status - " + (result.Demo == true ? "true" : "false"));
Console.WriteLine("License expiration - " + result.LicenseExpiration);
Console.WriteLine("Total obfuscations - " + result.UsagesTotal);
Console.WriteLine("Max. source code size - " + result.StringLimit);
}
else
{
throw new InvalidOperationException("Something unexpected happen while trying to login to the service.");
}
command=obfuscate)Alongside key and source, you may POST compression (boolean). In demo mode, strategy POST fields are ignored; obfuscate always applies integers_to_arrays, mba_binops, and encrypt_strings (1000-character source limit). When not in demo mode, each strategy is a separate boolean POST field (defaults are false unless your client sends true/1/yes):
| Virtualization | |
|---|---|
code_virtualization (vm | fsa | flat, CLI --code-virtualization). Omit this field to skip virtualization. | |
| Protection & renaming | |
self_defending (CLI --self-defending) | protection_linker (CLI --protection-linker, requires self_defending) |
rename_variables | rename_parameters |
rename_functions | rename_function_calls |
shuffle_functions | resolve_constants |
| Strings | |
split_strings | modify_strings |
encrypt_strings | string_char_array_vault |
| Numeric | |
encrypt_integers | mba_binops |
integers_to_floating | encrypt_floating |
integers_to_arrays | floats_to_arrays |
affine_integer_mask | |
| Encrypted array literals | |
array_int_crypt | array_char_crypt |
array_double_crypt | array_string_crypt |
| Decoy value pools | |
insert_random_value_bucket | random_bucket_integers |
random_bucket_arrays | random_bucket_functions |
random_bucket_characters | random_bucket_anti_regex |
random_bucket_autostart | |
| Opaque predicates & noise | |
insert_ternary_operators | complexify_booleans |
opaque_branches | opaque_mixer_chain |
insert_dead_code | try_finally_noise |
| Decoys | |
decoy_functions | lambda_decoys (alias scriptblock_decoys) |
literal_padding | fake_import_markers (alias fake_dot_source_markers) |
dynamic_getattr_calls (alias reflect_invoke_commands) | obfuscate_imports |
callback_registration_stubs (alias event_stub) | |
| Anti-analysis | |
detect_debugger (CLI --detect-debugger) | anti_vm |
anti_sandbox | anti_emulator |
Early probes run at the start of the script and silently terminate on a hit. detect_debugger: sys.gettrace() and Windows IsDebuggerPresent. anti_sandbox: CPU cores fewer than 3, Sandboxie DLLs/registry, Joe Sandbox processes, analysis host/user/path/env. anti_vm: VMware / VirtualBox / Parallels / KVM (processes, files, drivers, BIOS registry, MAC OUI, platform; Linux DMI off Windows). anti_emulator: WINE, Bochs/QEMU, XEN, emulator markers and a timing self-check. Windows checks use the Python standard library only (no WMI). | |
| Other | |
remove_comments | seed (integer, optional) |
randomization_density (integer 0-100, optional) | rename_style (il | o0 | confusable | hex | homoglyph | mangled, optional) |
Legacy field names (scriptblock_decoys, fake_dot_source_markers, reflect_invoke_commands, event_stub) are accepted as backward-compatible aliases and mapped to their primary CLI flags automatically. The server only forwards --remove-comments when at least one strategy is enabled and remove_comments is true.
$result["error"] [out]| Name | Value | Description |
|---|---|---|
| ERROR_SUCCESS | 0 |
Everything went fine. |
| ERROR_INPUT_SIZE | 1 |
Source code size is too big. Most probably you hit the demo mode limitation (1000 characters max.). |
| ERROR_INPUT | 2 |
Malformed or empty source code. |
| ERROR_PARSING | 3 |
Python source code parsing error, check the syntax. |
| ERROR_OBFUSCATION | 4 |
Error while obfuscating the parsed Python code. |
| ERROR_OUTPUT | 5 |
Error while generating obfuscated output code. |
| ERROR_EXEC | 6 |
Could not run the obfuscator engine on the server. |
| ERROR_JSON | 7 |
Invalid or missing JSON response from the obfuscator engine. |
$result["output"] [out, optional]$result["demo"] [out]$result["license_expiration"] [out, optional]Y-m-d), empty if the license does not expire.$result["usages_total"] [out, optional]$result["string_limit"] [out, optional]| PHP Library | PythonObfuscator |
| Python 3 Module | PythonObfuscator |
| JavaScript Module | PythonObfuscator |
| Rust Crate | PythonObfuscator |
| C# / .NET Library | PELock.PythonObfuscator |
Use the Python Obfuscator Decorator package to mark functions and classes that should skip chosen obfuscation strategies. You need it only to run original source. The obfuscator reads @obfuscator.skip from the AST, applies the skip, then strips the decorator and unused import obfuscator lines. Obfuscated output has no runtime dependency on this package.
Import package name: obfuscator. PyPI distribution name: python-obfuscator-decorator.
| Repository | Language | Installation | Package | Sources |
|---|---|---|---|---|
![]() |
Python | Run:
or
|
PyPI | GitHub |
import obfuscator
@obfuscator.skip()
def handshake(secret: str) -> str:
"""Skip every mutating strategy on this function."""
return secret
Also valid:
@obfuscator.skip(obfuscator.ENCRYPT_STRINGS, obfuscator.CODE_VIRTUALIZATION) — skip listed strategies@obfuscator.skip("encrypt_strings") — string keys match engine strategy names@obfuscator.skip (bare, no call) — skip every mutating strategy on that constructimport obfuscator as alias then @alias.skip(...)CODE_VIRTUALIZATION skips all virtualization modes (VM, FSA, flatten) on that function or class. Shipped scripts do not import obfuscator — markers are removed from the emitted source.
If you would like to ask about Python Obfuscator, or something is not clear, mail us. We are happy to answer your questions.