diff --git a/.gitignore b/.gitignore index ee58457..9533f04 100644 --- a/.gitignore +++ b/.gitignore @@ -1,5 +1,6 @@ __pycache__/ +.DS_Store log/ main.build/ main.exe -main.cmd \ No newline at end of file +main.cmd diff --git a/DeveloperDiskImage/12.5/DeveloperDiskImage.dmg b/DeveloperDiskImage/12.5/DeveloperDiskImage.dmg new file mode 100644 index 0000000..0fb8af3 Binary files /dev/null and b/DeveloperDiskImage/12.5/DeveloperDiskImage.dmg differ diff --git a/DeveloperDiskImage/12.5/DeveloperDiskImage.dmg.signature b/DeveloperDiskImage/12.5/DeveloperDiskImage.dmg.signature new file mode 100644 index 0000000..7e5d2a5 Binary files /dev/null and b/DeveloperDiskImage/12.5/DeveloperDiskImage.dmg.signature differ diff --git a/README.md b/README.md index eb96ec7..9d86102 100644 --- a/README.md +++ b/README.md @@ -57,7 +57,7 @@ iOSRealRun-cli > 打开[路径拾取网站](https://fakerun.myth.cx/)。通过点击地图构造路径。点击时无需考虑间距,会自动用直线连接。路径点击完成后,单击上方的路径坐标——复制,将坐标数据复制到剪贴板 5. 打开脚本目录里的 `route.txt` 文件,将刚复制的内容原封不动的粘贴进去,保存并退出 6. 对于 Windows,你需要安装 iTunes,以确保驱动正常运行 - 7. 在脚本目录中的 `config.yaml` 文件中设置 `v` 变量以设置速度(m/s),给个参考,3.3大概是5分到5分半的配速(我也没仔细看) + 7. 在脚本目录中的 `config.yaml` 文件中设置 `v` 变量以设置速度(m/s),给个参考,3.3大概是5分到5分半的配速(我也没仔细看);设置 `distance` 变量以设置目标距离(m),脚本会在此基础上额外多跑约 200 m 后自动停止并恢复正常定位,设置为 0 或不设置则默认无限循环 8. Mac用户和Windows用户可能需要打开iTunes,**且在跑完前不应关闭** 9. 如果你是Mac用户且发现无法使用,请继续看这一条 由于MacOS新版系统的原因,无法直接打开下载的脚本,所以要进行一些操作赋予执行权限并通过“无法验证开发者”。 diff --git a/config.yaml b/config.yaml index 8dae34a..b226c46 100644 --- a/config.yaml +++ b/config.yaml @@ -1,4 +1,5 @@ -v: 3.3 -routeConfig: "HNroute.txt" +v: 4.0 +distance: 3000 +routeConfig: "ZJGroute.txt" libimobiledeviceDir: "libimobiledevice" imageDir: "DeveloperDiskImage" diff --git a/libimobiledevice/darwin/idevicedevmodectl b/libimobiledevice/darwin/idevicedevmodectl old mode 100644 new mode 100755 diff --git a/libimobiledevice/darwin/ideviceimagemounter b/libimobiledevice/darwin/ideviceimagemounter old mode 100644 new mode 100755 diff --git a/libimobiledevice/darwin/ideviceinfo b/libimobiledevice/darwin/ideviceinfo old mode 100644 new mode 100755 diff --git a/libimobiledevice/darwin/idevicepair b/libimobiledevice/darwin/idevicepair old mode 100644 new mode 100755 diff --git a/libimobiledevice/darwin/idevicesetlocation b/libimobiledevice/darwin/idevicesetlocation old mode 100644 new mode 100755 diff --git a/libimobiledevice/darwin/libimobiledevice-1.0.6.dylib b/libimobiledevice/darwin/libimobiledevice-1.0.6.dylib old mode 100644 new mode 100755 diff --git a/libimobiledevice/darwin/libimobiledevice-glue-1.0.0.dylib b/libimobiledevice/darwin/libimobiledevice-glue-1.0.0.dylib old mode 100644 new mode 100755 diff --git a/libimobiledevice/darwin/libplist-2.0.3.dylib b/libimobiledevice/darwin/libplist-2.0.3.dylib old mode 100644 new mode 100755 diff --git a/libimobiledevice/darwin/libusbmuxd-2.0.6.dylib b/libimobiledevice/darwin/libusbmuxd-2.0.6.dylib old mode 100644 new mode 100755 diff --git a/libimobiledevice/win/idevicedevmodectl.exe b/libimobiledevice/win/idevicedevmodectl.exe old mode 100644 new mode 100755 diff --git a/libimobiledevice/win/ideviceimagemounter.exe b/libimobiledevice/win/ideviceimagemounter.exe old mode 100644 new mode 100755 diff --git a/libimobiledevice/win/ideviceinfo.exe b/libimobiledevice/win/ideviceinfo.exe old mode 100644 new mode 100755 diff --git a/libimobiledevice/win/idevicepair.exe b/libimobiledevice/win/idevicepair.exe old mode 100644 new mode 100755 diff --git a/libimobiledevice/win/idevicesetlocation.exe b/libimobiledevice/win/idevicesetlocation.exe old mode 100644 new mode 100755 diff --git a/libimobiledevice/win/libcrypto-3-x64.dll b/libimobiledevice/win/libcrypto-3-x64.dll old mode 100644 new mode 100755 diff --git a/libimobiledevice/win/libimobiledevice-1.0.dll b/libimobiledevice/win/libimobiledevice-1.0.dll old mode 100644 new mode 100755 diff --git a/libimobiledevice/win/libimobiledevice-glue-1.0.dll b/libimobiledevice/win/libimobiledevice-glue-1.0.dll old mode 100644 new mode 100755 diff --git a/libimobiledevice/win/libplist++-2.0.dll b/libimobiledevice/win/libplist++-2.0.dll old mode 100644 new mode 100755 diff --git a/libimobiledevice/win/libplist-2.0.dll b/libimobiledevice/win/libplist-2.0.dll old mode 100644 new mode 100755 diff --git a/libimobiledevice/win/libssl-3-x64.dll b/libimobiledevice/win/libssl-3-x64.dll old mode 100644 new mode 100755 diff --git a/libimobiledevice/win/libusbmuxd-2.0.dll b/libimobiledevice/win/libusbmuxd-2.0.dll old mode 100644 new mode 100755 diff --git a/main.command b/main.command old mode 100644 new mode 100755 diff --git a/main.py b/main.py index 49c03f2..f9a15fe 100644 --- a/main.py +++ b/main.py @@ -9,43 +9,55 @@ import tools.utils as utils import tools.run as run from tools.initialize import connect, init -from tools.config import config - -if not os.path.exists("./log"): - os.mkdir("./log") -sys.stderr=open("./log/error.log", "w") # redirect error message - - -OS = utils.getOS() # get the OS, possible values: win, darwin, linux -# path separators for different systems -seperator = {"win": "\\", "darwin": "/", "linux": "/"} # path seperator -seperator = seperator[OS] -libimobiledeviceDir = config.libimobiledeviceDir + seperator + OS # path to libimobiledevice -v = config.v # simulate speed, unit: m/s -# environment variables -env = { # environment variables for library - "win": None, - "darwin": {"DYLD_LIBRARY_PATH": os.getcwd() + "/" + libimobiledeviceDir}, - "linux": {"LD_LIBRARY_PATH": os.getcwd() + "/" + libimobiledeviceDir} -} - -# connect to the device and mount DevelopDiskImage -connect() - -loc = init() # get the route -print("路线信息读取成功") - - -if OS == "win": - utils.setDisplayRequired() -print("已开始模拟跑步, 速度大约为 {} m/s".format(str(v))) -print("会无限绕圈,要停可以按Ctrl+C") -print("请勿直接关闭窗口,否则无法还原正常定位") - -try: - run.run(loc, v) -finally: - utils.resetLoc() # reset the location - if OS == "win": - utils.resetDisplayRequired() - print("现在你可以关闭当前窗口或终端了") +from tools import runtime + + +def main(): + if not os.path.exists("./log"): + os.mkdir("./log") + sys.stderr = open("./log/error.log", "w") # redirect error message + + running = False + display_required = False + try: + # connect to the device and mount DevelopDiskImage + connect() + + loc = init() # get the route + print("路线信息读取成功") + + if runtime.OS == "win": + utils.setDisplayRequired() + display_required = True + print("已开始模拟跑步, 速度大约为 {} m/s".format(str(runtime.v))) + print("会无限绕圈,要停可以按Ctrl+C") + print("请勿直接关闭窗口,否则无法还原正常定位") + + running = True + run.run(loc, runtime.v) + except KeyboardInterrupt: + print("已停止模拟跑步") + except Exception as exc: + import traceback + + print("程序遇到错误:{}".format(exc)) + print("详细错误已写入 log/error.log") + traceback.print_exc() + return 1 + finally: + if running: + try: + utils.resetLoc() # reset the location + except Exception as exc: + import traceback + + print("恢复正常定位失败:{}".format(exc)) + traceback.print_exc() + if display_required: + utils.resetDisplayRequired() + print("现在你可以关闭当前窗口或终端了") + return 0 + + +if __name__ == "__main__": + sys.exit(main()) diff --git a/requirements.txt b/requirements.txt index 4133b0e..be2b74d 100644 --- a/requirements.txt +++ b/requirements.txt @@ -1,2 +1 @@ -geopy==2.4.1 PyYAML==6.0.1 diff --git a/tools/initialize.py b/tools/initialize.py index 72c1ada..fafb3e2 100644 --- a/tools/initialize.py +++ b/tools/initialize.py @@ -1,17 +1,16 @@ import tools.utils as utils +from tools import runtime # connect to the device and mount DevelopDiskImage def connect() -> int: import os import sys - from main import seperator - from main import OS from tools.config import config - if OS != "win": + if runtime.OS != "win": os.system("chmod -R +rx " + config.libimobiledeviceDir) - if OS == "linux": + if runtime.OS == "linux": path = os.environ["PATH"].split(":") check = False for i in path: @@ -65,8 +64,8 @@ def connect() -> int: imageCMD = [ "ideviceimagemounter", - "{}{}{}{}DeveloperDiskImage.dmg".format(config.imageDir, seperator, version, seperator), - "{}{}{}{}DeveloperDiskImage.dmg.signature".format(config.imageDir, seperator, version, seperator), + "{}{}{}{}DeveloperDiskImage.dmg".format(config.imageDir, runtime.separator, version, runtime.separator), + "{}{}{}{}DeveloperDiskImage.dmg.signature".format(config.imageDir, runtime.separator, version, runtime.separator), ] if -1 != utils.cmd(imageCMD).find("-3"): print("开发者镜像签名验证失败,你要重新下一遍") diff --git a/tools/run.py b/tools/run.py index a9f8c59..45d678a 100644 --- a/tools/run.py +++ b/tools/run.py @@ -52,8 +52,16 @@ def transform_lon(x, y): # get the ditance according to the latitude and longitude def geodistance(p1, p2): - from geopy.distance import geodesic - return geodesic((p1["lat"],p1["lng"]),(p2["lat"],p2["lng"])).m + import math + + radius = 6371008.8 + lat1 = math.radians(p1["lat"]) + lat2 = math.radians(p2["lat"]) + d_lat = lat2 - lat1 + d_lng = math.radians(p2["lng"] - p1["lng"]) + + a = math.sin(d_lat / 2) ** 2 + math.cos(lat1) * math.cos(lat2) * math.sin(d_lng / 2) ** 2 + return 2 * radius * math.asin(min(1, math.sqrt(a))) def smooth(start, end, i): import math @@ -128,6 +136,12 @@ def fixLockT(loc: list, v, dt): t += dt return fixedLoc +def pathDistance(loc: list): + distance = 0 + for i in range(len(loc)): + distance += geodistance(loc[i], loc[(i+1)%len(loc)]) + return distance + def run1(loc: list, v, dt=0.2): import time import tools.utils as utils @@ -136,18 +150,40 @@ def run1(loc: list, v, dt=0.2): nList = (5, 6, 7, 8, 9) n = nList[random.randint(0, len(nList)-1)] fixedLoc = randLoc(fixedLoc, n=n) # a path will be divided into n parts for random route + distance = pathDistance(fixedLoc) clock = time.time() for i in fixedLoc: utils.setLoc(bd09Towgs84(i)) while time.time()-clock < dt: pass clock = time.time() + return distance + +def getDistanceLimit(extraDistance=200): + from tools.config import config + distance = getattr(config, "distance", None) + if distance is None: + return None + distance = float(distance) + if distance <= 0: + return None + return distance + extraDistance def run(loc: list, v, d=15): import random import time random.seed(time.time()) + distanceLimit = getDistanceLimit() + distance = 0 + if distanceLimit: + print("设置跑步距离为 {} m,将额外多跑约 200 m 后自动停止".format(str(distanceLimit-200))) while True: vRand = 1000/(1000/v-(2*random.random()-1)*d) - run1(loc, vRand) - print("跑完一圈了") \ No newline at end of file + distance += run1(loc, vRand) + if distanceLimit: + print("跑完一圈了,累计约 {:.1f} m".format(distance)) + if distance >= distanceLimit: + print("已达到设置距离,将恢复正常定位并结束") + return + else: + print("跑完一圈了") diff --git a/tools/runtime.py b/tools/runtime.py new file mode 100644 index 0000000..c576891 --- /dev/null +++ b/tools/runtime.py @@ -0,0 +1,38 @@ +""" +Shared runtime configuration for command helpers. +""" + +import os +import sys + +from tools.config import config + + +def get_os(): + platform = sys.platform + if -1 != platform.find("win32"): + return "win" + if -1 != platform.find("darwin"): + return "darwin" + return "linux" + + +OS = get_os() +separator = {"win": "\\", "darwin": "/", "linux": "/"}[OS] +seperator = separator # Backward-compatible spelling used elsewhere. +libimobiledevice_dir = config.libimobiledeviceDir + separator + OS +libimobiledeviceDir = libimobiledevice_dir +v = config.v + + +def _library_env(variable_name): + result = os.environ.copy() + result[variable_name] = os.getcwd() + "/" + libimobiledevice_dir + return result + + +env = { + "win": None, + "darwin": _library_env("DYLD_LIBRARY_PATH"), + "linux": _library_env("LD_LIBRARY_PATH"), +} diff --git a/tools/utils.py b/tools/utils.py index f073cf6..9fc76c8 100644 --- a/tools/utils.py +++ b/tools/utils.py @@ -4,19 +4,20 @@ # execute a command and return the output def cmd(i_cmd, getoutp=True, libimobiledevice=True): - from main import seperator - from main import libimobiledeviceDir - from main import OS, env import subprocess + from tools import runtime + + command = i_cmd if libimobiledevice: - if type(i_cmd) == str: - i_cmd = seperator.join([libimobiledeviceDir, i_cmd]) + if type(command) == str: + command = runtime.separator.join([runtime.libimobiledevice_dir, command]) else: - i_cmd[0] = seperator.join([libimobiledeviceDir, i_cmd[0]]) + command = list(command) + command[0] = runtime.separator.join([runtime.libimobiledevice_dir, command[0]]) if getoutp: - return subprocess.Popen(i_cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=env[OS]).stdout.read().decode("utf-8") + return subprocess.Popen(command, stdout=subprocess.PIPE, stderr=subprocess.PIPE, env=runtime.env[runtime.OS]).stdout.read().decode("utf-8") else: - subprocess.run(i_cmd, env=env[OS]) + subprocess.run(command, env=runtime.env[runtime.OS]) # get the OS @@ -76,4 +77,4 @@ def setDisplayRequired(): ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS | ES_DISPLAY_REQUIRED) def resetDisplayRequired(): import ctypes - ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS) \ No newline at end of file + ctypes.windll.kernel32.SetThreadExecutionState(ES_CONTINUOUS)