fix the rest of obfuscated names
All checks were successful
Publish to snapshot maven / build (push) Successful in 14s

This commit is contained in:
moehreag 2024-05-17 20:46:36 +02:00
parent c89e190c0b
commit 0c213ceff4

View file

@ -1,11 +1,15 @@
package org.ecorous.esnesnon.nonsense_remapper.api;
import java.util.*;
import java.util.HashSet;
import java.util.Locale;
import java.util.Optional;
import java.util.Set;
import org.ecorous.esnesnon.nonsense_remapper.api.data.Parchment;
import org.objectweb.asm.Label;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import org.objectweb.asm.Type;
import org.objectweb.asm.commons.MethodRemapper;
import org.objectweb.asm.commons.Remapper;
@ -32,21 +36,10 @@ public class ParameterMethodRemapper extends MethodRemapper {
}
private String getNewName(String descriptor, String signature) {
String newName = switch (descriptor.charAt(0)) {
case 'I' -> "i";
case 'B' -> "b";
case 'C' -> "c";
case 'S' -> "s";
case 'D' -> "d";
case 'F' -> "f";
case 'J' -> "l";
case 'Z' -> "bl";
default -> {
String name = cleanType(descriptor);
name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
yield name;
}
};
descriptor = remapper.mapDesc(descriptor);
signature = remapper.mapSignature(signature, false);
String newName = convertDescriptor(descriptor);
int count = 1;
String nameCopy = newName;
@ -63,9 +56,29 @@ public class ParameterMethodRemapper extends MethodRemapper {
}
usedLocalNames.add(newName);
System.out.println("new name for: "+descriptor+" "+signature+" "+newName);
return newName;
}
private String convertDescriptor(String descriptor){
return switch (descriptor.charAt(0)) {
case 'I' -> "i";
case 'B' -> "b";
case 'C' -> "c";
case 'S' -> "s";
case 'D' -> "d";
case 'F' -> "f";
case 'J' -> "l";
case 'Z' -> "bl";
case '[' -> Type.getType(descriptor).getElementType().getClassName() + "s";
default -> {
String name = cleanType(descriptor);
name = Character.toLowerCase(name.charAt(0)) + name.substring(1);
yield name;
}
};
}
private String cleanType(String type) {
var cleaned = type;
if (cleaned.indexOf('<') != -1) {