Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface QMCCrypto

Hierarchy

Index

Properties

HEAPU8

HEAPU8: Uint8Array

Emscripten HEAP, use this for raw memory access.

Methods

UTF8ToString

  • UTF8ToString(ptr: number, maxBytesToRead?: number): string
  • Given a pointer ptr to a null-terminated UTF8-encoded string in the Emscripten HEAP, returns a copy of that string as a JavaScript String object.

    Parameters

    • ptr: number

      A pointer to a null-terminated UTF8-encoded string in the Emscripten HEAP.

    • Optional maxBytesToRead: number

      An optional length that specifies the maximum number of bytes to read. Omit to read until the null-terminator.

    Returns string

_free

  • _free(ptr: number): void

_malloc

  • _malloc(size: number): number
  • Allocate a block of {@link size} bytes of memory in Emscripten HEAP

    Parameters

    • size: number

      Size of the memory block, in bytes.

    Returns number

    Returns a pointer to the beginning of the block.

createInstWidthEKey

  • createInstWidthEKey(ekey: string, seed: number, mix_key_1: string, mix_key_2: string): StreamCencrypt
  • Creates an instance of StreamCencrypt that can be later used to decrypt file created using this very key.

    Parameters

    • ekey: string

      ekey, extracted from the request or end of the file.

    • seed: number

      seed to generate simple key.

    • mix_key_1: string

      stage 1 key for EncV2 decryption.

    • mix_key_2: string

      stage 2 key for EncV2 decryption.

    Returns StreamCencrypt

    a pointer to the encrypt class.

decryptStream

  • decryptStream(encryptor: StreamCencrypt, buffer: number, offset: number, size: number): void
  • Decrypt

    example
    // Decrypt a block of the file

    // Setup:
    const offset = 10;
    const blockSize = 4096;
    const buf = QMCCrypto._malloc(blockSize);
    const blockData = new Uint8Array(
    inputArrayBuffer.slice(offset, offset + blockSize)
    );
    QMCCrypto.writeArrayToMemory(blockData, buf);

    // Decrypt:
    QMCCrypto.decryptStream(hCrypto, buf, offset, blockSize);

    // Retrive decrypted data:
    const decryptedBlock = QMCCrypto.HEAPU8.slice(buf, buf + blockSize);

    Parameters

    • encryptor: StreamCencrypt

      Encryptor instance created using createInstWidthEKey.

    • buffer: number

      Pointer to buffer allocated using _malloc. Data can be written here using writeArrayToMemory.

    • offset: number

      Offset of the buffer from original file. This parameter is required to derive correct key.

    • size: number

      Size of the provided buffer.

    Returns void

detectKeyEndPosition

  • detectKeyEndPosition(result: number, detectBuf: number, size: number): boolean
  • Detect embedded ekey position using the end-of-file buffer. Recommanded size of detection buffer is 40.

    example
    // Allocate memory for detection buffer in Emscripten HEAP.
    const detectionBuf = new Uint8Array(inputArrayBuffer.slice(-40));
    const pDetectionBuf = QMCCrypto._malloc(detectionBuf.length);
    QMCCrypto.writeArrayToMemory(detectionBuf, pDetectionBuf);

    // Allocate memory for result buffer in Emscripten HEAP.
    const pDetectionResult = QMCCrypto._malloc(QMCCrypto.sizeof_qmc_detection());

    // Perform detection
    const detectOK = QMCCrypto.detectKeyEndPosition(
    pDetectionResult,
    pDetectionBuf,
    detectionBuf.length
    );

    // Extract result
    const ekeyPosition = QMCCrypto.getValue(pDetectionResult, "i32");
    const ekeyLength = QMCCrypto.getValue(pDetectionResult + 4, "i32");
    const errorMessage = QMCCrypto.UTF8ToString(pDetectionResult + 8);
    if (!detectOK) {
    console.error(errorMessage);
    } else {
    // continue with ekey data...
    }

    Parameters

    • result: number

      WASM ptr with size from sizeof_qmc_detection.

    • detectBuf: number

      WASM ptr points to the beginning of the detection buffer.

    • size: number

      size of detection buffer.

    Returns boolean

getValue

  • Gets a value at a specific memory address at run-time. NOTE: it only does aligned write and read.

    Parameters

    • ptr: number

      A pointer (number) representing the memory address.

    • type: WASM_NUMBER

      An LLVM IR type as a string.

    Returns number

    value at a specific address.

offsetof_error_msg

  • offsetof_error_msg(): number

offsetof_song_id

  • offsetof_song_id(): number

sizeof_error_msg

  • sizeof_error_msg(): number

sizeof_qmc_detection

  • sizeof_qmc_detection(): number

sizeof_song_id

  • sizeof_song_id(): number

writeArrayToMemory

  • writeArrayToMemory(data: Uint8Array, bufferPointer: number): void

Generated using TypeDoc