简体   繁体   English

将PHP文件转换为二进制文件

[英]Convert PHP file to binary

是否可以将PHP文件转换为二进制文件并将其部署在Web服务器上?

Since PHP is a (relatively)portable language, compiling PHP source to bytecode instead of binary code is more preferable. 由于PHP是一种(相对)可移植语言,因此更优选将PHP源代码编译为字节码而不是二进制代码。 For this purpose there is an experimental project called bcompiler . 为此目的,有一个名为bcompiler的实验项目。

Some months ago I searched for it (php code protection or script protection) and my results were: 几个月前我搜索它(PHP代码保护或脚本保护),我的结果是:

I provide some description but try to google them and pardon me. 我提供了一些描述,但试着谷歌他们并原谅我。

Be careful with your search because you may encounter to php compressors instead and compressors are just about GZIP and other http transfer compression mechanisms. 请小心你的搜索,因为你可能会遇到php压缩器而压缩器只是关于GZIP和其他http传输压缩机制。

The most important issues with php script protecting tools are: php脚本保护工具最重要的问题是:

  1. How much speed of php runtime performance will get low(down)(how much speed down) php运行时性能的速度会降低多少(下降)(速度下降多少)

  2. Will we need an extra environment or installed tools on the php server? 我们需要一个额外的环境或php服务器上安装的工具吗?

  3. Easy handling 易于处理

You will find about whole description and comparison on: http://www.seocompany.ca/software/free-encryption-software.html 您将在以下网址找到有关完整描述和比较的信息: http//www.seocompany.ca/software/free-encryption-software.html

Obfuscators 混淆器

A lot of obfuscators you will find on the web but there's no guarantee for your codes to work. 您可以在网上找到很多混淆器,但无法保证您的代码能够正常工作。

Even I found a mixed way with Visual C++ and MSVS for obfuscating php and because also I'm experienced with asp.net I tested it however didn't work. 即使我发现使用Visual C++MSVS来混淆php的混合方式,因为我对asp.net也很有经验,但我测试了它但是没有用。

