org.objectweb.asm.tree.MethodInsnNode Java Examples

The following examples show how to use org.objectweb.asm.tree.MethodInsnNode. 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: Constructor.java    From Stark with Apache License 2.0 6 votes vote down vote up
Constructor(@NonNull String owner,
        @NonNull List<AbstractInsnNode> prelude,
        @NonNull VarInsnNode loadThis,
        int lineForLoad,
        @NonNull MethodNode args,
        @NonNull MethodInsnNode delegation,
        @NonNull MethodNode body,
        @NonNull List<LocalVariable> variables,
        int localsAtLoadThis) {
    this.owner = owner;
    this.prelude = prelude;
    this.loadThis = loadThis;
    this.lineForLoad = lineForLoad;
    this.args = args;
    this.delegation = delegation;
    this.body = body;
    this.variables = variables;
    this.localsAtLoadThis = localsAtLoadThis;
}
 
Example #2
Source File: StackHelper.java    From zelixkiller with GNU General Public License v3.0 6 votes vote down vote up
public InsnValue onMethod(AbstractInsnNode insn, List<InsnValue> values) {
	String desc = "V";
	if (insn.getOpcode() == Opcodes.INVOKEDYNAMIC){
		desc = ((InvokeDynamicInsnNode) insn).desc;
	}else{
		desc = ((MethodInsnNode) insn).desc;
	}
	// Until I'm ready to simulate method calls the opcode here really
	// doesn't matter.
	/*
	 * switch (insn.getOpcode()) { case Opcodes.INVOKEDYNAMIC: case
	 * Opcodes.INVOKESPECIAL: case Opcodes.INVOKEINTERFACE: case
	 * Opcodes.INVOKESTATIC: case Opcodes.INVOKEVIRTUAL: }
	 */
	if (desc.endsWith("V")) {
		return null;
	}
	return new InsnValue(Type.getReturnType(desc));
}
 
Example #3
Source File: MethodByteCodeUtil.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
private static AbstractInsnNode getInitializationInstructionsSet(AbstractInsnNode node) {
	AbstractInsnNode paramStartNode = null;
	AbstractInsnNode traversalInsnNode = node;

	if (node instanceof MethodInsnNode) {
		MethodInsnNode min = (MethodInsnNode) node;

		String initializedObjectType = min.owner;
		traversalInsnNode = node.getPrevious();
		while (!isInitializationInstructionStartReached(traversalInsnNode, initializedObjectType)) {
			traversalInsnNode = traversalInsnNode.getPrevious();
		}
		paramStartNode = traversalInsnNode;
	}
	return paramStartNode;
}
 
Example #4
Source File: Sandbox.java    From zelixkiller with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Invokes the method through reflection. Other methods and fields are removed to prevent accidental execution.
 * 
 * @param owner
 *          Decryption classnode
 * @param min
 *          Decryption method
 * @param args
 *          Decryption method args
 * @return
 */
public static Object getIsolatedReturn(ClassNode owner, MethodInsnNode min, Object[] args) {
	if (owner == null) {
		return null;
	}
	ClassNode isolated = new ClassNode();
	isolated.version = 52;
	isolated.name = owner.name;
	isolated.superName = "java/lang/Object";
	int i = 0;
	for (MethodNode mn : owner.methods) {
		if (mn.name.equals(min.name) && mn.desc.equals(min.desc)) {
			isolated.methods.add(owner.methods.get(i));
		}
		i++;
	}
	return get(isolated, min.name, min.desc, args);
}
 
Example #5
Source File: ControlFlowT11.java    From zelixkiller with GNU General Public License v3.0 6 votes vote down vote up
private AbstractInsnNode getNumberPush(MethodInsnNode min, int var) {
	// TODO find out by invoking if it can't be identified by patterns in future versions
	AbstractInsnNode ain = min;
	while (ain != null) {
		if (ain instanceof VarInsnNode) {
			if (((VarInsnNode) ain).var == var) {
				int nextOp = ain.getNext().getOpcode();
				// jump should never happen
				if (nextOp == IFEQ) {
					return new InsnNode(ICONST_1);
				} else if (nextOp == IFNE) {
					return new InsnNode(ICONST_0);
				}
			}
		}
		ain = ain.getNext();
	}
	return null;
}
 
Example #6
Source File: StringObfuscationCipherVMT11.java    From zelixkiller with GNU General Public License v3.0 6 votes vote down vote up
private ArrayList<String> findNeededContents(ClassNode cn, MethodNode mn) {
	ArrayList<String> neededContents = new ArrayList<>();
	for (AbstractInsnNode ain : mn.instructions.toArray()) {
		if (ain instanceof MethodInsnNode) {
			MethodInsnNode min = (MethodInsnNode) ain;
			if (min.owner.equals(cn.name) && !neededContents.contains(min.name + min.desc)) {
				neededContents.add(min.name + min.desc);
				neededContents.addAll(findNeededContents(cn, ClassUtils.getMethod(cn, min.name, min.desc)));
			}
		}
		if (ain instanceof FieldInsnNode) {
			FieldInsnNode fin = (FieldInsnNode) ain;
			if (fin.owner.equals(cn.name) && !neededContents.contains(fin.name + fin.desc)) {
				neededContents.add(fin.name + fin.desc);
			}
		}
	}
	return neededContents;
}
 
Example #7
Source File: StringObfuscationCipherT11.java    From zelixkiller with GNU General Public License v3.0 6 votes vote down vote up
private void findBelongingClasses(ArrayList<MethodNode> scanned, ArrayList<ClassNode> decryptionClasses,
		JarArchive ja, ClassNode cn, ClassNode proxy, MethodNode node) {
	if (scanned.contains(node)) {
		return;
	}
	scanned.add(node);
	for (AbstractInsnNode ain : node.instructions.toArray()) {
		if (ain instanceof MethodInsnNode) {
			MethodInsnNode min = (MethodInsnNode) ain;
			if (!min.owner.startsWith("java/") && !min.owner.startsWith("javax/")) {
				ClassNode decryptionClass = ja.getClasses().get(min.owner);
				if (decryptionClass != null && !decryptionClasses.contains(decryptionClass)) {
					decryptionClasses.add(decryptionClass);
					for (MethodNode mn : decryptionClass.methods) {
						findBelongingClasses(scanned, decryptionClasses, ja, decryptionClass, proxy, mn);
					}
				}
			}
		}
	}
}
 
Example #8
Source File: MethodByteCodeUtil.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * API that returns the list of parameter types
 * @param min
 * @return
 */
public static List<String> getParamType(MethodInsnNode min) {
	List<String> paramTypeList = new LinkedList<String>();

	String desc = min.desc;
	desc = desc.substring(1, desc.indexOf(')'));
	String[] type = desc.split(";");

	for (String t : type) {
		// Removing the L that starts the class name and then adding type in
		// a list
		paramTypeList.add(t.substring(1));
	}

	return paramTypeList;
}
 
Example #9
Source File: IForgeRegistryEntryTransformer.java    From NOVA-Core with GNU Lesser General Public License v3.0 6 votes vote down vote up
@Override
public void transform(ClassNode cnode) {
	Game.logger().info("Transforming IForgeRegistryEntry class for correct NOVA mod id mapping.");

	ObfMapping mapping = new ObfMapping("net/minecraftforge/fml/common/registry/IForgeRegistryEntry$Impl", "setRegistryName", "(Ljava/lang/String;)Lnet/minecraftforge/fml/common/registry/IForgeRegistryEntry;");
	MethodNode method = ASMHelper.findMethod(mapping, cnode);

	if (method == null) {
		throw new IllegalStateException("[NOVA] Lookup " + mapping + " failed!");
	}

	Game.logger().info("Transforming method {}", method.name);

	InsnList list = new InsnList();
	list.add(new VarInsnNode(ALOAD, 5));
	list.add(new MethodInsnNode(INVOKESTATIC, "nova/core/wrapper/mc/forge/v1_11_2/asm/StaticForwarder", "isNovaPrefix", "(Ljava/lang/String;)Z", false));
	list.add(new JumpInsnNode(IFNE, (LabelNode) method.instructions.get(120)));

	method.instructions.insert(method.instructions.get(101), list);

	Game.logger().info("Injected instruction to method: {}", method.name);
}
 
