-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathparser.py
146 lines (119 loc) · 4.27 KB
/
parser.py
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
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
#!/usr/bin/python3
# -*- coding: Utf-8 -*-
# Fichier : parser.py
import binascii, struct
SERVER_QUEUE = []
CLIENT_QUEUE = []
def h_NOP(data):
pass
#return data
def h_Timer1(data):
#print("deplacement -> %s" %(data.encode("hex")))
return data[1:]
def h_Timer2(data):
#print("deplacement -> %s" %(data.encode("hex")))
return data[1:]
def h_Movement(data): # Server
#print("deplacement -> %s" %(data.encode("hex")))
return data[4:]
def h_Attack(data): # Client
entityNumber = struct.unpack("H", data[1:3])[0]
print("Attaque l'entite identifie %i" %(entityNumber))
return data[5:]
def h_Spawn(data): # Server
entityNumber = struct.unpack("H", data[1:3])[0]
print("spawn -> %i" %(entityNumber))
return data[3:]
def h_GoToLoot(data): # Client
print("va loot -> %s" %(data.encode("hex")))
return data[2:]
def h_InfoLoot(data): # Server
bytesToProcess = data
print("Ouvre le loot -> %s" %(data.encode("hex")))
return data[23:]
def h_TakeItem(data): # Client
itemNumber = struct.unpack("B", data[1])[0]
itemQuantity = struct.unpack("I", data[2:6])[0]
print("Ramasse l'item -> item #%i*%s" %(itemNumber, itemQuantity))
return data[6:]
def h_DropItem(data): # Client
itemNumber = struct.unpack("B", data[1])[0]
itemQuantity = struct.unpack("I", data[2:6])[0]
print("Jete l'item item #%i*%s" %(itemNumber, itemQuantity))
return data[6:]
def h_UseItem(data): # Client
itemNumber = struct.unpack("B", data[1])[0]
print("Utilise l'item -> %s" %(data[1].encode("hex")))
return data[6:]
def h_UseEnvironment(data): # Client
entityNumber = struct.unpack("H", data[1:3])[0]
print("Utilise l'environnement identifie %i" %(entityNumber))
return data[9:]
def h_UseLiving(data): # Client
entityNumber = struct.unpack("H", data[1:3])[0]
print("Utilise l'entite vivante identifie %i" %(entityNumber))
return data[9:]
def h_LookEnvironment(data): # Client
entityNumber = struct.unpack("H", data[1:3])[0]
print("Regarde l'environnement identifie %i -> %s" %(entityNumber, data.encode("hex")))
return data[9:]
def h_LookLiving(data): # Client
entityNumber = struct.unpack("H", data[1:3])[0]
print("Regarde l'entite vivante identifie %i" %(entityNumber))
return data[9:]
def h_HpDecrease(data): # Server
entityNumber = struct.unpack("H", data[1:3])[0]
damage = struct.unpack("H", data[3:5])[0]
print("Entity %i took %i damages -> %s" %(entityNumber, damage, data[5:7].encode("hex")))
return data[7:]
def h_HpIncrease(data): # Server
entityNumber = struct.unpack("H", data[1:3])[0]
damage = struct.unpack("H", data[3:5])[0]
print("Entity %i gain %i hp -> %s" %(entityNumber, damage, data[5:7].encode("hex")))
return data[6:]
def h_StatChange(data): # Server
#print("StatChange -> %s" %(data[:7].encode("hex")))
return data[6:]
def h_dialogChoice(data): # Client
entityNumber = struct.unpack("H", data[1:3])[0]
choice = struct.unpack("I", data[3:7])[0]
print("Choix #%i lors du dialog avec l'entite %i -> %s" %(choice, entityNumber, data.encode('hex')))
return data[7:]
def h_Farming(data): # Client
entityNumber = struct.unpack("H", data[1:3])[0]
print("Va recolter l'entite identifie %i" %(entityNumber))
return data[3:]
handlers = {
0x0105: h_Timer1,
0x0e01: h_Timer2,
0x1a01: h_Timer2,
0x3c01: h_Timer2,
0x0204: h_Movement,
0x2805: h_Attack,
0x6103: h_Spawn,
0x1902: h_GoToLoot,
0x1717: h_InfoLoot,
0x1706: h_TakeItem,
0x1606: h_DropItem,
0x3007: h_HpIncrease,
0x2f07: h_HpDecrease,
0x3106: h_StatChange,
0x1f02: h_UseItem,
0x1009: h_UseEnvironment,
0x1c05: h_UseLiving,
0x1b05: h_LookEnvironment,
0x0505: h_LookLiving,
0x1d07: h_dialogChoice,
0x1503: h_Farming,
}
def parse(data, origin):
if origin:
while data:
#data = binascii.hexlify(data).decode('ascii')
packet_id = struct.unpack(">H", data[0:2])[0]
if packet_id not in handlers and origin == 'client' and True:
print("[%s] %s" %(origin, data.encode('hex')))
#print(hex(packet_id), data)
data = handlers.get(packet_id, h_NOP)(data[2:])
if __name__ == "__main__":
print("Hello world!")