From 642373b4ac5f03f73b263246552160da59a9eb0c Mon Sep 17 00:00:00 2001 From: zaaarf Date: Wed, 29 Mar 2023 13:19:08 +0200 Subject: fix: member name mapping bugs --- .../java/ftbsc/lll/processor/tools/ASTUtils.java | 2 +- .../processor/tools/containers/FieldContainer.java | 2 +- .../tools/containers/MethodContainer.java | 2 +- .../tools/obfuscation/ObfuscationMapper.java | 38 ++++++++++------------ 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java b/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java index 7fb2dc7..1afd123 100644 --- a/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java +++ b/src/main/java/ftbsc/lll/processor/tools/ASTUtils.java @@ -134,7 +134,7 @@ public class ASTUtils { /** * Finds the member name and maps it to the correct format. - * @param parentFQN the already mapped FQN of the parent class + * @param parentFQN the unobfuscated FQN of the parent class * @param memberName the name of the member * @param methodDescriptor the descriptor of the method, may be null * @param mapper the {@link ObfuscationMapper} to use, may be null diff --git a/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java b/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java index b6a98bd..37dbbc1 100644 --- a/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java +++ b/src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java @@ -79,7 +79,7 @@ public class FieldContainer { this.descriptor = descriptorFromType(this.elem.asType()); this.descriptorObf = mapper == null ? this.descriptor : mapper.obfuscateType(Type.getType(this.descriptor)).getDescriptor(); } - this.nameObf = findMemberName(parent.fqnObf, name, descriptor, mapper); + this.nameObf = findMemberName(parent.fqnObf, this.name, null, mapper); } /** diff --git a/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java b/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java index 7f328d6..4ee6c7f 100644 --- a/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java +++ b/src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java @@ -81,7 +81,7 @@ public class MethodContainer { this.descriptor = descriptorFromExecutableElement(this.elem); this.descriptorObf = mapper == null ? this.descriptor : mapper.obfuscateMethodDescriptor(this.descriptor); } - this.nameObf = findMemberName(parent.fqnObf, name, descriptor, mapper); + this.nameObf = findMemberName(parent.fqn, this.name, this.descriptor, mapper); } /** diff --git a/src/main/java/ftbsc/lll/processor/tools/obfuscation/ObfuscationMapper.java b/src/main/java/ftbsc/lll/processor/tools/obfuscation/ObfuscationMapper.java index e4e11c4..69b2e69 100644 --- a/src/main/java/ftbsc/lll/processor/tools/obfuscation/ObfuscationMapper.java +++ b/src/main/java/ftbsc/lll/processor/tools/obfuscation/ObfuscationMapper.java @@ -89,10 +89,7 @@ public class ObfuscationMapper { ObfuscationData data = mapper.get(parentName.replace('.', '/')); if(data == null) throw new MappingNotFoundException(parentName + "::" + memberName); - String member = data.get(memberName, methodDescriptor); - if(member == null) - throw new MappingNotFoundException(parentName + "::" + memberName); - return member; + return data.get(memberName, methodDescriptor); } /** @@ -231,28 +228,29 @@ public class ObfuscationMapper { * @throws AmbiguousDefinitionException if not enough data was given to uniquely identify a mapping */ public String get(String memberName, String methodDescriptor) { - if(methodDescriptor == null) { - String res = members.get(memberName); - if(res != null) return res; - else { - List candidates = members.keySet().stream().filter(k -> k.startsWith(memberName)).collect(Collectors.toList()); - if(candidates.size() == 1) - return candidates.get(0); - else throw new AmbiguousDefinitionException("Mapper could not uniquely identify method " + this.unobf + "::" + memberName); - } - } + //find all keys that start with the name List candidates = members.keySet().stream().filter(m -> m.startsWith(memberName)).collect(Collectors.toList()); - if(candidates.size() == 1) - return members.get(candidates.get(0)); - String signature = memberName + " " + methodDescriptor; - candidates = candidates.stream().filter(m -> m.startsWith(signature)).collect(Collectors.toList()); + if(methodDescriptor != null) { + String signature = String.format("%s %s", memberName, methodDescriptor); + candidates = candidates.stream().filter(m -> m.equals(signature)).collect(Collectors.toList()); + } switch(candidates.size()) { case 0: - return null; + throw new MappingNotFoundException(String.format( + "%s.%s%s", + this.unobf, + memberName, + methodDescriptor == null ? "" : "()" + )); case 1: return members.get(candidates.get(0)); default: - throw new AmbiguousDefinitionException("Mapper could not uniquely identify method " + this.unobf + "::" + memberName); + throw new AmbiguousDefinitionException(String.format( + "Mapper could not uniquely identify member %s.%s%s", + this.unobf, + memberName, + methodDescriptor == null ? "" : "()" + )); } } } -- cgit v1.2.3-56-ga3b1