Visa ett inlägg
Oläst 2011-10-01, 18:16 #5
Jake.Nu Jake.Nu är inte uppkopplad
Medlem
 
Reg.datum: Oct 2006
Inlägg: 224
Jake.Nu Jake.Nu är inte uppkopplad
Medlem
 
Reg.datum: Oct 2006
Inlägg: 224
Om du vågar

script.php
PHP-kod:
<?php
if ($obj->id 0) {}
$obj = new stdClass();
if (
$obj->id 0) {}
if (
$array["id"] < 0) {}
if (
$id != 0) {}
?>
fix_file.php
PHP-kod:
<?php
function fix_file($filename) {
    
$index = array();
    
$props = array();
    
$varib = array();
    
    
$data file_get_contents($filename);
    
    
ob_start();
    eval(
str_replace("<?php"""$data));
    
$rows explode("\n"ob_get_clean());
    foreach (
$rows as $row) {
        if (empty(
$row)) {
            continue;
        }
        if (
preg_match('/Undefined index:\040+(.+)\040+in.+on line\040([0-9]+)/'$row$match)) {
            
$index[$match[2] - 1][] = $match[1];
            continue;
        }
        if (
preg_match('/Undefined property:\040+.+::\$(.+)\040+in.+on line\040([0-9]+)/'$row$match)) {
            
$props[$match[2] - 1][] = $match[1];
            continue;
        }
        if (
preg_match('/Undefined variable:\040+(.+)\040+in.+on line\040([0-9]+)/'$row$match)) {
            
$varib[$match[2] - 1][] = $match[1];
            continue;
        }
    }
    
$rows explode("\n"$data);
    foreach (
$index as $idx => $keys) {
        foreach (
$keys as $index_name) {
            if (
preg_match('/\$.+\[[\"|\']' $index_name '[\"|\']\]/'$rows[$idx], $match)) {
                
$rows[$idx] = str_replace($match[0], 'isset(' $match[0] . ') && ' $match[0], $rows[$idx]);
                continue;
            }
        }
    }
    foreach (
$props as $idx => $keys) {
        foreach (
$keys as $prop_name) {
            if (
preg_match('/\$.+->' $prop_name '/'$rows[$idx], $match)) {
                
$rows[$idx] = str_replace($match[0], 'isset(' $match[0] . ') && ' $match[0], $rows[$idx]);
                continue;
            }
        }
    }
    foreach (
$varib as $idx => $keys) {
        foreach (
$keys as $varib_name) {
            if (
preg_match('/\$' $varib_name '/'$rows[$idx], $match)) {
                
$rows[$idx] = str_replace($match[0], 'isset(' $match[0] . ') && ' $match[0], $rows[$idx]);
                continue;
            }
        }
    }
    
file_put_contents($filenameimplode("\n"$rows));
}

error_reporting(E_ALL);
ini_set("display_errors"1);
ini_set("html_errors"0);

// fixar bara en fil, gör något själv!
fix_file("./script.php");
?>

Senast redigerad av Jake.Nu den 2011-11-26 klockan 03:49
Jake.Nu är inte uppkopplad   Svara med citatSvara med citat