How to use java annotations to modify source code before final compilation? -


i've read apt tool page 1 can create annotationprocessors generate new derived files (source files, class files, deployment descriptors, etc.). looking example so.

my need encode annotated strings @ compile time, reading class file not allow reading static strings:

base code:

string message = (@obfuscated "a string should not readable in class file"); 

should reworked as:

string message = new obfuscatedstring(new long[] {0x86dd4dbb5166c13dl, 0x4c79b1cdc313ae09l, 0x1a353051daf6463bl}).tostring(); 

based on static obfuscatedstring.obfuscate(string) method of truelicense framework, processor can generate code replace annotated string. indeed, method generates string "new obfuscatedstring([numeric_code]).tostring()". @ runtime tostring() method of obfuscatedstring able return string encoded in numeric code.

any idea on how write process() method of annotationprocessor edit annotated code?

thanks in advance,

you have

string message = obfuscated.decode("a string should not readable in class file"); 

which compiles normally, after compilation have tool examines bytecode e.g. using objectweb's asm, changes string literal looks like

string message = obfuscated.decode("\u86dd\u4dbb\u5166\uc13d\u4c79\ub1cd\uc313\uae09\u1a35\u3051\udaf6\u463b"); 

to make easer identify strings need changed, add prefix them, , ensure prefix appear after code has been obfuscated.

string s = "obfuscate: string should not readable in class file"; // later string message = obfuscated.decode(s); 

Comments

Popular posts from this blog

c# - SharpSVN - How to get the previous revision? -

c++ - Is it possible to compile a VST on linux? -

url - Querystring manipulation of email Address in PHP -