H5上复刻外挂界经典外挂,齿轮变速齿轮原理分析

来源:优游网责编:网络时间:2024-05-11 15:08:01

在H5上复刻外挂界经典外挂,变速齿轮0.变速齿轮原理分析

使用扫扫描工具扫描被变速齿轮变速的程序发现变速齿轮hook掉了系统提供的时间函数

简单的反编译代码+简单的理解

hook系统提供的时间函数,返回修改后的时间

1.分析游戏引擎时间计算方法

通过 new Date().() 或 Date.now()来获取当前本地时间

或.now()来获取程序运行时间

2.思路分析

方法一:hook Date的、now和的now方法返回倍率的时间

方法二:返回增量倍率的时间

注意方法一直接返回倍率的时间,会造成时间戳过大,在需要大致正确的时间戳的地方会出错

3.代码实现

/*
 * 变速齿轮.js
 * Created by 还有醋v on 2021/7/18.
 * Copyright © 2021 haiyoucuv. All rights reserved.
 */
// 写个配置,方便修改
const __pxConfig = {
   px: 4,
   date_last_t: Date.now(),        // Date上一次的真实值
   date_last_c: Date.now(),        // Date上一次的计算值
   p_last_t: performance.now(),    // performance上一次的真实值
   p_last_c: performance.now(),    // performance上一次的计算值
};
/**
 * 计算方法
 * 当前时间 = 上一次计算时间 + (当前真实时间 - 上一次真实时间) * 当前倍率
 */
// es5写法
window.Date._now = Date.now;
window.Date.prototype._getTime = window.Date.prototype.getTime;
window.Date.prototype.getTime = function () {
   const { date_last_c, date_last_t, px } = __pxConfig;
   const t = __pxConfig.date_last_t = this._getTime();
   return date_last_c + (t - date_last_t) * px;
};
// 重写performance
window.performance._now = window.performance.now;
window.performance.now = function () {
   const { p_last_c, p_last_t, px } = __pxConfig;
   const t = window.performance._now();
   return p_last_c + (t - p_last_t) * px;
}

以下使用es6写法更清晰

// es6写法
window.Date = class Date extends window.Date {
   getTime() {
      const { date_last_c, date_last_t, px } = __pxConfig;
      const t = __pxConfig.date_last_t = super.getTime();
      return __pxConfig.date_last_c = date_last_c + (t - date_last_t) * px;
   };
   static now() {
      return super.now() * __pxConfig.px;
   }
}

4.测试

打开 ://dino/看到我们的小恐龙

在控制台中输入以上代码游戏变速器,现在是4倍速再次输入.px = 1;改为正常速度

输入.px = 100;改为改成100倍速度

猜你喜欢
最新游戏更多
热门专题更多
最新资讯更多