Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include "php.h"
- #include "SAPI.h"
- #include <stdio.h>
- #include "zend.h"
- #include "php_main.h"
- #include "ext/standard/php_standard.h"
- #include "EnigneFunction.h"
- size_t Engineub_write(const char *str, size_t str_length)
- {
- if (str_length > 0) printf(str);
- return str_length;
- }
- void IniSet2(HashTable *hash, const char *name, const char *value) {
- zval tmp;
- ZVAL_NEW_STR(&tmp, zend_string_init(value, strlen(value), 1));
- zend_hash_str_update(hash, name, strlen(name), &tmp);
- }
- void IniSet(const char *name, const char *value) {
- IniSet2(php_ini_get_configuration_hash(), name, value);
- }
- void Engineini_defaults(HashTable *configuration_hash)
- {
- IniSet2(configuration_hash, "report_zend_debug", "0");
- IniSet2(configuration_hash, "display_errors", "1");
- IniSet2(configuration_hash, "html_errors", "0");
- IniSet2(configuration_hash, "max_execution_time", "0");
- IniSet2(configuration_hash, "memory_limit", "-1");
- }
- static int php_cli_startup(sapi_module_struct *sapi_module) { return php_module_startup(sapi_module, NULL, 0); }
- static int sapi_cli_deactivate(void) { fflush(stdout); return SUCCESS; }
- static void sapi_cli_flush(void *server_context) { if (fflush(stdout)==EOF && errno!=EBADF) { } }
- static int sapi_cli_header_handler(sapi_header_struct *h, sapi_header_op_enum op, sapi_headers_struct *s){ return 0; }
- static int sapi_cli_send_headers(sapi_headers_struct *sapi_headers) { return SAPI_HEADER_SENT_SUCCESSFULLY; }
- static void sapi_cli_send_header(sapi_header_struct *sapi_header, void *server_context) { }
- static char* sapi_cli_read_cookies(void){ return NULL; }
- static void sapi_cli_register_variables(zval *track_vars_array) { }
- static void sapi_cli_log_message(char *message, int syslog_type_int) { fprintf(stderr, "%s\n", message); fflush(stderr); }
- //**********************************************************************************
- sapi_module_struct sapi_module;
- int SessionInit = 0;
- int SessionInit2 = 0;
- void evalCode(const char *str, zval *retval_ptr, char *string_name, int handle_exceptions) {
- EG(exit_status) = 0;
- zend_bool in_compilation = CG(in_compilation);
- CG(in_compilation) = 0;
- zend_bool during_request_startup = PG(during_request_startup);
- PG(during_request_startup) = 0;
- zend_string *new_compiled_filename = zend_string_init(string_name, strlen(string_name), 0);
- zend_set_compiled_filename(new_compiled_filename);
- zend_try {
- zend_eval_string_ex((char *)str, retval_ptr, string_name, handle_exceptions);
- } zend_end_try();
- zend_string_release_ex(new_compiled_filename, 0);
- PG(during_request_startup) = during_request_startup;
- CG(in_compilation) = in_compilation;
- }
- // Let's create our class initialization, the standard one does not work
- void *RegisterPHPCLASS(const char *ClassName) {
- zend_class_entry *ce = malloc(sizeof(zend_class_entry));
- memset(ce, 0, sizeof(zend_class_entry));
- ce->name = zend_string_init_interned(ClassName, strlen(ClassName), 1);
- ce->type = ZEND_INTERNAL_CLASS;
- zend_initialize_class_data(ce, 1);
- ce->ce_flags = ZEND_ACC_CONSTANTS_UPDATED | ZEND_ACC_LINKED | ZEND_ACC_RESOLVED_PARENT | ZEND_ACC_RESOLVED_INTERFACES;
- ce->info.internal.module = EG(current_module);
- zend_string *lowercase_name = zend_string_tolower_ex(ce->name, 0);
- lowercase_name = zend_new_interned_string(lowercase_name);
- zend_hash_update_ptr(CG(class_table), lowercase_name, ce);
- zend_string_release_ex(lowercase_name, 1);
- return ce;
- }
- void Test() {
- evalCode("function pinfo() { ob_start(); phpinfo(); $data = ob_get_contents(); ob_clean(); return $data; } file_put_contents('IsRun.txt', pinfo()); ", NULL, "Test Eval", 1);
- zend_class_entry *register_class_entry;
- // ERROR register class :
- // INIT_CLASS_ENTRY(class_entry, "TestClass", NULL);
- // register_class_entry = zend_register_internal_class(&class_entry);
- // Project .exe raised exception class $C0000005 with message 'access violation at 0x682dc627: read of address 0x0000004c'.
- // - 682DC61E 8B84012C030000 mov eax,[ecx+eax+$032c]
- // - 682DC625 33C9 xor ecx,ecx
- // LINE Error - 682DC627 80784C01 cmp byte ptr [eax+$4c],$01
- // New function Register
- register_class_entry = RegisterPHPCLASS("TestClass");
- // Class creation went well
- evalCode(" file_put_contents('NewClass.txt', print_r(new TestClass, true)); ", NULL, "Test Eval", 1);
- // Okay! Call
- // zend_declare_property_null(register_class_entry, "line", sizeof("line")-1, ZEND_ACC_PROTECTED);
- // ERROR!!!
- // Project Project1.exe raised exception class $C0000005 with message 'access violation at 0x682d7e47: read of address 0x0000004c'.
- // php7ts.zend_declare_property:
- // 682D7E30 53 push ebx
- // 682D7E31 8B5C2408 mov ebx,[esp+$08]
- // 682D7E35 55 push ebp
- // 682D7E36 8B6C2414 mov ebp,[esp+$14]
- // 682D7E3A 56 push esi
- // 682D7E3B F60301 test byte ptr [ebx],$01
- // 682D7E3E 57 push edi
- // 682D7E3F 7413 jz $682d7e54
- // 682D7E41 8B8318010000 mov eax,[ebx+$00000118]
- // 682D7E47 80784C01 cmp byte ptr [eax+$4c],$01 !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
- // Set the fix for the is_persistent_class function and everything works
- zend_declare_property_null(register_class_entry, "line", sizeof("line")-1, ZEND_ACC_PROTECTED);
- evalCode(" file_put_contents('NewClass2.txt', print_r(new TestClass, true)); ", NULL, "Test Eval", 1);
- /*
- TestClass Object
- (
- [line:protected] =>
- )
- FIX FUNCTION
- static zend_always_inline zend_bool is_persistent_class(zend_class_entry *ce) {
- return (ce->type & ZEND_INTERNAL_CLASS)
- && (!ce->info.internal.module || ce->info.internal.module->type == MODULE_PERSISTENT);
- }
- */
- }
- void destructor() {
- if(SessionInit2) {
- sapi_deactivate();
- zend_ini_deactivate();
- }
- php_request_shutdown((void *) 0);
- if(SessionInit)
- php_module_shutdown();
- sapi_shutdown();
- tsrm_shutdown();
- memset(&sapi_module, 0, sizeof(sapi_module_struct));
- }
- SAPI_API void PHPInit(char * name, char * pretty_name)
- {
- memset(&sapi_module, 0, sizeof(sapi_module_struct));
- sapi_module.name = strdup(name);
- sapi_module.pretty_name = strdup(pretty_name);
- sapi_module.startup = php_cli_startup;
- sapi_module.shutdown = php_module_shutdown_wrapper;
- sapi_module.deactivate = sapi_cli_deactivate;
- sapi_module.ub_write = Engineub_write;
- sapi_module.flush = sapi_cli_flush;
- sapi_module.sapi_error = php_error;
- sapi_module.header_handler = sapi_cli_header_handler;
- sapi_module.send_headers = sapi_cli_send_headers;
- sapi_module.send_header = sapi_cli_send_header;
- sapi_module.read_cookies = sapi_cli_read_cookies;
- sapi_module.register_server_variables = sapi_cli_register_variables;
- sapi_module.log_message = sapi_cli_log_message;
- php_tsrm_startup();
- ZEND_TSRMLS_CACHE_UPDATE();
- zend_signal_startup();
- sapi_module.ini_defaults = Engineini_defaults;
- sapi_module.phpinfo_as_text = 1;
- sapi_module.php_ini_ignore_cwd = 1;
- sapi_startup(&sapi_module);
- if (sapi_module.startup(&sapi_module) != FAILURE) {
- SessionInit2 = php_request_startup()!=FAILURE;
- if(SessionInit2) Test();
- }
- }
RAW Paste Data