Source: The source code of phphotPHP files is plain text, which is not suitable for some commercial purposes. Therefore, we consider using encryption to protect the source code. It is really impatient to wait for zend to exit the compiler, and compilation and encryption are not the same thing in nature. Start modification by yourself. I. Basic principles
Consider intercepting interfaces for PHP to read source files. At the beginning, I considered processing from the interface between Apache and PHP. For more information, see src/modules/php4/mod_php4.c of apache. (this is PHP compiled into apache in static mode, make install file), intercept the file pointer in the send_php () function, use the temporary file method, decrypt and replace the file pointer. This method has been tested and proved to be feasible. However, two file operations are required, which is inefficient and not applicable to DSO. Shuangyuan nursing home
As a result, re-consider the process of intercepting PHP to read files and load them to the cache, after laborious search, found that the zend-scanner.c in the Zend Engine is doing this. Start modifying this file. Lighting Engineering
II. implementation method diagram
Libmcrypt is used as the encryption module, and the DES method is used for ECB mode encryption,
The source code of file encryption is as follows:
C ++ code
/* Ecb. c ------------------- cut here -----------*/
/* Encrypt for php source code version 0.99 beta
We are using libmcrypt to encrypt codes, please
Install it first.
Compile command line:
Gcc-O6-lmcrypt-lm-o encryptphp ecb. c
Please set LD_LIBRARY_PATH before use.
GNU copyleft, designed by wangsu, miweicong */
# Define MCRYPT_BACKWARDS_COMPATIBLE 1
# Define PHP_CACHESIZE 8192
# Include <mcrypt. h>
# Include <stdio. h>
# Include <stdlib. h>
# Include <math. h>
# Include <sys/types. h>
# Include <sys/stat. h>
# Include <fcntl. h>
Main (int argc, char ** argv)
{
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;
}
/* --- End of ecb. c ------------------------------------*/
Because ECB mode is block encryption with a fixed block length, some null characters are entered here. International Exhibition
Then, modify the Zend/zend-scanner.c in php code as follows:
(My php version is 4.01pl2, suniscsi/solaris 2.7, gcc 2.95 ;)
Before the file is added:
# Define MCRYPT_BACKWARDS_COMPATIBLE 1
# Include <mcrypt. h>
Then, comment out the definition of YY_INPUT before and after about 3510 rows.
Then, modify the yy_get_next_buffer () function before and after about 5150 rows:
Define the function header:
Void * tempbuf;
Char * key;
Char debugstr [255];
Int td, keysize;
Int x, y;
FILE * fp;
Then, comment out
YY_INPUT (& yy_current_buffer-> yy_ch_buf [number_to_move]),
Yy_n_chars, num_to_read );
This sentence.
Changed:
Then compile php and install it as usual. because I am not familiar with libtool, I chose static mode and added -- with-mcrypt in configure, in this way, I don't have to manually modify the Makefile cable tray.
III. test and result
Compile php, apache, and use ecb. c-compiled encryptphp encrypts several files, which are <1 K, 10 K +, and 40 K +. errors occur when processing 40 K files. other files are normal. Plastic floor
This is because the ECB encryption method of the block determines that the fixed length block must be used. Therefore, please give us some advice on the stream encryption method which can take into account the zend cache processing method that reads 8192 bytes each time. (The length of each zend read block on other platforms may be different)
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.