summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-03-29 13:19:08 +0200
committer zaaarf <zaaarf@proton.me>2023-03-29 13:19:08 +0200
commit642373b4ac5f03f73b263246552160da59a9eb0c (patch)
tree206b9d580a2decd63f38f2bff30a4fcba5ec9592
parentcc22e84eb716e2b0877489f6f0084c7cc8ea681e (diff)
fix: member name mapping bugs
-rw-r--r--src/main/java/ftbsc/lll/processor/tools/ASTUtils.java2
-rw-r--r--src/main/java/ftbsc/lll/processor/tools/containers/FieldContainer.java2
-rw-r--r--src/main/java/ftbsc/lll/processor/tools/containers/MethodContainer.java2
-rw-r--r--src/main/java/ftbsc/lll/processor/tools/obfuscation/ObfuscationMapper.java38
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<String> 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<String> 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 ? "" : "()"
+ ));
}
}
}