1 19 20 25 26 package soot.jimple.toolkits.pointer.nativemethods; 27 28 import soot.*; 29 import soot.jimple.toolkits.pointer.representations.*; 30 import soot.jimple.toolkits.pointer.util.*; 31 32 public class JavaLangSystemNative extends NativeMethodClass { 33 public JavaLangSystemNative( NativeHelper helper ) { super(helper); } 34 35 40 public void simulateMethod(SootMethod method, 41 ReferenceVariable thisVar, 42 ReferenceVariable returnVar, 43 ReferenceVariable params[]){ 44 45 String subSignature = method.getSubSignature(); 46 47 if (subSignature.equals("void arraycopy(java.lang.Object,int,java.lang.Object,int,int)")) { 48 java_lang_System_arraycopy(method, thisVar, returnVar, params); 49 return; 50 51 } else if (subSignature.equals("void setIn0(java.io.InputStream)")) { 52 java_lang_System_setIn0(method, thisVar, returnVar, params); 53 return; 54 55 } else if (subSignature.equals("void setOut0(java.io.PrintStream)")) { 56 java_lang_System_setOut0(method, thisVar, returnVar, params); 57 return; 58 59 } else if (subSignature.equals("void setErr0(java.io.PrintStream)")) { 60 java_lang_System_setErr0(method, thisVar, returnVar, params); 61 return; 62 63 } else if (subSignature.equals("java.util.Properties initProperties(java.util.Properties)")) { 64 java_lang_System_initProperties(method, thisVar, returnVar, params); 65 return; 66 67 } else if (subSignature.equals("java.lang.String mapLibraryName(java.lang.String)")) { 68 java_lang_System_mapLibraryName(method, thisVar, returnVar, params); 69 return; 70 71 } else if (subSignature.equals("java.lang.Class getCallerClass()")) { 72 java_lang_System_getCallerClass(method, thisVar, returnVar, params); 73 return; 74 75 } else { 76 defaultMethod(method, thisVar, returnVar, params); 77 return; 78 } 79 } 80 81 82 99 public void java_lang_System_arraycopy(SootMethod method, 100 ReferenceVariable thisVar, 101 ReferenceVariable returnVar, 102 ReferenceVariable params[]){ 103 ReferenceVariable srcElm = helper.arrayElementOf(params[0]); 104 ReferenceVariable dstElm = helper.arrayElementOf(params[2]); 105 ReferenceVariable tmpVar = helper.tempLocalVariable(method); 108 helper.assign(tmpVar, srcElm); 109 helper.assign(dstElm, tmpVar); 110 } 111 112 119 public void java_lang_System_setIn0(SootMethod method, 120 ReferenceVariable thisVar, 121 ReferenceVariable returnVar, 122 ReferenceVariable params[]) { 123 ReferenceVariable sysIn = 124 helper.staticField("java.lang.System", "in"); 125 helper.assign(sysIn, params[0]); 126 } 127 128 134 public void java_lang_System_setOut0(SootMethod method, 135 ReferenceVariable thisVar, 136 ReferenceVariable returnVar, 137 ReferenceVariable params[]) { 138 ReferenceVariable sysOut = 139 helper.staticField("java.lang.System", "out"); 140 helper.assign(sysOut, params[0]); 141 } 142 143 149 public void java_lang_System_setErr0(SootMethod method, 150 ReferenceVariable thisVar, 151 ReferenceVariable returnVar, 152 ReferenceVariable params[]) { 153 ReferenceVariable sysErr = 154 helper.staticField("java.lang.System", "err"); 155 helper.assign(sysErr, params[0]); 156 } 157 158 166 public 167 void java_lang_System_initProperties(SootMethod method, 168 ReferenceVariable thisVar, 169 ReferenceVariable returnVar, 170 ReferenceVariable params[]) { 171 ReferenceVariable sysProps = 172 helper.staticField("java.lang.System", "props"); 173 helper.assign(returnVar, sysProps); 174 helper.assign(sysProps, params[0]); 175 } 176 177 182 public 183 void java_lang_System_mapLibraryName(SootMethod method, 184 ReferenceVariable thisVar, 185 ReferenceVariable returnVar, 186 ReferenceVariable params[]) { 187 helper.assignObjectTo(returnVar, Environment.v().getStringObject()); 188 } 189 190 195 public 196 void java_lang_System_getCallerClass(SootMethod method, 197 ReferenceVariable thisVar, 198 ReferenceVariable returnVar, 199 ReferenceVariable params[]) { 200 helper.assignObjectTo(returnVar, Environment.v().getClassObject()); 201 } 202 203 210 211 212 } 213 | Popular Tags |