From 88dd7266cc3bae657afe00b1126704f9f9ce2484 Mon Sep 17 00:00:00 2001 From: Andrei Karas Date: Mon, 5 Sep 2016 20:51:40 +0300 Subject: servergreps: add parsing and basic report for brAthena. --- servergreps/hercules/packets.py | 7 ++ servergreps/hercules/src/brathena.py | 182 +++++++++++++++++++++++++++++++++++ servergreps/hercules/src/reporter.py | 11 +++ 3 files changed, 200 insertions(+) create mode 100755 servergreps/hercules/src/brathena.py (limited to 'servergreps') diff --git a/servergreps/hercules/packets.py b/servergreps/hercules/packets.py index c5b73ed..40d67a6 100755 --- a/servergreps/hercules/packets.py +++ b/servergreps/hercules/packets.py @@ -6,6 +6,7 @@ import sys +from src.brathena import Brathena from src.hercules import Hercules from src.manaplus import ManaPlus from src.rathena import Rathena @@ -30,6 +31,9 @@ hercules.reportName = "hercules" rathena = Rathena() rathena.dirName = "rathena" rathena.reportName = "rathena" +brathena = Brathena() +brathena.dirName = "brathena" +brathena.reportName = "brathena" manaplus = ManaPlus() reporter = Reporter() @@ -39,8 +43,11 @@ hercules.prepareTempFiles(codeDir, packetDir, packetVersion) hercules.processPackets(packetDir, packetVersion) rathena.prepareTempFiles("rathena", packetDir, packetVersion) rathena.processPackets(packetDir, packetVersion) +brathena.prepareTempFiles("brathena", packetDir, packetVersion) +brathena.processPackets(packetDir, packetVersion) manaplus.processPackets(packetVersion); reporter.reportManaplus(hercules, manaplus) reporter.reportHercules(hercules) reporter.reportRathena(hercules, rathena) +reporter.reportHerculesFork(hercules, brathena, "brAthena") diff --git a/servergreps/hercules/src/brathena.py b/servergreps/hercules/src/brathena.py new file mode 100755 index 0000000..2ef51a2 --- /dev/null +++ b/servergreps/hercules/src/brathena.py @@ -0,0 +1,182 @@ +#! /usr/bin/env python2 +# -*- coding: utf8 -*- +# +# Copyright (C) 2015-2016 Evol Online +# Author: Andrei Karas (4144) + +import os +import re + +from src.preproc import PreProc + +filt = re.compile(".+[.](c|h)", re.IGNORECASE) + +class Brathena: + namedPackets = dict() + packetsSet = set() + outPacketsSorted = [] + inPacketsSorted = [] + inPackets = dict() + functionToId = dict() + loginPacketNameToId = dict() + + namedPacketre = re.compile( + "((\t|[ ])*)(?P[\w0-9_]+)([ ]*)=" + + "([ ]*)0x(?P[0-9a-fA-F]+)") + ourPacketre = re.compile( + "(WFIFOW|WBUFW)([ ]*)[(]([ ]*)([\w>_-]+),([ ]*)" + + "(?P0)([ ]*)[)]([ ]*)=([ ]*)0x(?P[0-9a-fA-F]+)([ ]*)[;]") + ourPacketre2 = re.compile("PacketType([ ]*)=([ ]*)(?P[\w_]+);") + ourPacketre3 = re.compile( + "(WFIFOW|WBUFW)([ ]*)[(]([ ]*)([\w>_-]+),([ ]*)" + + "(?P0)([ ]*)[)]([ ]*)=([ ]*)(?P[0-9\w]+)([ ]*)[;]") + ourPacketre4 = re.compile("int cmd([ ]*)=([ ]*)0x(?P[0-9a-fA-F]+);") + outPacketLoginre = re.compile( + "([ ]*)PACKET_ID_(?P[A-Z0-9_]+)([ ]*)=" + + "([ ]*)0x(?P[0-9a-fA-F]+),") + serverpacketLoginOutre = re.compile("packet_id([ ]*)=([ ]*)(?P[\w_]+);") + clientpacketre = re.compile( + "(\t*)packet[(]0x(?P[0-9a-fA-F]+),(?P[\w-]+)" + + ",(?P[0-9a-zA-Z_>-]+)(,|[)])") + lclifPacketre = re.compile( + "([ ]*)[{][ ]PACKET_ID_CA_(?P[A-Z0-9_]+),([^,]+)," + + "([ ]*)[&](?P[0-9a-zA-Z_>-]+)([ ]*)[}],") + + def collectNamedPackets(self, fileName): + with open(fileName, "r") as f: + for line in f: + m = self.namedPacketre.search(line) + if m is not None: + if m.group("name") not in self.namedPackets: + self.namedPackets[m.group("name")] = [] + data = m.group("value").lower() + while len(data) < 4: + data = "0" + data + self.namedPackets[m.group("name")].append(data) + + + def addServerPacket(self, data): + if data in self.namedPackets: + for val in self.namedPackets[data]: + if int(val, 16) > 4096: + return + self.packetsSet.add(val) + else: + try: + if int(data, 16) > 4096: + return + except: + pass + self.packetsSet.add(data.lower()) + + + def collectOutPackets(self, parentDir): + files = os.listdir(parentDir) + for file1 in files: + if file1[0] == ".": + continue + file2 = os.path.abspath(parentDir + os.path.sep + file1) + if not os.path.isfile(file2): + if file2.find("/src/evol") <= 0: + self.collectOutPackets(file2) + elif filt.search(file1): + with open(file2, "r") as f: + for line in f: + m = self.ourPacketre4.findall(line) + if len(m) > 0: + for str in m: + data = str[2] + while len(data) < 4: + data = "0" + data + self.addServerPacket(data) + m = self.outPacketLoginre.findall(line) + if len(m) > 0: + for str in m: + data = str[4] + while len(data) < 4: + data = "0" + data + self.loginPacketNameToId["PACKET_ID_" + str[1]] = data + m = self.ourPacketre.findall(line) + if len(m) == 0: + m = self.ourPacketre3.findall(line) + if len(m) > 0: + for str in m: + if str[9] == "0": + continue + data = str[9] + if data == "cmd": + continue + while len(data) < 4: + data = "0" + data + self.addServerPacket(data) + + m = self.ourPacketre2.findall(line) + if len(m) > 0: + for str in m: + if str[2] == "0": + continue + data = str[2] + if len(data) > 2 and data[0:2] == "0x": + data = data[2:] + while len(data) < 4: + data = "0" + data + self.addServerPacket(data) + m = self.serverpacketLoginOutre.findall(line) + if len(m) > 0: + for str in m: + if str[2] in self.loginPacketNameToId: + data = str[2] + data = self.loginPacketNameToId[data] + self.addServerPacket(data) + + + def sortOutPackets(self): + for packet in self.packetsSet: + self.outPacketsSorted.append(packet) + self.outPacketsSorted.sort() + + + def collectInPackets(self, packetsH): + with open(packetsH, "r") as f: + for line in f: + m = self.clientpacketre.search(line) + if m is not None: + data = m.group("packet").lower() + while len(data) < 4: + data = "0" + data + self.inPackets[data] = \ + (int(m.group("len")), m.group("function")) + self.functionToId[m.group("function")] = data + + + def sortInPackets(self): + for packet in self.inPackets: + self.inPacketsSorted.append(packet) + self.inPacketsSorted.sort() + + + def processPackets(self, packetDir, packetVersion): + namedPacketsPath = packetDir + "/src/" + self.dirName + "/packets_struct.h" + srcPath = packetDir + "/src/" + self.dirName + serverInPacketsHPath = packetDir + "/src/" + self.dirName + "/packets.h" + self.collectNamedPackets(namedPacketsPath) + self.collectOutPackets(srcPath) + self.collectInPackets(serverInPacketsHPath) + self.sortInPackets() + self.sortOutPackets() + + + def prepareTempFiles(self, codeDir, packetDir, packetVersion): + proc = PreProc() + proc.init(packetDir + "/src/" + self.dirName) + proc.defines = "-DPACKETVER=" + packetVersion + " -DCOMMON_SOCKET_H -DWFIFOW\\(fd,pos\\)=WFIFOW\\(fd,pos\\) -DWBUFW\\(p,pos\\)=WBUFW\\(p,pos\\)" + proc.includes = "-I../links/" + codeDir + "/src -I../links/" + codeDir + "/3rdparty" + proc.inDir = "../links/" + codeDir + "/src/" + proc.outDir = packetDir + "/src/" + self.dirName + "/" + proc.run("map", "packets_struct.h"); + proc.run("char", "char.c"); + proc.run("char", "pincode.c"); + proc.run("login", "login.c"); + proc.run("map", "clif.c"); + proc.defines = "-DPACKETVER=" + packetVersion + " -Dpacket\\(id,size,...\\)=packet\\(id,size,__VA_ARGS__\\)" + proc.run("map", "packets.h"); diff --git a/servergreps/hercules/src/reporter.py b/servergreps/hercules/src/reporter.py index 128c668..a3ecb17 100755 --- a/servergreps/hercules/src/reporter.py +++ b/servergreps/hercules/src/reporter.py @@ -209,3 +209,14 @@ class Reporter: for packet in rathena.outPacketsSorted: if packet not in hercules.packetsSet: w.write("Exists only in rAthena: " + packet + "\n") + + def reportHerculesFork(self, hercules, fork, name): + with open(self.packetDir + "/" + hercules.reportName + "_" + fork.reportName + "_outpackets.txt", "w") as w: + for packet in fork.outPacketsSorted: + if packet not in hercules.packetsSet: + w.write("Exists only in " + name + ": " + packet + "\n") + + with open(self.packetDir + "/" + hercules.reportName + "_" + fork.reportName + "_inpackets.txt", "w") as w: + for packet in fork.inPacketsSorted: + if packet not in hercules.inPackets: + w.write("Exists only in " + name + ": " + packet + "\n") -- cgit v1.2.3-70-g09d2