luajava KillGG
KillGG 的实现方式 需要用的函数库 luajava
大致流程图
1
获取运行的进程
2
匹配App特征
3
杀死特征后的App
需要知道的是 需要到GG的Process里面调用此类的方法:save 这个更方便去获取运行的进程
.class public Landroid/ext/process;.super Ljava/lang/Object;.source "process.java"# static fields.field public static list:Ljava/util/List;.annotation system Ldalvik/annotation/Signature;value = {"Ljava/util/List","<","Landroid/ext/ProcessList$ProcessInfo;",">;"}.end annotation.end field# direct methods.method public constructor <init>()V.registers 1invoke-direct {p0}, Ljava/lang/Object;-><init>()Vreturn-void.end method.method public static save(Ljava/util/List;)V.registers 1.annotation system Ldalvik/annotation/Signature;value = {"(","Ljava/util/List","<","Landroid/ext/ProcessList$ProcessInfo;",">;)V"}.end annotationsput-object p0, Landroid/ext/process;->list:Ljava/util/List;return-void.end method
function killGG(package, intensity)assert(luajava, "缺少luajava函数库")local Scanner = luajava.bindClass("java.util.Scanner")local File = luajava.bindClass("java.io.File")local process = luajava.bindClass("android.ext.process")local data = {["InstalledApplications"] = {},["RunningAppProcesses"] = {},["Check"] = {},--["Search"] = {}}local package = packagecontext = luajava.bindClass("android.ext.Tools"):getContext()InstalledApplications = context:getPackageManager():getInstalledApplications(0)iterator = InstalledApplications:iterator()while (iterator:hasNext()) doentry = iterator:next()if (entry.name) thenif (entry.name):find("%.Application") thendata.InstalledApplications[entry.packageName] = {["packageName"] = entry.packageName,["sourceDir"] = entry.sourceDir}endendend--获取运行的进程RunningAppProcesses = process.listdata.RunningAppProcesses["size"] = RunningAppProcesses:size()if data.RunningAppProcesses["size"] > 1 thenit = RunningAppProcesses:iterator()while (it:hasNext()) doprocess = it:next()data.RunningAppProcesses[process.packageName] = {["pid"] = process.pid}endendstring.endsWith = function(str, chars)return chars == '' or string.sub(str, -string.len(chars)) == charsendfunction checkApp(sourceDir, str)local DexFile = luajava.bindClass("dalvik.system.DexFile")if sourceDir and sourceDir:endsWith("apk") thendexFile = luajava.new(DexFile, sourceDir)if (dexFile) thenentries = dexFile:entries()while (entries:hasMoreElements()) donextElement = entries:nextElement()if nextElement:find("android%.ext%.MainService")or nextElement:find("android%.ext%.HotPoint")or nextElement:find("android%.fix%.Button")or nextElement:find(str .. "%.FileProvider") thendata.Check[str] = truebreak;elsedata.Check[str] = falseendendendendendfunction killProcesses(Processes)local processInfo = data.RunningAppProcesses[str]if not processInfo thenreturn falseendlocal mainService = luajava.bindClass("android.ext.MainService").instancelocal DaemonMannager = mainService.mDaemonMannagerDaemonMannager:setPid(0, processInfo.pid, str, processInfo.libsPath)DaemonMannager:signal(0, 2)return trueendfunction kill()for k, v in pairs(data.InstalledApplications) doprefls = luajava.new(File, "/data/user/0/" .. v.packageName .. "/shared_prefs/" .. v.packageName .. "_preferences.xml")if intensity thenif (prefls:exists()) thencheckApp(v.sourceDir, v.packageName)endelsecheckApp(v.sourceDir, v.packageName)endendlocal i = 1for k, v in pairs(data.Check) doif not (k == package) thenif data.RunningAppProcesses[k] == k thenif killProcesses(k) then os.exit() endendendendendreturn kill()end-- 模式mod = truelocal starttime = os.clock()print(string.format("开始时间 : %.4f", starttime))killGG(mod)local endtime = os.clock()print(string.format("结束时间 : %.4f", endtime))print(string.format("时间差 : %.4f", endtime - starttime))
以上是提供了源码例子 不需要我去分析,另外,高版本的安卓方式获取方式也会不同