diff options
author | zaaarf <zaaarf@proton.me> | 2023-06-11 14:48:24 +0200 |
---|---|---|
committer | zaaarf <zaaarf@proton.me> | 2023-06-11 14:48:24 +0200 |
commit | 7c427316a675cbe7e81a04294781c59f2606239d (patch) | |
tree | 3a4efc720f44205db6c518ee854f03eebf215e7c /src/main/java/ftbsc/lll/mapper/impl |
feat: initial implementation, created interface and moved stuff from processor
Diffstat (limited to 'src/main/java/ftbsc/lll/mapper/impl')
-rw-r--r-- | src/main/java/ftbsc/lll/mapper/impl/TSRGMapper.java | 72 |
1 files changed, 72 insertions, 0 deletions
diff --git a/src/main/java/ftbsc/lll/mapper/impl/TSRGMapper.java b/src/main/java/ftbsc/lll/mapper/impl/TSRGMapper.java new file mode 100644 index 0000000..0fc6489 --- /dev/null +++ b/src/main/java/ftbsc/lll/mapper/impl/TSRGMapper.java @@ -0,0 +1,72 @@ +package ftbsc.lll.mapper.impl; + +import ftbsc.lll.exceptions.MappingNotFoundException; +import ftbsc.lll.mapper.IMapper; +import ftbsc.lll.mapper.tools.ClassData; + +import java.util.HashMap; +import java.util.Map; + +/** + * Parses a .tsrg file into a mapper capable of converting from + * plain names to obfuscated ones and vice versa. + */ +public class TSRGMapper implements IMapper { + + /** + * A Map containing the deobfuscated names as keys and information about + * each class as values. + */ + private final Map<String, ClassData> mappings = new HashMap<>(); + + /** + * Reads the given lines of text and attempts to interpret them as + * mappings of the given type. + * @param lines the lines to read + */ + @Override + public void populate(Iterable<String> lines) { + String currentClass = ""; + for(String l : lines) { + if(l == null) continue; + if(l.startsWith("\t")) + mappings.get(currentClass).addMember(l); + else { + String[] sp = l.split(" "); + ClassData s = new ClassData(sp[0], sp[1]); + currentClass = s.unobf; + mappings.put(s.unobf, s); + } + } + } + + /** + * Gets the obfuscated name of the class. + * @param name the unobfuscated internal name of the desired class + * @return the obfuscated name of the class + * @throws MappingNotFoundException if no mapping is found + */ + @Override + public String obfuscateClass(String name) { + ClassData data = mappings.get(name.replace('.', '/')); + if(data == null) + throw new MappingNotFoundException(name); + else return data.obf; + } + + /** + * Gets the obfuscated name of a class member (field or method). + * @param parentName the unobfuscated internal name of the parent class + * @param memberName the field name or method signature + * @param methodDescriptor the optional descriptor of the member, may be null or partial + * @return the obfuscated name of the given member + * @throws MappingNotFoundException if no mapping is found + */ + @Override + public String obfuscateMember(String parentName, String memberName, String methodDescriptor) { + ClassData data = mappings.get(parentName.replace('.', '/')); + if(data == null) + throw new MappingNotFoundException(parentName + "::" + memberName); + return data.get(memberName, methodDescriptor); + } +} |