@Override public void transform(ClassNode clazz, MethodNode method, InsnMatcher matcher) { AbstractInsnNode[] match = Iterators.getOnlyElement(matcher.match("BIPUSH ISTORE", m -> { IntInsnNode push = (IntInsnNode) m[0]; if (push.operand != 50) { return false; } VarInsnNode store = (VarInsnNode) m[1]; LocalVariableNode node = AsmUtils.getLocalVariable(method, store.var, store); return node != null && node.name.equals("resource") && node.desc.equals("I"); })); method.instructions.remove(match[0]); method.instructions.remove(match[1]); }
private String getMethodText(MethodNode node) { Type typeMethod = Type.getMethodType(node.desc); // Args string String args = ""; for (Type t : typeMethod.getArgumentTypes()) { args += getTypeStr(t, options) + ", "; } if (args.endsWith(", ")) { args = args.substring(0, args.length() - 2); } String s = italic(color(getTheme().memberReturnType, getTypeStr(typeMethod.getReturnType(), options))) + " "; s += color(getTheme().memberName, escape(node.name)) + "("; s += color(getTheme().memberParameterType, args); s += ")"; return s; }
@Override public void transform(ClassNode clazz, MethodNode method, InsnMatcher matcher) { method.tryCatchBlocks.clear(); method.localVariables.clear(); method.instructions.clear(); /* this.loginHandlerList.put(SteamIdAsString, loginHandler); */ method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); method.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, "com/wurmonline/server/steam/SteamHandler", "loginHandlerList", "Ljava/util/Map;")); method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 1)); method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 2)); method.instructions.add(new MethodInsnNode(Opcodes.INVOKEINTERFACE, "java/util/Map", "put", "(Ljava/lang/Object;Ljava/lang/Object;)Ljava/lang/Object;", true)); method.instructions.add(new InsnNode(Opcodes.POP)); /* return true; */ method.instructions.add(new InsnNode(Opcodes.ICONST_1)); method.instructions.add(new InsnNode(Opcodes.IRETURN)); }
public static <T> Class<? extends T> createSubClass(Class<T> superClass, String nameSuffix, int constructorParams) { ClassNode superNode = createClassNode(superClass); MethodNode constructor = findConstructor(superNode, constructorParams); String className = superClass.getName().replace('.', '/') + "_" + nameSuffix.replace(":", "_"); ClassWriter cw = new ClassWriter(0); cw.visit(V1_7, ACC_PUBLIC + ACC_SUPER, className, null, Type.getInternalName(superClass), null); // Constructor MethodVisitor mv = cw.visitMethod(ACC_PUBLIC, constructor.name, constructor.desc, null, null); int[] opcodes = createLoadOpcodes(constructor); for (int i = 0; i < opcodes.length; i++) { mv.visitVarInsn(opcodes[i], i); } mv.visitMethodInsn(INVOKESPECIAL, Type.getInternalName(superClass), constructor.name, constructor.desc, false); mv.visitInsn(RETURN); mv.visitMaxs(constructorParams + 1, constructorParams + 1); mv.visitEnd(); byte[] byteCode = cw.toByteArray(); return (Class<? extends T>) createClassFromBytes(className, byteCode); }
@Override public MethodTransformer[] getMethodTransformers() { MethodTransformer transformLoadWorld = new MethodTransformer() { @Override public MethodName getName() { return Names.Minecraft_loadWorld; } @Override public void transform(ClassNode classNode, MethodNode method, boolean obfuscated) { CLTLog.info("Found method: " + method.name + " " + method.desc); CLTLog.info("begining at start of method " + getName().all()); InsnList toInsert = new InsnList(); toInsert.add(new VarInsnNode(ALOAD, 1)); //worldClientIn toInsert.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(RenderUtil.class), "onWorldLoad", "(L" + Type.getInternalName(WorldClient.class) + ";)V", false)); method.instructions.insertBefore(method.instructions.getFirst(), toInsert); } }; return new MethodTransformer[] {transformLoadWorld}; }
@Override public MethodTransformer[] getMethodTransformers() { MethodTransformer loadWorldTransformer = new MethodTransformer() { public String getMethodName() {return CoreLoader.isObfuscated ? "a" : "loadWorld";} public String getDescName() {return "(L" + (CoreLoader.isObfuscated ? "bnq" : Type.getInternalName(WorldClient.class)) + ";Ljava/lang/String;)V";} public void transform(ClassNode classNode, MethodNode method, boolean obfuscated) { CLTLog.info("Found method: " + method.name + " " + method.desc); CLTLog.info("begining at start of method " + getMethodName()); //TransformerUtil.onWorldLoad(WorldClient worldClientIn) InsnList toInsert = new InsnList(); toInsert.add(new VarInsnNode(ALOAD, 1)); //worldClientIn toInsert.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(TransformerUtil.class), "onWorldLoad", "(L" + Type.getInternalName(WorldClient.class) + ";)V", false)); method.instructions.insertBefore(method.instructions.getFirst(), toInsert); } }; return new MethodTransformer[] {loadWorldTransformer}; }
private void checkArrayArgs(MethodNode methodNode, Frame<BasicValue> logMessageFrame, Frame<BasicValue> arraySizeFrame, int lineNumber, MethodInsnNode methodInsn, int messageIndex, int arrayIndex) { BasicValue arraySizeObject = getStackValue(arraySizeFrame, methodInsn, arrayIndex); if (arraySizeObject instanceof ArraySizeBasicValue == false) { wrongUsageCallback.accept(new WrongLoggerUsage(className, methodNode.name, methodInsn.name, lineNumber, "Could not determine size of array")); return; } ArraySizeBasicValue arraySize = (ArraySizeBasicValue) arraySizeObject; PlaceHolderStringBasicValue logMessageLength = checkLogMessageConsistency(methodNode, logMessageFrame, lineNumber, methodInsn, messageIndex, arraySize.minValue); if (logMessageLength == null) { return; } if (arraySize.minValue != arraySize.maxValue) { wrongUsageCallback.accept(new WrongLoggerUsage(className, methodNode.name, methodInsn.name, lineNumber, "Multiple parameter arrays with conflicting sizes")); return; } assert logMessageLength.minValue == logMessageLength.maxValue && arraySize.minValue == arraySize.maxValue; if (logMessageLength.minValue != arraySize.minValue) { wrongUsageCallback.accept(new WrongLoggerUsage(className, methodNode.name, methodInsn.name, lineNumber, "Expected " + logMessageLength.minValue + " arguments but got " + arraySize.minValue)); return; } }
private PlaceHolderStringBasicValue checkLogMessageConsistency(MethodNode methodNode, Frame<BasicValue> logMessageFrame, int lineNumber, MethodInsnNode methodInsn, int messageIndex, int argsSize) { BasicValue logMessageLengthObject = getStackValue(logMessageFrame, methodInsn, messageIndex); if (logMessageLengthObject instanceof PlaceHolderStringBasicValue == false) { if (argsSize > 0) { wrongUsageCallback.accept(new WrongLoggerUsage(className, methodNode.name, methodInsn.name, lineNumber, "First argument must be a string constant so that we can statically ensure proper place holder usage")); } else { // don't check logger usage for logger.warn(someObject) } return null; } PlaceHolderStringBasicValue logMessageLength = (PlaceHolderStringBasicValue) logMessageLengthObject; if (logMessageLength.minValue != logMessageLength.maxValue) { wrongUsageCallback.accept(new WrongLoggerUsage(className, methodNode.name, methodInsn.name, lineNumber, "Multiple log messages with conflicting number of place holders")); return null; } return logMessageLength; }
private void replaceInvokeSpecial(ClassNode clazz, List<MethodNode> toReplace) { for (MethodNode method : clazz.methods) { for (Iterator<AbstractInsnNode> it = method.instructions.iterator(); it.hasNext();) { AbstractInsnNode insn = it.next(); if (insn.getOpcode() == INVOKESPECIAL) { MethodInsnNode mInsn = (MethodInsnNode) insn; for (MethodNode n : toReplace) { if (n.name.equals(mInsn.name) && n.desc.equals(mInsn.desc)) { mInsn.setOpcode(INVOKEVIRTUAL); break; } } } } } }
private Detour callDetour(ClassNode cn, MethodNode mn, AnnotationNode a) { String owner = getFirstParameter(mn); if (owner == null) { _log.debug("Could not get parameter type for detour " + mn.name + mn.desc); return null; } MethodInsnNode mi = getMethodInstruction(mn, owner, mn.name); if (mi == null) { _log.debug("Could not get method instruction for detour " + mn.name + mn.desc); return null; } CallDetour detour = new CallDetour(_log); detour.matchMethod = mn.name; detour.matchDesc = mi.desc; detour.owner = owner.replace('/', '.'); detour.detourOwner = cn.name; detour.detourDesc = mn.desc; return detour; }
@SuppressWarnings(UNCHECKED) void analyzeInnerClass(ClassNode innerClass) { if (methodNode.name.equals(innerClass.outerMethod) && methodNode.desc.equals(innerClass.outerMethodDesc)) { // s'il y a une classe interne créée dans cette méthode // utilisant éventuellement une variable finale de cette méthode, // alors on cherche les constantes de variables (et uniquement celles-ci) dans toutes ses méthodes // (si ce n'est pas une constante, alors elle serait déjà détectée utilisée dans la méthode) for (final MethodNode innerMethodNode : (List<MethodNode>) innerClass.methods) { for (final Iterator<AbstractInsnNode> it = innerMethodNode.instructions .iterator(); it.hasNext();) { // CHECKSTYLE:OFF final AbstractInsnNode instruction = it.next(); // CHECKSTYLE:ON analyzeConstantInstruction(instruction); if (localVariables.isEmpty()) { // si toutes les variables ont été utilisées, inutile de continuer à lire les instructions return; } } } } }
@SuppressWarnings("unchecked") private void analyzeClassesForLocalDeadCode(String dir, Set<String> classesToVisit) throws IOException, XMLStreamException { for (final String className : classesToVisit) { if (isInterrupted()) { break; } // les classes *SoapBindingStub générées par Apache Axis // contiennent beaucoup des variables locales non utilisées, // mais il est inutile de le signaler puisque c'est généré par Axis if (!className.endsWith("SoapBindingStub")) { final ClassNode classNode = new ClassNode(); final ClassReader classReader = createClassReader(dir, className); classReader.accept(classNode, ClassReader.EXPAND_FRAMES); for (final MethodNode methodNode : (List<MethodNode>) classNode.methods) { analyzeMethodForLocalDeadCode(dir, className, classNode, methodNode); analyzeMethodForSelfAssignments(className, methodNode); if (Factory.createStringToStringAnalyzer(methodNode).analyze()) { report.reportStringToString(className, methodNode); suspectCount++; } } } } }
private void stripMethod(ClassNode classNode, String methodDescriptor) { if(classNode.name.endsWith("$class")) { String subName = classNode.name.substring(0, classNode.name.length() - 6); int pos = methodDescriptor.indexOf('(') + 1; methodDescriptor = methodDescriptor.substring(0, pos) + 'L' + subName + ';' + methodDescriptor.substring(pos); } for (ListIterator<MethodNode> iterator = classNode.methods.listIterator(); iterator.hasNext();) { MethodNode method = iterator.next(); if (methodDescriptor.equals(method.name+method.desc)) { iterator.remove(); if (logDebugInfo) FMLRelaunchLog.finer("Optional removal - method %s removed", methodDescriptor); return; } } if (logDebugInfo) FMLRelaunchLog.finer("Optional removal - method %s NOT removed - not found", methodDescriptor); }
private MergeAdapter(ClassSet set, ClassVisitor cv, ClassNode cn) { super(CompilationConfig.ASM_API_VERSION, cv); this.classToMerge = cn; this.set = set; boolean hasInit = false; for (Object o : classToMerge.methods) { String name = ((MethodNode)o).name; if (name.equals("<init>")) { continue; } if (name.equals(SignatureHolder.DRILL_INIT_METHOD)) { hasInit = true; } mergingNames.add(name); } this.hasInit = hasInit; }
private boolean isLocalVariableAnnotationFound(List<Annotation> annotationRules, MethodNode methodNode) { boolean annotationFound = true; List<AnnotationNode> allLocalVariableAnnotations = new ArrayList<>(); List<LocalVariableAnnotationNode> invisibleVariableAnnotations = methodNode.invisibleLocalVariableAnnotations; if (invisibleVariableAnnotations != null) { allLocalVariableAnnotations.addAll(invisibleVariableAnnotations); } List<LocalVariableAnnotationNode> visibleVariableAnnotations = methodNode.visibleLocalVariableAnnotations; if (visibleVariableAnnotations != null) { allLocalVariableAnnotations.addAll(visibleVariableAnnotations); } for (Annotation annotationRule : annotationRules) { annotationFound &= RuleHelper.containsAnnotation(annotationRule, allLocalVariableAnnotations); } return annotationFound; }
private EContextMenu(Context context, JPopupMenu menu, ClassDisplayPanel display, FieldNode field, MethodNode method, AbstractInsnNode ain) { this.context = context; this.menu = menu; this.display = display; this.field = field; this.method = method; this.ain = ain; }
public AbsFuncType[] getLocalConstructors() throws CompileException { @SuppressWarnings("unchecked") List<MethodNode> methods = class_node.methods; MethodNode method = null; TResolvedFunc rsol_func = null; LinkedList<TResolvedFunc> const_list = new LinkedList<TResolvedFunc>(); int len = methods.size(); for (int i = 0; i < len; i++) { method = methods.get(i); if (AbsClassType.CONSTRUCTOR_NAME.equals(method.name)) { rsol_func = new TResolvedFunc(this, method, cpLoader); rsol_func.setIsConstuctor(true); const_list.add(rsol_func); } } if (const_list.size() == 0) { return null; } AbsFuncType[] arr = new AbsFuncType[const_list.size()]; for (int i = 0; i < arr.length; i++) { arr[i] = (AbsFuncType) const_list.get(i); } return arr; }
public int getIndexOfVar(MethodNode m, String desc, String signature) { desc = patchDESC(desc); signature = signature == null ? null : patchDESC(signature); for (Iterator<LocalVariableNode> iterator = m.localVariables.iterator(); iterator.hasNext();) { LocalVariableNode local = iterator.next(); if (local.desc.equals(desc) && (signature == null || signature.equals(local.signature))) return local.index; } return -1; }
@Override public MethodVisitor visitMethod(final int access, final String name, final String desc, final String signature, final String[] exceptions) { MethodNode mn = new TrackingMethodNode(this, access, name, desc, signature, exceptions); methods.add(mn); return mn; }
@Override public void transform(ClassNode clazz, MethodNode method, InsnMatcher matcher) { method.tryCatchBlocks.clear(); method.instructions.clear(); method.localVariables.clear(); /* return true; */ method.instructions.add(new InsnNode(Opcodes.ICONST_1)); method.instructions.add(new InsnNode(Opcodes.IRETURN)); // TODO adjust maxLocals and maxStack? }
private MethodInstance(ClassInstance cls, String origName, String desc, MethodNode asmNode, boolean nameObfuscated, int position, boolean isStatic) { super(cls, getId(origName, desc), origName, nameObfuscated, position, isStatic); this.asmNode = asmNode; this.args = gatherArgs(this, desc); //this.vars = gatherVars(this); this.retType = cls.getEnv().getCreateClassInstance(Type.getReturnType(desc).getDescriptor()); classRefs.add(retType); retType.methodTypeRefs.add(this); }
private static void dump(MethodNode method) { Textifier textifier = new Textifier(); method.accept(new TraceMethodVisitor(textifier)); StringWriter writer = new StringWriter(); try (PrintWriter pw = new PrintWriter(writer)) { textifier.print(pw); } System.out.println(writer.toString()); }
@Override public MethodTransformer[] getMethodTransformers() { MethodTransformer transformRenderParticle = new MethodTransformer() { @Override public MethodName getName() { return Names.Particle_renderParticle; } @Override public void transform(ClassNode classNode, MethodNode method, boolean obfuscated) { CLTLog.info("Found method: " + method.name + " " + method.desc); for (AbstractInsnNode instruction : method.instructions.toArray()) { if (instruction.getOpcode() == ANEWARRAY) { CLTLog.info("Found ANEWARRAY in method " + getName().all()); instruction = instruction.getPrevious(); transformParticle(classNode, method, instruction, 14); break; } } } }; return new MethodTransformer[] {transformRenderParticle}; }
/** * Generates a new clinit. * @param className * @param target */ private void insertClassInit(String className, ClassNode target) { // method void static clinit() MethodNode clinit = new MethodNode(Opcodes.ASM5, Opcodes.ACC_STATIC | Opcodes.ACC_SYNTHETIC, CLASS_INIT_NAME, CLASS_INIT_DESC, null, new String[0] ); transformClassInit(className, clinit); target.methods.add(clinit); }
static void printAnalyzerResult(MethodNode method, Analyzer<BasicValue> a, final PrintWriter pw) { Frame<BasicValue>[] frames = a.getFrames(); Textifier t = new Textifier(); TraceMethodVisitor mv = new TraceMethodVisitor(t); pw.println(method.name + method.desc); for (int j = 0; j < method.instructions.size(); ++j) { method.instructions.get(j).accept(mv); StringBuilder sb = new StringBuilder(); Frame<BasicValue> f = frames[j]; if (f == null) { sb.append('?'); } else { for (int k = 0; k < f.getLocals(); ++k) { sb.append(getShortName(f.getLocal(k).toString())) .append(' '); } sb.append(" : "); for (int k = 0; k < f.getStackSize(); ++k) { sb.append(getShortName(f.getStack(k).toString())) .append(' '); } } while (sb.length() < method.maxStack + method.maxLocals + 1) { sb.append(' '); } pw.print(Integer.toString(j + 100000).substring(1)); pw.print(" " + sb + " : " + t.text.get(t.text.size() - 1)); } for (int j = 0; j < method.tryCatchBlocks.size(); ++j) { method.tryCatchBlocks.get(j).accept(mv); pw.print(" " + t.text.get(t.text.size() - 1)); } pw.println(); }
@Override public MethodTransformer[] getMethodTransformers() { MethodTransformer transformRenderParticle = new MethodTransformer() { @Override public MethodName getName() { return Names.Particle_renderParticle; } @Override public void transform(ClassNode classNode, MethodNode method, boolean obfuscated) { CLTLog.info("Found method: " + method.name + " " + method.desc); for (AbstractInsnNode instruction : method.instructions.toArray()) { if (instruction.getOpcode() == ISHR) { CLTLog.info("Found ISHR in method " + getName().all()); for (int i = 0; i < 12; i++) { instruction = instruction.getNext(); } transformParticle(classNode, method, instruction, 14); break; } } } }; return new MethodTransformer[] {transformRenderParticle}; }
private void setupMethodsFrame() { frameMethods = new JInternalFrame("Methods"); frameMethods.setResizable(true); frameMethods.setIconifiable(true); int fw = frameFields == null ? 0 : frameFields.getWidth(); frameMethods.setBounds(fw + frameClass.getWidth() + 11, 11, 180, 120); frameMethods.setVisible(true); frameMethods.setLayout(new BorderLayout()); methods = new JList<>(); methods.setCellRenderer(new MemberNodeRenderer()); methods.addMouseListener(new MemberNodeClickListener(this, node, methods)); DefaultListModel<MethodNode> model = new DefaultListModel<>(); for (MethodNode mn : node.methods) { model.addElement(mn); } if (node.methods.size() == 0) { methods.setVisibleRowCount(5); methods.setPrototypeCellValue(new MethodNode(0, "Add_A_Method", "()Ljava/lang/Object;", null, null)); } methods.setModel(model); frameMethods.add(new JScrollPane(methods), BorderLayout.CENTER); // TODO: Switch to table. A table may be bigger but allows for sorting // of members. // // frameMethods.add(new JScrollPane(MemberTable.create(node.methods)), // BorderLayout.CENTER); frameMethods.pack(); }
@Override public void transform(ClassNode clazz, MethodNode method, InsnMatcher matcher) { method.tryCatchBlocks.clear(); method.instructions.clear(); method.localVariables.clear(); /* return invulnerable || trader; */ LabelNode trueLabel = new LabelNode(); LabelNode falseLabel = new LabelNode(); LabelNode returnLabel = new LabelNode(); method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); method.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, clazz.name, "invulnerable", "Z")); method.instructions.add(new JumpInsnNode(Opcodes.IFNE, trueLabel)); method.instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); method.instructions.add(new FieldInsnNode(Opcodes.GETFIELD, clazz.name, "trader", "Z")); method.instructions.add(new JumpInsnNode(Opcodes.IFEQ, falseLabel)); method.instructions.add(trueLabel); method.instructions.add(new InsnNode(Opcodes.ICONST_1)); method.instructions.add(new JumpInsnNode(Opcodes.GOTO, returnLabel)); method.instructions.add(falseLabel); method.instructions.add(new InsnNode(Opcodes.ICONST_0)); method.instructions.add(returnLabel); method.instructions.add(new InsnNode(Opcodes.IRETURN)); // TODO adjust maxLocals and maxStack? }
@Override public MethodTransformer[] getMethodTransformers() { MethodTransformer transformSetupCameraTransform = new MethodTransformer() { public String getMethodName() {return CoreLoader.isObfuscated ? "a" : "setupCameraTransform";} public String getDescName() {return "(FI)V";} /** * Transforms {@link net.minecraft.client.renderer.EntityRenderer#setupCameraTransform()} */ public void transform(ClassNode classNode, MethodNode method, boolean obfuscated) { CLTLog.info("Found method: " + method.name + " " + method.desc); for (AbstractInsnNode instruction : method.instructions.toArray()) { if (instruction.getOpcode() == TABLESWITCH) { CLTLog.info("Found tableswitch in method " + getMethodName()); //Go back to orientCamera for (int i = 0; i < 8+4; i++) { instruction = instruction.getPrevious(); } InsnList toInsert = new InsnList(); //GlStateManager.translate(0, 0, -0.05F); toInsert.add(new InsnNode(FCONST_0)); //0 toInsert.add(new InsnNode(FCONST_0)); //0 toInsert.add(new LdcInsnNode(-0.05f)); //-0.05 toInsert.add(new MethodInsnNode(INVOKESTATIC, Type.getInternalName(GlStateManager.class), obfuscated ? "func_179109_b" : "translate", "(FFF)V", false)); method.instructions.insertBefore(instruction, toInsert); break; } } } }; return new MethodTransformer[] {transformSetupCameraTransform}; }
public OpcodeListBox(ClassDisplayPanel display, MethodNode mn) throws Exception { super("Opcodes: " + mn.name); setBackground(bg); setLayout(new BorderLayout()); setMaximumSize(new Dimension(900, 900)); // Opcodes list add(new JScrollPane(list = new OpcodeList(display, mn)), BorderLayout.CENTER); setVisible(true); }
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { MethodNode node = new JSRInlinerAdapter(null, access, name, desc, signature, exceptions); JarCode code = context.lookupMap.get(application.getMethod(context.owner.type, name, desc)); if (code != null) { code.context = null; code.node = node; return node; } return null; }
@Override public void visitEnd() { if (ignoreChecks == false) { findBadLoggerUsages((MethodNode) mv); } super.visitEnd(); }
private void stripInterface(ClassNode classNode, String interfaceName, boolean stripRefs) { final String ifaceName = interfaceName.replace('.', '/'); boolean found = classNode.interfaces.remove(ifaceName); if (found && classNode.signature != null) { SignatureReader sr = new SignatureReader(classNode.signature); final RemovingSignatureWriter signatureWriter = new RemovingSignatureWriter(ifaceName); sr.accept(signatureWriter); classNode.signature = signatureWriter.toString(); if (logDebugInfo) FMLRelaunchLog.finer("Optional removal - interface %s removed from type signature"); } if (found && logDebugInfo) FMLRelaunchLog.finer("Optional removal - interface %s removed", interfaceName); if (!found && logDebugInfo) FMLRelaunchLog.finer("Optional removal - interface %s NOT removed - not found", interfaceName); if (found && stripRefs) { if (logDebugInfo) FMLRelaunchLog.finer("Optional removal - interface %s - stripping method signature references", interfaceName); for (Iterator<MethodNode> iterator = classNode.methods.iterator(); iterator.hasNext();) { MethodNode node = iterator.next(); if (node.desc.contains(ifaceName)) { if (logDebugInfo) FMLRelaunchLog.finer("Optional removal - interface %s - stripping method containing reference %s", interfaceName, node.name); iterator.remove(); } } if (logDebugInfo) FMLRelaunchLog.finer("Optional removal - interface %s - all method signature references stripped", interfaceName); } else if (found) { if (logDebugInfo) FMLRelaunchLog.finer("Optional removal - interface %s - NOT stripping method signature references", interfaceName); } }
@Override public void transform(ClassNode clazz, MethodNode method, InsnMatcher matcher) { method.instructions.clear(); method.localVariables.clear(); method.tryCatchBlocks.clear(); method.instructions.add(new InsnNode(Opcodes.ICONST_1)); method.instructions.add(new InsnNode(Opcodes.IRETURN)); // TODO adjust maxLocals and maxStack? }
public BasicFrame openVariables(MethodNode method) { BasicFrame box = null; try { addWindow(box = new BasicFrame(method.name + ": Variables")); box.add(new JScrollPane(VariableTable.create(null, method))); box.setVisible(true); } catch (Exception e) { exception(e); } return box; }
public DefinitionBox(MethodNode mn, JList<?> list) { super("Definition: " + mn.name); setMaximumSize(new Dimension(700, 700)); setLayout(new GridBagLayout()); GridBagConstraints c = new GridBagConstraints(); c.weightx = 1.0; c.anchor = GridBagConstraints.WEST; c.fill = GridBagConstraints.HORIZONTAL; add(c, new JLabel("Name:"), new ActionTextField(mn.name, n -> { mn.name = n; list.repaint(); })); add(c, new JLabel("Descriptor:"), new ActionTextField(mn.desc, d -> { mn.desc = d; list.repaint(); })); add(c, new JLabel("Signature:"), new ActionTextField(mn.signature == null ? "" : mn.signature, s -> { if (s.isEmpty()) { mn.signature = null; } else { mn.signature = s; } })); add(c, new AccessPanel(mn, null)); // Exceptions JPanel exceptions = new JPanel(); exceptions.setBorder(BorderFactory.createTitledBorder("Exceptions")); exceptions.setLayout(new BoxLayout(exceptions, BoxLayout.Y_AXIS)); update(exceptions, mn); add(c, exceptions); setVisible(true); }
@Override public MethodVisitor visitMethod(int access, String name, String desc, String signature, String[] exceptions) { AcesoProguardMap.instance().putMethod(visitedClassName, IncrementalTool.getMtdSig(name, desc)); access = IncrementalTool.transformAccessForInstantRun(access); MethodVisitor defaultVisitor = super.visitMethod(access, name, desc, signature, exceptions); MethodNode method = getMethodByNameInClass(name, desc, classNode); // does the method use blacklisted APIs. boolean hasIncompatibleChange = InstantRunMethodVerifier.verifyMethod(method); if (hasIncompatibleChange || disableRedirectionForClass || !isAccessCompatibleWithInstantRun(access) || name.equals(ByteCodeUtils.CLASS_INITIALIZER)) { return defaultVisitor; } else { ArrayList<Type> args = new ArrayList<Type>(Arrays.asList(Type.getArgumentTypes(desc))); boolean isStatic = (access & Opcodes.ACC_STATIC) != 0; if (!isStatic) { args.add(0, Type.getType(Object.class)); } ISMethodVisitor mv = new ISMethodVisitor(defaultVisitor, access, name, desc); if (name.equals(ByteCodeUtils.CONSTRUCTOR)) { } else { mv.addRedirection(new MethodRedirection( new LabelNode(mv.getStartLabel()), visitedClassName, name, desc, args, Type.getReturnType(desc), isStatic)); } method.accept(mv); return null; } }
public MethodNode methodNode() { MethodNode node = new MethodNode(ACC_STATIC, "<clinit>", "()V", null, null); InsnList il = node.instructions; LabelNode begin = new LabelNode(); LabelNode end = new LabelNode(); il.add(begin); if (!context.hasUpvalues()) { il.add(new TypeInsnNode(NEW, context.thisClassType().getInternalName())); il.add(new InsnNode(DUP)); il.add(new MethodInsnNode( INVOKESPECIAL, context.thisClassType().getInternalName(), "<init>", ctorMethod.methodType().getDescriptor(), false)); il.add(new FieldInsnNode( PUTSTATIC, context.thisClassType().getInternalName(), context.instanceFieldName(), context.thisClassType().getDescriptor())); } if (!runMethod.constFields().isEmpty()) { for (RunMethod.ConstFieldInstance cfi : runMethod.constFields()) { il.add(cfi.instantiateInsns()); } } il.add(new InsnNode(RETURN)); il.add(end); return node; }
public static MethodNode findMethodNodeOfClass(ClassNode classNode, String methodName, String methodDesc) { for (MethodNode method : classNode.methods) { if (method.name.equals(methodName) && method.desc.equals(methodDesc)) { return method; } } return null; }
@Override public void transform(ClassNode clazz, MethodNode method, InsnMatcher matcher) { method.instructions.clear(); method.localVariables.clear(); method.tryCatchBlocks.clear(); method.instructions.add(new InsnNode(Opcodes.ICONST_0)); method.instructions.add(new InsnNode(Opcodes.IRETURN)); // TODO adjust maxLocals and maxStack? }