mirror of
https://github.com/lcdr/utils.git
synced 2024-08-30 17:32:16 +00:00
Packet search now doesn't delete tags
This commit is contained in:
parent
4811452be4
commit
7ffb5a0ca2
@ -59,19 +59,24 @@ for rootdir, _, files in os.walk("packetdefinitions"):
|
|||||||
class ParserOutput:
|
class ParserOutput:
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
self.text = ""
|
self.text = ""
|
||||||
self.tag = ""
|
self.tags = []
|
||||||
|
|
||||||
def __enter__(self):
|
def __enter__(self):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
def __exit__(self, exc_type, exc_value, traceback):
|
def __exit__(self, exc_type, exc_value, tb):
|
||||||
if exc_type is not None:
|
if exc_type is not None:
|
||||||
if exc_type == AssertionError:
|
if exc_type == AssertionError:
|
||||||
exc_name = "ASSERTION FAILED"
|
exc_name = "ASSERTION FAILED"
|
||||||
self.tag = "assertfail"
|
self.tags.append("assertfail")
|
||||||
elif exc_type == IndexError:
|
elif exc_type == IndexError:
|
||||||
exc_name = "READ ERROR"
|
exc_name = "READ ERROR"
|
||||||
self.tag = "readerror"
|
self.tags.append("readerror")
|
||||||
|
else:
|
||||||
|
exc_name = "ERROR"
|
||||||
|
self.tags.append("error")
|
||||||
|
import traceback
|
||||||
|
traceback.print_tb(tb)
|
||||||
self.text = exc_name+" "+str(exc_value)+"\n"+self.text
|
self.text = exc_name+" "+str(exc_value)+"\n"+self.text
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -79,7 +84,7 @@ class ParserOutput:
|
|||||||
for level, description, value, unexpected in structs:
|
for level, description, value, unexpected in structs:
|
||||||
if unexpected:
|
if unexpected:
|
||||||
self.text += "UNEXPECTED: "
|
self.text += "UNEXPECTED: "
|
||||||
self.tag = "unexpected"
|
self.tags.append("unexpected")
|
||||||
self.text += "\t"*level+description+": "+str(value)+"\n"
|
self.text += "\t"*level+description+": "+str(value)+"\n"
|
||||||
|
|
||||||
class CaptureObject:
|
class CaptureObject:
|
||||||
@ -127,7 +132,7 @@ class CaptureViewer(viewer.Viewer):
|
|||||||
menubar.add_cascade(label="Parse", menu=parse_menu)
|
menubar.add_cascade(label="Parse", menu=parse_menu)
|
||||||
self.master.config(menu=menubar)
|
self.master.config(menu=menubar)
|
||||||
|
|
||||||
columns = ("id",)
|
columns = "id",
|
||||||
self.tree.configure(columns=columns)
|
self.tree.configure(columns=columns)
|
||||||
for col in columns:
|
for col in columns:
|
||||||
self.tree.heading(col, text=col, command=(lambda col: lambda: self.sort_column(col, False))(col))
|
self.tree.heading(col, text=col, command=(lambda col: lambda: self.sort_column(col, False))(col))
|
||||||
@ -215,13 +220,13 @@ class CaptureViewer(viewer.Viewer):
|
|||||||
parser_output.append(creation_header_parser.parse(packet))
|
parser_output.append(creation_header_parser.parse(packet))
|
||||||
if error is not None:
|
if error is not None:
|
||||||
parser_output.text = error+"\n"+parser_output.text
|
parser_output.text = error+"\n"+parser_output.text
|
||||||
parser_output.tag = "error"
|
parser_output.tags.append("error")
|
||||||
else:
|
else:
|
||||||
self.parse_serialization(packet, parser_output, parsers, is_creation=True)
|
self.parse_serialization(packet, parser_output, parsers, is_creation=True)
|
||||||
|
|
||||||
obj = CaptureObject(network_id=network_id, object_id=object_id, lot=lot)
|
obj = CaptureObject(network_id=network_id, object_id=object_id, lot=lot)
|
||||||
self.objects.append(obj)
|
self.objects.append(obj)
|
||||||
obj.entry = self.tree.insert("", END, text=packet_name, values=(id_, parser_output.text), tag=parser_output.tag)
|
obj.entry = self.tree.insert("", END, text=packet_name, values=(id_, parser_output.text), tags=parser_output.tags)
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def parse_serialization(packet, parser_output, parsers, is_creation=False):
|
def parse_serialization(packet, parser_output, parsers, is_creation=False):
|
||||||
@ -254,10 +259,10 @@ class CaptureViewer(viewer.Viewer):
|
|||||||
with parser_output:
|
with parser_output:
|
||||||
self.parse_serialization(packet, parser_output, parsers)
|
self.parse_serialization(packet, parser_output, parsers)
|
||||||
if error is not None:
|
if error is not None:
|
||||||
parser_output.tag = "error"
|
parser_output.tags.append("error")
|
||||||
else:
|
else:
|
||||||
error = ""
|
error = ""
|
||||||
self.tree.insert(obj.entry, END, text=packet_name, values=(error, parser_output.text), tag=parser_output.tag)
|
self.tree.insert(obj.entry, END, text=packet_name, values=(error, parser_output.text), tags=parser_output.tags)
|
||||||
|
|
||||||
def parse_game_message(self, packet_name, packet):
|
def parse_game_message(self, packet_name, packet):
|
||||||
object_id = packet.read(c_int64)
|
object_id = packet.read(c_int64)
|
||||||
@ -339,7 +344,7 @@ class CaptureViewer(viewer.Viewer):
|
|||||||
else:
|
else:
|
||||||
raise NotImplementedError("Custom serialization")
|
raise NotImplementedError("Custom serialization")
|
||||||
values = "\n".join(["%s = %s" % (a, b) for a, b in attr_values.items()])
|
values = "\n".join(["%s = %s" % (a, b) for a, b in attr_values.items()])
|
||||||
tag = ""
|
tags = []
|
||||||
else:
|
else:
|
||||||
local_enums = {}
|
local_enums = {}
|
||||||
for enum in message.findall("enum"):
|
for enum in message.findall("enum"):
|
||||||
@ -410,25 +415,25 @@ class CaptureViewer(viewer.Viewer):
|
|||||||
raise ValueError
|
raise ValueError
|
||||||
except NotImplementedError as e:
|
except NotImplementedError as e:
|
||||||
values = (msg_name, str(e)+"\nlen: "+str(len(packet)-10)+"\n"+"\n".join(["%s = %s" % (a, b) for a, b in attr_values.items()]))
|
values = (msg_name, str(e)+"\nlen: "+str(len(packet)-10)+"\n"+"\n".join(["%s = %s" % (a, b) for a, b in attr_values.items()]))
|
||||||
tag = "error"
|
tags = ["error"]
|
||||||
except (IndexError, UnicodeDecodeError) as e:
|
except (IndexError, UnicodeDecodeError) as e:
|
||||||
print(packet_name, msg_name)
|
print(packet_name, msg_name)
|
||||||
import traceback
|
import traceback
|
||||||
traceback.print_exc()
|
traceback.print_exc()
|
||||||
values = ("likely not "+msg_name, "Error while parsing, likely not this message!\n"+str(e)+"\nlen: "+str(len(packet)-10)+"\n"+"\n".join(["%s = %s" % (a, b) for a, b in attr_values.items()]))
|
values = ("likely not "+msg_name, "Error while parsing, likely not this message!\n"+str(e)+"\nlen: "+str(len(packet)-10)+"\n"+"\n".join(["%s = %s" % (a, b) for a, b in attr_values.items()]))
|
||||||
tag = "error"
|
tags = ["error"]
|
||||||
except ValueError as e:
|
except ValueError as e:
|
||||||
values = ("likely not "+msg_name, "Error while parsing, likely not this message!\n"+str(e)+"\nlen: "+str(len(packet)-10))
|
values = ("likely not "+msg_name, "Error while parsing, likely not this message!\n"+str(e)+"\nlen: "+str(len(packet)-10))
|
||||||
tag = "error"
|
tags = ["error"]
|
||||||
else:
|
else:
|
||||||
values = (msg_name, "\n".join(["%s = %s" % (a, b) for a, b in attr_values.items()]))
|
values = (msg_name, "\n".join(["%s = %s" % (a, b) for a, b in attr_values.items()]))
|
||||||
tag = ""
|
tags = []
|
||||||
self.tree.insert(entry, END, text=packet_name, values=values, tag=tag)
|
self.tree.insert(entry, END, text=packet_name, values=values, tags=tags)
|
||||||
|
|
||||||
def parse_normal_packet(self, packet_name, packet):
|
def parse_normal_packet(self, packet_name, packet):
|
||||||
id_ = packet_name[packet_name.index("[")+1:packet_name.index("]")]
|
id_ = packet_name[packet_name.index("[")+1:packet_name.index("]")]
|
||||||
if id_ not in norm_parser:
|
if id_ not in norm_parser:
|
||||||
self.tree.insert("", END, text=packet_name, values=(id_, "Add the struct definition file packetdefinitions/"+id_+".structs to enable parsing of this packet."), tag="error")
|
self.tree.insert("", END, text=packet_name, values=(id_, "Add the struct definition file packetdefinitions/"+id_+".structs to enable parsing of this packet."), tags=["error"])
|
||||||
return
|
return
|
||||||
if id_.startswith("53"):
|
if id_.startswith("53"):
|
||||||
packet.skip_read(8)
|
packet.skip_read(8)
|
||||||
@ -436,7 +441,7 @@ class CaptureViewer(viewer.Viewer):
|
|||||||
packet.skip_read(1)
|
packet.skip_read(1)
|
||||||
parser_output = ParserOutput()
|
parser_output = ParserOutput()
|
||||||
parser_output.append(norm_parser[id_].parse(packet))
|
parser_output.append(norm_parser[id_].parse(packet))
|
||||||
self.tree.insert("", END, text=packet_name, values=(id_, parser_output.text), tag=parser_output.tag)
|
self.tree.insert("", END, text=packet_name, values=(id_, parser_output.text), tags=parser_output.tags)
|
||||||
|
|
||||||
def on_item_select(self, event):
|
def on_item_select(self, event):
|
||||||
item = self.tree.selection()[0]
|
item = self.tree.selection()[0]
|
||||||
|
@ -48,7 +48,9 @@ class Viewer(Frame):
|
|||||||
def find(self):
|
def find(self):
|
||||||
query = self.find_input.get().lower()
|
query = self.find_input.get().lower()
|
||||||
for item in self.tree.tag_has("match"):
|
for item in self.tree.tag_has("match"):
|
||||||
self.tree.item(item, tags=())
|
tags = list(self.tree.item(item, "tags"))
|
||||||
|
tags.remove("match")
|
||||||
|
self.tree.item(item, tags=tags)
|
||||||
for parent, detached_children in self.detached_items.items():
|
for parent, detached_children in self.detached_items.items():
|
||||||
for i in detached_children:
|
for i in detached_children:
|
||||||
self.tree.reattach(i, parent, END)
|
self.tree.reattach(i, parent, END)
|
||||||
@ -60,7 +62,9 @@ class Viewer(Frame):
|
|||||||
detached_children = [item for item in all_children if not any(query in i.lower() for i in self.tree.item(item, "values"))] # first, find all children that don't match
|
detached_children = [item for item in all_children if not any(query in i.lower() for i in self.tree.item(item, "values"))] # first, find all children that don't match
|
||||||
for item in all_children:
|
for item in all_children:
|
||||||
if item not in detached_children:
|
if item not in detached_children:
|
||||||
self.tree.item(item, tags=("match",))
|
tags = list(self.tree.item(item, "tags"))
|
||||||
|
tags.append("match")
|
||||||
|
self.tree.item(item, tags=tags)
|
||||||
self.tree.see(item)
|
self.tree.see(item)
|
||||||
if self.filter_items(query, item) and item in detached_children:
|
if self.filter_items(query, item) and item in detached_children:
|
||||||
detached_children.remove(item) # don't detach if a child matches
|
detached_children.remove(item) # don't detach if a child matches
|
||||||
|
Loading…
Reference in New Issue
Block a user