Implement local login

Route login and character requests by their original host names on one
loopback port. Add local accounts, saves, and credential redaction.
This commit is contained in:
N0VAN0M4LY committed 2026-11-24 05:01:26 +08:00
1 parent 5421268fbf
commit 18f63bf33e
55 files changed
+1559 -58

No files matched your search

+2 -2
View File
@@ -46,9 +46,9 @@ def _check_patches(args: argparse.Namespace) -> int:
problem = disagreement(definition)
if problem:
mismatched += 1
print(f" assembly disagrees with stored bytes: {definition.identifier}: {problem}")
print(f" source disagrees with stored bytes: {definition.identifier}: {problem}")
if not mismatched:
print(" every patch's assembly source compiles to its stored bytes")
print(" every patch's source (assembly or data text) encodes to its stored bytes")
plan = plan_patches(PeImage(args.exe.read_bytes()), definitions)
print(plan.describe())
+19 -5
View File
@@ -27,12 +27,26 @@ def assemble(lines: tuple[str, ...] | list[str]) -> bytes:
return bytes(encoding)
def encode_data(data: dict, length: int) -> bytes:
"""Encode a data edit's text and pad it with zero bytes to `length`."""
try:
encoded = str(data["text"]).encode(str(data["encoding"]))
except (KeyError, LookupError) as error:
raise DefinitionError(f"data edit needs a valid 'encoding' and 'text': {error}") from error
if len(encoded) > length:
raise DefinitionError(f"data text is {len(encoded)} bytes, longer than the {length}-byte edit")
return encoded + bytes(length - len(encoded))
def disagreement(definition: PatchDefinition) -> str | None:
"""Why a definition's assembly source and stored bytes differ, or None if they agree."""
if not definition.edit.asm:
return "no assembly source recorded for the stored bytes"
compiled = assemble(definition.edit.asm)
"""Why a definition's source (assembly or data text) and stored bytes differ, or None if they agree."""
if definition.edit.data is not None:
source, compiled = "data text", encode_data(definition.edit.data, len(definition.edit.payload))
elif definition.edit.asm:
source, compiled = "assembly", assemble(definition.edit.asm)
else:
return "no assembly source or data text recorded for the stored bytes"
if compiled != definition.edit.payload:
return (f"assembly compiles to {compiled.hex()} but the stored bytes are "
return (f"{source} encodes to {compiled.hex()} but the stored bytes are "
f"{definition.edit.payload.hex()}")
return None
@@ -30,6 +30,9 @@ class PatchEdit:
payload: bytes
expect_original: bytes
asm: tuple[str, ...]
# For edits to constant data (strings) instead of code: {"encoding": ..., "text": ...}.
# The text, encoded and padded with zero bytes to the edit's length, must equal the payload.
data: dict | None = None
def __post_init__(self) -> None:
if len(self.payload) != len(self.expect_original):
@@ -94,6 +97,7 @@ def _read_edit(directory: Path, raw: object) -> PatchEdit:
payload=_hex(directory, "bytes", raw["bytes"]),
expect_original=_hex(directory, "expect_original", raw["expect_original"]),
asm=tuple(str(line) for line in raw.get("asm", ())),
data=raw.get("data") if isinstance(raw.get("data"), dict) else None,
)