从控制台访问 em-dosbox 内存

Access em-dosbox memory from console

there's DosBox(一个 Dos 模拟器)的这个 emscripten 端口允许 运行 浏览器中的旧 DOS 软件。现在我想要实现的是创建某种内存扫描器,允许在 dosbox 中调整一些内存值。我查看了 Google Chrome 配置文件选项卡,它显示 DosBox 创建了一个看起来像整个程序内存的大型 UInt 数组,但我不知道如何访问它。

有什么想法吗?提前致谢!

Emscripten 的默认设置在页面的全局范围内放置一个 Module 对象,其中包含用作程序内存的数组缓冲区的各种视图。例如,

Module.HEAPU8

Uint8Array 视图。查看使用 Emscripten 的 https://archive.org/details/msdos_Prince_of_Persia_1990 的控制台,完整列表为:

Module.HEAP16
Module.HEAP32
Module.HEAPF32
Module.HEAPF64
Module.HEAPU8
Module.HEAPU16
Module.HEAPU32

仅供参考,这是我用过的扫描码

class MemoryScanner {
  constructor(target) {
    this.set = new Set();
    this.target = target;
  }

  search(value) {
    let target = this.target, length = target.length, set = this.set;
    for (let i = 0; i < length; i++) {
      if (target[i] === value) {
        set.add(i);
      }
    }
  }

  search2(value1, value2) {
    let target = this.target, length = target.length, set = this.set;
    for (let i = 0; i < length; i++) {
      if (target[i] === value1 && target[i + 1] === value2) {
        set.add(i);
      }
    }
  }

  search4(value1, value2, value3, value4) {
    let target = this.target, length = target.length, set = this.set;
    for (let i = 0; i < length; i++) {
      if (target[i + 0] === value1 &&
          target[i + 1] === value2 &&
          target[i + 2] === value3 &&
          target[i + 3] === value4) {
        set.add(i);
      }
    }
  }

  search8(value1, value2, value3, value4, value5, value6, value7, value8) {
    let target = this.target, length = target.length, set = this.set;
    for (let i = 0; i < length; i++) {
      if (target[i + 0] === value1 &&
          target[i + 1] === value2 &&
          target[i + 2] === value3 &&
          target[i + 3] === value4 &&
          target[i + 4] === value5 &&
          target[i + 5] === value6 &&
          target[i + 6] === value7 &&
          target[i + 7] === value8) {
        set.add(i);
      }
    }
  }

  intersect(value) {
    let target = this.target, length = target.length, set = this.set;

    for (let index of this.set) {
      if (target[index] !== value) {
        set.delete(index)
      }
    }
  }

  intersect2(value1, value2) {
    let target = this.target, length = target.length, set = this.set;

    for (let index of this.set) {
      if (target[index] !== value1 || target[index + 1] !== value2) {
        set.delete(index)
      }
    }
  }

  intersect4(value1, value2, value3, value4) {
    let target = this.target, length = target.length, set = this.set;

    for (let index of this.set) {
      if (target[index + 0] !== value1 ||
          target[index + 1] !== value2 ||
          target[index + 2] !== value3 ||
          target[index + 3] !== value4) {
        set.delete(index)
      }
    }
  }

  intersect8(value1, value2, value3, value4, value5, value6, value7, value8) {
    let target = this.target, length = target.length, set = this.set;

    for (let index of this.set) {
      if (target[index + 0] !== value1 ||
          target[index + 1] !== value2 ||
          target[index + 2] !== value3 ||
          target[index + 3] !== value4 ||
          target[index + 4] !== value5 ||
          target[index + 5] !== value6 ||
          target[index + 6] !== value7 ||
          target[index + 7] !== value8) {
        set.delete(index)
      }
    }
  }
}