import struct import subprocess import tempfile import unittest from pathlib import Path SCRIPT = Path(__file__).resolve().parents[1] / "linuxfs/unwrap-dwarfs.sh" class UnwrapDwarfsTest(unittest.TestCase): def setUp(self): self.temp = tempfile.TemporaryDirectory() self.addCleanup(self.temp.cleanup) self.dir = Path(self.temp.name) self.output = self.dir / "dwarfsextract" def wrapper(self, payload, magic=b"SQUEEZE!", packed=None): compressed = subprocess.run(["zstd", "-q", "-c"], input=payload, capture_output=True, check=True).stdout size = len(compressed) if packed is None else packed path = self.dir / "wrapper" path.write_bytes(b"\x7fELF stub" * 100 + compressed + magic + struct.pack("