### Yakpro-PO Configuration for External Libraries (PHP) Source: https://github.com/pk-fr/yakpro-po/blob/master/README.md This section provides PHP code examples for configuring Yakpro-PO to handle external libraries. It demonstrates how to disable obfuscation for functions, classes, properties, and methods by modifying the `yakpro-po.cnf` configuration file or by explicitly listing ignored elements. ```php $conf->obfuscate_function_name = false; $conf->t_ignore_functions = array('my_func1','my_func2'); ``` ```php $conf->obfuscate_class_name = false; $conf->obfuscate_property_name = false; $conf->obfuscate_method_name = false; $conf->t_ignore_classes = array(...); $conf->t_ignore_properties = array(...); $conf->t_ignore_methods = array(...); ``` -------------------------------- ### Adjust Stack Limit for PHP Segmentation Faults Source: https://github.com/pk-fr/yakpro-po/blob/master/README.md A segmentation fault can occur in PHP's garbage collector when obfuscating many large files. This can be resolved by increasing the stack limit using the `ulimit -s` command. For example, change it to `ulimit -s 102400`. ```bash ulimit -s ``` ```bash ulimit -s 102400 ``` -------------------------------- ### PHP PDO Fetch Mode Recommendation Source: https://github.com/pk-fr/yakpro-po/blob/master/README.md It is recommended to use `PDO::FETCH_ASSOC` instead of `PDO::FETCH_OBJ` when working with PDO to avoid potential issues with obfuscation. Alternatively, disable properties obfuscation in the configuration file. ```php PDO::FETCH_OBJ ``` ```php PDO::FETCH_ASSOC ``` -------------------------------- ### Yakpro-PO Command Line Options for Obfuscation Control Source: https://github.com/pk-fr/yakpro-po/blob/master/README.md These command-line options allow granular control over the obfuscation process. They can be used to enable or disable obfuscation for specific code elements like variable names, function names, class names, and more. Some options also control output formatting and scrambling behavior. ```bash --silent do not display Information level messages. --debug (internal debugging use) displays the syntax tree. -s or --no-strip-indentation multi line output --strip-indentation single line output --no-shuffle-statements do not shuffle statements --shuffle-statements shuffle statements --no-obfuscate-string-literal do not obfuscate string literals --obfuscate-string-literal obfuscate string literals --no-obfuscate-loop-statement do not obfuscate loop statements --obfuscate-loop-statement obfuscate loop statements --no-obfuscate-if-statement do not obfuscate if statements --obfuscate-if-statement obfuscate if statements --no-obfuscate-constant-name do not obfuscate constant names --obfuscate-constant-name obfuscate constant names --no-obfuscate-variable-name do not obfuscate variable names --obfuscate-variable-name obfuscate variable names --no-obfuscate-function-name do not obfuscate function names --obfuscate-function-name obfuscate function names --no-obfuscate-class_constant-name do not obfuscate class constant names --obfuscate-class_constant-name obfuscate class constant names --no-obfuscate-class-name do not obfuscate class names --obfuscate-class-name obfuscate class names --no-obfuscate-interface-name do not obfuscate interface names --obfuscate-interface-name obfuscate interface names --no-obfuscate-trait-name do not obfuscate trait names --obfuscate-trait-name obfuscate trait names --no-obfuscate-property-name do not obfuscate property names --obfuscate-property-name obfuscate property names --no-obfuscate-method-name do not obfuscate method names --obfuscate-method-name obfuscate method names --no-obfuscate-namespace-name do not obfuscate namespace names --obfuscate-namespace-name obfuscate namespace names --no-obfuscate-label-name do not obfuscate label names --obfuscate-label-name obfuscate label names ``` -------------------------------- ### Yakpro-PO Scramble and Debugging Options Source: https://github.com/pk-fr/yakpro-po/blob/master/README.md These options control the scrambling mode and length for obfuscated code, and provide a way to retrieve original symbol names from the obfuscation context. The `--whatis` option is particularly useful for debugging obfuscated code. ```bash --scramble-mode identifier|hexa|numeric force scramble mode --scramble-length length ( min=2; max = 16 for scramble_mode=identifier, max = 32 for scramble_mode = hexa or numeric) --whatis scrambled_name retrieves original symbol from obfuscation context. (usefull for debugging your code when you give away obfuscated code, and keep the same obfuscation context). Tip: do not include the $ symbol, or use \$ because $ has special meaning in shell. -h or --help displays help. ``` -------------------------------- ### Basic File Obfuscation with YAK Pro CLI Source: https://context7.com/pk-fr/yakpro-po/llms.txt Obfuscates a single PHP file using the YAK Pro command-line interface, outputting the result to standard output or a specified file. This is useful for quick obfuscation of individual scripts. ```bash # Obfuscate to stdout yakpro-po source.php # Obfuscate to specific output file yakpro-po source.php -o obfuscated.php # Example with sample PHP file echo '' > test.php yakpro-po test.php -o test_obfuscated.php # Result: All variable names, function names scrambled, whitespace removed # Output will look like: ``` -------------------------------- ### Directory Obfuscation with YAK Pro CLI Source: https://context7.com/pk-fr/yakpro-po/llms.txt Recursively obfuscates an entire directory structure using YAK Pro's command-line interface. It supports timestamp-based incremental processing, ensuring only changed files are re-obfuscated. Includes options for cleaning output and defining custom configurations. ```bash # Obfuscate entire project directory yakpro-po /path/to/source -o /path/to/target # Creates target/yakpro-po/obfuscated with processed files # Only re-obfuscates files modified since last run # Clean obfuscated output before fresh obfuscation yakpro-po --clean --config-file project.cnf # Example workflow mkdir my_project echo ' my_project/db.php echo ' my_project/user.php yakpro-po my_project -o output_dir # Result: output_dir/yakpro-po/obfuscated/ contains scrambled versions # Context saved in output_dir/yakpro-po/context/ for consistent renaming ``` -------------------------------- ### YAK Pro PHP Configuration for Obfuscation Control Source: https://context7.com/pk-fr/yakpro-po/llms.txt A PHP configuration file used with YAK Pro to control various obfuscation behaviors. It allows fine-grained control over name scrambling, feature enablement, statement shuffling, and directory processing. ```php scramble_mode = 'identifier'; // 'identifier', 'hexa', or 'numeric' $conf->scramble_length = 5; // Length of scrambled names (2-16 for identifier) // Enable/disable obfuscation features $conf->obfuscate_variable_name = true; $conf->obfuscate_function_name = true; $conf->obfuscate_class_name = true; $conf->obfuscate_method_name = true; $conf->obfuscate_property_name = true; $conf->obfuscate_constant_name = true; $conf->obfuscate_string_literal = true; $conf->obfuscate_if_statement = true; $conf->obfuscate_loop_statement = true; // Statement shuffling for control flow obfuscation $conf->shuffle_stmts = true; $conf->shuffle_stmts_min_chunk_size = 1; $conf->shuffle_stmts_chunk_mode = 'fixed'; // 'fixed' or 'ratio' $conf->shuffle_stmts_chunk_ratio = 20; // Output formatting $conf->strip_indentation = true; // Single-line output // Ignore specific names (won't be obfuscated) $conf->t_ignore_functions = array('myPublicAPI', 'webhook_handler'); $conf->t_ignore_classes = array('PublicInterface', 'PluginBase'); $conf->t_ignore_variables = array('wpdb', 'post'); // Ignore by prefix $conf->t_ignore_functions_prefix = array('wp_', 'public_'); $conf->t_ignore_classes_prefix = array('WP_', 'Public'); // Handle pre-defined PHP classes $conf->t_ignore_pre_defined_classes = 'all'; // 'all', 'none', or array of class names // Directory processing $conf->source_directory = '/path/to/source'; $conf->target_directory = '/path/to/target'; $conf->t_skip = array('vendor', 'tests', '.git'); // Skip these directories $conf->t_keep = array('config/public.php'); // Keep unobfuscated // Example: Obfuscate with custom config // Save above as myproject.cnf, then run: // yakpro-po --config-file myproject.cnf ?> ``` -------------------------------- ### Name Lookup for Debugging Obfuscated Code with YAK Pro CLI Source: https://context7.com/pk-fr/yakpro-po/llms.txt Uses the YAK Pro command-line interface to perform a reverse lookup of scrambled names to their original identifiers. This is essential for debugging obfuscated PHP code, requiring a configuration file that preserves the mapping. ```bash # Look up what a scrambled name originally was yakpro-po --whatis a1b2c3 --config-file project.cnf # Example workflow: # 1. Obfuscate project with context preservation yakpro-po src/ -o dist/ ``` -------------------------------- ### YakPro-PO: Selective Obfuscation Command Line Flags Source: https://context7.com/pk-fr/yakpro-po/llms.txt Control specific obfuscation behaviors using command-line flags. This allows fine-tuning the obfuscation process to preserve certain elements or disable specific transformations. ```bash # Preserve function names but obfuscate variables yakpro-po source.php -o output.php --no-obfuscate-function-name --obfuscate-variable-name ``` ```bash # Keep code readable (multi-line) but scramble names yakpro-po source.php -o output.php --no-strip-indentation -s ``` ```bash # Disable statement shuffling for performance yakpro-po source.php -o output.php --no-shuffle-statements ``` ```bash # Disable string literal obfuscation to avoid encoding issues yakpro-po source.php -o output.php --no-obfuscate-string-literal ``` ```bash # Example: WordPress plugin obfuscation (preserve hook compatibility) yakpro-po wp-plugin.php -o wp-plugin-obf.php \ --no-obfuscate-function-name \ --no-obfuscate-class-name \ --obfuscate-variable-name \ --obfuscate-method-name ``` ```bash # Result: Public API preserved, internal logic obfuscated ``` -------------------------------- ### YakPro-PO: Identify Code Elements Source: https://context7.com/pk-fr/yakpro-po/llms.txt Use the `yakpro-po --whatis` command to identify the type and original name of code elements such as functions, variables, and methods. This is useful for debugging or understanding obfuscated code. ```bash yakpro-po --whatis f4e8a2 --config-file project.cnf # Output: function: calculateTotalPrice ``` ```bash # For variables (omit $ or escape it) yakpro-po --whatis v7x3p9 # Output: variable: $userAuthentication ``` ```bash # For methods yakpro-po --whatis m2k5j8 # Output: method: validateInput ``` -------------------------------- ### Core PHP Function: obfuscate() Source: https://context7.com/pk-fr/yakpro-po/llms.txt The `obfuscate()` function processes a given PHP file, parses its Abstract Syntax Tree (AST), applies various obfuscation techniques like name scrambling and statement shuffling, and returns the obfuscated code as a string. It requires external configuration and parser objects. ```php parse($source); // Traverse and transform AST (scramble names, obfuscate control flow) $stmts = $traverser->traverse($stmts); // Shuffle statements if enabled if ($conf->shuffle_stmts && (count($stmts) > 2)) { $last_inst = array_pop($stmts); $stmts = shuffle_statements($stmts); $stmts[] = $last_inst; } // Generate obfuscated code from modified AST $code = $prettyPrinter->prettyPrintFile($stmts); // Strip whitespace if configured if ($conf->strip_indentation) { $code = remove_whitespaces($code); } return trim($code); } // Example usage in custom script: require_once 'include/functions.php'; require_once 'include/classes/config.php'; require_once 'include/classes/scrambler.php'; $conf = new Config(); $conf->obfuscate_variable_name = true; $conf->strip_indentation = true; $obfuscated = obfuscate('/path/to/source.php'); file_put_contents('/path/to/output.php', $obfuscated); ?> ``` -------------------------------- ### Obfuscate Directory Recursively (PHP) Source: https://context7.com/pk-fr/yakpro-po/llms.txt Recursively traverses a source directory, obfuscating files based on timestamp differences and configuration settings. It skips specified directories and files, handles symbolic links, and preserves metadata. Dependencies include a `Config` object and an `obfuscate` function. ```php t_skip)) continue; // Handle symbolic links if (!$conf->follow_symlinks && is_link($source_path)) { symlink(readlink($source_path), $target_path); continue; } // Recursively process directories if (is_dir($source_path)) { if (!file_exists($target_path)) mkdir($target_path, 0777, true); $new_keep = in_array($source_path, $conf->t_keep) ? true : $keep_mode; obfuscate_directory($source_path, $target_path, $new_keep); continue; } // Process files based on timestamp and configuration if (is_file($source_path)) { $source_stat = lstat($source_path); $target_stat = @lstat($target_path); // Skip if target is newer than source if ($target_stat && ($source_stat['mtime'] <= $target_stat['mtime'])) { continue; } $extension = pathinfo($source_path, PATHINFO_EXTENSION); $keep = $keep_mode || in_array($source_path, $conf->t_keep) || !in_array($extension, $conf->t_obfuscate_php_extension); if ($keep) { file_put_contents($target_path, file_get_contents($source_path)); } else { $obfuscated_str = obfuscate($source_path); // Assuming obfuscate() is defined elsewhere file_put_contents($target_path, $obfuscated_str . PHP_EOL); } // Preserve file metadata touch($target_path, $source_stat['mtime']); chmod($target_path, $source_stat['mode']); } } closedir($dp); } // Example: Custom obfuscation script class Config { public $t_skip = []; public $t_keep = []; public $follow_symlinks = false; public $t_obfuscate_php_extension = ['php']; } function create_context_directories($dir) { // Placeholder for directory creation logic if (!is_dir($dir)) { mkdir($dir, 0777, true); } } function obfuscate($filePath) { // Placeholder for actual obfuscation logic return "Obfuscated content of " . basename($filePath); } $conf = new Config(); $conf->source_directory = '/var/www/myapp'; $conf->target_directory = '/var/www/dist'; $conf->t_skip = array('/var/www/myapp/vendor', '/var/www/myapp/tests'); $conf->t_keep = array('/var/www/myapp/config/routes.php'); create_context_directories($conf->target_directory); obfuscate_directory($conf->source_directory, "{$conf->target_directory}/yakpro-po/obfuscated"); ?> ``` -------------------------------- ### PHP Define Function Usage for Constants Source: https://github.com/pk-fr/yakpro-po/blob/master/README.md When using the `define` function for constants in PHP, ensure it has exactly two arguments and the first argument is a literal string. For any other usage, disable constants obfuscation in the configuration file. The `const MY_CONST = something;` form is not affected. ```php define('MY_CONSTANT', 'value'); ``` ```php const MY_CONST = 'value'; ``` -------------------------------- ### Core Function: shuffle_statements() - PHP Source: https://context7.com/pk-fr/yakpro-po/llms.txt Implements control flow obfuscation by breaking PHP code into chunks, assigning goto labels, shuffling these chunks, and reassembling them. This function takes an array of statements as input and returns a modified array of statements with obfuscated control flow. It relies on global configurations and a scrambler object for label generation. ```php shuffle_stmts) return $stmts; $chunk_size = shuffle_get_chunk_size($stmts); $n = count($stmts); if ($n < (2 * $chunk_size)) return $stmts; $scrambler = $t_scrambler['label']; $label_name_prev = $scrambler->scramble($scrambler->generate_label_name()); $first_goto = new PhpParser\Node\Stmt\Goto_($label_name_prev); $chunks = array(); $current_chunk = array(); // Break statements into chunks for ($i = 0; $i < $n; $i++) { $current_chunk[] = $stmts[$i]; if (count($current_chunk) >= $chunk_size) { $label = array(new PhpParser\Node\Stmt\Label($label_name_prev)); $label_name = $scrambler->scramble($scrambler->generate_label_name()); $goto = array(new PhpParser\Node\Stmt\Goto_($label_name)); // Create chunk: label + statements + goto $chunks[] = array_merge($label, $current_chunk, $goto); $label_name_prev = $label_name; $current_chunk = array(); } } // Handle remaining statements if (count($current_chunk) > 0) { $label = array(new PhpParser\Node\Stmt\Label($label_name_prev)); $label_name = $scrambler->scramble($scrambler->generate_label_name()); $goto = array(new PhpParser\Node\Stmt\Goto_($label_name)); $chunks[] = array_merge($label, $current_chunk, $goto); $label_name_prev = $label_name; } $last_label = new PhpParser\Node\Stmt\Label($label_name); // Shuffle chunks randomly shuffle($chunks); // Reassemble: first_goto + shuffled_chunks + last_label $result = array($first_goto); foreach ($chunks as $chunk) { foreach ($chunk as $stmt) { $result[] = $stmt; } } $result[] = $last_label; return $result; } function shuffle_get_chunk_size(&$stmts) { global $conf; $n = count($stmts); switch ($conf->shuffle_stmts_chunk_mode) { case 'ratio': $chunk_size = floor($n / $conf->shuffle_stmts_chunk_ratio); if ($chunk_size < $conf->shuffle_stmts_min_chunk_size) { $chunk_size = $conf->shuffle_stmts_min_chunk_size; } break; case 'fixed': default: $chunk_size = $conf->shuffle_stmts_min_chunk_size; } return $chunk_size; } // Example transformation: // Original code: // $a = 1; // $b = 2; // $c = 3; // echo $a + $b + $c; // // After shuffle_statements() with chunk_size=1: // goto L4k8; // L9m2: $b = 2; goto L6p3; // L4k8: $a = 1; goto L9m2; // L7x1: echo $a + $b + $c; goto L2n5; // L6p3: $c = 3; goto L7x1; // L2n5: // // Same functionality, randomized execution order ?> ``` -------------------------------- ### Configure Statement Shuffling in yakpro-po Source: https://github.com/pk-fr/yakpro-po/blob/master/README.md The `$conf->shuffle_stmts` option in yakpro-po controls statement shuffling obfuscation. It is true by default. If performance issues arise, set this to false or tune associated shuffle parameters like chunk size. ```php $conf->shuffle_stmts = true; ``` ```php $conf->shuffle_stmts = false; ``` -------------------------------- ### PHP Scrambler Class for Name Obfuscation Source: https://context7.com/pk-fr/yakpro-po/llms.txt The Scrambler class in PHP is designed to generate scrambled names for identifiers. It manages internal translation tables to map original names to scrambled ones and vice-versa, ensuring consistency and preventing collisions. It can load and save its context to persist naming schemes across different executions. Dependencies include a Config class and file system access for context persistence. ```php scramble_type = $type; $this->scramble_mode = $conf->scramble_mode; $this->scramble_length = $conf->scramble_length; $this->t_ignore = array_flip($this->t_reserved_function_names); if ($target_directory && file_exists("{$target_directory}/yakpro-po/context/{$type}")) { $context = unserialize(file_get_contents("{$target_directory}/yakpro-po/context/{$type}")); $this->t_scramble = $context[1]; $this->t_rscramble = $context[2]; $this->scramble_length = $context[3]; } } public function scramble($name) { $key = $this->case_sensitive ? $name : strtolower($name); if (array_key_exists($key, $this->t_ignore)) return $name; if (isset($this->t_scramble[$key])) { return $this->t_scramble[$key]; } for ($i = 0; $i < 50; $i++) { $scrambled = $this->str_scramble($name); $normalized = strtolower($scrambled); if (!isset($this->t_rscramble[$normalized]) && !isset($this->t_ignore[$normalized])) { $this->t_scramble[$key] = $scrambled; $this->t_rscramble[$normalized] = $key; return $scrambled; } if ($i == 5 && $this->scramble_length < $this->scramble_length_max) { $this->scramble_length++; } } fprintf(STDERR, "Scramble Error: Could not generate unique name after 50 attempts\n"); exit(2); } public function unscramble($scrambled_name) { $key = $this->case_sensitive ? $scrambled_name : strtolower($scrambled_name); return isset($this->t_rscramble[$key]) ? $this->t_rscramble[$key] : ''; } private function str_scramble($s) { $first_char = $this->t_first_chars[mt_rand(0, $this->l1)]; $this->r = str_shuffle(md5($s . md5($this->r))); $result = $first_char; switch ($this->scramble_mode) { case 'numeric': for ($i = 0; $i < $this->scramble_length - 1; $i++) { $result .= $this->t_chars[base_convert(substr($this->r, $i, 2), 16, 10) % ($this->l2 + 1)]; } break; case 'hexa': $result .= substr($this->r, 0, $this->scramble_length - 1); break; case 'identifier': default: for ($i = 0; $i < $this->scramble_length - 1; $i++) { $result .= $this->t_chars[base_convert(substr($this->r, 2*$i, 2), 16, 10) % ($this->l2 + 1)]; } } return $result; } public function __destruct() { if (isset($this->context_directory)) { $context = array( self::SCRAMBLER_CONTEXT_VERSION, $this->t_scramble, $this->t_rscramble, $this->scramble_length, $this->label_counter ); file_put_contents( "{$this->context_directory}/yakpro-po/context/{$this->scramble_type}", serialize($context) ); } } } // Example: Using Scrambler directly $conf = new Config(); $conf->scramble_mode = 'identifier'; $conf->scramble_length = 6; $conf->t_ignore_functions = array('main', 'init'); $scrambler = new Scrambler('function', $conf, '/tmp/project'); echo $scrambler->scramble('getUserData'); echo $scrambler->scramble('calculateTotal'); echo $scrambler->scramble('main'); echo $scrambler->scramble('getUserData'); // Reverse lookup ``` -------------------------------- ### Avoid Indirect Function Calls in PHP Source: https://github.com/pk-fr/yakpro-po/blob/master/README.md When obfuscating functions in PHP, avoid indirect function calls. If indirect calls are necessary, list the function names in the `$conf->t_ignore_functions` array to prevent obfuscation issues. ```php $my_var = 'my_function'; $my_var(); ``` -------------------------------- ### Avoid Indirect Variable Names in PHP Source: https://github.com/pk-fr/yakpro-po/blob/master/README.md Do not use indirect variable names in PHP when obfuscating. If indirect variable usage is required, add the variable names to the `$conf->t_ignore_variables` array to avoid conflicts. ```php $$my_var = something; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.