Skip to content

Instantly share code, notes, and snippets.

@idokd
Created October 31, 2021 13:42
Show Gist options
  • Select an option

  • Save idokd/1766df0e4daad53d3ac5830a98bc139b to your computer and use it in GitHub Desktop.

Select an option

Save idokd/1766df0e4daad53d3ac5830a98bc139b to your computer and use it in GitHub Desktop.
un-obfuscation
<?php
if ( !function_exists( 'str_ends_with' ) ) {
function str_ends_with( $str, $end ) {
return( @substr_compare( $str, $end, -strlen( $end ) ) == 0 );
}
}
function mocleanr( $filename, $replace = false ) {
if ( !is_dir( $filename ) ) {
moclean( $filename, $replace );
return;
}
$di = new RecursiveDirectoryIterator( $filename );
foreach ( new RecursiveIteratorIterator( $di ) as $filename => $file) {
if ( !str_ends_with( $filename, '.php' ) ) continue;
moclean( $filename, $replace );
}
}
function moclean( $filename, $replace = false ) {
if ( !str_ends_with( $filename, '.php' ) ) return;
$lines = file( $filename );
$re = '/(?s)\'(?:[^\'\\\\]|\\\\.)*\'|"(?:[^"\\\\]|\\\\.)*"/';
$fcontent = '';
print "processing: " . $filename . "\n";
foreach( $lines as $content ){
preg_match_all( $re, $content, $output );
if ( count( $output ) ) {
foreach ( $output[ 0 ] as $line ) {
if ( $line ) {
$rep = eval( 'return ' . $line . ';' );
$content = str_replace( $line, '"' . addslashes( $rep ) . '"', $content );
}
}
}
$fcontent .= $content;
}
if ( $replace ) {
file_put_contents( $filename, $fcontent );
} else {
print $filename . ':' . $fcontent;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment