INNER CODE UNIT · Python

_detect_payload_type

Nour833/StegoForge · web/app.py:79

def _detect_payload_type(data: bytes) -> tuple[str, str]:
    """Return (mime_type, extension) guessed from magic bytes."""
    if len(data) >= 12:
        # ISO base media (mp4/mov) — ftyp box at offset 4
        if data[4:8] == b"ftyp":
            return "video/mp4", ".mp4"
    if data[:4] == b"PK\x03\x04":
        # Could be DOCX or XLSX inside a zip
        return "application/zip", ".zip"
    if data[:4] == b"SFRG":
        return "application/octet-stream", ".sfrg"
    for magic, mime, ext in _MAGIC_MAP:
        if mime and data[:len(magic)] == magic:
            return mime, ext
    # Try UTF-8 text heuristic
    try:
        text = data[:512].decode("utf-8")
        printable = sum(1 for c in text if c.isprintable() or c in "\n\r\t")

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…