类人猿学院
课程推荐

这个TC的adb开源库+大漠做中控非常好用

119
发表时间:2018-04-08 17:50


这个TC的adb开源库+大漠做中控非常好用。

//为适应ld.exe的命令,除获取模拟器信息此条命令外,其他命令全部改写成基于模拟器序号,序号可由获取模拟器信息此条命令获取

//本人只封装了个人认为比较常用的命令,如果你需要的命令没有,可以自己去扩展,或联系本人QQ:1104573225,欢迎学习交流及定制脚本

var dnc路径 = ""

function dncCmd(cmdStr)

   if(dnc路径 == "")

       取dnc路径()

   end

   traceprint(dnc路径)

   cmdStr = dnc路径 & cmdStr

   return pipecmd(cmdStr)

end

function 取dnc路径()

   dnc路径 = reggetvalue("HKEY_CURRENT_USER\\Software\\ChangZhi2\\dnplayer", "InstallDir") & "dnconsole.exe"

end

function 启动模拟器(序号)

   dncCmd(" launch --index " & 转字符型(序号))

end

function 启动应用(序号, 应用包名)

   dncCmd(" runapp --index " & 转字符型(序号) & " --packagename " & 应用包名)

end

function 获取模拟器信息(模拟器标题)

   //返回数组,下标从0开始,顺序为:序号,标题,顶层窗口句柄,绑定窗口句柄,是否进入android,进程PID,VBox进程PID

   var retstr = ""

   var retarrSize = -1

   var retarr = array()

   retstr = dncCmd(" list2")

   strsplit(retstr, "\r\n", retarr)

   retarrSize = arraysize(retarr)

   for(var i = 0; i < retarrSize + 1; i++)

       if(strfind(retarr[i], 模拟器标题) != -1)

           strsplit(retarr[i], ",", retarr[i])

           return retarr[i]

       end

   end

   //traceprint("模拟器不存在,脚本退出")

   //退出()

   //这里自己做好异常处理!!

   return ""

end

function 重启模拟器并进入指定应用(序号, 应用包名 = "null")

   dncCmd(" action --index " & 转字符型(序号) & " --key call.reboot --value " & 应用包名)

end

function 关闭应用(序号, 应用包名)

   dncCmd(" killapp --name " & 转字符型(序号) & " --packagename " & 应用包名)

end

function 降低cpu(序号, 数值)

   //取值范围0-99  取值为0 表示关闭CPU优化. 这个值越大表示降低CPU效果越好

   dncCmd(" downcpu --index " & 转字符型(序号) & " --rate " & cstring(数值))

end

function 克隆模拟器(序号1, 序号2)

   dncCmd(" copy --index " & 转字符型(序号1) & " --from " & 转字符型(序号2))

end

function 删除模拟器(序号)

   dncCmd(" remove --index " & 转字符型(序号))

end

function 修改模拟器信息(序号)

   var retarr = 随机设备信息()

   dncCmd(" modify --index " & 转字符型(序号) & " --manufacturer " & retarr[0] & " --model " & retarr[1] & " --imei " & retarr[2] & " --androidid auto --mac auto")  

end

function 关闭模拟器(序号)

   dncCmd(" quit --index " & 转字符型(序号))

end




function 还原模拟器(序号, 备份路径)

   dncCmd(" restore --index " & 转字符型(序号) & " --file " & 备份路径)

end

function 修改定位(序号, 经纬度)

   dncCmd(" action --index " & 转字符型(序号) & " --key call.locate --value " & 经纬度)

end

function 文字输入(序号, intputstr)

   dncCmd(" action --index " & 转字符型(序号) & " --key call.input --value " & intputstr)

end

function 安卓按键(序号, 键值)//back/home/menu/volumeup/volumedown

   dncCmd(" action --index " & 转字符型(序号) & " --key call.keyboard --value " & 键值)

end

