Skip to content

Commit

Permalink
Don't propose names in classes marked with @DeobfuscateClass
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Feb 26, 2025
1 parent 436c8c0 commit 13d4b41
Showing 1 changed file with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,18 @@
import java.util.Map;
import java.util.Set;

import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassVisitor;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.tree.MethodNode;

public class NameFinderVisitor extends ClassVisitor {
private static final String DONT_OBFUSCATE_DESC = "Lnet/minecraft/class_6177;";

private String owner;
private boolean notObfuscated;
private final Map<String, Set<String>> allEnumFields;
private final Map<String, List<MethodNode>> allMethods;

Expand All @@ -42,11 +46,25 @@ public NameFinderVisitor(int api, Map<String, Set<String>> allEnumFields, Map<St
@Override
public void visit(int version, int access, String name, String signature, String superName, String[] interfaces) {
this.owner = name;
this.notObfuscated = false;
super.visit(version, access, name, signature, superName, interfaces);
}

@Override
public AnnotationVisitor visitAnnotation(String descriptor, boolean visible) {
if (DONT_OBFUSCATE_DESC.equals(descriptor)) {
this.notObfuscated = true;
}

return super.visitAnnotation(descriptor, visible);
}

@Override
public FieldVisitor visitField(int access, String name, String descriptor, String signature, Object value) {
if (notObfuscated) {
return super.visitField(access, name, descriptor, signature, value);
}

if ((access & Opcodes.ACC_ENUM) != 0) {
if (!allEnumFields.computeIfAbsent(owner, s -> new HashSet<>()).add(descriptor + name)) {
throw new IllegalArgumentException("Found two enum fields with the same name \"" + name + "\"!");
Expand All @@ -63,6 +81,10 @@ public MethodVisitor visitMethod(
final String descriptor,
final String signature,
final String[] exceptions) {
if (notObfuscated) {
return super.visitMethod(access, name, descriptor, signature, exceptions);
}

if ("<clinit>".equals(name)) {
MethodNode node = new MethodNode(api, access, name, descriptor, signature, exceptions);
allMethods.computeIfAbsent(owner, s -> new ArrayList<>()).add(node);
Expand Down

0 comments on commit 13d4b41

Please sign in to comment.