|
|
@ -8,6 +8,7 @@ from stat import * # suggested usage…
|
|
|
|
import selectors
|
|
|
|
import selectors
|
|
|
|
from dataclasses import dataclass
|
|
|
|
from dataclasses import dataclass
|
|
|
|
import logging as log
|
|
|
|
import logging as log
|
|
|
|
|
|
|
|
import math
|
|
|
|
# Note: get/setrlimit are in resource module
|
|
|
|
# Note: get/setrlimit are in resource module
|
|
|
|
|
|
|
|
|
|
|
|
def setup_logging():
|
|
|
|
def setup_logging():
|
|
|
@ -21,9 +22,19 @@ class Direction:
|
|
|
|
sigil: str
|
|
|
|
sigil: str
|
|
|
|
color: str
|
|
|
|
color: str
|
|
|
|
|
|
|
|
|
|
|
|
def hexdump(data: bytes) -> str:
|
|
|
|
def hexdump(data: bytes) -> list[str]: # We will be prefixing the lines with sigils, so no need to join.
|
|
|
|
# TODO: dump somehow
|
|
|
|
result = []
|
|
|
|
...
|
|
|
|
offset = 0
|
|
|
|
|
|
|
|
offset_len = math.ceil(math.log(len(data), 16))
|
|
|
|
|
|
|
|
while data:
|
|
|
|
|
|
|
|
left_chunk, right_chunk, data = data[:8], data[8:16], data[16:]
|
|
|
|
|
|
|
|
left_ascii = ''.join(chr(x) if x in range(32,127) else ',' for x in left_chunk)
|
|
|
|
|
|
|
|
right_ascii = ''.join(chr(x) if x in range(32,127) else ',' for x in right_chunk)
|
|
|
|
|
|
|
|
offset_str = f'{offset:0{offset_len}x}'
|
|
|
|
|
|
|
|
line = f"{offset_str} {left_chunk.hex(' ').ljust(23)} {right_chunk.hex(' ').ljust(23)} |{left_ascii.ljust(8)}{right_ascii.ljust(8)}|"
|
|
|
|
|
|
|
|
offset += 16
|
|
|
|
|
|
|
|
result.append(line)
|
|
|
|
|
|
|
|
return result
|
|
|
|
|
|
|
|
|
|
|
|
def fdinfo(fd: int) -> str:
|
|
|
|
def fdinfo(fd: int) -> str:
|
|
|
|
stat = os.fstat(fd)
|
|
|
|
stat = os.fstat(fd)
|
|
|
|