fix: member name mapping bugs

This commit is contained in:
zaaarf 2023-03-29 13:19:08 +02:00
parent cc22e84eb7
commit 642373b4ac
No known key found for this signature in database
GPG key ID: 82240E075E31FA4C
4 changed files with 21 additions and 23 deletions

View file

@ -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

View file

@ -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);
}
/**

View file

@ -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);
}
/**

View file

@ -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 ? "" : "()"
));
}
}
}