function 随机设备信息()

   var imei = -1

   var 随机型号 = rnd(0, 9)

   var retarr = array()

   select(随机型号)

       case 0//酷派cool1

       imei = array(8, 6, 1, 7, 9, 5, 0, 3)

       retarr[0] = "Coolpad"

       retarr[1] = "C106"

       case 1//小米5

       imei = array(8, 6, 2, 2, 5, 8, 0, 3)

       retarr[0] = "MI"

       retarr[1] = "MI 5"

       case 2//华为荣耀7

       imei = array(8, 6, 7, 6, 8, 9, 0, 2)

       retarr[0] = "Honor"

       retarr[1] = "PLK-TL01H"

       case 3//魅族pro5

       imei = array(8, 6, 7, 9, 0, 5, 0, 2)

       retarr[0] = "MEIZU"

       retarr[1] = "M576"

       case 4//锤子M1

       imei = array(9, 9, 0, 0, 0, 7, 1, 7)

       retarr[0] = "smartisan"

       retarr[1] = "M1"

       case 5//魅族pro6

       imei = array(8, 6, 9, 0, 1, 6, 0, 2)

       retarr[0] = "MEIZU"

       retarr[1] = "M570Q"

       case 6//一加3T

       imei = array(8, 6, 2, 5, 6, 1, 0, 3)

       retarr[0] = "One Plus"

       retarr[1] = "A3010"

       case 7//努比亚Z9mini

       imei = array(8, 6, 6, 7, 6, 9, 0, 2)

       retarr[0] = "nubia"

       retarr[1] = "NX511J"

       case 8//vivo X7

       imei = array(8, 6, 3, 1, 8, 7, 0, 3)

       retarr[0] = "VIVO"

       retarr[1] = "X7"

       case 9//小米4lte

       imei = array(8, 6, 7, 8, 2, 6, 0, 2)

       retarr[0] = "MI"

       retarr[1] = "MI4 LTE"

   end

   var 偶数 = array(), 偶数位数和 = array()

   var 奇数和, 偶数和, 效验值, imei码, 十位数, 个位数

   imei码 = ""

   for(var i = 8; i < 14; i++)

       imei[i] = rnd(0, 9)

   end

   for(var i = 0; i < 7; i++)

       奇数和 = 奇数和 + imei[i * 2]

       偶数[i] = imei[i * 2 + 1] * 2

       偶数[i] = cstring(偶数[i])

       if(strlen(偶数[i]) == 2)

           十位数 = strleft(偶数[i], 1)

           个位数 = strright(偶数[i], 1)

           偶数位数和[i] = cint(十位数) + cint(个位数)

       else

           偶数位数和[i] = cint(偶数[i])

       end

       偶数和 = 偶数和 + 偶数位数和[i]

   end

   for(var i = 0; i < 14; i++)

       imei[i] = cstring(imei[i])

       imei码 = imei码 & imei[i]

   end

   效验值 = strright(cstring(奇数和 + 偶数和), 1)

   if(效验值 == 0)

       imei码 = cstring(效验值)

   else

       效验值 = 10 - cint(效验值)

   end

   imei码 = imei码 & cstring(效验值)

   if(strlen(imei码) == 15)

       retarr[2] = imei码

       return retarr

   else

       return 随机设备信息()

   end

end


//通过管道执行命令结果,禁止执行,带交互的命令,可能会卡死

//cmdstr 执行的命令

//time_out命令执行的超时时间,防止卡死

功能 pipecmd(cmdstr, time_out = 100000)

   变量 sa

   _SECURITY_ATTRIBUTES(sa)

   sa["nLength"]["value"] = 结构体长度(sa)

   sa["bInheritHandle"]["value"] = 真

   //创建管道

   变量 hRead, hWrite

   如果(!CreatePipe(hRead, hWrite, sa, 0))

       调试输出(获取错误信息(1))

       调试输出("创建管道失败")

       返回 ""

   结束

   变量 si, pi

   _STARTUPINFOW(si)

   _PROCESS_INFORMATION(pi)

   si["cb"]["value"] = 结构体长度(si)

   si["hStdError"]["value"] = hWrite

   si["hStdOutput"]["value"] = hWrite

   si["wShowWindow"]["value"] = 0

   si["dwFlags"]["value"] = #00000101

   //创建进程 与管道关联

   如果(!CreateProcess(0, cmdstr, 0, 0, 1, 0, 0, 0, si, pi))

       调试输出(获取错误信息(1))

       调试输出("创建进程失败")

       返回 ""

   结束

   CloseHandle(hWrite)

   变量 nSize = 1024

   变量 buffer = new(1024)

   memset(buffer, 0, 1024 + 1)

   变量 nReadSize = 0

   变量 string

   变量 time1 = 获取系统时间()

   循环(ReadFile(hRead, buffer, 1024, nReadSize, 0))

       //内存溢出

       如果(nReadSize > 1024)

           跳出

       结束

       //超时

       变量 time2 = 获取系统时间()

       如果(time2 - time1 > time_out)

           跳出

       结束            

       string = string & 地址取值(buffer, "char *")

       等待(1, 0)

       memset(buffer, 0, 1024 + 1)

   结束

   delete(buffer) //之前漏掉了这处代码,让程序有内存泄漏

   CloseHandle(hRead)

   返回 string

结束

//申请内存地址

function new(nSize)

   var string = array()

   string["str"] = array("char" = nSize + 1, "value" = "")

   return structmalloc(string)

end

//释放内存

function delete(address)

   structfree(address)

end

//重置一段内存中值

function memset(address, value, nSize)

   return dllcall("kernel32.dll", "long", "RtlFillMemory", "long", address, "long", nSize, "long", value)

end

function _SECURITY_ATTRIBUTES(&SECURITY_ATTRIBUTES)

   SECURITY_ATTRIBUTES = array()

   SECURITY_ATTRIBUTES["nLength"] = array("long" = 0, "value" = 0)

   SECURITY_ATTRIBUTES["lpSecurityDescriptor"] = array("long" = 0, "value" = 0)

   SECURITY_ATTRIBUTES["bInheritHandle"] = array("long" = 0, "value" = 0)

end

function _STARTUPINFOW(&STARTUPINFOW)

   STARTUPINFOW = array()

   STARTUPINFOW["cb"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["lpReserved"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["lpDesktop"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["lpTitle"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["dwX"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["dwY"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["dwXSize"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["dwYSize"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["dwXCountChars"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["dwYCountChars"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["dwFillAttribute"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["dwFlags"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["wShowWindow"] = array("short" = 0, "value" = 0)

   STARTUPINFOW["cbReserved2"] = array("short" = 0, "value" = 0)

   STARTUPINFOW["lpReserved2"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["hStdInput"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["hStdOutput"] = array("long" = 0, "value" = 0)

   STARTUPINFOW["hStdError"] = array("long" = 0, "value" = 0)

end

function _PROCESS_INFORMATION(&PROCESS_INFORMATION)

   PROCESS_INFORMATION = array()

   PROCESS_INFORMATION["hProcess"] = array("long" = 0, "value" = 0)

   PROCESS_INFORMATION["hThread"] = array("long" = 0, "value" = 0)

   PROCESS_INFORMATION["dwProcessId"] = array("long" = 0, "value" = 0)

   PROCESS_INFORMATION["dwThreadId"] = array("long" = 0, "value" = 0)

end

//创建管道

function CreatePipe(&readPipe, &writePipe, &lpPipeAttributes, nSize)

   return dllcall("kernel32.dll", "long", "CreatePipe", "plong", readPipe, "plong", writePipe, "pstruct", lpPipeAttributes, "long", nSize)

end

//创建进程

function CreateProcess(lpApplicationName, lpCommandLine, lpProcessAttributes, lpThreadAttributes, bInheritHandles, dwCreationFlags, lpEnvironment, lpCurrentDirectory, &lpStartupInfo, &lpProcessInformation)

   return dllcall("kernel32.dll", "long", "CreateProcessW", "long", lpApplicationName, "wchar *", lpCommandLine, "long", lpProcessAttributes, "long", lpThreadAttributes, "long", bInheritHandles, "long", dwCreationFlags, "long", lpEnvironment, "long", lpCurrentDirectory, "pstruct", lpStartupInfo, "pstruct", lpProcessInformation)

end

//关闭句柄

function CloseHandle(handle)

   return dllcall("kernel32.dll", "long", "CloseHandle", "long", handle)

end

//读文件句柄,可以文件,管理,io这一系列的句柄内容

function ReadFile(hFile, lpBuffer, nNumberOfBytesToRead, &lpNumberOfBytesRead, lpOverlapped = 0)

   return dllcall("kernel32.dll", "long", "ReadFile", "long", hFile, "long", lpBuffer, "long", nNumberOfBytesToRead, "plong", lpNumberOfBytesRead, "long", lpOverlapped)

end