mirror of
https://github.com/FalsePattern/FalsePatternLib.git
synced 2026-11-17 06:25:02 +00:00
Annotate all the things
This commit is contained in:
63 files changed
+623
-369
No files matched your search
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package com.falsepattern.lib.asm;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import com.falsepattern.lib.asm.exceptions.AsmClassNotFoundException;
|
||||
import com.falsepattern.lib.asm.exceptions.AsmFieldNotFoundException;
|
||||
import com.falsepattern.lib.asm.exceptions.AsmMethodNotFoundException;
|
||||
@@ -42,7 +43,9 @@ import org.objectweb.asm.tree.MethodNode;
|
||||
import java.util.Arrays;
|
||||
import java.util.Objects;
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
public class ASMUtil {
|
||||
@StableAPI.Expose
|
||||
public static FieldNode findFieldStandard(ClassNode cn, String name, boolean optional) {
|
||||
for (final FieldNode ret : cn.fields) {
|
||||
if (name.equals(ret.name)) {
|
||||
@@ -56,6 +59,7 @@ public class ASMUtil {
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@StableAPI.Expose
|
||||
public static FieldNode findFieldFromMCP(ClassNode cn, String fieldName, boolean optional) {
|
||||
val classMapping = discoverClassMappingType(cn);
|
||||
if (classMapping == null) {
|
||||
@@ -67,6 +71,7 @@ public class ASMUtil {
|
||||
.getName(classMapping), optional);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static FieldNode findFieldFromUniversal(ClassNode cn, UniversalField field, boolean optional) {
|
||||
String[] possibilities = CoreLoadingPlugin.isObfuscated() ? new String[]{field.getName(MappingType.SRG),
|
||||
field.getName(MappingType.Notch)}
|
||||
@@ -83,6 +88,7 @@ public class ASMUtil {
|
||||
possibilities.length == 1 ? possibilities[0] : Arrays.toString(possibilities));
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static MethodNode findMethodStandard(ClassNode cn, String name, String descriptor, boolean optional) {
|
||||
for (final MethodNode ret : cn.methods) {
|
||||
if (name.equals(ret.name) && descriptor.equals(ret.desc)) {
|
||||
@@ -96,6 +102,7 @@ public class ASMUtil {
|
||||
}
|
||||
|
||||
@SneakyThrows
|
||||
@StableAPI.Expose
|
||||
public static MethodNode findMethodFromMCP(ClassNode cn, String mcpName, String mcpDescriptor, boolean optional) {
|
||||
val classMapping = discoverClassMappingType(cn);
|
||||
if (classMapping == null) {
|
||||
@@ -107,6 +114,7 @@ public class ASMUtil {
|
||||
return findMethodStandard(cn, method.getName(classMapping), method.getDescriptor(classMapping), optional);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static MethodNode findMethodFromUniversal(ClassNode cn, UniversalMethod method, boolean optional) {
|
||||
String[] possibleNames = CoreLoadingPlugin.isObfuscated() ? new String[]{method.getName(MappingType.SRG),
|
||||
method.getName(MappingType.Notch)}
|
||||
@@ -127,6 +135,7 @@ public class ASMUtil {
|
||||
possibleDescriptors.length == 1 ? possibleDescriptors[0] : Arrays.toString(possibleDescriptors));
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static MappingType discoverClassMappingType(ClassNode cn) {
|
||||
if (CoreLoadingPlugin.isObfuscated()) {
|
||||
if (MappingManager.containsClass(NameType.Internal, MappingType.MCP, cn.name)) {
|
||||
@@ -140,6 +149,7 @@ public class ASMUtil {
|
||||
return null;
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static UniversalClass toUniversalClass(ClassNode cn) {
|
||||
if (CoreLoadingPlugin.isObfuscated()) {
|
||||
try {
|
||||
@@ -160,6 +170,7 @@ public class ASMUtil {
|
||||
}
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static ClassNode parseClass(byte[] bytes, int readerFlags) {
|
||||
val cn = new ClassNode(Opcodes.ASM5);
|
||||
val reader = new ClassReader(bytes);
|
||||
@@ -167,11 +178,13 @@ public class ASMUtil {
|
||||
return cn;
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static byte[] serializeClass(ClassNode cn, int writerFlags) {
|
||||
val writer = new ClassWriter(writerFlags);
|
||||
return writer.toByteArray();
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public static boolean anyEquals(String str, String... options) {
|
||||
for (val option : options) {
|
||||
if (Objects.equals(str, option)) {
|
||||
|
||||
@@ -20,16 +20,22 @@
|
||||
*/
|
||||
package com.falsepattern.lib.asm;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import org.objectweb.asm.tree.ClassNode;
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
public interface IClassNodeTransformer {
|
||||
@StableAPI.Expose
|
||||
String getName();
|
||||
|
||||
@StableAPI.Expose
|
||||
boolean shouldTransform(ClassNode cn, String transformedName, boolean obfuscated);
|
||||
|
||||
@StableAPI.Expose
|
||||
default int internalSortingOrder() {
|
||||
return 0;
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
void transform(ClassNode cn, String transformedName, boolean obfuscated);
|
||||
}
|
||||
@@ -20,6 +20,7 @@
|
||||
*/
|
||||
package com.falsepattern.lib.asm;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
import com.falsepattern.lib.internal.CoreLoadingPlugin;
|
||||
import lombok.val;
|
||||
import org.apache.logging.log4j.Logger;
|
||||
@@ -35,9 +36,12 @@ import java.util.List;
|
||||
/**
|
||||
* An ASM transformation dispatcher utility, inspired by mixins.
|
||||
*/
|
||||
@StableAPI(since = "0.10.0")
|
||||
public interface SmartTransformer extends IClassTransformer {
|
||||
@StableAPI.Expose
|
||||
Logger logger();
|
||||
|
||||
@StableAPI.Expose
|
||||
List<IClassNodeTransformer> transformers();
|
||||
|
||||
@Override
|
||||
|
||||
@@ -20,7 +20,11 @@
|
||||
*/
|
||||
package com.falsepattern.lib.asm.exceptions;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
public class AsmClassNotFoundException extends AsmTransformException {
|
||||
@StableAPI.Internal
|
||||
public AsmClassNotFoundException(final String clazz) {
|
||||
super("can't find class " + clazz);
|
||||
}
|
||||
|
||||
@@ -20,7 +20,11 @@
|
||||
*/
|
||||
package com.falsepattern.lib.asm.exceptions;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
public class AsmFieldNotFoundException extends AsmTransformException {
|
||||
@StableAPI.Internal
|
||||
public AsmFieldNotFoundException(final String field) {
|
||||
super("can't find field " + field);
|
||||
}
|
||||
|
||||
@@ -20,6 +20,9 @@
|
||||
*/
|
||||
package com.falsepattern.lib.asm.exceptions;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
public class AsmMethodNotFoundException extends AsmTransformException {
|
||||
public AsmMethodNotFoundException(final String method) {
|
||||
super("can't find method " + method);
|
||||
|
||||
@@ -20,15 +20,21 @@
|
||||
*/
|
||||
package com.falsepattern.lib.asm.exceptions;
|
||||
|
||||
import com.falsepattern.lib.StableAPI;
|
||||
|
||||
@StableAPI(since = "0.10.0")
|
||||
public class AsmTransformException extends RuntimeException {
|
||||
@StableAPI.Expose
|
||||
public AsmTransformException(final String message) {
|
||||
super(message);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public AsmTransformException(final Throwable cause) {
|
||||
super(cause);
|
||||
}
|
||||
|
||||
@StableAPI.Expose
|
||||
public AsmTransformException(final String message, final Throwable cause) {
|
||||
super(message, cause);
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user