iOS自动化_免越狱_免签名

石臻
2023-12-01

      由于iphone的系统的封闭性和安全性,同时长时间运行的稳定性。所以越来越多的人使用iphone作为自己的随身工具,ios系统作为世界上流行的手机系统,所以很多公司会在iPhone上开发、测试APP,而测试是一个反复繁琐的工作,所以想到自动化完成工作较好,且都需要一个可以同时控制iphone,还可以跑脚本的产品出现,鉴于iphone较强的安全性,也导致了这个产品会比较难。WDA出现了。它WebDriverAgent简称WDA。它是由Facebook推出的一款移动端测试框架。它是在iOS客户端实现了一个WebDriver的Server,借助这个server,我们可以远程控制iOS设备进行测试。它更多的是测试人员进行自动化测试用的

后来阿里巴巴,有在其基础上整合出tidevice框架,就能在windows上轻松控制苹果手机了。

WebDriverAgent下载链接 https://github.com/openatx/facebook-wda
里面有详细的api
下面是一些简单的api
c = wda.Client('http://localhost:8100')
c.status()#获得手机状态
c.home()#回到手机首页
c.locked() # true of false
c.lock() # lock screen
c.unlock() # unlock
c.app_current() # 当前打开的APP
c.session().app_activate("com.apple.Health")#启动对应的APP
s.click(200, 200)#点击坐标(200,200)
s.click(0.5, 0.5) # 点击屏幕中心点
 

但是。开发出来的东西要签名,而且不一定每个手机都支持。后来又出现第三方库iMouse,使用又更简单了。请看:

下面是一些简单的api,是python代码:

api = iMouse_api.HttpApi("127.0.0.1")  #初始化库
api.find_image(手机mac, 图片)   #找图
api.ocr(手机mac, 区域)  #文字识别
api.click(手机mac, x,y)  #点击
api.mouse_movie(手机mac, x,y)  #鼠标移动
api.send_key(手机mac, "", "ENTER") #按下回车键

 api.send_key(手机mac, "dgfasdf23324", "") #发送字符串

api.send_text(手机mac, "发送中文", "CTRL+ALT+SHIFT+WIN+v")
api.send_key(手机mac, '', 'FN+h')     #返回主界面

本人写的薅羊毛DEMO:

# coding:utf-8
# This is a sample Python script.

# Press Shift+F10 to execute it or replace it with your code.
# Press Double Shift to search everywhere for classes, files, tool windows, actions, and settings.
import random
import threading
import time
import re  # 导入包
import iMouse_api

api = iMouse_api.HttpApi("127.0.0.1")


def print_hi(name):
    # Use a breakpoint in the code line below to debug your script.
    print(f'Hi, {name}')  # Press Ctrl+F8 to toggle the breakpoint.


def findimage(deviceID, filename, isClick, offsetX, offsetY, afor=5, confidence=0.8):
    file = open(filename, "rb")
    byte = file.read()
    file.close()
    tmp = False
    for i in range(afor):
        ret = api.find_image(deviceID, byte)
        if ret["status"] == 0 and ret["data"]["code"] == 0 and ret["data"]["confidence"] >= confidence:
            if isClick:
                # api.mouse_movie(deviceID, ret["data"]["result"][0] + offsetX, ret["data"]["result"][1] + offsetY)
                api.click(deviceID, ret["data"]["result"][0] + offsetX, ret["data"]["result"][1] + offsetY, "left")
                time.sleep(0.4)
                api.mouse_movie(deviceID, random.randint(50, 300), random.randint(100, 600))
            else:
                api.mouse_movie(deviceID, ret["data"]["result"][0] + offsetX, ret["data"]["result"][1] + offsetY)
            tmp = True
            break
        else:
            print("find_image", i, filename, ret)
            time.sleep(0.4)
    return tmp


def findocr(deviceID, ocr, txtLst, isClick):
    for item in ocr["data"]["list"]:
        for txtItem in txtLst:
            if txtItem == item["txt"]:
                if isClick:
                    api.click(deviceID, item["result"][0], item["result"][1], "left")
                return True
    return False


def findocr1(deviceID, ocr, txt, isClick):
    ok = False
    for item in ocr["data"]["list"]:
        if item["txt"].find("反馈"):
            ok = True
        if item["txt"].find("跳过") == 0 and (item["txt"].find("s") >= 0 or ok):
            if isClick:
                api.click(deviceID, item["result"][0], item["result"][1], "left")
            return True
    return False


