第十五步:定制加密字符串
在第一步的基础上修改,定制加密字符串。
custom.jar 包含一个带有加密解密样例方法的类。
配置文件如下:
<config>
<input>
<jar in="test.jar" out="obf-test.jar"/>
<jar in="mousegestures-1.2.jar" out="obf-mousegestures-1.2.jar"/>
<jar in="custom.jar" out="obf-custom.jar"/>
</input>
<-names>
<class access="protected+">
<field access="protected+"/>
<method access="protected+"/>
</class>
</keep-names>
<!-- We recommend using the v3 setting if custom string encryption is applied to ALL your classes. -->
<!-- This way Allatori would not add any additional (unused) string decryption methods. -->
<!-- If you combine custom string encryption and Allatori string encryption, then the default v4 setting is recommended. -->
<property name="string-encryption-version" value="v3"/>
<!-- Disabling string encryption in custom decryption methods, as it could lead to infinite recursive calls. -->
<property name="string-encryption" value="disable" apply2class="class com.allatori.custom.EncryptDecryptString" apply2method="decrypt*(java.lang.String)"/>
<property name="string-encryption" value="maximum"/>
<property name="string-encryption-type" value="custom(com.allatori.custom.EncryptDecryptString.encryptString, com.allatori.custom.EncryptDecryptString.decryptString)"/>
<property name="log-file" value="log.xml"/>
</config>
其中
<jar in="custom.jar" out="obf-custom.jar"/>
......
<property name="string-encryption-version" value="v3"/>
......
<property name="string-encryption" value="disable" apply2class="class com.allatori.custom.EncryptDecryptString" apply2method="decrypt*(java.lang.String)"/>
<property name="string-encryption" value="maximum"/>
<property name="string-encryption-type" value="custom(com.allatori.custom.EncryptDecryptString.encryptString, com.allatori.custom.EncryptDecryptString.decryptString)"/>
......
是改变的部分。
你可以在指定的包中应用定制化的字符串加密方法:
<property name="string-encryption-type" value="custom(package.EncryptClassName.encryptMethodName, package.DecryptClassName.decryptMethodName)" apply2class="class com.some.package.*"/>
也可以使用多种字符串加密方法:
<property name="string-encryption-type" value="custom(package.EncryptClassName1.encryptMethodName1, package.DecryptClassName1.decryptMethodName1)" apply2class="class com.some.package.*"/>
<property name="string-encryption-type" value="custom(package.EncryptClassName2.encryptMethodName2, package.DecryptClassName2.decryptMethodName2)" apply2class="class com.some.other.package.*"/>
<!-- Methods for classes not matched by the rules above -->
<property name="string-encryption-type" value="custom(package.EncryptClassName3.encryptMethodName3, package.DecryptClassName3.decryptMethodName3)"/>
加密方法只在混淆过程中需要,运行过程中不需要。
解密方法在运行时是需要的,你可以把它们放到你程序的任何地方。
定制化加密方法可以使用国际化信息。在Allatori的methodCall方法中,你可以在加密方法中跟踪并翻译字符,也可以在运行时的解密方法中对字符串进行国际化处理。