Created
October 19, 2014 08:45
-
-
Save drkameleon/1afb267c6fbdb2bef9f2 to your computer and use it in GitHub Desktop.
HTML::Obfuscator
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env php | |
<?php | |
/********************************************* | |
HTML::Obfuscator | |
For PHP | |
Copyright (c) 2014, Dr.Kameleon | |
********************************************* | |
Requirements: | |
node packer module | |
install: sudo npm install -g packer | |
Usage: | |
php htmlobf.php myfile.html | |
*********************************************/ | |
if (!(isset($argv[1]))) die("HTML::Obfuscator: No input file specified\n"); | |
$input = $argv[1]; | |
$path_parts = pathinfo($input); | |
$filename = $path_parts["filename"]; | |
// Get HTML | |
$c = file_get_contents($input); | |
// Char Encode Contents | |
$obf = "s=["; | |
$chars = str_split($c); | |
foreach ($chars as $k=>$char) | |
{ | |
$obf .= ord($char); | |
if ($k!=count($chars)-1) $obf .= ","; | |
} | |
$obf .= "];for (var c=0; c<s.length; c++) { document.write(String.fromCharCode(s[c])); }"; | |
// Write it | |
file_put_contents("$filename.obf.js", $obf); | |
// Pack it | |
$packed = exec("packer -i $filename.obf.js -b -s true"); | |
// Delete leftovers | |
unlink("$filename.obf.js"); | |
// Re-HTML it | |
$html = "<script>".$packed."</script>"; | |
// Re-write it | |
file_put_contents("$filename.html", $html); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment