12.07.2015 Views

DANUT RUSU Protection Methods of Java Bytecode

DANUT RUSU Protection Methods of Java Bytecode

DANUT RUSU Protection Methods of Java Bytecode

SHOW MORE
SHOW LESS
  • No tags were found...

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

By means <strong>of</strong> a hex editor anyone can read andmodify the String literals <strong>of</strong> <strong>Java</strong> class files. If forthe appropriate CONSTANT_Utf8 entry, the fields“length” is modified, the length <strong>of</strong> these literals canbe also changed. A solution against this type <strong>of</strong>attack is the encrypting. Algorithm <strong>of</strong> insertion andencrypting must execute the following steps:1. Makes a random string with a specifiedminimum length (special characters andUnicode characters can be used). This stringis the key used by the encrypting anddecrypting functions.2. Gives a name to decrypting function,according to the algorithm <strong>of</strong> methods’rename. We suppose that the decryptingfunction is named dd.3. Searches CONSTANT_String entries intoConstant_Pool and encrypts theCONSTANT_Utf8 entries’ content addressedby these.4. Makes the following transforms in thebytecode:• increments suiting Constant_Pool_Count,• writes in Constant_Pool all encryptedmessage and increments/decrements, if isnecessary, CONSTANT_Utf8.length,• appends to Constant_Pool supplementaryentries with the name and signature <strong>of</strong>decrypting method, names and signatures<strong>of</strong> invoked methods by that, used literals,• Code attribute <strong>of</strong> each method whichcontains an encrypted message, mustsupport the following modifying:Bytes_Count and Code_Count areincremented with 3*N (where N is theencrypted messages’ number <strong>of</strong> themethod), Max_Stack is incremented with1 and, for each encrypted message, aninvokestatic instruction (which invokesthe dd method and its parameter is anindex at CONSTANT_Methodref entryappended to Constant_Pool), is insertedafter the ldc instruction’s code whichloads the encrypted message,• appends to bytecode the dd’s code, afterthe last method,• increments <strong>Methods</strong>_Count with 1.Now, we suppose that the random string is:String key = ".\rT\3752>l:h\u1212";and, we also suppose that the encrypting method is:String encrypt (String s) {char[] ac = s.toCharArray();char[] ac1 =key.toCharArray();for(int k = 0; k < ac.length; k++)ac[k] ^= ac1[k % ac1.length];return new String(ac);}If we apply encrypt to the string “<strong>Java</strong> is a portablelanguage”, we obtain the following encoded string:dl\"\234\022W\037\032\t\u1232^b&\211S\\\000_H\u127eOc3\210SY\t. If we apply encrypt to theencoded string, we obtain the initial string.encrypt’s inverse function is also encrypt.If the decrypting method’s name is dd, we mustinsert the code <strong>of</strong> the following method into theobfuscated bytecode:static String dd (String s) {char[] ac = s.toCharArray();char[] ac1 = null;ac1 =".\rT\3752>l:h\u1212".toCharArray();for(int k = 0; k < ac.length; k++)ac[k] ^= ac1[k % ac1.length];return new String(ac);}Let be n = Constant_Pool_Count and u, v, w, x, yare indexes at Constant_Pool such that:CONSTANT_Class Entry (u) (..)(reference at this class)CONSTANT_Utf8 Entry (v) CONSTANT_Utf8 Entry (w) CodeCONSTANT_Class Entry (x) (y)CONSTANT_Utf8 Entry (y) java/lang/StringWe look for u, v, w, x into Constant_Pool.if (x == 0) {x = n; y = x + 1; n++; flag = true;}Add at Constant_Pool the following entries:if(flag) {Constant_Pool_Count += 15;CONSTANT_Class Entry (x) (x+1)bytes: 07 (short)(x+1)(reference at String Class)CONSTANT_Utf8 Entry (x+1) java/lang/Stringbytes: 01 0010 6A61 7661 2F6C 616E 672F5374 7269 6E67(fully qualified form <strong>of</strong> String Class)} else Constant_Pool_Count += 13;CONSTANT_Methodref Entry (n) Class (u)Name/Type (n+1)bytes: 0A (short)u (short)(n+1)(reference at dd method from this Class)CONSTANT_NameAndType Entry (n+1) Name(n+2) Type (n+3)bytes: 0C (short)(n+2) (short)(n+3)(name and type <strong>of</strong> dd method)CONSTANT_Utf8 Entry (n+2) ddbytes: 0100 0264 64(decrypting method’s name)CONSTANT_Utf8 Entry (n+3)(Ljava/lang/String;)Ljava/lang/String;215

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!