Add method hook interface (not implemented yet)
This commit is contained in:
parent
e4aa920424
commit
80987dee03
|
|
@ -1275,7 +1275,7 @@ public class XResources extends XposedResources {
|
|||
* Mainly used when inflating layouts.
|
||||
* @hide
|
||||
*/
|
||||
public static class XTypedArray extends XTypedArraySuperClass {
|
||||
public static class XTypedArray extends XposedTypedArray {
|
||||
|
||||
public XTypedArray(Resources resources) {
|
||||
super(resources);
|
||||
|
|
|
|||
|
|
@ -5,6 +5,9 @@ import android.content.ContextWrapper;
|
|||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public class XposedContextWrapper extends ContextWrapper implements XposedInterface {
|
||||
|
||||
XposedContextWrapper(XposedContext base) {
|
||||
|
|
@ -15,14 +18,13 @@ public class XposedContextWrapper extends ContextWrapper implements XposedInterf
|
|||
super(base);
|
||||
}
|
||||
|
||||
@Override
|
||||
final public XposedContext getBaseContext() {
|
||||
return (XposedContext) super.getBaseContext();
|
||||
final long getAPIVersion() {
|
||||
return 100;
|
||||
}
|
||||
|
||||
@Override
|
||||
final public void hook() {
|
||||
getBaseContext().hook();
|
||||
final public XposedContext getBaseContext() {
|
||||
return (XposedContext) super.getBaseContext();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
|
|
@ -42,6 +44,36 @@ public class XposedContextWrapper extends ContextWrapper implements XposedInterf
|
|||
return getBaseContext().implementationVersionCode();
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodUnhooker<BeforeMethodHooker<Method>, Method> hookBefore(@NonNull Method origin, @NonNull BeforeMethodHooker<Method> hooker) {
|
||||
return getBaseContext().hookBefore(origin, hooker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodUnhooker<AfterMethodHooker<Method>, Method> hookAfter(@NonNull Method origin, @NonNull AfterMethodHooker<Method> hooker) {
|
||||
return getBaseContext().hookAfter(origin, hooker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public MethodUnhooker<MethodHooker<Method>, Method> hook(@NonNull Method origin, @NonNull MethodHooker<Method> hooker) {
|
||||
return getBaseContext().hook(origin, hooker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> MethodUnhooker<BeforeMethodHooker<Constructor<T>>, Constructor<T>> hookBefore(@NonNull Constructor<T> origin, @NonNull BeforeMethodHooker<Constructor<T>> hooker) {
|
||||
return getBaseContext().hookBefore(origin, hooker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> MethodUnhooker<AfterMethodHooker<Constructor<T>>, Constructor<T>> hookAfter(@NonNull Constructor<T> origin, @NonNull AfterMethodHooker<Constructor<T>> hooker) {
|
||||
return getBaseContext().hookAfter(origin, hooker);
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> MethodUnhooker<MethodHooker<Constructor<T>>, Constructor<T>> hook(@NonNull Constructor<T> origin, @NonNull MethodHooker<Constructor<T>> hooker) {
|
||||
return getBaseContext().hook(origin, hooker);
|
||||
}
|
||||
|
||||
@Override
|
||||
final public void log(@NonNull String message) {
|
||||
getBaseContext().log(message);
|
||||
|
|
|
|||
|
|
@ -1,17 +1,111 @@
|
|||
package io.github.libxposed;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
|
||||
public interface XposedInterface {
|
||||
interface BeforeHookCallback<T> {
|
||||
@NonNull
|
||||
T getOrigin();
|
||||
|
||||
long API_VERSION = 100;
|
||||
@Nullable
|
||||
Object getThis();
|
||||
|
||||
void hook();
|
||||
@NonNull
|
||||
Object[] getArgs();
|
||||
|
||||
void returnAndSkip(@Nullable Object returnValue);
|
||||
|
||||
void throwAndSkip(@Nullable Throwable throwable);
|
||||
|
||||
@Nullable
|
||||
Object invokeOrigin(@Nullable Object thisObject, Object[] args);
|
||||
|
||||
<U> void setExtra(String key, @Nullable U value);
|
||||
}
|
||||
|
||||
interface AfterHookCallback<T> {
|
||||
@NonNull
|
||||
T getOrigin();
|
||||
|
||||
@Nullable
|
||||
Object getThis();
|
||||
|
||||
@NonNull
|
||||
Object[] getArgs();
|
||||
|
||||
@Nullable
|
||||
Object getResult();
|
||||
|
||||
@Nullable
|
||||
Throwable getThrowable();
|
||||
|
||||
boolean isSkipped();
|
||||
|
||||
void setResult(@Nullable Object result);
|
||||
|
||||
void setThrowable(@Nullable Throwable throwable);
|
||||
|
||||
@Nullable
|
||||
Object invokeOrigin(@Nullable Object thisObject, Object[] args);
|
||||
|
||||
@Nullable
|
||||
<U> U getExtra(String key);
|
||||
}
|
||||
|
||||
interface PriorityMethodHooker {
|
||||
int PRIORITY_DEFAULT = 50;
|
||||
|
||||
default int getPriority() {
|
||||
return PRIORITY_DEFAULT;
|
||||
}
|
||||
}
|
||||
|
||||
interface BeforeMethodHooker<T> extends PriorityMethodHooker {
|
||||
void before(@NonNull BeforeHookCallback<T> callback);
|
||||
}
|
||||
|
||||
interface AfterMethodHooker<T> extends PriorityMethodHooker {
|
||||
void after(@NonNull AfterHookCallback<T> callback);
|
||||
}
|
||||
|
||||
interface MethodHooker<T> extends BeforeMethodHooker<T>, AfterMethodHooker<T> {
|
||||
}
|
||||
|
||||
interface MethodUnhooker<T, U> {
|
||||
@NonNull
|
||||
U getOrigin();
|
||||
|
||||
@NonNull
|
||||
T getHooker();
|
||||
|
||||
void unhook();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
String implementationName();
|
||||
|
||||
@NonNull
|
||||
String implementationVersion();
|
||||
|
||||
@NonNull String implementationName();
|
||||
@NonNull String implementationVersion();
|
||||
long implementationVersionCode();
|
||||
|
||||
MethodUnhooker<BeforeMethodHooker<Method>, Method> hookBefore(@NonNull Method origin, @NonNull BeforeMethodHooker<Method> hooker);
|
||||
|
||||
MethodUnhooker<AfterMethodHooker<Method>, Method> hookAfter(@NonNull Method origin, @NonNull AfterMethodHooker<Method> hooker);
|
||||
|
||||
MethodUnhooker<MethodHooker<Method>, Method> hook(@NonNull Method origin, @NonNull MethodHooker<Method> hooker);
|
||||
|
||||
<T> MethodUnhooker<BeforeMethodHooker<Constructor<T>>, Constructor<T>> hookBefore(@NonNull Constructor<T> origin, @NonNull BeforeMethodHooker<Constructor<T>> hooker);
|
||||
|
||||
<T> MethodUnhooker<AfterMethodHooker<Constructor<T>>, Constructor<T>> hookAfter(@NonNull Constructor<T> origin, @NonNull AfterMethodHooker<Constructor<T>> hooker);
|
||||
|
||||
<T> MethodUnhooker<MethodHooker<Constructor<T>>, Constructor<T>> hook(@NonNull Constructor<T> origin, @NonNull MethodHooker<Constructor<T>> hooker);
|
||||
|
||||
void log(@NonNull String message);
|
||||
|
||||
void log(@NonNull String message, @NonNull Throwable throwable);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -11,32 +11,50 @@ import androidx.annotation.Nullable;
|
|||
public interface XposedModuleInterface {
|
||||
interface ModuleLoadedParam {
|
||||
boolean isSystemServer();
|
||||
@NonNull String getProcessName();
|
||||
@NonNull String getAppDataDir();
|
||||
@Nullable Bundle getExtras();
|
||||
|
||||
@NonNull
|
||||
String getProcessName();
|
||||
|
||||
@NonNull
|
||||
String getAppDataDir();
|
||||
|
||||
@Nullable
|
||||
Bundle getExtras();
|
||||
}
|
||||
|
||||
interface PackageLoadedParam {
|
||||
@NonNull String getPackageName();
|
||||
@NonNull ApplicationInfo getAppInfo();
|
||||
@NonNull ClassLoader getClassLoader();
|
||||
@NonNull String getProcessName();
|
||||
@NonNull
|
||||
String getPackageName();
|
||||
|
||||
@NonNull
|
||||
ApplicationInfo getAppInfo();
|
||||
|
||||
@NonNull
|
||||
ClassLoader getClassLoader();
|
||||
|
||||
@NonNull
|
||||
String getProcessName();
|
||||
|
||||
boolean isFirstApplication();
|
||||
@Nullable Bundle getExtras();
|
||||
|
||||
@Nullable
|
||||
Bundle getExtras();
|
||||
}
|
||||
|
||||
interface ResourcesLoadedParam {
|
||||
@NonNull String getPackageName();
|
||||
@NonNull XposedResources getResources();
|
||||
@Nullable Bundle getExtras();
|
||||
@NonNull
|
||||
String getPackageName();
|
||||
|
||||
@NonNull
|
||||
XposedResources getResources();
|
||||
|
||||
@Nullable
|
||||
Bundle getExtras();
|
||||
}
|
||||
|
||||
default void onPackageLoaded(@NonNull PackageLoadedParam param) {
|
||||
|
||||
}
|
||||
|
||||
default void onResourceLoaded(@NonNull ResourcesLoadedParam param) {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -42,6 +42,8 @@ import java.io.File;
|
|||
import java.io.FileInputStream;
|
||||
import java.io.FileOutputStream;
|
||||
import java.io.InputStream;
|
||||
import java.lang.reflect.Constructor;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.ConcurrentHashMap;
|
||||
|
|
@ -720,11 +722,6 @@ public class LSPosedContext extends XposedContext {
|
|||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void hook() {
|
||||
throw new AbstractMethodError();
|
||||
}
|
||||
|
||||
@NonNull
|
||||
@Override
|
||||
public String implementationName() {
|
||||
|
|
@ -742,6 +739,42 @@ public class LSPosedContext extends XposedContext {
|
|||
return 0;
|
||||
}
|
||||
|
||||
// TODO
|
||||
@Override
|
||||
public MethodUnhooker<BeforeMethodHooker<Method>, Method> hookBefore(@NonNull Method origin, @NonNull BeforeMethodHooker<Method> hooker) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO
|
||||
@Override
|
||||
public MethodUnhooker<AfterMethodHooker<Method>, Method> hookAfter(@NonNull Method origin, @NonNull AfterMethodHooker<Method> hooker) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO
|
||||
@Override
|
||||
public MethodUnhooker<MethodHooker<Method>, Method> hook(@NonNull Method origin, @NonNull MethodHooker<Method> hooker) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO
|
||||
@Override
|
||||
public <T> MethodUnhooker<BeforeMethodHooker<Constructor<T>>, Constructor<T>> hookBefore(@NonNull Constructor<T> origin, @NonNull BeforeMethodHooker<Constructor<T>> hooker) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO
|
||||
@Override
|
||||
public <T> MethodUnhooker<AfterMethodHooker<Constructor<T>>, Constructor<T>> hookAfter(@NonNull Constructor<T> origin, @NonNull AfterMethodHooker<Constructor<T>> hooker) {
|
||||
return null;
|
||||
}
|
||||
|
||||
// TODO
|
||||
@Override
|
||||
public <T> MethodUnhooker<MethodHooker<Constructor<T>>, Constructor<T>> hook(@NonNull Constructor<T> origin, @NonNull MethodHooker<Constructor<T>> hooker) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void log(@NonNull String message) {
|
||||
Log.i(TAG, mPackageName + ": " + message);
|
||||
|
|
|
|||
Loading…
Reference in New Issue