Beispiel #1
0
 static function r2_functions($binary)
 {
     #calculate code_start and code_end
     $code_section = Binary::codeSection($binary);
     $imagebase = Pefile::imagebase($binary);
     $code_start = hexdec($code_section["va"]) + hexdec($imagebase);
     $code_end = hexdec($code_section["va"]) + hexdec($imagebase) + hexdec($code_section["srd"]["value"]);
     $cmd = "echo \"aa;af;e scr.interactive=false;echo BEGIN;afj\"|" . Config::$radare2_path . "/radare2 {$binary}";
     @ob_start();
     system($cmd);
     $res = ob_get_contents();
     ob_end_clean();
     $out = "";
     $res = preg_replace("/.*BEGIN/s", "", $res);
     $res = preg_replace("/\\033\\[2K.*/s", "", $res);
     $items = array();
     $lines = json_decode($res);
     if (count($lines)) {
         foreach ($lines as $line) {
             $item = array();
             $item["address"] = "0x" . dechex($line->offset);
             $item["size"] = $line->size;
             $item["cc"] = $line->cc;
             $item["name"] = $line->name;
             $item["type"] = $line->type;
             $item["callrefs"] = count($line->callrefs);
             $item["datarefs"] = count($line->datarefs);
             if (hexdec($item["address"]) >= $code_start && hexdec($item["address"]) <= $code_end) {
                 $item["incodesec"] = 1;
             } else {
                 $item["incodesec"] = 0;
             }
             array_push($items, $item);
         }
     }
     @usort($items, array(self, "cmp_functions"));
     return $items;
 }