From 43bc3c7b25b91e67f517862493acb3bc89bba32d Mon Sep 17 00:00:00 2001 From: "Dylan K. Taylor" Date: Thu, 1 Dec 2022 19:35:59 +0000 Subject: [PATCH] Added tool to dump JSON contents of encoded crashdump data --- tools/decode-crashdump.php | 87 ++++++++++++++++++++++++++++++++++++++ 1 file changed, 87 insertions(+) create mode 100644 tools/decode-crashdump.php diff --git a/tools/decode-crashdump.php b/tools/decode-crashdump.php new file mode 100644 index 000000000..b73cc201f --- /dev/null +++ b/tools/decode-crashdump.php @@ -0,0 +1,87 @@ + $line){ + if(trim($line) === "===BEGIN CRASH DUMP==="){ + $start = $num + 1; + break; + } +} + +if($start === -1){ + fwrite(STDERR, "Crashdump encoded data not found in target file" . PHP_EOL); + exit(1); +} + +$data = array_slice($lines, $start); +array_pop($data); + +$zlibData = base64_decode(implode("", $data), true); +if($zlibData === false){ + fwrite(STDERR, "Invalid encoded data in crashdump" . PHP_EOL); + exit(1); +} +$decoded = zlib_decode($zlibData); +if($decoded === false){ + fwrite(STDERR, "Invalid compressed data in crashdump" . PHP_EOL); + exit(1); +} + +file_put_contents($output, json_encode(json_decode($decoded), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)); +echo "Wrote decoded crashdump to " . realpath($output) . PHP_EOL;