diff --git a/.github/workflows/test.yml b/.github/workflows/test.yml index 1ae3c60..a0ec387 100644 --- a/.github/workflows/test.yml +++ b/.github/workflows/test.yml @@ -2,32 +2,31 @@ name: C/C++ CI on: push: - branches: [ "master" ] + branches: ["master"] pull_request: - branches: [ "master" ] + branches: ["master"] jobs: build: - runs-on: ubuntu-latest steps: - - name: dependencies - run: sudo apt-get install -y php8.1 php8.1-dev - - name: php version - run: php --version - - uses: actions/checkout@v3 - - name: phpize - run: phpize - - name: configure - run: ./configure --enable-bfr - - name: make - run: make - - name: make install - run: sudo make install - - name: enable extension - run: | - sudo php --ini | grep Loaded - echo "zend_extension = /usr/lib/php/20210902/bfr.so" | sudo tee -a /etc/php/8.1/cli/php.ini - - name: php version test - run: php --version | grep "with Better Function Replacer" + - name: dependencies + run: sudo apt-get install -y php8.1 php8.1-dev + - name: php version + run: php --version + - uses: actions/checkout@v3 + - name: phpize + run: phpize + - name: configure + run: ./configure --enable-bfr + - name: make + run: make + - name: make install + run: sudo make install + - name: enable extension + run: | + sudo php --ini | grep Loaded + echo "zend_extension = /usr/lib/php/20210902/bfr.so" | sudo tee -a /etc/php/8.1/cli/php.ini + - name: php version test + run: php --version | grep "with Better Function Replacer" diff --git a/php_bfr.c b/php_bfr.c index 6a2765e..38faa48 100644 --- a/php_bfr.c +++ b/php_bfr.c @@ -38,11 +38,8 @@ ZEND_END_ARG_INFO() zend_function_entry bfr_functions[] = { PHP_FE(override_function, arginfo_override_function) - PHP_FE(rename_function, arginfo_rename_function) - { - NULL, NULL, NULL - } -}; + PHP_FE(rename_function, arginfo_rename_function){ + NULL, NULL, NULL}}; /* -------------------------------------------------------------------------- Module Entry @@ -57,8 +54,7 @@ zend_module_entry bfr_module_entry = { PHP_RSHUTDOWN(bfr), PHP_MINFO(bfr), PHP_BFR_VERSION, - STANDARD_MODULE_PROPERTIES -}; + STANDARD_MODULE_PROPERTIES}; #if COMPILE_DL_BFR @@ -128,20 +124,18 @@ PHP_FUNCTION(override_function) if (ZEND_NUM_ARGS() != 3 || zend_parse_parameters(ZEND_NUM_ARGS(), "sss", - &z_function_name, &function_name_len, - &z_function_args, &function_args_len, - &z_function_code, &function_code_len) == FAILURE) + &z_function_name, &function_name_len, + &z_function_args, &function_args_len, + &z_function_code, &function_code_len) == FAILURE) { ZEND_WRONG_PARAM_COUNT(); } - eval_code_length = sizeof(TEMP_OVRD_FUNC_HEADER) - + function_args_len - + 2 /* parentheses */ - + 2 /* curlies */ - + function_code_len; + eval_code_length = sizeof(TEMP_OVRD_FUNC_HEADER) + function_args_len + 2 /* parentheses */ + + 2 /* curlies */ + + function_code_len; - eval_code = (char *) emalloc(eval_code_length); + eval_code = (char *)emalloc(eval_code_length); sprintf(eval_code, TEMP_OVRD_FUNC_PATTERN, z_function_args, z_function_code); eval_name = zend_make_compiled_string_description(TEMP_OVRD_FUNC_DESC); retval = zend_eval_string(eval_code, NULL, eval_name); @@ -151,16 +145,16 @@ PHP_FUNCTION(override_function) if (retval != SUCCESS) { zend_error(E_ERROR, "%s() failed to eval temporary function", - get_active_function_name()); + get_active_function_name()); RETURN_FALSE; } if ((func = zend_hash_str_find_ptr(EG(function_table), - TEMP_OVRD_FUNC_NAME, sizeof(TEMP_OVRD_FUNC_NAME) - 1)) == NULL) + TEMP_OVRD_FUNC_NAME, sizeof(TEMP_OVRD_FUNC_NAME) - 1)) == NULL) { zend_error(E_ERROR, "%s() temporary function name not present in global function_table", - get_active_function_name()); + get_active_function_name()); RETURN_FALSE; } @@ -168,30 +162,30 @@ PHP_FUNCTION(override_function) func_dup = duplicate_function(func); if (zend_hash_str_exists(EG(function_table), - z_function_name, function_name_len)) + z_function_name, function_name_len)) { zend_hash_str_del(EG(function_table), - z_function_name, function_name_len); + z_function_name, function_name_len); } if (zend_hash_str_add_new_ptr(EG(function_table), - z_function_name, function_name_len, - func_dup) == NULL) + z_function_name, function_name_len, + func_dup) == NULL) { zend_error(E_ERROR, "%s() failed to add function", - get_active_function_name()); + get_active_function_name()); RETURN_FALSE; } if (zend_hash_str_del(EG(function_table), TEMP_OVRD_FUNC_NAME, - sizeof(TEMP_OVRD_FUNC_NAME) - 1) == FAILURE) + sizeof(TEMP_OVRD_FUNC_NAME) - 1) == FAILURE) { zend_error(E_ERROR, "%s() failed to delete temporary function", - get_active_function_name()); + get_active_function_name()); zend_hash_str_del(EG(function_table), - z_function_name, function_name_len); + z_function_name, function_name_len); RETURN_FALSE; } @@ -205,26 +199,26 @@ PHP_FUNCTION(rename_function) if (ZEND_NUM_ARGS() != 2 || zend_parse_parameters(ZEND_NUM_ARGS(), "ss", - &z_orig_fname, &orig_fname_len, - &z_new_fname, &new_fname_len) == FAILURE) + &z_orig_fname, &orig_fname_len, + &z_new_fname, &new_fname_len) == FAILURE) { ZEND_WRONG_PARAM_COUNT(); } if ((func = zend_hash_str_find_ptr(EG(function_table), - z_orig_fname, orig_fname_len)) == NULL) + z_orig_fname, orig_fname_len)) == NULL) { zend_error(E_WARNING, "%s(%s, %s) failed: %s does not exist!", - get_active_function_name(), - z_orig_fname, z_new_fname, z_orig_fname); + get_active_function_name(), + z_orig_fname, z_new_fname, z_orig_fname); RETURN_FALSE; } if (zend_hash_str_exists(EG(function_table), z_new_fname, new_fname_len)) { zend_error(E_WARNING, "%s(%s, %s) failed: %s already exists!", - get_active_function_name(), - z_orig_fname, z_new_fname, z_new_fname); + get_active_function_name(), + z_orig_fname, z_new_fname, z_new_fname); RETURN_FALSE; } @@ -234,14 +228,14 @@ PHP_FUNCTION(rename_function) if (zend_hash_str_add_ptr(EG(function_table), z_new_fname, new_fname_len, func_dup) == NULL) { zend_error(E_WARNING, "%s() failed to insert %s into EG(function_table)", - get_active_function_name(), z_new_fname); + get_active_function_name(), z_new_fname); RETURN_FALSE; } if (zend_hash_str_del(EG(function_table), z_orig_fname, orig_fname_len) == FAILURE) { zend_error(E_WARNING, "%s() failed to remove %s from function table", - get_active_function_name(), z_orig_fname); + get_active_function_name(), z_orig_fname); zend_hash_str_del(EG(function_table), z_new_fname, new_fname_len); @@ -275,7 +269,7 @@ ZEND_DLEXPORT zend_extension zend_extension_entry = { PHP_BFR_VERSION, "Lukas Rist", "http://mushmush.org/", - "Copyright (C) 2015", + "Copyright (C) 2023", bfr_zend_startup, bfr_zend_shutdown, NULL, // activate_func_t @@ -288,15 +282,4 @@ ZEND_DLEXPORT zend_extension zend_extension_entry = { NULL, // op_array_ctor_func_t NULL, // op_array_dtor_func_t NULL, // api_no_check - COMPAT_ZEND_EXTENSION_PROPERTIES -}; - -/** - * Local Variables: - * indent-tabs-mode: t - * tab-width: 4 - * c-basic-offset: 4 - * End: - * vim600:fdm=marker - * vim:noet:sw=4:ts=4 - */ + COMPAT_ZEND_EXTENSION_PROPERTIES}; diff --git a/php_bfr.h b/php_bfr.h index 5eff5cb..f300178 100644 --- a/php_bfr.h +++ b/php_bfr.h @@ -1,4 +1,4 @@ -/* +/* +----------------------------------------------------------------------+ | Better Function Replacer | | based on APD Profiler & Debugger | @@ -44,7 +44,7 @@ PHP_MINFO_FUNCTION(bfr); extern zend_module_entry bfr_module_entry; -#define PHP_BFR_VERSION "0.1" +#define PHP_BFR_VERSION "1.0" ZEND_BEGIN_MODULE_GLOBALS(bfr) ZEND_END_MODULE_GLOBALS(bfr) @@ -52,10 +52,6 @@ ZEND_END_MODULE_GLOBALS(bfr) PHPAPI ZEND_EXTERN_MODULE_GLOBALS(bfr) /* Declare global structure. */ -#ifdef ZTS -#define BFR_GLOBALS(v) TSRMG(bfr_globals_id, zend_bfr_globals *, v) -#else #define BFR_GLOBALS(v) (bfr_globals.v) -#endif -#endif \ No newline at end of file +#endif diff --git a/php_helpers.c b/php_helpers.c index ccd940b..d521103 100644 --- a/php_helpers.c +++ b/php_helpers.c @@ -25,23 +25,23 @@ zend_function *duplicate_function(zend_function *func) { - zend_function *new_function; + zend_function *new_function; - if (func->type != ZEND_INTERNAL_FUNCTION) - { - new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array)); - memcpy(new_function, func, sizeof(zend_op_array)); + if (func->type != ZEND_INTERNAL_FUNCTION) + { + new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array)); + memcpy(new_function, func, sizeof(zend_op_array)); - function_add_ref(new_function); + function_add_ref(new_function); - return new_function; - } + return new_function; + } - new_function = zend_arena_alloc(&CG(arena), sizeof(zend_internal_function)); - memcpy(new_function, func, sizeof(zend_internal_function)); - new_function->common.fn_flags |= ZEND_ACC_ARENA_ALLOCATED; + new_function = zend_arena_alloc(&CG(arena), sizeof(zend_internal_function)); + memcpy(new_function, func, sizeof(zend_internal_function)); + new_function->common.fn_flags |= ZEND_ACC_ARENA_ALLOCATED; - function_add_ref(new_function); + function_add_ref(new_function); - return new_function; -} \ No newline at end of file + return new_function; +} diff --git a/php_helpers.h b/php_helpers.h index 64a9e0d..d831a04 100644 --- a/php_helpers.h +++ b/php_helpers.h @@ -29,4 +29,4 @@ zend_function *duplicate_function(zend_function *func); -#endif \ No newline at end of file +#endif