From 7c427316a675cbe7e81a04294781c59f2606239d Mon Sep 17 00:00:00 2001 From: zaaarf Date: Sun, 11 Jun 2023 14:48:24 +0200 Subject: feat: initial implementation, created interface and moved stuff from processor --- src/main/java/ftbsc/lll/mapper/IMapper.java | 56 +++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) create mode 100644 src/main/java/ftbsc/lll/mapper/IMapper.java (limited to 'src/main/java/ftbsc/lll/mapper/IMapper.java') diff --git a/src/main/java/ftbsc/lll/mapper/IMapper.java b/src/main/java/ftbsc/lll/mapper/IMapper.java new file mode 100644 index 0000000..8adf860 --- /dev/null +++ b/src/main/java/ftbsc/lll/mapper/IMapper.java @@ -0,0 +1,56 @@ +package ftbsc.lll.mapper; + +import ftbsc.lll.exceptions.MappingNotFoundException; + +import java.util.HashSet; +import java.util.ServiceLoader; +import java.util.Set; + +/** + * A generic obfuscation mapper. + */ +public interface IMapper { + + /** + * Reads the given lines of text and attempts to interpret them as + * mappings of the given type. + * @param lines the lines to read + */ + void populate(Iterable lines); + + /** + * 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 + */ + String obfuscateClass(String name); + + /** + * 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 descriptor of the member + * @return the obfuscated name of the given member + * @throws MappingNotFoundException if no mapping is found + */ + String obfuscateMember(String parentName, String memberName, String methodDescriptor); + + /** + * Loads all valid parsers available in the classpath (via the Java Service API), + * attempts to parse the given lines into mappings, and returns all built mappers + * that succeeded without throwing errors or ftbsc.lll.exceptions. + * @param lines the lines of the mapping file + * @return a {@link Set} of mappers that could interpret the given input + */ + static Set getMappers(Iterable lines) { + Set parsed = new HashSet<>(); + for(IMapper mapper: ServiceLoader.load(IMapper.class)) { + try { + mapper.populate(lines); + parsed.add(mapper); + } catch(Throwable ignored) {} + } + return parsed; + } +} -- cgit v1.2.3-56-ga3b1