public FlowObfuscation getFlowObfuscation() { if (flowCheckBox.isSelected()) { switch (flowComboBox.getSelectedIndex()) { case 0: { return new LightFlowObfuscation(); } case 1: { return new NormalFlowObfuscation(); } case 2: { return new HeavyFlowObfuscation(); } default: { throw new IllegalStateException(String.format("Bad flow obfuscation type %d.", flowComboBox.getSelectedIndex())); } } } else { return null; } }
@Override public void transform() { AtomicInteger counter = new AtomicInteger(); this.getClassWrappers().parallelStream().filter(classWrapper -> !excluded(classWrapper)).forEach(classWrapper -> { ClassNode classNode = classWrapper.classNode; String fieldName = StringUtils.randomSpacesString(RandomUtils.getRandomInt(10)); classWrapper.methods.parallelStream().filter(methodWrapper -> !excluded(methodWrapper) && hasInstructions(methodWrapper.methodNode)).forEach(methodWrapper -> { MethodNode methodNode = methodWrapper.methodNode; int leeway = getSizeLeeway(methodNode); for (AbstractInsnNode insn : methodNode.instructions.toArray()) { if (leeway < 10000) { break; } if (insn.getOpcode() == GOTO) { methodNode.instructions.insertBefore(insn, new FieldInsnNode(GETSTATIC, classNode.name, fieldName, "Z")); methodNode.instructions.insert(insn, new InsnNode(ATHROW)); methodNode.instructions.insert(insn, new InsnNode(ACONST_NULL)); methodNode.instructions.set(insn, new JumpInsnNode(IFEQ, ((JumpInsnNode) insn).label)); leeway -= 7; counter.incrementAndGet(); } } }); classNode.fields.add(new FieldNode(ACC_PUBLIC + ACC_STATIC + ACC_FINAL, fieldName, "Z", null, null)); }); LoggerUtils.stdOut(String.format("Added %d fake throw-null sequences", counter.get())); }
public static FlowObfuscation getTransformerFromString(String s) { switch (s.toLowerCase()) { case "light": { return new LightFlowObfuscation(); } case "normal": { return new NormalFlowObfuscation(); } case "heavy": { return new HeavyFlowObfuscation(); } default: { throw new IllegalConfigurationValueException("Did not expect " + s + " as a flow obfuscation mode"); } } } }