Advertisement
Guest User

Untitled

a guest
Jan 13th, 2014
466
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. // xmap_inst_v3.php
  4.  
  5. ini_set('memory_limit', '900M');
  6. ini_set('display_errors', '1');
  7.  
  8. $files = explode("\n", `dir /b /s *.xmap`);
  9. $section_const = "\x11\x11\x33\x33";
  10. $inst_code = "\xce\x50\x14\x83";
  11. $inst_token = "\x00\x00\x00\x00";
  12.  
  13. foreach ($files as $file)
  14. {
  15.     if (!is_file($file)) continue;
  16.     $data = file_get_contents($file);
  17.     if ($data !== false)
  18.     {
  19.         // parse section list
  20.         $loffset = fix_offset(substr($data, 0x40, 4));
  21.         while (substr($data, $loffset + 0xc, 4) == $section_const)
  22.         {
  23.             $code = substr($data, $loffset + 0x0, 4);
  24.             $ssize = parse_int(substr($data, $loffset + 0x4, 4));
  25.             $soffset = fix_offset(substr($data, $loffset + 0x8, 4));
  26.            
  27.             // parse inst section
  28.             if ($code == $inst_code)
  29.             {
  30.                 $size_parsed = 0;
  31.                 while ($size_parsed + 0x70 <= $ssize)
  32.                 {
  33.                     if (substr($data, $soffset + 0x0, 4) == $inst_token)
  34.                     {
  35.                         $h = "0x" . strtoupper( bin2hex(substr($data, $soffset + 0x4, 4)) );
  36.                         $x = parse_float(substr($data, $soffset + 0x10, 4));
  37.                         $y = parse_float(substr($data, $soffset + 0x14, 4));
  38.                         $z = parse_float(substr($data, $soffset + 0x18, 4));
  39.                         $rx = parse_float(substr($data, $soffset + 0x20, 4));
  40.                         $ry = parse_float(substr($data, $soffset + 0x24, 4));
  41.                         $rz = parse_float(substr($data, $soffset + 0x28, 4));
  42.                         $rw = parse_float(substr($data, $soffset + 0x2c, 4));
  43.                        
  44.                         // print
  45.                         printf("%.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %.4f, %s\r\n", $x, $y, $z, $rx, $ry, $rz, $rw, $h);
  46.                     }
  47.                    
  48.                     $soffset += 0x70;
  49.                     $size_parsed += 0x70;
  50.                 }
  51.             }
  52.            
  53.             $loffset += 0x10;
  54.         }
  55.     }
  56. }
  57.  
  58. // takes 0x50XXXXXX offset and fixes it to file offset
  59. function fix_offset($data)
  60. {
  61.     $data[0] = "\x00";
  62.     return 0x10 + array_pop(unpack("N", $data));
  63. }
  64.  
  65. function parse_int($data)
  66. {
  67.     return array_pop(unpack("N", $data));
  68. }
  69.    
  70. function parse_float($data)
  71. {
  72.     return array_pop(unpack("f", strrev($data)));
  73. }
  74.  
  75. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement