Skip to content

Instantly share code, notes, and snippets.

@esterTion
Last active November 4, 2019 08:37
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 esterTion/989b30794ef6111dc0daf59165e15249 to your computer and use it in GitHub Desktop.
Save esterTion/989b30794ef6111dc0daf59165e15249 to your computer and use it in GitHub Desktop.
<?php
// https://store.steampowered.com/app/1044620/
require_once 'UnityBundle.php';
chdir(__DIR__);
$f = fopen('patch.dat', 'r');
$head = fread($f, 1024);
$heads = new MemoryStream($head);
$heads->littleEndian = true;
$heads->position = 4*4;
for ($itemCount=0,$i=4;$i<255;$i++) {
$itemCount += $heads->long;
}
$itemCount = int($itemCount);
echo "Items count: $itemCount\n";
//fseek($f, 0);
$fileInfos = fread($f, 16*$itemCount);
$heads->position = 212;
$fileInfos = dd($fileInfos, 16*$itemCount, $heads->long);
$fileInfos = array_values(unpack('V*', $fileInfos));
$firstFileOffset = $fileInfos[3];
$fileNamesLen = $firstFileOffset - (1024 + 16 * $itemCount);
$fileNames = fread($f, $fileNamesLen);
$heads->position = 92;
$fileNames = new MemoryStream(dd($fileNames, $fileNamesLen, $heads->long));
$map = [];
for ($j=0; $j<$itemCount; $j++) {
$key = $fileNames->string;
$map[$key] = [
'position' => $fileInfos[4 * $j + 3],
'length' => $fileInfos[4 * $j + 1],
'key' => $fileInfos[4 * $j + 2]
];
}
print_r($map);
function dd($b, int $L, int $k) {
$array = gk($k);
for ($i=0; $i < $L; $i++) {
$b2 = ord($b[$i]);
$b2 ^= $array[$i%253];
$b2 += 3;
$b2 += $array[$i%89];
$b2 ^= 153;
$b[$i] = chr($b2 & 0xff);
}
return $b;
}
function gk(int $k0) {
$itemCount = int($k0 * 7391 + 42828);
$firstFileOffset = int($itemCount << 17 ^ $itemCount);
$b = [];
for ($i=0; $i<256; $i++) {
$itemCount -= $k0; $itemCount = int($itemCount);
$itemCount += $firstFileOffset; $itemCount = int($itemCount);
$firstFileOffset = $itemCount + 56;
$itemCount *= $firstFileOffset & 239; $itemCount = int($itemCount);
$b[$i] = $itemCount & 0xff;
$itemCount >>= 1; $itemCount = int($itemCount);
}
return $b;
}
function int(int $d) {return $d&0xffffffff;}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment