checkstyle - mixin processor

This commit is contained in:
Lucas
2019-05-17 03:04:15 +02:00
parent 0d8dbfee38
commit 7740b7a85e
18 changed files with 51 additions and 78 deletions

View File

@@ -33,11 +33,11 @@ public class MethodGarbageValue
public MethodGarbageValue(int value)
{
if(value <= Byte.MAX_VALUE && value >= Byte.MIN_VALUE)
if (value <= Byte.MAX_VALUE && value >= Byte.MIN_VALUE)
{
type = "B";
}
else if(value <= Short.MAX_VALUE && value >= Short.MIN_VALUE)
else if (value <= Short.MAX_VALUE && value >= Short.MIN_VALUE)
{
type = "S";
}
@@ -60,6 +60,6 @@ public class MethodGarbageValue
public String toString()
{
return "MethodGarbageValue[type="+getType()+",value="+getValue()+"]";
return "MethodGarbageValue[type=" + getType() + ",value=" + getValue() + "]";
}
}

View File

@@ -33,10 +33,6 @@ import io.sigpipe.jbsdiff.Patch;
import javassist.ClassPool;
import javassist.CtClass;
import javassist.LoaderClassPath;
import org.objectweb.asm.AnnotationVisitor;
import org.objectweb.asm.ClassWriter;
import org.objectweb.asm.FieldVisitor;
import org.objectweb.asm.MethodVisitor;
import org.objectweb.asm.Opcodes;
import us.runelitepl.mixinprocessor.generators.AnnotationProcessor;
import us.runelitepl.mixinprocessor.generators.PatchGenerator;
@@ -50,14 +46,11 @@ import us.runelitepl.mixinprocessor.util.JavassistUtils;
import us.runelitepl.mixinprocessor.util.RefUtils;
import org.apache.maven.plugin.AbstractMojo;
import org.apache.maven.plugin.MojoExecutionException;
import org.apache.maven.plugin.MojoFailureException;
import org.apache.maven.plugins.annotations.LifecyclePhase;
import org.apache.maven.plugins.annotations.Mojo;
import org.apache.maven.plugins.annotations.Parameter;
import org.apache.maven.plugins.annotations.ResolutionScope;
import org.apache.maven.project.MavenProject;
import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.File;
@@ -111,9 +104,9 @@ public class MixinProcessorMojo
public static HashMap<String, MethodGarbageValue> methodGarbageValues = new HashMap<>();
public static HashMap<String, byte[]> gamepack = new HashMap<>();
private static HashMap<String, byte[]> gamepack = new HashMap<>();
public static final int BUFFER_SIZE = 1024 * 1024 * 4;
private static final int BUFFER_SIZE = 1024 * 1024 * 4;
public void execute()
throws MojoExecutionException
@@ -257,7 +250,7 @@ public class MixinProcessorMojo
}
public void stderr(String s, Object... format)
private void stderr(String s, Object... format)
{
getLog().info(String.format(s, format));
}
@@ -267,7 +260,7 @@ public class MixinProcessorMojo
INST.stderr(s, format);
}
static void deleteDir(File file) throws IOException
private static void deleteDir(File file) throws IOException
{
if (!file.exists())
{

View File

@@ -31,5 +31,5 @@ public enum InjectionType
APPEND,
OVERWRITE,
PREPEND,
PROVIDED;
PROVIDED
}

View File

@@ -26,8 +26,6 @@
package us.runelitepl.mixinprocessor.generators;
import us.runelitepl.mixinprocessor.transformers.AnnotationRemoverTransformer;
import us.runelitepl.mixinprocessor.transformers.AsmMethodGarbageTransformer;
import us.runelitepl.mixinprocessor.transformers.AsmMethodSignatureTransformer;
import us.runelitepl.mixinprocessor.transformers.AsmNameTransformer;
import us.runelitepl.mixinprocessor.transformers.AsmStaticUsageTransformer;
import us.runelitepl.mixinprocessor.transformers.DoNothingTransformer;

View File

@@ -25,18 +25,12 @@
package us.runelitepl.mixinprocessor.generators;
import javassist.CannotCompileException;
import javassist.CtClass;
import javassist.NotFoundException;
import us.runelitepl.mixinprocessor.MixinProcessorMojo;
import us.runelitepl.mixinprocessor.util.JavassistUtils;
import us.runelitepl.mixinprocessor.util.RefUtils;
import org.objectweb.asm.ClassReader;
import org.objectweb.asm.tree.ClassNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
@@ -45,11 +39,11 @@ import java.util.Set;
public class StaticGenerator
{
public static HashMap<String, ArrayList<MethodNode>> staticMethods = new HashMap<>();
public static HashMap<String, ArrayList<FieldNode>> staticFields = new HashMap<>();
public static Set<String> modifiedClasses = new HashSet<>();
static HashMap<String, ArrayList<MethodNode>> staticMethods = new HashMap<>();
static HashMap<String, ArrayList<FieldNode>> staticFields = new HashMap<>();
static Set<String> modifiedClasses = new HashSet<>();
public void run(byte[] bytecode) throws NotFoundException, IOException, CannotCompileException
public void run(byte[] bytecode)
{
ClassReader cr = new ClassReader(bytecode);
@@ -68,7 +62,7 @@ public class StaticGenerator
continue;
}
String reobbed = RefUtils.reobMethodName(RefUtils.STATICS_STRING, methodName, method.desc);
if(reobbed == null)
if (reobbed == null)
{
MixinProcessorMojo.log("Failed to reob static method: %s %s", methodName, method.desc);
throw new RuntimeException();
@@ -93,7 +87,7 @@ public class StaticGenerator
continue;
}
String reobbed = RefUtils.reobFieldName(RefUtils.STATICS_STRING, fieldName, field.desc);
if(reobbed == null)
if (reobbed == null)
{
MixinProcessorMojo.log("Failed to reob static field: %s %s", fieldName, field.desc);
throw new RuntimeException();

View File

@@ -36,7 +36,6 @@ import org.objectweb.asm.tree.AnnotationNode;
import org.objectweb.asm.tree.FieldNode;
import org.objectweb.asm.tree.MethodNode;
import org.objectweb.asm.tree.TypeAnnotationNode;
import us.runelitepl.mixinprocessor.MixinProcessorMojo;
import us.runelitepl.mixinprocessor.parsers.MethodReflector;
import java.util.HashMap;

View File

@@ -48,7 +48,7 @@ public class GamepackDownloader
ZipInputStream zipInputStream = new ZipInputStream(new ByteArrayInputStream(gamepackJarAry));
byte[] buffer = new byte[2048];
ZipEntry entry;
ByteArrayOutputStream fileContent = new ByteArrayOutputStream(1024*1024*4);
ByteArrayOutputStream fileContent = new ByteArrayOutputStream(1024 * 1024 * 4);
while ((entry = zipInputStream.getNextEntry()) != null)
{
if (entry.getName().startsWith("META-INF"))
@@ -56,8 +56,8 @@ public class GamepackDownloader
continue;
}
String key = entry.getName().replace(".class", "");
int len = 0;
while((len = zipInputStream.read(buffer)) > 0)
int len;
while ((len = zipInputStream.read(buffer)) > 0)
{
fileContent.write(buffer, 0, len);
}
@@ -83,7 +83,7 @@ public class GamepackDownloader
}
}
public static String getGamepackUrl()
private static String getGamepackUrl()
{
return codebase + initial_jar;
}

View File

@@ -71,7 +71,7 @@ public class HooksParser
String f_owner = (String) field.get("owner");
long f_decoder = (long) field.getOrDefault("decoder", (long) 1);
String f_deobbedOwner = null;
if(f_deobbedName.startsWith("__"))
if (f_deobbedName.startsWith("__"))
{
continue;
}
@@ -104,7 +104,7 @@ public class HooksParser
String m_deobbedOwner = null;
String m_obbedName = (String) method.get("name");
String m_descriptor = (String) method.get("descriptor");
if(m_deobbedName.startsWith("__"))
if (m_deobbedName.startsWith("__"))
{
continue;
}

View File

@@ -51,7 +51,7 @@ public class MethodAnnotationParser
public void run() throws ClassNotFoundException
{
for(CtMethod method : patch.getDeclaredMethods())
for (CtMethod method : patch.getDeclaredMethods())
{
Object[] annotations = method.getAnnotations();
@@ -112,7 +112,7 @@ public class MethodAnnotationParser
}
}
if(reobfuscate)
if (reobfuscate)
{
MixinProcessorMojo.log("Marking: %s %s %s", method.getDeclaringClass().getSimpleName(), methodName,
RefUtils.reobMethodDescriptor(method.getSignature()));

View File

@@ -96,7 +96,7 @@ public class AnnotationRemoverTransformer extends AsmBaseTransformer
return cw.toByteArray();
}
public static String makeAnnotationDescriptor(String s)
static String makeAnnotationDescriptor(String s)
{
return "Lus/runelitepl/mixinprocessor/annotations/" + s + ";";
}

View File

@@ -34,11 +34,12 @@ public abstract class AsmBaseTransformer implements Opcodes
protected final ArrayList<String> validMethods = new ArrayList<>();
protected final ArrayList<String> validFields = new ArrayList<>();
// CHECKSTYLE:OFF
protected void buildMethodList(){}
protected void buildFieldList(){}
// CHECKSTYLE:ON
public abstract byte[] transform();
}

View File

@@ -32,8 +32,6 @@ import org.objectweb.asm.MethodVisitor;
import us.runelitepl.mixinprocessor.MethodGarbageValue;
import us.runelitepl.mixinprocessor.MixinProcessorMojo;
import us.runelitepl.mixinprocessor.util.RefUtils;
import java.sql.Ref;
import java.util.HashMap;
public class AsmMethodGarbageTransformer extends AsmBaseTransformer
@@ -74,13 +72,13 @@ public class AsmMethodGarbageTransformer extends AsmBaseTransformer
// mv.visitLdcInsn(BIPUSH, constant);
// call super method with new descriptor
if(RefUtils.shouldReobMethod(owner, name, desc))
if (RefUtils.shouldReobMethod(owner, name, desc))
{
String nc = RefUtils.reobMethodName(owner, name, desc).split(" ")[0];
String nn = RefUtils.reobMethodName(owner, name, desc).split(" ")[1];
String nd = RefUtils.reobMethodDescriptor(desc);
MethodGarbageValue value;
if((value = MixinProcessorMojo.methodGarbageValues.getOrDefault(String.format("%s.%s%s",
if ((value = MixinProcessorMojo.methodGarbageValues.getOrDefault(String.format("%s.%s%s",
nc, nn, nd), null)) != null)
{
switch (value.getType())

View File

@@ -72,7 +72,7 @@ public class AsmMethodSignatureTransformer extends AsmBaseTransformer
private String fixMethodDesc(String className, String name, String desc)
{
if(className.startsWith(RefUtils.TYPE_PREFIX))
if (className.startsWith(RefUtils.TYPE_PREFIX))
{
className = className.substring(RefUtils.TYPE_PREFIX.length());
}

View File

@@ -32,11 +32,6 @@ import org.objectweb.asm.MethodVisitor;
import us.runelitepl.mixinprocessor.MixinProcessorMojo;
import us.runelitepl.mixinprocessor.util.RefUtils;
import static org.objectweb.asm.Opcodes.ASM6;
import static org.objectweb.asm.Opcodes.GETSTATIC;
import static org.objectweb.asm.Opcodes.INVOKESTATIC;
import static org.objectweb.asm.Opcodes.PUTSTATIC;
public class AsmStaticUsageTransformer extends AsmBaseTransformer
{
@@ -89,7 +84,7 @@ public class AsmStaticUsageTransformer extends AsmBaseTransformer
@Override
public void visitMethodInsn(int opcode, String owner, String name, String descriptor, boolean isInterface)
{
if(opcode == INVOKESTATIC && owner.endsWith(RefUtils.STATICS_STRING))
if (opcode == INVOKESTATIC && owner.endsWith(RefUtils.STATICS_STRING))
{
String originalOwner = owner.replace(TYPE_PREFIX, "");
String temp = RefUtils.reobMethodName(RefUtils.STATICS_STRING, name, descriptor);

View File

@@ -47,10 +47,10 @@ public class DoNothingTransformer extends AsmBaseTransformer
ClassReader cr = new ClassReader(bytecode);
ClassWriter cw = new ClassWriter(cr, ClassWriter.COMPUTE_FRAMES);
// CHECKSTYLE:OFF
cr.accept(new ClassVisitor(ASM6, cw)
{}, 0);
//CHECKSTYLE:ON
return cw.toByteArray();
}
}

View File

@@ -53,22 +53,22 @@ public class ProvidedRemoverTransformer extends AsmBaseTransformer
ClassNode node = new ClassNode();
cr.accept(node, 0);
for(Object obj : node.methods)
for (Object obj : node.methods)
{
MethodNode method = (MethodNode) obj;
if(method == null)
if (method == null)
{
MixinProcessorMojo.log("ProvidedRemoverTransformer: Method null?");
continue;
}
if(method.visibleAnnotations == null)
if (method.visibleAnnotations == null)
{
continue;
}
for(Object obj2 : method.visibleAnnotations)
for (Object obj2 : method.visibleAnnotations)
{
AnnotationNode annot = (AnnotationNode) obj2;
if(annot.desc.equals(AnnotationRemoverTransformer.makeAnnotationDescriptor("Provided")))
if (annot.desc.equals(AnnotationRemoverTransformer.makeAnnotationDescriptor("Provided")))
{
validMethods.add(method.access + " " + method.desc + " " + method.name);
}
@@ -88,7 +88,7 @@ public class ProvidedRemoverTransformer extends AsmBaseTransformer
public MethodVisitor visitMethod(int access, String name, String desc, String signature,
String[] exceptions)
{
if(validMethods.contains(access + " " + desc + " " + name))
if (validMethods.contains(access + " " + desc + " " + name))
{
return null;
}

View File

@@ -125,7 +125,7 @@ public class RefUtils
public static String reobMethodName(String owner, String deob, String signature)
{
String prefix = "";
if(owner.startsWith(RefUtils.TYPE_PREFIX))
if (owner.startsWith(RefUtils.TYPE_PREFIX))
{
owner = owner.substring(RefUtils.TYPE_PREFIX.length());
}
@@ -169,11 +169,7 @@ public class RefUtils
i++;
}
}
if (i == 1)
{
return true;
}
return false;
return i == 1;
}
@Deprecated
@@ -187,11 +183,7 @@ public class RefUtils
i++;
}
}
if (i == 1)
{
return true;
}
return false;
return i == 1;
}
public static boolean shouldReobField(String owner, String deob, String desc)
@@ -205,7 +197,7 @@ public class RefUtils
public static boolean shouldReobMethod(String owner, String deob, String desc)
{
if(owner.startsWith(RefUtils.TYPE_PREFIX))
if (owner.startsWith(RefUtils.TYPE_PREFIX))
{
owner = owner.substring(RefUtils.TYPE_PREFIX.length());
}
@@ -275,7 +267,7 @@ public class RefUtils
{
obbedName = className;
}
deobbed.append("L" + obbedName + ";");
deobbed.append("L").append(obbedName ).append(";");
strIndex += sigPart.length();
}
catch (StringIndexOutOfBoundsException ex)

View File

@@ -50,14 +50,17 @@ public class WebUtils
return pageText;
}
public static byte[] downloadFile(String urlText) throws IOException {
public static byte[] downloadFile(String urlText) throws IOException
{
URL url = new URL(urlText);
ByteArrayOutputStream output = new ByteArrayOutputStream();
try (InputStream inputStream = url.openStream()) {
int n = 0;
try (InputStream inputStream = url.openStream())
{
int n;
byte [] buffer = new byte[ 1024 ];
while (-1 != (n = inputStream.read(buffer))) {
while (-1 != (n = inputStream.read(buffer)))
{
output.write(buffer, 0, n);
}
}