exec常用命令

[复制链接]
查看5776 | 回复19 | 2021-8-17 05:36:05 | 显示全部楼层 |阅读模式
本帖最后由 蜗牛 于 2021-8-18 11:48 编辑

  1. function path(name)
  2.         if name then
  3.                 return '/sdcard/' .. name
  4.         else
  5.                 return '/sdcard/APE.txt'
  6.         end
  7. end

  8. function read(path, hms)
  9.         local t1 = os.time(), tt
  10.     -- 循环判断
  11.         repeat
  12.                 if hms == nil then
  13.                         xv, text =
  14.                         pcall(
  15.                         function(path)
  16.                                 return io.open(path):read('*a')
  17.                         end,
  18.                         path
  19.                         )
  20.             print(xv,text)
  21.                 else
  22.                         xv, text =
  23.                         pcall(
  24.                         function(path)
  25.                                 return io.open(path):read()
  26.                         end,
  27.                         path
  28.                         )
  29.                 end
  30.                 local t2 = os.time()
  31.                 local tt = os.difftime(t2, t1)
  32.         until (xv or tt == 1)
  33.    
  34.         if text then
  35.                 return text
  36.         else
  37.                 return ''
  38.         end
  39.    
  40. end
  41. --read('/sdcard/APE.txt')
  42. -- 设备基本控制命令】
  43. -- [打出电话]
  44. -- num 电话号
  45. function callup(Num)
  46.         exec('am start -a android.intent.action.CALL -d tel:' .. Num .. '')
  47. end

  48. --[发出短信]
  49. -- num电话号
  50. -- mms 短信内容
  51. function mms(Num, MMS)
  52.         if MMS == nil then
  53.                 exec('am start -a android.intent.action.SENDTO -d sms: --es sms_body ' .. Num .. '')
  54.         else
  55.                 exec('am start -a android.intent.action.SENDTO -d sms:' .. Num .. ' --es sms_body ' .. MMS .. '')
  56.                 exec('input keyevent 22')
  57.                 exec('input keyevent 66')
  58.         end
  59. end
  60. -- [重启或者关机]
  61. -- str为空就关机不为空重启
  62. function reboot(str)
  63.         if str == nil then
  64.                 exec('reboot')
  65.         else
  66.                 exec('reboot -p')
  67.         end
  68. end
  69. -- [开关数据流量]
  70. -- str为空就打开不为空关闭
  71. function net(str)
  72.         if str == nil then
  73.                 exec('svc data enable')
  74.         else
  75.                 exec('svc data disable')
  76.         end
  77. end
  78. -- [ 开关Wifi ]
  79. -- str为空就打开不为空关闭
  80. function wifi(str)
  81.         if str == nil then
  82.                 exec('svc wifi enable')
  83.         else
  84.                 exec('svc wifi disable')
  85.         end
  86. end
  87. -- [ 开关飞行模式 ]
  88. -- str为空就打开不为空关闭
  89. function airplane(str)
  90.         if str == nil then
  91.                 exec('settings put global airplane_mode_on 1')
  92.                 exec('am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true')
  93.         else
  94.                 exec('settings put global airplane_mode_on 0')
  95.                 exec('am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false')
  96.         end
  97. end
  98. -- 设备信息状态查看】
  99. -- [获取安卓设备系统版本号]
  100. function version()
  101.         exec('getprop ro.build.version.release > ' .. path())
  102.         return read(path())
  103. end
  104. -- [获取设备电池剩余电量值]
  105. function power()
  106.         exec('dumpsys power  | grep -e mBatteryLevel > ' .. path())
  107.         return string.match(read(path()), '=([^ ]+)')
  108. end
  109. -- [检测屏幕状态是否亮屏]
  110. function stateled()
  111.         exec('dumpsys power  | grep -e mWakefulness > ' .. path())
  112.         if string.match(read(path()), 'Awake') then
  113.                 return true
  114.         else
  115.                 return false
  116.         end
  117. end
  118. -- [检测wifi是否开启]
  119. function wifistate()
  120.         exec('dumpsys wifi | grep Wi-Fi > ' .. path())
  121.         if string.match(read(path()), 'enabled') then
  122.                 return true
  123.         else
  124.                 return false
  125.         end
  126. end

  127. -- [获取Wifi帐号与密码][部分手机获取不到]
  128. function wifipsk()
  129.         exec('dumpsys wifi | grep -A 0 WPA-PSK > ' .. path())
  130.         local str = string.sub(read(path(), 1), 1, -44)
  131.         local wifim = string.match(str, '.+ ([^ ]+)')
  132.         exec('cat /data/misc/wifi/*.conf >' .. path())
  133.         local s, e = string.find(read(path()), 'ssid="' .. wifim .. '"')
  134.         print(str,wifim)
  135.         local psk = string.match(read(path()), 'psk=([^\r\n]+)', e)
  136.         print(psk)
  137.         if wifim and psk then
  138.                 return wifim, psk
  139.         end
  140. end

  141. -- [获取前台运行APP包名与活动界面组件名/判断APP是否在指定界面运行]
  142. function activeac(act)
  143.         exec('dumpsys activity top | grep ACTIVITY > ' .. path())
  144.         local bm = string.match(read(path()), 'ACTIVITY ([^/]+)')
  145.         local hm = string.match(read(path()), 'ACTIVITY ([^ ]+)')
  146.         if act == bm or act == hm or act == nil then
  147.                 return bm, hm
  148.         else
  149.                 return false
  150.         end
  151. end

  152. -- 打开指定APP
  153. -- bm 包名/启动界面
  154. function offapp(bm)
  155.         exec('am start -n '.. bm .. '')
  156. end
  157. -- 关闭退出APP
  158. -- bm
  159. function offapp(bm)
  160.         exec('am force-stop ' .. bm .. '')
  161. end
  162. -- [返回指定APP安装包所在路径]
  163. -- bm 包名
  164. function package(bm)
  165.         exec('pm path ' .. bm .. ' > ' .. path())
  166.         local str = string.match(read(path()), '/.+k')
  167.         if str then
  168.                 return str
  169.         else
  170.                 return ''
  171.         end
  172. end

  173. -- [检测设备是否安装了指定的APP]
  174. -- bm 包名
  175. function packages(bm)
  176.         exec('pm list packages -3 > ' .. path())
  177.         local str = string.match(read(path()), bm)
  178.         if str then
  179.                 return true
  180.         else
  181.                 return false
  182.         end
  183. end

  184. -- [监听全部APP或指定APP通知栏信息](支持同步监听两个"指定"的APP)
  185. -- pkg 包名
  186. function ticker(pkg, pkg2)
  187.         if pkg == nil then
  188.                 exec('dumpsys notification | grep -e tickerText= >' .. path())
  189.                 local tickerText = read(path())
  190.                 if tickerText then
  191.                         return tickerText
  192.                 else
  193.                         return ''
  194.                 end
  195.         end
  196.         if pkg2 == nil then
  197.                 exec('dumpsys notification | grep -e pkg=' .. pkg .. ' -e tickerText >' .. path())
  198.                 tickerText = read(path())
  199.         elseif pkg and pkg2 then
  200.                 exec('dumpsys notification | grep -e pkg=' .. pkg .. ' -e pkg=' .. pkg2 .. ' -e tickerText >' .. path())
  201.                 tickerText = read(path())
  202.                 local s, e = string.find(tickerText, pkg2)
  203.                 if e then
  204.                         Text2 = string.match(tickerText, 'tickerText=([^\r\n]+)', e)
  205.                 end
  206.                 if Text2 == nil then
  207.                         Text2 = ''
  208.                 end
  209.         end
  210.         local s, e = string.find(tickerText, pkg)
  211.         if e then
  212.                 Text = string.match(tickerText, 'tickerText=([^\r\n]+)', e)
  213.         end
  214.         if Text == nil then
  215.                 Text = ''
  216.         end
  217.         return Text, Text2
  218. end

  219. -- [读网页源文件]
  220. -- http 网址
  221. -- time 默认就行
  222. function Gethttp(http, time)
  223.         if time == nil then
  224.                 time = 8
  225.         end
  226.         exec(string.format("curl --connect-timeout %s -o %s '%s' ", time, path(), http))
  227.         text = read(path())
  228.         if text then
  229.                 return text
  230.         else
  231.                 return ''
  232.         end
  233. end
  234. -- [使用浏览器打开网址]
  235. exec(string.format("am start -a android.intent.action.VIEW -d %s",网址))
  236. -- 删除AAAAA目录下所有文件
  237. url='/storage/emulated/0/AAAAA/*'
  238. exec("rm -rf ".. url)
