Advertisement
Guest User

unPMF

a guest
Dec 30th, 2014
346
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 5.28 KB | None | 0 0
  1. <?php
  2.  
  3. /*
  4. __PocketMine Plugin__
  5. name=PMFdecoder
  6. description=Decode PMF plugins
  7. version=2.0
  8. author=wies
  9. class=PMFdecoder
  10. apiversion=9,10,11
  11. */
  12.                
  13. class PMFdecoder implements Plugin{
  14.         private $api;
  15.         public function __construct(ServerAPI $api, $server = false){
  16.                 $this->api = $api;
  17.         }
  18.        
  19.         public function init(){
  20.                 $this->api->console->register('pmfdecode', 'Decode a pmf plugin', array($this, 'command'));
  21.         }
  22.        
  23.         public function command($cmd, $args, $issuer){
  24.                 if($issuer !== 'console'){
  25.                         return 'Must be run on the console';
  26.                 }
  27.                 if(!isset($args[0])){
  28.                         return 'Usage: /pmfdecode <classname> [variableRenaming]';
  29.                 }
  30.                 $renameVariables = false;
  31.                 if(isset($args[1]) and $args[1] == true or $args[1] == 1) $renameVariables = true;
  32.                 $classname = strtolower(trim($args[0]));
  33.                 return $this->decompile($classname, $renameVariables);
  34.         }
  35.        
  36.         private function decompile($classname, $variableRenaming){
  37.                 $info = $this->api->plugin->getInfo($classname);
  38.                 if($info === false){
  39.                         $output = 'The plugin class '.$classname." does not exist\n";
  40.                         $output .= "Here is a list of the classes of the plugins:\n";
  41.                         $list = $this->api->plugin->getList();
  42.                         foreach($list as $key => $val){
  43.                                 $output .= 'Plugin '.$val['name'].' has class: '.$val['class']."\n";
  44.                         }
  45.                         return $output;
  46.                 }
  47.                 $info = $info[0];
  48.                 $data = $info['code'];
  49.                 $src = token_get_all('<?php '.$data);
  50.                 $code = '';
  51.                 $variables = array();
  52.                 $count = 1;
  53.                 foreach($src as $index => $tag){
  54.                         if(!is_array($tag)){
  55.                                 $code .= $tag;
  56.                         }else{
  57.                                 switch($tag[0]){
  58.                                         case T_VARIABLE:
  59.                                                 if($variableRenaming === true){
  60.                                                         if(isset($variables[$tag[1]])){
  61.                                                                 $code .= $variables[$tag[1]];
  62.                                                                 break;
  63.                                                         }
  64.                                                         $v = '$variable'.$count;
  65.                                                         $code .= $v;
  66.                                                         $count++;
  67.                                                         $variables[$tag[1]] = $v;
  68.                                                 }else{
  69.                                                         $code .= $tag[1];
  70.                                                 }
  71.                                                 break;
  72.                                                
  73.                                         case T_CONSTANT_ENCAPSED_STRING:
  74.                                                 $data = $tag[1];
  75.                                                 while($pos = strpos($data, '\x')){
  76.                                                         $str = substr($data, $pos, 4);
  77.                                                         $value = chr(hexdec(substr($str, 2, 3)));
  78.                                                         $data = str_replace($str, $value, $data);
  79.                                                 }
  80.                                                 $code .= $data;
  81.                                                 break;
  82.                                                
  83.                                         case T_LOGICAL_AND:
  84.                                                 $code .= 'and';
  85.                                                 break;
  86.                                                
  87.                                         case T_LOGICAL_OR:
  88.                                                 $code .= 'or';
  89.                                                 break;
  90.                                                
  91.                                         default:
  92.                                                 $code .= $tag[1];
  93.                                                 break;  
  94.                                 }
  95.                         }
  96.                 }
  97.                 $code = str_replace(";", ";\r\n", $code);
  98.                 $code = str_replace("{", "{\r\n", $code);
  99.                 $code = str_replace("}", "}\r\n", $code);
  100.                 $code = "<?php
  101.  
  102. /*
  103. __PocketMine Plugin__
  104. name=".$info['name']."
  105. description=
  106. version=".$info['version']."
  107. author=".$info['author']."
  108. class=".$info['class']."
  109. apiversion=".$info['apiversion']."
  110. */
  111.  
  112. ".substr($code, 5);
  113.                 file_put_contents($this->api->plugin->configPath($this).$info['name'].'.php', $code);
  114.                 return 'The plugin '.$classname.' is decompiled';
  115.         }
  116.        
  117.         public function __destruct(){}
  118.  
  119. }
  120. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement