mirror of https://github.com/FongMi/TV.git
parent
a457780403
commit
d61b810dce
@ -0,0 +1 @@ |
||||
/build |
||||
@ -0,0 +1,13 @@ |
||||
plugins { |
||||
id 'com.android.library' |
||||
} |
||||
|
||||
android { |
||||
namespace 'com.fongmi.hook' |
||||
compileSdk 33 |
||||
|
||||
defaultConfig { |
||||
minSdk 21 |
||||
targetSdk 28 |
||||
} |
||||
} |
||||
@ -0,0 +1,2 @@ |
||||
<?xml version="1.0" encoding="utf-8"?> |
||||
<manifest /> |
||||
@ -0,0 +1,38 @@ |
||||
package com.fongmi.hook; |
||||
|
||||
import android.content.pm.PackageInfo; |
||||
import android.content.pm.Signature; |
||||
|
||||
import java.lang.reflect.InvocationHandler; |
||||
import java.lang.reflect.Method; |
||||
|
||||
public class Handler implements InvocationHandler { |
||||
|
||||
private String sign; |
||||
private Object base; |
||||
private String pkg; |
||||
|
||||
public Handler(Object base, String sign, String pkg) { |
||||
try { |
||||
this.base = base; |
||||
this.sign = sign; |
||||
this.pkg = pkg; |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
|
||||
@Override |
||||
public Object invoke(Object proxy, Method method, Object[] args) throws Throwable { |
||||
if ("getPackageInfo".equals(method.getName())) { |
||||
String pkgName = (String) args[0]; |
||||
Number flag = (Number) args[1]; |
||||
if (flag.intValue() == 64 && this.pkg.equals(pkgName)) { |
||||
PackageInfo info = (PackageInfo) method.invoke(this.base, args); |
||||
info.signatures[0] = new Signature(sign); |
||||
return info; |
||||
} |
||||
} |
||||
return method.invoke(this.base, args); |
||||
} |
||||
} |
||||
@ -0,0 +1,31 @@ |
||||
package com.fongmi.hook; |
||||
|
||||
import android.content.Context; |
||||
import android.content.pm.PackageManager; |
||||
|
||||
import java.lang.reflect.Field; |
||||
import java.lang.reflect.Method; |
||||
import java.lang.reflect.Proxy; |
||||
|
||||
public class Hook { |
||||
|
||||
public static void pm(Context context, String sign) { |
||||
try { |
||||
Class<?> activityThreadClass = Class.forName("android.app.ActivityThread"); |
||||
Method currentActivityThreadMethod = activityThreadClass.getDeclaredMethod("currentActivityThread", new Class[0]); |
||||
Object currentActivityThread = currentActivityThreadMethod.invoke(null, new Object[0]); |
||||
Field sPackageManagerField = activityThreadClass.getDeclaredField("sPackageManager"); |
||||
sPackageManagerField.setAccessible(true); |
||||
Object sPackageManager = sPackageManagerField.get(currentActivityThread); |
||||
Class<?> iPackageManagerInterface = Class.forName("android.content.pm.IPackageManager"); |
||||
Object proxy = Proxy.newProxyInstance(iPackageManagerInterface.getClassLoader(), new Class[]{iPackageManagerInterface}, new Handler(sPackageManager, sign, context.getPackageName())); |
||||
sPackageManagerField.set(currentActivityThread, proxy); |
||||
PackageManager pm = context.getPackageManager(); |
||||
Field mPmField = pm.getClass().getDeclaredField("mPM"); |
||||
mPmField.setAccessible(true); |
||||
mPmField.set(pm, proxy); |
||||
} catch (Exception e) { |
||||
e.printStackTrace(); |
||||
} |
||||
} |
||||
} |
||||
Loading…
Reference in new issue