Example #10
Source File: Invokestatic.java    From nuls with MIT License 6 votes vote down vote up
public static void invokestatic(Frame frame) {
    MethodInsnNode methodInsnNode = frame.methodInsnNode();
    String className = methodInsnNode.owner;
    String methodName = methodInsnNode.name;
    String methodDesc = methodInsnNode.desc;

    MethodCode methodCode = frame.methodArea.loadMethod(className, methodName, methodDesc);

    MethodArgs methodArgs = new MethodArgs(methodCode.argsVariableType, frame.operandStack, true);

    //Log.opcode(frame.getCurrentOpCode(), className, methodName, methodDesc);

    Result result = NativeMethod.run(methodCode, methodArgs, frame);
    if (result != null) {
        return;
    }

    frame.vm.run(methodCode, methodArgs.frameArgs, true);
}
 
Example #11
Source File: ClickableViewAccessibilityDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
@SuppressWarnings("unchecked") // ASM API
public static void checkSetOnTouchListenerCall(
        @NonNull ClassContext context,
        @NonNull MethodNode method,
        @NonNull MethodInsnNode call) {
    String owner = call.owner;

    // Ignore the call if it was called on a non-view.
    ClassNode ownerClass = context.getDriver().findClass(context, owner, 0);
    if(ownerClass == null
            || !context.getDriver().isSubclassOf(ownerClass, ANDROID_VIEW_VIEW)) {
        return;
    }

    MethodNode performClick = findMethod(ownerClass.methods, PERFORM_CLICK, PERFORM_CLICK_SIG);
    //noinspection VariableNotUsedInsideIf
    if (performClick == null) {
        String message = String.format(
                "Custom view `%1$s` has `setOnTouchListener` called on it but does not "
                        + "override `performClick`", ownerClass.name);
        context.report(ISSUE, method, call, context.getLocation(call), message);
    }
}
 
Example #12
Source File: Instrumentator.java    From instrumentation with Apache License 2.0 6 votes vote down vote up
private InsnList getThrowTraceInstructions() {
    InsnList il = new InsnList();

    int exceptionVariablePosition = getFistAvailablePosition();
    il.add(new VarInsnNode(Opcodes.ASTORE, exceptionVariablePosition));

    this.methodOffset++; // Actualizamos el offset
    addGetCallback(il);
    il.add(new VarInsnNode(Opcodes.ALOAD, this.methodVarIndex));
    il.add(new VarInsnNode(Opcodes.ALOAD, exceptionVariablePosition));
    il.add(new VarInsnNode(Opcodes.ALOAD, this.executionIdIndex));
    il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL,
            "org/brutusin/instrumentation/Callback", "onThrowableThrown",
            "(Ljava/lang/Object;Ljava/lang/Throwable;Ljava/lang/String;)V", false));

    il.add(new VarInsnNode(Opcodes.ALOAD, exceptionVariablePosition));

    return il;
}
 
Example #13
Source File: SecureRandomDetector.java    From javaide with GNU General Public License v3.0 6 votes vote down vote up
private static void checkValidSetSeed(ClassContext context, MethodInsnNode call) {
    assert call.name.equals(SET_SEED);

    // Make sure the argument passed is not a literal
    AbstractInsnNode prev = LintUtils.getPrevInstruction(call);
    if (prev == null) {
        return;
    }
    int opcode = prev.getOpcode();
    if (opcode == Opcodes.LCONST_0 || opcode == Opcodes.LCONST_1 || opcode == Opcodes.LDC) {
        context.report(ISSUE, context.getLocation(call),
                "Do not call `setSeed()` on a `SecureRandom` with a fixed seed: " +
                "it is not secure. Use `getSeed()`.");
    } else if (opcode == Opcodes.INVOKESTATIC) {
        String methodName = ((MethodInsnNode) prev).name;
        if (methodName.equals("currentTimeMillis") || methodName.equals("nanoTime")) {
            context.report(ISSUE, context.getLocation(call),
                    "It is dangerous to seed `SecureRandom` with the current time because " +
                    "that value is more predictable to an attacker than the default seed.");
        }
    }
}
 
