#!/usr/bin/python3
import struct
import subprocess
import xml.etree.ElementTree as ET
from pathlib import Path

collector = Path("/usr/share/sharphound/SharpHound.exe").read_bytes()
assert collector[:2] == b"MZ"
pe = struct.unpack_from("<I", collector, 0x3c)[0]
assert collector[pe:pe+4] == b"PE\0\0"
optional = pe + 24
magic = struct.unpack_from("<H", collector, optional)[0]
assert magic in [0x10b, 0x20b]
directory = optional + (96 if magic == 0x10b else 112)
cli_rva, cli_size = struct.unpack_from("<II", collector, directory + 14 * 8)
assert cli_rva and cli_size, "Windows binary is missing its .NET CLR header"
ET.parse("/usr/share/sharphound/SharpHound.exe.config")
assert Path("/usr/share/sharphound/SharpHound.ps1").stat().st_size > 0
subprocess.run(["sh", "-n", "/usr/bin/sharphound"], check=True)
