The principle and practice of modifying Zend engine to implement PHP source code encryption
Source: Internet
Author: User
The source code for PHP files is plaintext, which is not suitable for some commercial purposes.
So consider using encryption to protect the source code.
It's really impatient to wait for Zend out of the compiler, and compilation and encryption are inherently not the same thing. Do it yourself and start revising it.
First, the basic principle
Consider intercepting the interface that PHP reads from the source file. In the beginning, I considered processing from the interface between Apache and PHP, see Apache's src/modules/php4/mod_php4.c (this is the file that PHP compiles into apache,make install in a static way), Intercepts the file pointer in the send_php () function, using the temporary file, and decrypting and replacing the file pointer. This method has been proved to be feasible by testing and practice. However, must use two times file operation, inefficient, and for the DSO method can not be used. Double Margin Nursing Home
Thus, the process of intercepting PHP to read the file and loading it into the cache is reconsidered, and it is found that ZEND-SCANNER.C is doing this in the Zend engine. Start modifying this file. Lighting Engineering
Second, the realization method signals
Using Libmcrypt as the encryption module, the Des method is now used for ECB mode encryption,
The following is the source code for the file encryption:
/* ECB.C-------------------cut here-----------* *
/* Encrypt for PHP source code version 0.99 Beta
We are using Libmcrypt to encrypt codes, please
Install it.
Compile command line:
Gcc-o6-lmcrypt-lm-o encryptphp ECB.C
Please set ld_library_path before to use.
GNU copyleft, designed by WangSu, Miweicong * *
int TD, I,j,inputfilesize,filelength;
Char filename[255];
Char password[12];
File* IFP;
int READFD;
Char *key;
void *block_buffer;
void *file_buffer;
int keysize;
int decode=0;
int realbufsize=0;
struct stat *filestat;
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.
A Free Trial That Lets You Build Big!
Start building with 50+ products and up to 12 months usage for Elastic Compute Service