From 4478fd3e151ded19ea279497a20750a75edd7fb5 Mon Sep 17 00:00:00 2001 From: LoveSy Date: Thu, 5 Jan 2023 16:30:06 +0800 Subject: [PATCH] Add DexFile API --- .../org/lsposed/lspd/impl/LSPosedContext.java | 8 + .../libxposed/XposedContextWrapper.java | 8 + .../io/github/libxposed/XposedInterface.java | 193 ++++++++++++++++++ 3 files changed, 209 insertions(+) diff --git a/core/src/main/java/org/lsposed/lspd/impl/LSPosedContext.java b/core/src/main/java/org/lsposed/lspd/impl/LSPosedContext.java index 4c801644..56068dc0 100644 --- a/core/src/main/java/org/lsposed/lspd/impl/LSPosedContext.java +++ b/core/src/main/java/org/lsposed/lspd/impl/LSPosedContext.java @@ -48,12 +48,14 @@ import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.FileOutputStream; +import java.io.IOException; import java.io.InputStream; import java.lang.reflect.Constructor; import java.lang.reflect.Executable; import java.lang.reflect.Method; import java.lang.reflect.Modifier; import java.lang.reflect.Proxy; +import java.nio.ByteBuffer; import java.util.Map; import java.util.Set; import java.util.concurrent.ConcurrentHashMap; @@ -894,4 +896,10 @@ public class LSPosedContext extends XposedContext { public synchronized void log(@NonNull String message, @NonNull Throwable throwable) { Log.e(TAG, mPackageName + ": " + message, throwable); } + + @Nullable + @Override + public DexFile openDexFile(ByteBuffer dexData) throws IOException { + return null; + } } diff --git a/libxposed/api/src/main/java/io/github/libxposed/XposedContextWrapper.java b/libxposed/api/src/main/java/io/github/libxposed/XposedContextWrapper.java index 64b8e7da..1ae6784f 100644 --- a/libxposed/api/src/main/java/io/github/libxposed/XposedContextWrapper.java +++ b/libxposed/api/src/main/java/io/github/libxposed/XposedContextWrapper.java @@ -6,8 +6,10 @@ import android.content.ContextWrapper; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.Method; +import java.nio.ByteBuffer; public class XposedContextWrapper extends ContextWrapper implements XposedInterface { @@ -125,6 +127,12 @@ public class XposedContextWrapper extends ContextWrapper implements XposedInterf getBaseContext().log(message, throwable); } + @Nullable + @Override + public DexFile openDexFile(ByteBuffer dexData) throws IOException { + return getBaseContext().openDexFile(dexData); + } + @Override final protected void attachBaseContext(Context base) { if (base instanceof XposedContext || base instanceof XposedContextWrapper) { diff --git a/libxposed/api/src/main/java/io/github/libxposed/XposedInterface.java b/libxposed/api/src/main/java/io/github/libxposed/XposedInterface.java index ac673590..f4a7c3c2 100644 --- a/libxposed/api/src/main/java/io/github/libxposed/XposedInterface.java +++ b/libxposed/api/src/main/java/io/github/libxposed/XposedInterface.java @@ -3,9 +3,11 @@ package io.github.libxposed; import androidx.annotation.NonNull; import androidx.annotation.Nullable; +import java.io.IOException; import java.lang.reflect.Constructor; import java.lang.reflect.InvocationTargetException; import java.lang.reflect.Method; +import java.nio.ByteBuffer; import java.util.ConcurrentModificationException; public interface XposedInterface { @@ -143,4 +145,195 @@ public interface XposedInterface { void log(@NonNull String message); void log(@NonNull String message, @NonNull Throwable throwable); + + @Nullable + DexFile openDexFile(ByteBuffer dexData) throws IOException; + + interface DexFile extends AutoCloseable { + interface ClassDef { + @NonNull + TypeId getType(); + + int getAccessFlags(); + + @Nullable + TypeId getSuperClass(); + + @Nullable + TypeList getInterfaces(); + + @Nullable + StringId getSourceFile(); + + @NonNull + EncodedField[] getStaticFields(); + + @NonNull + EncodedField[] getInstanceFields(); + + @NonNull + EncodedMethod[] getDirectMethods(); + + @NonNull + EncodedMethod[] getVirtualMethods(); + + @Nullable + FieldAnnotation[] getFieldAnnotations(); + + @Nullable + MethodAnnotation[] getMethodAnnotations(); + + @Nullable + ParameterAnnotation[] getParameterAnnotations(); + } + + interface FieldAnnotation { + @NonNull + FieldId getField(); + + @NonNull + AnnotationItem[] getAnnotations(); + } + + interface MethodAnnotation { + @NonNull + MethodId getMethod(); + + @NonNull + AnnotationItem[] getAnnotations(); + } + + interface ParameterAnnotation { + @NonNull + MethodId getMethod(); + + @NonNull + AnnotationList getAnnotations(); + } + + interface AnnotationList { + @NonNull + AnnotationItem[] getAnnotations(); + } + + interface AnnotationItem { + int getVisibility(); + + @NonNull + Annotation getAnnotation(); + } + + interface Annotation { + @NonNull + TypeId getType(); + + @Nullable + AnnotationElement[] getElements(); + } + + interface AnnotationElement { + int getType(); + + ByteBuffer value(); + } + + interface TypeList { + @NonNull + TypeId[] getTypes(); + } + + interface TypeId { + @NonNull + StringId getDescriptor(); + } + + interface EncodedField { + @NonNull + FieldId getField(); + + int getAccessFlags(); + } + + interface EncodedMethod { + @NonNull + MethodId getMethod(); + + int getAccessFlags(); + + @NonNull + MethodId[] getInvokedMethods(); + + @NonNull + FieldId[] getAccessedFields(); + + @NonNull + FieldId[] getAssignedFields(); + + @NonNull + int[] getOpcodes(); + + @NonNull + StringId getReferencedString(); + } + + interface Id { + long getIndex(); + } + + interface StringId extends Id { + @NonNull + String getString(); + } + + interface FieldId extends Id { + @NonNull + TypeId getType(); + + @NonNull + TypeId getDeclaringClass(); + + @NonNull + StringId getName(); + } + + interface MethodId extends Id { + @NonNull + TypeId getDeclaringClass(); + + @NonNull + ProtoId getProtoType(); + + @NonNull + StringId getName(); + } + + interface ProtoId extends Id { + @NonNull + StringId getShorty(); + + @NonNull + TypeId getReturnType(); + } + + @NonNull + ClassDef[] getClassDef(); + + @NonNull + StringId[] getStringId(); + + @NonNull + TypeId[] getTypeId(); + + @NonNull + FieldId[] getFieldId(); + + @NonNull + MethodId[] getMethodId(); + + @NonNull + ProtoId[] getProtoId(); + + @NonNull + TypeList[] getTypeList(); + } }