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

, , ,
About — I'm an enthusiastic software engineer and consultant interested in many fields including J2EE, programming, electronics, 3D printing, video games, wood working and gardening.
See my Resume for more information.
The views expressed in this blog are my own and not those of my employer.
comments powered by Disqus
My other posts you may like...
Programming, DIY, Games, Hacks, Tech and more.
Follow me on...
Current and Past Projects
See my Resume

Subscribe


RSS Feed

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

Recent Blog Posts

Using Jersey 2.x as a shared library on WebLogic 12.1.2

Google DFP with AdSense fallback is causing infinite scroll pages to go haywire

Workaround for Mobile Safari scrollTop() not updating during scroll

Skipping execution of Maven plugins that do not have a native skip option

Unmarshalling an XML fragment representing a JAXB object without XmlRootElement

Injecting a ContainerRequestContext into a Jersey entity provider class

Obfuscating PHP source code with Maven and YAK Pro PO

Making use of corner shelves with easy to make slide out draws

Octotree breaks GitLab Issue Boards

Compiling the FHIR schema with XJC

Recent Galleries

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

Good Friday Electronics fun Easter Bunny LED PCB Kit IBEABU-01.0

Top Categories

Blogs I follow

Matt Moores Blog
Georgi's FlatPress Guide
Perplexing Permutations
The Security Sleuth

Friends

RAWS Parts Online
Alpha Dimensions Hosting
Kristensen Photography
Ilia Rogatchevski
Travelling Fairy

Blog Activity

Blog Activity
Follow me on... 
     
...or subscribe for updates!

Don't show this again