feat: xxbb

This commit is contained in:
hashbro
2026-08-13 07:08:02 +08:00
parent c6e386e069
commit dbe6358a3c
11 changed files with 311 additions and 159 deletions
+40 -17
View File
@@ -10,6 +10,7 @@ from pathlib import Path
TOOLS = Path(__file__).resolve().parents[1]
sys.path.insert(0, str(TOOLS))
from _details_pack import extract_member # noqa: E402
from _secondary_pack import decrypt_secondary_minjs # noqa: E402
import build as xxbb_build # noqa: E402
from reproduce_xxbb_dga import generate_domains # noqa: E402
@@ -49,12 +50,12 @@ class XxbbBuildTest(unittest.TestCase):
out = decrypt_secondary_minjs(wire, key)
self.assertEqual(out, patched[info["group"]])
def test_apply_writes_named_channel_html(self) -> None:
def test_apply_writes_shared_weifile_and_patched_details(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
artifact = Path(tmp) / "public"
state = Path(tmp) / "state"
out = Path(tmp) / "out"
name = "abcd1234"
channel_c = "33333333333333333333333333333333"
argv = [
"build.py",
"--deployment-seed",
@@ -62,9 +63,7 @@ class XxbbBuildTest(unittest.TestCase):
"--reporting-seed",
"11111111111111111111111111111111",
"--channel-c",
"33333333333333333333333333333333",
"--channel-name",
name,
channel_c,
"--artifact-root",
str(artifact),
"--state-root",
@@ -80,30 +79,46 @@ class XxbbBuildTest(unittest.TestCase):
self.assertEqual(xxbb_build.main(), 0)
finally:
sys.argv = old
channel_dir = artifact / "source" / name
weifile = artifact / "weifile"
details = artifact / "details"
self.assertTrue((channel_dir / "index.js").is_file())
self.assertTrue((channel_dir / "weifile.html").is_file())
self.assertTrue((channel_dir / "index.html").is_file())
self.assertTrue((weifile / "index.js").is_file())
self.assertTrue((weifile / "weifile.html").is_file())
self.assertFalse((artifact / "source").exists())
self.assertTrue((details / "show.html").is_file())
self.assertTrue((details / "corepayload.js").is_file())
self.assertTrue((details / "helion.js").is_file())
stem = "800d80e0fa1f2baf9a9e41169ecc88e18042bb17"
blob = (channel_dir / f"{stem}.min.js").read_bytes()
blob = (weifile / f"{stem}.min.js").read_bytes()
key = bytes.fromhex(json.loads((TOOLS / "secondary_keys.json").read_text())["stems"][stem]["key"])
dylib = decrypt_secondary_minjs(blob, key)
self.assertIn(b"11111111111111111111111111111111", dylib)
self.assertIn(b"33333333333333333333333333333333", dylib)
self.assertIn(channel_c.encode(), dylib)
self.assertIn(xxbb_build.SEVEN_ZIP_PASSWORD.encode(), dylib)
self.assertIn(b"https://%@\x00", dylib)
self.assertNotIn(b"http://%@\x00", dylib)
member, core = extract_member((details / "corepayload.js").read_bytes())
self.assertEqual(member, "corepayload.dylib")
self.assertEqual(core.count(channel_c.encode()), xxbb_build.CORE_C_EXPECT)
self.assertEqual(core.count(xxbb_build.ORIGINAL_C.encode()), 0)
show_member, show_plain = extract_member((details / "show.html").read_bytes())
self.assertEqual(show_member, "data.bin")
show = json.loads(show_plain.decode("utf-8"))
self.assertEqual(show["core"]["sha256"], xxbb_build.sha256_hex(core))
self.assertEqual(show["core"]["size"], len(core))
seeds = json.loads((state / "lab_seeds.json").read_text())
self.assertEqual(seeds["deployment_seed"], "11111111111111111111111111111111")
self.assertEqual(seeds["reporting_seed"], "11111111111111111111111111111111")
self.assertEqual(seeds["channel_c"], "33333333333333333333333333333333")
self.assertEqual(seeds["channel_c"], channel_c)
self.assertEqual(seeds["domains"]["deployment"][0], "syv4c2c8nb8fpzo.icu")
self.assertTrue(xxbb_build.XXBB_DGA_HOST_RE.fullmatch(seeds["domains"]["deployment"][0]))
manifest = json.loads((out / "MANIFEST.json").read_text())
self.assertEqual(manifest["weifile_path"], "/weifile/weifile.html")
self.assertEqual(manifest["details_path"], "/details/")
def test_seeds_generated_once_then_reused(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
state = Path(tmp) / "state"
@@ -216,23 +231,31 @@ class XxbbBuildTest(unittest.TestCase):
self.assertNotIn(b"https://backup%u.icu\x00", http)
self.assertEqual(len(http), len(https))
def test_apply_requires_channel_name(self) -> None:
def test_apply_works_without_channel_name(self) -> None:
with tempfile.TemporaryDirectory() as tmp:
artifact = Path(tmp) / "public"
state = Path(tmp) / "state"
argv = [
"build.py",
"--channel-c",
"33333333333333333333333333333333",
"--deployment-seed",
"11111111111111111111111111111111",
"--reporting-seed",
"11111111111111111111111111111111",
"--artifact-root",
tmp,
str(artifact),
"--state-root",
tmp,
str(state),
"--apply",
]
old = sys.argv
try:
sys.argv = argv
with self.assertRaises(SystemExit):
xxbb_build.main()
self.assertEqual(xxbb_build.main(), 0)
finally:
sys.argv = old
self.assertTrue((artifact / "weifile" / "weifile.html").is_file())
if __name__ == "__main__":