Example #14
Source File: NodeUtilsTest.java    From obfuscator with MIT License 6 votes vote down vote up
@Test
public void test_getWrapperMethod() {
    AbstractInsnNode wrapperMethod = NodeUtils.getWrapperMethod(Type.INT_TYPE);

    if (wrapperMethod instanceof MethodInsnNode) {
        MethodInsnNode method = (MethodInsnNode) wrapperMethod;
        assertEquals("valueOf", method.name);
        assertEquals(method.desc, "(I)Ljava/lang/Integer;");
        assertEquals(method.owner, "java/lang/Integer");
    } else {
        fail();
    }

    assertEquals(NodeUtils.getWrapperMethod(Type.VOID_TYPE).getOpcode(), Opcodes.NOP);
    assertEquals(NodeUtils.getWrapperMethod(Type.getType("Ljava/lang/Object;")).getOpcode(), Opcodes.NOP);
}
 
Example #15
Source File: InstrumentUtil.java    From jumbune with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * <p>
 * This method provides instruction to log method entry/exit information
 * </p>
 * 
 * @param className
 *            Class which has called the logger
 * @param methodName
 *            Method in which the logger has been called
 * @param logMsg
 *            log message
 * @return InsnList Instructions
 */
public static InsnList addLogMessage(Object... objects) {
	String method = "addLogMsg";

	InsnList il = getBasicInstructions(objects);

	Type[] types = new Type[objects.length];
	for (int i = 0; i < objects.length; i++) {
		types[i] = TYPE_OBJECT;
	}

	String methodDesc = Type.getMethodDescriptor(Type.VOID_TYPE, types);

	il.add(new MethodInsnNode(Opcodes.INVOKESTATIC, CLASSNAME_LOGUTIL,
			method, methodDesc));
	return il;
}
 
Example #16
Source File: NioBufferRefConverterTest.java    From bazel with Apache License 2.0 6 votes vote down vote up
@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 #17
Source File: EntrypointPatchBranding.java    From fabric-loader with Apache License 2.0 6 votes vote down vote up
private boolean applyBrandingPatch(ClassNode classNode) {
	boolean applied = false;

	for (MethodNode node : classNode.methods) {
		if (node.name.equals("getClientModName") || node.name.equals("getServerModName") && node.desc.endsWith(")Ljava/lang/String;")) {
			debug("Applying brand name hook to " + classNode.name + "::" + node.name);

			ListIterator<AbstractInsnNode> it = node.instructions.iterator();
			while (it.hasNext()) {
				if (it.next().getOpcode() == Opcodes.ARETURN) {
					it.previous();
					it.add(new MethodInsnNode(Opcodes.INVOKESTATIC, "net/fabricmc/loader/entrypoint/minecraft/hooks/EntrypointBranding", "brand", "(Ljava/lang/String;)Ljava/lang/String;", false));
					it.next();
				}
			}

			applied = true;
		}
	}

	return applied;
}
 
Example #18
Source File: InsnComparator.java    From TFC2 with GNU General Public License v3.0 5 votes vote down vote up
/**
 * Respects {@link #INT_WILDCARD} and {@link #WILDCARD} instruction properties.
 * Always returns true if {@code a} and {@code b} are label, line number, or frame instructions.
 * 
 * @return Whether or not the given instructions are equivalent.
 */
