Array Based Java Source Code Obfuscation Using Classes with Restructured Arrays

Array restructuring operations obscure arrays. Our work aims on java source code obfuscation containing arrays. Our main proposal is Classes with restructured array members and obscured member methods for setting, getting array elements and to get th…

Authors: Praveen Sivadasan, P. Sojan Lal

Array Based Java Source Code Obfuscation Using Classes with Restructured   Arrays
1 ARRAY BASED JA VA SOURCE CODE OBFUSCA TION USING CLASSES WITH RESTRU CTURED ARRAYS Praveen Sivadasan, P Sojan Lal, PhD Scholar, School of Co mputer Sciences, Faculty Guide, School of Computer Scie nces, Mahatma Gandhi University, Mahatma Gandhi University, Kottayam, Kerala, India. Kottayam, Kerala, India. praveen_sivadas@yahoo.co m sojanlal@gmail.com Abstract— Array restructuring operation s obscure arrays. Our work aims on java source code obfusca tion containing arrays. Our main proposal is Classes with restruc tured array members and obscured member methods for setting, getting array elements and to get the length of arrays. The class method definition codes are obscured through index transformation and constan t hiding. The instantiated objects of these classes are used for source code writing. A tool n amed JDATATRANS i s developed for g enerating classes and to the best of our k nowledge this is the first tool available fo r array restructuring, on java source codes. Keywords— Array restructu ring, Source cod e obfuscation, Index transformatio n, Consta nt hiding 1 INTRODUCTION Java ‘byte code’ retains most or all information prese nt in the original source code [1]. This is because the translation to real machine instruction happens in the br owser of the user’s machine by JIT (Just-In-Ti me Compiler). Also, Java programs are small in size because of the vast functionalities provided by the Java standard libraries. Retaining information of the source code by b yte code results in Deco mpilation which is is the process of generating source codes from machine codes or intermediate byte codes. Software obfuscation [2,3] is a popular and economical appro ach to trim down reverse engineeri ng and re-engineeri ng attacks through deco mpilation. Source code obfuscation cons ists of any technique that is targeted at making the source code less intelligible [10] and our focus is on obfuscating arrays of java source codes. Array restructuring operations obscure arrays by its reorganization , index, dimension and array name changes. The array restructuring operations are arra y splitting, array merging, array folding and array flattening [4]. Array splitting is generalized in [7] and homomorphic obfuscations [5] are to strengt hen obfuscation. I n array splitting, an arr ay ‘A’ is split into two sub-arr ays A1 and A2 where A1 holds elements of A with even indices and A2 hold elements of A with odd indices. Array merging merges two 1D arra ys into one. Array folding transfor ms a 1D arra y into a 2D arra y and Arra y flattening from a 2 D array into a 1D array. Anal ysis metrics for o bfuscation have been pro posed in [8 ]. Figure 1. Arra y Splitting Figure 2. Arra y Merging Figure 3. Arra y Folding Figure 4. Arra y Flattening 2 In [6], I = f (i) = 2 * i + 3 , is a function representing the new value of i and an imp rovement for this index transformation is suggested in [11]. William Feng Zhu in [5] has shown a case of obfusca ted program (Figure 6), for the code in Figure 5. .... int A[100]; ...; S = 0; for (i = 0; i < 1 00; i++) S = S + A[i]; ... Figure 5. An unobfuscated pr ogram ... int B[100]; ... S = 0; for (i = 0; i < 100; i++) S = S + B[i*3 mo d 100]; ... Figure 6. An obfuscated pr ogram A class say ‘B’ is prop osed for encapsulating arra y obj ect ‘B [ ]’ w ith scan and access methods. The class say ‘test’(Figure 7) is written using class ‘B’ where the obscurity is maintained for the codes of class B, but not for class test, thus implementing partial ob scurity to the entire codes. class B { int[] B=new int[ 100]; public void scan (int i, int elem) { B[i* 3mod100] =elem;} public int acces s(int i) { return (B[i*3mo d100]);} } public class tes t { public static vo id main( String args[]) { S=0; B b=new B( ); for (i=0;i< 100;i++) b.scan (i, 3*i + 1000); for (i=0;i<1 00;i++) S=S+b.access(i) ; } } Figure 7. class ‘test’ using cl ass B We also propose classes with restructured arrays. Let us consider a class ‘SplitArray_I nteger’ with split arra y objects ‘iObj1’ and ‘iObj2 ’, in Figure 8. public class Sp litArray _Integer extends obfusca te { int[] iObj1;int[ ] iObj2; public SplitArr ay_Integ er(int size ) { if((size%2)= =0) { iObj1= new int [(int)(s ize/2)]; iObj2= new int[( int)(siz e/2)];} else { int temp =(int)(size/2)+1 ;iObj1= new int[ temp]; iObj2= n ew int[size-temp ];}} public v oid setArray(int pos ,int ele m) {….. } public i nt getArray(int pos ) {……} public i nt lengthArray() {……}………………} Figure 8. Class with split arr ay object members iObj 1 and iObj 2 The setArray, getArray, lengthArra y method definitions of class SplitArra y_Integer, in Figure 9 public void setArray(int pos ,int ele m) { if((pos%2)==0) iObj1[(int)pos/2 ]=elem; else iObj2[(int)pos/2 ]=elem; } public int getArray(int pos) { if((pos%2)==0 ) return(iObj1[(in t)pos/2] ); else return(iObj2[(in t)pos/2] );} public int lengthArray( ) {return (iObj1.l ength+iObj2.leng th);} Figure 9. Method Definitions of class ‘Split Array_Integer’ The codes of class SplitArray_Integer are obscured and this class operates onl y on integer arra ys . This class is considered for source code writing, to instantiate 1D integer arra y objects (Figure 12). The other classes SplitArray_Double, SplitArray_String, SplitArra y_Char are to instantiate double, string, char arra y obj ects respectively. 3 The method F(a,b) is used to strengthen obfuscation by hiding the integer constant 2,[6]. The 2D array ‘y-factors’ stores a list of pairs o f numbers whose sum gives a p rime number. T he values in y_factors ar e based on the rule that n1+n2 results in a pri me number. T he function calls F (41 mod 23, 2), F(6130%30 71,9), F(24560%12287,11) are to hide value 2. public static in t F(int y,int count) {int[][] y_facto rs=new i nt[count][2]; //A 2Dim ensional array /*Assign values to y_fac tors based on th e rule t hat n1+n 2 results in a p rime num ber*/ y_factors=[2,3], [5,6],[1 1,12],[23,24],[4 7,48],[9 5,96],[1 91,192],[383,384 ],[767,7 68],[153 5,1536], [3071,3072],[ 6143, 61 44], [12287, 122 88]; // Parameter val ue say, 2 for ‘count’ of F(int, int), co nsiders pairs of y_facto rs [2,3] ,[5,6] // Parameter v alue say , 4 considers pa irs [2,3 ], [5,6] ,[11,12],[23,24] for (int i= count;i> 0;i--){ Here y1=y_fac tors[i-1][0]+y_f actors[i -1][1]; y=ym ody1; } return y; } Figure10. Implementation o f F(int y, int count) for hiding constant 2 Also, classes with folded and flattened arra ys for integer, double, string, char data t ypes are pr oposed. A tool named ‘JDATAT RANS’ has been desig ned to genera te the classe s. The investigati on of the tool is done for Splitting, Folding and Flattening operatio ns. The key tool steps for the class generation is (i) Representing the proposed arrays required for source code writing (ii) Decide about the arra y restruct uring operatio n (iv)Generate the classe s (v) Source code writing using the generated classes. Let us discuss a case by consider ing Array Splitting. The proposed arrays for array splitting are represented in a file, say ‘InFile.txt’ with java array obj ect instantiation state ments like int[] array=new int[1000 00]; int[ ] a=new int [23]; double ab=new do uble[45] ; String[ ] abc=ne w String [34]; char abcd[]=new char[100 ]; Figure11. Tool I nput for Array Splitting The file ‘InFile.txt’ is the input to the tool and genera tes classes Split Array_Integer, SplitArray_Double, SplitArray_String, SplitArra y_Char in the working folder, to be used for source code writing. A source code ‘test.java’ writt en using the too l generated classes is in, Figure 11. public class tes t { public static vo id main( String args[]){i nt n; SplitArray_Integ er array =new SplitArray_ Integer( 100000); SplitArray_Integ er a=new SplitArray_Inte ger(23); SplitArray_Doubl e ab=new SplitArray_Doub le(45); SplitArr ay_Strin g abc=new SplitA rray_Str ing(34); SplitArr ay_Char abcd=new SplitAr ray_Char (100); try{BufferedRead er stdin =new BufferedRe ader(new InputSt reamReader(Syste m.in), 1 ); n=Integer.parseI nt(stdin .readLine()); for(int i=0;i

Original Paper

Loading high-quality paper...

Comments & Academic Discussion

Loading comments...

Leave a Comment