org.objectweb.asm.tree.MethodNode Java Examples
The following examples show how to use
org.objectweb.asm.tree.MethodNode.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NioBufferRefConverterTest.java From bazel with Apache License 2.0 | 6 votes |
@Test public void methodOfNioBufferWithCovariantTypes_afterDesugar( @AsmNode(className = "NioBufferInvocations", memberName = "getByteBufferPosition", round = 1) MethodNode after) { ImmutableList<AbstractInsnNode> methodInvocations = Arrays.stream(after.instructions.toArray()) .filter(insnNode -> insnNode.getType() == METHOD_INSN) .collect(toImmutableList()); assertThat(methodInvocations).hasSize(1); MethodInsnNode methodInsnNode = (MethodInsnNode) Iterables.getOnlyElement(methodInvocations); assertThat(methodInsnNode.owner).isEqualTo("java/nio/ByteBuffer"); assertThat(methodInsnNode.name).isEqualTo("position"); assertThat(methodInsnNode.desc).isEqualTo("(I)Ljava/nio/Buffer;"); TypeInsnNode typeInsnNode = (TypeInsnNode) methodInsnNode.getNext(); assertThat(typeInsnNode.getOpcode()).isEqualTo(Opcodes.CHECKCAST); assertThat(typeInsnNode.desc).isEqualTo("java/nio/ByteBuffer"); assertThat(typeInsnNode.getNext().getOpcode()).isEqualTo(Opcodes.ARETURN); }
Example #2
Source File: ClickableViewAccessibilityDetector.java From javaide with GNU General Public License v3.0 | 6 votes |
@SuppressWarnings("unchecked") // ASM API public static void scanForAndCheckSetOnTouchListenerCalls( ClassContext context, ClassNode classNode) { List<MethodNode> methods = classNode.methods; for (MethodNode methodNode : methods) { ListIterator<AbstractInsnNode> iterator = methodNode.instructions.iterator(); while (iterator.hasNext()) { AbstractInsnNode abstractInsnNode = iterator.next(); if (abstractInsnNode.getType() == AbstractInsnNode.METHOD_INSN) { MethodInsnNode methodInsnNode = (MethodInsnNode) abstractInsnNode; if (methodInsnNode.name.equals(SET_ON_TOUCH_LISTENER) && methodInsnNode.desc.equals(SET_ON_TOUCH_LISTENER_SIG)) { checkSetOnTouchListenerCall(context, methodNode, methodInsnNode); } } } } }
Example #3
Source File: Transformer.java From Diorite with MIT License | 6 votes |
private void addGlobalInjectInvokes() { MethodNode codeBefore = new MethodNode(); MethodNode codeAfter = new MethodNode(); this.fillMethodInvokes(codeBefore, codeAfter, this.classData); for (Entry<MethodNode, TransformerInitMethodData> initEntry : this.inits.entrySet()) { MethodNode init = initEntry.getKey(); TransformerInitMethodData initPair = initEntry.getValue(); MethodInsnNode superInvoke = initPair.superInvoke; if (codeAfter.instructions.size() > 0) { for (InsnNode node : initPair.returns) { init.instructions.insertBefore(node, codeAfter.instructions); } } if (codeBefore.instructions.size() > 0) { init.instructions.insert(superInvoke, codeBefore.instructions); } } }
Example #4
Source File: MyCodeList.java From JByteMod-Beta with GNU General Public License v2.0 | 6 votes |
protected void duplicate(MethodNode mn, AbstractInsnNode ain) { try { if (ain instanceof LabelNode) { mn.instructions.insert(ain, new LabelNode()); OpUtils.clearLabelCache(); } else if (ain instanceof JumpInsnNode) { mn.instructions.insert(ain, new JumpInsnNode(ain.getOpcode(), ((JumpInsnNode) ain).label)); } else { mn.instructions.insert(ain, ain.clone(new HashMap<>())); } MyCodeList.this.loadInstructions(mn); } catch (Exception e1) { new ErrorDisplay(e1); } }
Example #5
Source File: DefaultImplementationTransformer.java From CodeChickenCore with MIT License | 6 votes |
public boolean patch(ClassNode cnode) { LinkedList<String> names = new LinkedList<String>(); for(MethodNode method : cnode.methods) { ObfMapping m = new ObfMapping(cnode.name, method.name, method.desc).toRuntime(); names.add(m.s_name+m.s_desc); } boolean changed = false; for(MethodNode impl : impls) { if(names.contains(impl.name+impl.desc)) continue; MethodNode copy = new MethodNode(impl.access, impl.name, impl.desc, impl.signature, impl.exceptions == null ? null : impl.exceptions.toArray(new String[0])); ASMHelper.copy(impl, copy); cnode.methods.add(impl); changed = true; } return changed; }
Example #6
Source File: MixinPostProcessor.java From Mixin with MIT License | 6 votes |
/** * "Pass through" a synthetic inner class. Transforms package-private * members in the class into public so that they are accessible from their * new home in the target class */ private void processSyntheticInner(ClassNode classNode) { classNode.access |= Opcodes.ACC_PUBLIC; for (FieldNode field : classNode.fields) { if ((field.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) == 0) { field.access |= Opcodes.ACC_PUBLIC; } } for (MethodNode method : classNode.methods) { if ((method.access & (Opcodes.ACC_PRIVATE | Opcodes.ACC_PROTECTED)) == 0) { method.access |= Opcodes.ACC_PUBLIC; } } }
Example #7
Source File: ReflectionObfuscationVMT11.java From zelixkiller with GNU General Public License v3.0 | 6 votes |
@Override public void transform(JarArchive ja, ClassNode node) { if (twoLongType) { // init surroundings before decryption Outer: for (ClassNode cn : ja.getClasses().values()) { for (MethodNode mn : cn.methods) { for (AbstractInsnNode ain : mn.instructions.toArray()) { if (ain.getOpcode() == INVOKESPECIAL) { MethodInsnNode min = (MethodInsnNode) ain; if (min.owner.equals(node.name) && min.name.equals("<init>")) { try { Class.forName(cn.name.replace("/", "."), true, vm); } catch (ClassNotFoundException e) { } continue Outer; } } } } } } node.methods.forEach(mn -> removeDynamicCalls(node, mn)); }
Example #8
Source File: EntityPlayerSPPatch.java From ForgeHax with MIT License | 6 votes |
@Inject(description = "Add hook to disable pushing out of blocks") public void inject(MethodNode main) { AbstractInsnNode preNode = main.instructions.getFirst(); AbstractInsnNode postNode = ASMHelper.findPattern(main.instructions.getFirst(), new int[]{ICONST_0, IRETURN}, "xx"); Objects.requireNonNull(preNode, "Find pattern failed for pre node"); Objects.requireNonNull(postNode, "Find pattern failed for post node"); LabelNode endJump = new LabelNode(); InsnList insnPre = new InsnList(); insnPre.add(ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onPushOutOfBlocks)); insnPre.add(new JumpInsnNode(IFNE, endJump)); main.instructions.insertBefore(preNode, insnPre); main.instructions.insertBefore(postNode, endJump); }
Example #9
Source File: CustomMethodVisitor.java From custom-bytecode-analyzer with GNU General Public License v3.0 | 6 votes |
private boolean isParameterAnnotationFound(List<Annotation> annotationRules, MethodNode methodNode) { boolean annotationFound = true; List<AnnotationNode> allParameterAnnotations = new ArrayList<>(); List<AnnotationNode>[] visibleParameterAnnotations = methodNode.visibleParameterAnnotations; if (visibleParameterAnnotations != null && visibleParameterAnnotations.length != 0) { addIfNotNull(allParameterAnnotations, visibleParameterAnnotations); } List<AnnotationNode>[] inVisibleParameterAnnotations = methodNode.invisibleParameterAnnotations; if (inVisibleParameterAnnotations != null && inVisibleParameterAnnotations.length != 0) { addIfNotNull(allParameterAnnotations, inVisibleParameterAnnotations); } if (annotationRules != null && !annotationRules.isEmpty()) { for (Annotation annotationRule : annotationRules) { annotationFound &= RuleHelper.containsAnnotation(annotationRule, allParameterAnnotations); } } return annotationFound; }
Example #10
Source File: ChunkRenderDispatcherPatch.java From ForgeHax with MIT License | 6 votes |
@Inject(description = "Insert hook before buffer is uploaded") public void inject(MethodNode main) { AbstractInsnNode node = ASMHelper.findPattern( main.instructions.getFirst(), new int[]{ INVOKESTATIC, IFEQ, 0x00, 0x00, ALOAD, }, "xx??x"); Objects.requireNonNull(node, "Find pattern failed for node"); InsnList insnList = new InsnList(); insnList.add(new VarInsnNode(ALOAD, 3)); insnList.add(new VarInsnNode(ALOAD, 2)); insnList.add(ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onChunkUploaded)); main.instructions.insertBefore(node, insnList); }
Example #11
Source File: IncrementalChangeVisitor.java From AnoleFix with MIT License | 6 votes |
/** * Returns the actual method access right or a best guess if we don't have access to the * method definition. * * @param owner the method owner class * @param name the method name * @param desc the method signature * @return the {@link AccessRight} for that method. */ private AccessRight getMethodAccessRight(String owner, String name, String desc) { AccessRight accessRight; if (owner.equals(visitedClassName)) { MethodNode methodByName = getMethodByName(name, desc); if (methodByName == null) { // we did not find the method invoked on ourselves, which mean that it really // is a parent class method invocation and we just don't have access to it. // the most restrictive access right in that case is protected. return AccessRight.PROTECTED; } accessRight = AccessRight.fromNodeAccess(methodByName.access); } else { // we are accessing another class method, and since we make all protected and // package-private methods public, we can safely assume it is public. accessRight = AccessRight.PUBLIC; } return accessRight; }
Example #12
Source File: RenderBoatPatch.java From ForgeHax with MIT License | 6 votes |
@Inject(description = "Add hook to set boat yaw when it's rendered") public void inject(MethodNode main) { InsnList insnList = new InsnList(); insnList.add(new VarInsnNode(ALOAD, 1)); // load the boat entity insnList.add(new VarInsnNode(FLOAD, 8)); // load the boat yaw insnList.add( ASMHelper.call( INVOKESTATIC, TypesHook.Methods .ForgeHaxHooks_onRenderBoat)); // fire the event and get the value(player // rotationYaw) returned by the method in // ForgeHaxHooks insnList.add(new VarInsnNode(FSTORE, 8)); // store it in entityYaw main.instructions.insert(insnList); // insert code at the top of the method }
Example #13
Source File: BlockPatch.java From ForgeHax with MIT License | 6 votes |
@Inject(description = "Changes in layer code so that we can change it") public void inject(MethodNode main) { AbstractInsnNode node = ASMHelper.findPattern(main.instructions.getFirst(), new int[]{INVOKEVIRTUAL}, "x"); Objects.requireNonNull(node, "Find pattern failed for node"); InsnList insnList = new InsnList(); // starting after INVOKEVIRTUAL on Block.getBlockLayer() insnList.add(new VarInsnNode(ASTORE, 3)); // store the result from getBlockLayer() insnList.add(new VarInsnNode(ALOAD, 0)); // push this insnList.add(new VarInsnNode(ALOAD, 1)); // push block state insnList.add(new VarInsnNode(ALOAD, 3)); // push this.getBlockLayer() result insnList.add( new VarInsnNode(ALOAD, 2)); // push the block layer of the block we are comparing to insnList.add( ASMHelper.call(INVOKESTATIC, TypesHook.Methods.ForgeHaxHooks_onRenderBlockInLayer)); // now our result is on the stack main.instructions.insert(node, insnList); }
Example #14
Source File: MCStripTransformer.java From CodeChickenLib with GNU Lesser General Public License v2.1 | 6 votes |
public static byte[] transform(byte[] bytes) { ClassNode cnode = ASMHelper.createClassNode(bytes, ClassReader.EXPAND_FRAMES); boolean changed = false; Iterator<MethodNode> it = cnode.methods.iterator(); while (it.hasNext()) { MethodNode mnode = it.next(); ReferenceDetector r = new ReferenceDetector(); mnode.accept(new RemappingMethodAdapter(mnode.access, mnode.desc, new MethodVisitor(Opcodes.ASM4) { }, r)); if (r.found) { it.remove(); changed = true; } } if (changed) { bytes = ASMHelper.createBytes(cnode, 0); } return bytes; }
Example #15
Source File: ASMClassNodeAdapter.java From pinpoint with Apache License 2.0 | 6 votes |
public void addGetterMethod(final String methodName, final ASMFieldNodeAdapter fieldNode) { Assert.requireNonNull(methodName, "methodName"); Assert.requireNonNull(fieldNode, "fieldNode"); // no argument is (). final String desc = "()" + fieldNode.getDesc(); final MethodNode methodNode = new MethodNode(Opcodes.ACC_PUBLIC, methodName, desc, null, null); final InsnList instructions = getInsnList(methodNode); // load this. instructions.add(new VarInsnNode(Opcodes.ALOAD, 0)); // get fieldNode. instructions.add(new FieldInsnNode(Opcodes.GETFIELD, classNode.name, fieldNode.getName(), fieldNode.getDesc())); // return of type. final Type type = Type.getType(fieldNode.getDesc()); instructions.add(new InsnNode(type.getOpcode(Opcodes.IRETURN))); addMethodNode0(methodNode); }
Example #16
Source File: IncrementalSupportVisitor.java From Aceso with Apache License 2.0 | 5 votes |
@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; } }
Example #17
Source File: ByteCodeUtils.java From Stark with Apache License 2.0 | 5 votes |
/** * Converts the given method to a String. */ public static String textify(@NonNull MethodNode method) { Textifier textifier = new Textifier(); TraceMethodVisitor trace = new TraceMethodVisitor(textifier); method.accept(trace); String ret = ""; for (Object line : textifier.getText()) { ret += line; } return ret; }
Example #18
Source File: InjectionInfo.java From Mixin with MIT License | 5 votes |
private void checkTarget(MethodNode target) { AnnotationNode merged = Annotations.getVisible(target, MixinMerged.class); if (merged == null) { return; } if (Annotations.getVisible(target, Final.class) != null) { throw new InvalidInjectionException(this, String.format("%s cannot inject into @Final method %s::%s%s merged by %s", this, this.classNode.name, target.name, target.desc, Annotations.<String>getValue(merged, "mixin"))); } }
Example #19
Source File: AsmTestUtils.java From grappa with Apache License 2.0 | 5 votes |
public static void assertTraceDumpEquality( final MethodNode method, final String traceDump) throws Exception { Preconditions.checkNotNull(method, "method"); final Printer printer = new NonMaxTextifier(); final TraceMethodVisitor traceMethodVisitor = new TraceMethodVisitor(printer); // MethodAdapter checkMethodAdapter = new MethodAdapter(traceMethodVisitor); final MethodVisitor checkMethodAdapter = new CheckMethodAdapter(traceMethodVisitor); method.accept(checkMethodAdapter); final StringWriter stringWriter = new StringWriter(); final PrintWriter printWriter = new PrintWriter(stringWriter); printer.print(printWriter); printWriter.flush(); assertEquals(stringWriter.toString(), traceDump); }
Example #20
Source File: AsmTestUtils.java From grappa with Apache License 2.0 | 5 votes |
public static void verifyIntegrity( final String classInternalName, final byte[] classCode) { Preconditions.checkNotNull(classCode, "classCode"); final ClassNode generatedClassNode = new ClassNode(); final ClassReader classReader = new ClassReader(classCode); classReader.accept(generatedClassNode, 0); for (final Object methodObj : generatedClassNode.methods) { verifyMethodIntegrity(classInternalName, (MethodNode) methodObj); } }
Example #21
Source File: ASMMethodNodeAdapterTest.java From pinpoint with Apache License 2.0 | 5 votes |
@Test public void methodAccess() throws Exception { final String targetClassName = "com.navercorp.pinpoint.profiler.instrument.mock.MethodClass"; final MethodNode methodNode = ASMClassNodeLoader.get(targetClassName, "publicStaticMethod"); ASMMethodNodeAdapter adapter = new ASMMethodNodeAdapter(JavaAssistUtils.javaNameToJvmName(targetClassName), methodNode); assertEquals(true, adapter.isStatic()); assertEquals(false, adapter.isAbstract()); assertEquals(false, adapter.isPrivate()); assertEquals(false, adapter.isNative()); }
Example #22
Source File: MethodEditorPanel.java From Cafebabe with GNU General Public License v3.0 | 5 votes |
public void editMethod(MethodNode method) { this.method = method; this.name.setText(method.name); for (Field f : Opcodes.class.getDeclaredFields()) { try { if (f.getName().startsWith("ACC_")) { int acc = f.getInt(null); String accName = f.getName().substring(4).toLowerCase(); for (Component c : access.getComponents()) { WebToggleButton tb = (WebToggleButton) c; if (tb.getToolTipText().equals(accName)) { tb.setSelected((method.access & acc) != 0); break; } } } } catch (Exception e) { e.printStackTrace(); } } this.arguments.setText(Descriptors.getDisplayTypeEditable(method.desc.split("\\)")[0].substring(1))); this.returns.setText(Descriptors.getDisplayTypeEditable(method.desc.split("\\)")[1])); if (method.signature != null) { hasSignature.setSelected(true); this.signature.setText(method.signature); } else { hasSignature.setSelected(false); this.signature.setText(""); } this.exceptions.setText(String.join(", ", method.exceptions)); }
Example #23
Source File: LintDriver.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Returns whether the given issue is suppressed in the given method. * * @param issue the issue to be checked, or null to just check for "all" * @param classNode the class containing the issue * @param method the method containing the issue * @param instruction the instruction within the method, if any * @return true if there is a suppress annotation covering the specific * issue on this method */ public boolean isSuppressed( @Nullable Issue issue, @NonNull ClassNode classNode, @NonNull MethodNode method, @Nullable AbstractInsnNode instruction) { if (method.invisibleAnnotations != null) { @SuppressWarnings("unchecked") List<AnnotationNode> annotations = method.invisibleAnnotations; return isSuppressed(issue, annotations); } // Initializations of fields end up placed in generated methods (<init> // for members and <clinit> for static fields). if (instruction != null && method.name.charAt(0) == '<') { AbstractInsnNode next = LintUtils.getNextInstruction(instruction); if (next != null && next.getType() == AbstractInsnNode.FIELD_INSN) { FieldInsnNode fieldRef = (FieldInsnNode) next; FieldNode field = findField(classNode, fieldRef.owner, fieldRef.name); if (field != null && isSuppressed(issue, field)) { return true; } } else if (classNode.outerClass != null && classNode.outerMethod == null && isAnonymousClass(classNode)) { if (isSuppressed(issue, classNode)) { return true; } } } return false; }
Example #24
Source File: TBIncrementalSupportVisitor.java From atlas with Apache License 2.0 | 5 votes |
public TBIncrementalSupportVisitor( @NonNull ClassNode classNode, @NonNull List<ClassNode> parentNodes, @NonNull ClassVisitor classVisitor, @NonNull ILogger logger) { super(classNode, parentNodes, classVisitor, logger); classNode.methods.forEach((Consumer<MethodNode>) o -> { if (!o.name.equals(ByteCodeUtils.CONSTRUCTOR) &&! o.name.equals(ByteCodeUtils.CLASS_INITIALIZER)) { methodNodes.add(o); } }); }
Example #25
Source File: ConstantVisitor.java From AVM with MIT License | 5 votes |
@Override public MethodVisitor visitMethod(int access, String name, String descriptor, String signature, String[] exceptions) { // If this is a clinit, capture it into the MethodNode, for later use. Otherwise, pass it on as normal. MethodVisitor visitor = null; if (kClinitName.equals(name)) { this.cachedClinit = new MethodNode(access, name, descriptor, signature, exceptions); visitor = this.cachedClinit; } else { visitor = super.visitMethod(access, name, descriptor, signature, exceptions); } return new MethodVisitor(Opcodes.ASM6, visitor) { @Override public void visitLdcInsn(Object value) { if (value instanceof Type && ((Type) value).getSort() == Type.OBJECT) { // class constants // This covers both Type.ARRAY and Type.OBJECT; since both cases were visited in UserClassMappingVisitor and renamed super.visitLdcInsn(value); super.visitMethodInsn(Opcodes.INVOKESTATIC, Helper.RUNTIME_HELPER_NAME, wrapClassMethodName, wrapClassMethodDescriptor, false); } else if (value instanceof String) { // Note that we are moving all strings to the constantClassName, so look up the constant which has this value. String staticFieldForConstant = ConstantVisitor.this.constantToFieldMap.get(value); // (we just created this map in StringConstantCollectionVisitor so nothing can be missing). RuntimeAssertionError.assertTrue(null != staticFieldForConstant); super.visitFieldInsn(Opcodes.GETSTATIC, ConstantVisitor.this.constantClassName, staticFieldForConstant, postRenameStringDescriptor); } else { // Type of METHOD and Handle are for classes with version 49 and 51 respectively, and should not happen // https://asm.ow2.io/javadoc/org/objectweb/asm/MethodVisitor.html#visitLdcInsn-java.lang.Object- RuntimeAssertionError.assertTrue(value instanceof Integer || value instanceof Float || value instanceof Long || value instanceof Double); super.visitLdcInsn(value); } } }; }
Example #26
Source File: StringObfuscationCipherT11.java From zelixkiller with GNU General Public License v3.0 | 5 votes |
@Override public boolean isAffected(ClassNode cn) { if (cn.methods.isEmpty()) { return false; } MethodNode staticInitializer = cn.methods.stream().filter(mn -> mn.name.equals("<clinit>")).findFirst() .orElse(null); return staticInitializer != null && StringObfuscationT11.containsEncryptedLDC(staticInitializer) && containsDESPadLDC(staticInitializer); }
Example #27
Source File: MethodListNode.java From Cafebabe with GNU General Public License v3.0 | 5 votes |
public MethodListNode(ClassNode cn, MethodNode mn) { super(); this.cn = cn; this.mn = mn; if (mn != null) { initText(); } }
Example #28
Source File: Analyzer.java From JReFrameworker with MIT License | 5 votes |
/** * Computes the initial execution stack frame of the given method. * * @param owner the internal name of the class to which 'method' belongs. * @param method the method to be analyzed. * @return the initial execution stack frame of the 'method'. */ private Frame<V> computeInitialFrame(final String owner, final MethodNode method) { Frame<V> frame = newFrame(method.maxLocals, method.maxStack); int currentLocal = 0; boolean isInstanceMethod = (method.access & ACC_STATIC) == 0; if (isInstanceMethod) { Type ownerType = Type.getObjectType(owner); frame.setLocal( currentLocal, interpreter.newParameterValue(isInstanceMethod, currentLocal, ownerType)); currentLocal++; } Type[] argumentTypes = Type.getArgumentTypes(method.desc); for (Type argumentType : argumentTypes) { frame.setLocal( currentLocal, interpreter.newParameterValue(isInstanceMethod, currentLocal, argumentType)); currentLocal++; if (argumentType.getSize() == 2) { frame.setLocal(currentLocal, interpreter.newEmptyValue(currentLocal)); currentLocal++; } } while (currentLocal < method.maxLocals) { frame.setLocal(currentLocal, interpreter.newEmptyValue(currentLocal)); currentLocal++; } frame.setReturn(interpreter.newReturnTypeValue(Type.getReturnType(method.desc))); return frame; }
Example #29
Source File: ClassContext.java From javaide with GNU General Public License v3.0 | 5 votes |
/** * Finds the line number closest to the given class declaration * * @param node the method node to get a line number for * @return the closest line number, or -1 if not known */ public static int findLineNumber(@NonNull ClassNode node) { if (node.methods != null && !node.methods.isEmpty()) { MethodNode firstMethod = getFirstRealMethod(node); if (firstMethod != null) { return findLineNumber(firstMethod); } } return -1; }
Example #30
Source File: OverclockingClassTransformer.java From malmo with MIT License | 5 votes |
private static void insertTextureHandler(ClassNode node, boolean isObfuscated) { // We're attempting to turn this line from GlStateManager.bindTexture: // GL11.glBindTexture(GL11.GL_TEXTURE_2D, texture); // into this: // TextureHelper.glBindTexture(GL11.GL_TEXTURE_2D, texture); // TextureHelpers's method then decides whether or not add a shader to the OpenGL pipeline before // passing the call on to GL11.glBindTexture. final String methodName = isObfuscated ? "func_179144_i" : "bindTexture"; final String methodDescriptor = "(I)V"; // Takes one int, returns void. System.out.println("MALMO: Found GlStateManager, attempting to transform it"); for (MethodNode method : node.methods) { if (method.name.equals(methodName) && method.desc.equals(methodDescriptor)) { System.out.println("MALMO: Found GlStateManager.bindTexture() method, attempting to transform it"); for (AbstractInsnNode instruction : method.instructions.toArray()) { if (instruction.getOpcode() == Opcodes.INVOKESTATIC) { MethodInsnNode visitMethodNode = (MethodInsnNode)instruction; if (visitMethodNode.name.equals("glBindTexture")) { visitMethodNode.owner = "com/microsoft/Malmo/Utils/TextureHelper"; if (isObfuscated) { visitMethodNode.name = "bindTexture"; } System.out.println("MALMO: Hooked into call to GlStateManager.bindTexture()"); } } } } } }