缩小/混淆PHP代码 [英] Minify / Obfuscate PHP Code

查看:82
本文介绍了缩小/混淆PHP代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 Haxe 生成PHP代码. (这意味着您用Haxe语言编写代码,并在编译后得到一堆php文件.)今天,一位客户告诉我,他需要使用Haxe进行的旧项目中的一项新功能.他还告诉我,他根据自己的需要更改了代码上的一些小内容.现在,我首先将他的更改移植到我的Haxe代码中,然后添加新功能,因为否则,下次我编译该项目时,他的更改将被覆盖.

为防止再次发生这种情况,我正在寻找某种程序来减少/混淆PHP代码.目的是使代码尽可能不可读/不可编辑.
理想的工具可以在Linux下运行,并且可以处理整个文件夹以及所有包含文件的文件.

有人有建议吗?

解决方案

我同意这一评论,您的所作所为非常卑鄙,但是在这家公司工作10年后,我可以证明一件事:获得的代码一半如此令人费解,它可能也已被缩小,而实际上函数/变量名通常是完全任意的,我编辑了缩小的js,与未简化的代码相比,这没有什么麻烦.

我找不到任何这样的脚本/程序,最有可能的原因是,这与PHP的精神背道而驰,甚至有所欠缺.

首先:Php对空格不敏感,因此第一步是删除字符串之外的所有换行符和空白.

对于普通的修补匠来说,这将很困难,一个中级程序员只会找到并替换所有; {}为$ 1 \ n或类似的东西.

下一步将是get_defined_functions并保存该数组(返回数组中的用户"键),您需要包括所有文件才能执行此操作.

如果是oo代码,则还需要get_defined_classes.保存该数组.

从本质上讲,您需要获取变量,方法和类实例,必须在其上实例化该类和get_object_vars,并且可以四处看看,还可以看到很多其他信息,例如Constants和类var等.

然后,您获取这些列表,遍历它们,为每件事创建一个唯一的名称,然后preg_replace或str_replace该名称在所有文件中.

确保在测试副本上执行此操作,然后查看遇到的错误.

不过,为了清楚起见,在地狱中有一个特殊的地方,专为因混淆而混淆的人使用.

签出: get_defined_functions get_declared_classes ,只需点击周围的链接即可查看您可以做什么. /p>

I use Haxe to generate PHP code. (This means you write you code in the Haxe language and get a bunch of php files after compiling.) Today a customer told me that he needs a new feature on a old project made with Haxe. He also told me that he altered some small things on the code for his own needs. Now I first have port his changes to my Haxe code and then add the new feature, because otherwise his changes will be overwritten by the next time I compile the project.

To prevent that this happens again I am looking for some kind of program that minifies / obfuscates the PHP code. The goal is to make the code unreadable / uneditable as possible.
The ideal tool would run under Linux and could process whole folders and all it containing files.

Anybody any suggestions?

解决方案

I agree with the comment, what you are doing is very underhanded, but after 10 years in this biz I can attest to one thing: Half the code you get is so convoluted it might as well have been minified, and really function/var names are so often completely arbitrary, i've edited minified js and it wasn't much more of a hassle than some unminified code.

I couldn't find any such script/program, most likely because this is kind of against the PHP spirit and a bit underhanded, never the less.

First: Php isn't white space sensitive, so step one is to remove all newlines and whitespace outside of string.

That would make it difficult to mess with for the average tinkerer, an intermediate programmer would just find and replace all ;{} with $1\n or something to that effect.

The next step would be to get_defined_functions and save that array (The 'user' key in the returned array), you'll need to include all of the files to do this.

If it's oo code, you'll need get_defined_classes as well. Save that array.

Essentially, you need to get the variables, methods, and class instances, you'll have to instantiate the class and get_object_vars on it, and you can poke around and see that you can get alot of other info, like Constants and class vars etc.

Then you take those lists, loop through them, create a unique name for each thing, and then preg_replace, or str_replace that in all of the files.

Make sure you do this on a test copy, and see what errors you get.

Though, just to be clear, there is a special place in hell reserved for people who obfuscate for obfuscation's sake.

Check out: get_defined_functions get_declared_classes and just follow the links around to see what you can do.

这篇关于缩小/混淆PHP代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