How to use Java annotations to modify the source code before final compilation?

From the apt tool page, I can create annotation processors to generate new derived files (source files, class files, deployment descriptors, etc.) I am looking for examples to do this

I need to encode all comment strings at compile time to read class files. Static strings are not allowed:

Basic code:

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

Should redo:

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

Based on static obfuscatedstring Obfuscate (string) method of the truelicense framework, the processor can generate code to replace the comment string Indeed, this method generates the string "new obfuscatedstring ([numeric_code]) tostring()" At runtime, obfuscatedstring's toString () method can return a string encoded in numeric code

Any ideas on how to write the process () method of annotationprocessor to edit annotation code?

Thank you in advance,

Solution

You can have

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

However, after compilation, you have a tool to check the bytecode, such as using objectweb's ASM to change the string text, so it looks like

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

To make it easier to identify strings that need to be changed, you can prefix them and ensure that they appear after the prefix has been blurred

String s = "Obfuscate: a string that should not be readable in class file";
// later
String message = Obfuscated.decode(s);
The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>