Showing posts with label PHP. Show all posts
Showing posts with label PHP. Show all posts

try/catch in C [PHP interpreter]

Abstract

PHP interpreter is written in C, but uses try/catch construct known from other popular languages. This approach is different from everyday C-like error handling, where it's done by using function return value or by modifying error variable passed as an argument to a function.

    zend_try {
        PG(during_request_startup) = 1;
        php_output_activate(TSRMLS_C);
       /* unimportant stuff */
    } zend_catch {
        retval = FAILURE;
    } zend_end_try();

If one of instructions in a "try" block raises an exception then the evaluation of this block is terminated and execution flow moves to a "catch" block.

Images hardcoded in a source code [PHP interpreter]

Abstract

Recently I presented a simple way to protect an image against saving, today I will show how PHP interpreter protect some of its images against changing.

Image may be hardcoded in a regular array, where each field contains corresponding value of a byte in the original image file. You may imagine that you open image in a hex editor, you see its content as a chain of values of the bytes, and then you retype them as a fields in your array (this can be automatized of course).