beambam 1.1.0__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of beambam might be problematic. Click here for more details.

Files changed (120) hide show
  1. bambu_cert.py +199 -0
  2. beambam/__init__.py +70 -0
  3. beambam/analyze.py +614 -0
  4. beambam/cloud_fetch.py +262 -0
  5. beambam/frame.py +90 -0
  6. beambam/printer.py +272 -0
  7. beambam/schemas.py +346 -0
  8. beambam/simulate.py +202 -0
  9. beambam/state_hub.py +165 -0
  10. beambam-1.1.0.dist-info/METADATA +807 -0
  11. beambam-1.1.0.dist-info/RECORD +120 -0
  12. beambam-1.1.0.dist-info/WHEEL +4 -0
  13. beambam-1.1.0.dist-info/entry_points.txt +7 -0
  14. beambam-1.1.0.dist-info/licenses/LICENSE +43 -0
  15. cloud_client.py +724 -0
  16. inject_thumbnails.py +127 -0
  17. lan_print.py +517 -0
  18. lan_upload.py +279 -0
  19. mcp_x2d.py +9 -0
  20. preflight_3mf.py +389 -0
  21. remix_3mf.py +346 -0
  22. resolve_profile.py +104 -0
  23. runtime/assistant/__init__.py +12 -0
  24. runtime/assistant/router.py +305 -0
  25. runtime/build_egl_vendor.sh +35 -0
  26. runtime/build_gst_soup_termux.sh +126 -0
  27. runtime/colorsync/__init__.py +8 -0
  28. runtime/colorsync/data/filaments_color_codes.json +7019 -0
  29. runtime/colorsync/mapper.py +195 -0
  30. runtime/demos/__init__.py +14 -0
  31. runtime/demos/render.py +372 -0
  32. runtime/ha/__init__.py +11 -0
  33. runtime/ha/publisher.py +664 -0
  34. runtime/handy_extract/.gitignore +9 -0
  35. runtime/handy_extract/README.md +177 -0
  36. runtime/handy_extract/analyze_shield.py +213 -0
  37. runtime/handy_extract/anti_antidebug.js +149 -0
  38. runtime/handy_extract/check_capture.sh +14 -0
  39. runtime/handy_extract/dump_keys.py +339 -0
  40. runtime/handy_extract/dump_unpacker.sh +105 -0
  41. runtime/handy_extract/find_boringssl.py +288 -0
  42. runtime/handy_extract/find_brx0.py +47 -0
  43. runtime/handy_extract/handy_hook.js +956 -0
  44. runtime/handy_extract/init_capture_hooks.js +28 -0
  45. runtime/handy_extract/init_combined.js +685 -0
  46. runtime/handy_extract/init_filewriter.js +47 -0
  47. runtime/handy_extract/init_logcat.js +23 -0
  48. runtime/handy_extract/init_nowriter.js +662 -0
  49. runtime/handy_extract/init_v10.js +804 -0
  50. runtime/handy_extract/init_v11.js +834 -0
  51. runtime/handy_extract/init_v12.js +704 -0
  52. runtime/handy_extract/init_v13.js +706 -0
  53. runtime/handy_extract/init_v5.js +708 -0
  54. runtime/handy_extract/init_v6.js +721 -0
  55. runtime/handy_extract/init_v7.js +701 -0
  56. runtime/handy_extract/init_v8.js +704 -0
  57. runtime/handy_extract/init_v9.js +783 -0
  58. runtime/handy_extract/keystore_dumper/aes_cbc_scan.py +78 -0
  59. runtime/handy_extract/keystore_dumper/build.sh +27 -0
  60. runtime/handy_extract/keystore_dumper/decrypt_prefs.py +129 -0
  61. runtime/handy_extract/keystore_dumper/run.sh +30 -0
  62. runtime/handy_extract/keystore_dumper/src/com/x2d/dump/ExportCert.java +55 -0
  63. runtime/handy_extract/keystore_dumper/src/com/x2d/dump/LegacyKeyStorageDumper.java +94 -0
  64. runtime/handy_extract/keystore_dumper/src/com/x2d/dump/ListAliases.java +56 -0
  65. runtime/handy_extract/keystore_dumper/src/com/x2d/dump/SecureStorageDumper.java +421 -0
  66. runtime/handy_extract/memscan.js +130 -0
  67. runtime/handy_extract/patch_handy_debuggable.sh +171 -0
  68. runtime/handy_extract/patch_handy_shareduid.sh +109 -0
  69. runtime/handy_extract/patch_libflutter_apk.py +191 -0
  70. runtime/handy_extract/quick_hook.js +125 -0
  71. runtime/handy_extract/run_capture.sh +87 -0
  72. runtime/handy_extract/saga_init.js +1175 -0
  73. runtime/handy_extract/scan_xor_keys.py +104 -0
  74. runtime/handy_extract/setup_microg_module.sh +44 -0
  75. runtime/handy_extract/setup_rooted_device.sh +152 -0
  76. runtime/handy_extract/shield_patch.js +151 -0
  77. runtime/handy_extract/sign_helper/AndroidManifest.xml +17 -0
  78. runtime/handy_extract/sign_helper/build.sh +56 -0
  79. runtime/handy_extract/sign_helper/src/com/x2d/sign/SignActivity.java +92 -0
  80. runtime/handy_extract/stalker_syscalls.js +204 -0
  81. runtime/handy_extract/unpack_libapp.py +244 -0
  82. runtime/handy_extract/zygisk/README.md +117 -0
  83. runtime/handy_extract/zygisk/STATUS.md +116 -0
  84. runtime/handy_extract/zygisk/build.sh +97 -0
  85. runtime/handy_extract/zygisk/handy.config.json +23 -0
  86. runtime/handy_extract/zygisk/libgadget.config.so +9 -0
  87. runtime/libEGL_x2dadreno.c +681 -0
  88. runtime/mcp/__init__.py +11 -0
  89. runtime/mcp/server.py +553 -0
  90. runtime/preload_egl_x11.c +443 -0
  91. runtime/preload_gtkinit.c +481 -0
  92. runtime/probes/probe_angle_direct.c +66 -0
  93. runtime/probes/probe_vendor_gl.c +88 -0
  94. runtime/probes/probe_vendor_window.c +142 -0
  95. runtime/queue/__init__.py +15 -0
  96. runtime/queue/manager.py +269 -0
  97. runtime/saga_apt_search.sh +14 -0
  98. runtime/saga_hosts_setup.sh +77 -0
  99. runtime/saga_iptables.sh +35 -0
  100. runtime/saga_mitm_help.sh +7 -0
  101. runtime/saga_mitm_run.sh +46 -0
  102. runtime/saga_mitm_test.sh +34 -0
  103. runtime/saga_patch_mitm.sh +64 -0
  104. runtime/saga_pyplat.sh +18 -0
  105. runtime/saga_termux_mitm.sh +33 -0
  106. runtime/saga_termux_setup.sh +36 -0
  107. runtime/timelapse/__init__.py +10 -0
  108. runtime/timelapse/recorder.py +274 -0
  109. runtime/webrtc/__init__.py +4 -0
  110. runtime/webrtc/server.py +313 -0
  111. runtime/webui/__init__.py +1 -0
  112. web/cam.webrtc.html +103 -0
  113. web/cam.webrtc.js +153 -0
  114. web/index.css +369 -0
  115. web/index.html +124 -0
  116. web/index.js +689 -0
  117. web/login.html +70 -0
  118. web/login.js +81 -0
  119. x2d_bridge.py +6432 -0
  120. x2d_slice.py +739 -0
