Skip to content

Instantly share code, notes, and snippets.

@georgejecook
Created January 16, 2020 14:17
Show Gist options
  • Save georgejecook/b7142c44ddf42b147a9cc9e5f62d73d7 to your computer and use it in GitHub Desktop.
Save georgejecook/b7142c44ddf42b147a9cc9e5f62d73d7 to your computer and use it in GitHub Desktop.
const path = require('path');
const fs = require('fs-extra');
/*
some roku libraries obfuscate the code in their player.
We can deobfuscate a bunch of the code with these functions
*/
export function Chr(code) {
var num = 0;
if (code.substring(0, 2) === '&H') {
var hexValue = code.substring(2, code.length);
num = parseInt(hexValue, 16);
} else {
num = parseInt(code);
}
return String.fromCharCode(num);
}
export function deObfuscateFile(text) {
var regex = /(?:Chr\()([a-z|A-Z|0-9|&]*)(?:\)\+*)/gim;
var newText = text.replace(regex, (v0, v1) => {
return Chr(v1);
});
return newText;
}
export function deObfuscate() {
//this is a debug script it's
const glob = require('glob-all');
var outDir = `PATH/component-src-deobfuscated`;
var srcDir = 'PATH/component-src';
fs.removeSync(outDir);
fs.mkdir(outDir);
fs.copySync(srcDir, outDir);
process.chdir(outDir);
console.log(`processing out dir ${outDir}`);
let files = glob.sync(['**/*.brs'], { cwd: outDir });
for (const file of files) {
var fullPath = path.resolve(file);
console.log('found file ' + fullPath);
let text = fs.readFileSync(fullPath, 'utf8');
text = deObfuscateFile(text);
fs.writeFileSync(fullPath, text, 'utf8');
}
console.log(`files are in ${outDir}`);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment