PHP code example of pelock / python-obfuscator

1. Go to this page and download the library: Download pelock/python-obfuscator library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

pelock / python-obfuscator example snippets


use PELock\PythonObfuscator;





/******************************************************************************
 * 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
 *
 *****************************************************************************/

//
// )
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"]          - demo mode (empty/invalid key); strategy flags ignored; always integers_to_arrays, mba_binops, encrypt_strings (no virt; 1000 char limit)
// $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.");
}




/******************************************************************************
 * Python Obfuscator WebApi interface usage example.
 *
 * In this example we will obfuscate sample source with every public option
 * set, so you can see the full client surface and turn flags on or off.
 *
 * 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;
use PELock\PythonObfuscator\RenameStyle;

//
// 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;

//
// globals
//
// fixed random seed for reproducible obfuscation output (optional)
//
$myPythonObfuscator->seed = null;

//
// randomization density / intensity (0-100)
//
$myPythonObfuscator->randomizationDensity = null;

//
// identifier renaming style: RenameStyle::Il, O0, Confusable, Hex, Homoglyph, or Mangled
//
$myPythonObfuscator->renameStyle = RenameStyle::Il;

//
// code virtualization (exactly one): VM, FSA, or FLAT
// set to null to skip virtualization
//
$myPythonObfuscator->codeVirtualization = CodeVirtualization::VM;

//
// protection (opt-in on the service for --all; shown enabled here so every flag is visible)
//
// protection against tampering with protected code (integrity verification)
//
$myPythonObfuscator->selfDefending = true;

//
// protection linker (decoy call graph; h
//
$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;

//
// encrypted array literals
//
// 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;

//
// decoy value pools
//
// 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;

//
// opaque predicates & noise
//
// 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;

//
// decoys
//
// 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;

//
// other
//
// 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"]          - demo mode (empty/invalid key); strategy flags ignored; always integers_to_arrays, mba_binops, encrypt_strings (no virt; 1000 char limit)
// $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.");
}




/******************************************************************************
 * 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
 *
 *****************************************************************************/

//
// //
// $result["demo"]          - demo mode (empty/invalid key); strategy flags ignored; always integers_to_arrays, mba_binops, encrypt_strings (no virt; 1000 char limit)
// $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.");
}