newbtophp Posted September 29, 2009 Share Posted September 29, 2009 Im stuck and in need of help. I have a file and for example contains: <?php $test = "variable"; function rrandom($input){ ... return $output; } eval(base64_decode("ZWNobyAieWF5Ijs=")); ?> If I run the file through my code, its meant to decode and output: <?php $test = "variable"; function rrandom($input){ ... return $output; } echo "yay"; ?> This is my code: if (preg_match_all('/"([^"]+)"/Umis', $file, $match)) { //Base64 decode the code within the quotes $file2 = base64_decode($match[0][1]); } //Here it dont replace the eval statement with the decoded base64, instead it just replaces the outer quotes $toreplace = array('eval(base64_decode("', '"));'); $file = str_replace($toreplace, "$file2", $file); //echo the output echo($file); But I get: <?php $test = "variable"; function rrandom($input){ ... return $output; } //The $file2 decode doesnt replace it? ZWNobyAieWF5Ijs= ?> Link to comment https://forums.phpfreaks.com/topic/175977-solved-struggling-to-replace/ Share on other sites More sharing options...
newbtophp Posted September 29, 2009 Author Share Posted September 29, 2009 Oops very sorry i hit the submit button twice accidentally Link to comment https://forums.phpfreaks.com/topic/175977-solved-struggling-to-replace/#findComment-927274 Share on other sites More sharing options...
salathe Posted September 29, 2009 Share Posted September 29, 2009 The replacement could be done pretty easily with preg_replace_callback. Something like: echo preg_replace_callback( '#\beval\(base64_decode\("([a-zA-Z0-9+/]+=*)"\)\);#', function ($m) { return base64_decode($m[1]); }, $file ); Note: The anonymous function is only available as of PHP 5.3, prior to that you could either use a normal named function or create_function (e.g. create_function('$m', 'return base64_decode($m[1]);')) Link to comment https://forums.phpfreaks.com/topic/175977-solved-struggling-to-replace/#findComment-927337 Share on other sites More sharing options...
newbtophp Posted September 30, 2009 Author Share Posted September 30, 2009 I've tried your code and it returns with syntax errors like: "unexpected T_FUNCTION" and "unexpected ;"... Im running php 5. Link to comment https://forums.phpfreaks.com/topic/175977-solved-struggling-to-replace/#findComment-927733 Share on other sites More sharing options...
salathe Posted October 1, 2009 Share Posted October 1, 2009 Please read the note that was attached to my post. Link to comment https://forums.phpfreaks.com/topic/175977-solved-struggling-to-replace/#findComment-928516 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.