public List<String> getExcludedStrings() { return this.setup.getExemptedStrings(); }
public StringPool getStringPool() { return (stringEncryptionEnabledCheckBox.isSelected() && stringPoolCheckBox.isSelected()) ? new StringPool(new StringEncryptionSetup(stringExclusions)) : null; }
public static StringEncryption getTransformerFromString(String s, StringEncryptionSetup setup) { switch (s.toLowerCase()) { case "light": { return new LightStringEncryption(setup); } case "normal": { return new NormalStringEncryption(setup); } case "heavy": { return new HeavyStringEncryption(setup); } default: { throw new IllegalConfigurationValueException("Did not expect " + s + " as a string obfuscation mode"); } } } }
public StringEncryption getStringEncryption() { if (stringEncryptionEnabledCheckBox.isSelected()) { StringEncryptionSetup setup = new StringEncryptionSetup(stringExclusions); StringEncryption encryptionTransformer; switch (stringEncryptionTypeSelector.getSelectedIndex()) { case 0: { encryptionTransformer = new LightStringEncryption(setup); break; } case 1: { encryptionTransformer = new NormalStringEncryption(setup); break; } case 2: { encryptionTransformer = new HeavyStringEncryption(setup); break; } default: { throw new IllegalStateException(String.format("Bad string encryption type %d.", stringEncryptionTypeSelector.getSelectedIndex())); } } return encryptionTransformer; } else { return null; } }
@Override public void transform() { AtomicInteger counter = new AtomicInteger(); MemberNames memberNames = new MemberNames(); this.getClassWrappers().parallelStream().filter(classWrapper -> !excluded(classWrapper)).forEach(classWrapper -> classWrapper.methods.parallelStream().filter(methodWrapper -> !excluded(methodWrapper) && hasInstructions(methodWrapper.methodNode)).forEach(methodWrapper -> { MethodNode methodNode = methodWrapper.methodNode; int leeway = getSizeLeeway(methodNode); String cst = (String) ldc.cst; if (!excludedString(cst)) { int extraKey = RandomUtils.getRandomInt(); ldc.cst = encrypt(cst, extraKey); methodNode.instructions.insert(insn, new MethodInsnNode(INVOKESTATIC, memberNames.className, memberNames.decryptMethodName, ClassNode decryptor = createDecryptor(memberNames); getClasses().put(decryptor.name, new ClassWrapper(decryptor, false));
@Override public void transform() { AtomicInteger counter = new AtomicInteger(); MemberNames memberNames = new MemberNames(); this.getClassWrappers().parallelStream().filter(classWrapper -> !excluded(classWrapper)).forEach(classWrapper -> classWrapper.methods.parallelStream().filter(methodWrapper -> !excluded(methodWrapper) && hasInstructions(methodWrapper.methodNode)).forEach(methodWrapper -> { MethodNode methodNode = methodWrapper.methodNode; int leeway = getSizeLeeway(methodNode); String cst = (String) ldc.cst; if (!excludedString(cst)) { int extraKey = RandomUtils.getRandomInt(); int callerClassHC = classWrapper.classNode.name.replace("/", ".").hashCode(); int callerMethodHC = methodNode.name.hashCode(); int decryptorClassHC = memberNames.className.replace("/", ".").hashCode(); ldc.cst = encrypt(cst, decryptorClassHC, callerClassHC, callerMethodHC, extraKey); methodNode.instructions.insert(insn, new MethodInsnNode(INVOKESTATIC, memberNames.className, memberNames.decryptMethodName, "(Ljava/lang/Object;I)Ljava/lang/String;", false)); ClassNode decryptor = createDecryptor(memberNames); getClasses().put(decryptor.name, new ClassWrapper(decryptor, false));
@Override public void transform() { AtomicInteger counter = new AtomicInteger(); MemberNames memberNames = new MemberNames(); getClassWrappers().parallelStream().filter(classWrapper -> !excluded(classWrapper)).forEach(classWrapper -> classWrapper.methods.parallelStream().filter(methodWrapper -> !excluded(methodWrapper) && hasInstructions(methodWrapper.methodNode)).forEach(methodWrapper -> { MethodNode methodNode = methodWrapper.methodNode; int leeway = getSizeLeeway(methodNode); String cst = (String) ldc.cst; if (!excludedString(cst)) { int extraKey = RandomUtils.getRandomInt(); int callerClassHC = classWrapper.classNode.name.replace("/", ".").hashCode(); int decryptorClassHC = memberNames.className.replace("/", ".").hashCode(); int decryptorMethodHC = memberNames.decryptorMethodName.hashCode(); ldc.cst = encrypt(cst, callerClassHC, callerMethodHC, decryptorClassHC, decryptorMethodHC, extraKey); methodNode.instructions.insert(insn, new MethodInsnNode(INVOKESTATIC, ClassNode decryptor = createDecryptor(memberNames); getClasses().put(decryptor.name, new ClassWrapper(decryptor, false));
AtomicInteger counter = new AtomicInteger(); getClassWrappers().parallelStream().filter(classWrapper -> !excluded(classWrapper)).forEach(classWrapper -> { ArrayList<String> strList = new ArrayList<>(); String methodName = randomString(4); String fieldName = randomString(4); classWrapper.methods.parallelStream().filter(methodWrapper -> !excluded(methodWrapper) && hasInstructions(methodWrapper.methodNode)).forEach(methodWrapper -> { MethodNode methodNode = methodWrapper.methodNode; String str = (String) cst; if (!excludedString(str)) { strList.add(str); classWrapper.classNode.methods.add(stringPool(classWrapper.classNode.name, methodName, fieldName, strList));
private List<StringEncryption> getStringEncryptionTransformers() { Object o = map.get(ConfigurationSettings.STRING_ENCRYPTION.getValue()); if (o == null) return null; if (!(o instanceof Map)) throw new IllegalConfigurationValueException(ConfigurationSettings.STRING_ENCRYPTION.getValue(), Map.class, o.getClass()); Map<String, Object> settings = (Map) o; if (!(boolean) settings.get("Enabled")) return null; String s = (String) settings.get("Mode"); if (!"Light".equals(s) && !"Normal".equals(s) && !"Heavy".equals(s)) throw new IllegalConfigurationValueException("Expected Light, Normal or Heavy as mode for string " + "encryption. Got " + s + " instead."); boolean pool = (boolean) settings.getOrDefault("StringPool", false); List<String> exclusions = (List) settings.getOrDefault("Exclusions", new ArrayList<String>()); ArrayList<StringEncryption> things = new ArrayList<>(); things.add(StringEncryption.getTransformerFromString(s, new StringEncryptionSetup(exclusions))); if (pool) things.add(new StringPool(new StringEncryptionSetup(exclusions))); return things; }
stringExclusions.addAll(((StringEncryption) transformer).getExcludedStrings());
.put("StringPool", true); if (encryption.getExcludedStrings() != null) ((LinkedHashMap) documentMap.get(ConfigurationSettings.STRING_ENCRYPTION.getValue())) .putIfAbsent("Exclusions", encryption.getExcludedStrings());
protected boolean excludedString(String str) { for (String s : this.setup.getExemptedStrings()) { if (str.contains(s)) { return true; } } return false; }