From 702c10eff4223b3f0d114a7a91cda07be67ec4f1 Mon Sep 17 00:00:00 2001 From: Nullptr <52071314+Dr-TSNG@users.noreply.github.com> Date: Thu, 5 Jan 2023 20:16:36 +0800 Subject: [PATCH] Move DexParser to util package --- .../org/lsposed/lspd/impl/LSPosedContext.java | 1 + .../io/github/libxposed/XposedContext.java | 1 - .../libxposed/XposedContextWrapper.java | 2 + .../io/github/libxposed/XposedInterface.java | 190 +---------------- .../io/github/libxposed/util/DexParser.java | 195 ++++++++++++++++++ 5 files changed, 200 insertions(+), 189 deletions(-) create mode 100644 libxposed/api/src/main/java/io/github/libxposed/util/DexParser.java 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 e320ced7..babb6195 100644 --- a/core/src/main/java/org/lsposed/lspd/impl/LSPosedContext.java +++ b/core/src/main/java/org/lsposed/lspd/impl/LSPosedContext.java @@ -66,6 +66,7 @@ import de.robv.android.xposed.XposedInit; import io.github.libxposed.XposedContext; import io.github.libxposed.XposedModule; import io.github.libxposed.XposedModuleInterface; +import io.github.libxposed.util.DexParser; public class LSPosedContext extends XposedContext { diff --git a/libxposed/api/src/main/java/io/github/libxposed/XposedContext.java b/libxposed/api/src/main/java/io/github/libxposed/XposedContext.java index 321aeae4..7465c0f5 100644 --- a/libxposed/api/src/main/java/io/github/libxposed/XposedContext.java +++ b/libxposed/api/src/main/java/io/github/libxposed/XposedContext.java @@ -5,4 +5,3 @@ import android.content.Context; public abstract class XposedContext extends Context implements XposedInterface { } - 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 fe317d02..a8899c7c 100644 --- a/libxposed/api/src/main/java/io/github/libxposed/XposedContextWrapper.java +++ b/libxposed/api/src/main/java/io/github/libxposed/XposedContextWrapper.java @@ -11,6 +11,8 @@ import java.lang.reflect.Constructor; import java.lang.reflect.Method; import java.nio.ByteBuffer; +import io.github.libxposed.util.DexParser; + public class XposedContextWrapper extends ContextWrapper implements XposedInterface { XposedContextWrapper(XposedContext base) { 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 f766b184..31a8430a 100644 --- a/libxposed/api/src/main/java/io/github/libxposed/XposedInterface.java +++ b/libxposed/api/src/main/java/io/github/libxposed/XposedInterface.java @@ -10,6 +10,8 @@ import java.lang.reflect.Method; import java.nio.ByteBuffer; import java.util.ConcurrentModificationException; +import io.github.libxposed.util.DexParser; + public interface XposedInterface { int API = 100; @@ -148,192 +150,4 @@ public interface XposedInterface { @Nullable DexParser parseDex(ByteBuffer dexData) throws IOException; - - interface DexParser 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 { - int 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(); - } } diff --git a/libxposed/api/src/main/java/io/github/libxposed/util/DexParser.java b/libxposed/api/src/main/java/io/github/libxposed/util/DexParser.java new file mode 100644 index 00000000..7a080ebb --- /dev/null +++ b/libxposed/api/src/main/java/io/github/libxposed/util/DexParser.java @@ -0,0 +1,195 @@ +package io.github.libxposed.util; + +import androidx.annotation.NonNull; +import androidx.annotation.Nullable; + +import java.nio.ByteBuffer; + +public interface DexParser 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 { + int 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(); +}