复制代码

回复

使用道具 举报

xywl | 2021-8-17 11:53:31 | 显示全部楼层
谢谢分享
回复

使用道具 举报

LUA蜂群 | 2021-8-17 13:06:06 来自手机 | 显示全部楼层
欢迎重新编辑,注明语法,参数,案例
回复

使用道具 举报

蜗牛 | 2021-8-17 13:27:33 | 显示全部楼层
LUA蜂群 发表于 2021-8-17 13:06
欢迎重新编辑,注明语法,参数,案例

等我睡醒,把参数注释加上吧,语法全是if应该一看就懂
回复

使用道具 举报

qq99989680 | 2021-8-17 14:50:35 | 显示全部楼层
不错不错 多来点
回复

使用道具 举报

秋风落叶 | 2021-8-18 08:45:43 | 显示全部楼层
mark,已纳
回复

使用道具 举报

qiaohw04 | 2021-8-18 10:46:13 | 显示全部楼层
擦,  我看成excel命令了
回复

使用道具 举报

风雷 | 2021-8-18 11:32:10 | 显示全部楼层
常用.真是常用..分享牛...B
回复

使用道具 举报

yh4132990 | 2021-8-18 12:06:26 | 显示全部楼层

谢谢分享
谢谢分享
回复

使用道具 举报

zj1997 | 2021-8-20 11:38:00 | 显示全部楼层
感谢分享
回复

使用道具 举报

您需要登录后才可以回帖 登录 | 立即注册

本版积分规则