在最终编译之前如何使用java注释来修改源代码?

我从apt工具页面读取可以创建AnnotationProcessors到 generate new derived files (source files,class files,deployment descriptors,etc.).我正在寻找例子来做到这一点.

我的需要是在编译时对所有注释字符串进行编码,以便读取类文件不允许读取静态字符串:

基本代码

String message = (@Obfuscated "a string that should not be readable in class file");

应该重做:

String message = new ObfuscatedString(new long[] {0x86DD4DBB5166C13DL,0x4C79B1CDC313AE09L,0x1A353051DAF6463BL}).toString();

基于静态ObfuscatedString.obfuscate(String) method of the TrueLicense framework,处理器可以生成代码来替换注释字符串.的确,此方法生成字符串“new ObfuscatedString([numeric_code])toString()”.
在运行时,ObfuscatedString的toString()方法能够返回用数字代码编码的字符串.

任何关于如何编写AnnotationProcessor的process()方法来编辑注释代码的想法?

提前致谢,

解决方法

你可以有
String message = Obfuscated.decode("a string that should not be readable in class file");

然而在编译之后,您有一个工具来检查字节码例如使用ObjectWeb的ASM,更改字符串文字,因此它看起来像

String message = Obfuscated.decode("\u86DD\u4DBB\u5166\uC13D\u4C79\uB1CD\uC313\uAE09\u1A35\u3051\uDAF6\u463B");

为了更容易地识别需要更改的字符串,您可以为它们添加前缀,并且可以确保在前缀已经被模糊化之后出现.

String s = "Obfuscate: a string that should not be readable in class file";
// later
String message = Obfuscated.decode(s);

相关文章

最近看了一下学习资料,感觉进制转换其实还是挺有意思的,尤...
/*HashSet 基本操作 * --set:元素是无序的,存入和取出顺序不...
/*list 基本操作 * * List a=new List(); * 增 * a.add(inde...
/* * 内部类 * */ 1 class OutClass{ 2 //定义外部类的成员变...
集合的操作Iterator、Collection、Set和HashSet关系Iterator...
接口中常量的修饰关键字:public,static,final(常量)函数...