16fd87ee by bruffner

Packet parser initial commit

0 parents
This diff could not be displayed because it is too large.
1 #!/usr/bin/python
2
3 import sys
4
5 # Packet
6 # | 0 1 2 3 4 5 6 7 8 9 A B C D E F | 0123456789ABCDEF
7 # ----------------------------------------------------- ----------------------
8 # 0 | 0E 1C DD 27 0B B2 05 01 0B 02 07 C0 BE DF 85 43 0 | ...'...........C
9 # 1 | 5E BA C9 40 E1 3A 40 43 8B 0A 00 00 28 28 55 01 1 | ^..@.:@C....((U.
10 # 2 | 01 81 00 00 00 0C 00 00 20 00 00 00 B1 9E 03 00 2 | ........ .......
11 # 3 | 00 00 4E 08 00 00 00 00 -- -- -- -- -- -- -- -- 3 | ..N.....--------
12
13 # Packet
14 # | 0 1 2 3 4 5 6 7 8 9 A B C D E F | 0123456789ABCDEF
15 # ----------------------------------------------------- ----------------------
16 # 0 | 0E 1C DD 27 51 B8 05 01 51 07 01 5A FE F4 86 43 0 | ...'Q...Q..Z...C
17 # 1 | BE 9F FA 40 60 05 43 43 65 02 00 00 7D 32 00 00 1 | ...@`.CCe...}2..
18 # 2 | 00 00 00 00 00 00 00 00 00 00 00 04 00 00 00 00 2 | ................
19 # 3 | 00 00 CA 0B 00 00 00 00 -- -- -- -- -- -- -- -- 3 | ........--------
20
21 # Packet
22 # | 0 1 2 3 4 5 6 7 8 9 A B C D E F | 0123456789ABCDEF
23 # ----------------------------------------------------- ----------------------
24 # 0 | 0E 24 0A 1D 22 82 05 01 22 02 09 79 0E 9D 05 C4 0 | .$.."..."..y....
25 # 1 | BE 1F 26 42 F8 D3 A2 42 DA 00 00 00 28 28 00 00 1 | ..&B...B....((..
26 # 2 | 01 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2 | ................
27 # 3 | 00 00 4E 08 42 65 61 64 65 61 75 78 56 61 6E 67 3 | ..N.BeadeauxVang
28 # 4 | 75 61 00 00 00 00 00 00 -- -- -- -- -- -- -- -- 4 | ua......--------
29
30
31 # 0x00 - 0x03 = Packet Header
32 # 0x04 - 0x07 = MobNpC ID (Reversed Hex->Dec)
33 # 0x08 - 0x09 = TargetID (Reversed Hex->Dec)
34 # 0x0A - 0x0B = Flags / Moving
35 # 0x0C - 0x0F = X position Converted
36 # 0x10 - 0x13 = Y position Converted
37 # 0x14 - 0x17 = Z Position Converted I'd have to find my notes I cant remember the converstion right off
38 # 0x18 - 0x19 = Flags
39 # 0x1A = Unknown would leave Raw if possible
40 # 0x1B = Unknown would leave Raw if possible
41 # 0x1C = Speed
42 # 0x1D = SpeedSub
43 # 0x1E = HP %
44 # 0x1F = Animation
45 # 0x20 = Status
46 # 0x21 - 0x22 = Flags2 (Reversed Hex->Dec)
47 # 0x23 = Unknown would leave Raw if possible
48 # 0x24 = Unknown would leave Raw if possible
49 # 0x25 = Unknown would leave Raw if possible
50 # 0x26 = Unknown would leave Raw if possible
51 # 0x27 = name prefix
52 # 0x28 = StatusEffect(terror)
53 # 0x29 = Allegiance
54 # 0x2A = AnimationSub
55 # 0x2B = NameVis
56 # 0x2C = OwnerID
57 # 0x2D = Unknown would leave Raw if possible
58 # 0x2E = Unknown would leave Raw if possible
59 # 0x2F = Unknown would leave Raw if possible
60 # 0x30 - 0x33 = ModelID (In some cases geared NPCs continue past this but can manually check those)
61 # 0x34 - 0x40 = Name (posted sample below)
62
63 class PacketParser(object):
64 """A Packet Parser"""
65
66 def parse_file(self, filename, output_filename):
67 lines_to_ignore = ["Packet",
68 "| 0 1 2 3 4 5 6 7 8 9 A B C D E F | 0123456789ABCDEF",
69 "----------------------------------------------------- ----------------------"]
70 output = []
71 with open(output_filename, 'w') as f_out:
72 with open(filename) as f:
73 line_count = 0
74 packet_count = 0
75 for line in f:
76 line_count+=1
77 line = line.strip()
78 if line == 'Packet':
79 packet_count+=1
80 packet_data = []
81 elif line not in lines_to_ignore:
82 packet_data.append(line)
83 if line == "":
84 f_out.write(",".join(map(str, self.parse_packet(packet_data))) + '\n')
85
86 print("Lines Parsed: " + str(line_count) + "\nPackets Parsed: " + str(packet_count))
87
88 def get_byte(self, packet, byte):
89 return str(packet[byte])
90
91 def parse_packet(self, packet_data):
92 packet = []
93 for packet_line in packet_data:
94 for byte in packet_line[4:51].split(' '):
95 packet.append(byte)
96
97 # print("Parsing packet: ")
98 # print(packet)
99
100 header = int(self.get_byte(packet, 0x00) + self.get_byte(packet, 0x01) + self.get_byte(packet, 0x02), 16)
101 # print("header: " + str(header))
102 mob_npc_id = int(self.get_byte(packet, 0x07) + self.get_byte(packet, 0x06) + self.get_byte(packet, 0x05) + self.get_byte(packet, 0x04), 16)
103 # print("MobNPC ID: " + str(mob_npc_id))
104 target_id = int(self.get_byte(packet, 0x09) + self.get_byte(packet, 0x08), 16)
105 # print("Target ID: " + str(target_id))
106 flags_moving = int(self.get_byte(packet, 0x0A) + self.get_byte(packet, 0x0B), 16)
107 # print("Flags: " + str(flags_moving))
108 x_pos = int(self.get_byte(packet, 0x0C) + self.get_byte(packet, 0x0D) + self.get_byte(packet, 0x0E) + self.get_byte(packet, 0x0F), 16)
109 # print("X Position: " + str(x_pos))
110 y_pos = int(self.get_byte(packet, 0x10) + self.get_byte(packet, 0x11) + self.get_byte(packet, 0x12) + self.get_byte(packet, 0x13), 16)
111 # print("Y Position: " + str(y_pos))
112 z_pos = int(self.get_byte(packet, 0x14) + self.get_byte(packet, 0x15) + self.get_byte(packet, 0x16) + self.get_byte(packet, 0x17), 16)
113 # print("Z Position: " + str(z_pos))
114 flags = int(self.get_byte(packet, 0x18) + self.get_byte(packet, 0x19), 16)
115 # print("Flags: " + str(flags))
116 raw_1 = self.get_byte(packet, 0x1A)
117 # print("Raw 1: " + str(raw_1))
118 raw_2 = self.get_byte(packet, 0x1B)
119 # print("Raw 2: " + str(raw_2))
120 speed = int(self.get_byte(packet, 0x1C), 16)
121 # print("Speed: " + str(speed))
122 speed_sub = int(self.get_byte(packet, 0x1D), 16)
123 # print("SpeedSub: " + str(speed_sub))
124 hp_percent = int(self.get_byte(packet, 0x1E), 16)
125 # print("HP %: " + str(hp_percent))
126 animation = int(self.get_byte(packet, 0x1F), 16)
127 # print("Animation: " + str(animation))
128 status = int(self.get_byte(packet, 0x20), 16)
129 # print("Status: " + str(status))
130 flags2 = int(self.get_byte(packet, 0x22) + self.get_byte(packet, 0x21), 16)
131 # print("Flags2: " + str(flags2))
132 raw_3 = self.get_byte(packet, 0x23)
133 # print("Raw 3: " + str(raw_3))
134 raw_4 = self.get_byte(packet, 0x24)
135 # print("Raw 4: " + str(raw_4))
136 raw_5 = self.get_byte(packet, 0x25)
137 # print("Raw 5: " + str(raw_5))
138 raw_6 = self.get_byte(packet, 0x26)
139 # print("Raw 6: " + str(raw_6))
140 name_prefix = int(self.get_byte(packet, 0x27), 16)
141 # print("Name Prefix: " + str(name_prefix))
142 status_effect = int(self.get_byte(packet, 0x28), 16)
143 # print("Status Effect(terror): " + str(status_effect))
144 allegiance = int(self.get_byte(packet, 0x29), 16)
145 # print("Allegiance: " + str(allegiance))
146 animation_sub = int(self.get_byte(packet, 0x2A), 16)
147 # print("AnimationSub: " + str(animation_sub))
148 name_vis = int(self.get_byte(packet, 0x2B), 16)
149 # print("NameVis: " + str(name_vis))
150 owner_id = int(self.get_byte(packet, 0x2C), 16)
151 # print("OwnerID: " + str(owner_id))
152 raw_7 = self.get_byte(packet, 0x2D)
153 # print("Raw 7: " + str(raw_7))
154 raw_8 = self.get_byte(packet, 0x2E)
155 # print("Raw 8: " + str(raw_8))
156 raw_9 = self.get_byte(packet, 0x2F)
157 # print("Raw 9: " + str(raw_9))
158 model_id = int(self.get_byte(packet, 0x30) + self.get_byte(packet, 0x31) + self.get_byte(packet, 0x32) + self.get_byte(packet, 0x33), 16)
159 # print("ModelID: " + str(model_id))
160 name = ""
161 for byte in packet[0x34:]:
162 if byte == "--" or byte == "00":
163 break
164 name += byte.decode("hex")
165 # print("Name: " + str(name))
166
167 return [header, mob_npc_id, target_id, flags, raw_1, raw_2, speed, speed_sub, hp_percent, animation, status, flags2, raw_3,
168 raw_4, raw_5, raw_6, name_prefix, status_effect, allegiance, animation_sub, name_vis, owner_id, raw_7, raw_8, raw_9,
169 model_id, name]
170
171
172 if __name__ == '__main__':
173 if len(sys.argv) < 3:
174 print('Please provide the packet file you wish to convert along with the output file.\n Example: python packetparser 0x00E.log 0x00e-output.csv')
175 else:
176 print('Reading File: ' + sys.argv[1] + "\nWriting File: " + sys.argv[2])
177 PacketParser().parse_file(sys.argv[1], sys.argv[2])
178 print('Completed parsing')
179
180
This diff could not be displayed because it is too large.