Skip to content

Instantly share code, notes, and snippets.

@lawvs
Created April 1, 2022 16:01
Show Gist options
  • Save lawvs/a4c504f0a40204285a0d50c37cbb28a0 to your computer and use it in GitHub Desktop.
Save lawvs/a4c504f0a40204285a0d50c37cbb28a0 to your computer and use it in GitHub Desktop.
Recovery file from .CHK
const fs = require("fs");
const { exec } = require("child_process");
const files = fs.readdirSync(__dirname);
files
.filter((i) => i.endsWith(".CHK"))
.forEach((i) => {
exec("file " + i, (err, stdout, stderr) => {
if (stdout.includes("JPEG")) {
exec("mv " + i + " " + i.replace(".CHK", ".jpg"));
return;
}
if (stdout.includes("PNG")) {
exec("mv " + i + " " + i.replace(".CHK", ".png"));
return;
}
if (stdout.includes("MP4")) {
exec("mv " + i + " " + i.replace(".CHK", ".mp4"));
return;
}
if (stdout.includes("Excel")) {
exec("mv " + i + " " + i.replace(".CHK", ".xls"));
return;
}
if (stdout.includes("PDF")) {
exec("mv " + i + " " + i.replace(".CHK", ".pdf"));
return;
}
if (stdout.includes("executable")) {
exec("mv " + i + " " + i.replace(".CHK", ".exe"));
return;
}
console.log(stdout);
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment