local icloud = "test@gmail.com" local host, port = "34.124.132.199", 8083 local socket = require("socket") local tcp = assert(socket.tcp()) local json = require "json" local iMessCreateX = 0; local iMessCreateY = 0; local w, h = getScreenResolution(); local returnX = w - 50; local returnY = h - 50; local cancelX = 650; local cancelY = 150; local sendX = 665; local sendY = 765; local backX = 50; local backY = 80; local addNewNumberX = 673; local addNewNumberY = 276; local IMBlue = 31487; local IMNotFoundColor = 2737433; local licenseX = 382; local licenseY = 1072; function iMessage(receiver, message) local res = { ["success"] = false, ["code"] = 0, ["message"] = "Lỗi không xác định" } appRun("com.apple.MobileSMS"); usleep(1000000); local isHomeScreen = backToHome(4, 500000); if not isHomeScreen then res["code"] = 1 res["message"] = "Không nhận dạng được màn hình chính của iMessage" return res end usleep(1000000); local isTapCreate = tapCreateBtn(4, 500000); if not isTapCreate then res["code"] = 2 res["message"] = "Không tạo được tin iMessage mới" return res end usleep(500000); local isInputReceiver = inputReceiver(receiver, 4, 500000) if not isTapCreate then res["code"] = 3 res["message"] = "Không thể nhập iCloud người gửi" return res end tap(returnX, returnY); usleep(1000000); local findReceiverColor = findColor(IMNotFoundColor, 2, {20, 200, 200, 250}); local r1 = 0; local r2 = 0; for i, v in pairs(findReceiverColor) do r1 = v[1]; r2 = v[2]; end if (r1 == 0 or r2 == 0) then tap(returnX, returnY); usleep(500000); inputText(message); usleep(500000); local findSendBtn = findColor(IMBlue, 2, {600, 700, 100, 100}); local b1 = 0; local b2 = 0; for i, v in pairs(findSendBtn) do b1 = v[1]; b2 = v[2]; end if (b1 ~= 0 or b2 ~= 0) then tap(sendX, sendY); usleep(1000000); tapBackBtn(4, 500000); res["success"] = true res["message"] = "" return res else tap(cancelX, cancelY); res["code"] = 4 res["message"] = "Không thể gửi tin nhắn iMessage" return res end else tap(cancelX, cancelY); res["code"] = 5 res["message"] = "Tài khoản iCloud không tồn tại" return res end end function isIMessage() local region = {80, 10, 600, 250}; local result = recognizeText(region); local found = false; for key,value in pairs(result) do if string.find(value["text"], "iMessage") then found = true; end end return found; end function tapBackBtn(times, delay) local getBackTimes = 0; local isTap = false; repeat getBackTimes = getBackTimes + 1; local findSendBtn = findColor(IMBlue, 2, {10, 10, 150, 150}) local b1 = 0; local b2 = 0; for i, v in pairs(findSendBtn) do b1 = v[1]; b2 = v[2]; end if (b1 ~= 0 or b2 ~= 0) then tap(b1, b2); isTap = true; else usleep(delay); end until(getBackTimes == times or isTap) return isTap; end function backToHome(times, delay) local runTimes = 0; local isHome = false; repeat runTimes = runTimes + 1; -- check is home screen local findCreateBtn = findColor(IMCanSendColor, 2, {560, 70, 40, 130}) local b1 = 0; local b2 = 0; for i, v in pairs(findCreateBtn) do b1 = v[1]; b2 = v[2]; end if (b1 ~= 0 or b2 ~= 0) then isHome = true; end if not isHome then -- check is type message screen local region = {80, 10, w - 90, 200}; local result = recognizeText(region); for key,value in pairs(result) do if string.find(value["text"], "Cancel") then tap(cancelX, cancelY); isHome = true; end end end if not isHome then -- check is detail message screen local findBackBtn = findColor(IMCanSendColor, 2, {10, 10, 150, 150}) b1 = 0; b2 = 0; for i, v in pairs(findBackBtn) do b1 = v[1]; b2 = v[2]; end if (b1 ~= 0 or b2 ~= 0) then tap(b1, b2); isHome = true; end end if not isHome then usleep(delay); end until(runTimes == times or isHome) return isHome; end function tapCreateBtn(times, delay) local runTimes = 0; local isTap = false; repeat runTimes = runTimes + 1; local findBtnColor = findColor(IMBlue, 2, {660, 70, 60, 120}) local tapX = 0; local tapY = 0; for i, v in pairs(findBtnColor) do tapX = v[1]; tapY = v[2]; end if (tapX ~= 0 or tapY ~= 0) then tap(tapX, tapY); isTap = true; else usleep(delay); end until(runTimes == times or isTap) return isTap; end function inputReceiver(receiver, times, delay) local isInput = false; local runTimes = 0; repeat runTimes = runTimes + 1; local findAddColor = findColor(IMBlue, 2, {addNewNumberX-10, addNewNumberY-10, 20, 30}) local tapX = 0; local tapY = 0; for i, v in pairs(findAddColor) do tapX = v[1]; tapY = v[2]; end if (tapX ~= 0 or tapY ~= 0) then inputText(receiver) isInput = true else usleep(delay); end until(runTimes == times or isInput) return isInput end function tapOKLicense() local findAddColor = findColor(IMBlue, 2, {licenseX-10, licenseY-10, 20, 30}) local tapX = 0; local tapY = 0; for i, v in pairs(findAddColor) do tapX = v[1]; tapY = v[2]; end if (tapX ~= 0 or tapY ~= 0) then tap(tapX, tapY) return true end return false end tcp:connect(host, port); tcp:setoption("keepalive", true) tcp:setoption("reuseaddr", true) local init = { ["sender"] = icloud, } assert(tcp:send(json.encode(init))) repeat data, errormsg = tcp:receive() if data then print("message received: "..data) if (data == "end") then break else local mess = json.decode(data) local res = { ["id"] = mess["id"], ["sender"] = icloud, ["receiver"] = mess["receiver"], ["content"] = mess["content"], ["message"] = "", ["success"] = false } local result = iMessage(mess["receiver"], mess["content"]) if (result["success"] == false) then local isTapLS = tapOKLicense() if isTapLS then result = iMessage(mess["receiver"], mess["content"]) end end res["success"] = result["success"] res["message"] = result["message"] tcp:send(json.encode(res)) end else assert(tcp:send("ready")) end until not tcp