Converters and Lockers 转换器和储物柜

  • ion protector ( http://www.ioncube.com/ ): Oh not free but I heard many about his famous name 离子保护器http://www.ioncube.com/ ):哦,不是免费的,但我听到很多关于他的名字

  • phc (php compiler) : free and was a good case but "Brendan Long" said the truth because phc has a painful install way. phc(php编译器) :免费并且是一个很好的案例,但“Brendan Long”说实话,因为phc有一个痛苦的安装方式。 However result is magic and has famous name such as ion 但是结果是神奇的,并且有离子等的名称

  • php locker : I got it and test it. php locker :我得到了它并测试它。 It had error with compiled code and it's released for lower than php5. 它有编译代码的错误,它的发布低于php5。 Absolutely not free and for who thinking about ccr-ac*ks finding it for php locker is impossible. 绝对不是免费的,谁想到ccr-ac * ks找到它的php锁定是不可能的。

  • Zend Guard : A perfect way to guard but it's harder than phc or ion because you need Zend runtime environment (ZRE) on your server and Zend Guard is absolutely non-free however if you are a Zend guy (zend framework+zend IDE+zend Guard) you should know Zend Guard is compatible with zend IDE and code blocking process will be so easy. Zend Guard :一种完美的防范方式,但它比phc或ion更难,因为你的服务器上需要Zend运行时环境(ZRE),Zend Guard绝对不是免费的,但如果你是Zend家伙(zend framework + zend IDE + zend) Guard)您应该知道Zend Guard与zend IDE兼容并且代码阻塞过程将非常简单。 I'm not a Zend guy because either of zend framework and zend guard get down runtime speed obviously. 我不是Zend的人,因为zend框架和zend guard都明显地降低了运行时速度。 I love php speeded runtime. 我喜欢php speeded运行时。

  • php -> C/C++ compiling (YES IT'S POSSIBLE) (BEST PERFORMANCE THROUGH THE WORLD): It's not so famous so it's normal if no one talked about. php -> C/C++ compiling (是的可能)(通过世界的最佳表现):它不是那么有名,所以没有人谈论这是正常的。

  • facebook hiphop : This tool is using by facebook to compile php files on c++/c for getting a better performance however finally we have unreadable compiled codes. facebook hiphop :这个工具用于facebook在c ++ / c上编译php文件以获得更好的性能,但最后我们有不可读的编译代码。 I don't remeber but I think it needs a good familiarity to linux or about php recompile mechanism on Microsoft Visual C++ . 我不记得,但我认为它需要熟悉Linux或Microsoft Visual C++上的PHP重新编译机制。 (However DON'T TRUST to my weak memory and google it) (AND FOR LEARNING ABOUT PHP RECOMPILE WAY PLZ REFER TO latest release of php_manual.chm) (但是不要相信我的弱记忆并谷歌)(和学习关于PHP重建方式PLZ请参阅最新版本的php_manual.chm)

Finally I made my self simple php obfuscator using regular expressions which worked on php 5.3 and my complex scripts so I moved on OpenSSL and different encryption mechanisms and got a review on php secure development. 最后,我使用正则表达式创建了我自己的简单php混淆器,这些表达式适用于php 5.3和我的复杂脚本,因此我转向了OpenSSL和不同的加密机制,并对php安全开发进行了审核。

Wishing you be successful. 祝你成功。

This is way overdue but should do what you want. 这是过期但应该做你想要的。

Make your own custom extension with the zend engine as they compile to a c++ dll. 使用zend引擎创建自己的自定义扩展,因为它们编译为c ++ dll。 Add that dll to your ext location in the php directory. 将该DLL添加到php目录中的ext位置。 After that you can call your own php scripts as php functions. 之后,您可以将自己的PHP脚本称为php函数。 Keep in mind that php is server side only so no one can get your scripts unless they are copied from the server and handed out. 请记住,php只是服务器端,因此除非从服务器复制并分发,否则没有人可以获取您的脚本。

Download the php source library for the version that you have. 下载您拥有的版本的php源库。 [windows.php.net] The zend stuff you need will be included. [windows.php.net]你需要的东西将被包括在内。

Step 1. Create a new project and select "General" under Visual C++ and the empty project option. 步骤1.创建一个新项目,然后在Visual C ++下选择“常规”和空项目选项。 Give it a name and Click ok. 给它一个名字然后点击确定。 Mine is Project1 so I will be using that. 我的是Project1所以我将使用它。

Step 2. Right click the solution name and select properties. 步骤2.右键单击解决方案名称并选择属性。 Select Dynamic Library (.dll) Under Project Defaults/Configuration Type in the Configuration Properties/General item. 在“配置属性/常规”项中的“项目默认值/配置类型”下,选择“动态库(.dll)”。 Be sure that you are changing the Debug config as Release is not used. 确保您正在更改Debug配置,因为未使用Release。

Step 3. Under VC++ Directiories add the following under the Include libraries: C:\\php-7.1.8-src\\Zend C:\\php-7.1.8-src\\win32 C:\\php-7.1.8-src\\TSRM C:\\php-7.1.8-src\\main C:\\php-7.1.8-src Libraries: C:\\php-7.1.8\\dev 步骤3.在VC ++ Directiories下,在Include库下添加以下内容:C:\\ php-7.1.8-src \\ Zend C:\\ php-7.1.8-src \\ win32 C:\\ php-7.1.8-src \\ TSRM C:\\ php-7.1.8-src \\ main C:\\ php-7.1.8-src库:C:\\ php-7.1.8 \\ dev

Step 4. Under C/C++ Preprocessor add ZEND_DEBUG=0;ZTS=1;ZEND_WIN32;PHP_WIN32 to Preprocessor Definitions 步骤4.在C / C ++预处理器下,将ZEND_DEBUG = 0; ZTS = 1; ZEND_WIN32; PHP_WIN32添加到预处理器定义

Step 5. Under Linker Input add php7ts.lib. 步骤5.在链接器输入下添加php7ts.lib。 This needs to match the lib for your version of php 这需要匹配你的php版本的lib

Click ok to save the Property settings for your solution. 单击“确定”以保存解决方案的“属性”设置。

Now lets add a code file for your function (Project1) 现在让我们为你的函数添加一个代码文件(Project1)

Under the source files folder right click and add Code. 在源文件文件夹下右键单击并添加代码。 I called mine Project1.cpp and here is the source. 我打电话给我的Project1.cpp,这里是源码。 You'll need to rename config.w32.h.in to config.w32.h and copy it to the directories where it is needed. 您需要将config.w32.h.in重命名为config.w32.h并将其复制到需要它的目录中。 Intellisense should tell you where it's looking and config.w32.h.in is in the C:\\php-7.1.8-src\\win32 directory. Intellisense应该告诉你它在哪里,config.w32.h.in在C:\\ php-7.1.8-src \\ win32目录中。

// this needs to match the compiler version that php was compiled with
#define _CRT_SECURE_NO_WARNINGS
#define PHP_COMPILER_ID "VC14"

#pragma once
/* You must include config.w32.h first */
#include "win32/config.w32.h"

#include "php.h"

ZEND_FUNCTION(ReturnString);

zend_function_entry Project1_functions[] =
{
    ZEND_FE(ReturnString, NULL)
    {
        NULL, NULL, NULL
    }
};

zend_module_entry Project1_module_entry =
{
    STANDARD_MODULE_HEADER,
    "Project1 Module",
    Project1_functions,
    NULL, NULL, NULL, NULL, NULL,
    NO_VERSION_YET, STANDARD_MODULE_PROPERTIES
};

ZEND_GET_MODULE(Project1)

ZEND_FUNCTION(ReturnString)
{
    zval* value;

    if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "z", &value) == FAILURE)
    {
        RETURN_FALSE;
    }

    convert_to_string(value);

    RETURN_STRING(Z_STRVAL_P(value), true);
}

