diff options
author | zaaarf <zaaarf@proton.me> | 2023-08-26 18:47:04 +0200 |
---|---|---|
committer | zaaarf <zaaarf@proton.me> | 2023-08-26 18:47:04 +0200 |
commit | 4f5394ce5a95e87b35d1b51004cf6c16d6886f72 (patch) | |
tree | ca1b729c3dd2b5fb4ab2d7a75f553f5a6f71be25 /src/main/java/ftbsc/lll/mapper/tools | |
parent | f03bb3c932b035a94222cdd57b60ba1c77130585 (diff) |
feat: implemented multimapper
Diffstat (limited to 'src/main/java/ftbsc/lll/mapper/tools')
-rw-r--r-- | src/main/java/ftbsc/lll/mapper/tools/MappingUtils.java | 31 | ||||
-rw-r--r-- | src/main/java/ftbsc/lll/mapper/tools/data/ClassData.java | 2 |
2 files changed, 18 insertions, 15 deletions
diff --git a/src/main/java/ftbsc/lll/mapper/tools/MappingUtils.java b/src/main/java/ftbsc/lll/mapper/tools/MappingUtils.java index df0b79d..c8d76af 100644 --- a/src/main/java/ftbsc/lll/mapper/tools/MappingUtils.java +++ b/src/main/java/ftbsc/lll/mapper/tools/MappingUtils.java @@ -10,33 +10,34 @@ import org.objectweb.asm.Type; * mappers. */ public class MappingUtils { + /** - * Obfuscates a method descriptor, replacing its class references - * with their obfuscated counterparts. + * Maps a method descriptor, replacing its class references with their mapped counterparts. * @param descriptor a {@link String} containing the descriptor * @param mapper the {@link IMapper} to use for the process - * @return the obfuscated descriptor + * @param reverse whether it should deobfuscate rather than obfuscate + * @return the mapped descriptor */ - public static String obfuscateMethodDescriptor(String descriptor, IMapper mapper) { + public static String mapMethodDescriptor(String descriptor, IMapper mapper, boolean reverse) { Type method = Type.getMethodType(descriptor); Type[] arguments = method.getArgumentTypes(); Type returnType = method.getReturnType(); - Type[] obfArguments = new Type[arguments.length]; - for(int i = 0; i < obfArguments.length; i++) - obfArguments[i] = obfuscateType(arguments[i], mapper); + Type[] mappedArguents = new Type[arguments.length]; + for(int i = 0; i < mappedArguents.length; i++) + mappedArguents[i] = mapType(arguments[i], mapper, reverse); - return Type.getMethodDescriptor(obfuscateType(returnType, mapper), obfArguments); + return Type.getMethodDescriptor(mapType(returnType, mapper, reverse), mappedArguents); } /** - * Given a {@link Type} and a valid {@link IMapper} it returns its obfuscated - * counterpart. + * Given a {@link Type} and a valid {@link IMapper} it returns its mapped counterpart. * @param type the type in question * @param mapper the {@link IMapper} to use for the process + * @param reverse whether it should deobfuscate rather than obfuscate * @return the obfuscated type */ - public static Type obfuscateType(Type type, IMapper mapper) { + public static Type mapType(Type type, IMapper mapper, boolean reverse) { //unwrap arrays Type unwrapped = type; int arrayLevel = 0; @@ -51,10 +52,12 @@ public class MappingUtils { String internalName = type.getInternalName(); - String internalNameObf; + String internalNameMapped; try { - internalNameObf = mapper.obfuscateClass(internalName); - return Type.getType(DescriptorBuilder.nameToDescriptor(internalNameObf, arrayLevel)); + internalNameMapped = reverse + ? mapper.deobfuscateClass(internalName) + : mapper.obfuscateClass(internalName); + return Type.getType(DescriptorBuilder.nameToDescriptor(internalNameMapped, arrayLevel)); } catch(MappingNotFoundException e) { return type; } diff --git a/src/main/java/ftbsc/lll/mapper/tools/data/ClassData.java b/src/main/java/ftbsc/lll/mapper/tools/data/ClassData.java index 5ae4124..3b53055 100644 --- a/src/main/java/ftbsc/lll/mapper/tools/data/ClassData.java +++ b/src/main/java/ftbsc/lll/mapper/tools/data/ClassData.java @@ -77,7 +77,7 @@ public class ClassData { public ClassData generateReverseMappings(IMapper mapper) { ClassData reverse = new ClassData(this.nameMapped, this.name); this.methods.forEach((signature, data) -> reverse.addMethod(nameMapped, signature.name, - MappingUtils.obfuscateMethodDescriptor(signature.descriptor, mapper))); + MappingUtils.mapMethodDescriptor(signature.descriptor, mapper, false))); this.fields.forEach((name, data) -> reverse.addField(data.nameMapped, name)); return reverse; } |