Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- function str_to_a32($b)
- {
- // Add padding, we need a string with a length multiple of 4
- $b = str_pad($b, 4 * ceil(strlen($b) / 4), "\0");
- return array_values(unpack('N*', $b));
- }
- function base64url_decode($data)
- {
- if (($s = (2 - strlen($data) * 3) % 4) < 2) $data .= substr(',,', $s);
- return base64_decode(strtr($data, '-_,', '+/='));
- }
- function a32_to_str($hex)
- {
- return call_user_func_array('pack', array_merge(array('N*'), $hex));
- }
- function aes128_cbc_decrypt($raw, $key)
- {
- $ivlen = openssl_cipher_iv_length($cipher="AES-128-CBC");
- $iv = str_repeat("\0",$ivlen);
- return openssl_decrypt($raw,$cipher, $key,OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
- }
- function aes128_cbc_decrypt1($raw, $key,$iv)
- {
- $ivlen = openssl_cipher_iv_length($cipher="AES-128-CTR");
- return openssl_decrypt($raw,$cipher, $key,OPENSSL_RAW_DATA|OPENSSL_ZERO_PADDING, $iv);
- }
- function mega($path,$paramm)
- {
- $curl = curl_init('https://g.api.mega.co.nz/cs');
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
- curl_setopt($curl, CURLOPT_HEADER, 0);
- if($paramm)
- {
- curl_setopt($curl, CURLOPT_POST, 1);
- curl_setopt($curl, CURLOPT_POSTFIELDS, $paramm);
- }
- $response = curl_exec($curl);
- $code = curl_getinfo($curl);
- curl_close($curl);
- return json_decode($response);
- }
- $jsondata = json_decode(file_get_contents("./data.json"));
- if(isset($_GET['pic']) && $_GET['pic'] != "" && array_key_exists($_GET['pic'], $jsondata->pics))
- {
- $data = explode("/",$jsondata->pics->{$_GET['pic']});
- $pic = explode("#", $data[count($data)-1]);
- $param = [];
- $param['a'] = 'g';
- $param['g'] = '1';
- $param['ssl'] = '2';
- $param['v'] = '2';
- $param['p'] = $pic[0];
- $key_plain = base64url_decode($pic[1]);
- $key = str_to_a32($key_plain);
- $m = mega('',json_encode([$param]));
- $enc = $m[0]->at;
- $enc = base64url_decode($enc);
- $iv = array($key[4], $key[5], 0, 0);
- if (count($key) != 4)
- {
- $key = array($key[0] ^ $key[4], $key[1] ^ $key[5], $key[2] ^ $key[6], $key[3] ^ $key[7]);
- }
- $url = $m[0]->g;
- $curl = curl_init();
- curl_setopt($curl, CURLOPT_URL, $url);
- curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
- curl_setopt($curl, CURLOPT_HEADER, false);
- $enc = curl_exec($curl);
- curl_close($curl);
- $iv = a32_to_str($iv);
- $raw = aes128_cbc_decrypt1($enc,a32_to_str($key),$iv);
- }
- else
- {
- $raw = "";
- }
- //Si no hemos obtenido ninguna imagen
- if($raw == "")
- {
- //Cargamos la imagen
- $source = imagecreatefromjpeg("placeholder.jpg");
- }
- //Si hemos obtenido una imagen
- else
- {
- //Convertimos la imagen en un objeto GD
- $source = imagecreatefromstring($raw);
- }
- //Obtenemos las dimensiones de la imagen
- $width = imagesx($source);
- $height = imagesy($source);
- //Cargamos el tamaño
- $size = $jsondata->default;
- if(isset($_GET['size']) && array_key_exists($_GET['size'], $jsondata->sizes))
- {
- $size = $_GET['size'];
- }
- //Establecemos las nuevas dimensiones
- $newwidth = $jsondata->sizes->{$size}->width;
- $newheight = $jsondata->sizes->{$size}->height;
- //Instanciamos una imagen vacía con las nuevas dimensiones
- $thumb = imagecreatetruecolor($newwidth, $newheight);
- // Copiamos resizeando la imagen en la nueva instancia
- imagecopyresized($thumb, $source, 0, 0, 0, 0, $newwidth, $newheight, $width, $height);
- // Cabecera html que indica que mandamos imagen
- header('Content-Type: image/jpeg');
- // Mostramos la imagen
- imagejpeg($thumb);
- ?>
Add Comment
Please, Sign In to add comment