3v4l.org

run code in 200+ php & hhvm versions
Bugs & Features
<?php # set up a new session $imei = '000999999999999999'; $source_id = '0000000099'; $source_key = "\x24\x73\xAB\x7F\x88\x4F\x4B\x2F"; $host = $argv[1]; $port = $argv[2]; # set up a new session $c_request = $imei."".$source_id; $enc_c_request = Crypt::encrypt( $c_request, Crypt::COMMON_KEY); $url = 'http://'.$host.':'.$port.'/sw-system/sloc8r/public/c.php'; //$url = 'http://'.$host.':'.$port.'/V2.7.2/c.php'; $response = send_request($url, $enc_c_request); $result = split(',', $response,3); $session_data = split(',', Crypt::decrypt($result[2], $source_key), 2); $session_id = sprintf("%020d", $session_data[0]); $session_key = $session_data[1]; //print "session_id: $session_id\n"; # send a location block $time = time(); $dataFiles = scandir ($argv[3]); foreach($dataFiles as $dataFile){ if(strlen($dataFile)<5) continue; print_r($dataFile);echo "\n"; $reqData = fopen($argv[3]."/".$dataFile, "r"); $file_name = preg_replace('/[^0-9]/', '', $dataFile); $url = 'http://'.$host.':'.$port.'/sw-system/sloc8r/public/d.php'; //$url = 'http://'.$host.':'.$port.'/V2.7.2/d.php'; $sleepTime = 3; if (isset($argv[4])){ $sleepTime = $argv[4]; } while (!feof($reqData)){ $line = fgets($reqData); if(strlen($line)<120) continue; //echo $line."\n"; $line = explode(",",$line,3); //print_r($line);exit; $d_request_data = $line[2]; //$d_request_data = $line; $enc_d_request = Crypt::encrypt(gzencode($d_request_data), $session_key); $request = $session_id.$enc_d_request; #print "request: $request\n"; file_put_contents('/tmp/request.post', $request); # response from d.php $response = send_request($url, $request); #print "raw response:\n"; //var_dump($response); #print "\n\n"; if (preg_match('/^\$UP/', $response)){ $uncompressed = $response; } else { $decrypted = Crypt::decrypt($response, $session_key); $stripped = substr($decrypted,10,-8); $uncompressed = gzinflate( $stripped ); } $d_response = split(',',$uncompressed); # var_dump($d_response); if ($d_response[0] == "\$UP" && ($d_response[1] == "1")){ print $file_name.",$uncompressed\n"; } else { print "response: ".implode(',',$d_response)."\n"; } //print "sleeping for $sleepTime seconds\n"; sleep($sleepTime); } } ############################################## function printStrHex($string) { echo "begin hex dump\n"; for ($i = 0; $i < strlen($string); $i++) { echo dechex(ord($string[$i])); } echo "\nEnd hex dump\n"; } function send_request($url, $request) { $options = array( 'http' => array( 'header' => "Content-type: application/x-www-form-urlencoded\r\n" . "Content-Length: " . strlen($request) . "\r\n" . "Expect: \r\n", 'method' => 'POST', 'content' => $request, ), ); $context = stream_context_create($options); if ( $result = file_get_contents($url, false, $context) ) { return $result; } else { print "Couldnt conenct to $url ($result)\n"; exit(2); } } class Crypt { const COMMON_KEY = "\xb5\xfb\xf4\x70\xd8\xd4\xf9\xb9"; static public function decrypt($str, $key) { $str = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $key, $str, MCRYPT_MODE_ECB); $pad = ord($str[($len = strlen($str)) - 1]); //last byte contains amount of padding applied return substr($str, 0, strlen($str) - $pad); } static public function encrypt($str, $key) { $block = mcrypt_get_block_size('rijndael_128', 'ecb'); $pad = $block - (strlen($str) % $block); $str .= str_repeat(chr($pad), $pad); return mcrypt_encrypt(MCRYPT_RIJNDAEL_128, $key, $str, MCRYPT_MODE_ECB); } } ?>
based on ibh47
Output for 7.0.0 - 7.3.0rc3
Notice: Undefined offset: 1 in /in/b2W1u on line 8 Notice: Undefined offset: 2 in /in/b2W1u on line 9 Fatal error: Uncaught Error: Call to undefined function mcrypt_get_block_size() in /in/b2W1u:148 Stack trace: #0 /in/b2W1u(14): Crypt::encrypt('000999999999999...', '\xB5\xFB\xF4p\xD8\xD4\xF9\xB9') #1 {main} thrown in /in/b2W1u on line 148
Process exited with code 255.
Output for hhvm-3.15.4
Notice: Undefined index: 1 in /in/b2W1u on line 8 Notice: Undefined index: 2 in /in/b2W1u on line 9 Warning: Failed to open http://:/sw-system/sloc8r/public/c.php (Could not resolve host: ) in /in/b2W1u on line 126 Couldnt conenct to http://:/sw-system/sloc8r/public/c.php ()
Process exited with code 2.
Output for 5.6.0 - 5.6.30
Notice: Undefined offset: 1 in /in/b2W1u on line 8 Notice: Undefined offset: 2 in /in/b2W1u on line 9 Fatal error: Call to undefined function mcrypt_get_block_size() in /in/b2W1u on line 148
Process exited with code 255.