i am coding a PHP extension , i modify the zend_compile_file
to my own function here is the source code :
FILE *bravery_ext_fopen(FILE *fp)
{
struct stat stat_buf;
char *datap, *newdatap;
int datalen, newdatalen;
char sign[] = "BRAVERY";
int cryptkey_len = sizeof(sign);
fstat(_fileno(fp), &stat_buf);
datalen = stat_buf.st_size - sizeof(sign);
datap = (char*)malloc(datalen);
fread(datap, datalen, 1, fp);
fclose(fp);
fp = tmpfile();
fwrite(datap, datalen-1, 1, fp);
free(datap);
rewind(fp);
return fp;
}
zend_op_array *bravery_compile_file(zend_file_handle *file_handle, int type TSRMLS_DC)
{
FILE *fp;
char sign[] = "BRAVERY";
char buf[8];
char fname[128];
memset(fname, 0, sizeof fname);
if (zend_is_executing(TSRMLS_C)) {
if (get_active_function_name(TSRMLS_C)) {
strncpy(fname, get_active_function_name(TSRMLS_C), sizeof fname - 2);
}
}
if (fname[0]) {
if ( strcasecmp(fname, "show_source") == 0
|| strcasecmp(fname, "highlight_file") == 0) {
return NULL;
}
}
fp = fopen(file_handle->filename, "r");
if (!fp) {
return org_compile_file(file_handle, type TSRMLS_CC);
}
fread(buf, 7, 1, fp);
if (memcmp(buf, sign, 7) != 0) {
fclose(fp);
return org_compile_file(file_handle, type TSRMLS_CC);
}
if (file_handle->type == ZEND_HANDLE_FP) fclose(file_handle->handle.fp);
if (file_handle->type == ZEND_HANDLE_FD) close(file_handle->handle.fd);
file_handle->handle.fp = bravery_ext_fopen(fp);
file_handle->type = ZEND_HANDLE_FP;
//file_handle->opened_path = expand_filepath(file_handle->filename, NULL TSRMLS_CC);
file_handle->opened_path = NULL;
return org_compile_file(file_handle, type TSRMLS_CC);
}
its works good on normal PHP files,
BUT it gives me a Fatal error: Unknown: Failed opening required 'C:\php5411\1.php' (include_path='.;C:\php\pear') in Unknown on line 0
error to me when the phpfile start with "BRAVERY"(this is what i am using to sign my php file).
here is the debug info of file_handle.Could any one help me? sorry for the google docs link cause i cannot post image here