查看: 907|回覆: 0

羊了個羊MatchPlayInfo序列化分析

[複製連結]
羊了個羊MatchPlayInfo序列化分析
2022-9-21 22:29:53 1樓
0 907

7771

主題

112

回覆

3891

積分

Lv.70 熾天使

積分
3891
藍鑽
7852
GP
12424

中秋紀念勳章FB破千人紀念章開站元老性別認證我一直在線上創站註冊滿萬人紀念章論壇註冊破兩萬人紀念章夢遊FB臉書紀念章FACEBOOK粉絲紀念2026 萬聖節勳章

發表於 2022-9-21 22:29:53 | 顯示全部樓層 |閱讀模式
通過分析原始碼可以得到以下MatchPlayInfo序列的生成程式碼
  1. const protobuf = require("protobufjs");
  2. var i = protobuf.Reader, a = protobuf.Writer, r = protobuf.util;
  3. MatchStepInfo = function () {
  4.     function t(t) {
  5.         if (t)
  6.             for (var e = Object.keys(t), o = 0; o < e.length; ++o) null != t[e[o]] &&
  7.                 (this[e[o]] = t[e[o]])
  8.     }
  9.     return t.prototype.chessIndex = 0, t.prototype.timeTag = 0, t.create = function (
  10.         e) {
  11.         return new t(e)
  12.     }, t.encode = function (t, e) {
  13.         return e || (e = a.create()), null != t.chessIndex && Object.hasOwnProperty
  14.             .call(t, "chessIndex") && e.uint32(8).int32(t.chessIndex), null !=
  15.             t.timeTag && Object.hasOwnProperty.call(t, "timeTag") && e.uint32(
  16.                 16).int32(t.timeTag), e
  17.     }, t.decode = function (t, e) {
  18.         t instanceof i || (t = i.create(t));
  19.         for (var o = void 0 === e ? t.len : t.pos + e, n = new MatchStepInfo; t
  20.             .pos < o;) {
  21.             var a = t.uint32();
  22.             switch (a >>> 3) {
  23.                 case 1:
  24.                     n.chessIndex = t.int32();
  25.                     break;
  26.                 case 2:
  27.                     n.timeTag = t.int32();
  28.                     break;
  29.                 default:
  30.                     t.skipType(7 & a)
  31.             }
  32.         }
  33.         return n
  34.     }, t
  35. }(), MatchPlayInfo = function () {
  36.     function t(t) {
  37.         if (this.stepInfoList = [], t)
  38.             for (var e = Object.keys(t), o = 0; o < e.length; ++o) null != t[e[o]] &&
  39.                 (this[e[o]] = t[e[o]])
  40.     }
  41.     return t.prototype.gameType = 0, t.prototype.mapId = 0, t.prototype.mapSeed = 0,
  42.         t.prototype.stepInfoList = r.emptyArray, t.create = function (e) {
  43.             return new t(e)
  44.         }, t.encode = function (t, e) {
  45.             if (e || (e = a.create()), null != t.gameType && Object.hasOwnProperty.call(
  46.                 t, "gameType") && e.uint32(8).int32(t.gameType), null != t.mapId &&
  47.                 Object.hasOwnProperty.call(t, "mapId") && e.uint32(16).int32(t.mapId),
  48.                 null != t.mapSeed && Object.hasOwnProperty.call(t, "mapSeed") && e.uint32(
  49.                     24).int32(t.mapSeed), null != t.stepInfoList && t.stepInfoList.length
  50.             )
  51.                 for (var o = 0; o < t.stepInfoList.length; ++o) MatchStepInfo
  52.                     .encode(t.stepInfoList[o], e.uint32(34).fork()).ldelim();
  53.             return e
  54.         }, t.decode = function (t, e) {
  55.             t instanceof i || (t = i.create(t));
  56.             for (var o = void 0 === e ? t.len : t.pos + e, n = new MatchPlayInfo; t
  57.                 .pos < o;) {
  58.                 var a = t.uint32();
  59.                 switch (a >>> 3) {
  60.                     case 1:
  61.                         n.gameType = t.int32();
  62.                         break;
  63.                     case 2:
  64.                         n.mapId = t.int32();
  65.                         break;
  66.                     case 3:
  67.                         n.mapSeed = t.int32();
  68.                         break;
  69.                     case 4:
  70.                         n.stepInfoList && n.stepInfoList.length || (n.stepInfoList = []),
  71.                             n.stepInfoList.push(MatchStepInfo.decode(t,
  72.                                 t.uint32()));
  73.                         break;
  74.                     default:
  75.                         t.skipType(7 & a)
  76.                 }
  77.             }
  78.             return n
  79.         }, t
  80. }()
  81. var operationList = []
  82. function addOp(t, e) { //增加操作
  83.     void 0 === e && (e = -100);
  84.     var o = {
  85.         id: t, // 操作卡片的id,從levelData第一層開始按順序編號
  86.         time: Date.now() // 操作時間
  87.     };
  88.     operationList.push(o)
  89. }
  90. function sleep(delay) {
  91.     for (var t = Date.now(); Date.now() - t <= delay;);
  92. }
  93. let range = n => [...Array(n).keys()]
  94. for (let i of range(50)) { // 生成了50次操作
  95.     addOp(i);
  96.     sleep(Math.random() * 10); // 模擬操作過程中的等待
  97. }
  98. console.log(operationList)
  99. for (var u = operationList, p = [], d = 0, h = 0; h < u.length; h++) // 把時間戳轉換為兩次操作的間隔
  100.     p.push({ chessIndex: u[h].id, timeTag: 0 == d ? 0 : u[h].time - d }), d = u[h].time;
  101. console.log(p)
  102. GAMEDAILY = 3
  103. GAMETOPIC = 4
  104. for (var f = { gameType: GAMEDAILY, stepInfoList: p }, y = MatchPlayInfo.create(f), v = MatchPlayInfo.encode(y).finish(), b = "", _ = 0; _ < v.length; _++)
  105.     b += String.fromCharCode(v[_]); // 序列化
  106. var data = Buffer.from(b).toString('base64');
  107. console.log(data);
  108. data = Buffer.from(data, 'base64');
  109. console.log(data);
  110. console.log(MatchPlayInfo.decode(data));
複製代碼
分析一下MatchPlayInfo的生成操作
首先可以得知MatchPlayInfo是由stepInfoList和gameType組成的,stepInfoList裡有兩個參數分別是chessIndex和timeTag,分別記錄點選卡片id和兩次操作間隔
觀察MatchPlayInfo.encode可以看到
  1. e = a.create()
複製代碼
會建立一個protobuf.Writer對象
  1. e.uint32(8).int32(t.gameType)
複製代碼
會建立序列"\x08\x03",雖然寫著是32但是經過偵錯發現是1位元組的,不知道是為什麼
  1. MatchStepInfo.encode(t.stepInfoList[o], e.uint32(34).fork()).ldelim()
複製代碼
這裡首先插入1位元組34變成"\x08\x03\x22",接著fork函數會生成一個分叉,類似於git等待處理完這個分支後呼叫ldelim就會把當前分支上內容的長度和內容合併回主分支,分析MatchStepInfo.encode後可以得知會插入4個位元組,分別是[8,chessIndex,16,timeTag],此時序列就是"\x08\x03\x22"+"\x04"+"\x08\x00\x10\x00"="\x08\x03\x22\x04\x08\x00\x10\x00",重複這個過程把stepInfoList裡的chessIndex和timeTag循環增加到序列,可以得知生成過程是MatchPlayInfo="\x08\x03“+("\x04\x08\x??\x10\x??"*卡牌個數)

4bW4ULj.jpg

然而生成的序列無法增加通關次數,研究了一下發現stepInfoList裡的值大於127的數值是錯誤的,不知道是什麼原因,於是過濾掉大於127的數可以成功增加通關次數
python程式碼如下
本段內容需要解鎖
回覆主題後可查看,或 進入解除隱藏文流程。
藍鑽活動 完成解除隱藏可獲得 2 藍鑽,每 30 分鐘最多一次、每日最多 5 次;可用於參加抽獎。
發文隨機獎勵事件感謝你讓這個社群更有溫度!這次未能中獎,但每一份善意的回覆,都是值得珍惜的禮物!
活動說明

網友還看了什麼

本板近期熱門文章
回覆

使用道具 舉報

回覆

0
您需要登入後纔可以回覆 登入 | 加入會員

本版積分規則

Powered by Discuz! X5.0 © 2001-2026 Discuz! Team.

在本版發文
返回頂部