Press F7 to compile and it should create Project1\\Debug\\Project1.dll. 按F7进行编译,它应该创建Project1 \\ Debug \\ Project1.dll。 Copy Project1 to your ext directory C:\\php-7.1.8\\ext and add an extension=Project1.dll to your php.ini and you should be good to go. 将Project1复制到你的ext目录C:\\ php-7.1.8 \\ ext,并在你的php.ini中添加一个extension = Project1.dll,你应该好好去。 If it doesn't work double check your properties to make sure you didn't miss something. 如果它不起作用,请仔细检查您的属性,以确保您没有错过任何东西。

The script is quite simple:

<?php
echo ReturnString("The Returning String");
?>

It depends on what you mean by "binary". 这取决于你所说的“二元”。

If you want to compile (or just obfuscate) your PHP code to keep someone else from modifying then use a bytecode compiler. 如果您想编译(或只是混淆)您的PHP代码以防止其他人修改,那么使用字节码编译器。 One example are the tools from Zend , among others. 一个例子是Zend的工具等。 (I prefer Zend's tools because they the primary company behind PHP and fully QA all their tools against all the versions of PHP). (我更喜欢Zend的工具,因为他们是PHP背后的主要公司,完全QA所有他们的工具对所有PHP版本)。

If you want to compile your PHP code and link the PHP runtime to it and then deploy it (like C\\C++), then no. 如果你想编译你的PHP代码并将PHP运行时链接到它,然后部署它(如C \\ C ++),那么没有。 Maybe in theory that would be possible but it would be a mess. 也许在理论上这是可能的,但它会是一团糟。 (Not practical or feasible and don't think anyone has put anything together to try and the output would also be tied to a particular architecture). (不实用或不可行,并且不认为任何人将任何东西放在一起尝试,输出也将与特定架构相关联)。

If the web server is Linux based, you can create a package like .deb or .rpm (depending on the Linux distribution) and easily distribute/deploy it. 如果Web服务器是基于Linux的,您可以创建一个类似.deb.rpm的软件包(取决于Linux发行版)并轻松分发/部署它。

BR, Dawid. BR,Dawid。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM