Inject code within Compiler?
| From: | Clint M Priest | Date: | Sat, 26 Nov 2011 01:47:14 +0000 |
| Subject: | Inject code within Compiler? | ||
| Groups: | php.internals | ||
| Request: | Send a blank email to internals+get-56640@lists.php.net to get a copy of this message | ||
Trying implement empty getter/setter syntax such as:
public $Hours {
get;
set;
}
Is there any way to "inject" code into the compile process?
I'm trying via (just some proof of concept code, ignore the buffer overrun potential)
char injected_code[1024] = "";
sprintf((char*)&injected_code, "{ return
$this->%s; }", Z_STRVAL(var_name->u.constant));
znode *injected_node = emalloc(sizeof(znode));
Z_STRVAL(injected_node->u.constant) =
(char*)&injected_code;
Z_STRLEN(injected_node->u.constant) =
strlen(injected_code);
zend_do_abstract_method(function_token, modifiers,
injected_node TSRMLS_CC);
However this is causing a segfault, I'm assuming this is because I'm not initializing
something of the znode properly.
How can I do this?
Thanks,
-Clint