public boolean areInsnsEqual(AbstractInsnNode a, AbstractInsnNode b)
{
	if (a == b)
		return true;

	if (a == null || b == null)
		return false;

	if (a.equals(b))
		return true;

	if (a.getOpcode() != b.getOpcode())
		return false;

	switch (a.getType())
	{
		case AbstractInsnNode.VAR_INSN:
			return areVarInsnsEqual((VarInsnNode) a, (VarInsnNode) b);
		case AbstractInsnNode.TYPE_INSN:
			return areTypeInsnsEqual((TypeInsnNode) a, (TypeInsnNode) b);
		case AbstractInsnNode.FIELD_INSN:
			return areFieldInsnsEqual((FieldInsnNode) a, (FieldInsnNode) b);
		case AbstractInsnNode.METHOD_INSN:
			return areMethodInsnsEqual((MethodInsnNode) a, (MethodInsnNode) b);
		case AbstractInsnNode.LDC_INSN:
			return areLdcInsnsEqual((LdcInsnNode) a, (LdcInsnNode) b);
		case AbstractInsnNode.IINC_INSN:
			return areIincInsnsEqual((IincInsnNode) a, (IincInsnNode) b);
		case AbstractInsnNode.INT_INSN:
			return areIntInsnsEqual((IntInsnNode) a, (IntInsnNode) b);
		default:
			return true;
	}
}
 
Example #19
Source File: ExecutionContextMethods.java    From rembulan with Apache License 2.0 5 votes vote down vote up
public static MethodInsnNode registerTicks() {
	return new MethodInsnNode(
			INVOKEINTERFACE,
			selfTpe().getInternalName(),
			"registerTicks",
			Type.getMethodDescriptor(
					Type.VOID_TYPE,
					Type.INT_TYPE),
			true);
}
 
Example #20
Source File: ConfigureMapReduceAdapter.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * It removes variables related to Partitioner logging set in threadLocal
 * like totalNumberOfReducerTasks.
 *
 * @param isSetup - true if setup method, false if cleanup method
 * @return the insn list
 */
private InsnList addRemoveTotalReducerTasksFromThreadLocal(boolean isSetup) {
	InsnList il = new InsnList();
	il.add(new LabelNode());

	String methodName = SET_NUM_REDUCER_TASKS;
	String methodDesc = DESC_INT_PARAM_RETURN_VOID;

	if (isSetup) {
		// The method MapReduceExecutionUtil.setNumReducerTasks require a
		// int
		// parameter which is fetched from context.getNumReduceTasks()
		String className = CLASSNAME_TASKINPUTOUTPUTCONTEXT;
		if (isOldApiClazz()) {
			className = CLASSNAME_JOB_CONF;
		}

		il.add(new VarInsnNode(Opcodes.ALOAD, 1));
		il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, className,
				GET_NUMBER_OF_REDUCERS, DESC_EMPTY_PARAM_RETURN_INT));

	} else {
		LOGGER.debug("Removing number of reduce tasks from threadLocal");
		methodName = REMOVE_NUM_REDUCER_TASKS;
		methodDesc = EMPTY_PARAMETER_VOID_RETURN;
	}

	il.add(new MethodInsnNode(Opcodes.INVOKESTATIC,
			CLASSNAME_MAPREDUCEEXECUTIL, methodName, methodDesc));
	return il;
}
 
Example #21
Source File: DetourLoader.java    From android-perftracking with MIT License 5 votes vote down vote up
private Detour staticCallDetour(ClassNode cn, MethodNode mn, AnnotationNode a) {
  MethodInsnNode mi = getMethodInstruction(mn, null, mn.name);
  if (mi == null) {
    _log.debug("Could not get method instruction for detour " + mn.name + mn.desc);
    return null;
  }

  StaticCallDetour detour = new StaticCallDetour(_log);
  detour.matchMethod = mn.name;
  detour.matchDesc = mi.desc;
  detour.owner = mi.owner;
  detour.detourOwner = cn.name;

  return detour;
}
 
