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:
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.
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;
}
/*---End of ecb.c------------------------------------* *
Because the ECB model is block-length-determined block encryption, some empty characters are populated here. International Exhibitions
Then, modify the PHP code in ZEND/ZEND-SCANNER.C as follows:
(My PHP version is 4.01PL2, Sunsparc/solaris 2.7, gcc 2.95;)
Then, comment out the definition of yy_input around 3510 lines.
Then, modify the Yy_get_next_buffer () function around 5150 lines:
function header Plus definition:
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.
To
Then, compile PHP, the normal way to install it, because I am not familiar with the libtool, so I chose the static mode, and in the Configure when I joined the--with-mcrypt, so I do not have to manually modify the makefile cable tray
III. Testing and Results
After compiling the Php,apache, ECB.C compiled the encryptphp to encrypt several files, respectively < 1k,10k+, and 40k+, when processing 40K size file error, other files are normal. Plastic Flooring
This is because the ECB encryption of the block determines the need to use fixed-length blocks, so let's all have a look at what kind of streaming encryption can take into account the Zend each read 8192 bytes of cache processing mode. (Zend per read block length may vary on other platforms)
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.