mirror of
https://github.com/revanced/smali.git
synced 2025-05-08 18:34:32 +02:00
Change the name of the invoke method handle types
Change the names to match the name used in the smali grammar
This commit is contained in:
parent
9ccda3a1bf
commit
858d264db9
@ -31,37 +31,58 @@
|
|||||||
|
|
||||||
package org.jf.dexlib2;
|
package org.jf.dexlib2;
|
||||||
|
|
||||||
|
import com.google.common.collect.Maps;
|
||||||
import org.jf.util.ExceptionWithContext;
|
import org.jf.util.ExceptionWithContext;
|
||||||
|
|
||||||
import javax.annotation.Nonnull;
|
import javax.annotation.Nonnull;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
public class MethodHandleType {
|
public class MethodHandleType {
|
||||||
public static final int STATIC_PUT = 0;
|
public static final int STATIC_PUT = 0;
|
||||||
public static final int STATIC_GET = 1;
|
public static final int STATIC_GET = 1;
|
||||||
public static final int INSTANCE_PUT = 2;
|
public static final int INSTANCE_PUT = 2;
|
||||||
public static final int INSTANCE_GET = 3;
|
public static final int INSTANCE_GET = 3;
|
||||||
public static final int INVOKE_STATIC = 4;
|
public static final int STATIC_INVOKE = 4;
|
||||||
public static final int INVOKE_INSTANCE = 5;
|
public static final int INSTANCE_INVOKE = 5;
|
||||||
|
|
||||||
|
private static final Map<String, Integer> methodHandleTypeNames = Maps.newHashMap();
|
||||||
|
|
||||||
|
static {
|
||||||
|
methodHandleTypeNames.put("static-put", STATIC_PUT);
|
||||||
|
methodHandleTypeNames.put("static-get", STATIC_GET);
|
||||||
|
methodHandleTypeNames.put("instance-put", INSTANCE_PUT);
|
||||||
|
methodHandleTypeNames.put("instance-get", INSTANCE_GET);
|
||||||
|
methodHandleTypeNames.put("static-invoke", STATIC_INVOKE);
|
||||||
|
methodHandleTypeNames.put("instance-invoke", INSTANCE_INVOKE);
|
||||||
|
}
|
||||||
|
|
||||||
@Nonnull public static String toString(int methodHandleType) {
|
@Nonnull public static String toString(int methodHandleType) {
|
||||||
switch (methodHandleType) {
|
switch (methodHandleType) {
|
||||||
case STATIC_PUT:
|
case STATIC_PUT:
|
||||||
return "static_put";
|
return "static-put";
|
||||||
case STATIC_GET:
|
case STATIC_GET:
|
||||||
return "static_get";
|
return "static-get";
|
||||||
case INSTANCE_PUT:
|
case INSTANCE_PUT:
|
||||||
return "instance_put";
|
return "instance-put";
|
||||||
case INSTANCE_GET:
|
case INSTANCE_GET:
|
||||||
return "instance_get";
|
return "instance-get";
|
||||||
case INVOKE_STATIC:
|
case STATIC_INVOKE:
|
||||||
return "invoke_static";
|
return "static-invoke";
|
||||||
case INVOKE_INSTANCE:
|
case INSTANCE_INVOKE:
|
||||||
return "invoke_instance";
|
return "instance-invoke";
|
||||||
default:
|
default:
|
||||||
throw new InvalidMethodHandleTypeException(methodHandleType);
|
throw new InvalidMethodHandleTypeException(methodHandleType);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static int getMethodHandleType(String methodHandleType) {
|
||||||
|
Integer ret = methodHandleTypeNames.get(methodHandleType);
|
||||||
|
if (ret == null) {
|
||||||
|
throw new ExceptionWithContext("Invalid method handle type: %s", methodHandleType);
|
||||||
|
}
|
||||||
|
return ret;
|
||||||
|
}
|
||||||
|
|
||||||
public static class InvalidMethodHandleTypeException extends ExceptionWithContext {
|
public static class InvalidMethodHandleTypeException extends ExceptionWithContext {
|
||||||
private final int methodHandleType;
|
private final int methodHandleType;
|
||||||
|
|
||||||
|
@ -66,8 +66,8 @@ public class DexBackedMethodHandleReference extends BaseMethodHandleReference {
|
|||||||
case MethodHandleType.STATIC_GET:
|
case MethodHandleType.STATIC_GET:
|
||||||
case MethodHandleType.STATIC_PUT:
|
case MethodHandleType.STATIC_PUT:
|
||||||
return new DexBackedFieldReference(dexFile, memberIndex);
|
return new DexBackedFieldReference(dexFile, memberIndex);
|
||||||
case MethodHandleType.INVOKE_INSTANCE:
|
case MethodHandleType.INSTANCE_INVOKE:
|
||||||
case MethodHandleType.INVOKE_STATIC:
|
case MethodHandleType.STATIC_INVOKE:
|
||||||
return new DexBackedMethodReference(dexFile, memberIndex);
|
return new DexBackedMethodReference(dexFile, memberIndex);
|
||||||
default:
|
default:
|
||||||
throw new ExceptionWithContext("Invalid method handle type: %d", getMethodHandleType());
|
throw new ExceptionWithContext("Invalid method handle type: %d", getMethodHandleType());
|
||||||
|
@ -48,7 +48,7 @@ public interface MethodHandleReference extends Reference, Comparable<MethodHandl
|
|||||||
/**
|
/**
|
||||||
* Gets the member that is being referenced by this method handle.
|
* Gets the member that is being referenced by this method handle.
|
||||||
*
|
*
|
||||||
* For INVOKE_STATIC and INVOKE_INSTANCE method handle types, this should be a MethodReference.
|
* For STATIC_INVOKE and INSTANCE_INVOKE method handle types, this should be a MethodReference.
|
||||||
* For the other method handle types, this should be a FieldReference.
|
* For the other method handle types, this should be a FieldReference.
|
||||||
*
|
*
|
||||||
* @return A MethodReference or FieldReference, depending on the method handle type
|
* @return A MethodReference or FieldReference, depending on the method handle type
|
||||||
|
@ -71,8 +71,8 @@ public class ImmutableMethodHandleReference extends BaseMethodHandleReference im
|
|||||||
memberReference = ImmutableFieldReference.of(
|
memberReference = ImmutableFieldReference.of(
|
||||||
(FieldReference) methodHandleReference.getMemberReference());
|
(FieldReference) methodHandleReference.getMemberReference());
|
||||||
break;
|
break;
|
||||||
case MethodHandleType.INVOKE_INSTANCE:
|
case MethodHandleType.INSTANCE_INVOKE:
|
||||||
case MethodHandleType.INVOKE_STATIC:
|
case MethodHandleType.STATIC_INVOKE:
|
||||||
memberReference = ImmutableMethodReference.of(
|
memberReference = ImmutableMethodReference.of(
|
||||||
(MethodReference) methodHandleReference.getMemberReference());
|
(MethodReference) methodHandleReference.getMemberReference());
|
||||||
break;
|
break;
|
||||||
|
@ -588,8 +588,8 @@ public abstract class DexWriter<
|
|||||||
memberIndex = fieldSection.getItemIndex(
|
memberIndex = fieldSection.getItemIndex(
|
||||||
methodHandleSection.getFieldReference(methodHandleReference));
|
methodHandleSection.getFieldReference(methodHandleReference));
|
||||||
break;
|
break;
|
||||||
case MethodHandleType.INVOKE_INSTANCE:
|
case MethodHandleType.INSTANCE_INVOKE:
|
||||||
case MethodHandleType.INVOKE_STATIC:
|
case MethodHandleType.STATIC_INVOKE:
|
||||||
memberIndex = methodSection.getItemIndex(
|
memberIndex = methodSection.getItemIndex(
|
||||||
methodHandleSection.getMethodReference(methodHandleReference));
|
methodHandleSection.getMethodReference(methodHandleReference));
|
||||||
break;
|
break;
|
||||||
|
@ -68,8 +68,8 @@ public class BuilderMethodHandlePool extends BaseBuilderPool
|
|||||||
memberReference = dexBuilder.internFieldReference(
|
memberReference = dexBuilder.internFieldReference(
|
||||||
(FieldReference) methodHandleReference.getMemberReference());
|
(FieldReference) methodHandleReference.getMemberReference());
|
||||||
break;
|
break;
|
||||||
case MethodHandleType.INVOKE_INSTANCE:
|
case MethodHandleType.INSTANCE_INVOKE:
|
||||||
case MethodHandleType.INVOKE_STATIC:
|
case MethodHandleType.STATIC_INVOKE:
|
||||||
memberReference = dexBuilder.internMethodReference(
|
memberReference = dexBuilder.internMethodReference(
|
||||||
(MethodReference) methodHandleReference.getMemberReference());
|
(MethodReference) methodHandleReference.getMemberReference());
|
||||||
break;
|
break;
|
||||||
|
@ -56,8 +56,8 @@ public class MethodHandlePool extends BaseIndexPool<MethodHandleReference>
|
|||||||
case MethodHandleType.STATIC_PUT:
|
case MethodHandleType.STATIC_PUT:
|
||||||
dexPool.fieldSection.intern((FieldReference) methodHandleReference.getMemberReference());
|
dexPool.fieldSection.intern((FieldReference) methodHandleReference.getMemberReference());
|
||||||
break;
|
break;
|
||||||
case MethodHandleType.INVOKE_INSTANCE:
|
case MethodHandleType.INSTANCE_INVOKE:
|
||||||
case MethodHandleType.INVOKE_STATIC:
|
case MethodHandleType.STATIC_INVOKE:
|
||||||
dexPool.methodSection.intern((MethodReference) methodHandleReference.getMemberReference());
|
dexPool.methodSection.intern((MethodReference) methodHandleReference.getMemberReference());
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -74,7 +74,7 @@ public class CallSiteTest {
|
|||||||
new ImmutableMethodImplementation(10, ImmutableList.of(
|
new ImmutableMethodImplementation(10, ImmutableList.of(
|
||||||
new ImmutableInstruction35c(Opcode.INVOKE_CUSTOM, 0, 0, 0, 0, 0, 0,
|
new ImmutableInstruction35c(Opcode.INVOKE_CUSTOM, 0, 0, 0, 0, 0, 0,
|
||||||
new ImmutableCallSiteReference("call_site_1",
|
new ImmutableCallSiteReference("call_site_1",
|
||||||
new ImmutableMethodHandleReference(MethodHandleType.INVOKE_STATIC,
|
new ImmutableMethodHandleReference(MethodHandleType.STATIC_INVOKE,
|
||||||
new ImmutableMethodReference("Lcls1", "loader",
|
new ImmutableMethodReference("Lcls1", "loader",
|
||||||
ImmutableList.of("Ljava/lang/invoke/Lookup;",
|
ImmutableList.of("Ljava/lang/invoke/Lookup;",
|
||||||
"Ljava/lang/String;",
|
"Ljava/lang/String;",
|
||||||
@ -96,7 +96,7 @@ public class CallSiteTest {
|
|||||||
|
|
||||||
BuilderCallSiteReference callSite = dexBuilder.internCallSite(new ImmutableCallSiteReference("call_site_1",
|
BuilderCallSiteReference callSite = dexBuilder.internCallSite(new ImmutableCallSiteReference("call_site_1",
|
||||||
new ImmutableMethodHandleReference(
|
new ImmutableMethodHandleReference(
|
||||||
MethodHandleType.INVOKE_STATIC,
|
MethodHandleType.STATIC_INVOKE,
|
||||||
new ImmutableMethodReference("Lcls1", "loader", ImmutableList.of("Ljava/lang/invoke/Lookup;",
|
new ImmutableMethodReference("Lcls1", "loader", ImmutableList.of("Ljava/lang/invoke/Lookup;",
|
||||||
"Ljava/lang/String;",
|
"Ljava/lang/String;",
|
||||||
"Ljava/lang/invoke/MethodType;"),
|
"Ljava/lang/invoke/MethodType;"),
|
||||||
|
Loading…
x
Reference in New Issue
Block a user