Example #22
Source File: SourceInterpreter.java    From JReFrameworker with MIT License 5 votes vote down vote up
@Override
public SourceValue naryOperation(
    final AbstractInsnNode insn, final List<? extends SourceValue> values) {
  int size;
  int opcode = insn.getOpcode();
  if (opcode == MULTIANEWARRAY) {
    size = 1;
  } else if (opcode == INVOKEDYNAMIC) {
    size = Type.getReturnType(((InvokeDynamicInsnNode) insn).desc).getSize();
  } else {
    size = Type.getReturnType(((MethodInsnNode) insn).desc).getSize();
  }
  return new SourceValue(size, insn);
}
 
Example #23
Source File: Invokespecial.java    From nuls with MIT License 5 votes vote down vote up
public static void invokespecial(Frame frame) {
    MethodInsnNode methodInsnNode = frame.methodInsnNode();
    String className = methodInsnNode.owner;
    String methodName = methodInsnNode.name;
    String methodDesc = methodInsnNode.desc;

    MethodCode methodCode = frame.methodArea.loadMethod(className, methodName, methodDesc);

    MethodArgs methodArgs = new MethodArgs(methodCode.argsVariableType, frame.operandStack, false);
    ObjectRef objectRef = methodArgs.objectRef;
    if (objectRef == null) {
        frame.throwNullPointerException();
        return;
    }

    //Log.opcode(frame.getCurrentOpCode(), className, methodName, methodDesc);

    if (Constants.OBJECT_CLASS_NAME.equals(className) && Constants.CONSTRUCTOR_NAME.equals(methodName)) {
        return;
    }

    Result result = NativeMethod.run(methodCode, methodArgs, frame);
    if (result != null) {
        return;
    }

    frame.vm.run(methodCode, methodArgs.frameArgs, true);
}
 
Example #24
Source File: InstructionMatchers.java    From pitest with Apache License 2.0 5 votes vote down vote up
public static  Match<AbstractInsnNode> methodCallTo(final ClassName owner, final String name) {
  return (c, t) -> {
    if ( t instanceof MethodInsnNode ) {
      final MethodInsnNode call = (MethodInsnNode) t;
      return call.name.equals(name) && call.owner.equals(owner.asInternalName());
    }
    return false;
  };
}
 
Example #25
Source File: SubmitCaseAdapter.java    From jumbune with GNU Lesser General Public License v3.0 5 votes vote down vote up
/**
 * Adds the job conf.
 *
 * @param il the il
 */
private void addJobConf(InsnList il) {
	il.add(new LdcInsnNode(TYPE_JOB_CONTEXT));
	il.add(new LdcInsnNode(JOB_CONF));
	il.add(new MethodInsnNode(Opcodes.INVOKEVIRTUAL, CLASSNAME_CLASS,
			"getDeclaredField", Type.getMethodDescriptor(TYPE_FIELD,
					TYPE_STRING)));
}
 
Example #26
Source File: AntiDebug.java    From radon with GNU General Public License v3.0 5 votes vote down vote up
private InsnList generateCheck() {
    LabelNode notDebugLabel = new LabelNode();
    InsnList insnList = new InsnList();
    insnList.add(createIsDebugList());
    insnList.add(new JumpInsnNode(IFEQ, notDebugLabel));

    if (RandomUtils.getRandomBoolean()) {
        if (getMessage() != null) {
            insnList.add(new FieldInsnNode(GETSTATIC, "java/lang/System", "out", "Ljava/io/PrintStream;"));
            insnList.add(new LdcInsnNode(getMessage()));
            insnList.add(new MethodInsnNode(INVOKEVIRTUAL, "java/io/PrintStream", "println", "(Ljava/lang/String;)V", false));
        }
        if (RandomUtils.getRandomBoolean()) {
            insnList.add(new LdcInsnNode(RandomUtils.getRandomInt()));
            insnList.add(new MethodInsnNode(INVOKESTATIC, "java/lang/System", "exit", "(I)V", false));
        } else {
            insnList.add(new MethodInsnNode(INVOKESTATIC, "java/lang/Runtime", "getRuntime", "()Ljava/lang/Runtime;", false));
            insnList.add(new LdcInsnNode(RandomUtils.getRandomInt()));
            insnList.add(new MethodInsnNode(INVOKEVIRTUAL, "java/lang/Runtime", "halt", "(I)V", false));
        }
    } else {
        String message = getMessage();
        if (message == null)
            message = randomString();

        insnList.add(new TypeInsnNode(NEW, "java/lang/RuntimeException"));
        insnList.add(new InsnNode(DUP));
        insnList.add(new LdcInsnNode(message));
        insnList.add(new MethodInsnNode(INVOKESPECIAL, "java/lang/RuntimeException", "<init>", "(Ljava/lang/String;)V", false));
        insnList.add(new InsnNode(ATHROW));
    }
    insnList.add(notDebugLabel);
    return insnList;
}
 
Example #27
Source File: ContinuableMethodVisitor.java    From tascalate-javaflow with Apache License 2.0 5 votes vote down vote up
private static int getOwnerSize(AbstractInsnNode node) {
    if (node instanceof MethodInsnNode) {
        return node.getOpcode() == INVOKESTATIC ? 0 : 1;
    } else {
        // INVOKEDYNAMIC
        return 0;
    }
}
 
Example #28
Source File: LdcSwapInvokeSwapPopRemover.java    From deobfuscator with Apache License 2.0 5 votes vote down vote up
@Override
public boolean transform() throws Throwable {
    AtomicInteger counter = new AtomicInteger();
    classNodes().forEach(classNode -> {
        classNode.methods.stream().filter(methodNode -> methodNode.instructions.getFirst() != null).forEach(methodNode -> {
            boolean modified = false;
            do {
                modified = false;
                for (int i = 0; i < methodNode.instructions.size(); i++) {
                    AbstractInsnNode node = methodNode.instructions.get(i);
                    if (Utils.willPushToStack(node.getOpcode())) {
                        AbstractInsnNode next = Utils.getNext(node);
                        if (next.getOpcode() == Opcodes.SWAP) {
                            AbstractInsnNode swap = next;
                            next = Utils.getNext(next);
                            if (next instanceof MethodInsnNode) {
                                MethodInsnNode methodInsnNode = (MethodInsnNode) next;
                                if (methodInsnNode.desc.equals("(Ljava/lang/String;)Ljava/lang/String;")) { //Lazy
                                    AbstractInsnNode next1 = Utils.getNext(next);
                                    if (next1.getOpcode() == Opcodes.SWAP && next1.getNext().getOpcode() == Opcodes.POP) {
                                        methodNode.instructions.remove(next1.getNext());
                                        methodNode.instructions.remove(next1);
                                        methodNode.instructions.remove(swap);
                                        methodNode.instructions.remove(node);
                                        counter.incrementAndGet();
                                        modified = true;
                                    }
                                }
                            }
                        }
                    }
                }
            } while (modified);
        });
    });
    System.out.println("Removed " + counter.get() + " ldc-swap-invoke-swap-pop patterns");
    return counter.get() > 0;
}
 
Example #29
Source File: ConversionMethods.java    From rembulan with Apache License 2.0 5 votes vote down vote up
public static AbstractInsnNode unboxedNumberToLuaFormatString(Type tpe) {
	Check.isTrue(tpe.equals(Type.DOUBLE_TYPE) || tpe.equals(Type.LONG_TYPE));
	return new MethodInsnNode(
			INVOKESTATIC,
			Type.getInternalName(LuaFormat.class),
			"toString",
			Type.getMethodDescriptor(
					Type.getType(String.class),
					tpe),
			false);
}
 
Example #30
Source File: ConstInterpreter.java    From pro with GNU General Public License v3.0 5 votes vote down vote up
@Override
public ConstValue naryOperation(AbstractInsnNode insn, List<? extends ConstValue> values) {
  int opcode = insn.getOpcode();
  if (opcode == MULTIANEWARRAY) {
    return ConstValue.ONE_SLOT;
  }
  var desc = (opcode == INVOKEDYNAMIC) ? ((InvokeDynamicInsnNode) insn).desc
      : ((MethodInsnNode) insn).desc;
  return ConstValue.slotForSize(Type.getReturnType(desc).getSize());
}