Fallout Shelter - Save Game File to JSON Decryption
<?php
/**
* Fallout Shelter - Save Game File to JSON Decryption
*/
/*
The save data is simply Rijndael CBC encrypted json using the passphrase "PlayerData" (without the quotes)
and the salt "tu89geji340t89u2" (without the quotes) stored in a file called Vault1.sav, Vault2.sav, or Vault3.sav
Locations:
Android = /sdcard/Android/data/com.bethsoft.falloutshelter/files/Vault*.sav
iOS = /private/var/mobile/Containers/Data/Application/*\/Documents/Vault*.sav
*/
define("SALT", "tu89geji340t89u2");
define("RAW_PASSPHRASE", "PlayerData");
function pad_str($s, $p = 16)
{
$pad_count = ($p - strlen($s) % $p);
return $s . ($pad_count * chr($pad_count));
}
function generate_passphrase($s)
{
while(strlen($s) < 8)
{
$s .= $s;
}
return hash_pbkdf2("sha1", substr(base64_encode($s), 0, 8), SALT, 1000, 32, true);
}
function encrypt_save($json_array)
{
return base64_encode(mcrypt_encrypt(MCRYPT_RIJNDAEL_128, generate_passphrase(RAW_PASSPHRASE), pad_str(json_encode($json_array)), MCRYPT_MODE_CBC, SALT));
}
function decrypt_save($save_data)
{
$decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, generate_passphrase(RAW_PASSPHRASE), base64_decode($save_data), MCRYPT_MODE_CBC, SALT);
if(substr($decrypted, -1) != "}")
{
$decrypted = rtrim($decrypted, substr($decrypted, -1));
}
return json_decode($decrypted);
}
$json = decrypt_save(file_get_contents("Vault1.sav"));
file_put_contents("test.sav", encrypt_save($json));