class L06 {
  private module_name_winmine = "winmine.exe";
  private module_winmine: Module;
  private offset地雷数量: number = 0x56a4;
  private offset棋盘高度: number = 0x56a8;
  private offset棋盘宽度: number = 0x56ac;
  private height: number = 0;
  private width: number = 0;
  private mine_count: number = 0;
  private head: NativePointer = ptr(0);

  constructor() {
    console.log(
      "======================",
      new Date().toISOString(),
      "=========================="
    );
    console.log("Frida.version", Frida.version);
    //获取模块基址
    this.module_winmine = Process.getModuleByName(this.module_name_winmine);

    // 初始化游戏相关数据
    this.height = this.module_winmine.base.add(this.offset棋盘高度).readU32();
    this.width = this.module_winmine.base.add(this.offset棋盘宽度).readU32();
    this.mine_count = this.module_winmine.base.add(this.offset地雷数量).readU32();
    this.head = this.module_winmine.base.add(0x5340);
  }

  run() {
    //遍历棋盘，按行遍历
    for (let i = 0; i < this.height + 2; i++) {
      //按列遍历
      let data = [];
      for (let j = 0; j < this.width + 2; j++) {
        let byte_data = this.head.add(j + 0x20 * i).readU8();
        data.push(byte_data.toString(16).padStart(2, "0"));

        // 如果是地雷，将其状态改为标记
        if  (byte_data == 0x8F) {
          this.head.add(j + 0x20 * i).writeU8(0x8E);
        }
      }
      console.log(data.join(" "));
    }
  }
}

let l06 = new L06();
l06.run();
