summaryrefslogtreecommitdiff
path: root/src/main/java/ftbsc/lll/mapper/IMapper.java
diff options
context:
space:
mode:
author zaaarf <zaaarf@proton.me>2023-06-11 14:48:24 +0200
committer zaaarf <zaaarf@proton.me>2023-06-11 14:48:24 +0200
commit7c427316a675cbe7e81a04294781c59f2606239d (patch)
tree3a4efc720f44205db6c518ee854f03eebf215e7c /src/main/java/ftbsc/lll/mapper/IMapper.java
feat: initial implementation, created interface and moved stuff from processor
Diffstat (limited to 'src/main/java/ftbsc/lll/mapper/IMapper.java')
-rw-r--r--src/main/java/ftbsc/lll/mapper/IMapper.java56
1 files changed, 56 insertions, 0 deletions
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<String> 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<IMapper> getMappers(Iterable<String> lines) {
+ Set<IMapper> parsed = new HashSet<>();
+ for(IMapper mapper: ServiceLoader.load(IMapper.class)) {
+ try {
+ mapper.populate(lines);
+ parsed.add(mapper);
+ } catch(Throwable ignored) {}
+ }
+ return parsed;
+ }
+}