{"version":3,"sources":["../src/cli.ts","../src/utils.ts","../src/olefile.ts","../src/exceptions.ts","../src/crypto.ts","../src/method/ecma376_agile.ts","../src/method/ecma376_standard.ts","../src/format/common.ts","../src/format/ooxml.ts","../src/method/rc4_common.ts","../src/method/rc4.ts","../src/method/rc4_cryptoapi.ts","../src/method/xor_obfuscation.ts","../src/format/xls97.ts","../src/format/doc97.ts","../src/format/ppt97.ts","../src/index.ts"],"sourcesContent":["#!/usr/bin/env node\n/**\n * office-crypto CLI. Mirrors the upstream Python `msoffcrypto-tool` script:\n *\n *   office-crypto -p PASSWORD infile [outfile]   # decrypt\n *   office-crypto -t infile                       # test if encrypted\n */\n\nimport { readFileSync, writeFileSync } from \"node:fs\";\nimport { OfficeFile, isEncrypted, FileFormatError } from \"./index.js\";\n\ninterface Args {\n  password?: string;\n  passwordStdin: boolean;\n  passwordFile?: string;\n  test: boolean;\n  encrypt: boolean;\n  verbose: boolean;\n  infile?: string;\n  outfile?: string;\n}\n\nfunction parseArgs(argv: string[]): Args {\n  const args: Args = {\n    test: false,\n    encrypt: false,\n    verbose: false,\n    passwordStdin: false,\n  };\n  const positional: string[] = [];\n  for (let i = 0; i < argv.length; i++) {\n    const a = argv[i];\n    if (a === \"-p\" || a === \"--password\") {\n      // Consume the next token as password unless it starts with '-' or absent.\n      const next = argv[i + 1];\n      if (next !== undefined && !next.startsWith(\"-\")) {\n        args.password = next;\n        i++;\n      } else {\n        args.password = \"\";\n      }\n    } else if (a === \"--password-stdin\") {\n      args.passwordStdin = true;\n    } else if (a === \"--password-file\") {\n      const next = argv[i + 1];\n      if (next === undefined || next.startsWith(\"-\")) {\n        console.error(\"--password-file requires a path argument\");\n        process.exit(2);\n      }\n      args.passwordFile = next;\n      i++;\n    } else if (a === \"-t\" || a === \"--test\") {\n      args.test = true;\n    } else if (a === \"-e\") {\n      args.encrypt = true;\n    } else if (a === \"-v\") {\n      args.verbose = true;\n    } else if (a === \"-h\" || a === \"--help\") {\n      printUsage();\n      process.exit(0);\n    } else if (a === \"--\") {\n      // End of options — remaining args are positional.\n      for (let j = i + 1; j < argv.length; j++) positional.push(argv[j]);\n      break;\n    } else if (a.startsWith(\"-\")) {\n      console.error(`Unknown option: ${a}`);\n      process.exit(2);\n    } else {\n      positional.push(a);\n    }\n  }\n  args.infile = positional[0];\n  args.outfile = positional[1];\n  return args;\n}\n\nfunction printUsage(): void {\n  const lines = [\n    \"Usage: office-crypto [options] infile [outfile]\",\n    \"\",\n    \"Options:\",\n    \"  -p, --password PWD     decrypt with the given password\",\n    \"                         (note: visible in `ps`; prefer the options below)\",\n    \"      --password-stdin   read password from stdin (newline terminates)\",\n    \"      --password-file F  read password from file F (first line)\",\n    \"  -t, --test             test whether the file is encrypted (exit 0=yes, 1=no)\",\n    \"  -v                     verbose output\",\n    \"  -h, --help             show this help\",\n    \"\",\n    \"If outfile is omitted, the decrypted bytes are written to stdout.\",\n    \"If neither -p / --password-stdin / --password-file is given, the user is\",\n    \"prompted on stderr (terminal input).\",\n  ];\n  console.log(lines.join(\"\\n\"));\n}\n\n/**\n * Prompt the user for a password on the controlling terminal, with echo off\n * when stdin is a TTY. Falls back to a regular line read otherwise.\n */\nasync function promptPassword(): Promise<string> {\n  const readline = await import(\"node:readline\");\n\n  if (!process.stdin.isTTY) {\n    // Non-TTY: read a single line without echo handling.\n    const rl = readline.createInterface({ input: process.stdin });\n    return new Promise<string>((resolve) => {\n      rl.once(\"line\", (line: string) => {\n        rl.close();\n        resolve(line);\n      });\n    });\n  }\n\n  process.stderr.write(\"Password: \");\n  process.stdin.setRawMode(true);\n  process.stdin.resume();\n  process.stdin.setEncoding(\"utf8\");\n\n  return new Promise<string>((resolve) => {\n    let pwd = \"\";\n    const onData = (chunk: string) => {\n      for (const ch of chunk) {\n        if (ch === \"\\r\" || ch === \"\\n\") {\n          process.stdin.setRawMode(false);\n          process.stdin.pause();\n          process.stdin.removeListener(\"data\", onData);\n          process.stderr.write(\"\\n\");\n          resolve(pwd);\n          return;\n        }\n        if (ch === \"\\x03\") {\n          // Ctrl-C\n          process.stdin.setRawMode(false);\n          process.stderr.write(\"\\n\");\n          process.exit(130);\n        }\n        if (ch === \"\\x7f\" || ch === \"\\b\") {\n          // Backspace\n          pwd = pwd.slice(0, -1);\n        } else {\n          pwd += ch;\n        }\n      }\n    };\n    process.stdin.on(\"data\", onData);\n  });\n}\n\n/** Read a password from stdin (one line), without prompting. */\nasync function readPasswordFromStdinPipe(): Promise<string> {\n  const chunks: Buffer[] = [];\n  for await (const chunk of process.stdin) {\n    chunks.push(chunk as Buffer);\n  }\n  // Strip a single trailing newline (CR/LF).\n  let s = Buffer.concat(chunks).toString(\"utf8\");\n  if (s.endsWith(\"\\r\\n\")) s = s.slice(0, -2);\n  else if (s.endsWith(\"\\n\") || s.endsWith(\"\\r\")) s = s.slice(0, -1);\n  return s;\n}\n\nasync function resolvePassword(args: Args): Promise<string> {\n  if (args.passwordFile) {\n    const raw = readFileSync(args.passwordFile, \"utf8\");\n    // Use only the first line; trim a trailing newline.\n    const newline = raw.indexOf(\"\\n\");\n    return (newline === -1 ? raw : raw.slice(0, newline)).replace(/\\r$/, \"\");\n  }\n  if (args.passwordStdin) return readPasswordFromStdinPipe();\n  if (args.password !== undefined && args.password !== \"\") return args.password;\n  return promptPassword();\n}\n\nasync function main(): Promise<void> {\n  const args = parseArgs(process.argv.slice(2));\n\n  if (!args.infile) {\n    printUsage();\n    process.exit(2);\n  }\n\n  const buf = readFileSync(args.infile);\n  const view = new Uint8Array(buf.buffer, buf.byteOffset, buf.byteLength);\n\n  if (args.test) {\n    const enc = isEncrypted(view);\n    if (!enc) {\n      console.error(`${args.infile}: not encrypted`);\n      process.exit(1);\n    } else {\n      if (args.verbose) console.error(`${args.infile}: encrypted`);\n      process.exit(0);\n    }\n  }\n\n  if (args.encrypt) {\n    throw new FileFormatError(\n      \"Encryption mode (-e) is not yet implemented in this TypeScript port\",\n    );\n  }\n\n  const password = await resolvePassword(args);\n\n  const file = OfficeFile(view);\n  file.loadKey({ password });\n  const decrypted = file.decrypt();\n\n  if (args.outfile) {\n    writeFileSync(args.outfile, decrypted);\n  } else {\n    process.stdout.write(decrypted);\n  }\n}\n\nmain().catch((err: Error) => {\n  process.stderr.write(`error: ${err.message}\\n`);\n  if (process.env.DEBUG) process.stderr.write(`${err.stack}\\n`);\n  process.exit(1);\n});\n","/**\n * Utility helpers: byte/struct manipulation, UTF-16 encoding, BytesIO equivalent.\n */\n\nexport function concatBytes(...parts: Uint8Array[]): Uint8Array {\n  let total = 0;\n  for (const p of parts) total += p.length;\n  const out = new Uint8Array(total);\n  let off = 0;\n  for (const p of parts) {\n    out.set(p, off);\n    off += p.length;\n  }\n  return out;\n}\n\nexport function bytesEqual(a: Uint8Array, b: Uint8Array): boolean {\n  if (a.length !== b.length) return false;\n  let diff = 0;\n  for (let i = 0; i < a.length; i++) diff |= a[i] ^ b[i];\n  return diff === 0;\n}\n\nexport function utf16leEncode(s: string): Uint8Array {\n  const out = new Uint8Array(s.length * 2);\n  for (let i = 0; i < s.length; i++) {\n    const c = s.charCodeAt(i);\n    out[i * 2] = c & 0xff;\n    out[i * 2 + 1] = (c >>> 8) & 0xff;\n  }\n  return out;\n}\n\nexport function utf16leDecode(b: Uint8Array): string {\n  let s = \"\";\n  for (let i = 0; i + 1 < b.length; i += 2) {\n    const c = b[i] | (b[i + 1] << 8);\n    s += String.fromCharCode(c);\n  }\n  return s;\n}\n\nexport function utf8Encode(s: string): Uint8Array {\n  return new TextEncoder().encode(s);\n}\n\nexport function utf8Decode(b: Uint8Array): string {\n  return new TextDecoder().decode(b);\n}\n\nexport function hexToBytes(hex: string): Uint8Array {\n  const clean = hex.replace(/[^0-9a-fA-F]/g, \"\");\n  const out = new Uint8Array(clean.length / 2);\n  for (let i = 0; i < out.length; i++) {\n    out[i] = parseInt(clean.substr(i * 2, 2), 16);\n  }\n  return out;\n}\n\nexport function bytesToHex(b: Uint8Array): string {\n  let s = \"\";\n  for (let i = 0; i < b.length; i++) s += b[i].toString(16).padStart(2, \"0\");\n  return s;\n}\n\nconst B64_CHARS = \"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/\";\n\nexport function base64Encode(b: Uint8Array): string {\n  // Use globalThis.btoa if available, else manual encode.\n  let s = \"\";\n  for (let i = 0; i < b.length; i += 3) {\n    const a = b[i];\n    const c = i + 1 < b.length ? b[i + 1] : 0;\n    const d = i + 2 < b.length ? b[i + 2] : 0;\n    const n = (a << 16) | (c << 8) | d;\n    s +=\n      B64_CHARS[(n >> 18) & 63] +\n      B64_CHARS[(n >> 12) & 63] +\n      (i + 1 < b.length ? B64_CHARS[(n >> 6) & 63] : \"=\") +\n      (i + 2 < b.length ? B64_CHARS[n & 63] : \"=\");\n  }\n  return s;\n}\n\nexport function base64Decode(s: string): Uint8Array {\n  const clean = s.replace(/\\s+/g, \"\");\n  const raw = clean.replace(/=+$/, \"\");\n  // Output length: every 4 input chars become 3 bytes, plus partial groups\n  // (2 chars → 1 byte, 3 chars → 2 bytes).\n  const fullGroups = Math.floor(raw.length / 4);\n  const remainder = raw.length % 4;\n  const outLen =\n    fullGroups * 3 + (remainder === 2 ? 1 : remainder === 3 ? 2 : 0);\n  const out = new Uint8Array(outLen);\n  let oi = 0;\n  for (let i = 0; i < raw.length; i += 4) {\n    const a = B64_CHARS.indexOf(raw[i]);\n    const b = B64_CHARS.indexOf(raw[i + 1]);\n    const c = i + 2 < raw.length ? B64_CHARS.indexOf(raw[i + 2]) : 0;\n    const d = i + 3 < raw.length ? B64_CHARS.indexOf(raw[i + 3]) : 0;\n    const n = (a << 18) | (b << 12) | (c << 6) | d;\n    out[oi++] = (n >> 16) & 0xff;\n    if (i + 2 < raw.length) out[oi++] = (n >> 8) & 0xff;\n    if (i + 3 < raw.length) out[oi++] = n & 0xff;\n  }\n  return out;\n}\n\n/**\n * Pack 32-bit unsigned little-endian.\n */\nexport function packU32LE(n: number): Uint8Array {\n  const b = new Uint8Array(4);\n  b[0] = n & 0xff;\n  b[1] = (n >>> 8) & 0xff;\n  b[2] = (n >>> 16) & 0xff;\n  b[3] = (n >>> 24) & 0xff;\n  return b;\n}\n\nexport function packU16LE(n: number): Uint8Array {\n  const b = new Uint8Array(2);\n  b[0] = n & 0xff;\n  b[1] = (n >>> 8) & 0xff;\n  return b;\n}\n\nexport function packU64LE(n: bigint | number): Uint8Array {\n  const v = typeof n === \"bigint\" ? n : BigInt(n);\n  const b = new Uint8Array(8);\n  const lo = Number(v & 0xffffffffn);\n  const hi = Number((v >> 32n) & 0xffffffffn);\n  b[0] = lo & 0xff;\n  b[1] = (lo >>> 8) & 0xff;\n  b[2] = (lo >>> 16) & 0xff;\n  b[3] = (lo >>> 24) & 0xff;\n  b[4] = hi & 0xff;\n  b[5] = (hi >>> 8) & 0xff;\n  b[6] = (hi >>> 16) & 0xff;\n  b[7] = (hi >>> 24) & 0xff;\n  return b;\n}\n\n/**\n * Read helpers (little-endian).\n */\nexport function readU16LE(b: Uint8Array, o = 0): number {\n  return b[o] | (b[o + 1] << 8);\n}\nexport function readU32LE(b: Uint8Array, o = 0): number {\n  return (\n    (b[o] | (b[o + 1] << 8) | (b[o + 2] << 16) | (b[o + 3] << 24)) >>> 0\n  );\n}\nexport function readU64LE(b: Uint8Array, o = 0): bigint {\n  const lo = BigInt(readU32LE(b, o));\n  const hi = BigInt(readU32LE(b, o + 4));\n  return (hi << 32n) | lo;\n}\nexport function readI32LE(b: Uint8Array, o = 0): number {\n  return b[o] | (b[o + 1] << 8) | (b[o + 2] << 16) | (b[o + 3] << 24);\n}\n\n/**\n * Minimal stream-reader interface — both `BytesIO` and the read-only\n * `OleStream` satisfy this. Used by the `read{U16,U32,U64}` stream helpers\n * below so callers don't have to write `readU32LE(s.read(4), 0)` everywhere.\n */\nexport interface Readable {\n  read(size?: number): Uint8Array;\n}\n\nexport function readU16(s: Readable): number {\n  return readU16LE(s.read(2), 0);\n}\nexport function readU32(s: Readable): number {\n  return readU32LE(s.read(4), 0);\n}\nexport function readU64(s: Readable): bigint {\n  return readU64LE(s.read(8), 0);\n}\n\n/**\n * Append-style bytes builder. Replaces the `parts.push(packU32LE(...))` +\n * concat dance used by the various `pack*` helpers in the format/ folder.\n */\nexport class ByteWriter {\n  private chunks: Uint8Array[] = [];\n  private len = 0;\n\n  bytes(b: Uint8Array): this {\n    this.chunks.push(b);\n    this.len += b.length;\n    return this;\n  }\n  u8(v: number): this {\n    this.chunks.push(new Uint8Array([v & 0xff]));\n    this.len += 1;\n    return this;\n  }\n  u16(v: number): this {\n    return this.bytes(packU16LE(v));\n  }\n  u32(v: number): this {\n    return this.bytes(packU32LE(v >>> 0));\n  }\n  u64(v: bigint | number): this {\n    return this.bytes(packU64LE(v));\n  }\n  zeros(n: number): this {\n    return this.bytes(new Uint8Array(n));\n  }\n\n  get length(): number {\n    return this.len;\n  }\n\n  build(): Uint8Array {\n    const out = new Uint8Array(this.len);\n    let off = 0;\n    for (const c of this.chunks) {\n      out.set(c, off);\n      off += c.length;\n    }\n    return out;\n  }\n}\n\n/**\n * Bit-field helpers for the legacy formats (FibBase, RecordHeader, etc.).\n */\nexport function getBit(bits: number, i: number): number {\n  return (bits >>> i) & 1;\n}\nexport function getBitSlice(bits: number, i: number, w: number): number {\n  return (bits >>> i) & ((1 << w) - 1);\n}\nexport function setBit(bits: number, i: number, v: number): number {\n  return v ? bits | (1 << i) : bits & ~(1 << i);\n}\nexport function setBitSlice(\n  bits: number,\n  i: number,\n  w: number,\n  v: number,\n): number {\n  const mask = ((1 << w) - 1) << i;\n  return (bits & ~mask) | ((v & ((1 << w) - 1)) << i);\n}\n\n/**\n * Stream-like wrapper around a Uint8Array providing seek/tell/read.\n * Mirrors `io.BytesIO` semantics enough for the rest of the library.\n */\nexport class BytesIO {\n  private _buf: Uint8Array;\n  private _pos = 0;\n\n  constructor(initial?: Uint8Array | ArrayBuffer | number) {\n    if (initial === undefined) {\n      this._buf = new Uint8Array(0);\n    } else if (typeof initial === \"number\") {\n      this._buf = new Uint8Array(initial);\n    } else if (initial instanceof ArrayBuffer) {\n      this._buf = new Uint8Array(initial);\n    } else {\n      this._buf = initial;\n    }\n  }\n\n  get length(): number {\n    return this._buf.length;\n  }\n\n  tell(): number {\n    return this._pos;\n  }\n\n  seek(offset: number, whence: 0 | 1 | 2 = 0): number {\n    if (whence === 0) this._pos = offset;\n    else if (whence === 1) this._pos += offset;\n    else this._pos = this._buf.length + offset;\n    if (this._pos < 0) this._pos = 0;\n    return this._pos;\n  }\n\n  read(size?: number): Uint8Array {\n    const remaining = this._buf.length - this._pos;\n    const n = size === undefined ? remaining : Math.min(size, remaining);\n    const out = this._buf.subarray(this._pos, this._pos + n);\n    this._pos += n;\n    return out;\n  }\n\n  /** Returns the entire underlying buffer (does not move position). */\n  getValue(): Uint8Array {\n    return this._buf;\n  }\n\n  /**\n   * Writes data at the current position, growing the buffer if needed.\n   */\n  write(data: Uint8Array): number {\n    const needed = this._pos + data.length;\n    if (needed > this._buf.length) {\n      const next = new Uint8Array(needed);\n      next.set(this._buf, 0);\n      this._buf = next;\n    }\n    this._buf.set(data, this._pos);\n    this._pos += data.length;\n    return data.length;\n  }\n}\n\n/**\n * Coerce input (Uint8Array | ArrayBuffer | BytesIO) into BytesIO.\n */\nexport function toBytesIO(\n  src: Uint8Array | ArrayBuffer | BytesIO,\n): BytesIO {\n  if (src instanceof BytesIO) return src;\n  return new BytesIO(src);\n}\n","/**\n * Minimal OLE2 / Microsoft Compound File Binary (CFB) reader.\n *\n * Direct TypeScript port of the read-only subset of `olefile.py` (Philippe\n * Lagadec) needed by msoffcrypto: header parsing, FAT/MiniFAT/DIFAT loading,\n * directory tree walking, and stream extraction. Encrypted OOXML containers,\n * and legacy XLS/DOC/PPT files, expose their data through this layer.\n *\n * Original Python: https://www.decalage.info/olefile (BSD-2-Clause-like)\n */\n\nimport { readU16LE, readU32LE, utf16leDecode } from \"./utils.js\";\n\nexport const MAGIC = new Uint8Array([\n  0xd0, 0xcf, 0x11, 0xe0, 0xa1, 0xb1, 0x1a, 0xe1,\n]);\n\nexport const MAXREGSECT = 0xfffffffa;\nexport const DIFSECT = 0xfffffffc;\nexport const FATSECT = 0xfffffffd;\nexport const ENDOFCHAIN = 0xfffffffe;\nexport const FREESECT = 0xffffffff;\n\nexport const NOSTREAM = 0xffffffff;\nexport const UNKNOWN_SIZE = 0x7fffffff;\n\nexport const STGTY_EMPTY = 0;\nexport const STGTY_STORAGE = 1;\nexport const STGTY_STREAM = 2;\nexport const STGTY_LOCKBYTES = 3;\nexport const STGTY_PROPERTY = 4;\nexport const STGTY_ROOT = 5;\n\nexport const MINIMAL_OLEFILE_SIZE = 1536;\n\nexport class OleFileError extends Error {\n  constructor(message: string) {\n    super(message);\n    this.name = \"OleFileError\";\n  }\n}\n\nexport class NotOleFileError extends OleFileError {\n  constructor(message: string) {\n    super(message);\n    this.name = \"NotOleFileError\";\n  }\n}\n\n/**\n * Test if `data` looks like an OLE2 compound file by checking the magic bytes\n * at the start. Mirrors `olefile.isOleFile`.\n */\nexport function isOleFile(data: Uint8Array): boolean {\n  if (data.length < MAGIC.length) return false;\n  for (let i = 0; i < MAGIC.length; i++) {\n    if (data[i] !== MAGIC[i]) return false;\n  }\n  return true;\n}\n\n/**\n * Directory entry as parsed from the 128-byte directory record.\n * Field names match the AAF/MS-CFB specification.\n */\nexport interface OleDirectoryEntry {\n  sid: number;\n  name: string;\n  entryType: number;\n  color: number;\n  sidLeft: number;\n  sidRight: number;\n  sidChild: number;\n  clsid: string;\n  stateBits: number;\n  createTime: bigint;\n  modifyTime: bigint;\n  isectStart: number;\n  size: number;\n  isMinifat: boolean;\n  kids: OleDirectoryEntry[];\n  used: boolean;\n}\n\n/**\n * Read-only view of a single OLE stream. Returns the materialized bytes once;\n * the .py implementation eagerly assembles the sector chain into a BytesIO,\n * and we mirror that.\n */\nexport class OleStream {\n  private _buf: Uint8Array;\n  private _pos = 0;\n\n  constructor(buf: Uint8Array) {\n    this._buf = buf;\n  }\n\n  get size(): number {\n    return this._buf.length;\n  }\n\n  tell(): number {\n    return this._pos;\n  }\n\n  seek(offset: number, whence: 0 | 1 | 2 = 0): number {\n    if (whence === 0) this._pos = offset;\n    else if (whence === 1) this._pos += offset;\n    else this._pos = this._buf.length + offset;\n    if (this._pos < 0) this._pos = 0;\n    return this._pos;\n  }\n\n  read(size?: number): Uint8Array {\n    const remaining = this._buf.length - this._pos;\n    const n = size === undefined ? remaining : Math.min(size, remaining);\n    const out = this._buf.subarray(this._pos, this._pos + n);\n    this._pos += n;\n    return out;\n  }\n\n  /** Whole stream contents (does not move position). */\n  getValue(): Uint8Array {\n    return this._buf;\n  }\n}\n\ntype ParsedDirEntry = OleDirectoryEntry;\n\n/**\n * Read-only OLE/CFB compound file accessor.\n *\n * Constructed from a raw `Uint8Array`. After construction, use `openstream`\n * to read named streams or `listdir` to enumerate them.\n */\nexport class OleFileIO {\n  // Header values\n  private dllVersion = 0;\n  private byteOrder = 0;\n  private sectorShift = 0;\n  private miniSectorShift = 0;\n  private firstDirSector = 0;\n  private miniStreamCutoffSize = 0;\n  private firstMiniFatSector = 0;\n  private numMiniFatSectors = 0;\n  private firstDifatSector = 0;\n  private numDifatSectors = 0;\n\n  private sectorSize = 0;\n  private miniSectorSize = 0;\n  private nbSect = 0;\n  private filesize = 0;\n\n  private fp: Uint8Array;\n  private fat: number[] = [];\n  private minifat: number[] | null = null;\n  private ministream: Uint8Array | null = null;\n  private writable = false;\n\n  private direntries: ParsedDirEntry[] = [];\n  public root!: ParsedDirEntry;\n\n  constructor(input: Uint8Array | ArrayBuffer) {\n    const buf = input instanceof ArrayBuffer ? new Uint8Array(input) : input;\n    this.fp = buf;\n    this.filesize = buf.length;\n    this.parseHeader();\n    this.loadFat();\n    this.loadDirectory();\n  }\n\n  /**\n   * Return the underlying file bytes. After `writeStream` calls, this reflects\n   * the modified container.\n   */\n  getBuffer(): Uint8Array {\n    return this.fp;\n  }\n\n  /**\n   * Make sure `this.fp` is a private writable copy. Called before any\n   * `writeStream` mutation.\n   */\n  private ensureWritable(): void {\n    if (this.writable) return;\n    const copy = new Uint8Array(this.fp.length);\n    copy.set(this.fp, 0);\n    this.fp = copy;\n    this.writable = true;\n  }\n\n  // ---- Header parsing ----\n\n  private parseHeader(): void {\n    if (this.filesize < MINIMAL_OLEFILE_SIZE) {\n      throw new NotOleFileError(\"File too small to be an OLE file\");\n    }\n    const header = this.fp.subarray(0, 512);\n    for (let i = 0; i < MAGIC.length; i++) {\n      if (header[i] !== MAGIC[i]) {\n        throw new NotOleFileError(\"Not an OLE2 structured storage file\");\n      }\n    }\n\n    this.dllVersion = readU16LE(header, 0x1a);\n    this.byteOrder = readU16LE(header, 0x1c);\n    this.sectorShift = readU16LE(header, 0x1e);\n    this.miniSectorShift = readU16LE(header, 0x20);\n    // 0x22..0x27: reserved (6 bytes)\n    // 0x28: numDirSectors (only used for 4K sector files; we don't validate)\n    // 0x2c: numFatSectors (validation only — DIFAT walk handles overflow)\n    this.firstDirSector = readU32LE(header, 0x30);\n    // 0x34: transactionSignatureNumber\n    this.miniStreamCutoffSize = readU32LE(header, 0x38);\n    this.firstMiniFatSector = readU32LE(header, 0x3c);\n    this.numMiniFatSectors = readU32LE(header, 0x40);\n    this.firstDifatSector = readU32LE(header, 0x44);\n    this.numDifatSectors = readU32LE(header, 0x48);\n\n    if (this.byteOrder !== 0xfffe) {\n      throw new OleFileError(\"Unsupported byte order in OLE header\");\n    }\n    if (this.dllVersion !== 3 && this.dllVersion !== 4) {\n      throw new OleFileError(\"Unsupported DLL version in OLE header\");\n    }\n    this.sectorSize = 1 << this.sectorShift;\n    this.miniSectorSize = 1 << this.miniSectorShift;\n    if (this.sectorSize !== 512 && this.sectorSize !== 4096) {\n      throw new OleFileError(\n        `Unsupported sector size: ${this.sectorSize}`,\n      );\n    }\n    if (this.miniSectorSize !== 64) {\n      throw new OleFileError(\n        `Unsupported mini sector size: ${this.miniSectorSize}`,\n      );\n    }\n    this.nbSect =\n      Math.floor((this.filesize + this.sectorSize - 1) / this.sectorSize) - 1;\n  }\n\n  // ---- Sector access ----\n\n  /** Read a full sector by index (from the file allocation space). */\n  private getSect(sect: number): Uint8Array {\n    const off = this.sectorSize * (sect + 1);\n    if (off + this.sectorSize > this.fp.length) {\n      // Some OLE files terminate without a fully padded final sector. Return\n      // whatever bytes remain (the caller already trims to declared size).\n      return this.fp.subarray(off, this.fp.length);\n    }\n    return this.fp.subarray(off, off + this.sectorSize);\n  }\n\n  // ---- FAT / DIFAT loading ----\n\n  private sectorToU32Array(sect: Uint8Array): number[] {\n    const n = sect.length >> 2;\n    const out = new Array<number>(n);\n    for (let i = 0; i < n; i++) {\n      out[i] = readU32LE(sect, i * 4);\n    }\n    return out;\n  }\n\n  /**\n   * Walk through one DIFAT-style array of FAT sector pointers and append the\n   * referenced FAT sectors to `this.fat`.\n   */\n  private loadFatSect(values: number[]): number {\n    let isect = ENDOFCHAIN;\n    for (const raw of values) {\n      isect = raw >>> 0;\n      if (isect === ENDOFCHAIN || isect === FREESECT) break;\n      const sectorBytes = this.getSect(isect);\n      const next = this.sectorToU32Array(sectorBytes);\n      for (const v of next) this.fat.push(v >>> 0);\n    }\n    return isect;\n  }\n\n  private loadFat(): void {\n    // The first 109 FAT sector pointers live in the header itself,\n    // starting at offset 0x4C (76).\n    const headerSlice = this.fp.subarray(76, 512);\n    const headerFatRefs = this.sectorToU32Array(headerSlice);\n    this.loadFatSect(headerFatRefs);\n\n    if (this.numDifatSectors !== 0) {\n      const slotsPerSector = (this.sectorSize >> 2) - 1;\n      let isect = this.firstDifatSector >>> 0;\n      for (let i = 0; i < this.numDifatSectors; i++) {\n        const sectorBytes = this.getSect(isect);\n        const difat = this.sectorToU32Array(sectorBytes);\n        this.loadFatSect(difat.slice(0, slotsPerSector));\n        isect = difat[slotsPerSector] >>> 0;\n        if (isect === ENDOFCHAIN || isect === FREESECT) break;\n      }\n    }\n\n    if (this.fat.length > this.nbSect) {\n      this.fat.length = this.nbSect;\n    }\n  }\n\n  private loadMinifat(): void {\n    if (this.minifat !== null) return;\n    const streamSize = this.numMiniFatSectors * this.sectorSize;\n    const data = this.openByChain(\n      this.firstMiniFatSector,\n      streamSize,\n      /*forceFat=*/ true,\n    );\n    const arr = this.sectorToU32Array(data);\n    const nbMinisectors = Math.floor(\n      (this.root.size + this.miniSectorSize - 1) / this.miniSectorSize,\n    );\n    this.minifat = arr.slice(0, nbMinisectors).map((v) => v >>> 0);\n  }\n\n  private getMinistream(): Uint8Array {\n    if (this.ministream !== null) return this.ministream;\n    this.ministream = this.openByChain(\n      this.root.isectStart,\n      this.root.size,\n      /*forceFat=*/ true,\n    );\n    return this.ministream;\n  }\n\n  /**\n   * Read a full sector chain and return the joined bytes (truncated to size,\n   * if known). This is the workhorse used by both stream loading and FAT\n   * sub-stream extraction.\n   */\n  private openByChain(\n    start: number,\n    size: number,\n    forceFat: boolean,\n  ): Uint8Array {\n    const useMinifat = !forceFat && size < this.miniStreamCutoffSize;\n    let sectorSize: number;\n    let fat: number[];\n    let storage: Uint8Array;\n    let offset: number;\n\n    if (useMinifat) {\n      this.loadMinifat();\n      const ministream = this.getMinistream();\n      sectorSize = this.miniSectorSize;\n      fat = this.minifat!;\n      storage = ministream;\n      offset = 0;\n    } else {\n      sectorSize = this.sectorSize;\n      fat = this.fat;\n      storage = this.fp;\n      offset = this.sectorSize; // FAT sectors are 1-indexed relative to file start\n    }\n\n    let unknownSize = false;\n    if (size === UNKNOWN_SIZE) {\n      size = fat.length * sectorSize;\n      unknownSize = true;\n    }\n\n    const nbSectors = Math.floor((size + (sectorSize - 1)) / sectorSize);\n    const parts: Uint8Array[] = [];\n    let sect = start >>> 0;\n\n    for (let i = 0; i < nbSectors; i++) {\n      if (sect === ENDOFCHAIN) {\n        if (unknownSize) break;\n        throw new OleFileError(\"Incomplete OLE stream (early ENDOFCHAIN)\");\n      }\n      if (sect >= fat.length) {\n        throw new OleFileError(\n          `Incorrect OLE FAT sector index ${sect.toString(16)}`,\n        );\n      }\n      const sliceStart = offset + sectorSize * sect;\n      const sliceEnd = Math.min(sliceStart + sectorSize, storage.length);\n      parts.push(storage.subarray(sliceStart, sliceEnd));\n      sect = fat[sect] >>> 0;\n    }\n\n    let total = 0;\n    for (const p of parts) total += p.length;\n    const joined = new Uint8Array(total);\n    {\n      let off = 0;\n      for (const p of parts) {\n        joined.set(p, off);\n        off += p.length;\n      }\n    }\n    if (joined.length >= size) return joined.subarray(0, size);\n    return joined;\n  }\n\n  // ---- Directory parsing ----\n\n  private parseDirEntry(buf: Uint8Array, sid: number): ParsedDirEntry {\n    // 64s name_raw + H namelength + B type + B color + I left + I right + I child\n    // + 16s clsid + I stateBits + Q createTime + Q modifyTime + I isectStart\n    // + I sizeLow + I sizeHigh\n    const nameRaw = buf.subarray(0, 64);\n    const nameLength = readU16LE(buf, 64);\n    const entryType = buf[66];\n    const color = buf[67];\n    const sidLeft = readU32LE(buf, 68);\n    const sidRight = readU32LE(buf, 72);\n    const sidChild = readU32LE(buf, 76);\n\n    const clsidBytes = buf.subarray(80, 96);\n    const stateBits = readU32LE(buf, 96);\n    const createTime = bytesToBigUint64LE(buf, 100);\n    const modifyTime = bytesToBigUint64LE(buf, 108);\n    const isectStart = readU32LE(buf, 116);\n    const sizeLow = readU32LE(buf, 120);\n    const sizeHigh = readU32LE(buf, 124);\n\n    const safeNameLen = Math.max(0, Math.min(nameLength, 64) - 2);\n    const name = utf16leDecode(nameRaw.subarray(0, safeNameLen));\n\n    let size: number;\n    if (this.sectorSize === 512) {\n      size = sizeLow;\n    } else {\n      // Up to 2^53 — JS number is fine here, real-world streams aren't anywhere near that.\n      size = sizeLow + sizeHigh * 0x100000000;\n    }\n\n    const isMinifat =\n      entryType === STGTY_STREAM &&\n      size > 0 &&\n      size < this.miniStreamCutoffSize;\n\n    return {\n      sid,\n      name,\n      entryType,\n      color,\n      sidLeft,\n      sidRight,\n      sidChild,\n      clsid: formatClsid(clsidBytes),\n      stateBits,\n      createTime,\n      modifyTime,\n      isectStart,\n      size,\n      isMinifat,\n      kids: [],\n      used: false,\n    };\n  }\n\n  private loadDirectory(): void {\n    const dirData = this.openByChain(\n      this.firstDirSector,\n      UNKNOWN_SIZE,\n      /*forceFat=*/ true,\n    );\n    const maxEntries = Math.floor(dirData.length / 128);\n    this.direntries = new Array(maxEntries);\n\n    // Lazily fault entries in as the storage tree is walked.\n    const loadEntry = (sid: number): ParsedDirEntry => {\n      if (sid < 0 || sid >= maxEntries) {\n        throw new OleFileError(\n          `OLE directory index out of range: ${sid}`,\n        );\n      }\n      const cached = this.direntries[sid];\n      if (cached) return cached;\n      const entry = this.parseDirEntry(\n        dirData.subarray(sid * 128, (sid + 1) * 128),\n        sid,\n      );\n      this.direntries[sid] = entry;\n      return entry;\n    };\n\n    const root = loadEntry(0);\n    if (root.entryType !== STGTY_ROOT) {\n      throw new OleFileError(\"First directory entry is not the root entry\");\n    }\n    this.root = root;\n\n    // Walk the red-black tree in-order to collect children. Per the spec, the\n    // tree contains storage and stream entries; visit left, self, right and\n    // recurse into storages.\n    const appendKids = (parent: ParsedDirEntry, childSid: number): void => {\n      if (childSid === NOSTREAM) return;\n      const child = loadEntry(childSid);\n      if (child.used) {\n        throw new OleFileError(\"OLE entry referenced more than once\");\n      }\n      child.used = true;\n      appendKids(parent, child.sidLeft);\n      parent.kids.push(child);\n      appendKids(parent, child.sidRight);\n      if (child.sidChild !== NOSTREAM) {\n        appendKids(child, child.sidChild);\n        child.kids.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));\n      }\n    };\n\n    if (root.sidChild !== NOSTREAM) {\n      appendKids(root, root.sidChild);\n      root.kids.sort((a, b) => (a.name < b.name ? -1 : a.name > b.name ? 1 : 0));\n    }\n  }\n\n  // ---- Public API ----\n\n  /**\n   * Find a directory entry by case-insensitive path. Path may be a string with\n   * '/' separators or an array of names.\n   */\n  private find(filename: string | string[]): ParsedDirEntry {\n    const parts =\n      typeof filename === \"string\" ? filename.split(\"/\") : filename;\n    let node: ParsedDirEntry = this.root;\n    for (const name of parts) {\n      const lower = name.toLowerCase();\n      const next = node.kids.find((k) => k.name.toLowerCase() === lower);\n      if (!next) {\n        throw new OleFileError(`Stream not found: ${parts.join(\"/\")}`);\n      }\n      node = next;\n    }\n    return node;\n  }\n\n  /** Return true if the named stream/storage exists in the file. */\n  exists(filename: string | string[]): boolean {\n    try {\n      this.find(filename);\n      return true;\n    } catch {\n      return false;\n    }\n  }\n\n  /** Get the size of a named stream. */\n  getSize(filename: string | string[]): number {\n    return this.find(filename).size;\n  }\n\n  /**\n   * Open a named stream and return a read-only `OleStream` that exposes\n   * `seek/tell/read`. Mirrors `olefile.openstream`.\n   */\n  openstream(filename: string | string[]): OleStream {\n    const entry = this.find(filename);\n    if (entry.entryType !== STGTY_STREAM) {\n      throw new OleFileError(`Not a stream: ${filename}`);\n    }\n    if (entry.size === 0) return new OleStream(new Uint8Array(0));\n    const data =\n      entry.isMinifat && entry.size < this.miniStreamCutoffSize\n        ? this.openByChain(entry.isectStart, entry.size, false)\n        : this.openByChain(entry.isectStart, entry.size, true);\n    return new OleStream(data);\n  }\n\n  /**\n   * Overwrite the contents of an existing stream with `data`. The new data\n   * MUST be exactly the same size as the original — this keeps the FAT chain\n   * untouched, which is all we need for the legacy decrypt-in-place flow.\n   *\n   * Handles both FAT and MiniFAT-allocated streams.\n   */\n  writeStream(filename: string | string[], data: Uint8Array): void {\n    const entry = this.find(filename);\n    if (entry.entryType !== STGTY_STREAM) {\n      throw new OleFileError(`Not a stream: ${filename}`);\n    }\n    if (data.length !== entry.size) {\n      throw new OleFileError(\n        `writeStream requires same-sized data (expected ${entry.size}, got ${data.length})`,\n      );\n    }\n    this.ensureWritable();\n\n    if (entry.isMinifat && entry.size < this.miniStreamCutoffSize) {\n      this.writeStreamMiniFat(entry, data);\n    } else {\n      this.writeStreamFat(entry, data);\n    }\n  }\n\n  /** Walk the FAT chain for a stream and overwrite each sector. */\n  private writeStreamFat(entry: OleDirectoryEntry, data: Uint8Array): void {\n    let sect = entry.isectStart >>> 0;\n    let off = 0;\n    const sectorSize = this.sectorSize;\n    while (off < data.length) {\n      if (sect === ENDOFCHAIN || sect >= this.fat.length) {\n        throw new OleFileError(\"FAT chain ended unexpectedly during write\");\n      }\n      const fileOffset = this.sectorSize + sect * sectorSize;\n      const remaining = data.length - off;\n      const chunk = data.subarray(off, off + Math.min(sectorSize, remaining));\n      this.fp.set(chunk, fileOffset);\n      off += chunk.length;\n      sect = this.fat[sect] >>> 0;\n    }\n  }\n\n  /**\n   * Mini-streams live inside the root entry's stream (which itself follows the\n   * regular FAT). Walk the MiniFAT chain to compute mini-sector positions, map\n   * those into FAT positions, and write.\n   */\n  private writeStreamMiniFat(\n    entry: OleDirectoryEntry,\n    data: Uint8Array,\n  ): void {\n    this.loadMinifat();\n    const minifat = this.minifat!;\n    const ministreamSize = this.root.size;\n\n    // The ministream itself is allocated on the FAT — collect its sectors.\n    const ministreamFatSectors: number[] = [];\n    let sect = this.root.isectStart >>> 0;\n    const fatSectorCount = Math.ceil(ministreamSize / this.sectorSize);\n    for (let i = 0; i < fatSectorCount; i++) {\n      if (sect === ENDOFCHAIN || sect >= this.fat.length) break;\n      ministreamFatSectors.push(sect);\n      sect = this.fat[sect] >>> 0;\n    }\n\n    // For each mini-sector, find its position inside the ministream, then map\n    // that to (fatSectorIndex, offsetInsideFatSector).\n    let miniSect = entry.isectStart >>> 0;\n    let off = 0;\n    while (off < data.length) {\n      if (miniSect === ENDOFCHAIN || miniSect >= minifat.length) {\n        throw new OleFileError(\"MiniFAT chain ended unexpectedly during write\");\n      }\n      const ministreamOffset = miniSect * this.miniSectorSize;\n      const fatSectorIdx = Math.floor(ministreamOffset / this.sectorSize);\n      const offsetInFatSector = ministreamOffset % this.sectorSize;\n      const fileOffset =\n        this.sectorSize +\n        ministreamFatSectors[fatSectorIdx] * this.sectorSize +\n        offsetInFatSector;\n      const remaining = data.length - off;\n      const chunk = data.subarray(\n        off,\n        off + Math.min(this.miniSectorSize, remaining),\n      );\n      this.fp.set(chunk, fileOffset);\n      off += chunk.length;\n      miniSect = minifat[miniSect] >>> 0;\n    }\n\n    // Invalidate the cached ministream so next reads pick up fresh data.\n    this.ministream = null;\n  }\n\n  /** List all stream paths in the file (depth-first walk). */\n  listdir(streams = true, storages = false): string[][] {\n    const out: string[][] = [];\n    const walk = (node: ParsedDirEntry, prefix: string[]) => {\n      for (const kid of node.kids) {\n        const path = [...prefix, kid.name];\n        if (kid.entryType === STGTY_STORAGE) {\n          if (storages) out.push(path);\n          walk(kid, path);\n        } else if (kid.entryType === STGTY_STREAM) {\n          if (streams) out.push(path);\n        }\n      }\n    };\n    walk(this.root, []);\n    return out;\n  }\n}\n\nfunction bytesToBigUint64LE(b: Uint8Array, o = 0): bigint {\n  const lo = BigInt(readU32LE(b, o));\n  const hi = BigInt(readU32LE(b, o + 4));\n  return (hi << 32n) | lo;\n}\n\nfunction formatClsid(b: Uint8Array): string {\n  let allZero = true;\n  for (const byte of b) if (byte !== 0) { allZero = false; break; }\n  if (allZero) return \"\";\n  const hex2 = (n: number) => n.toString(16).padStart(2, \"0\").toUpperCase();\n  const hex4 = (n: number) => n.toString(16).padStart(4, \"0\").toUpperCase();\n  const hex8 = (n: number) => n.toString(16).padStart(8, \"0\").toUpperCase();\n  const a = hex8(readU32LE(b, 0));\n  const c = hex4(readU16LE(b, 4));\n  const d = hex4(readU16LE(b, 6));\n  let tail = \"\";\n  for (let i = 8; i < 16; i++) tail += hex2(b[i]);\n  return `${a}-${c}-${d}-${tail.slice(0, 4)}-${tail.slice(4)}`;\n}\n","export class FileFormatError extends Error {\n  constructor(message: string) {\n    super(message);\n    this.name = \"FileFormatError\";\n  }\n}\n\nexport class ParseError extends Error {\n  constructor(message: string) {\n    super(message);\n    this.name = \"ParseError\";\n  }\n}\n\nexport class DecryptionError extends Error {\n  constructor(message: string) {\n    super(message);\n    this.name = \"DecryptionError\";\n  }\n}\n\nexport class EncryptionError extends Error {\n  constructor(message: string) {\n    super(message);\n    this.name = \"EncryptionError\";\n  }\n}\n\nexport class InvalidKeyError extends DecryptionError {\n  constructor(message: string) {\n    super(message);\n    this.name = \"InvalidKeyError\";\n  }\n}\n","/**\n * Cryptography helpers backed by Node.js `node:crypto`.\n *\n * Algorithms used by the Office encryption schemes:\n *   - SHA-1 / SHA-256 / SHA-384 / SHA-512\n *   - MD5 (used by RC4 / XOR obfuscation)\n *   - HMAC-{SHA1,256,384,512}\n *   - AES-CBC / AES-ECB (128, 192, 256 bit keys)\n *   - RC4 (a.k.a. ARC4) — implemented in pure TS to avoid OpenSSL legacy provider\n *   - RSA-PKCS1 v1.5 decrypt (for private-key based unwrap)\n */\n\nimport {\n  createHash,\n  createHmac,\n  createCipheriv,\n  createDecipheriv,\n  createPrivateKey,\n  privateDecrypt,\n  constants as cryptoConstants,\n} from \"node:crypto\";\n\nexport type HashAlgorithm = \"SHA1\" | \"SHA256\" | \"SHA384\" | \"SHA512\" | \"MD5\";\n\nfunction nodeAlgo(a: HashAlgorithm): string {\n  switch (a) {\n    case \"SHA1\":\n      return \"sha1\";\n    case \"SHA256\":\n      return \"sha256\";\n    case \"SHA384\":\n      return \"sha384\";\n    case \"SHA512\":\n      return \"sha512\";\n    case \"MD5\":\n      return \"md5\";\n  }\n}\n\nexport function hash(algorithm: HashAlgorithm, ...parts: Uint8Array[]): Uint8Array {\n  const h = createHash(nodeAlgo(algorithm));\n  for (const p of parts) h.update(p);\n  return new Uint8Array(h.digest());\n}\n\nexport function hashSize(algorithm: HashAlgorithm): number {\n  switch (algorithm) {\n    case \"SHA1\":\n      return 20;\n    case \"SHA256\":\n      return 32;\n    case \"SHA384\":\n      return 48;\n    case \"SHA512\":\n      return 64;\n    case \"MD5\":\n      return 16;\n  }\n}\n\nexport function hmac(\n  algorithm: HashAlgorithm,\n  key: Uint8Array,\n  message: Uint8Array,\n): Uint8Array {\n  const h = createHmac(nodeAlgo(algorithm), key);\n  h.update(message);\n  return new Uint8Array(h.digest());\n}\n\nfunction aesCbcCipher(key: Uint8Array): string {\n  switch (key.length) {\n    case 16:\n      return \"aes-128-cbc\";\n    case 24:\n      return \"aes-192-cbc\";\n    case 32:\n      return \"aes-256-cbc\";\n    default:\n      throw new Error(`Unsupported AES key length: ${key.length}`);\n  }\n}\n\nfunction aesEcbCipher(key: Uint8Array): string {\n  switch (key.length) {\n    case 16:\n      return \"aes-128-ecb\";\n    case 24:\n      return \"aes-192-ecb\";\n    case 32:\n      return \"aes-256-ecb\";\n    default:\n      throw new Error(`Unsupported AES key length: ${key.length}`);\n  }\n}\n\nexport function aesCbcDecrypt(\n  data: Uint8Array,\n  key: Uint8Array,\n  iv: Uint8Array,\n): Uint8Array {\n  const decipher = createDecipheriv(aesCbcCipher(key), key, iv);\n  decipher.setAutoPadding(false);\n  const a = decipher.update(data);\n  const b = decipher.final();\n  const out = new Uint8Array(a.length + b.length);\n  out.set(a, 0);\n  out.set(b, a.length);\n  return out;\n}\n\nexport function aesCbcEncrypt(\n  data: Uint8Array,\n  key: Uint8Array,\n  iv: Uint8Array,\n): Uint8Array {\n  const cipher = createCipheriv(aesCbcCipher(key), key, iv);\n  cipher.setAutoPadding(false);\n  const a = cipher.update(data);\n  const b = cipher.final();\n  const out = new Uint8Array(a.length + b.length);\n  out.set(a, 0);\n  out.set(b, a.length);\n  return out;\n}\n\nexport function aesEcbDecrypt(data: Uint8Array, key: Uint8Array): Uint8Array {\n  const decipher = createDecipheriv(aesEcbCipher(key), key, null);\n  decipher.setAutoPadding(false);\n  const a = decipher.update(data);\n  const b = decipher.final();\n  const out = new Uint8Array(a.length + b.length);\n  out.set(a, 0);\n  out.set(b, a.length);\n  return out;\n}\n\nexport function aesEcbEncrypt(data: Uint8Array, key: Uint8Array): Uint8Array {\n  const cipher = createCipheriv(aesEcbCipher(key), key, null);\n  cipher.setAutoPadding(false);\n  const a = cipher.update(data);\n  const b = cipher.final();\n  const out = new Uint8Array(a.length + b.length);\n  out.set(a, 0);\n  out.set(b, a.length);\n  return out;\n}\n\n/**\n * Pure-TS RC4 (ARC4) — Node's native rc4 cipher requires the OpenSSL legacy\n * provider on modern builds, which pulls in environment-specific flags. A\n * direct port keeps the library deployable everywhere.\n */\nexport function rc4(key: Uint8Array, data: Uint8Array): Uint8Array {\n  const S = new Uint8Array(256);\n  for (let i = 0; i < 256; i++) S[i] = i;\n  let j = 0;\n  const klen = key.length;\n  for (let i = 0; i < 256; i++) {\n    j = (j + S[i] + key[i % klen]) & 0xff;\n    const t = S[i];\n    S[i] = S[j];\n    S[j] = t;\n  }\n\n  const out = new Uint8Array(data.length);\n  let i = 0;\n  j = 0;\n  for (let n = 0; n < data.length; n++) {\n    i = (i + 1) & 0xff;\n    j = (j + S[i]) & 0xff;\n    const t = S[i];\n    S[i] = S[j];\n    S[j] = t;\n    const k = S[(S[i] + S[j]) & 0xff];\n    out[n] = data[n] ^ k;\n  }\n  return out;\n}\n\n/**\n * Decrypt RSA PKCS#1 v1.5 with a PEM-encoded private key.\n */\nexport function rsaDecryptPkcs1v15(\n  privateKeyPem: Uint8Array | string,\n  ciphertext: Uint8Array,\n): Uint8Array {\n  const keyObj = createPrivateKey({\n    key: typeof privateKeyPem === \"string\" ? privateKeyPem : Buffer.from(privateKeyPem),\n    format: \"pem\",\n  });\n  const out = privateDecrypt(\n    {\n      key: keyObj,\n      padding: cryptoConstants.RSA_PKCS1_PADDING,\n    },\n    Buffer.from(ciphertext),\n  );\n  return new Uint8Array(out);\n}\n\n/**\n * Cryptographically secure random bytes.\n */\nexport function randomBytes(n: number): Uint8Array {\n  // eslint-disable-next-line @typescript-eslint/no-require-imports\n  const { randomFillSync } = require(\"node:crypto\") as typeof import(\"node:crypto\");\n  const out = new Uint8Array(n);\n  randomFillSync(out);\n  return out;\n}\n","/**\n * ECMA-376 Agile encryption (the most common encryption flavor used by\n * password-protected DOCX/XLSX/PPTX files).\n *\n * Spec: https://learn.microsoft.com/en-us/openspecs/office_file_formats/ms-offcrypto/\n *\n * Direct port of `msoffcrypto/method/ecma376_agile.py`.\n */\n\nimport {\n  aesCbcDecrypt,\n  aesCbcEncrypt,\n  hash,\n  hashSize,\n  hmac,\n  randomBytes,\n  rsaDecryptPkcs1v15,\n  type HashAlgorithm,\n} from \"../crypto.js\";\nimport {\n  bytesEqual,\n  concatBytes,\n  packU32LE,\n  packU64LE,\n  readU64LE,\n  utf16leEncode,\n} from \"../utils.js\";\nimport type { BytesIO } from \"../utils.js\";\n\n/** Block keys defined by [MS-OFFCRYPTO] §2.3.4.13. */\nexport const BLK_VERIFIER_HASH_INPUT = new Uint8Array([\n  0xfe, 0xa7, 0xd2, 0x76, 0x3b, 0x4b, 0x9e, 0x79,\n]);\nexport const BLK_ENCRYPTED_VERIFIER_HASH_VALUE = new Uint8Array([\n  0xd7, 0xaa, 0x0f, 0x6d, 0x30, 0x61, 0x34, 0x4e,\n]);\nexport const BLK_ENCRYPTED_KEY_VALUE = new Uint8Array([\n  0x14, 0x6e, 0x0b, 0xe7, 0xab, 0xac, 0xd0, 0xd6,\n]);\nexport const BLK_DATA_INTEGRITY1 = new Uint8Array([\n  0x5f, 0xb2, 0xad, 0x01, 0x0c, 0xb9, 0xe1, 0xf6,\n]);\nexport const BLK_DATA_INTEGRITY2 = new Uint8Array([\n  0xa0, 0x67, 0x7f, 0x02, 0xb2, 0x2c, 0x84, 0x33,\n]);\n\nfunction resizeBuffer(\n  buf: Uint8Array,\n  n: number,\n  pad: number = 0x00,\n): Uint8Array {\n  if (buf.length === n) return buf;\n  if (buf.length > n) return buf.subarray(0, n);\n  const out = new Uint8Array(n);\n  out.set(buf, 0);\n  out.fill(pad, buf.length);\n  return out;\n}\n\nfunction normalizeKey(key: Uint8Array, n: number): Uint8Array {\n  // Per spec: pad short keys with 0x36, truncate long keys.\n  return resizeBuffer(key, n, 0x36);\n}\n\nfunction roundUp(sz: number, block: number): number {\n  return Math.floor((sz + block - 1) / block) * block;\n}\n\nexport interface AgileEncryptionInfo {\n  keyDataSalt: Uint8Array;\n  keyDataHashAlgorithm: HashAlgorithm;\n  keyDataBlockSize: number;\n  encryptedHmacKey: Uint8Array;\n  encryptedHmacValue: Uint8Array;\n  encryptedVerifierHashInput: Uint8Array;\n  encryptedVerifierHashValue: Uint8Array;\n  encryptedKeyValue: Uint8Array;\n  spinValue: number;\n  passwordSalt: Uint8Array;\n  passwordHashAlgorithm: HashAlgorithm;\n  passwordKeyBits: number;\n}\n\n/**\n * Hash chain used by both verify_password and makekey: H₀ = sha(salt || pw),\n * Hₙ = sha(uint32_le(n-1) || Hₙ₋₁) — repeated `spinValue` times.\n *\n * Expensive (default spinCount is 100 000); callers should reuse the result.\n */\nfunction deriveIteratedHashFromPassword(\n  password: string,\n  saltValue: Uint8Array,\n  hashAlgorithm: HashAlgorithm,\n  spinValue: number,\n): Uint8Array {\n  let h = hash(hashAlgorithm, saltValue, utf16leEncode(password));\n  for (let i = 0; i < spinValue; i++) {\n    h = hash(hashAlgorithm, packU32LE(i), h);\n  }\n  return h;\n}\n\n/** Final block-key hashing step used to derive each per-purpose AES key. */\nfunction deriveEncryptionKey(\n  h: Uint8Array,\n  blockKey: Uint8Array,\n  hashAlgorithm: HashAlgorithm,\n  keyBits: number,\n): Uint8Array {\n  const finalHash = hash(hashAlgorithm, h, blockKey);\n  return finalHash.subarray(0, keyBits / 8);\n}\n\nexport class ECMA376Agile {\n  /**\n   * Decrypt the EncryptedPackage stream using a derived secret key.\n   *\n   * The payload format is `<u64 totalSize>` followed by AES-CBC blocks, each\n   * 4096-byte segment using `IV = sha(keyDataSalt || u32_le(blockIndex))`\n   * truncated to 16 bytes.\n   */\n  static decrypt(\n    key: Uint8Array,\n    keyDataSalt: Uint8Array,\n    hashAlgorithm: HashAlgorithm,\n    ibuf: BytesIO,\n  ): Uint8Array {\n    const SEGMENT_LENGTH = 4096;\n\n    ibuf.seek(0);\n    const head = ibuf.read(8);\n    const totalSize = Number(readU64LE(head, 0));\n\n    const out: Uint8Array[] = [];\n    let written = 0;\n    let i = 0;\n    while (true) {\n      const buf = ibuf.read(SEGMENT_LENGTH);\n      if (buf.length === 0) break;\n      // Avoid an extra allocation: `hash()` accepts multiple parts.\n      const iv = hash(hashAlgorithm, keyDataSalt, packU32LE(i)).subarray(0, 16);\n      let dec = aesCbcDecrypt(buf, key, iv);\n      const remaining = totalSize - written;\n      if (remaining < dec.length) dec = dec.subarray(0, remaining);\n      out.push(dec);\n      written += dec.length;\n      if (written >= totalSize) break;\n      i++;\n    }\n\n    return concatBytes(...out);\n  }\n\n  /**\n   * Encrypt arbitrary payload bytes using the same agile scheme used for\n   * decryption. Returns an EncryptedPackage stream (the OLE container is\n   * built separately by `ECMA376Encrypted`).\n   */\n  static encryptPayload(\n    ibuf: Uint8Array,\n    secretKey: Uint8Array,\n    saltValue: Uint8Array,\n    hashAlgorithm: HashAlgorithm,\n    saltSize: number,\n    blockSize: number,\n  ): Uint8Array {\n    const SEGMENT_LENGTH = 4096;\n\n    const totalSize = ibuf.length;\n    const segments: Uint8Array[] = [];\n    segments.push(packU64LE(totalSize));\n\n    let i = 0;\n    let off = 0;\n    while (off < ibuf.length) {\n      const chunk = ibuf.subarray(off, off + SEGMENT_LENGTH);\n      const ivSeed = hash(hashAlgorithm, saltValue, packU32LE(i));\n      const iv = normalizeKey(ivSeed, saltSize);\n      let buf = chunk;\n      if (buf.length % blockSize) {\n        buf = resizeBuffer(buf, roundUp(buf.length, blockSize));\n      }\n      segments.push(aesCbcEncrypt(buf, secretKey, iv));\n      off += SEGMENT_LENGTH;\n      i++;\n    }\n\n    return concatBytes(...segments);\n  }\n\n  /**\n   * Verify password by decrypting the stored verifier hash inputs and\n   * comparing to the stored hash. Mirrors the spec's password-verifier flow.\n   */\n  static verifyPassword(\n    password: string,\n    saltValue: Uint8Array,\n    hashAlgorithm: HashAlgorithm,\n    encryptedVerifierHashInput: Uint8Array,\n    encryptedVerifierHashValue: Uint8Array,\n    spinValue: number,\n    keyBits: number,\n  ): boolean {\n    const h = deriveIteratedHashFromPassword(\n      password,\n      saltValue,\n      hashAlgorithm,\n      spinValue,\n    );\n\n    const key1 = deriveEncryptionKey(\n      h,\n      BLK_VERIFIER_HASH_INPUT,\n      hashAlgorithm,\n      keyBits,\n    );\n    const key2 = deriveEncryptionKey(\n      h,\n      BLK_ENCRYPTED_VERIFIER_HASH_VALUE,\n      hashAlgorithm,\n      keyBits,\n    );\n\n    const hashInput = aesCbcDecrypt(encryptedVerifierHashInput, key1, saltValue);\n    const actualHash = hash(hashAlgorithm, hashInput);\n    const expectedFull = aesCbcDecrypt(\n      encryptedVerifierHashValue,\n      key2,\n      saltValue,\n    );\n    const expected = expectedFull.subarray(0, hashSize(hashAlgorithm));\n\n    return bytesEqual(actualHash, expected);\n  }\n\n  /**\n   * HMAC-verify the encrypted payload. Used for tamper detection (the spec\n   * recommends running this before decrypting).\n   */\n  static verifyIntegrity(\n    secretKey: Uint8Array,\n    keyDataSalt: Uint8Array,\n    keyDataHashAlgorithm: HashAlgorithm,\n    keyDataBlockSize: number,\n    encryptedHmacKey: Uint8Array,\n    encryptedHmacValue: Uint8Array,\n    streamBytes: Uint8Array,\n  ): boolean {\n    const iv1 = hash(\n      keyDataHashAlgorithm,\n      keyDataSalt,\n      BLK_DATA_INTEGRITY1,\n    ).subarray(0, keyDataBlockSize);\n    const iv2 = hash(\n      keyDataHashAlgorithm,\n      keyDataSalt,\n      BLK_DATA_INTEGRITY2,\n    ).subarray(0, keyDataBlockSize);\n\n    const hmacKey = aesCbcDecrypt(encryptedHmacKey, secretKey, iv1);\n    const hmacValue = aesCbcDecrypt(encryptedHmacValue, secretKey, iv2);\n\n    const expectedSize = hashSize(keyDataHashAlgorithm);\n    const actual = hmac(keyDataHashAlgorithm, hmacKey, streamBytes);\n    return bytesEqual(hmacValue.subarray(0, expectedSize), actual);\n  }\n\n  /**\n   * Recover the document secret key from a password.\n   */\n  static makekeyFromPassword(\n    password: string,\n    saltValue: Uint8Array,\n    hashAlgorithm: HashAlgorithm,\n    encryptedKeyValue: Uint8Array,\n    spinValue: number,\n    keyBits: number,\n  ): Uint8Array {\n    const h = deriveIteratedHashFromPassword(\n      password,\n      saltValue,\n      hashAlgorithm,\n      spinValue,\n    );\n    const encryptionKey = deriveEncryptionKey(\n      h,\n      BLK_ENCRYPTED_KEY_VALUE,\n      hashAlgorithm,\n      keyBits,\n    );\n    return aesCbcDecrypt(encryptedKeyValue, encryptionKey, saltValue);\n  }\n\n  /**\n   * Recover the document secret key from a private key (PEM bytes or string).\n   * Matches the legacy private-key key-encryptor flow used by certificate\n   * protected files.\n   */\n  static makekeyFromPrivkey(\n    privkeyPem: Uint8Array | string,\n    encryptedKeyValue: Uint8Array,\n  ): Uint8Array {\n    return rsaDecryptPkcs1v15(privkeyPem, encryptedKeyValue);\n  }\n\n  /**\n   * Generate a fresh secret key + parameter set suitable for encrypting a\n   * brand-new file. Used by the encryption path.\n   */\n  static generateEncryptionParameters(\n    password: string,\n    saltValue: Uint8Array | null,\n    spinCount: number,\n  ): {\n    info: AgileEncryptionInfo;\n    secretKey: Uint8Array;\n    encryptedKey: AgileCipherParams;\n    keyData: AgileCipherParams;\n  } {\n    const encryptedKey: AgileCipherParams = {\n      cipherName: \"AES\",\n      hashName: \"SHA512\",\n      saltSize: 16,\n      blockSize: 16,\n      keyBits: 256,\n      hashSize: 64,\n      saltValue: saltValue ?? randomBytes(16),\n    };\n    const keyData: AgileCipherParams = {\n      cipherName: \"AES\",\n      hashName: \"SHA512\",\n      saltSize: 16,\n      blockSize: 16,\n      keyBits: 256,\n      hashSize: 64,\n      saltValue: randomBytes(16),\n    };\n\n    const h = deriveIteratedHashFromPassword(\n      password,\n      encryptedKey.saltValue!,\n      encryptedKey.hashName,\n      spinCount,\n    );\n\n    const key1 = deriveEncryptionKey(\n      h,\n      BLK_VERIFIER_HASH_INPUT,\n      encryptedKey.hashName,\n      encryptedKey.keyBits,\n    );\n    const key2 = deriveEncryptionKey(\n      h,\n      BLK_ENCRYPTED_VERIFIER_HASH_VALUE,\n      encryptedKey.hashName,\n      encryptedKey.keyBits,\n    );\n    const key3 = deriveEncryptionKey(\n      h,\n      BLK_ENCRYPTED_KEY_VALUE,\n      encryptedKey.hashName,\n      encryptedKey.keyBits,\n    );\n\n    let verifierHashInput = randomBytes(encryptedKey.saltSize);\n    verifierHashInput = resizeBuffer(\n      verifierHashInput,\n      roundUp(verifierHashInput.length, encryptedKey.blockSize),\n    );\n    const encryptedVerifierHashInput = aesCbcEncrypt(\n      verifierHashInput,\n      key1,\n      encryptedKey.saltValue!,\n    );\n\n    let hashedVerifier = hash(encryptedKey.hashName, verifierHashInput);\n    hashedVerifier = resizeBuffer(\n      hashedVerifier,\n      roundUp(hashedVerifier.length, encryptedKey.blockSize),\n    );\n    const encryptedVerifierHashValue = aesCbcEncrypt(\n      hashedVerifier,\n      key2,\n      encryptedKey.saltValue!,\n    );\n\n    let secretKey = randomBytes(encryptedKey.saltSize);\n    secretKey = normalizeKey(secretKey, encryptedKey.keyBits / 8);\n\n    const encryptedKeyValue = aesCbcEncrypt(\n      secretKey,\n      key3,\n      encryptedKey.saltValue!,\n    );\n\n    const info: AgileEncryptionInfo = {\n      keyDataSalt: keyData.saltValue!,\n      keyDataHashAlgorithm: keyData.hashName,\n      keyDataBlockSize: keyData.blockSize,\n      encryptedHmacKey: new Uint8Array(0),\n      encryptedHmacValue: new Uint8Array(0),\n      encryptedVerifierHashInput,\n      encryptedVerifierHashValue,\n      encryptedKeyValue,\n      spinValue: spinCount,\n      passwordSalt: encryptedKey.saltValue!,\n      passwordHashAlgorithm: encryptedKey.hashName,\n      passwordKeyBits: encryptedKey.keyBits,\n    };\n\n    return { info, secretKey, encryptedKey, keyData };\n  }\n\n  /**\n   * Compute and return the encrypted HMAC key + value for the given payload.\n   */\n  static generateIntegrityParameter(\n    encryptedData: Uint8Array,\n    keyData: AgileCipherParams,\n    secretKey: Uint8Array,\n  ): { encryptedHmacKey: Uint8Array; encryptedHmacValue: Uint8Array } {\n    const salt = randomBytes(keyData.hashSize);\n    const iv1 = generateIv(keyData, BLK_DATA_INTEGRITY1, keyData.saltValue!);\n    const iv2 = generateIv(keyData, BLK_DATA_INTEGRITY2, keyData.saltValue!);\n\n    const encryptedHmacKey = aesCbcEncrypt(salt, secretKey, iv1);\n    const value = hmac(keyData.hashName, salt, encryptedData);\n\n    // Pad to AES block size before encrypting\n    const padded = resizeBuffer(value, roundUp(value.length, keyData.blockSize));\n    const encryptedHmacValue = aesCbcEncrypt(padded, secretKey, iv2);\n\n    return { encryptedHmacKey, encryptedHmacValue };\n  }\n}\n\nexport interface AgileCipherParams {\n  cipherName: \"AES\";\n  hashName: HashAlgorithm;\n  saltSize: number;\n  blockSize: number;\n  keyBits: number;\n  hashSize: number;\n  saltValue: Uint8Array | null;\n}\n\nfunction generateIv(\n  params: AgileCipherParams,\n  blkKey: Uint8Array | null,\n  saltValue: Uint8Array,\n): Uint8Array {\n  if (!blkKey) return normalizeKey(saltValue, params.blockSize);\n  return normalizeKey(\n    hash(params.hashName, saltValue, blkKey),\n    params.blockSize,\n  );\n}\n","/**\n * ECMA-376 Standard encryption: SHA-1 + AES-128 ECB key derivation, used by\n * older Office 2007/2010 password protection.\n *\n * Direct port of `msoffcrypto/method/ecma376_standard.py`.\n */\n\nimport { aesEcbDecrypt, hash } from \"../crypto.js\";\nimport {\n  bytesEqual,\n  concatBytes,\n  packU32LE,\n  readU32LE,\n  utf16leEncode,\n} from \"../utils.js\";\nimport type { BytesIO } from \"../utils.js\";\n\nexport class ECMA376Standard {\n  static decrypt(key: Uint8Array, ibuf: BytesIO): Uint8Array {\n    ibuf.seek(0);\n    const head = ibuf.read(4);\n    const totalSize = readU32LE(head, 0);\n    ibuf.seek(8);\n    const payload = ibuf.read();\n    const dec = aesEcbDecrypt(payload, key);\n    return dec.subarray(0, totalSize);\n  }\n\n  /**\n   * Verify a derived key by comparing the encrypted verifier hash and the\n   * SHA-1 of the decrypted verifier.\n   */\n  static verifyKey(\n    key: Uint8Array,\n    encryptedVerifier: Uint8Array,\n    encryptedVerifierHash: Uint8Array,\n  ): boolean {\n    const verifier = aesEcbDecrypt(encryptedVerifier, key);\n    const expectedHash = hash(\"SHA1\", verifier);\n    const verifierHash = aesEcbDecrypt(encryptedVerifierHash, key).subarray(\n      0,\n      20,\n    );\n    return bytesEqual(expectedHash, verifierHash);\n  }\n\n  /**\n   * Standard SHA-1 based PBKDF used by ECMA-376 v2/v3 (50 000 iterations).\n   * Truncates to `keySize` bits.\n   */\n  static makekeyFromPassword(\n    password: string,\n    _algId: number,\n    _algIdHash: number,\n    _providerType: number,\n    keySize: number,\n    _saltSize: number,\n    salt: Uint8Array,\n  ): Uint8Array {\n    const ITER_COUNT = 50000;\n    const pwBytes = utf16leEncode(password);\n    let h = hash(\"SHA1\", salt, pwBytes);\n    for (let i = 0; i < ITER_COUNT; i++) {\n      h = hash(\"SHA1\", packU32LE(i), h);\n    }\n    // Final block\n    const hfinal = hash(\"SHA1\", h, packU32LE(0));\n\n    const cbHash = 20;\n    const cbRequiredKeyLength = keySize / 8;\n\n    const buf1 = new Uint8Array(64);\n    buf1.fill(0x36);\n    for (let i = 0; i < cbHash; i++) buf1[i] ^= hfinal[i];\n    const x1 = hash(\"SHA1\", buf1);\n\n    const buf2 = new Uint8Array(64);\n    buf2.fill(0x5c);\n    for (let i = 0; i < cbHash; i++) buf2[i] ^= hfinal[i];\n    const x2 = hash(\"SHA1\", buf2);\n\n    const x3 = concatBytes(x1, x2);\n    return x3.subarray(0, cbRequiredKeyLength);\n  }\n}\n","/**\n * EncryptionInfo structure helpers shared by OOXML, XLS97, DOC97, PPT97.\n *\n * Direct port of `msoffcrypto/format/common.py`.\n */\n\nimport {\n  BytesIO,\n  readU32,\n  utf16leDecode,\n  type Readable,\n} from \"../utils.js\";\n\nexport type { Readable };\n\nexport interface EncryptionHeader {\n  flags: number;\n  sizeExtra: number;\n  algId: number;\n  algIdHash: number;\n  keySize: number;\n  providerType: number;\n  reserved1: number;\n  reserved2: number;\n  cspName: string;\n}\n\nexport interface EncryptionVerifier {\n  saltSize: number;\n  salt: Uint8Array;\n  encryptedVerifier: Uint8Array;\n  verifierHashSize: number;\n  encryptedVerifierHash: Uint8Array;\n}\n\nexport function parseEncryptionHeader(blob: Readable): EncryptionHeader {\n  return {\n    flags: readU32(blob),\n    sizeExtra: readU32(blob),\n    algId: readU32(blob),\n    algIdHash: readU32(blob),\n    keySize: readU32(blob),\n    providerType: readU32(blob),\n    reserved1: readU32(blob),\n    reserved2: readU32(blob),\n    cspName: utf16leDecode(blob.read()),\n  };\n}\n\nexport function parseEncryptionVerifier(\n  blob: Readable,\n  algorithm: \"AES\" | \"RC4\",\n): EncryptionVerifier {\n  const saltSize = readU32(blob);\n  const salt = new Uint8Array(blob.read(16));\n  const encryptedVerifier = new Uint8Array(blob.read(16));\n  const verifierHashSize = readU32(blob);\n  const encryptedVerifierHash = new Uint8Array(\n    blob.read(algorithm === \"RC4\" ? 20 : 32),\n  );\n  return {\n    saltSize,\n    salt,\n    encryptedVerifier,\n    verifierHashSize,\n    encryptedVerifierHash,\n  };\n}\n\nexport interface RC4CryptoAPIInfo {\n  salt: Uint8Array;\n  keySize: number;\n  encryptedVerifier: Uint8Array;\n  encryptedVerifierHash: Uint8Array;\n}\n\nexport function parseHeaderRC4CryptoAPI(\n  encryptionHeader: Readable,\n): RC4CryptoAPIInfo {\n  encryptionHeader.read(4); // flags (we don't surface them yet)\n  const headerSize = readU32(encryptionHeader);\n  const headerBlob = new BytesIO(\n    new Uint8Array(encryptionHeader.read(headerSize)),\n  );\n  const header = parseEncryptionHeader(headerBlob);\n  const keySize = header.keySize === 0 ? 0x28 : header.keySize;\n  const verifierBlob = new BytesIO(new Uint8Array(encryptionHeader.read()));\n  const verifier = parseEncryptionVerifier(verifierBlob, \"RC4\");\n  return {\n    salt: verifier.salt,\n    keySize,\n    encryptedVerifier: verifier.encryptedVerifier,\n    encryptedVerifierHash: verifier.encryptedVerifierHash,\n  };\n}\n\nexport interface RC4Info {\n  salt: Uint8Array;\n  encryptedVerifier: Uint8Array;\n  encryptedVerifierHash: Uint8Array;\n}\n\n/**\n * RC4 (non-CryptoAPI) header used by older XLS / DOC files: three back-to-back\n * 16-byte chunks (salt, encryptedVerifier, encryptedVerifierHash).\n */\nexport function parseHeaderRC4(blob: Readable): RC4Info {\n  return {\n    salt: new Uint8Array(blob.read(16)),\n    encryptedVerifier: new Uint8Array(blob.read(16)),\n    encryptedVerifierHash: new Uint8Array(blob.read(16)),\n  };\n}\n","/**\n * OOXML (DOCX/XLSX/PPTX) format handler.\n *\n * Encrypted OOXML is wrapped inside an OLE compound file containing an\n * `EncryptionInfo` stream (header + XML descriptor or binary header) and an\n * `EncryptedPackage` stream (the actual encrypted ZIP).\n *\n * Plain OOXML is a regular ZIP starting with `PK\\x03\\x04`.\n *\n * Direct port of `msoffcrypto/format/ooxml.py`.\n */\n\nimport { DecryptionError, FileFormatError, InvalidKeyError } from \"../exceptions.js\";\nimport {\n  isOleFile,\n  OleFileIO,\n  type OleStream,\n} from \"../olefile.js\";\nimport { ECMA376Agile } from \"../method/ecma376_agile.js\";\nimport { ECMA376Standard } from \"../method/ecma376_standard.js\";\nimport { base64Decode, BytesIO, readU16, readU32 } from \"../utils.js\";\nimport {\n  parseEncryptionHeader,\n  parseEncryptionVerifier,\n  type EncryptionHeader,\n  type EncryptionVerifier,\n} from \"./common.js\";\nimport type {\n  BaseOfficeFile,\n  DecryptOptions,\n  LoadKeyOptions,\n} from \"./base.js\";\nimport type { HashAlgorithm } from \"../crypto.js\";\n\n/**\n * Quick zip-magic sniff for plain OOXML detection. We don't decompress; we\n * only need to know whether the file is encrypted (OLE) or not (zip).\n */\nexport function isZip(buf: Uint8Array): boolean {\n  // Local file header magic\n  return (\n    buf.length >= 4 &&\n    buf[0] === 0x50 &&\n    buf[1] === 0x4b &&\n    (buf[2] === 0x03 || buf[2] === 0x05 || buf[2] === 0x07) &&\n    (buf[3] === 0x04 || buf[3] === 0x06 || buf[3] === 0x08)\n  );\n}\n\n/** Heuristic: is this a plain (unencrypted) OOXML file? */\nexport function isOoxml(buf: Uint8Array): boolean {\n  if (!isZip(buf)) return false;\n  // We could verify [Content_Types].xml exists, but that requires a zip\n  // parser. Detecting the magic + later confirming via OLE absence is enough\n  // for the routing decision the library needs.\n  return true;\n}\n\n/** EncryptionInfo with type discriminator. */\ntype AgileInfo = {\n  type: \"agile\";\n  keyDataSalt: Uint8Array;\n  keyDataHashAlgorithm: HashAlgorithm;\n  keyDataBlockSize: number;\n  encryptedHmacKey: Uint8Array;\n  encryptedHmacValue: Uint8Array;\n  encryptedVerifierHashInput: Uint8Array;\n  encryptedVerifierHashValue: Uint8Array;\n  encryptedKeyValue: Uint8Array;\n  spinValue: number;\n  passwordSalt: Uint8Array;\n  passwordHashAlgorithm: HashAlgorithm;\n  passwordKeyBits: number;\n};\n\ntype StandardInfo = {\n  type: \"standard\";\n  header: EncryptionHeader;\n  verifier: EncryptionVerifier;\n};\n\ntype ParsedInfo = AgileInfo | StandardInfo;\n\n/**\n * Pull a single attribute value out of an XML tag matching `tagPattern`.\n * Used because the Agile descriptor has a fixed schema — full XML parsing\n * would just inflate the dependency footprint.\n */\nfunction readAttr(\n  xml: string,\n  tagPattern: RegExp,\n  attr: string,\n): string {\n  const tagMatch = xml.match(tagPattern);\n  if (!tagMatch) throw new FileFormatError(`Tag not found: ${tagPattern}`);\n  const tag = tagMatch[0];\n  const re = new RegExp(`${attr}\\\\s*=\\\\s*\"([^\"]*)\"`);\n  const m = tag.match(re);\n  if (!m) throw new FileFormatError(`Attribute not found: ${attr}`);\n  return m[1];\n}\n\nfunction parseAgileInfo(xml: string): AgileInfo {\n  const keyDataSalt = base64Decode(readAttr(xml, /<keyData\\s[^>]*\\/?>/, \"saltValue\"));\n  const keyDataHashAlgorithm = readAttr(\n    xml,\n    /<keyData\\s[^>]*\\/?>/,\n    \"hashAlgorithm\",\n  ) as HashAlgorithm;\n  const keyDataBlockSize = parseInt(\n    readAttr(xml, /<keyData\\s[^>]*\\/?>/, \"blockSize\"),\n    10,\n  );\n  const encryptedHmacKey = base64Decode(\n    readAttr(xml, /<dataIntegrity\\s[^>]*\\/?>/, \"encryptedHmacKey\"),\n  );\n  const encryptedHmacValue = base64Decode(\n    readAttr(xml, /<dataIntegrity\\s[^>]*\\/?>/, \"encryptedHmacValue\"),\n  );\n\n  // Look for the password keyEncryptor's <p:encryptedKey> element. The\n  // namespace prefix may be \"p:\" or another prefix bound to the same URI.\n  const ekTagRe = /<(?:[A-Za-z0-9_-]+:)?encryptedKey\\s[^>]*\\/?>/;\n  const spinValue = parseInt(readAttr(xml, ekTagRe, \"spinCount\"), 10);\n  const encryptedKeyValue = base64Decode(\n    readAttr(xml, ekTagRe, \"encryptedKeyValue\"),\n  );\n  const encryptedVerifierHashInput = base64Decode(\n    readAttr(xml, ekTagRe, \"encryptedVerifierHashInput\"),\n  );\n  const encryptedVerifierHashValue = base64Decode(\n    readAttr(xml, ekTagRe, \"encryptedVerifierHashValue\"),\n  );\n  const passwordSalt = base64Decode(readAttr(xml, ekTagRe, \"saltValue\"));\n  const passwordHashAlgorithm = readAttr(\n    xml,\n    ekTagRe,\n    \"hashAlgorithm\",\n  ) as HashAlgorithm;\n  const passwordKeyBits = parseInt(readAttr(xml, ekTagRe, \"keyBits\"), 10);\n\n  return {\n    type: \"agile\",\n    keyDataSalt,\n    keyDataHashAlgorithm,\n    keyDataBlockSize,\n    encryptedHmacKey,\n    encryptedHmacValue,\n    encryptedVerifierHashInput,\n    encryptedVerifierHashValue,\n    encryptedKeyValue,\n    spinValue,\n    passwordSalt,\n    passwordHashAlgorithm,\n    passwordKeyBits,\n  };\n}\n\nfunction parseStandardInfo(stream: OleStream): StandardInfo {\n  // headerFlags + encryptionHeaderSize, then encryptionHeader, then verifier.\n  readU32(stream); // headerFlags (unused)\n  const encryptionHeaderSize = readU32(stream);\n  const headerBytes = new Uint8Array(stream.read(encryptionHeaderSize));\n  const header = parseEncryptionHeader(new BytesIO(headerBytes));\n  const verifierBytes = new Uint8Array(stream.read());\n  const isAes = (header.algId & 0xff00) === 0x6600;\n  const verifier = parseEncryptionVerifier(\n    new BytesIO(verifierBytes),\n    isAes ? \"AES\" : \"RC4\",\n  );\n  return { type: \"standard\", header, verifier };\n}\n\nfunction parseInfo(stream: OleStream): ParsedInfo {\n  const versionMajor = readU16(stream);\n  const versionMinor = readU16(stream);\n  if (versionMajor === 4 && versionMinor === 4) {\n    stream.seek(8);\n    const xmlBytes = stream.read();\n    const xml = new TextDecoder(\"utf-8\").decode(xmlBytes);\n    return parseAgileInfo(xml);\n  }\n  if (\n    (versionMajor === 2 || versionMajor === 3 || versionMajor === 4) &&\n    versionMinor === 2\n  ) {\n    return parseStandardInfo(stream);\n  }\n  if ((versionMajor === 3 || versionMajor === 4) && versionMinor === 3) {\n    throw new DecryptionError(\n      \"Unsupported EncryptionInfo version (Extensible Encryption)\",\n    );\n  }\n  throw new DecryptionError(\n    `Unsupported EncryptionInfo version (${versionMajor}:${versionMinor})`,\n  );\n}\n\nexport class OOXMLFile implements BaseOfficeFile {\n  format = \"ooxml\" as const;\n  keyTypes: readonly string[];\n  type: \"agile\" | \"standard\" | \"plain\";\n\n  private file: OleFileIO | Uint8Array;\n  private info?: ParsedInfo;\n  private secretKey: Uint8Array | null = null;\n\n  constructor(buf: Uint8Array) {\n    if (isOleFile(buf)) {\n      const ole = new OleFileIO(buf);\n      this.file = ole;\n      if (!ole.exists(\"EncryptionInfo\")) {\n        throw new FileFormatError(\n          \"Supposed to be an encrypted OOXML file, but no EncryptionInfo stream found\",\n        );\n      }\n      this.info = parseInfo(ole.openstream(\"EncryptionInfo\"));\n      this.type = this.info.type;\n      this.keyTypes =\n        this.type === \"agile\"\n          ? ([\"password\", \"private_key\", \"secret_key\"] as const)\n          : ([\"password\", \"secret_key\"] as const);\n    } else if (isOoxml(buf)) {\n      this.file = buf;\n      this.type = \"plain\";\n      this.keyTypes = [];\n    } else {\n      throw new FileFormatError(\"Unsupported file format\");\n    }\n  }\n\n  loadKey(opts: LoadKeyOptions): void {\n    const { password, privateKey, secretKey, verifyPassword = false } = opts;\n    if (password !== undefined) {\n      if (this.type === \"agile\") {\n        const info = this.info as AgileInfo;\n        this.secretKey = ECMA376Agile.makekeyFromPassword(\n          password,\n          info.passwordSalt,\n          info.passwordHashAlgorithm,\n          info.encryptedKeyValue,\n          info.spinValue,\n          info.passwordKeyBits,\n        );\n        if (verifyPassword) {\n          const ok = ECMA376Agile.verifyPassword(\n            password,\n            info.passwordSalt,\n            info.passwordHashAlgorithm,\n            info.encryptedVerifierHashInput,\n            info.encryptedVerifierHashValue,\n            info.spinValue,\n            info.passwordKeyBits,\n          );\n          if (!ok) throw new InvalidKeyError(\"Key verification failed\");\n        }\n      } else if (this.type === \"standard\") {\n        const info = this.info as StandardInfo;\n        this.secretKey = ECMA376Standard.makekeyFromPassword(\n          password,\n          info.header.algId,\n          info.header.algIdHash,\n          info.header.providerType,\n          info.header.keySize,\n          info.verifier.saltSize,\n          info.verifier.salt,\n        );\n        if (verifyPassword) {\n          const ok = ECMA376Standard.verifyKey(\n            this.secretKey,\n            info.verifier.encryptedVerifier,\n            info.verifier.encryptedVerifierHash,\n          );\n          if (!ok) throw new InvalidKeyError(\"Key verification failed\");\n        }\n      } else if (this.type === \"plain\") {\n        // Nothing to do; the file is unencrypted.\n      }\n    } else if (privateKey !== undefined) {\n      if (this.type !== \"agile\") {\n        throw new DecryptionError(\n          \"Unsupported key type for the encryption method\",\n        );\n      }\n      const info = this.info as AgileInfo;\n      this.secretKey = ECMA376Agile.makekeyFromPrivkey(\n        privateKey,\n        info.encryptedKeyValue,\n      );\n    } else if (secretKey !== undefined) {\n      this.secretKey = secretKey;\n    } else {\n      throw new DecryptionError(\"No key specified\");\n    }\n  }\n\n  decrypt(opts: DecryptOptions = {}): Uint8Array {\n    if (this.type === \"plain\") {\n      throw new DecryptionError(\"Document is not encrypted\");\n    }\n    const ole = this.file as OleFileIO;\n    const stream = ole.openstream(\"EncryptedPackage\");\n    let result: Uint8Array;\n\n    if (this.type === \"agile\") {\n      const info = this.info as AgileInfo;\n      if (opts.verifyIntegrity) {\n        const ok = ECMA376Agile.verifyIntegrity(\n          this.secretKey!,\n          info.keyDataSalt,\n          info.keyDataHashAlgorithm,\n          info.keyDataBlockSize,\n          info.encryptedHmacKey,\n          info.encryptedHmacValue,\n          stream.getValue(),\n        );\n        if (!ok) {\n          throw new InvalidKeyError(\"Payload integrity verification failed\");\n        }\n      }\n      result = ECMA376Agile.decrypt(\n        this.secretKey!,\n        info.keyDataSalt,\n        info.keyDataHashAlgorithm,\n        new BytesIO(stream.getValue()),\n      );\n    } else if (this.type === \"standard\") {\n      result = ECMA376Standard.decrypt(\n        this.secretKey!,\n        new BytesIO(stream.getValue()),\n      );\n    } else {\n      throw new DecryptionError(\"Unsupported encryption method\");\n    }\n\n    if (!isZip(result)) {\n      throw new InvalidKeyError(\n        \"The file could not be decrypted with this password\",\n      );\n    }\n    return result;\n  }\n\n  isEncrypted(): boolean {\n    return this.type !== \"plain\";\n  }\n}\n","/**\n * Shared building blocks for the RC4-based Office encryption schemes\n * (`DocumentRC4` for Office 97 RC4 and `DocumentRC4CryptoAPI` for the later\n * RC4 CryptoAPI provider). Both share the same per-block re-keying loop and\n * the same verify-by-hash flow; only the key-derivation function differs.\n */\n\nimport { hash, rc4, type HashAlgorithm } from \"../crypto.js\";\nimport { bytesEqual, concatBytes } from \"../utils.js\";\nimport type { Readable } from \"../format/common.js\";\n\n/**\n * Verify a password by RC4-decrypting the verifier + verifier hash with the\n * key derived for block 0, then comparing `H(verifier) == verifierHash`.\n *\n * The two ciphertexts share an RC4 keystream — concatenate, decrypt, split.\n */\nexport function rc4VerifyByHash(\n  hashAlgo: HashAlgorithm,\n  key: Uint8Array,\n  encryptedVerifier: Uint8Array,\n  encryptedVerifierHash: Uint8Array,\n): boolean {\n  const ct = concatBytes(encryptedVerifier, encryptedVerifierHash);\n  const pt = rc4(key, ct);\n  const verifier = pt.subarray(0, encryptedVerifier.length);\n  const verifierHash = pt.subarray(encryptedVerifier.length);\n  const expected = hash(hashAlgo, verifier);\n  return bytesEqual(expected, verifierHash);\n}\n\n/**\n * Walk an input stream in `blockSize` chunks and decrypt each chunk under a\n * freshly derived key. Used by both DocumentRC4 (per-block MD5 rekey) and\n * DocumentRC4CryptoAPI (per-block SHA-1 rekey).\n *\n * @param ibuf       input stream — read until EOF\n * @param makeKey    derive the RC4 key for block index `b`\n * @param blockSize  chunk size in bytes\n * @param startBlock first block index (defaults to 0; PPT uses persistId here)\n */\nexport function blockwiseRc4Decrypt(\n  ibuf: Readable,\n  makeKey: (block: number) => Uint8Array,\n  blockSize: number,\n  startBlock = 0,\n): Uint8Array {\n  const out: Uint8Array[] = [];\n  let block = startBlock;\n  let key = makeKey(block);\n  while (true) {\n    const buf = ibuf.read(blockSize);\n    if (buf.length === 0) break;\n    out.push(rc4(key, buf));\n    block += 1;\n    key = makeKey(block);\n  }\n  return concatBytes(...out);\n}\n","/**\n * Office 97 RC4 encryption (MD5-based key derivation). Used by older Excel,\n * Word, and PowerPoint password protection via the legacy\n * \"Office Binary Document RC4\" provider.\n *\n * Direct port of `msoffcrypto/method/rc4.py`.\n */\n\nimport { hash } from \"../crypto.js\";\nimport { packU32LE, utf16leEncode } from \"../utils.js\";\nimport type { Readable } from \"../format/common.js\";\nimport { blockwiseRc4Decrypt, rc4VerifyByHash } from \"./rc4_common.js\";\n\nfunction makekey(\n  password: string,\n  salt: Uint8Array,\n  block: number,\n): Uint8Array {\n  // [MS-OFFCRYPTO] §2.3.6.1.\n  const pwBytes = utf16leEncode(password);\n  const truncated = hash(\"MD5\", pwBytes).subarray(0, 5);\n  // Build (truncated || salt) repeated 16 times — same as the Python original.\n  const segLen = truncated.length + salt.length;\n  const intermediate = new Uint8Array(segLen * 16);\n  for (let i = 0; i < 16; i++) {\n    intermediate.set(truncated, i * segLen);\n    intermediate.set(salt, i * segLen + truncated.length);\n  }\n  const truncatedHash = hash(\"MD5\", intermediate).subarray(0, 5);\n  return hash(\"MD5\", truncatedHash, packU32LE(block)).subarray(0, 16);\n}\n\nexport class DocumentRC4 {\n  static verifyPassword(\n    password: string,\n    salt: Uint8Array,\n    encryptedVerifier: Uint8Array,\n    encryptedVerifierHash: Uint8Array,\n  ): boolean {\n    const key = makekey(password, salt, 0);\n    return rc4VerifyByHash(\"MD5\", key, encryptedVerifier, encryptedVerifierHash);\n  }\n\n  static decrypt(\n    password: string,\n    salt: Uint8Array,\n    ibuf: Readable,\n    blockSize = 0x200,\n  ): Uint8Array {\n    return blockwiseRc4Decrypt(\n      ibuf,\n      (b) => makekey(password, salt, b),\n      blockSize,\n    );\n  }\n}\n","/**\n * RC4 CryptoAPI encryption (Office 97-2003 SP3 / 2007 SP1+ legacy XLS, DOC,\n * PPT). Uses SHA-1 + RC4 with per-block re-keying.\n *\n * Direct port of `msoffcrypto/method/rc4_cryptoapi.py`.\n */\n\nimport { hash } from \"../crypto.js\";\nimport { packU32LE, utf16leEncode } from \"../utils.js\";\nimport type { Readable } from \"../format/common.js\";\nimport { blockwiseRc4Decrypt, rc4VerifyByHash } from \"./rc4_common.js\";\n\nfunction makekey(\n  password: string,\n  salt: Uint8Array,\n  keyLength: number,\n  block: number,\n): Uint8Array {\n  // [MS-OFFCRYPTO] §2.3.5.2.\n  const pwBytes = utf16leEncode(password);\n  const hfinal = hash(\"SHA1\", hash(\"SHA1\", salt, pwBytes), packU32LE(block));\n  if (keyLength === 40) {\n    // 40-bit export-grade key: 5 bytes from the hash, padded to 16 with zeros.\n    const out = new Uint8Array(16);\n    out.set(hfinal.subarray(0, 5), 0);\n    return out;\n  }\n  return hfinal.subarray(0, keyLength / 8);\n}\n\nexport class DocumentRC4CryptoAPI {\n  static verifyPassword(\n    password: string,\n    salt: Uint8Array,\n    keySize: number,\n    encryptedVerifier: Uint8Array,\n    encryptedVerifierHash: Uint8Array,\n    block = 0,\n  ): boolean {\n    const key = makekey(password, salt, keySize, block);\n    return rc4VerifyByHash(\n      \"SHA1\",\n      key,\n      encryptedVerifier,\n      encryptedVerifierHash,\n    );\n  }\n\n  static decrypt(\n    password: string,\n    salt: Uint8Array,\n    keySize: number,\n    ibuf: Readable,\n    blockSize = 0x200,\n    startBlock = 0,\n  ): Uint8Array {\n    return blockwiseRc4Decrypt(\n      ibuf,\n      (b) => makekey(password, salt, keySize, b),\n      blockSize,\n      startBlock,\n    );\n  }\n}\n","/**\n * XOR Obfuscation (a.k.a. \"Method 1\") used by old XLS files. Algorithm copied\n * verbatim from [MS-OFFCRYPTO] §2.3.6.\n *\n * Direct port of `msoffcrypto/method/xor_obfuscation.py`.\n */\n\nimport type { BytesIO } from \"../utils.js\";\n\nconst PAD_ARRAY = [\n  0xbb, 0xff, 0xff, 0xba, 0xff, 0xff, 0xb9, 0x80, 0x00, 0xbe, 0x0f, 0x00, 0xbf,\n  0x0f, 0x00,\n];\n\nconst INITIAL_CODE = [\n  0xe1f0, 0x1d0f, 0xcc9c, 0x84c0, 0x110c, 0x0e10, 0xf1ce, 0x313e, 0x1872,\n  0xe139, 0xd40f, 0x84f9, 0x280c, 0xa96a, 0x4ec3,\n];\n\nconst XOR_MATRIX = [\n  0xaefc, 0x4dd9, 0x9bb2, 0x2745, 0x4e8a, 0x9d14, 0x2a09, 0x7b61, 0xf6c2,\n  0xfda5, 0xeb6b, 0xc6f7, 0x9dcf, 0x2bbf, 0x4563, 0x8ac6, 0x05ad, 0x0b5a,\n  0x16b4, 0x2d68, 0x5ad0, 0x0375, 0x06ea, 0x0dd4, 0x1ba8, 0x3750, 0x6ea0,\n  0xdd40, 0xd849, 0xa0b3, 0x5147, 0xa28e, 0x553d, 0xaa7a, 0x44d5, 0x6f45,\n  0xde8a, 0xad35, 0x4a4b, 0x9496, 0x390d, 0x721a, 0xeb23, 0xc667, 0x9cef,\n  0x29ff, 0x53fe, 0xa7fc, 0x5fd9, 0x47d3, 0x8fa6, 0x0f6d, 0x1eda, 0x3db4,\n  0x7b68, 0xf6d0, 0xb861, 0x60e3, 0xc1c6, 0x93ad, 0x377b, 0x6ef6, 0xddec,\n  0x45a0, 0x8b40, 0x06a1, 0x0d42, 0x1a84, 0x3508, 0x6a10, 0xaa51, 0x4483,\n  0x8906, 0x022d, 0x045a, 0x08b4, 0x1168, 0x76b4, 0xed68, 0xcaf1, 0x85c3,\n  0x1ba7, 0x374e, 0x6e9c, 0x3730, 0x6e60, 0xdcc0, 0xa9a1, 0x4363, 0x86c6,\n  0x1dad, 0x3331, 0x6662, 0xccc4, 0x89a9, 0x0373, 0x06e6, 0x0dcc, 0x1021,\n  0x2042, 0x4084, 0x8108, 0x1231, 0x2462, 0x48c4,\n];\n\nfunction ror(n: number, rotations: number, width: number): number {\n  return ((1 << width) - 1) & ((n >>> rotations) | (n << (width - rotations)));\n}\n\nfunction xorRor(byte1: number, byte2: number): number {\n  return ror(byte1 ^ byte2, 1, 8);\n}\n\nexport class DocumentXOR {\n  /**\n   * Verify password by computing the obfuscation verifier and comparing to\n   * the on-disk verificationBytes. Spec: [MS-OFFCRYPTO] §2.3.7.\n   */\n  static verifyPassword(password: string, verificationBytes: number): boolean {\n    let verifier = 0;\n    const arr: number[] = [];\n    arr.push(password.length);\n    for (const ch of password) arr.push(ch.charCodeAt(0));\n    arr.reverse();\n    for (const passwordByte of arr) {\n      const intermediate1 = (verifier & 0x4000) === 0 ? 0 : 1;\n      const intermediate2 = (verifier * 2) & 0x7fff;\n      const intermediate3 = intermediate1 ^ intermediate2;\n      verifier = intermediate3 ^ passwordByte;\n    }\n    return (verifier ^ 0xce4b) === verificationBytes;\n  }\n\n  /** Build the 16-byte XOR pad described by [MS-OFFCRYPTO] §2.3.6.2. */\n  static createXorArrayMethod1(password: string): number[] {\n    const xorKey = (() => {\n      let k = INITIAL_CODE[password.length - 1];\n      let currentElement = 0x68;\n      const data: number[] = [];\n      for (let i = password.length - 1; i >= 0; i--) {\n        data.push(password.charCodeAt(i));\n      }\n      for (let ch of data) {\n        for (let i = 0; i < 7; i++) {\n          if ((ch & 0x40) !== 0) k = (k ^ XOR_MATRIX[currentElement]) % 65536;\n          ch = (ch << 1) % 256;\n          currentElement -= 1;\n        }\n      }\n      return k;\n    })();\n\n    let index = password.length;\n    const obfuscationArray = new Array<number>(16).fill(0);\n\n    if (index % 2 === 1) {\n      let temp = (xorKey & 0xff00) >>> 8;\n      obfuscationArray[index] = xorRor(PAD_ARRAY[0], temp);\n\n      index -= 1;\n      temp = xorKey & 0x00ff;\n      const passwordLastChar = password.charCodeAt(password.length - 1);\n      obfuscationArray[index] = xorRor(passwordLastChar, temp);\n    }\n\n    while (index > 0) {\n      index -= 1;\n      let temp = (xorKey & 0xff00) >>> 8;\n      obfuscationArray[index] = xorRor(password.charCodeAt(index), temp);\n\n      index -= 1;\n      temp = xorKey & 0x00ff;\n      obfuscationArray[index] = xorRor(password.charCodeAt(index), temp);\n    }\n\n    let i = 15;\n    let padIndex = 15 - password.length;\n    while (padIndex > 0) {\n      let temp = (xorKey & 0xff00) >>> 8;\n      obfuscationArray[i] = xorRor(PAD_ARRAY[padIndex], temp);\n\n      i -= 1;\n      padIndex -= 1;\n\n      temp = xorKey & 0x00ff;\n      obfuscationArray[i] = xorRor(PAD_ARRAY[padIndex], temp);\n\n      i -= 1;\n      padIndex -= 1;\n    }\n\n    return obfuscationArray;\n  }\n\n  /**\n   * Decrypt records using the Method 1 XOR scheme. The plaintext array marks\n   * which bytes are actually encrypted (-1, -2) vs. plaintext-as-is (>=0).\n   */\n  static decrypt(\n    password: string,\n    ibuf: BytesIO,\n    plaintext: number[],\n    _records: unknown,\n    _base: unknown,\n  ): Uint8Array {\n    const xorArray = DocumentXOR.createXorArrayMethod1(password);\n    const out: number[] = [];\n\n    let dataIndex = 0;\n    while (dataIndex < plaintext.length) {\n      let count = 1;\n      if (plaintext[dataIndex] === -1 || plaintext[dataIndex] === -2) {\n        for (let j = dataIndex + 1; j < plaintext.length; j++) {\n          if (plaintext[j] >= 0) break;\n          count += 1;\n        }\n\n        let xorArrayIndex =\n          plaintext[dataIndex] === -2\n            ? (dataIndex + count + 4) % 16\n            : (dataIndex + count) % 16;\n\n        for (let item = 0; item < count; item++) {\n          const dataByte = ibuf.read(1)[0];\n          let tempRes = dataByte ^ xorArray[xorArrayIndex];\n          tempRes = ror(tempRes, 5, 8);\n          out.push(tempRes);\n          xorArrayIndex = (xorArrayIndex + 1) % 16;\n        }\n      } else {\n        out.push(ibuf.read(1)[0]);\n      }\n      dataIndex += count;\n    }\n\n    return new Uint8Array(out);\n  }\n}\n","/**\n * Excel 97-2003 (BIFF8) format handler.\n *\n * The Workbook stream is decrypted in place — encryption is applied per\n * record, but a handful of records (BOF, FilePass, BoundSheet8.lbPlyPos, …)\n * MUST stay plaintext. We mirror the Python implementation's two-pass plan:\n *   1. Walk all records; build a per-byte plan (\"keep plain\" / \"decrypt\").\n *   2. Build a contiguous \"encrypted-only\" buffer (zeros where plain bytes\n *      should land), feed it to the cipher, then merge back per the plan.\n *\n * Direct port of `msoffcrypto/format/xls97.py`.\n */\n\nimport { OleFileIO } from \"../olefile.js\";\nimport {\n  DecryptionError,\n  FileFormatError,\n  InvalidKeyError,\n  ParseError,\n} from \"../exceptions.js\";\nimport { DocumentRC4 } from \"../method/rc4.js\";\nimport { DocumentRC4CryptoAPI } from \"../method/rc4_cryptoapi.js\";\nimport { DocumentXOR } from \"../method/xor_obfuscation.js\";\nimport { parseHeaderRC4, parseHeaderRC4CryptoAPI } from \"./common.js\";\nimport { BytesIO, packU16LE, readU16, readU16LE } from \"../utils.js\";\nimport type {\n  BaseOfficeFile,\n  DecryptOptions,\n  LoadKeyOptions,\n} from \"./base.js\";\n\n/** A subset of BIFF record IDs the decryptor cares about. */\nconst RECORD = {\n  Formula: 6,\n  EOF: 10,\n  FilePass: 47,\n  WriteAccess: 92,\n  BoundSheet8: 133,\n  Country: 140,\n  InterfaceHdr: 225,\n  RRDInfo: 406,\n  RRDHead: 312,\n  UsrExcl: 404,\n  FileLock: 405,\n  BOF: 2057,\n} as const;\n\n/**\n * Iterator-style helper for stepping over BIFF records. Each record is a\n * 4-byte header (`<HH`: id, size) followed by `size` bytes of payload.\n */\nclass BIFFStream {\n  constructor(public data: BytesIO) {}\n\n  /**\n   * Read the 4-byte (id, size) record header at the current position.\n   * Returns null at EOF (no header bytes available).\n   */\n  private readHeader(): { num: number; size: number } | null {\n    const h = this.data.read(4);\n    if (h.length === 0) return null;\n    return { num: readU16LE(h, 0), size: readU16LE(h, 2) };\n  }\n\n  hasRecord(target: number): boolean {\n    const pos = this.data.tell();\n    while (true) {\n      const h = this.readHeader();\n      if (!h) {\n        this.data.seek(pos);\n        return false;\n      }\n      if (h.num === target) {\n        this.data.seek(pos);\n        return true;\n      }\n      this.data.read(h.size);\n    }\n  }\n\n  skipTo(target: number): { num: number; size: number } {\n    while (true) {\n      const h = this.readHeader();\n      if (!h) throw new ParseError(\"Record not found\");\n      if (h.num === target) return h;\n      this.data.read(h.size);\n    }\n  }\n\n  *iterRecord(): Generator<{ num: number; size: number; record: BytesIO }> {\n    while (true) {\n      const h = this.readHeader();\n      if (!h) break;\n      const record = new BytesIO(new Uint8Array(this.data.read(h.size)));\n      yield { num: h.num, size: h.size, record };\n    }\n  }\n}\n\ntype EncType = \"rc4\" | \"rc4_cryptoapi\" | \"xor\";\n\nexport class Xls97File implements BaseOfficeFile {\n  format = \"xls97\";\n  keyTypes: readonly string[] = [\"password\"];\n\n  private workbookData: Uint8Array;\n  private type?: EncType;\n  private password?: string;\n  private salt?: Uint8Array;\n  private keySize?: number;\n\n  constructor(public ole: OleFileIO) {\n    if (!ole.exists(\"Workbook\")) {\n      throw new FileFormatError(\"Not an Excel 97-2003 file (no Workbook stream)\");\n    }\n    this.workbookData = ole.openstream(\"Workbook\").getValue();\n  }\n\n  loadKey(opts: LoadKeyOptions): void {\n    const password = opts.password;\n    if (password === undefined) {\n      throw new DecryptionError(\"xls97 requires a password\");\n    }\n\n    const wb = new BIFFStream(new BytesIO(this.workbookData));\n    // First record must be BOF (id 2057).\n    const bofId = readU16(wb.data);\n    if (bofId !== RECORD.BOF) {\n      throw new ParseError(\"Workbook stream does not start with BOF\");\n    }\n    const bofSize = readU16(wb.data);\n    wb.data.read(bofSize);\n\n    const filePass = wb.skipTo(RECORD.FilePass);\n    const wEncryptionType = readU16(wb.data);\n    const encryptionInfo = new BytesIO(\n      new Uint8Array(wb.data.read(filePass.size - 2)),\n    );\n\n    if (wEncryptionType === 0x0000) {\n      // XOR obfuscation: <key:u16><verificationBytes:u16>; key is unused here.\n      readU16(encryptionInfo); // key\n      const verificationBytes = readU16(encryptionInfo);\n      if (!DocumentXOR.verifyPassword(password, verificationBytes)) {\n        throw new InvalidKeyError(\"Failed to verify password\");\n      }\n      this.type = \"xor\";\n      this.password = password;\n      return;\n    }\n\n    if (wEncryptionType !== 0x0001) {\n      throw new DecryptionError(\n        `Unsupported wEncryptionType: 0x${wEncryptionType.toString(16)}`,\n      );\n    }\n\n    // RC4 family — branch on the version major/minor that follows.\n    const vMajor = readU16(encryptionInfo);\n    const vMinor = readU16(encryptionInfo);\n\n    if (vMajor === 1 && vMinor === 1) {\n      const info = parseHeaderRC4(encryptionInfo);\n      if (\n        !DocumentRC4.verifyPassword(\n          password,\n          info.salt,\n          info.encryptedVerifier,\n          info.encryptedVerifierHash,\n        )\n      ) {\n        throw new InvalidKeyError(\"Failed to verify password\");\n      }\n      this.type = \"rc4\";\n      this.password = password;\n      this.salt = info.salt;\n      return;\n    }\n\n    if ((vMajor === 2 || vMajor === 3 || vMajor === 4) && vMinor === 2) {\n      const info = parseHeaderRC4CryptoAPI(encryptionInfo);\n      if (\n        !DocumentRC4CryptoAPI.verifyPassword(\n          password,\n          info.salt,\n          info.keySize,\n          info.encryptedVerifier,\n          info.encryptedVerifierHash,\n        )\n      ) {\n        throw new InvalidKeyError(\"Failed to verify password\");\n      }\n      this.type = \"rc4_cryptoapi\";\n      this.password = password;\n      this.salt = info.salt;\n      this.keySize = info.keySize;\n      return;\n    }\n\n    throw new DecryptionError(\n      `Unsupported encryption version: ${vMajor}.${vMinor}`,\n    );\n  }\n\n  decrypt(_opts: DecryptOptions = {}): Uint8Array {\n    if (!this.type || !this.password) {\n      throw new DecryptionError(\"Must call loadKey before decrypt\");\n    }\n\n    // Pass 1: classify each byte of the workbook into \"preserve plain\" or\n    // \"decrypt\". We accumulate a parallel \"encrypted-only\" buffer (zero-filled\n    // where plain bytes will land) so the cipher's per-block re-keying lines\n    // up with the actual stream offsets — both buffers share the same length.\n    const plain: number[] = []; // values >=0 land verbatim; -1 / -2 are decrypted\n    const encrypted: number[] = []; // bytes fed to the cipher (0 at plain spots)\n\n    const wb = new BIFFStream(new BytesIO(this.workbookData));\n    for (const { num, size, record } of wb.iterRecord()) {\n      const header = packU16LE(num);\n      const sizeHeader = packU16LE(size);\n      if (num === RECORD.FilePass) {\n        // Zero out the FilePass record so the output is no longer marked as\n        // encrypted. Header bytes [0, 0] then [size_lo, size_hi] preserves\n        // the record framing.\n        plain.push(0, 0, sizeHeader[0], sizeHeader[1]);\n        for (let i = 0; i < size; i++) plain.push(0);\n        for (let i = 0; i < 4 + size; i++) encrypted.push(0);\n        continue;\n      }\n      if (\n        num === RECORD.BOF ||\n        num === RECORD.UsrExcl ||\n        num === RECORD.FileLock ||\n        num === RECORD.InterfaceHdr ||\n        num === RECORD.RRDInfo ||\n        num === RECORD.RRDHead\n      ) {\n        // Records that MUST NOT be encrypted — preserve verbatim.\n        plain.push(header[0], header[1], sizeHeader[0], sizeHeader[1]);\n        const rec = record.read();\n        for (const b of rec) plain.push(b);\n        for (let i = 0; i < 4 + size; i++) encrypted.push(0);\n        continue;\n      }\n      if (num === RECORD.BoundSheet8) {\n        // Per spec, BoundSheet8.lbPlyPos (first 4 bytes after header) must\n        // stay plain; the remainder is encrypted.\n        plain.push(header[0], header[1], sizeHeader[0], sizeHeader[1]);\n        const lbPlyPos = record.read(4);\n        for (const b of lbPlyPos) plain.push(b);\n        for (let i = 0; i < size - 4; i++) plain.push(-2);\n        for (let i = 0; i < 8; i++) encrypted.push(0);\n        const rest = record.read();\n        for (const b of rest) encrypted.push(b);\n        continue;\n      }\n      // Default: 4-byte header stays plain, body gets decrypted.\n      plain.push(header[0], header[1], sizeHeader[0], sizeHeader[1]);\n      for (let i = 0; i < size; i++) plain.push(-1);\n      for (let i = 0; i < 4; i++) encrypted.push(0);\n      const body = record.read();\n      for (const b of body) encrypted.push(b);\n    }\n\n    if (plain.length !== encrypted.length) {\n      throw new DecryptionError(\n        \"Internal error: plain/encrypted length mismatch\",\n      );\n    }\n\n    // Pass 2: decrypt the parallel encrypted-only buffer.\n    const encryptedBuf = new Uint8Array(encrypted);\n    let dec: Uint8Array;\n    if (this.type === \"rc4\") {\n      dec = DocumentRC4.decrypt(\n        this.password,\n        this.salt!,\n        new BytesIO(encryptedBuf),\n        1024,\n      );\n    } else if (this.type === \"rc4_cryptoapi\") {\n      dec = DocumentRC4CryptoAPI.decrypt(\n        this.password,\n        this.salt!,\n        this.keySize!,\n        new BytesIO(encryptedBuf),\n        1024,\n      );\n    } else {\n      // XOR's per-byte rotation depends on position within the stream and\n      // uses the marker array to know which bytes are real.\n      dec = DocumentXOR.decrypt(\n        this.password,\n        new BytesIO(encryptedBuf),\n        plain,\n        null,\n        10,\n      );\n    }\n\n    // Pass 3: merge — decrypted byte at -1/-2 positions, plain byte elsewhere.\n    const out = new Uint8Array(plain.length);\n    for (let i = 0; i < plain.length; i++) {\n      const c = plain[i];\n      out[i] = c === -1 || c === -2 ? dec[i] : c;\n    }\n\n    // Write the decrypted Workbook back into a copy of the OLE container,\n    // matching the Python implementation's behaviour.\n    this.ole.writeStream(\"Workbook\", out);\n    return this.ole.getBuffer();\n  }\n\n  isEncrypted(): boolean {\n    try {\n      const wb = new BIFFStream(new BytesIO(this.workbookData));\n      if (readU16(wb.data) !== RECORD.BOF) return false;\n      const bofSize = readU16(wb.data);\n      wb.data.read(bofSize);\n      if (!wb.hasRecord(RECORD.FilePass)) return false;\n      wb.skipTo(RECORD.FilePass);\n      const t = readU16(wb.data);\n      return t === 0x0000 || t === 0x0001;\n    } catch {\n      return false;\n    }\n  }\n}\n\n","/**\n * Word 97-2003 (BIFF / FIB) format handler.\n *\n * Word's encryption affects three streams:\n *   - WordDocument: starts with a 0x44-byte FibBase header. The first 0x44\n *     bytes (with `fEncrypted=0` and `fObfuscation=0` cleared) MUST be\n *     written plaintext; the rest of the stream is decrypted.\n *   - 0Table or 1Table (selected by FibBase.fWhichTblStm): fully decrypted.\n *   - Data: optional, fully decrypted if present.\n *\n * Direct port of `msoffcrypto/format/doc97.py`.\n */\n\nimport { OleFileIO } from \"../olefile.js\";\nimport {\n  DecryptionError,\n  FileFormatError,\n  InvalidKeyError,\n} from \"../exceptions.js\";\nimport { DocumentRC4 } from \"../method/rc4.js\";\nimport { DocumentRC4CryptoAPI } from \"../method/rc4_cryptoapi.js\";\nimport { parseHeaderRC4, parseHeaderRC4CryptoAPI } from \"./common.js\";\nimport {\n  ByteWriter,\n  BytesIO,\n  getBit,\n  getBitSlice,\n  readU16,\n  readU32,\n  setBit,\n  setBitSlice,\n  type Readable,\n} from \"../utils.js\";\nimport type {\n  BaseOfficeFile,\n  DecryptOptions,\n  LoadKeyOptions,\n} from \"./base.js\";\n\ninterface FibBase {\n  wIdent: number;\n  nFib: number;\n  unused: number;\n  lid: number;\n  pnNext: number;\n  // Bit fields packed into one u16\n  fDot: number;\n  fGlsy: number;\n  fComplex: number;\n  fHasPic: number;\n  cQuickSaves: number;\n  fEncrypted: number;\n  fWhichTblStm: number;\n  fReadOnlyRecommended: number;\n  fWriteReservation: number;\n  fExtChar: number;\n  fLoadOverride: number;\n  fFarEast: number;\n  fObfuscation: number;\n  // ---\n  nFibBack: number;\n  IKey: number;\n  envr: number;\n  // Bit field byte\n  fMac: number;\n  fEmptySpecial: number;\n  fLoadOverridePage: number;\n  reserved1: number;\n  reserved2: number;\n  fSpare0: number;\n  // ---\n  reserved3: number;\n  reserved4: number;\n  reserved5: number;\n  reserved6: number;\n}\n\nfunction parseFibBase(blob: Readable): FibBase {\n  const wIdent = readU16(blob);\n  const nFib = readU16(blob);\n  const unused = readU16(blob);\n  const lid = readU16(blob);\n  const pnNext = readU16(blob);\n\n  const flagsA = readU16(blob);\n  const fDot = getBit(flagsA, 0);\n  const fGlsy = getBit(flagsA, 1);\n  const fComplex = getBit(flagsA, 2);\n  const fHasPic = getBit(flagsA, 3);\n  const cQuickSaves = getBitSlice(flagsA, 4, 4);\n  const fEncrypted = getBit(flagsA, 8);\n  const fWhichTblStm = getBit(flagsA, 9);\n  const fReadOnlyRecommended = getBit(flagsA, 10);\n  const fWriteReservation = getBit(flagsA, 11);\n  const fExtChar = getBit(flagsA, 12);\n  const fLoadOverride = getBit(flagsA, 13);\n  const fFarEast = getBit(flagsA, 14);\n  const fObfuscation = getBit(flagsA, 15);\n\n  const nFibBack = readU16(blob);\n  const IKey = readU32(blob);\n  const envr = blob.read(1)[0];\n\n  const flagsB = blob.read(1)[0];\n  const fMac = getBit(flagsB, 0);\n  const fEmptySpecial = getBit(flagsB, 1);\n  const fLoadOverridePage = getBit(flagsB, 2);\n  const reserved1 = getBit(flagsB, 3);\n  const reserved2 = getBit(flagsB, 4);\n  const fSpare0 = getBitSlice(flagsB, 5, 3);\n\n  const reserved3 = readU16(blob);\n  const reserved4 = readU16(blob);\n  const reserved5 = readU32(blob);\n  const reserved6 = readU32(blob);\n\n  return {\n    wIdent,\n    nFib,\n    unused,\n    lid,\n    pnNext,\n    fDot,\n    fGlsy,\n    fComplex,\n    fHasPic,\n    cQuickSaves,\n    fEncrypted,\n    fWhichTblStm,\n    fReadOnlyRecommended,\n    fWriteReservation,\n    fExtChar,\n    fLoadOverride,\n    fFarEast,\n    fObfuscation,\n    nFibBack,\n    IKey,\n    envr,\n    fMac,\n    fEmptySpecial,\n    fLoadOverridePage,\n    reserved1,\n    reserved2,\n    fSpare0,\n    reserved3,\n    reserved4,\n    reserved5,\n    reserved6,\n  };\n}\n\nfunction packFibBase(fib: FibBase): Uint8Array {\n  let flagsA = 0xffff;\n  flagsA = setBit(flagsA, 0, fib.fDot);\n  flagsA = setBit(flagsA, 1, fib.fGlsy);\n  flagsA = setBit(flagsA, 2, fib.fComplex);\n  flagsA = setBit(flagsA, 3, fib.fHasPic);\n  flagsA = setBitSlice(flagsA, 4, 4, fib.cQuickSaves);\n  flagsA = setBit(flagsA, 8, fib.fEncrypted);\n  flagsA = setBit(flagsA, 9, fib.fWhichTblStm);\n  flagsA = setBit(flagsA, 10, fib.fReadOnlyRecommended);\n  flagsA = setBit(flagsA, 11, fib.fWriteReservation);\n  flagsA = setBit(flagsA, 12, fib.fExtChar);\n  flagsA = setBit(flagsA, 13, fib.fLoadOverride);\n  flagsA = setBit(flagsA, 14, fib.fFarEast);\n  flagsA = setBit(flagsA, 15, fib.fObfuscation);\n\n  let flagsB = 0xff;\n  flagsB = setBit(flagsB, 0, fib.fMac);\n  flagsB = setBit(flagsB, 1, fib.fEmptySpecial);\n  flagsB = setBit(flagsB, 2, fib.fLoadOverridePage);\n  flagsB = setBit(flagsB, 3, fib.reserved1);\n  flagsB = setBit(flagsB, 4, fib.reserved2);\n  flagsB = setBitSlice(flagsB, 5, 3, fib.fSpare0);\n\n  return new ByteWriter()\n    .u16(fib.wIdent)\n    .u16(fib.nFib)\n    .u16(fib.unused)\n    .u16(fib.lid)\n    .u16(fib.pnNext)\n    .u16(flagsA & 0xffff)\n    .u16(fib.nFibBack)\n    .u32(fib.IKey >>> 0)\n    .u8(fib.envr)\n    .u8(flagsB & 0xff)\n    .u16(fib.reserved3)\n    .u16(fib.reserved4)\n    .u32(fib.reserved5 >>> 0)\n    .u32(fib.reserved6 >>> 0)\n    .build();\n}\n\ntype EncType = \"rc4\" | \"rc4_cryptoapi\";\n\nexport class Doc97File implements BaseOfficeFile {\n  format = \"doc97\";\n  keyTypes: readonly string[] = [\"password\"];\n\n  private fib: FibBase;\n  private tableName: \"0Table\" | \"1Table\";\n\n  private type?: EncType;\n  private password?: string;\n  private salt?: Uint8Array;\n  private keySize?: number;\n\n  constructor(public ole: OleFileIO) {\n    const wd = ole.exists(\"WordDocument\")\n      ? \"WordDocument\"\n      : ole.exists(\"wordDocument\")\n        ? \"wordDocument\"\n        : null;\n    if (!wd) {\n      throw new FileFormatError(\"Not a Word 97-2003 file (no WordDocument stream)\");\n    }\n    this.fib = parseFibBase(new BytesIO(ole.openstream(wd).getValue()));\n    this.tableName = this.fib.fWhichTblStm === 1 ? \"1Table\" : \"0Table\";\n  }\n\n  loadKey(opts: LoadKeyOptions): void {\n    const password = opts.password;\n    if (password === undefined) {\n      throw new DecryptionError(\"doc97 requires a password\");\n    }\n    if (!this.fib.fEncrypted) {\n      throw new DecryptionError(\"File is not encrypted\");\n    }\n    if (this.fib.fObfuscation === 1) {\n      throw new DecryptionError(\n        \"XOR-obfuscated DOC files are not supported (the format is rare)\",\n      );\n    }\n\n    if (!this.ole.exists(this.tableName)) {\n      throw new FileFormatError(`Table stream not found: ${this.tableName}`);\n    }\n    const table = this.ole.openstream(this.tableName);\n    const vMajor = readU16(table);\n    const vMinor = readU16(table);\n\n    if (vMajor === 1 && vMinor === 1) {\n      const info = parseHeaderRC4(table);\n      if (\n        !DocumentRC4.verifyPassword(\n          password,\n          info.salt,\n          info.encryptedVerifier,\n          info.encryptedVerifierHash,\n        )\n      ) {\n        throw new InvalidKeyError(\"Failed to verify password\");\n      }\n      this.type = \"rc4\";\n      this.password = password;\n      this.salt = info.salt;\n      return;\n    }\n\n    if ((vMajor === 2 || vMajor === 3 || vMajor === 4) && vMinor === 2) {\n      const info = parseHeaderRC4CryptoAPI(table);\n      if (\n        !DocumentRC4CryptoAPI.verifyPassword(\n          password,\n          info.salt,\n          info.keySize,\n          info.encryptedVerifier,\n          info.encryptedVerifierHash,\n        )\n      ) {\n        throw new InvalidKeyError(\"Failed to verify password\");\n      }\n      this.type = \"rc4_cryptoapi\";\n      this.password = password;\n      this.salt = info.salt;\n      this.keySize = info.keySize;\n      return;\n    }\n\n    throw new DecryptionError(\n      `Unsupported encryption version: ${vMajor}.${vMinor}`,\n    );\n  }\n\n  decrypt(_opts: DecryptOptions = {}): Uint8Array {\n    if (!this.type || !this.password) {\n      throw new DecryptionError(\"Must call loadKey before decrypt\");\n    }\n\n    // Build the new WordDocument: 0x44 plaintext header (with fEncrypted=0,\n    // fObfuscation=0, IKey=0) followed by decrypted data starting at 0x44.\n    const FIB_LENGTH = 0x44;\n    const newFib: FibBase = {\n      ...this.fib,\n      fEncrypted: 0,\n      fObfuscation: 0,\n      IKey: 0,\n    };\n\n    const wordDocBytes = this.ole.openstream(\"WordDocument\").getValue();\n    const fibBytes = packFibBase(newFib);\n    const newWordDoc = new Uint8Array(wordDocBytes.length);\n    newWordDoc.set(fibBytes, 0);\n    // Bytes between fibBytes.length and FIB_LENGTH come from the original\n    // WordDocument plaintext (FibRgW, FibRgLw, etc.).\n    const remainingHeader = wordDocBytes.subarray(fibBytes.length, FIB_LENGTH);\n    newWordDoc.set(remainingHeader, fibBytes.length);\n\n    const decFull = this.cipherDecrypt(wordDocBytes);\n    newWordDoc.set(decFull.subarray(FIB_LENGTH), FIB_LENGTH);\n\n    // Decrypt the table stream wholesale.\n    const tableBytes = this.ole.openstream(this.tableName).getValue();\n    const tableDec = this.cipherDecrypt(tableBytes);\n\n    // Optional Data stream\n    let dataDec: Uint8Array | null = null;\n    if (this.ole.exists(\"Data\")) {\n      const dataBytes = this.ole.openstream(\"Data\").getValue();\n      dataDec = this.cipherDecrypt(dataBytes);\n    }\n\n    this.ole.writeStream(\"WordDocument\", newWordDoc);\n    this.ole.writeStream(this.tableName, tableDec);\n    if (dataDec) this.ole.writeStream(\"Data\", dataDec);\n\n    return this.ole.getBuffer();\n  }\n\n  private cipherDecrypt(buf: Uint8Array): Uint8Array {\n    if (this.type === \"rc4\") {\n      return DocumentRC4.decrypt(this.password!, this.salt!, new BytesIO(buf));\n    }\n    return DocumentRC4CryptoAPI.decrypt(\n      this.password!,\n      this.salt!,\n      this.keySize!,\n      new BytesIO(buf),\n    );\n  }\n\n  isEncrypted(): boolean {\n    return this.fib.fEncrypted === 1;\n  }\n}\n\n","/**\n * PowerPoint 97-2003 format handler.\n *\n * PPT's encryption story is the most involved of the legacy formats:\n *\n *   1. The Current User Stream contains a CurrentUserAtom whose\n *      `offsetToCurrentEdit` points into the PowerPoint Document stream.\n *   2. Following that pointer lands on a UserEditAtom; its\n *      `encryptSessionPersistIdRef` resolves (via the persist object\n *      directory built from the chain of UserEditAtoms +\n *      PersistDirectoryAtoms) to a CryptSession10Container record holding\n *      the EncryptionInfo header.\n *   3. Each persist object in the directory is independently RC4-CryptoAPI\n *      encrypted, using its `persistId` as the cipher block index.\n *   4. UserEditAtom, PersistDirectoryAtom, and CryptSession10Container\n *      records themselves MUST NOT be encrypted.\n *\n * We mirror the Python implementation: build the persist directory, decrypt\n * each persist object in place, zero out the CryptSession10Container, drop\n * the encryptSessionPersistIdRef, and rewrite Current User Stream's header\n * token to \"not encrypted\".\n *\n * Direct port of `msoffcrypto/format/ppt97.py`.\n */\n\nimport { OleFileIO } from \"../olefile.js\";\nimport {\n  DecryptionError,\n  FileFormatError,\n  InvalidKeyError,\n  ParseError,\n} from \"../exceptions.js\";\nimport { DocumentRC4CryptoAPI } from \"../method/rc4_cryptoapi.js\";\nimport { parseHeaderRC4CryptoAPI } from \"./common.js\";\nimport {\n  ByteWriter,\n  BytesIO,\n  readU16,\n  readU16LE,\n  readU32LE,\n  setBitSlice,\n} from \"../utils.js\";\nimport type {\n  BaseOfficeFile,\n  DecryptOptions,\n  LoadKeyOptions,\n} from \"./base.js\";\n\ninterface RecordHeader {\n  recVer: number;\n  recInstance: number;\n  recType: number;\n  recLen: number;\n}\n\nfunction parseRecordHeader(b: Uint8Array, off: number): RecordHeader {\n  const w0 = readU16LE(b, off);\n  const recVer = w0 & 0xf;\n  const recInstance = (w0 >>> 4) & 0xfff;\n  const recType = readU16LE(b, off + 2);\n  const recLen = readU32LE(b, off + 4);\n  return { recVer, recInstance, recType, recLen };\n}\n\nfunction packRecordHeader(rh: RecordHeader): Uint8Array {\n  const w0 = (rh.recVer & 0xf) | ((rh.recInstance & 0xfff) << 4);\n  return new ByteWriter().u16(w0).u16(rh.recType).u32(rh.recLen).build();\n}\n\ninterface CurrentUserAtom {\n  rh: RecordHeader;\n  size: number;\n  headerToken: number;\n  offsetToCurrentEdit: number;\n  lenUserName: number;\n  docFileVersion: number;\n  majorVersion: number;\n  minorVersion: number;\n  unused: Uint8Array;\n  ansiUserName: Uint8Array;\n  relVersion: number;\n  unicodeUserName: Uint8Array;\n}\n\nfunction parseCurrentUserAtom(buf: Uint8Array): CurrentUserAtom {\n  const rh = parseRecordHeader(buf, 0);\n  if (rh.recVer !== 0 || rh.recInstance !== 0 || rh.recType !== 0x0ff6) {\n    throw new ParseError(\"Invalid CurrentUserAtom record header\");\n  }\n  let off = 8;\n  const size = readU32LE(buf, off); off += 4;\n  if (size !== 0x14) throw new ParseError(\"CurrentUserAtom.size != 0x14\");\n  const headerToken = readU32LE(buf, off); off += 4;\n  const offsetToCurrentEdit = readU32LE(buf, off); off += 4;\n  const lenUserName = readU16LE(buf, off); off += 2;\n  const docFileVersion = readU16LE(buf, off); off += 2;\n  const majorVersion = buf[off++];\n  const minorVersion = buf[off++];\n  const unused = buf.subarray(off, off + 2); off += 2;\n  const ansiUserName = buf.subarray(off, off + lenUserName); off += lenUserName;\n  const relVersion = readU32LE(buf, off); off += 4;\n  const unicodeUserName = buf.subarray(off, off + 2 * lenUserName);\n  return {\n    rh,\n    size,\n    headerToken,\n    offsetToCurrentEdit,\n    lenUserName,\n    docFileVersion,\n    majorVersion,\n    minorVersion,\n    unused: new Uint8Array(unused),\n    ansiUserName: new Uint8Array(ansiUserName),\n    relVersion,\n    unicodeUserName: new Uint8Array(unicodeUserName),\n  };\n}\n\nfunction packCurrentUserAtom(c: CurrentUserAtom): Uint8Array {\n  return new ByteWriter()\n    .bytes(packRecordHeader(c.rh))\n    .u32(c.size)\n    .u32(c.headerToken >>> 0)\n    .u32(c.offsetToCurrentEdit)\n    .u16(c.lenUserName)\n    .u16(c.docFileVersion)\n    .u8(c.majorVersion)\n    .u8(c.minorVersion)\n    .bytes(c.unused)\n    .bytes(c.ansiUserName)\n    .u32(c.relVersion)\n    .bytes(c.unicodeUserName)\n    .build();\n}\n\ninterface UserEditAtom {\n  rh: RecordHeader;\n  lastSlideIdRef: number;\n  version: number;\n  minorVersion: number;\n  majorVersion: number;\n  offsetLastEdit: number;\n  offsetPersistDirectory: number;\n  docPersistIdRef: number;\n  persistIdSeed: number;\n  lastView: number;\n  unused: Uint8Array;\n  encryptSessionPersistIdRef: number | null;\n}\n\nfunction parseUserEditAtom(buf: Uint8Array, baseOff: number): UserEditAtom {\n  const rh = parseRecordHeader(buf, baseOff);\n  if (rh.recVer !== 0 || rh.recInstance !== 0 || rh.recType !== 0x0ff5) {\n    throw new ParseError(\"Invalid UserEditAtom record header\");\n  }\n  if (rh.recLen !== 0x1c && rh.recLen !== 0x20) {\n    throw new ParseError(`Unexpected UserEditAtom recLen: ${rh.recLen}`);\n  }\n  let off = baseOff + 8;\n  const lastSlideIdRef = readU32LE(buf, off); off += 4;\n  const version = readU16LE(buf, off); off += 2;\n  const minorVersion = buf[off++];\n  const majorVersion = buf[off++];\n  const offsetLastEdit = readU32LE(buf, off); off += 4;\n  const offsetPersistDirectory = readU32LE(buf, off); off += 4;\n  const docPersistIdRef = readU32LE(buf, off); off += 4;\n  const persistIdSeed = readU32LE(buf, off); off += 4;\n  const lastView = readU16LE(buf, off); off += 2;\n  const unused = buf.subarray(off, off + 2); off += 2;\n  let encryptSessionPersistIdRef: number | null = null;\n  if (rh.recLen === 0x20) {\n    encryptSessionPersistIdRef = readU32LE(buf, off);\n  }\n  return {\n    rh,\n    lastSlideIdRef,\n    version,\n    minorVersion,\n    majorVersion,\n    offsetLastEdit,\n    offsetPersistDirectory,\n    docPersistIdRef,\n    persistIdSeed,\n    lastView,\n    unused: new Uint8Array(unused),\n    encryptSessionPersistIdRef,\n  };\n}\n\nfunction packUserEditAtom(u: UserEditAtom): Uint8Array {\n  const w = new ByteWriter()\n    .bytes(packRecordHeader(u.rh))\n    .u32(u.lastSlideIdRef)\n    .u16(u.version)\n    .u8(u.minorVersion)\n    .u8(u.majorVersion)\n    .u32(u.offsetLastEdit)\n    .u32(u.offsetPersistDirectory)\n    .u32(u.docPersistIdRef)\n    .u32(u.persistIdSeed)\n    .u16(u.lastView)\n    .bytes(u.unused);\n  if (u.encryptSessionPersistIdRef !== null) {\n    w.u32(u.encryptSessionPersistIdRef);\n  }\n  return w.build();\n}\n\ninterface PersistDirectoryEntry {\n  persistId: number;\n  cPersist: number;\n  rgPersistOffset: number[];\n}\n\ninterface PersistDirectoryAtom {\n  rh: RecordHeader;\n  rgPersistDirEntry: PersistDirectoryEntry[];\n}\n\nfunction parsePersistDirectoryAtom(\n  buf: Uint8Array,\n  baseOff: number,\n): PersistDirectoryAtom {\n  const rh = parseRecordHeader(buf, baseOff);\n  if (rh.recVer !== 0 || rh.recInstance !== 0 || rh.recType !== 0x1772) {\n    throw new ParseError(\"Invalid PersistDirectoryAtom record header\");\n  }\n  const entries: PersistDirectoryEntry[] = [];\n  let pos = 0;\n  let off = baseOff + 8;\n  while (pos < rh.recLen) {\n    const w = readU32LE(buf, off);\n    off += 4;\n    const persistId = w & 0xfffff;\n    const cPersist = (w >>> 20) & 0xfff;\n    const rgPersistOffset: number[] = [];\n    for (let i = 0; i < cPersist; i++) {\n      rgPersistOffset.push(readU32LE(buf, off));\n      off += 4;\n    }\n    const entrySize = 4 + 4 * cPersist;\n    entries.push({ persistId, cPersist, rgPersistOffset });\n    pos += entrySize;\n  }\n  return { rh, rgPersistDirEntry: entries };\n}\n\nfunction packPersistDirectoryAtom(pda: PersistDirectoryAtom): Uint8Array {\n  const w = new ByteWriter().bytes(packRecordHeader(pda.rh));\n  for (const e of pda.rgPersistDirEntry) {\n    // Pack {persistId: u20, cPersist: u12} into one u32 (LE).\n    let bits = 0xffffffff >>> 0;\n    bits = setBitSlice(bits, 0, 20, e.persistId);\n    bits = setBitSlice(bits, 20, 12, e.cPersist);\n    w.u32(bits >>> 0);\n    for (const o of e.rgPersistOffset) w.u32(o);\n  }\n  return w.build();\n}\n\n/**\n * Build the persist object directory: persistId → byte offset within the\n * PowerPoint Document stream. Walks the UserEditAtom chain via offsetLastEdit.\n */\nfunction constructPersistObjectDirectory(\n  currentUserBytes: Uint8Array,\n  pptBytes: Uint8Array,\n): Map<number, number> {\n  const cu = parseCurrentUserAtom(currentUserBytes);\n  const stack: PersistDirectoryAtom[] = [];\n\n  let off = cu.offsetToCurrentEdit;\n  // Spec says exactly one UserEditAtom — but we walk the chain in case of\n  // multiple revisions, mirroring the Python implementation.\n  // eslint-disable-next-line no-constant-condition\n  while (true) {\n    const ue = parseUserEditAtom(pptBytes, off);\n    const pda = parsePersistDirectoryAtom(pptBytes, ue.offsetPersistDirectory);\n    stack.push(pda);\n    if (ue.offsetLastEdit === 0) break;\n    off = ue.offsetLastEdit;\n    // Defensive break: real-world PPT has 1 entry\n    if (stack.length > 1) break;\n  }\n\n  const dir = new Map<number, number>();\n  while (stack.length > 0) {\n    const pda = stack.pop()!;\n    for (const e of pda.rgPersistDirEntry) {\n      for (let i = 0; i < e.rgPersistOffset.length; i++) {\n        dir.set(e.persistId + i, e.rgPersistOffset[i]);\n      }\n    }\n  }\n  return dir;\n}\n\nexport class Ppt97File implements BaseOfficeFile {\n  format = \"ppt97\";\n  keyTypes: readonly string[] = [\"password\"];\n\n  private currentUserBytes: Uint8Array;\n  private pptBytes: Uint8Array;\n\n  private password?: string;\n  private salt?: Uint8Array;\n  private keySize?: number;\n\n  constructor(public ole: OleFileIO) {\n    if (!ole.exists(\"Current User\") || !ole.exists(\"PowerPoint Document\")) {\n      throw new FileFormatError(\n        \"Not a PowerPoint 97-2003 file (missing Current User or PowerPoint Document stream)\",\n      );\n    }\n    this.currentUserBytes = ole.openstream(\"Current User\").getValue();\n    this.pptBytes = ole.openstream(\"PowerPoint Document\").getValue();\n  }\n\n  loadKey(opts: LoadKeyOptions): void {\n    const password = opts.password;\n    if (password === undefined) {\n      throw new DecryptionError(\"ppt97 requires a password\");\n    }\n\n    const cu = parseCurrentUserAtom(this.currentUserBytes);\n    const ue = parseUserEditAtom(this.pptBytes, cu.offsetToCurrentEdit);\n    if (ue.encryptSessionPersistIdRef === null) {\n      throw new DecryptionError(\"File does not contain an encryption session\");\n    }\n\n    const dir = constructPersistObjectDirectory(\n      this.currentUserBytes,\n      this.pptBytes,\n    );\n    const cryptOff = dir.get(ue.encryptSessionPersistIdRef);\n    if (cryptOff === undefined) {\n      throw new ParseError(\n        \"encryptSessionPersistIdRef not in persist object directory\",\n      );\n    }\n\n    // CryptSession10Container: 8-byte rh + recLen bytes of EncryptionInfo.\n    const containerRh = parseRecordHeader(this.pptBytes, cryptOff);\n    if (containerRh.recType !== 0x2f14) {\n      throw new ParseError(\n        `Expected CryptSession10Container, got recType=0x${containerRh.recType.toString(16)}`,\n      );\n    }\n    const cryptData = this.pptBytes.subarray(\n      cryptOff + 8,\n      cryptOff + 8 + containerRh.recLen,\n    );\n    const blob = new BytesIO(new Uint8Array(cryptData));\n\n    const vMajor = readU16(blob);\n    const vMinor = readU16(blob);\n    if (\n      !(vMajor === 2 || vMajor === 3 || vMajor === 4) ||\n      vMinor !== 2\n    ) {\n      throw new DecryptionError(\n        `PPT only supports RC4 CryptoAPI encryption (got ${vMajor}.${vMinor})`,\n      );\n    }\n\n    const info = parseHeaderRC4CryptoAPI(blob);\n    if (\n      !DocumentRC4CryptoAPI.verifyPassword(\n        password,\n        info.salt,\n        info.keySize,\n        info.encryptedVerifier,\n        info.encryptedVerifierHash,\n      )\n    ) {\n      throw new InvalidKeyError(\"Failed to verify password\");\n    }\n\n    this.password = password;\n    this.salt = info.salt;\n    this.keySize = info.keySize;\n  }\n\n  decrypt(_opts: DecryptOptions = {}): Uint8Array {\n    if (this.password === undefined) {\n      throw new DecryptionError(\"Must call loadKey before decrypt\");\n    }\n\n    // ---- Current User Stream rewrite ----\n    const cu = parseCurrentUserAtom(this.currentUserBytes);\n    const cuNew: CurrentUserAtom = {\n      ...cu,\n      // 0xE391C05F: spec value indicating \"this file SHOULD NOT be encrypted\".\n      headerToken: 0xe391c05f,\n    };\n    const newCurrentUser = packCurrentUserAtom(cuNew);\n    if (newCurrentUser.length !== this.currentUserBytes.length) {\n      throw new DecryptionError(\n        \"Internal: Current User stream size changed unexpectedly\",\n      );\n    }\n\n    // ---- PowerPoint Document Stream rewrite ----\n    const dec = new Uint8Array(this.pptBytes.length);\n    dec.set(this.pptBytes, 0);\n\n    // Patch UserEditAtom: clear encryptSessionPersistIdRef + drop 4 bytes\n    // from recLen.\n    const ueOff = cu.offsetToCurrentEdit;\n    const ue = parseUserEditAtom(this.pptBytes, ueOff);\n    const ueNew: UserEditAtom = {\n      ...ue,\n      rh: { ...ue.rh, recLen: ue.rh.recLen - 4 },\n      encryptSessionPersistIdRef: 0x00000000,\n    };\n    const ueBytes = packUserEditAtom(ueNew);\n    dec.set(ueBytes, ueOff);\n\n    // Patch PersistDirectoryAtom: drop 1 from cPersist (we'll zero out the\n    // CryptSession10Container record below).\n    const pda = parsePersistDirectoryAtom(this.pptBytes, ue.offsetPersistDirectory);\n    const firstEntry = pda.rgPersistDirEntry[0];\n    const pdaNew: PersistDirectoryAtom = {\n      rh: pda.rh,\n      rgPersistDirEntry: [\n        {\n          persistId: firstEntry.persistId,\n          cPersist: firstEntry.cPersist - 1,\n          rgPersistOffset: firstEntry.rgPersistOffset,\n        },\n      ],\n    };\n    const pdaBytes = packPersistDirectoryAtom(pdaNew);\n    dec.set(pdaBytes, ue.offsetPersistDirectory);\n\n    // ---- Decrypt each persist object ----\n    const dir = constructPersistObjectDirectory(\n      this.currentUserBytes,\n      this.pptBytes,\n    );\n    // Convert to ordered array (Map preserves insertion order, matching the\n    // Python dict iteration semantics on Python 3.7+).\n    const items = Array.from(dir.entries());\n\n    for (let i = 0; i < items.length; i++) {\n      const [persistId, off] = items[i];\n      const rh = parseRecordHeader(this.pptBytes, off);\n\n      // CryptSession10Container — zero out the entire record.\n      if (rh.recType === 0x2f14) {\n        const total = 8 + rh.recLen;\n        for (let k = 0; k < total; k++) dec[off + k] = 0;\n        continue;\n      }\n\n      // UserEditAtom / PersistDirectoryAtom — already handled above; skip.\n      if (rh.recType === 0x0ff5 || rh.recType === 0x1772) continue;\n\n      // Compute the encrypted-region length: from this offset to the next\n      // persist object's offset, minus the 8-byte record header. The Python\n      // code has the same rule.\n      if (i + 1 >= items.length) continue;\n      const nextOff = items[i + 1][1];\n      const recLen = nextOff - off - 8;\n      if (recLen < 0) continue;\n\n      const encBuf = this.pptBytes.subarray(off, off + 8 + recLen);\n      // The Python source uses an \"undocumented\" blocksize that's a multiple\n      // of keySize big enough to cover (8 + recLen) plus one extra round.\n      const blockSize =\n        this.keySize! * (Math.floor((8 + recLen) / this.keySize!) + 1);\n      const decoded = DocumentRC4CryptoAPI.decrypt(\n        this.password!,\n        this.salt!,\n        this.keySize!,\n        new BytesIO(new Uint8Array(encBuf)),\n        blockSize,\n        persistId,\n      );\n      dec.set(decoded.subarray(0, encBuf.length), off);\n    }\n\n    this.ole.writeStream(\"Current User\", newCurrentUser);\n    this.ole.writeStream(\"PowerPoint Document\", dec);\n    return this.ole.getBuffer();\n  }\n\n  isEncrypted(): boolean {\n    try {\n      const cu = parseCurrentUserAtom(this.currentUserBytes);\n      const ue = parseUserEditAtom(this.pptBytes, cu.offsetToCurrentEdit);\n      return ue.rh.recLen === 0x20;\n    } catch {\n      return false;\n    }\n  }\n}\n","/**\n * office-crypto — TypeScript port of msoffcrypto-tool.\n *\n * Entry point. Exposes:\n *   - `OfficeFile(buf)`: factory that auto-detects file format.\n *   - `OOXMLFile`: handler for DOCX/XLSX/PPTX.\n *   - `Xls97File` / `Doc97File` / `Ppt97File`: legacy stubs.\n *   - `isEncrypted(buf)`: quick helper.\n *\n * See README for usage and the documented public surface area.\n */\n\nimport { isOleFile, OleFileIO } from \"./olefile.js\";\nimport { FileFormatError } from \"./exceptions.js\";\nimport { OOXMLFile, isOoxml } from \"./format/ooxml.js\";\nimport { Xls97File } from \"./format/xls97.js\";\nimport { Doc97File } from \"./format/doc97.js\";\nimport { Ppt97File } from \"./format/ppt97.js\";\nimport type { BaseOfficeFile } from \"./format/base.js\";\n\nexport {\n  FileFormatError,\n  ParseError,\n  DecryptionError,\n  EncryptionError,\n  InvalidKeyError,\n} from \"./exceptions.js\";\n\nexport { OOXMLFile, isOoxml } from \"./format/ooxml.js\";\nexport { Xls97File } from \"./format/xls97.js\";\nexport { Doc97File } from \"./format/doc97.js\";\nexport { Ppt97File } from \"./format/ppt97.js\";\nexport { OleFileIO, isOleFile } from \"./olefile.js\";\n\nexport type {\n  BaseOfficeFile,\n  LoadKeyOptions,\n  DecryptOptions,\n} from \"./format/base.js\";\n\n/**\n * Auto-detect the format of `buf` and return the appropriate handler.\n *\n * @example\n *   const buf = await fs.promises.readFile(\"encrypted.docx\");\n *   const file = OfficeFile(buf);\n *   file.loadKey({ password: \"secret\" });\n *   const decrypted = file.decrypt();\n *   await fs.promises.writeFile(\"plain.docx\", decrypted);\n */\nexport function OfficeFile(buf: Uint8Array | ArrayBuffer): BaseOfficeFile {\n  const view = buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf;\n\n  if (isOleFile(view)) {\n    const ole = new OleFileIO(view);\n    if (ole.exists(\"EncryptionInfo\")) return new OOXMLFile(view);\n    if (ole.exists(\"WordDocument\") || ole.exists(\"wordDocument\")) {\n      return new Doc97File(ole);\n    }\n    if (ole.exists(\"Workbook\")) return new Xls97File(ole);\n    if (ole.exists(\"PowerPoint Document\")) return new Ppt97File(ole);\n    throw new FileFormatError(\"Unrecognized OLE file format\");\n  }\n  if (isOoxml(view)) return new OOXMLFile(view);\n  throw new FileFormatError(\"Unsupported file format\");\n}\n\n/**\n * Returns true if the input bytes look like an encrypted Office file.\n * Plain OOXML (.docx etc.) returns false; legacy OLE-based protected files\n * return true if a known encryption marker is present.\n */\nexport function isEncrypted(buf: Uint8Array | ArrayBuffer): boolean {\n  const view = buf instanceof ArrayBuffer ? new Uint8Array(buf) : buf;\n  if (!isOleFile(view)) return false;\n  try {\n    const file = OfficeFile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