Created
December 9, 2015 11:53
-
-
Save 5l/105a8154d1789dccbd0c to your computer and use it in GitHub Desktop.
Decode CGSS packets (USER_ID, UDID, viewer_id, Response)
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
<?php | |
# Decode USER_ID, UDID | |
echo decode("USER_ID, UDID"); | |
# Decode Response | |
echo decrypt("Response", decode("UDID")); | |
# Decode viewer_id | |
echo deviewer_id("viewer_id"); | |
function decrypt($data, $IV){ | |
$dbase64 = base64_decode($data); | |
$key = substr($dbase64, -32); | |
$dbase64 = substr($dbase64, 0, -32); | |
$rtn = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $dbase64, MCRYPT_MODE_CBC, $IV); | |
$rtn = base64_decode($rtn); | |
return msgpack_unpack($rtn); | |
} | |
function decode($str){ | |
if($str == null || mb_strlen($str) < 4){ | |
return $str; | |
} | |
$s = substr($str, 0, 4); | |
$n = hexdec($s); | |
$text = ""; | |
$n2 = 2; | |
$text2 = substr($str, 4, mb_strlen($str) - 4); | |
for($i = 0; $i < mb_strlen($text2); $i++){ | |
$value = $text2[$i]; | |
if($n2 % 4 == 0){ | |
$text .= chr(ord($value) - 10); | |
} | |
$n2++; | |
if(mb_strlen($text) >= $n){ | |
break; | |
} | |
} | |
return str_replace("-", "", $text); | |
} | |
function decryptRJ256($key, $iv, $string_to_decrypt) | |
{ | |
$string_to_decrypt = base64_decode($string_to_decrypt); | |
$rtn = mcrypt_decrypt(MCRYPT_RIJNDAEL_256, $key, $string_to_decrypt, MCRYPT_MODE_CBC, $iv); | |
$rtn = rtrim($rtn, ""); | |
return($rtn); | |
} | |
function deviewer_id($data){ | |
$key = "s%5VNQ(H$&Bqb6#3+78h29!Ft4wSg)ex"; | |
$IV = substr($data, 0, 32); | |
$data = substr($data, 32); | |
return decryptRJ256($key, $IV, $data); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment