diff --git a/asm/src/main/java/dev/openrs2/asm/InsnMatcher.java b/asm/src/main/java/dev/openrs2/asm/InsnMatcher.java index c12b49c2fe..1aa26806b3 100644 --- a/asm/src/main/java/dev/openrs2/asm/InsnMatcher.java +++ b/asm/src/main/java/dev/openrs2/asm/InsnMatcher.java @@ -1,12 +1,12 @@ package dev.openrs2.asm; import java.util.ArrayList; -import java.util.Collections; import java.util.List; -import java.util.Map; import java.util.regex.Pattern; import java.util.stream.Stream; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.AbstractInsnNode; import org.objectweb.asm.tree.InsnList; @@ -15,8 +15,8 @@ import org.objectweb.asm.util.Printer; public final class InsnMatcher { private static final int PRIVATE_USE_AREA = 0xE000; - private static final Map OPCODE_GROUPS = Map.ofEntries( - Map.entry("InsnNode", new int[] { + private static final ImmutableMap OPCODE_GROUPS = ImmutableMap.builder() + .put("InsnNode", new int[] { Opcodes.NOP, Opcodes.ACONST_NULL, Opcodes.ICONST_M1, @@ -124,13 +124,13 @@ public final class InsnMatcher { Opcodes.ATHROW, Opcodes.MONITORENTER, Opcodes.MONITOREXIT - }), - Map.entry("IntInsnNode", new int[] { + }) + .put("IntInsnNode", new int[] { Opcodes.BIPUSH, Opcodes.SIPUSH, Opcodes.NEWARRAY - }), - Map.entry("VarInsnNode", new int[] { + }) + .put("VarInsnNode", new int[] { Opcodes.ILOAD, Opcodes.LLOAD, Opcodes.FLOAD, @@ -142,29 +142,29 @@ public final class InsnMatcher { Opcodes.DSTORE, Opcodes.ASTORE, Opcodes.RET - }), - Map.entry("TypeInsnNode", new int[] { + }) + .put("TypeInsnNode", new int[] { Opcodes.NEW, Opcodes.ANEWARRAY, Opcodes.CHECKCAST, Opcodes.INSTANCEOF - }), - Map.entry("FieldInsnNode", new int[] { + }) + .put("FieldInsnNode", new int[] { Opcodes.GETSTATIC, Opcodes.PUTSTATIC, Opcodes.GETFIELD, Opcodes.PUTFIELD - }), - Map.entry("MethodInsnNode", new int[] { + }) + .put("MethodInsnNode", new int[] { Opcodes.INVOKEVIRTUAL, Opcodes.INVOKESPECIAL, Opcodes.INVOKESTATIC, Opcodes.INVOKEINTERFACE - }), - Map.entry("InvokeDynamicInsnNode", new int[] { + }) + .put("InvokeDynamicInsnNode", new int[] { Opcodes.INVOKEDYNAMIC - }), - Map.entry("JumpInsnNode", new int[] { + }) + .put("JumpInsnNode", new int[] { Opcodes.IFEQ, Opcodes.IFNE, Opcodes.IFLT, @@ -183,23 +183,23 @@ public final class InsnMatcher { Opcodes.JSR, Opcodes.IFNULL, Opcodes.IFNONNULL - }), - Map.entry("LdcInsnNode", new int[] { + }) + .put("LdcInsnNode", new int[] { Opcodes.LDC - }), - Map.entry("IincInsnNode", new int[] { + }) + .put("IincInsnNode", new int[] { Opcodes.IINC - }), - Map.entry("TableSwitchInsnNode", new int[] { + }) + .put("TableSwitchInsnNode", new int[] { Opcodes.TABLESWITCH - }), - Map.entry("LookupSwitchInsnNode", new int[] { + }) + .put("LookupSwitchInsnNode", new int[] { Opcodes.LOOKUPSWITCH - }), - Map.entry("MultiANewArrayInsnNode", new int[] { + }) + .put("MultiANewArrayInsnNode", new int[] { Opcodes.MULTIANEWARRAY - }), - Map.entry("ICONST", new int[] { + }) + .put("ICONST", new int[] { Opcodes.ICONST_M1, Opcodes.ICONST_0, Opcodes.ICONST_1, @@ -208,7 +208,7 @@ public final class InsnMatcher { Opcodes.ICONST_4, Opcodes.ICONST_5 }) - ); + .build(); private static char opcodeToCodepoint(int opcode) { return (char) (PRIVATE_USE_AREA + opcode); @@ -295,19 +295,19 @@ public final class InsnMatcher { this.pattern = pattern; } - public Stream> match(MethodNode method) { + public Stream> match(MethodNode method) { return match(method.instructions); } - public Stream> match(InsnList list) { - Stream.Builder> matches = Stream.builder(); + public Stream> match(InsnList list) { + Stream.Builder> matches = Stream.builder(); var insns = createRealInsnList(list); var matcher = pattern.matcher(createCodepointSeq(insns)); while (matcher.find()) { var start = matcher.start(); var end = matcher.end(); - matches.add(Collections.unmodifiableList(insns.subList(start, end))); + matches.add(ImmutableList.copyOf(insns.subList(start, end))); } return matches.build(); diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.java b/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.java index b7ba6f8ec0..92ad831e76 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.java +++ b/asm/src/main/java/dev/openrs2/asm/classpath/AsmClassMetadata.java @@ -1,8 +1,6 @@ package dev.openrs2.asm.classpath; -import java.util.List; -import java.util.stream.Collectors; - +import com.google.common.collect.ImmutableList; import dev.openrs2.asm.MemberDesc; import org.objectweb.asm.Opcodes; import org.objectweb.asm.tree.ClassNode; @@ -42,24 +40,24 @@ public final class AsmClassMetadata extends ClassMetadata { } @Override - public List getSuperInterfaces() { + public ImmutableList getSuperInterfaces() { return clazz.interfaces.stream() .map(classPath::get) - .collect(Collectors.toUnmodifiableList()); + .collect(ImmutableList.toImmutableList()); } @Override - public List getFields() { + public ImmutableList getFields() { return clazz.fields.stream() .map(f -> new MemberDesc(f.name, f.desc)) - .collect(Collectors.toUnmodifiableList()); + .collect(ImmutableList.toImmutableList()); } @Override - public List getMethods() { + public ImmutableList getMethods() { return clazz.methods.stream() .map(m -> new MemberDesc(m.name, m.desc)) - .collect(Collectors.toUnmodifiableList()); + .collect(ImmutableList.toImmutableList()); } @Override diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.java b/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.java index 2c3fc6f732..1dbf737116 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.java +++ b/asm/src/main/java/dev/openrs2/asm/classpath/ClassMetadata.java @@ -1,8 +1,8 @@ package dev.openrs2.asm.classpath; -import java.util.List; import java.util.Objects; +import com.google.common.collect.ImmutableList; import dev.openrs2.asm.MemberDesc; public abstract class ClassMetadata { @@ -10,9 +10,9 @@ public abstract class ClassMetadata { public abstract boolean isDependency(); public abstract boolean isInterface(); public abstract ClassMetadata getSuperClass(); - public abstract List getSuperInterfaces(); - public abstract List getFields(); - public abstract List getMethods(); + public abstract ImmutableList getSuperInterfaces(); + public abstract ImmutableList getFields(); + public abstract ImmutableList getMethods(); public abstract boolean isNative(MemberDesc method); @Override diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.java b/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.java index 41fd7ca903..bbe767e559 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.java +++ b/asm/src/main/java/dev/openrs2/asm/classpath/ClassPath.java @@ -1,13 +1,10 @@ package dev.openrs2.asm.classpath; -import java.util.ArrayList; -import java.util.Collections; import java.util.HashMap; -import java.util.HashSet; -import java.util.List; import java.util.Map; -import java.util.Set; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableSet; import dev.openrs2.asm.MemberDesc; import dev.openrs2.asm.MemberRef; import dev.openrs2.util.collect.DisjointSet; @@ -16,21 +13,21 @@ import org.objectweb.asm.tree.ClassNode; public final class ClassPath { private final ClassLoader runtime; - private final List dependencies, libraries; + private final ImmutableList dependencies, libraries; private final Map cache = new HashMap<>(); - public ClassPath(ClassLoader runtime, List dependencies, List libraries) { + public ClassPath(ClassLoader runtime, ImmutableList dependencies, ImmutableList libraries) { this.runtime = runtime; this.dependencies = dependencies; this.libraries = libraries; } - public List getLibraries() { + public ImmutableList getLibraries() { return libraries; } - public List getLibraryClasses() { - var classes = new ArrayList(); + public ImmutableList getLibraryClasses() { + var classes = ImmutableList.builder(); for (var library : libraries) { for (var clazz : library) { @@ -38,7 +35,7 @@ public final class ClassPath { } } - return Collections.unmodifiableList(classes); + return classes.build(); } public ClassMetadata get(String name) { @@ -91,7 +88,7 @@ public final class ClassPath { public DisjointSet createInheritedFieldSets() { var disjointSet = new ForestDisjointSet(); - var ancestorCache = new HashMap>(); + var ancestorCache = new HashMap>(); for (var library : libraries) { for (var clazz : library) { @@ -102,12 +99,12 @@ public final class ClassPath { return disjointSet; } - private Set populateInheritedFieldSets(Map> ancestorCache, DisjointSet disjointSet, ClassMetadata clazz) { + private ImmutableSet populateInheritedFieldSets(Map> ancestorCache, DisjointSet disjointSet, ClassMetadata clazz) { var ancestors = ancestorCache.get(clazz); if (ancestors != null) { return ancestors; } - ancestors = new HashSet<>(); + var ancestorsBuilder = ImmutableSet.builder(); var superClass = clazz.getSuperClass(); if (superClass != null) { @@ -119,7 +116,7 @@ public final class ClassPath { disjointSet.union(partition1, partition2); } - ancestors.addAll(fields); + ancestorsBuilder.addAll(fields); } for (var superInterface : clazz.getSuperInterfaces()) { @@ -131,22 +128,22 @@ public final class ClassPath { disjointSet.union(partition1, partition2); } - ancestors.addAll(fields); + ancestorsBuilder.addAll(fields); } for (var field : clazz.getFields()) { disjointSet.add(new MemberRef(clazz.getName(), field)); - ancestors.add(field); + ancestorsBuilder.add(field); } - ancestors = Collections.unmodifiableSet(ancestors); + ancestors = ancestorsBuilder.build(); ancestorCache.put(clazz, ancestors); return ancestors; } public DisjointSet createInheritedMethodSets() { var disjointSet = new ForestDisjointSet(); - var ancestorCache = new HashMap>(); + var ancestorCache = new HashMap>(); for (var library : libraries) { for (var clazz : library) { @@ -157,12 +154,12 @@ public final class ClassPath { return disjointSet; } - private Set populateInheritedMethodSets(Map> ancestorCache, DisjointSet disjointSet, ClassMetadata clazz) { + private ImmutableSet populateInheritedMethodSets(Map> ancestorCache, DisjointSet disjointSet, ClassMetadata clazz) { var ancestors = ancestorCache.get(clazz); if (ancestors != null) { return ancestors; } - ancestors = new HashSet<>(); + var ancestorsBuilder = ImmutableSet.builder(); var superClass = clazz.getSuperClass(); if (superClass != null) { @@ -174,7 +171,7 @@ public final class ClassPath { disjointSet.union(partition1, partition2); } - ancestors.addAll(methods); + ancestorsBuilder.addAll(methods); } for (var superInterface : clazz.getSuperInterfaces()) { @@ -186,15 +183,15 @@ public final class ClassPath { disjointSet.union(partition1, partition2); } - ancestors.addAll(methods); + ancestorsBuilder.addAll(methods); } for (var method : clazz.getMethods()) { disjointSet.add(new MemberRef(clazz.getName(), method)); - ancestors.add(method); + ancestorsBuilder.add(method); } - ancestors = Collections.unmodifiableSet(ancestors); + ancestors = ancestorsBuilder.build(); ancestorCache.put(clazz, ancestors); return ancestors; } diff --git a/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.java b/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.java index 6b1e027a0c..7aad28b100 100644 --- a/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.java +++ b/asm/src/main/java/dev/openrs2/asm/classpath/ReflectionClassMetadata.java @@ -2,9 +2,8 @@ package dev.openrs2.asm.classpath; import java.lang.reflect.Modifier; import java.util.Arrays; -import java.util.List; -import java.util.stream.Collectors; +import com.google.common.collect.ImmutableList; import dev.openrs2.asm.MemberDesc; import org.objectweb.asm.Type; @@ -42,24 +41,24 @@ public final class ReflectionClassMetadata extends ClassMetadata { } @Override - public List getSuperInterfaces() { + public ImmutableList getSuperInterfaces() { return Arrays.stream(clazz.getInterfaces()) .map(i -> classPath.get(i.getName().replace('.', '/'))) - .collect(Collectors.toUnmodifiableList()); + .collect(ImmutableList.toImmutableList()); } @Override - public List getFields() { + public ImmutableList getFields() { return Arrays.stream(clazz.getDeclaredFields()) .map(f -> new MemberDesc(f.getName(), Type.getDescriptor(f.getType()))) - .collect(Collectors.toUnmodifiableList()); + .collect(ImmutableList.toImmutableList()); } @Override - public List getMethods() { + public ImmutableList getMethods() { return Arrays.stream(clazz.getDeclaredMethods()) .map(m -> new MemberDesc(m.getName(), Type.getMethodDescriptor(m))) - .collect(Collectors.toUnmodifiableList()); + .collect(ImmutableList.toImmutableList()); } @Override diff --git a/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.java b/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.java index 5642764f5b..37c9999942 100644 --- a/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.java +++ b/decompiler/src/main/java/dev/openrs2/decompiler/Decompiler.java @@ -4,15 +4,15 @@ import java.io.Closeable; import java.io.IOException; import java.nio.file.Path; import java.nio.file.Paths; -import java.util.List; -import java.util.Map; import java.util.function.Function; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.ImmutableMap; import org.jetbrains.java.decompiler.main.Fernflower; import org.jetbrains.java.decompiler.main.extern.IFernflowerPreferences; public final class Decompiler implements Closeable { - private static final Map OPTIONS = Map.of( + private static final ImmutableMap OPTIONS = ImmutableMap.of( IFernflowerPreferences.ASCII_STRING_CHARACTERS, "1", IFernflowerPreferences.INDENT_STRING, "\t", IFernflowerPreferences.SYNTHETIC_NOT_SET, "1" @@ -32,7 +32,7 @@ public final class Decompiler implements Closeable { public static void main(String[] args) throws IOException { var deobOutput = Paths.get("nonfree/code/deob"); - var sources = List.of( + var sources = ImmutableList.of( deobOutput.resolve("runescape_gl.jar"), deobOutput.resolve("jaggl.jar"), deobOutput.resolve("jaggl_dri.jar"), @@ -49,9 +49,9 @@ public final class Decompiler implements Closeable { private final DecompilerIo io; private final Fernflower fernflower; - private final List sources; + private final ImmutableList sources; - public Decompiler(List sources, Function destination) { + public Decompiler(ImmutableList sources, Function destination) { this.io = new DecompilerIo(destination); this.fernflower = new Fernflower(io, io, OPTIONS, Slf4jFernflowerLogger.INSTANCE); this.sources = sources; diff --git a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java index 103b89ad17..f151fe32e1 100644 --- a/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java +++ b/deob/src/main/java/dev/openrs2/deob/Deobfuscator.java @@ -6,6 +6,7 @@ import java.nio.file.Path; import java.nio.file.Paths; import java.util.List; +import com.google.common.collect.ImmutableList; import dev.openrs2.asm.classpath.ClassPath; import dev.openrs2.asm.classpath.Library; import dev.openrs2.asm.transform.Transformer; @@ -102,9 +103,9 @@ public final class Deobfuscator { /* bundle libraries together into a common classpath */ var runtime = ClassLoader.getPlatformClassLoader(); - var classPath = new ClassPath(runtime, List.of(), List.of(client, loader, signLink, unpack, unpacker)); - var glClassPath = new ClassPath(runtime, List.of(gl, glDri), List.of(glClient, glLoader, glSignLink, glUnpack, glUnpacker)); - var unsignedClassPath = new ClassPath(runtime, List.of(), List.of(unsignedClient)); + var classPath = new ClassPath(runtime, ImmutableList.of(), ImmutableList.of(client, loader, signLink, unpack, unpacker)); + var glClassPath = new ClassPath(runtime, ImmutableList.of(gl, glDri), ImmutableList.of(glClient, glLoader, glSignLink, glUnpack, glUnpacker)); + var unsignedClassPath = new ClassPath(runtime, ImmutableList.of(), ImmutableList.of(unsignedClient)); /* deobfuscate */ logger.info("Transforming client"); diff --git a/deob/src/main/java/dev/openrs2/deob/analysis/IntInterpreter.java b/deob/src/main/java/dev/openrs2/deob/analysis/IntInterpreter.java index be16536fc0..a03d53b0d2 100644 --- a/deob/src/main/java/dev/openrs2/deob/analysis/IntInterpreter.java +++ b/deob/src/main/java/dev/openrs2/deob/analysis/IntInterpreter.java @@ -1,8 +1,8 @@ package dev.openrs2.deob.analysis; import java.util.List; -import java.util.stream.Collectors; +import com.google.common.collect.ImmutableList; import com.google.common.collect.ImmutableSet; import com.google.common.collect.Sets; import dev.openrs2.asm.InsnNodeUtils; @@ -200,7 +200,7 @@ public final class IntInterpreter extends Interpreter { public IntValue naryOperation(AbstractInsnNode insn, List values) throws AnalyzerException { var args = values.stream() .map(IntValue::getBasicValue) - .collect(Collectors.toUnmodifiableList()); + .collect(ImmutableList.toImmutableList()); var basicValue = basicInterpreter.naryOperation(insn, args); if (basicValue == null) { return null; diff --git a/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java b/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java index 3cf19c19d0..47246a0868 100644 --- a/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java +++ b/deob/src/main/java/dev/openrs2/deob/remap/TypedRemapper.java @@ -3,9 +3,9 @@ package dev.openrs2.deob.remap; import java.util.HashMap; import java.util.List; import java.util.Map; -import java.util.Set; import com.google.common.base.Strings; +import com.google.common.collect.ImmutableSet; import dev.openrs2.asm.MemberDesc; import dev.openrs2.asm.MemberRef; import dev.openrs2.asm.classpath.ClassMetadata; @@ -20,21 +20,21 @@ import org.slf4j.LoggerFactory; public final class TypedRemapper extends Remapper { private static final Logger logger = LoggerFactory.getLogger(TypedRemapper.class); - public static final Set EXCLUDED_CLASSES = Set.of( + public static final ImmutableSet EXCLUDED_CLASSES = ImmutableSet.of( "client", "jagex3/jagmisc/jagmisc", "loader", "unpack", "unpackclass" ); - private static final Set EXCLUDED_METHODS = Set.of( + private static final ImmutableSet EXCLUDED_METHODS = ImmutableSet.of( "", "", "main", "providesignlink", "quit" ); - private static final Set EXCLUDED_FIELDS = Set.of( + private static final ImmutableSet EXCLUDED_FIELDS = ImmutableSet.of( "cache" ); private static final int MAX_OBFUSCATED_NAME_LEN = 2; diff --git a/deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.java index 1bdb0b1de1..558670fc48 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/BitShiftTransformer.java @@ -1,7 +1,6 @@ package dev.openrs2.deob.transform; -import java.util.Set; - +import com.google.common.collect.ImmutableSet; import dev.openrs2.asm.InsnMatcher; import dev.openrs2.asm.InsnNodeUtils; import dev.openrs2.asm.classpath.ClassPath; @@ -16,7 +15,7 @@ public final class BitShiftTransformer extends Transformer { private static final Logger logger = LoggerFactory.getLogger(BitShiftTransformer.class); private static final InsnMatcher CONST_SHIFT_MATCHER = InsnMatcher.compile("(ICONST | BIPUSH | SIPUSH | LDC) (ISHL | ISHR | IUSHR | LSHL | LSHR | LUSHR)"); - private static final Set LONG_SHIFTS = Set.of(Opcodes.LSHL, Opcodes.LSHR, Opcodes.LUSHR); + private static final ImmutableSet LONG_SHIFTS = ImmutableSet.of(Opcodes.LSHL, Opcodes.LSHR, Opcodes.LUSHR); private int simplified; diff --git a/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java b/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java index 4ada5eb01a..9342a91bdf 100644 --- a/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java +++ b/deob/src/main/java/dev/openrs2/deob/transform/OriginalNameTransformer.java @@ -3,6 +3,7 @@ package dev.openrs2.deob.transform; import java.util.ArrayList; import java.util.List; +import com.google.common.collect.ImmutableList; import dev.openrs2.asm.transform.Transformer; import dev.openrs2.deob.annotation.OriginalArg; import dev.openrs2.deob.annotation.OriginalClass; @@ -16,13 +17,13 @@ import org.objectweb.asm.tree.MethodNode; public final class OriginalNameTransformer extends Transformer { private static AnnotationNode createOriginalClassAnnotation(String name) { var annotation = new AnnotationNode(Type.getDescriptor(OriginalClass.class)); - annotation.values = List.of("value", name); + annotation.values = ImmutableList.of("value", name); return annotation; } private static AnnotationNode createOriginalMemberAnnotation(String owner, String name, String desc) { var annotation = new AnnotationNode(Type.getDescriptor(OriginalMember.class)); - annotation.values = List.of( + annotation.values = ImmutableList.of( "owner", owner, "name", name, "descriptor", desc @@ -32,7 +33,7 @@ public final class OriginalNameTransformer extends Transformer { private static AnnotationNode createOriginalArgAnnotation(int index) { var annotation = new AnnotationNode(Type.getDescriptor(OriginalArg.class)); - annotation.values = List.of("value", index); + annotation.values = ImmutableList.of("value", index); return annotation; }