Skip to content

Instantly share code, notes, and snippets.

@lvthinh1487
Last active December 16, 2018 07:05
Show Gist options
  • Save lvthinh1487/79272e0973e01a3999bf09dd00722922 to your computer and use it in GitHub Desktop.
Save lvthinh1487/79272e0973e01a3999bf09dd00722922 to your computer and use it in GitHub Desktop.
Decode DataLife Engine using nodejs + php (tested on DLE 11.2)
const fs = require('fs');
const path = require('path');
const exec = require('child_process').exec;
let dlePath = '/path/to/dle';
let index = 0;
let tmpFile = process.cwd() + '/tmp.php';
function readDirRecursively(dir) {
let files = [];
fs.readdirSync(dir).forEach(file => {
let tmpPath = `${dir}/${file}`;
if (fs.statSync(tmpPath).isFile() && file.slice(-4) === '.php') {
files.push(tmpPath);
}
if (fs.statSync(tmpPath).isDirectory()) {
files = files.concat(readDirRecursively(tmpPath));
}
});
return files;
}
function decode() {
let file = files[index];
if (!file) {
console.info('========================================================================');
console.info('Done!');
process.exit(0);
}
index++;
let content = fs.readFileSync(file).toString();
if (content.includes(';eval($_D')) {
console.info(`${index}. Decoding file: ${file}`);
fs.writeFile(tmpFile, content.replace(/__([A-Z]+)__/g, `'__BAKUP__$1__'`).replace(/eval\(\$_D\(\'([^\']+)\'\)\)/, "eval(str_replace('eval', 'echo', $_D('$1')))"), error => {
if (error) {
decode();
console.error(error);
console.info('Write tmp file Error');
return;
}
exec(`php ${tmpFile}`, (error, contentDecoded) => {
if (error) {
decode();
console.error(error);
return;
}
fs.writeFile(file, contentDecoded.replace(/'__BAKUP__([A-Z]+)__'/g, '__$1__')
.replace('?><?php', '<?php')
.replace('?><?PHP', '<?php')
.replace('<?PHP', '<?php'), err => {
if (err) {
decode();
console.error(err);
return;
}
decode();
console.info('\tDecoded file');
});
});
})
} else {
console.info(`${index}. Skip file: ${file}`);
decode();
}
}
const files = readDirRecursively(dlePath);
console.info(`Total files: ${files.length}`);
decode();
@moshenskyDV
Copy link

tested at 13.0 version. Still work))

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment