cr4n5/XiaoYuanKouSuan

方案三可用 抓包替换js的一些正则,可实现0.001秒,取消匹配动画,全自动答题

Opened this issue · 3 comments

项目里有写好导出的rules文件(.farx格式): xiaoyuankousuan-fiddler-autojs

  • 抓包正则匹配到PK页面的js文件的请求
 ^https:\/\/leo\.fbcontent\.cn\/bh5\/leo-web-oral-pk\/exercise_.*\.js$
  • 使用正则替换请求响应体中的js内容,正则忽略了函数名,所以不受js文件函数名变化影响,不容易失效
//取消匹配动画、readyGo动画:
     case 0:if(.{0,14})\.challengeCode(.{200,300})([a-zA-Z]{1,2})\("startExercise"\); 正则替换为 case 0:$3("startExercise");if$1.challengeCode$2
    "readyGoEnd"\)\}\),.{1,4}\)\}\),.{1,4}\)\}\),.{1,4}\)\}\) 正则替换为 "readyGoEnd")}),20)}),20)}),20)})

//好友挑战PK修改时间为0.001:
     correctCnt:(.{1,5}),costTime:(.{1,15}),updatedTime:(.{1,120})([a-zA-Z]{1,2})\.challengeCode  正则替换为  correctCnt:$1,costTime:$4.challengeCode?1:$2,updatedTime:$3$4.challengeCode

//所有PK场次修改时间为0.001
     correctCnt:(.{1,5}),costTime:(.{1,15}),updatedTime:(.{1,120})([a-zA-Z]{1,2})\.challengeCode   正则替换为  correctCnt:$1,costTime:1,updatedTime:$3$4.challengeCode    

//判断任何答案正确:
     return .{3,5}\)\?1:0\}, 正则替换为 return 1},

//自动触发答题:
     =function\(([a-zA-Z]{1,2}),([a-zA-Z]{1,2})\)\{([a-zA-Z]{1,2})&&\(([a-zA-Z]{1,2})\.value= 正则替换为 =function($1,$2){$2({ recognizeResult: "", pathPoints: [[]], answer: 1, showReductionFraction: 0 });$3&&($4.value=

//直接判断所有答题完成:
     \.value\+1>=[a-zA-Z]{1,2}\.value\.length\?([a-zA-Z]{1,2})\("finishExercise"\) 正则替换为 .value+1>=0?$1("finishExercise")
  • 注意修改后需要清除app缓存才生效

fiddler_20241015181548

谢谢提供思路!

def handle_target_response(self, flow, url):
    print(f"匹配到指定的 URL: {url}")
    responsetext = flow.response.text
    self.update_response_text(flow, responsetext)

def update_response_text(self, flow, responsetext):
    # 1. 取消PK准备动画
    text = re.sub(r'"readyGoEnd"\)\}\),.{1,4}\)\}\),.{1,4}\)\}\),.{1,4}\)\}\)',
                  r'"readyGoEnd")}),20)}),20)}),20)})', responsetext)

    # 2. case 0 替换
    text = re.sub(r'case 0:if(.{0,14})\.challengeCode(.{200,300})([a-zA-Z]{1,2})\("startExercise"\);',
                  r'case 0:\3("startExercise");if\1.challengeCode\2', text)

    # 3. 判断任何答案正确
    text = re.sub(r'return .{3,5}\)\?1:0\},', r'return 1},', text)

    # 4. 自动触发答题
    text = re.sub(r'=function\(([a-zA-Z]{1,2}),([a-zA-Z]{1,2})\)\{([a-zA-Z]{1,2})&&\(([a-zA-Z]{1,2})\.value=',
                  r"=function(\1,\2){\2({ recognizeResult: '', pathPoints: [[]], answer: 1, showReductionFraction: 0 });\3&&(\4.value=",
                  text)

    # 5. 直接判断所有答题完成
    text = re.sub(r'\.value\+1>=[a-zA-Z]{1,2}\.value\.length\?([a-zA-Z]{1,2})\("finishExercise"\)',
                  r'.value+1>=0?\1("finishExercise")', text)

    # 6. 好友挑战PK修改时间为0.001
    text = re.sub(r"correctCnt:(.{1,5}),costTime:(.{1,15}),updatedTime:(.{1,120})([a-zA-Z]{1,2})\.challengeCode",
                  r"correctCnt:\1,costTime:\4.challengeCode?1:\2,updatedTime:\3\4.challengeCode", text)

    # 7. 所有PK场次修改时间为0.001
    text = re.sub(r"correctCnt:(.{1,5}),costTime:(.{1,15}),updatedTime:(.{1,120})([a-zA-Z]{1,2})\.challengeCode",
                   r"correctCnt:\1,costTime:1,updatedTime:\3\4.challengeCode", text)

    flow.response.text = text
    print(f"替换后的响应: {text}")
    threading.Thread(target=self.show_message_box, args=("过滤成功", f"替换成功!")).start()
def handle_target_response(self, flow, url):
    print(f"匹配到指定的 URL: {url}")
    responsetext = flow.response.text
    self.update_response_text(flow, responsetext)

def update_response_text(self, flow, responsetext):
    # 1. 取消PK准备动画
    text = re.sub(r'"readyGoEnd"\)\}\),.{1,4}\)\}\),.{1,4}\)\}\),.{1,4}\)\}\)',
                  r'"readyGoEnd")}),20)}),20)}),20)})', responsetext)

    # 2. case 0 替换
    text = re.sub(r'case 0:if(.{0,14})\.challengeCode(.{200,300})([a-zA-Z]{1,2})\("startExercise"\);',
                  r'case 0:\3("startExercise");if\1.challengeCode\2', text)

    # 3. 判断任何答案正确
    text = re.sub(r'return .{3,5}\)\?1:0\},', r'return 1},', text)

    # 4. 自动触发答题
    text = re.sub(r'=function\(([a-zA-Z]{1,2}),([a-zA-Z]{1,2})\)\{([a-zA-Z]{1,2})&&\(([a-zA-Z]{1,2})\.value=',
                  r"=function(\1,\2){\2({ recognizeResult: '', pathPoints: [[]], answer: 1, showReductionFraction: 0 });\3&&(\4.value=",
                  text)

    # 5. 直接判断所有答题完成
    text = re.sub(r'\.value\+1>=[a-zA-Z]{1,2}\.value\.length\?([a-zA-Z]{1,2})\("finishExercise"\)',
                  r'.value+1>=0?\1("finishExercise")', text)

    # 6. 好友挑战PK修改时间为0.001
    text = re.sub(r"correctCnt:(.{1,5}),costTime:(.{1,15}),updatedTime:(.{1,120})([a-zA-Z]{1,2})\.challengeCode",
                  r"correctCnt:\1,costTime:\4.challengeCode?1:\2,updatedTime:\3\4.challengeCode", text)

    # 7. 所有PK场次修改时间为0.001
    text = re.sub(r"correctCnt:(.{1,5}),costTime:(.{1,15}),updatedTime:(.{1,120})([a-zA-Z]{1,2})\.challengeCode",
                   r"correctCnt:\1,costTime:1,updatedTime:\3\4.challengeCode", text)

    flow.response.text = text
    print(f"替换后的响应: {text}")
    threading.Thread(target=self.show_message_box, args=("过滤成功", f"替换成功!")).start()

已参考修改,修改后的代码
请点击这里