import hashlib
from hashlib import md5
from urllib.parse import urlencode
from copy import deepcopy
import requests
import time
import json
import random
import uuid
def md5_(char: str or int or float):
char = str(char)
m = md5()
m.update(char.encode('utf8'))
return m.hexdigest()
class Tmp:
@staticmethod
def reverse(num):
tmp_string = hex(num)[2:]
if len(tmp_string) < 2:
tmp_string = '0' + tmp_string
return int(tmp_string[1:] + tmp_string[:1], 16)
@staticmethod
def RBIT(num):
result = ''
tmp_string = bin(num)[2:]
while len(tmp_string) < 8:
tmp_string = '0' + tmp_string
for i in range(0, 8):
result = result + tmp_string[7 - i]
return int(result, 2)
@staticmethod
def hex2string(num):
tmp_string = hex(num)[2:]
if len(tmp_string) < 2:
tmp_string = '0' + tmp_string
return tmp_string
def encryption(self):
tmp = ''
hex_zu = []
for i in range(0, 256):
hex_zu.append(i)
for i in range(0, 256):
if i == 0:
A = 0
elif tmp:
A = tmp
else:
A = hex_zu[i - 1]
B = self.hex_str[i % 8]
if A == 85:
if i != 1:
if tmp != 85:
A = 0
C = A + i + B
while C >= 256:
C = C - 256
if C < i:
tmp = C
else:
tmp = ''
D = hex_zu[C]
hex_zu[i] = D
return hex_zu
def initialize(self, debug, hex_zu):
tmp_add = []
tmp_hex = deepcopy(hex_zu)
for i in range(self.length):
A = debug[i]
if not tmp_add:
B = 0
else:
B = tmp_add[-1]
C = hex_zu[i + 1] + B
while C >= 256:
C = C - 256
tmp_add.append(C)
D = tmp_hex[C]
tmp_hex[i + 1] = D
E = D + D
while E >= 256:
E = E - 256
F = tmp_hex[E]
G = A ^ F
debug[i] = G
return debug
def handle(self, debug):
for i in range(self.length):
A = debug[i]
B = Tmp.reverse(A)
C = debug[(i + 1) % self.length]
D = B ^ C
E = Tmp.RBIT(D)
F = E ^ self.length
G = ~F
while G < 0:
G += 4294967296
H = int(hex(G)[-2:], 16)
debug[i] = H
return debug
def main(self):
result = ''
for item in self.handle(self.initialize(self.debug, self.encryption())):
result = result + Tmp.hex2string(item)
return '0404{}{}0001{}'.format(Tmp.hex2string(self.hex_str[7]), Tmp.hex2string(self.hex_str[3]), result)
def __init__(self, debug):
self.length = 20
self.debug = debug
self.hex_str = [30, 0, 224, 228, 147, 69, 1, 208]
class Decode_Android_0408:
@staticmethod
def hex_string(num):
tmp_string = hex(num)[2:]
if len(tmp_string) < 2:
tmp_string = '0' + tmp_string
return tmp_string
@staticmethod
def reverse(num):
tmp_string = Decode_Android_0408.hex_string(num)
return int(tmp_string[1:] + tmp_string[:1], 16)
@staticmethod
def RBIT(num):
result = ''
tmp_string = bin(num)[2:]
while len(tmp_string) < 8:
tmp_string = '0' + tmp_string
for i in range(0, 8):
result = result + tmp_string[7 - i]
return int(result, 2)
@staticmethod
def X_Gorgon(url, data='', cookie=''):
param = url.split('?')[-1]
gorgon = ''
url_md5 = md5(bytearray(param, 'utf-8')).hexdigest()
gorgon += url_md5
if data:
data_md5 = md5(bytearray(data, 'utf-8')).hexdigest()
gorgon += data_md5
else:
gorgon += '00000000000000000000000000000000'
if cookie:
cookie_md5 = md5(bytearray(cookie, 'utf-8')).hexdigest()
gorgon += cookie_md5
else:
gorgon += '00000000000000000000000000000000'
gorgon += '00000000000000000000000000000000'
return Decode_Android_0408.calc_xg(gorgon)
@staticmethod
def calc_xg(data):
ts = int(time.time())
len = 0x14
key = [0xDF, 0x77, 0xB9, 0x40, 0xb9, 0x9b, 0x84, 0x83, 0xd1, 0xb9, 0xcb, 0xd1, 0xf7, 0xc2, 0xb9, 0x85, 0xc3, 0xd0, 0xfb, 0xc3]
param_list = []
for i in range(0, 12, 4):
temp = data[8 * i: 8 * (i + 1)]
for j in range(4):
H = int(temp[j * 2:(j + 1) * 2], 16)
param_list.append(H)
param_list.extend([0x0, 0x6, 0xB, 0x1C])
H = int(hex(ts), 16)
param_list.append((H & 0xFF000000) >> 24)
param_list.append((H & 0x00FF0000) >> 16)
param_list.append((H & 0x0000FF00) >> 8)
param_list.append((H & 0x000000FF) >> 0)
eor_result_list = []
for A, B in zip(param_list, key):
eor_result_list.append(A ^ B)
for i in range(len):
C = Decode_Android_0408.reverse(eor_result_list[i])
D = eor_result_list[(i + 1) % len]
E = C ^ D
F = Decode_Android_0408.RBIT(E)
H = ((F ^ 0xFFFFFFFF) ^ len) & 0xFF
eor_result_list[i] = H
result = ''
for param in eor_result_list:
result += Decode_Android_0408.hex_string(param)
xgorgon = '0408b0d30000' + result
return xgorgon, str(ts)
class Decode_Android_0404:
@staticmethod
def X_Gorgon(url, data='', cookie='', model='utf-8'):
param = url.split('?')[-1]
gorgon = []
Khronos = hex(int(time.time()))[2:]
url_md5 = md5(bytearray(param, 'utf-8')).hexdigest()
for i in range(0, 4):
gorgon.append(int(url_md5[2 * i: 2 * i + 2], 16))
if data:
if model == 'utf-8':
data_md5 = md5(bytearray(data, 'utf-8')).hexdigest()
for i in range(0, 4):
gorgon.append(int(data_md5[2 * i: 2 * i + 2], 16))
elif model == 'octet':
data_md5 = md5(data).hexdigest()
for i in range(0, 4):
gorgon.append(int(data_md5[2 * i: 2 * i + 2], 16))
else:
for i in range(0, 4):
gorgon.append(0)
if cookie:
cookie_md5 = md5(bytearray(cookie, 'utf-8')).hexdigest()
for i in range(0, 4):
gorgon.append(int(cookie_md5[2 * i: 2 * i + 2], 16))
else:
for i in range(0, 4):
gorgon.append(0)
for i in range(0, 4):
gorgon.append(0)
for i in range(0, 4):
gorgon.append(int(Khronos[2 * i: 2 * i + 2], 16))
return Tmp(gorgon).main(), str(int(Khronos, 16))
class DeviceRegister2:
@staticmethod
def get_md5(data):
return hashlib.new('md5', data.encode('utf-8')).hexdigest()
@staticmethod
def get_x_ss_stub(body):
return DeviceRegister2.get_md5(body).upper()
@staticmethod
def getCpuModel():
a = {
'骁龙200': ['MSM8x25Q', 'MSM8x10', 'MSM8x12', 'MSM8208', 'MSM8909', 'MSM8909'],
'骁龙400': ['MSM8940', 'MSM8937', 'MSM8920', 'MSM8917', 'MSM8916', 'MSM8x30'],
'骁龙600/700': ['MSM8976', 'MSM8956', 'MSM8953', 'MSM8952', 'MSM8939', 'APQ8064T', 'MSM8936'],
'骁龙800': ['MSM8974', 'MSM8x74AA', 'MSM8x74AB', 'MSM8x74AC', 'APQ8084', 'MSM8992', 'MSM8994',
'MSM8996', 'MSM8998']
}
b = a[list(a.keys())[random.randint(0, len(a) - 1)]]
return b[random.randint(0, len(b) - 1)]
@staticmethod
def get_phone_model(br