forked from sakib-773/TSun-FF-TCP-Bot
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.py
More file actions
57 lines (52 loc) · 2.09 KB
/
utils.py
File metadata and controls
57 lines (52 loc) · 2.09 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import binascii
import json
from Crypto.Cipher import AES
from Crypto.Util.Padding import pad
from google.protobuf.json_format import MessageToJson
import MajorLoginRes_pb2
from protobuf_decoder.protobuf_decoder import Parser
def encrypt_api(plain_text):
plain_text = bytes.fromhex(plain_text)
key = bytes([89, 103, 38, 116, 99, 37, 68, 69, 117, 104, 54, 37, 90, 99, 94, 56])
iv = bytes([54, 111, 121, 90, 68, 114, 50, 50, 69, 51, 121, 99, 104, 106, 77, 37])
cipher = AES.new(key, AES.MODE_CBC, iv)
cipher_text = cipher.encrypt(pad(plain_text, AES.block_size))
return cipher_text.hex()
def encrypt_packet(plain_text, key, iv):
plain_text = bytes.fromhex(plain_text)
cipher = AES.new(key, AES.MODE_CBC, iv)
cipher_text = cipher.encrypt(pad(plain_text, AES.block_size))
return cipher_text.hex()
def parse_my_message(serialized_data):
MajorLogRes = MajorLoginRes_pb2.MajorLoginRes()
MajorLogRes.ParseFromString(serialized_data)
jwt_token = MajorLogRes.jwt
key = MajorLogRes.ak
iv = MajorLogRes.aiv
timestamp = MajorLogRes.timestamp
return jwt_token, key, iv, timestamp
def get_available_room(input_hex):
try:
parsed_results = Parser().parse(input_hex)
parsed_results_objects = parsed_results
parsed_results_dict = parse_results(parsed_results_objects)
json_data = json.dumps(parsed_results_dict)
return json_data
except Exception as e:
print(f"Error in get_available_room: {e}")
return None
def parse_results(parsed_results):
result_dict = {}
for result in parsed_results:
field_data = {}
field_data["wire_type"] = result.wire_type
if result.wire_type == "varint":
field_data["data"] = result.data
if result.wire_type == "string":
field_data["data"] = result.data
if result.wire_type == "bytes":
field_data["data"] = result.data
elif result.wire_type == "length_delimited":
field_data["data"] = parse_results(result.data.results)
result_dict[result.field] = field_data
return result_dict