From 55cc60845411843d9300440110b00f3079f7213b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fabian=20M=C3=BCller?= Date: Mon, 1 Apr 2024 01:17:44 +0200 Subject: [PATCH] Add Python server script for reverse engineering --- tools/re-server.py | 42 ++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) create mode 100644 tools/re-server.py diff --git a/tools/re-server.py b/tools/re-server.py new file mode 100644 index 0000000..ec21fc6 --- /dev/null +++ b/tools/re-server.py @@ -0,0 +1,42 @@ +""" +Simple socket server used to reverse engineer the messaging protocol the bundled software uses to send data to the +LED sign. + +The server just dumps incoming messages in a hexdump-like format as well as an easy to read Python bytestring. +""" + + +import asyncio +import string + + +async def handle_client(reader, writer): + message = await reader.read(255) + + hex_chars = [hex(j)[2:].zfill(2) for j in message] + + ascii_chars = [] + for j in message: + char = chr(j) + if char in (string.ascii_letters + string.digits + string.punctuation): + ascii_chars.append(char) + else: + ascii_chars.append(".") + + print("Message received: ", end="") + print(" ".join(hex_chars), end=" | ") + print("".join(ascii_chars), end=" | ") + print("".join(repr(message))) + + writer.close() + + +async def run_server(): + server = await asyncio.start_server(handle_client, '', 3000) + async with server: + await server.serve_forever() + + +if __name__ == "__main__": + asyncio.run(run_server()) +