Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Writing PHP opcode and have it executed. How to do?

How can I write PHP opcode, save it in a file and make the Zend Engine execute it? Any method or hack is welcome, as long as it does the trick.

like image 465
Raffael Avatar asked Nov 30 '11 12:11

Raffael


2 Answers

There is an extension called ulopcodes that allows you to emit your own opcodes via a function that it exposes to PHP code.

For example:

ulopcodes_emit(ZEND_ECHO, "Hello world!");

Will create that line in the current oparray which will be executed by the VM.

This extension is purely educational and not intended to be used in production code.

(Disclaimer: I am the creator of ulopcodes)

like image 131
pmmaga Avatar answered Sep 28 '22 03:09

pmmaga


There's a couple of user-space methods (from plugins) that can deal with Opcodes.

  • http://uk.php.net/apc_bin_load (and http://uk.php.net/apc_bin_dump)
  • http://uk.php.net/bcompiler_read / http://uk.php.net/bcompiler_write_file

Neither produces plain text however because the opcodes are not designed to be a user-writable language (unlike Parrot).

like image 36
Alister Bulman Avatar answered Sep 28 '22 02:09

Alister Bulman