Created
June 3, 2015 06:28
-
-
Save Gargaj/81e63fd2b478180273ef to your computer and use it in GitHub Desktop.
Data extractor for the Rage demos "Reanim8r" and "Robotnik"
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
function unpackR8($data) | |
{ | |
$ret = ""; | |
for ($x = 0; $x < strlen($data);) | |
{ | |
$control = ord($data{$x++}); | |
for ($bit = 0; $bit < 8; $bit++) | |
{ | |
if (!($control & (1 << $bit))) | |
{ | |
$ret .= $data{$x++}; // copy | |
} | |
else | |
{ | |
$c1 = ord($data{$x++}); | |
$c2 = ord($data{$x++}); | |
$c = ($c1 >> 4) + 2; | |
for($i = 0; $i < $c; $i++) | |
$ret .= substr($ret, -($c2 + 1 + (($c1 & 0x0F) << 8)), 1); | |
} | |
} | |
} | |
return $ret; | |
} | |
//$f = file_get_contents("reanim8r.exe"); | |
$f = file_get_contents("robotnik.exe"); | |
if (!$f) exit(); | |
list(,$dataLen) = unpack("L",substr($f,-4)); | |
$ofs = strlen($f) - $dataLen; | |
while($ofs < strlen($f) - 4) | |
{ | |
$fn = trim(substr($f,$ofs,12)); | |
$ofs += 12; | |
list(,$unkW) = unpack("S",substr($f,$ofs,2)); $ofs += 2; // is packed | |
list(,$unk0) = unpack("L",substr($f,$ofs,4)); $ofs += 4; // unpacked length | |
list(,$unk1) = unpack("L",substr($f,$ofs,4)); $ofs += 4; // offset | |
list(,$unk2) = unpack("L",substr($f,$ofs,4)); $ofs += 4; // packed length | |
printf("%15s %04X %08X %08X %08X\n",$fn,$unkW,$unk0,$unk1,$unk2); | |
$pData = substr($f,strlen($f) - $unk1,$unk2); | |
if ($unkW) | |
$pData = unpackR8($pData); | |
@mkdir("rip"); | |
file_put_contents("rip/".$fn,$pData); | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment