forked from celophi/ToS-IDA
-
Notifications
You must be signed in to change notification settings - Fork 0
/
1-packetTypeFinder.py
59 lines (47 loc) · 1.95 KB
/
1-packetTypeFinder.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
#!/usr/bin/python
"""
Tree of Savior IDAPython Script
Find packet listing
"""
import idaapi
import idautils
import idc
import os
gePacketTable__PACKET_TABLE__AddPacketSize = 0x9E10E0; # ICBT2 ; Search "%d PacketCommandError MaxiMum -> %d"
fpy = open ('PacketType.py', 'w');
packetsId = [];
packetsName = [];
packetsSize = [];
# Rename all functions declared with gePacketTable__PACKET_TABLE__AddPacketSize
occ = RfirstB (gePacketTable__PACKET_TABLE__AddPacketSize);
while occ != BADADDR:
packetIdInsn = PrevHead (occ);
packetSizeInsn = PrevHead (packetIdInsn);
packetId = GetOperandValue (packetIdInsn, 0);
packetSize = GetOperandValue (packetSizeInsn, 0);
packetName = GetString (Dword (occ + 6));
packetsId.append (packetId);
packetsSize.append (packetSize);
packetsName.append (packetName);
packetLine = "\t%s = %d, // Size = %d" % (packetName, packetId, packetSize);
# f.write (packetLine + "\n");
fpy.write ("packetsType[%d] = \"%s\" # Size = %d\n" % (packetId, packetName, packetSize));
occ = RnextB (gePacketTable__PACKET_TABLE__AddPacketSize, occ);
# Write .h
f = open ('PacketType.h', 'w');
f.write ("#define FOREACH_PACKET_TYPE(GENERATOR) \\\n");
for name,id,size in zip (packetsName, packetsId, packetsSize):
f.write (" GENERATOR(%s, %d, %d) \\\n" % (name, id, size));
"""
f.write ("const PacketTypeInfo packetTypeInfo = {\n");
f.write (" #define REGISTER_PACKET_TYPE_ENTRY(packetType, packetValue, packetSize) \\\n");
f.write (" .packets[packetType] = {.value = packetValue, .size = packetSize, .string = STRINGIFY (packetType)}\n");
for name,id,size in zip (packetsName, packetsId, packetsSize):
f.write (" REGISTER_PACKET_TYPE_ENTRY (%s, %d, %d),\n" % (name, id, size));
f.write (" #undef REGISTER_PACKET_TYPE_ENTRY\n};");
"""
f.close ();
fpy.close ();
print "The structure has been written to : ";
print "%s" % (os.getcwd() + "\\PacketType.h");
print "%s" % (os.getcwd() + "\\PacketType.py");