bambu_cert.py ADDED
@@ -0,0 +1,199 @@
1
+ #!/usr/bin/env python3
2
+ """Bambu Connect signing key — publicly leaked, used by all open-source
3
+ Bambu LAN clients (orca-lan-bridge, bambulab-go, etc.).
4
+
5
+ X2D / H2D / refreshed P1+X1 firmwares (Jan-2025+) require every MQTT
6
+ publish to carry an RSA-SHA256 signature in a top-level `header` block,
7
+ verified against this certificate's public half. Without it the printer
8
+ returns `err_code 84033543 "mqtt message verify failed"` and ignores the
9
+ command. The cert leaked when the Bambu Connect plugin shipped without
10
+ obfuscating the private key from its on-disk JSON config.
11
+
12
+ If Bambu ever rotates and revokes this key, every LAN client breaks at
13
+ once. There is no good way around it short of finding the new cert in
14
+ the next plugin release.
15
+
16
+ cert_id used by the firmware: GLOF3813734089-524a37c80000c6a6a274a47b3281
17
+
18
+ == CLI ==
19
+
20
+ $ python3 bambu_cert.py validate
21
+ Sends a signed `pushing.pushall` to the [printer] in
22
+ ~/.x2d/credentials and reports if the firmware acked. Exit 0
23
+ on success; non-zero (with err_code if firmware sent one) on
24
+ rejection. Cron monthly to alert on cert rotation BEFORE a
25
+ real print silently fails:
26
+ 0 6 1 * * python3 ~/git/x2d/bambu_cert.py validate \
27
+ --silent || systemd-cat -p err -t bambu-cert
28
+
29
+ $ python3 bambu_cert.py validate --printer X2D2
30
+ Pick a [printer:NAME] section. Multi-printer accounts can
31
+ validate every bound printer with `for n in $(x2d_bridge.py
32
+ printers); do bambu_cert.py validate --printer "$n"; done`.
33
+
34
+ $ python3 bambu_cert.py validate --json
35
+ Machine-readable for monitoring stacks. Exit code matches.
36
+ """
37
+
38
+ from __future__ import annotations
39
+
40
+ import argparse
41
+ import json
42
+ import sys
43
+ import time
44
+ from pathlib import Path
45
+
46
+
47
+ BAMBU_PRIVATE_KEY_PEM = """-----BEGIN PRIVATE KEY-----
48
+ MIIEvQIBADANBgkqhkiG9w0B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kr
64
+ upDf7zz+hlvaFewme8aDeV3ex9Wvt73D66nwAy5ABOgn+66vZJeo0Iq/tnCwK3a/
65
+ evTL9BOzPwKBgEUi7AnziEc3Bl4Lttnqa08INZcPgs9grzmv6dVUF6J0Y8qhxFAd
66
+ 1Pw1w5raVfpSMU/QrGzSFKC+iFECLgKVCHOFYwPEgQWNRKLP4BjkcMAgiP63QTU7
67
+ ZS2oHsnJp7Ly6YKPK5Pg5O3JVSU4t+91i7TDc+EfRwTuZQ/KjSrS5u4XAoGBAP06
68
+ v9reSDVELuWyb0Yqzrxm7k7ScbjjJ28aCTAvCTguEaKNHS7DP2jHx5mrMT35N1j7
69
+ NHIcjFG2AnhqTf0M9CJHlQR9B4tvON5ISHJJsNAq5jpd4/G4V2XTEiBNOxKvL1tQ
70
+ 5NrGrD4zHs0R+25GarGcDwg3j7RrP4REHv9NZ4ENAoGAY7Nuz6xKu2XUwuZtJP7O
71
+ kjsoDS7bjP95ddrtsRq5vcVjJ04avnjsr+Se9WDA//t7+eSeHjm5eXD7u0NtdqZo
72
+ WtSm8pmWySOPXMn9QQmdzKHg1NOxer//f1KySVunX1vftTStjsZH7dRCtBEePcqg
73
+ z5Av6MmEFDojtwTqvEZuhBM=
74
+ -----END PRIVATE KEY-----"""
75
+
76
+
77
+ # ---------------------------------------------------------------------------
78
+ # Cert-rotation monitor (item #74).
79
+ #
80
+ # Sends a single signed `pushing.pushall` to the configured printer over
81
+ # the LAN-direct MQTT broker and reports if the firmware acked with
82
+ # state. A silent timeout (no state push back, or err_code=84033543 on
83
+ # the printer's own report stream) means our embedded Bambu Connect cert
84
+ # has been rotated/revoked and every LAN client will stop working.
85
+ # ---------------------------------------------------------------------------
86
+
87
+ # Canonical here — re-exported by x2d_bridge.py to keep its existing
88
+ # import surface backwards-compatible.
89
+ BAMBU_CERT_ID = "GLOF3813734089-524a37c80000c6a6a274a47b3281"
90
+
91
+
92
+ def _validate(printer_section: str, timeout: float, json_out: bool, silent: bool) -> int:
93
+ # Defer the heavy imports so `import bambu_cert` from a test stays cheap.
94
+ sys.path.insert(0, str(Path(__file__).resolve().parent))
95
+ import x2d_bridge # noqa: WPS433
96
+
97
+ class _A:
98
+ ip = ""
99
+ code = ""
100
+ serial = ""
101
+ printer = printer_section
102
+
103
+ try:
104
+ creds = x2d_bridge.Creds.resolve(_A())
105
+ except SystemExit as e:
106
+ if json_out:
107
+ print(json.dumps({"ok": False, "stage": "creds", "error": str(e)}))
108
+ elif not silent:
109
+ print(f"validate: cannot resolve credentials: {e}", file=sys.stderr)
110
+ return 2
111
+
112
+ cli = x2d_bridge.X2DClient(creds)
113
+ started = time.time()
114
+ err_code: int | None = None
115
+ err_stage = ""
116
+ state_seen = False
117
+ try:
118
+ cli.connect(timeout=min(8.0, timeout))
119
+ try:
120
+ state = cli.request_state(timeout=timeout)
121
+ state_seen = bool(state)
122
+ # If the printer fired an err_code in its report stream, surface it.
123
+ err = (state or {}).get("print", {}).get("command_err")
124
+ if isinstance(err, int) and err != 0:
125
+ err_code = err
126
+ err_stage = "command_err"
127
+ except TimeoutError as e:
128
+ err_stage = "timeout"
129
+ err_code = 84033543 # the verify-failed code firmware uses
130
+ if not silent and not json_out:
131
+ print(f"validate: TIMEOUT after {timeout:.0f}s — likely cert rotation",
132
+ file=sys.stderr)
133
+ except Exception as e:
134
+ err_stage = "connect"
135
+ if not silent and not json_out:
136
+ print(f"validate: connect/publish failed: {e}", file=sys.stderr)
137
+ err_code = -1
138
+ finally:
139
+ try:
140
+ cli.disconnect()
141
+ except Exception:
142
+ pass
143
+
144
+ elapsed = time.time() - started
145
+ ok = state_seen and err_code is None
146
+ payload = {
147
+ "ok": ok,
148
+ "printer": creds.serial,
149
+ "ip": creds.ip,
150
+ "elapsed_s": round(elapsed, 2),
151
+ "cert_id": BAMBU_CERT_ID,
152
+ }
153
+ if err_code is not None:
154
+ payload["err_code"] = err_code
155
+ payload["err_stage"] = err_stage
156
+ if json_out:
157
+ print(json.dumps(payload))
158
+ elif not silent:
159
+ if ok:
160
+ print(f"validate: OK — {creds.serial} acked signed pushall in {elapsed:.1f}s")
161
+ else:
162
+ print(f"validate: FAIL — printer={creds.serial} stage={err_stage} "
163
+ f"err_code={err_code} elapsed={elapsed:.1f}s", file=sys.stderr)
164
+ return 0 if ok else 1
165
+
166
+
167
+ def main() -> int:
168
+ ap = argparse.ArgumentParser(
169
+ prog="bambu_cert.py",
170
+ description="Bambu Connect cert tools — currently `validate`.",
171
+ )
172
+ sub = ap.add_subparsers(dest="cmd", required=True)
173
+ v = sub.add_parser(
174
+ "validate",
175
+ help="Probe a printer with a signed pushall and report whether "
176
+ "the embedded Bambu Connect cert is still accepted.",
177
+ description="Sends one signed pushing.pushall to the printer and "
178
+ "waits for the next state report. Useful as a cron "
179
+ "monitor: a sudden FAIL means Bambu rotated the cert "
180
+ "and every LAN client just broke.",
181
+ )
182
+ v.add_argument("--printer", default="",
183
+ help="Section name in ~/.x2d/credentials (default = "
184
+ "[printer]).")
185
+ v.add_argument("--timeout", type=float, default=15.0,
186
+ help="Seconds to wait for the printer's state report (default 15).")
187
+ v.add_argument("--json", action="store_true",
188
+ help="Emit JSON instead of human text.")
189
+ v.add_argument("--silent", action="store_true",
190
+ help="Suppress non-JSON output (exit code only). For cron use.")
191
+ args = ap.parse_args()
192
+
193
+ if args.cmd == "validate":
194
+ return _validate(args.printer, args.timeout, args.json, args.silent)
195
+ return 2
196
+
197
+
198
+ if __name__ == "__main__":
199
+ sys.exit(main())
beambam/__init__.py ADDED
@@ -0,0 +1,70 @@
1
+ """beambam — pure-Python signed-MQTT bridge for Bambu Lab printers
2
+ (Jan-2025+ firmware), plus a daemon stack (Home Assistant, MCP, web UI,
3
+ timelapse, queue, slicing helpers).
4
+
5
+ Supported printers: X1 / X1C / X1E, P1P / P1S, A1 / A1 mini, H2D / H2S /
6
+ H2C, P2S, X2D — anything that requires RSA-SHA256 signed MQTT.
7
+
8
+ Quickstart
9
+ ----------
10
+
11
+ pip install beambam
12
+
13
+ # Configure once in ~/.x2d/credentials (or env vars X2D_IP, X2D_CODE,
14
+ # X2D_SERIAL).
15
+ beambam status
16
+ beambam print mymodel.gcode.3mf
17
+
18
+ Library API
19
+ -----------
20
+
21
+ from beambam import Printer, Creds
22
+
23
+ p = Printer(Creds(ip="192.168.0.138", code="XXXXXXXX", serial="..."))
24
+ state = p.state() # full pushall state
25
+ p.upload("model.gcode.3mf") # FTPS upload
26
+ p.start_print("model.gcode.3mf", ams=[0,1,2]) # signed MQTT
27
+
28
+ NOTE on transitional layout (v1.1.0): this package re-exports the public
29
+ surface from the historical top-level modules (x2d_bridge, cloud_client,
30
+ lan_print, etc.). Subsequent releases will move the implementations under
31
+ src/beambam/ proper — the re-exports here will remain stable.
32
+ """
33
+
34
+ from __future__ import annotations
35
+
36
+ from importlib import metadata as _metadata
37
+
38
+ try:
39
+ __version__ = _metadata.version("beambam")
40
+ except _metadata.PackageNotFoundError:
41
+ # Editable / source checkout without `pip install -e .`
42
+ __version__ = "1.1.0"
43
+
44
+ # Public re-exports. Implementations live in the top-level modules until
45
+ # the src/ layout refactor lands (task #3).
46
+ from x2d_bridge import ( # noqa: E402
47
+ Creds,
48
+ BAMBU_CERT_ID,
49
+ sign_payload,
50
+ upload_file,
51
+ download_file,
52
+ list_files,
53
+ main as cli,
54
+ )
55
+ from cloud_client import CloudClient, CloudError # noqa: E402
56
+ from beambam.printer import Printer # noqa: E402
57
+
58
+ __all__ = [
59
+ "__version__",
60
+ "Printer",
61
+ "Creds",
62
+ "CloudClient",
63
+ "CloudError",
64
+ "BAMBU_CERT_ID",
65
+ "sign_payload",
66
+ "upload_file",
67
+ "download_file",
68
+ "list_files",
69
+ "cli",
70
+ ]