Igor's Blog

I'm very close to being able to release a PHP project that I've been working on and started looking at code obfuscation to make it a little bit more difficult for anyone looking to take my code and run with it. I looked at YAK Pro PHP Obfuscator for this purpose and liked how easy it was to configure and use. However, I wanted it to work with Maven since I already use that to minify my JavaScript.

With a bit of pushing and prodding I got YAK Pro PO working with Maven, here's how. Below is the basic layout for the project directory structure, the main directory is where all PHP source code is. That directory can have sub-directories too. The resources directory contains my yakpro-po.cnf file, which holds configuration for YAK Pro PO. The target directory is where the context and obfuscated files will appear.
 Project Structure
project_dir/
\_ src/
| \_ main/
| | \_ ...
| | \_ <php files>
| | \_ ...
| \_ resources/
| \_ yakpro-po.cnf
\_ target/
| \_ yakpro-po/
| \_ context/
| \_ obfuscated/
\_ pom.xml


Before I got started, I had to clone YAK Pro PO from Git, and get the PHP-Parser that it relies on. That is done via the following commands:
 Terminal Commands
git clone https://github.com/pk-fr/yakpro-po.git
cd yakpro-po
git clone --branch=1.x https://github.com/nikic/PHP-Parser.git


Then I had to add some properties to my pom.xml file as below. Adjust the path to the php executable and the path to where you cloned YAK Pro PO.
 POM Properties
<properties>
<php_exec>/path/to/php</php_exec>
<yakpro_bin>/path/to/yakpro-po/yakpro-po.php</yakpro_bin>
<yakpro_conf_dir>${basedir}/src/resources</yakpro_conf_dir>
</properties>




To run YAK Pro PO I used the exec-maven-plugin and configured it with the properties from above as well as assumed directories from the project directory structure outlined at the start of this article. This is what the plugin configuration looks like...
 Plugin Configuration
<plugin>
<groupId>org.codehaus.mojo</groupId>
<artifactId>exec-maven-plugin</artifactId>
<version>1.6.0</version>
<executions>
<execution>
<id>exec-yakpro</id>
<phase>compile</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${php_exec}</executable>
<workingDirectory>${yakpro_conf_dir}</workingDirectory>
<arguments>
<argument>${yakpro_bin}</argument>
<argument>${basedir}/src/main</argument>
<argument>-o</argument>
<argument>${basedir}/target</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>


Then to run, I just need to do:
 Terminal Commands
mvn clean compile


I have a few more plugins configured in my particular setup that takes these obfuscated files and packages them in a distribution ZIP as well as deploys the code to my web test server, but that's outside the scope of this article.

Don't forget to adjust the configuration file for your needs. The default didn't work for me and I had to tweak settings until I got output that was obfuscated but would still run as usual.

-i

comments powered by Disqus
Other posts you may like...
Programming, DIY, Games, Hacks, and Tech

Recent Blog Posts

A guide for plotting your hard drive for Burstcoin mining on a Mac using mjminer

Replacing a broken hard drive in a Samsung Story Station

Fix Java applications slow start and net connection times on macOS sierra

Pierre Cardin Leather Computer Bag (PC2278)

How to stop SSH remote host disconnecting your session

Using PayPal PHP SDK on Google App Engine

Use the Touch Bar to lock your Mac with a single button press

Multi module builds with Maven 3.5 and the parent-child pom version management

Google App Engine local dev server DataStore becoming corrupted after a bad GQL statement is run

Unboxing my new 2017 2.9Ghz 15" MacBook Pro

Recent Galleries

Monument Valley 2 is released and does not disappoint

Space Food - Chocolate Ice Cream with Chocolate Chips

Legeod Star Wars AT-DP kit

DIY spare parts computer build with a RAIDMAX Anura case

Fake 'Lepin' brand Lego packaging

Hardwood garden bench with clear resin void filler

Fixing a 3D printer extruder that stopped heating up

Easily increase disk space in a Lenovo Ideapad 100S 14" laptop with an M.2 SSD

Making a multi-piece 3D printed solder spool holder stand

DIY indoor apartment grow light wiring

My Other Web Sites

Igor and Elise's Travels
Riverside Expressway Cam
300 George St Blogumentary

My Online Tools

UUID to OID Converter
Guru JSON-RPC Tester
Extrudifier Object Designer
Travel ┬ÁBlog

Blogs and Friends

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Don't feel obliged, but you could follow me for more great content!
     
Don't show this again