ManInTheMiddleAmongUs/handler.py
2020-10-11 05:00:10 +02:00

44 lines
967 B
Python

import binascii
import itertools
import proto
from colordiff import Color, Diff
d_c = Diff(Color.GREEN, Color.RED)
d_s = Diff(Color.BLUE, Color.YELLOW)
def handle3(tag: str, data: str):
if data.startswith("0c") or data.startswith("0a"):
if tag == "server":
print(f"{Color.YELLOW}{data}{Color.RESET}")
elif tag == "client":
print(f"{Color.RED}{data}{Color.RESET}")
else:
if tag == "server":
d_s.consume(data)
elif tag == "client":
d_c.consume(data)
def handle2(tag: str, data: str):
if tag == "stdin":
# print(f"[stdin] {data}")
return
d_bytes = binascii.unhexlify(data)
if d_bytes[0] not in (8, 9):
return
print(f"[{tag}] {data}")
def handle(tag: str, data: str):
if tag == "stdin":
print(f"# {data}")
return
d_bytes = binascii.unhexlify(data)
pkt = proto.Parser.parse_packet(d_bytes)
print(pkt)