Skip to content

Commit

Permalink
fix Indy arg calls to modify.
Browse files Browse the repository at this point in the history
  • Loading branch information
wagyourtail committed May 13, 2024
1 parent b37f1b8 commit de8f07e
Show file tree
Hide file tree
Showing 27 changed files with 154 additions and 63 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package xyz.wagyourtail.downgradetest;

import java.util.function.Function;
import java.util.function.Supplier;

public class TestException {

public static void main(String[] args) {
Expand All @@ -20,12 +23,17 @@ public static void main(String[] args) {
}

new InternalError("test", new IndexOutOfBoundsException(1L));

Function<Long, IndexOutOfBoundsException> IOOBE = IndexOutOfBoundsException::new;
IOOBE.apply(0L);

try {
throw new InternalError("test", new IndexOutOfBoundsException(1L));
} catch (InternalError e) {
System.out.println(e);
}


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -219,7 +219,7 @@ public static void main(String[] args) throws IOException, URISyntaxException {
}
if (!unmatchedStubs.isEmpty()) {
var unmatched = Path.of("./coverage/" + stubVersion + "/unmatched.txt");
writeList(unmatchedStubs.stream().map(methodStubPair -> new MemberInfo("unknown", FullyQualifiedMemberNameAndDesc.fromMethod(methodStubPair), false, false)).collect(Collectors.toList()), unmatched);
writeList(unmatchedStubs.stream().map(methodStubPair -> new MemberInfo("unknown", FullyQualifiedMemberNameAndDesc.of(methodStubPair), false, false)).collect(Collectors.toList()), unmatched);
}

} catch (IOException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class J_I_PrintWriter {

@Modify(ref = @Ref(value = "Ljava/io/PrintWriter;", member = "<init>", desc = "(Ljava/io/OutputStream;ZLjava/nio/charset/Charset;)V"))
public static void init(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();
// stack: PrintWriter, OutputStream, boolean, Charset
list.add(new InsnNode(Opcodes.DUP2_X1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,12 @@
import org.objectweb.asm.tree.*;
import xyz.wagyourtail.jvmdg.version.Modify;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.nio.channels.ReadableByteChannel;
import java.nio.charset.Charset;
import java.util.Scanner;

public class J_U_Scanner {

// @Stub(ref = @Ref(value = "Ljava/util/Scanner;", member = "<init>"))
// public static Scanner init(ReadableByteChannel source, Charset charset) {
// return new Scanner(source, charset.name());
// }

@Modify(ref = @Ref(value = "Ljava/util/Scanner;", member = "<init>", desc = "(Ljava/nio/channels/ReadableByteChannel;Ljava/nio/charset/Charset;)V"))
public static void init(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();
// stack: Scanner, ReadableByteChannel, Charset
// call:J_N_C_Channels.newReader(ReadableByteChannel, Charset)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,12 @@
import org.objectweb.asm.tree.*;
import xyz.wagyourtail.jvmdg.version.Modify;
import xyz.wagyourtail.jvmdg.version.Ref;
import xyz.wagyourtail.jvmdg.version.Stub;

import java.util.NoSuchElementException;

public class J_U_NoSuchElementException {

@Modify(ref = @Ref(value = "Ljava/util/NoSuchElementException;", member = "<init>", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V"))
public static void init(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();
// stack: NoSuchElementException, String, Throwable
list.add(new InsnNode(Opcodes.DUP_X2));
Expand All @@ -40,7 +37,7 @@ public static void init(MethodNode mnode, int i) {

@Modify(ref = @Ref(value = "java/util/NoSuchElementException", member = "<init>", desc = "(Ljava/lang/Throwable;)V"))
public static void init2(MethodNode mNode, int i) {
AbstractInsnNode node = mNode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mNode.instructions.get(i);
InsnList list = new InsnList();
// stack: NoSuchElementException, Throwable
list.add(new InsnNode(Opcodes.DUP2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ public class J_L_IndexOutOfBoundsException {

@Modify(ref = @Ref(value = "java/lang/IndexOutOfBoundsException", member = "<init>", desc = "(J)V"))
public static void init(MethodNode mNode, int i) {
AbstractInsnNode node = mNode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mNode.instructions.get(i);
InsnList list = new InsnList();
// string concat factory, "Index out of range: \u0001"
list.add(new InvokeDynamicInsnNode(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public static void bootstrap(MethodNode mnode, int i, ClassNode cnode) {
}

private static void makeEquals(ClassNode cnode, String mname, String desc, Type recordClass, ArrayList<Handle> getters) {
var visitor = cnode.visitMethod(Constants.synthetic(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC), mname, desc, null, null);
var visitor = cnode.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, mname, desc, null, null);
visitor.visitCode();
visitor.visitVarInsn(Opcodes.ALOAD, 0);
visitor.visitVarInsn(Opcodes.ALOAD, 1);
Expand Down Expand Up @@ -117,7 +117,7 @@ private static void makeEquals(ClassNode cnode, String mname, String desc, Type
}

private static void makeHashCode(ClassNode cnode, String mname, String desc, Type recordClass, ArrayList<Handle> getters) {
var visitor = cnode.visitMethod(Constants.synthetic(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC), mname, desc, null, null);
var visitor = cnode.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, mname, desc, null, null);
visitor.visitCode();
visitor.visitLdcInsn(getters.size());
visitor.visitTypeInsn(Opcodes.ANEWARRAY, "java/lang/Object");
Expand Down Expand Up @@ -224,7 +224,7 @@ private static void makeHashCode(ClassNode cnode, String mname, String desc, Typ
}

private static void makeToString(ClassNode cnode, String mname, String desc, Type recordClass, String fieldNames, List<Handle> getters) {
var visitor = cnode.visitMethod(Constants.synthetic(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC), mname, desc, null, null);
var visitor = cnode.visitMethod(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC, mname, desc, null, null);
visitor.visitCode();
visitor.visitVarInsn(Opcodes.ALOAD, 0);
String last = recordClass.getInternalName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class J_I_InvalidClassException {

@Modify(ref = @Ref(value = "Ljava/io/InvalidClassException;", member = "<init>", desc = "(Ljava/lang/String;Ljava/lang/String;Ljava/lang/Throwable;)V;"))
public static void init(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();
// stack: InvalidClassException, String (cname), String (reason), Throwable
list.add(new InsnNode(Opcodes.DUP2_X2));
Expand Down Expand Up @@ -51,7 +51,7 @@ public static void init(MethodNode mnode, int i) {

@Modify(ref = @Ref(value = "Ljava/io/InvalidClassException;", member = "<init>", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V;"))
public static void init2(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();
// stack: InvalidClassException, String (reason), Throwable
list.add(new InsnNode(Opcodes.DUP_X2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class J_I_InvalidObjectException {

@Modify(ref = @Ref(value = "Ljava/io/InvalidObjectException;", member = "<init>", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V;"))
public static void init(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();
// stack: InvalidObjectException, String, Throwable
list.add(new InsnNode(Opcodes.DUP_X2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class J_I_ObjectStreamException {

@Modify(ref = @Ref(value = "Ljava/io/ObjectStreamException;", member = "<init>", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V;"))
public static void init(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();
// stack: ObjectStreamException, String, Throwable
list.add(new InsnNode(Opcodes.DUP_X2));
Expand All @@ -36,7 +36,7 @@ public static void init(MethodNode mnode, int i) {

@Modify(ref = @Ref(value = "Ljava/io/ObjectStreamException;", member = "<init>", desc = "(Ljava/lang/Throwable;)V;"))
public static void init2(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();
// stack: ObjectStreamException, Throwable
list.add(new InsnNode(Opcodes.DUP2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class J_N_S_SSLHandshakeException {

@Modify(ref = @Ref(value = "Ljavax/net/ssl/SSLHandshakeException;", member = "<init>", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V;"))
public static void init(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();

// stack: SSLHandshakeException, String (reason), Throwable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class J_N_S_SSLKeyException {

@Modify(ref = @Ref(value = "Ljavax/net/ssl/SSLKeyException;", member = "<init>", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V;"))
public static void init(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();

// stack: SSLKeyException, String (reason), Throwable
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class J_N_SocketException {

@Modify(ref = @Ref(value = "Ljava/net/SocketException;", member = "<init>", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V;"))
public static void init(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();
// stack: SocketException, String, Throwable
list.add(new InsnNode(Opcodes.DUP_X2));
Expand All @@ -36,7 +36,7 @@ public static void init(MethodNode mnode, int i) {

@Modify(ref = @Ref(value = "Ljava/net/SocketException;", member = "<init>", desc = "(Ljava/lang/Throwable;)V;"))
public static void init2(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();
// stack: SocketException, Throwable
list.add(new InsnNode(Opcodes.DUP2));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ public class J_S_InvalidParameterException {

@Modify(ref = @Ref(value = "Ljava/security/InvalidParameterException;", member = "<init>", desc = "(Ljava/lang/String;Ljava/lang/Throwable;)V;"))
public static void init(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();
// stack: InvalidParameterException, String, Throwable
list.add(new InsnNode(Opcodes.DUP_X2));
Expand All @@ -34,7 +34,7 @@ public static void init(MethodNode mnode, int i) {

@Modify(ref = @Ref(value = "Ljava/security/InvalidParameterException;", member = "<init>", desc = "(Ljava/lang/Throwable;)V;"))
public static void init1(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();
// stack: InvalidParameterException, Throwable
list.add(new InsnNode(Opcodes.DUP_X1));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ public StringConcatMethodNode(String args, Deque<Type> types, int index) {
if (index > 0) {
this.name += index;
}
this.access = Constants.synthetic(Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC);
this.access = Opcodes.ACC_PRIVATE | Opcodes.ACC_STATIC;
this.desc = Type.getMethodDescriptor(Type.getType(String.class), types.toArray(new Type[0]));
init(args, types);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class J_L_IndexOutOfBoundsException {

@Modify(ref = @Ref(value = "java/lang/IndexOutOfBoundsException", member = "<init>", desc = "(I)V"))
public static void init(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();

// stack: IndexOutOfBoundsException, int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
public class J_L_Thread {

private static final ThreadLocal<Object> old = new ThreadLocal<>();
private static final MethodHandles.Lookup impl_lookup = Utils.getImplLookup();

@Stub(ref = @Ref("Ljava/lang/Thread;"))
public static void onSpinWait() {
Expand All @@ -26,7 +27,7 @@ public static void onSpinWait() {

@Modify(ref = @Ref(value = "java/lang/Thread", member = "<init>", desc = "(Ljava/lang/ThreadGroup;Ljava/lang/Runnable;Ljava/lang/String;JZ)V"))
public static void init(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();

// stack: Thread, ThreadGroup, Runnable, String, long, boolean
Expand All @@ -46,7 +47,6 @@ public static void preInit(boolean inheritThreadLocals) {
if (!inheritThreadLocals) {
Thread current = Thread.currentThread();
try {
MethodHandles.Lookup impl_lookup = Utils.getImplLookup();
Class<?> map = Class.forName("java.lang.ThreadLocal$ThreadLocalMap");
MethodHandle setter = impl_lookup.findSetter(Thread.class, "inheritableThreadLocals", map);
MethodHandle getter = impl_lookup.findGetter(Thread.class, "inheritableThreadLocals", map);
Expand All @@ -65,7 +65,6 @@ public static void postInit() {
if (o != null) {
Thread current = Thread.currentThread();
try {
MethodHandles.Lookup impl_lookup = Utils.getImplLookup();
Class<?> map = Class.forName("java.lang.ThreadLocal$ThreadLocalMap");
MethodHandle setter = impl_lookup.findSetter(Thread.class, "inheritableThreadLocals", map);
setter.invoke(current, o);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class J_M_BigInteger {

@Modify(ref = @Ref(value = "Ljava/math/BigInteger;", member = "<init>", desc = "([BII)V"))
public static void init(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();

// stack: BigInteger, byte[], (start) int, (len) int
Expand All @@ -42,7 +42,7 @@ public static void init(MethodNode mnode, int i) {

@Modify(ref = @Ref(value = "Ljava/math/BigInteger;", member = "<init>", desc = "(I[BII)V"))
public static void init2(MethodNode mnode, int i) {
AbstractInsnNode node = mnode.instructions.get(i);
MethodInsnNode node = (MethodInsnNode) mnode.instructions.get(i);
InsnList list = new InsnList();

// stack: BigInteger, int, byte[], (start) int, (len) int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -395,7 +395,7 @@ private void createAccessors(ClassNode clazz, Map<String, Object> fields) {
} else {

// create new package-private method to call private method
MethodVisitor mv = clazz.visitMethod(Constants.synthetic(isStatic ? Opcodes.ACC_STATIC : 0), "jvmdowngrader$nest$" + clazz.name.replace("/", "_") + "$" + name, desc, null, null);
MethodVisitor mv = clazz.visitMethod(isStatic ? Opcodes.ACC_STATIC : 0, "jvmdowngrader$nest$" + clazz.name.replace("/", "_") + "$" + name, desc, null, null);
mv.visitCode();
if (!isStatic) {
mv.visitVarInsn(Opcodes.ALOAD, 0);
Expand Down Expand Up @@ -430,7 +430,7 @@ private void createAccessors(ClassNode clazz, Map<String, Object> fields) {
}

// create new package-private method to get field
MethodVisitor mv = clazz.visitMethod(Constants.synthetic(isStatic ? Opcodes.ACC_STATIC : 0), "jvmdowngrader$nest$" + clazz.name.replace("/", "_") + "$get$" + field, "()" + desc, null, null);
MethodVisitor mv = clazz.visitMethod(isStatic ? Opcodes.ACC_STATIC : 0, "jvmdowngrader$nest$" + clazz.name.replace("/", "_") + "$get$" + field, "()" + desc, null, null);
mv.visitCode();
if (!isStatic) {
mv.visitVarInsn(Opcodes.ALOAD, 0);
Expand All @@ -440,7 +440,7 @@ private void createAccessors(ClassNode clazz, Map<String, Object> fields) {
mv.visitEnd();

// create new package-private method to set field
mv = clazz.visitMethod(Constants.synthetic(isStatic ? Opcodes.ACC_STATIC : 0), "jvmdowngrader$nest$" + clazz.name.replace("/", "_") + "$set$" + field, "(" + desc + ")V", null, null);
mv = clazz.visitMethod(isStatic ? Opcodes.ACC_STATIC : 0, "jvmdowngrader$nest$" + clazz.name.replace("/", "_") + "$set$" + field, "(" + desc + ")V", null, null);
mv.visitCode();
if (!isStatic) {
mv.visitVarInsn(Opcodes.ALOAD, 0);
Expand All @@ -467,7 +467,7 @@ public void fixNestsForParent(ClassNode clazz, Function<String, ClassNode> getRe
sb.deleteCharAt(sb.length() - 1);

clazz.visitField(
Constants.synthetic(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL),
Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL,
"jvmdowngrader$nestMembers",
"Ljava/lang/String;",
null,
Expand All @@ -494,7 +494,7 @@ public void fixNestsForChild(ClassNode clazz, Function<String, ClassNode> getRea

// create nest members synthetic class
clazz.visitField(
Constants.synthetic(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL),
Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL,
"jvmdowngrader$nestHost",
"Ljava/lang/String;",
null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ public void recordRemover(ClassNode node) {
// value.deleteCharAt(value.length() - 1);
// node.recordComponents = null;
// node.visitField(
// Constants.synthetic(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL),
// Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL,
// "jvmdowngrader$recordComponents",
// "Ljava/lang/String;",
// null,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ public void unseal(ClassNode node) {
sb.deleteCharAt(sb.length() - 1);
node.permittedSubclasses = null;
node.visitField(
Constants.synthetic(Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL),
Opcodes.ACC_PUBLIC | Opcodes.ACC_STATIC | Opcodes.ACC_FINAL,
"jvmdowngrader$permittedSubclasses",
"Ljava/lang/String;",
null,
Expand Down
Loading

0 comments on commit de8f07e

Please sign in to comment.