Skip to content

Instantly share code, notes, and snippets.

@Gargaj
Created June 3, 2015 06:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Gargaj/81e63fd2b478180273ef to your computer and use it in GitHub Desktop.
Save Gargaj/81e63fd2b478180273ef to your computer and use it in GitHub Desktop.
Data extractor for the Rage demos "Reanim8r" and "Robotnik"
<?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