From ed1ef7599b4a800d53134acba569010a00a8fe4b Mon Sep 17 00:00:00 2001 From: xmdhs Date: Sat, 14 Oct 2023 16:16:10 +0000 Subject: [PATCH 1/4] fix 1.20.2 can not view skin --- .../transform/support/YggdrasilKeyTransformUnit.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java b/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java index 8145491..f881dad 100644 --- a/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java +++ b/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java @@ -47,6 +47,7 @@ public class YggdrasilKeyTransformUnit implements TransformUnit { public static final List PUBLIC_KEYS = new CopyOnWriteArrayList<>(); + private boolean isSignature = false; static { PUBLIC_KEYS.add(loadMojangPublicKey()); @@ -139,6 +140,9 @@ public Optional transform(ClassLoader classLoader, String classNam return Optional.of(new ClassVisitor(ASM9, writer) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { + if ("signature".equals(name)) { + isSignature = true; + } if ("isSignatureValid".equals(name) && "(Ljava/security/PublicKey;)Z".equals(desc)) { ctx.markModified(); @@ -170,9 +174,9 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); mv.visitCode(); mv.visitVarInsn(ALOAD, 1); - mv.visitMethodInsn(INVOKEVIRTUAL, "com/mojang/authlib/properties/Property", "getValue", "()Ljava/lang/String;", false); + mv.visitMethodInsn(INVOKEVIRTUAL, "com/mojang/authlib/properties/Property", isSignature ? "value" : "getValue", "()Ljava/lang/String;", false); mv.visitVarInsn(ALOAD, 1); - mv.visitMethodInsn(INVOKEVIRTUAL, "com/mojang/authlib/properties/Property", "getSignature", "()Ljava/lang/String;", false); + mv.visitMethodInsn(INVOKEVIRTUAL, "com/mojang/authlib/properties/Property", isSignature ? "signature" : "getSignature", "()Ljava/lang/String;", false); ctx.invokeCallback(mv, YggdrasilKeyTransformUnit.class, "verifyPropertySignature"); mv.visitInsn(IRETURN); mv.visitMaxs(-1, -1); From 4d9e9dd7ca01750f47b7855f867adc174cbc6b8c Mon Sep 17 00:00:00 2001 From: xmdhs Date: Sun, 15 Oct 2023 14:57:45 +0000 Subject: [PATCH 2/4] Add getter methods for 'value' and 'signature' --- .../support/YggdrasilKeyTransformUnit.java | 20 +++++++++++++++---- 1 file changed, 16 insertions(+), 4 deletions(-) diff --git a/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java b/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java index f881dad..35a75b3 100644 --- a/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java +++ b/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java @@ -47,7 +47,6 @@ public class YggdrasilKeyTransformUnit implements TransformUnit { public static final List PUBLIC_KEYS = new CopyOnWriteArrayList<>(); - private boolean isSignature = false; static { PUBLIC_KEYS.add(loadMojangPublicKey()); @@ -140,8 +139,21 @@ public Optional transform(ClassLoader classLoader, String classNam return Optional.of(new ClassVisitor(ASM9, writer) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { + if ("value".equals(name)) { + MethodVisitor mv = writer.visitMethod(access, "getValue", desc, signature, exceptions); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "com/mojang/authlib/properties/Property", "value", "Ljava/lang/String;"); + mv.visitInsn(ARETURN); + mv.visitMaxs(1, 1); + mv.visitEnd(); + } if ("signature".equals(name)) { - isSignature = true; + MethodVisitor mv = writer.visitMethod(access, "getSignature", desc, signature, exceptions); + mv.visitVarInsn(ALOAD, 0); + mv.visitFieldInsn(GETFIELD, "com/mojang/authlib/properties/Property", "signature", "Ljava/lang/String;"); + mv.visitInsn(ARETURN); + mv.visitMaxs(1, 1); + mv.visitEnd(); } if ("isSignatureValid".equals(name) && "(Ljava/security/PublicKey;)Z".equals(desc)) { ctx.markModified(); @@ -174,9 +186,9 @@ public MethodVisitor visitMethod(int access, String name, String desc, String si MethodVisitor mv = super.visitMethod(access, name, desc, signature, exceptions); mv.visitCode(); mv.visitVarInsn(ALOAD, 1); - mv.visitMethodInsn(INVOKEVIRTUAL, "com/mojang/authlib/properties/Property", isSignature ? "value" : "getValue", "()Ljava/lang/String;", false); + mv.visitMethodInsn(INVOKEVIRTUAL, "com/mojang/authlib/properties/Property", "getValue", "()Ljava/lang/String;", false); mv.visitVarInsn(ALOAD, 1); - mv.visitMethodInsn(INVOKEVIRTUAL, "com/mojang/authlib/properties/Property", isSignature ? "signature" : "getSignature", "()Ljava/lang/String;", false); + mv.visitMethodInsn(INVOKEVIRTUAL, "com/mojang/authlib/properties/Property", "getSignature", "()Ljava/lang/String;", false); ctx.invokeCallback(mv, YggdrasilKeyTransformUnit.class, "verifyPropertySignature"); mv.visitInsn(IRETURN); mv.visitMaxs(-1, -1); From aae07326c81eb7d8df6ef5680aee54849a8ae384 Mon Sep 17 00:00:00 2001 From: xmdhs Date: Wed, 18 Oct 2023 17:09:41 +0800 Subject: [PATCH 3/4] COMPUTE_MAXS enabled and check desc MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Co-authored-by: 红云cloud <137498714+HongYunCloud@users.noreply.github.com> --- .../transform/support/YggdrasilKeyTransformUnit.java | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java b/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java index 35a75b3..530de48 100644 --- a/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java +++ b/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java @@ -139,20 +139,20 @@ public Optional transform(ClassLoader classLoader, String classNam return Optional.of(new ClassVisitor(ASM9, writer) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { - if ("value".equals(name)) { + "value".equals(name) && "()Ljava/lang/String;".equals(desc) MethodVisitor mv = writer.visitMethod(access, "getValue", desc, signature, exceptions); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "com/mojang/authlib/properties/Property", "value", "Ljava/lang/String;"); mv.visitInsn(ARETURN); - mv.visitMaxs(1, 1); + mv.visitMaxs(-1, -1); mv.visitEnd(); } - if ("signature".equals(name)) { + "signature".equals(name) && "()Ljava/lang/String;".equals(desc) MethodVisitor mv = writer.visitMethod(access, "getSignature", desc, signature, exceptions); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "com/mojang/authlib/properties/Property", "signature", "Ljava/lang/String;"); mv.visitInsn(ARETURN); - mv.visitMaxs(1, 1); + mv.visitMaxs(-1, -1); mv.visitEnd(); } if ("isSignatureValid".equals(name) && "(Ljava/security/PublicKey;)Z".equals(desc)) { From 0f5157ab763eef9f3f3e9dea0f01c2186bbd7d7d Mon Sep 17 00:00:00 2001 From: xmdhs Date: Wed, 18 Oct 2023 17:20:21 +0800 Subject: [PATCH 4/4] lost if --- .../transform/support/YggdrasilKeyTransformUnit.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java b/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java index 530de48..7aece95 100644 --- a/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java +++ b/src/main/java/moe/yushi/authlibinjector/transform/support/YggdrasilKeyTransformUnit.java @@ -139,15 +139,14 @@ public Optional transform(ClassLoader classLoader, String classNam return Optional.of(new ClassVisitor(ASM9, writer) { @Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { - "value".equals(name) && "()Ljava/lang/String;".equals(desc) + if ("value".equals(name) && "()Ljava/lang/String;".equals(desc)) { MethodVisitor mv = writer.visitMethod(access, "getValue", desc, signature, exceptions); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "com/mojang/authlib/properties/Property", "value", "Ljava/lang/String;"); mv.visitInsn(ARETURN); mv.visitMaxs(-1, -1); mv.visitEnd(); - } - "signature".equals(name) && "()Ljava/lang/String;".equals(desc) + } else if ("signature".equals(name) && "()Ljava/lang/String;".equals(desc)) { MethodVisitor mv = writer.visitMethod(access, "getSignature", desc, signature, exceptions); mv.visitVarInsn(ALOAD, 0); mv.visitFieldInsn(GETFIELD, "com/mojang/authlib/properties/Property", "signature", "Ljava/lang/String;");