blob: a771cd5ecafb5e99c60f15f41079c962fa73af38 (
plain) (
blame)
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
|
import network_packet_pb2 as network_packet
from commands import buddy_list_notify_command_pb2 as buddy_list_notify_command
import command_pb2 as command
request = network_packet.NetworkPacket()
request.object_id.short_object_id = 0xFF
request.type = command.BUDDYLISTNOTIFYCMD
request.buddy_list_notify_command.CopyFrom(
buddy_list_notify_command.BuddyListNotifyCommand()
)
request.buddy_list_notify_command.buddy_name = "Whirl"
request.buddy_list_notify_command.logged_on = 1
request.length = 3 + len(request.buddy_list_notify_command.buddy_name) + 1 + 1
print(f"SerializeToString(): {request.SerializeToString()}")
print(f"request.WhichOneof('command'): {request.WhichOneof('command')}")
print()
deserialised_request = network_packet.NetworkPacket()
deserialised_request.ParseFromString(request.SerializeToString())
print(f"deserialised_request.length: {deserialised_request.length}")
print(
f"deserialised_request.short_object_id: {deserialised_request.object_id.short_object_id}"
)
print(f"deserialised_request.type: {deserialised_request.type}")
print(
f"deserialised_request.buddy_list_notify_command.buddy_name: {deserialised_request.buddy_list_notify_command.buddy_name}"
)
print(
f"deserialised_request.buddy_list_notify_command.logged_on: {deserialised_request.buddy_list_notify_command.logged_on}"
)
print()
def parse_network_packet(raw_bytes):
net_packet = network_packet.NetworkPacket()
net_packet.length = raw_bytes[0]
net_packet.object_id.short_object_id = raw_bytes[1]
net_packet.type = raw_bytes[2]
command_type = net_packet.type
match command_type:
case command.BUDDYLISTNOTIFYCMD:
print("This is a BuddyListNotifyCommand.")
buddy_list_notify_cmd = buddy_list_notify_command.BuddyListNotifyCommand()
buddy_list_notify_cmd.buddy_name = raw_bytes[4:-1].decode("utf-8")
buddy_list_notify_cmd.logged_on = raw_bytes[-1]
net_packet.buddy_list_notify_command.CopyFrom(buddy_list_notify_cmd)
case command.PROPREQCMD:
print("This is a PropertyRequestCommand.")
case _:
print(f"This is an unknown command type: {command_type}.")
return net_packet
print(parse_network_packet(b"\x03\xff\x1e"))
print(parse_network_packet(b"\x03\x00\x1a"))
print(parse_network_packet(b"\x03\xff\x0a"))
bytes = b"\xff"
bytes += command.BUDDYLISTNOTIFYCMD.to_bytes(1, byteorder="big")
bytes += b"\x05" + b"Whirl"
bytes += b"\x01"
bytes = bytes[0:1] + bytes
print(parse_network_packet(bytes))
|