Start line:  
End line:  

Snippet Preview

Snippet HTML Code

Stack Overflow Questions
  /* Soot - a J*va Optimization Framework
   * Copyright (C) 2003 Feng Qian
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2.1 of the License, or (at your option) any later version.
   *
   * This library is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
  * Lesser General Public License for more details.
  *
  * You should have received a copy of the GNU Lesser General Public
  * License along with this library; if not, write to the
  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  * Boston, MA 02111-1307, USA.
  */

Simulates the native method side effects in class java.lang.System

Author(s):
Feng Qian
 
 
 package soot.jimple.toolkits.pointer.nativemethods;
 
 import soot.*;
 
 public class JavaLangSystemNative extends NativeMethodClass {
     public JavaLangSystemNativeNativeHelper helper ) { super(helper); }

  
Implements the abstract method simulateMethod. It distributes the request to the corresponding methods by signatures.
 
   public void simulateMethod(SootMethod method,
 			     ReferenceVariable thisVar,
 			     ReferenceVariable returnVar,
 			     ReferenceVariable params[]){
 
     String subSignature = method.getSubSignature();
 
     if (subSignature.equals("void arraycopy(java.lang.Object,int,java.lang.Object,int,int)")) {
       java_lang_System_arraycopy(methodthisVarreturnVarparams);
       return;
     
     } else if (subSignature.equals("void setIn0(java.io.InputStream)")) {
       java_lang_System_setIn0(methodthisVarreturnVarparams);
       return;
       
     } else if (subSignature.equals("void setOut0(java.io.PrintStream)")) {
       java_lang_System_setOut0(methodthisVarreturnVarparams);
       return;
 
     } else if (subSignature.equals("void setErr0(java.io.PrintStream)")) {
       java_lang_System_setErr0(methodthisVarreturnVarparams);
       return;
 
     } else if (subSignature.equals("java.util.Properties initProperties(java.util.Properties)")) {
       java_lang_System_initProperties(methodthisVarreturnVarparams);
       return;
 
     } else if (subSignature.equals("java.lang.String mapLibraryName(java.lang.String)")) {
       java_lang_System_mapLibraryName(methodthisVarreturnVarparams);
       return;
 
     } else if (subSignature.equals("java.lang.Class getCallerClass()")) {
       java_lang_System_getCallerClass(methodthisVarreturnVarparams);
       return;
 
     } else {
       defaultMethod(methodthisVarreturnVarparams);
       return;
     }
   }

  
java.lang.System *******************
 
  
Copies an array from the specified source array, beginning at the specified position, to the specified position of the destination array. NOTE: If the content of array is reference type, then it is necessary to build a connection between elements of two arrays dst[] = src[] public static native void arraycopy(java.lang.Object, int, java.lang.Object, int, int);
 
   public void java_lang_System_arraycopy(SootMethod method,
    ReferenceVariable srcElm = .arrayElementOf(params[0]);
    ReferenceVariable dstElm = .arrayElementOf(params[2]);
    // never make a[] = b[], it violates the principle of jimple statement.
    // make a temporary variable.
    ReferenceVariable tmpVar = .tempLocalVariable(method);
    .assign(tmpVarsrcElm);
    .assign(dstElmtmpVar);
  }

  
NOTE: this native method is not documented in JDK API. It should have the side effect: System.in = parameter private static native void setIn0(java.io.InputStream);
  public void java_lang_System_setIn0(SootMethod method,
					     ReferenceVariable thisVar,
					     ReferenceVariable returnVar,
					     ReferenceVariable params[]) {
    ReferenceVariable sysIn = 
      .staticField("java.lang.System""in");
    .assign(sysInparams[0]);
  }

  
NOTE: the same explanation as setIn0: G.v().out = parameter private static native void setOut0(java.io.PrintStream);
  public void java_lang_System_setOut0(SootMethod method,
					      ReferenceVariable thisVar,
					      ReferenceVariable returnVar,
					      ReferenceVariable params[]) {
    ReferenceVariable sysOut = 
      .staticField("java.lang.System""out");
    .assign(sysOutparams[0]);
  }

  
NOTE: the same explanation as setIn0: System.err = parameter private static native void setErr0(java.io.PrintStream);
  public void java_lang_System_setErr0(SootMethod method,
					      ReferenceVariable thisVar,
					      ReferenceVariable returnVar,
					      ReferenceVariable params[]) {
    ReferenceVariable sysErr = 
      .staticField("java.lang.System""err");
    .assign(sysErrparams[0]);
  }

  
NOTE: this method is not documented, it should do following:

Returns:
= System.props; System.props = parameter; private static native java.util.Properties initProperties(java.util.Properties);
  public 
					 ReferenceVariable returnVar,
					 ReferenceVariable params[]) {
    ReferenceVariable sysProps = 
      .staticField("java.lang.System""props");
    .assign(returnVarsysProps);
    .assign(sysPropsparams[0]);
  }

  
NOTE: it is platform-dependent, create a new string, needs to be verified. public static native java.lang.String mapLibraryName(java.lang.String);
  public 
					 ReferenceVariable returnVar,
					 ReferenceVariable params[]) {
    .assignObjectTo(returnVar, Environment.v().getStringObject());
  }

  
Undocumented, used by class loading. static native java.lang.Class getCallerClass();
  public 
					 ReferenceVariable returnVar,
					 ReferenceVariable params[]) {
    .assignObjectTo(returnVar, Environment.v().getClassObject());
  }

  
Following methods have NO side effects. private static native void registerNatives(); public static native long currentTimeMillis(); public static native int identityHashCode(java.lang.Object);
New to GrepCode? Check out our FAQ X