def run(deviceID):
    print(deviceID)
    # api.mouse_movie(deviceID, random.randint(50, 300), random.randint(100, 600))
    # time.sleep(1.5)
    #
    # tmp = findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/主图标.bmp", True, 0, 0)
    # if not tmp:
    #     return
    # findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/继续闯关.bmp", True, 0, 0)
    # 恭喜获得-确认领取

    while True:
        api.mouse_movie(deviceID, random.randint(50, 300), random.randint(100, 600))
        time.sleep(0.4)

        ocr = api.ocr(deviceID, [[6, 7], [6, 885], [412, 7], [412, 885]])
        if ocr["status"] == 0 and ocr["data"]["code"] == 0 and len(ocr["data"]["list"]) > 0:
            try:
                print("恭喜获得-确认领取", ocr["data"]["list"][0]["txt"])
                sStr = str(ocr)
                if sStr.find("恭喜获得") >= 0 and sStr.find("恭喜获得") >= 0:
                    findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/恭喜获得-确认领取.bmp", False, 0, 0, 1)
                elif sStr.find("气泡红包") >= 0 and sStr.find("可提现至微信") >= 0:
                    # findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/气泡红包-领取.bmp", True, 0, 0, 1)
                    findocr(deviceID, ocr, ["领取"], True)
                elif sStr.find("当前分数") >= 0 and sStr.find("继续闯关") >= 0:
                    findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/主界面-红包手.bmp", True, 0, 0, 1)
                elif sStr.find("通关奖励") >= 0 and sStr.find("多倍领取") >= 0:
                    findocr(deviceID, ocr, ["多倍领取"], True)

                findocr(deviceID, ocr, ["残忍离开"], True)
                findocr1(deviceID, ocr, "", True)
            except:
                print('OCR异常')

        tmp = findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/通关-多倍领取.bmp", True, 0, 0, 1)
        if tmp:
            time.sleep(random.randint(1, 3))
        # print("swipe", i)

        findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/通用-关闭.bmp", True, 0, 0, 1)


        tmp = findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/恭喜获得-确认领取.bmp", False, 0, 0, 1)
        if tmp:
            ocr = api.ocr(deviceID, [[126, 299], [126, 348], [308, 299], [308, 348]])
            if ocr["status"] == 0 and ocr["data"]["code"] == 0 and len(ocr["data"]["list"]) > 0:
                print("恭喜获得-确认领取", ocr["data"]["list"][0]["txt"])
            findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/恭喜获得-确认领取.bmp", True, 0, 0, 1)
        # time.sleep(random.randint(1, 3))
        findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/恭喜过关-继续闯关.bmp", True, 0, 0, 1)

        findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/气泡红包-领取.bmp", True, 0, 0, 1)
        findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/通用-关闭2.bmp", True, 0, 0, 1)

        findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/可提现-立即拆开.bmp", True, 0, 0, 1)

        findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/通用-关闭4.bmp", True, 0, 0, 1)
50, -3, 1)
        findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/广告-放弃福利.bmp", True, 0, 0, 1)
        findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/跳过.bmp", True, 0, 0, 1)
        findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/跳过1.bmp", True, 0, 0, 1)
        findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/广告-不感兴趣.bmp", True, 0, 0, 1)
True, 0, 0, 1)
        findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/取消.bmp", True, 0, 0, 1)

        findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/主界面-红包手.bmp", True, 0, 0, 1)
    # 可提现-立即拆开  主界面-红包手

    # 用当前分数来定位,好找下面的广告来点击
    # tmp = findimage(deviceID, "D:/ScreenSrv/ScreenControl/Screenshot/主页-当前分数.bmp", True, -16, 68, 1, 0.9)
    # if tmp:
    #     time.sleep(random.randint(1, 3))
    print("Exit Thread.")


# Press the green button in the gutter to run the script.
if __name__ == '__main__':
    print_hi('PyCharm')

    deviceidLst = []
    deviceidLst.append('88:64:40:06:C6:53')  # 群控多台手机1
    # deviceidLst.append('DC:2B:2A:14:2A:F6')   #群控多台手机2
    # deviceidLst.append('DC:2B:2A:14:2A:F2')   #群控多台手机3
    # deviceidLst.append('DC:2B:2A:14:2A:F3')   #群控多台手机4
    for deviceId in deviceidLst:
        thread1 = threading.Thread(target=run, args=(deviceId,))
        thread1.start()
        time.sleep(1)

    while True:
        cmd = input("请输入:")
        if cmd == "q":
            break

此iMouse库有一个好处就是,苹果手机上面什么APP都不用安装。完全天然、绿色。所以没有所谓的越狱、签名(掉签),iOS进程保活等繁琐的问题。

源代码及视频:

[https://www.bilibili.com/video/BV1kY411m7pM/]

 类似资料: