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"); } } } }
private FlowObfuscation getFlowObfuscationTransformer() { Object o = map.get(ConfigurationSettings.FLOW_OBFUSCATION.getValue()); if (o == null) return null; if (!(o instanceof String)) throw new IllegalConfigurationValueException(ConfigurationSettings.FLOW_OBFUSCATION.getValue(), String.class, o.getClass()); String s = (String) o; if (!"Light".equals(s) && !"Normal".equals(s) && !"Heavy".equals(s)) throw new IllegalConfigurationValueException("Expected Light, Normal or Heavy as mode for flow " + "obfuscation. Got " + s + " instead."); return FlowObfuscation.getTransformerFromString(s); }
@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())); }
AtomicInteger counter = new AtomicInteger(); this.getClassWrappers().parallelStream().filter(classWrapper -> !excluded(classWrapper)).forEach(classWrapper -> { ClassNode classNode = classWrapper.classNode; FieldNode field = new FieldNode(ACC_PUBLIC + ACC_STATIC + ACC_FINAL, classWrapper.methods.parallelStream().filter(methodWrapper -> !excluded(methodWrapper) && hasInstructions(methodWrapper.methodNode)).forEach(methodWrapper -> { MethodNode methodNode = methodWrapper.methodNode; int leeway = getSizeLeeway(methodNode); int varIndex = methodNode.maxLocals; methodNode.maxLocals++; AbstractInsnNode[] untouchedList = methodNode.instructions.toArray(); LabelNode labelNode = exitLabel(methodNode); boolean calledSuper = false; Set<AbstractInsnNode> emptyAt = new StackEmulator(methodNode,
AtomicInteger counter = new AtomicInteger(); this.getClassWrappers().parallelStream().filter(classWrapper -> !excluded(classWrapper)).forEach(classWrapper -> { ClassNode classNode = classWrapper.classNode; FieldNode field = new FieldNode(ACC_PUBLIC + ACC_STATIC + ACC_FINAL, classWrapper.methods.parallelStream().filter(methodWrapper -> !excluded(methodWrapper) && hasInstructions(methodWrapper.methodNode)).forEach(methodWrapper -> { MethodNode methodNode = methodWrapper.methodNode; int leeway = getSizeLeeway(methodNode); int varIndex = methodNode.maxLocals; methodNode.maxLocals++; AbstractInsnNode[] untouchedList = methodNode.instructions.toArray(); LabelNode labelNode = exitLabel(methodNode); boolean calledSuper = false; Set<AbstractInsnNode> emptyAt = new StackEmulator(methodNode,
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; } }