星联指纹手机,支持一键新机的方案,同时支持海外Tiktok,附带了获取TK用户名的方法,下面就是官网提供的adb操作命令,简单好用


"""有不懂的地V球:TiktokLM 或者 Tik382"""

import cv2
import ctypes
import sys
import os
import time
from xml.dom import minidom
import xml.etree.ElementTree as ET

# 载入动态链接库
import numpy as np


# myt rpc  lib
class MytRpc(object):
    def __init__(self) -> None:
        # self._lib_PATH   替换成自己的链接库路径
        self._lib_PATH = os.path.dirname(os.path.abspath(__file__)) + "/lib/libmytrpc.so"
        self._handle = 0
        self.ptr = None
        if os.path.exists(self._lib_PATH) == False:
            self._lib_PATH = os.path.dirname(os.path.abspath(__file__)) + "/libmytrpc.so"

    def __del__(self):
        if self._handle > 0:
            self._rpc.closeDevice(self._handle)

    # 初始化
    def init(self, ip, port, timeout):
        ret = False
        # if os.path.exists(self._lib_PATH) == True:
        if sys.platform == "linux":
            self._rpc = ctypes.CDLL(self._lib_PATH)
        else:
            # self._rpc = ctypes.WinDLL(self._lib_PATH)
            self._rpc = ctypes.WinDLL('D:/small_et/x64/libmytrpc.dll')
        b_time = int(time.time())
        while True:
            self._handle = self._rpc.openDevice(bytes(ip, "utf-8"), port, 10)
            if self._handle > 0:
                ret = True
                print("rpc " + ip + " ok!")
                break
            else:
                now = int(time.time())
                if now - b_time > timeout:
                    print("rpc " + ip + " timeout " + str(timeout))
                    break
                else:
                    time.sleep(10)
        else:
            print("File not Found: " + self._lib_PATH)
        return ret

    # 释放指针内存
    def free_rpc(self):
        try:
            if self.ptr:
                print("释放指针内存")
                self._rpc.freeRpcPtr(self.ptr)
        except Exception as e:
            print(e)

    # 执行命令
    def exec_cmd(self, cmd):
        ret = False
        if self._handle > 0:
            # cmd = " pm install /data/local/TikTok_26.5.3_apkcombo.com.apk"
            # cmd = "ls"
            self._rpc.execCmd.restype = ctypes.c_char_p
            ptr = self._rpc.execCmd(self._handle, ctypes.c_int(1), ctypes.c_char_p(cmd.encode('utf-8')))
            if ptr is not None:
                ret = ptr.decode('utf-8')
                print("exec " + cmd + "  :" + ret)
            else:
                ret = True
        return ret

    # 导出节点信息
    # bDumpAll 导出所有节点  0   1
    def dumpNodeXml(self, bDumpAll):
        ret = False
        try:
            if self._handle > 0:
                self._rpc.dumpNodeXml.argtypes = [ctypes.c_long, ctypes.c_int]
                self._rpc.dumpNodeXml.restype = ctypes.c_void_p
                ptr = self._rpc.dumpNodeXml(self._handle, bDumpAll)
                p2 = ctypes.cast(ptr, ctypes.c_char_p)

                ret = p2.value.decode("utf-8")
                # 释放指针内存
                self._rpc.freeRpcPtr.argtypes = [ctypes.c_void_p]

                return ret
        except Exception as e:
            print(e)
            return ret
        # finally:
        #     # 释放指针内存
        #     self._rpc.freeRpcPtr(ptr)

    # 截图导出为bytes 数组
    # type  0 png  1 jpg
    # quality  图片质量  0-100
    # 返回字节数组
    def takeCaptrueCompress(self, type, quality):
        ret = False
        if self._handle > 0:
            dataLen = ctypes.c_int(0)
            ptr = self._rpc.takeCaptrueCompress(self._handle, type, quality, ctypes.byref(dataLen))
            if ptr:
                try:
                    # 将ptr转换为bytes对象
                    buf = ctypes.cast(ptr, ctypes.POINTER(ctypes.c_ubyte * dataLen.value)).contents
                    # 使用OpenCV将bytes对象转换为图像
                    img_array = bytes(buf)
                    ret = img_array
                    # img_np = np.frombuffer(img_array, dtype=np.uint8)
                    # img = cv2.imdecode(img_np, cv2.IMREAD_COLOR)

                    # # 显示图像
                    # cv2.imshow("Image", img)
                    # cv2.waitKey(0)
                finally:
                    # 释放指针内存
                    self._rpc.freeRpcPtr(ptr)
        return ret

    # 文字输入
    def sendText(self, text):
        ret = False
        if self._handle > 0:
            ret = self._rpc.takeCaptrueCompress(self._handle, ctypes.c_char_p(text.encode('utf-8')))
        return ret

    # 开启指定的应用
    def openApp(self, pkg):
        ret = False
        if self._handle > 0:
            ret = self._rpc.openApp(self._handle, ctypes.c_char_p(pkg.encode('utf-8')))
        return ret

    # 停止指定的应用
    def stopApp(self, pkg):
        ret = False
        if self._handle > 0:
            ret = self._rpc.stopApp(self._handle, ctypes.c_char_p(pkg.encode('utf-8')))
        return ret

    # 获取当前屏幕的方向
    #  4个方向(0,1,2,3)
    def getDisplayRotate(self):
        ret = False
        if self._handle > 0:
            ret = self._rpc.getDisplayRotate(self._handle)
        return ret

    # 按下操作
    def touchDown(self, finger_id, x, y):
        ret = False
        if self._handle > 0:
            ret = self._rpc.touchDown(self._handle, finger_id, x, y)
        return ret

    # 弹起操作
    def touchUp(self, finger_id, x, y):
        ret = False
        if self._handle > 0:
            ret = self._rpc.touchUp(self._handle, finger_id, x, y)
        return ret

    # 滑动操作
    def touchMove(self, finger_id, x, y):
        ret = False
        if self._handle > 0:
            ret = self._rpc.touchMove(self._handle, finger_id, x, y)
        return ret

    # 单击操作
    def touchClick(self, finger_id, x, y):
        ret = False
        if self._handle > 0:
            ret = self._rpc.touchClick(self._handle, finger_id, x, y)
        return ret

    # 按键操作
    def keyPress(self, code):
        ret = False
        if self._handle > 0:
            ret = self._rpc.keyPress(self._handle, code)
        return ret


# 获取用户名
def get_user_name(comm):
    try:
        rpc = MytRpc()
        # c_ip = "192.168.10.127"
        rpc_port = 9083
        if rpc.init(comm, rpc_port, 120):
            time.sleep(1)
            xml = rpc.dumpNodeXml(0)
            rpc.free_rpc()
            if xml:
                strs = xml.split("\" resource-id=\"com.zhiliaoapp.musically:id/kcq\"")
                if len(strs) > 1:
                    names = strs[0].split("@")
                    if len(names) > 1:
                        name = names[len(names) - 1]
                        return name

        return None
    except Exception as e:
        return None
        # doc = minidom.parseString(s)
        # et = ET.fromstring(s)
        # for chile in et[0]:
        #     print(chile.attrib)
        # print("=======")


Logo

为开发者提供学习成长、分享交流、生态实践、资源工具等服务,帮助开发者快速成长。

更多推荐