web/tools/PatchRetiredScepter.java

16 lines
2 KiB
Java

import java.nio.file.*;import java.security.*;import java.util.*;import org.objectweb.asm.*;import org.objectweb.asm.tree.*;
/** Retire only the legacy rod issuer in the exact deployed class. */
public final class PatchRetiredScepter {
static byte[] methodBytes(MethodNode m){var out=new ClassWriter(0);out.visit(65,1,"Check",null,"java/lang/Object",null);m.accept(out.visitMethod(m.access,m.name,m.desc,m.signature,m.exceptions.toArray(String[]::new)));out.visitEnd();return out.toByteArray();}
public static void main(String[] args)throws Exception{
byte[] original=Files.readAllBytes(Path.of(args[0]));String sha=HexFormat.of().formatHex(MessageDigest.getInstance("SHA-256").digest(original));
if(!sha.equals("48bdda439e8675aad801b73a7033201968d3d230f7828066f3afe94b04ac2466"))throw new IllegalStateException("Unexpected AdminGui input");
var node=new ClassNode();new ClassReader(original).accept(node,0);var before=new HashMap<String,byte[]>();int edited=0;
for(var method:node.methods){before.put(method.name+method.desc,methodBytes(method));if(method.name.equals("giveRod")&&method.desc.equals("(Lorg/bukkit/entity/Player;)V")){
method.instructions.clear();method.instructions.add(new InsnNode(Opcodes.RETURN));method.tryCatchBlocks.clear();if(method.localVariables!=null)method.localVariables.clear();method.visibleLocalVariableAnnotations=null;method.invisibleLocalVariableAnnotations=null;method.maxStack=0;method.maxLocals=2;edited++;
}}
if(edited!=1)throw new IllegalStateException("Issuer method changed");var out=new ClassWriter(0);node.accept(out);byte[] result=out.toByteArray();var verify=new ClassNode();new ClassReader(result).accept(verify,0);
for(var method:verify.methods)if(!method.name.equals("giveRod")&&!Arrays.equals(before.get(method.name+method.desc),methodBytes(method)))throw new IllegalStateException("Unrelated method changed: "+method.name);
Files.write(Path.of(args[1]),result,StandardOpenOption.CREATE_NEW);System.out.println("Retired legacy scepter issuer; unrelated Core methods preserved.");
}
}