本帖最后由 蜗牛 于 2021-8-18 11:48 编辑
- function path(name)
- if name then
- return '/sdcard/' .. name
- else
- return '/sdcard/APE.txt'
- end
- end
- function read(path, hms)
- local t1 = os.time(), tt
- -- 循环判断
- repeat
- if hms == nil then
- xv, text =
- pcall(
- function(path)
- return io.open(path):read('*a')
- end,
- path
- )
- print(xv,text)
- else
- xv, text =
- pcall(
- function(path)
- return io.open(path):read()
- end,
- path
- )
- end
- local t2 = os.time()
- local tt = os.difftime(t2, t1)
- until (xv or tt == 1)
-
- if text then
- return text
- else
- return ''
- end
-
- end
- --read('/sdcard/APE.txt')
- -- 设备基本控制命令】
- -- [打出电话]
- -- num 电话号
- function callup(Num)
- exec('am start -a android.intent.action.CALL -d tel:' .. Num .. '')
- end
- --[发出短信]
- -- num电话号
- -- mms 短信内容
- function mms(Num, MMS)
- if MMS == nil then
- exec('am start -a android.intent.action.SENDTO -d sms: --es sms_body ' .. Num .. '')
- else
- exec('am start -a android.intent.action.SENDTO -d sms:' .. Num .. ' --es sms_body ' .. MMS .. '')
- exec('input keyevent 22')
- exec('input keyevent 66')
- end
- end
- -- [重启或者关机]
- -- str为空就关机不为空重启
- function reboot(str)
- if str == nil then
- exec('reboot')
- else
- exec('reboot -p')
- end
- end
- -- [开关数据流量]
- -- str为空就打开不为空关闭
- function net(str)
- if str == nil then
- exec('svc data enable')
- else
- exec('svc data disable')
- end
- end
- -- [ 开关Wifi ]
- -- str为空就打开不为空关闭
- function wifi(str)
- if str == nil then
- exec('svc wifi enable')
- else
- exec('svc wifi disable')
- end
- end
- -- [ 开关飞行模式 ]
- -- str为空就打开不为空关闭
- function airplane(str)
- if str == nil then
- exec('settings put global airplane_mode_on 1')
- exec('am broadcast -a android.intent.action.AIRPLANE_MODE --ez state true')
- else
- exec('settings put global airplane_mode_on 0')
- exec('am broadcast -a android.intent.action.AIRPLANE_MODE --ez state false')
- end
- end
- -- 设备信息状态查看】
- -- [获取安卓设备系统版本号]
- function version()
- exec('getprop ro.build.version.release > ' .. path())
- return read(path())
- end
- -- [获取设备电池剩余电量值]
- function power()
- exec('dumpsys power | grep -e mBatteryLevel > ' .. path())
- return string.match(read(path()), '=([^ ]+)')
- end
- -- [检测屏幕状态是否亮屏]
- function stateled()
- exec('dumpsys power | grep -e mWakefulness > ' .. path())
- if string.match(read(path()), 'Awake') then
- return true
- else
- return false
- end
- end
- -- [检测wifi是否开启]
- function wifistate()
- exec('dumpsys wifi | grep Wi-Fi > ' .. path())
- if string.match(read(path()), 'enabled') then
- return true
- else
- return false
- end
- end
- -- [获取Wifi帐号与密码][部分手机获取不到]
- function wifipsk()
- exec('dumpsys wifi | grep -A 0 WPA-PSK > ' .. path())
- local str = string.sub(read(path(), 1), 1, -44)
- local wifim = string.match(str, '.+ ([^ ]+)')
- exec('cat /data/misc/wifi/*.conf >' .. path())
- local s, e = string.find(read(path()), 'ssid="' .. wifim .. '"')
- print(str,wifim)
- local psk = string.match(read(path()), 'psk=([^\r\n]+)', e)
- print(psk)
- if wifim and psk then
- return wifim, psk
- end
- end
- -- [获取前台运行APP包名与活动界面组件名/判断APP是否在指定界面运行]
- function activeac(act)
- exec('dumpsys activity top | grep ACTIVITY > ' .. path())
- local bm = string.match(read(path()), 'ACTIVITY ([^/]+)')
- local hm = string.match(read(path()), 'ACTIVITY ([^ ]+)')
- if act == bm or act == hm or act == nil then
- return bm, hm
- else
- return false
- end
- end
- -- 打开指定APP
- -- bm 包名/启动界面
- function offapp(bm)
- exec('am start -n '.. bm .. '')
- end
- -- 关闭退出APP
- -- bm
- function offapp(bm)
- exec('am force-stop ' .. bm .. '')
- end
- -- [返回指定APP安装包所在路径]
- -- bm 包名
- function package(bm)
- exec('pm path ' .. bm .. ' > ' .. path())
- local str = string.match(read(path()), '/.+k')
- if str then
- return str
- else
- return ''
- end
- end
- -- [检测设备是否安装了指定的APP]
- -- bm 包名
- function packages(bm)
- exec('pm list packages -3 > ' .. path())
- local str = string.match(read(path()), bm)
- if str then
- return true
- else
- return false
- end
- end
- -- [监听全部APP或指定APP通知栏信息](支持同步监听两个"指定"的APP)
- -- pkg 包名
- function ticker(pkg, pkg2)
- if pkg == nil then
- exec('dumpsys notification | grep -e tickerText= >' .. path())
- local tickerText = read(path())
- if tickerText then
- return tickerText
- else
- return ''
- end
- end
- if pkg2 == nil then
- exec('dumpsys notification | grep -e pkg=' .. pkg .. ' -e tickerText >' .. path())
- tickerText = read(path())
- elseif pkg and pkg2 then
- exec('dumpsys notification | grep -e pkg=' .. pkg .. ' -e pkg=' .. pkg2 .. ' -e tickerText >' .. path())
- tickerText = read(path())
- local s, e = string.find(tickerText, pkg2)
- if e then
- Text2 = string.match(tickerText, 'tickerText=([^\r\n]+)', e)
- end
- if Text2 == nil then
- Text2 = ''
- end
- end
- local s, e = string.find(tickerText, pkg)
- if e then
- Text = string.match(tickerText, 'tickerText=([^\r\n]+)', e)
- end
- if Text == nil then
- Text = ''
- end
- return Text, Text2
- end
- -- [读网页源文件]
- -- http 网址
- -- time 默认就行
- function Gethttp(http, time)
- if time == nil then
- time = 8
- end
- exec(string.format("curl --connect-timeout %s -o %s '%s' ", time, path(), http))
- text = read(path())
- if text then
- return text
- else
- return ''
- end
- end
- -- [使用浏览器打开网址]
- exec(string.format("am start -a android.intent.action.VIEW -d %s",网址))
- -- 删除AAAAA目录下所有文件
- url='/storage/emulated/0/AAAAA/*'
- exec("rm -rf ".. url)
复制代码
|