Advertisement
IDDQD-IDKFA

.unitypackage unpacker

May 9th, 2020
987
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 0.91 KB | None | 0 0
  1. <?php
  2.  
  3. $content = cmd('tar tf %s', [$argv[1]]);
  4.  
  5. $tree = [];
  6. foreach ($content as $fn) {
  7.     if (strpos($fn, '/')) {
  8.         list($d, $f) = explode('/', $fn, 2);
  9.     } else {
  10.         $f = '';
  11.         $d = $fn;
  12.     }
  13.     if ($f) {
  14.         $tree[$d][] = $f;
  15.     } else {
  16.         $tree[$d] = [];
  17.     }
  18. }
  19.  
  20. foreach ($tree as $d => $c) {
  21.  
  22.     $e = cmd('tar xf %s -O %s', [$argv[1], "{$d}/pathname"]);
  23.     echo $e[0], PHP_EOL;
  24.  
  25.     if (in_array('asset', $c)) {
  26.         $pi = pathinfo($e[0]);
  27.         @mkdir($pi['dirname'], 0755, true);
  28.         cmd('tar xf %s -O %s > %s', [$argv[1], "{$d}/asset", $e[0]]);
  29.     } else {
  30.         @mkdir($e[0], 0755, true);
  31.     }
  32. }
  33.  
  34. function cmd($c, $args)
  35. {
  36.     $encoded_args = array_map(
  37.         function ($a) {
  38.             return escapeshellarg($a);
  39.         },
  40.         $args
  41.     );
  42.  
  43.     exec(vsprintf($c, $encoded_args), $output);
  44.    
  45.     return $output;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement