Skip to content

Instantly share code, notes, and snippets.

@Fuitad
Created September 24, 2017 18:30
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Fuitad/f376e997d29ff61bf951fc3760d9398e to your computer and use it in GitHub Desktop.
Save Fuitad/f376e997d29ff61bf951fc3760d9398e to your computer and use it in GitHub Desktop.
FFRK JS unpacker
<?php
if (count($argv) <= 1) {
exit();
}
array_shift($argv);
foreach ($argv as $jsFile) {
if (!file_exists($jsFile)) {
echo "${jsFile} does not exist.\n";
continue;
}
echo "${jsFile}\n";
$js = file_get_contents($jsFile);
$isJp = (stripos($jsFile, '_jp') !== false);
$target = __DIR__ . '/storage/dev' . ($isJp ? '_jp' : '') . '/dff/static/js/';
var_dump(strlen($js));
if (!preg_match_all('/(define\("[\w\/]+", .*?(?:\)|\}))(?=((, |\n)define|;?\Z))/ism', $js, $m)) {
echo "no define block found in file, skipping.\n";
continue;
}
echo sprintf("Extracting %d blocks.\n", count($m[1]));
foreach ($m[1] as $codeblock) {
if (!preg_match('/define\("(.*?)",/i', $codeblock, $name)) {
//invalid block
continue;
}
$file = $target . $name[1] . ".js";
if (!file_exists(dirname($file))) {
mkdir(dirname($file), 0777, true);
}
file_put_contents($file, "/* Original file ${jsFile} */\n" . $codeblock);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment