SONIC3D

UG set torrent DHT free and remove UG tracker

Jun 8th, 2013
375
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.84 KB | None | 0 0
  1. <?php
  2. Header("content-type: text/plain");
  3. $parse_start_time = microtime(true);
  4. $tag='_UG-DHT_';
  5.  
  6. if ($dh = opendir("./"))
  7. {
  8.     while (($f = readdir($dh)) !== false)
  9.         if(!(($f==".")||($f=="..")) && filetype("./$f")!="dir" && strtolower(pathinfo($f, PATHINFO_EXTENSION))=="torrent" && substr($f, 0, strlen($tag))!=$tag )
  10.         {
  11.             $r=bdec(file_get_contents($f));
  12.             if (isset($r["info"]["source"]) && $r["info"]["source"]=="Underground Gamer")
  13.             {
  14.                 echo ($f.": ");
  15.                 $r["announce"]="http://localhost";
  16.                 unset($r["info"]["private"]);
  17.                 file_put_contents($tag.$f,benc($r));
  18.                 echo ("OK!\n");
  19.             }
  20.         }
  21.     closedir($dh);
  22. }
  23. function info_hash($info)
  24. {
  25.     return strtoupper(bin2hex(pack("H*", sha1(benc($info)))));
  26. }
  27. echo (memory_get_peak_usage() / 1024 / 1024) . " MB of RAM, " . (microtime(true) - $parse_start_time) . " seconds.\n\n";
  28.  
  29. /*
  30.   Bencoding OOP wrapper for PHP | by Proger_XP | In public domain
  31.     http://proger.i-forge.net/BEncoded/7Tn
  32.  
  33.   Based on lightenc.php functions from
  34.     http://wiki.theory.org/Decoding_encoding_bencoded_data_with_PHP
  35. */
  36. /* lightenc.php */
  37. function bdec($s, &$pos=0) {
  38.   if($pos>=strlen($s)) {
  39.     return null;
  40.   }
  41.   switch($s[$pos]){
  42.   case 'd':
  43.     $pos++;
  44.     $retval=array();
  45.     while ($s[$pos]!='e'){
  46.       $key=bdec($s, $pos);
  47.       $val=bdec($s, $pos);
  48.       if ($key===null || $val===null)
  49.         break;
  50.       $retval[$key]=$val;
  51.     }
  52.     $retval["isDct"]=true;
  53.     $pos++;
  54.     return $retval;
  55.  
  56.   case 'l':
  57.     $pos++;
  58.     $retval=array();
  59.     while ($s[$pos]!='e'){
  60.       $val=bdec($s, $pos);
  61.       if ($val===null)
  62.         break;
  63.       $retval[]=$val;
  64.     }
  65.     $pos++;
  66.     return $retval;
  67.  
  68.   case 'i':
  69.     $pos++;
  70.     $digits=strpos($s, 'e', $pos)-$pos;
  71.     // Proger_XP: changed (int) -> (float) to avoid trimming of values exceeding
  72.     //            signed int's max value (2147483647).
  73.     $val=(float)substr($s, $pos, $digits);
  74.     $pos+=$digits+1;
  75.     return $val;
  76.  
  77. //  case "0": case "1": case "2": case "3": case "4":
  78. //  case "5": case "6": case "7": case "8": case "9":
  79.   default:
  80.     $digits=strpos($s, ':', $pos)-$pos;
  81.     if ($digits<0 || $digits >20)
  82.       return null;
  83.     $len=(float)substr($s, $pos, $digits);
  84.     $pos+=$digits+1;
  85.     $str=substr($s, $pos, $len);
  86.     $pos+=$len;
  87.     //echo "pos: $pos str: [$str] len: $len digits: $digits\n";
  88.     return (string)$str;
  89.   }
  90.   return null;
  91. }
  92.  
  93. // Proger_XP: added added skipping for null values and $tempChar prefix for list/dicts.
  94. function benc(&$d, $tempChar = null){
  95.   if(is_array($d)){
  96.     $ret="l";
  97.     $isDict=!empty($d["isDct"]);
  98.     if($isDict){
  99.       $ret="d";
  100.       // this is required by the specs, and BitTornado actualy chokes on unsorted dictionaries
  101.       ksort($d, SORT_STRING);
  102.     }
  103.     foreach($d as $key=>$value) {
  104.       if($isDict){
  105.         // skip the isDct element, only if it's set by us
  106.         if (!bskip($key, $value, $tempChar)) {
  107.           $ret .= strlen($key).":$key";
  108.         }
  109.       } elseif (!is_int($key) and !is_float($key) and trim($key, '0..9') !== '') {
  110.                 // Proger_XP: added exception raising for non-numeric list keys.
  111.                 throw new Exception('Cannot bencode() a list - it contains a non-numeric key "'.$key.'".');
  112.             }
  113.  
  114.       if (is_string($value)) {
  115.         $ret.=strlen($value).":".$value;
  116.       } elseif (is_int($value) or is_float($value)){
  117.         $ret.="i${value}e";
  118.       } else {
  119.         $ret.=benc ($value);
  120.       }
  121.     }
  122.     return $ret."e";
  123.   } elseif (is_string($d)) { // fallback if we're given a single bencoded string or int
  124.     return strlen($d).":".$d;
  125.   } elseif (is_int($d) or is_float($d)) {
  126.     return "i${d}e";
  127.   } else {
  128.     return null;
  129.   }
  130. }
  131.  
  132. // bskip by Proger_XP.
  133. function bskip($key, &$value, $tempChar = null) {
  134.   return ($key === 'isDct' and $value) or $value === null or strpos($key, $tempChar) === 0;
  135. }
  136. ?>
Advertisement
Add Comment
Please, Sign In to add comment