Exemplo n.º 1
0
 private function shuffle_stmts(PhpParser\Node &$node)
 {
     global $conf;
     if ($conf->shuffle_stmts) {
         if (isset($node->stmts)) {
             $stmts = $node->stmts;
             $chunk_size = shuffle_get_chunk_size($stmts);
             if ($chunk_size <= 0) {
                 return false;
             }
             // should never occur!
             if (count($stmts) > 2 * $chunk_size) {
                 //    $last_inst      = array_pop($stmts);
                 $stmts = shuffle_statements($stmts);
                 //    $stmts[]        = $last_inst;
                 $node->stmts = $stmts;
                 return true;
             }
         }
     }
     return false;
 }
Exemplo n.º 2
0
function shuffle_statements($stmts)
{
    global $conf;
    global $t_scrambler;
    if (!$conf->shuffle_stmts) {
        return $stmts;
    }
    $chunk_size = shuffle_get_chunk_size($stmts);
    if ($chunk_size <= 0) {
        return $stmts;
    }
    // should never occur!
    $n = count($stmts);
    if ($n < 2 * $chunk_size) {
        return $stmts;
    }
    $scrambler = $t_scrambler['label'];
    $label_name_prev = $scrambler->scramble($scrambler->generate_label_name());
    $first_goto = new PhpParser\Node\Stmt\Goto_($label_name_prev);
    $t = array();
    $t_chunk = array();
    for ($i = 0; $i < $n; ++$i) {
        $t_chunk[] = $stmts[$i];
        if (count($t_chunk) >= $chunk_size) {
            $label = array(new PhpParser\Node\Stmt\Label($label_name_prev));
            $label_name = $scrambler->scramble($scrambler->generate_label_name());
            $goto = array(new PhpParser\Node\Stmt\Goto_($label_name));
            $t[] = array_merge($label, $t_chunk, $goto);
            $label_name_prev = $label_name;
            $t_chunk = array();
        }
    }
    if (count($t_chunk) > 0) {
        $label = array(new PhpParser\Node\Stmt\Label($label_name_prev));
        $label_name = $scrambler->scramble($scrambler->generate_label_name());
        $goto = array(new PhpParser\Node\Stmt\Goto_($label_name));
        $t[] = array_merge($label, $t_chunk, $goto);
        $label_name_prev = $label_name;
        $t_chunk = array();
    }
    $last_label = new PhpParser\Node\Stmt\Label($label_name);
    shuffle($t);
    $stmts = array();
    $stmts[] = $first_goto;
    foreach ($t as $dummy => $stmt) {
        foreach ($stmt as $dummy => $inst) {
            $stmts[] = $inst;
        }
    }
    $stmts[] = $last_label;
    return $stmts;
}