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.
  */

A wrapper for native method side-effect simulation. The caller passes in a native method with parameters, the corresponding native simulator gets called.

Author(s):
Feng Qian
 
 package soot.jimple.toolkits.pointer.util;
 
 import soot.*;
 import java.util.*;
 
 public class NativeMethodDriver {
     public NativeMethodDriverNativeHelper helper ) {
         .put("java.lang.Object"new JavaLangObjectNative(helper));
         .put("java.lang.System"new JavaLangSystemNative(helper));
         .put("java.lang.Runtime"new JavaLangRuntimeNative(helper));
         .put("java.lang.Shutdown"new JavaLangShutdownNative(helper));
         .put("java.lang.String"new JavaLangStringNative(helper));
         .put("java.lang.Float"new JavaLangFloatNative(helper));
         .put("java.lang.Double"new JavaLangDoubleNative(helper));
         .put("java.lang.StrictMath"new JavaLangStrictMathNative(helper));
         .put("java.lang.Throwable"new JavaLangThrowableNative(helper));
         .put("java.lang.Class"new JavaLangClassNative(helper));
         .put("java.lang.Package"new JavaLangPackageNative(helper));
         .put("java.lang.Thread"new JavaLangThreadNative(helper));
         .put("java.lang.ClassLoader"new JavaLangClassLoaderNative(helper));
         .put("java.lang.ClassLoader$NativeLibrary",
                        new JavaLangClassLoaderNativeLibraryNative(helper));
         .put("java.lang.SecurityManager",
                        new JavaLangSecurityManagerNative(helper));
 
 
         .put("java.lang.reflect.Field",
                        new JavaLangReflectFieldNative(helper));
         .put("java.lang.reflect.Array",
                        new JavaLangReflectArrayNative(helper));
         .put("java.lang.reflect.Method",
                        new JavaLangReflectMethodNative(helper));
         .put("java.lang.reflect.Constructor",
                        new JavaLangReflectConstructorNative(helper));
         .put("java.lang.reflect.Proxy",
                        new JavaLangReflectProxyNative(helper));
 
 
         .put("java.io.FileInputStream"
                        new JavaIoFileInputStreamNative(helper));
         .put("java.io.FileOutputStream"
                        new JavaIoFileOutputStreamNative(helper));
         .put("java.io.ObjectInputStream",
                        new JavaIoObjectInputStreamNative(helper));
         .put("java.io.ObjectOutputStream",
                        new JavaIoObjectOutputStreamNative(helper));
         .put("java.io.ObjectStreamClass",
                        new JavaIoObjectStreamClassNative(helper));
         .put("java.io.FileSystem"new JavaIoFileSystemNative(helper));
         .put("java.io.FileDescriptor"new JavaIoFileDescriptorNative(helper));
 
 
         .put("java.util.ResourceBundle"
                        new JavaUtilResourceBundleNative(helper));
         .put("java.util.TimeZone"new JavaUtilTimeZoneNative(helper));
         
 
         .put("java.util.jar.JarFile",
                        new JavaUtilJarJarFileNative(helper));
         
         .put("java.util.zip.CRC32",
                        new JavaUtilZipCRC32Native(helper));
         .put("java.util.zip.Inflater",
                        new JavaUtilZipInflaterNative(helper));
         .put("java.util.zip.ZipFile",
                        new JavaUtilZipZipFileNative(helper));
         .put("java.util.zip.ZipEntry",
                        new JavaUtilZipZipEntryNative(helper));
         
 
         .put("java.security.AccessController",
                       new JavaSecurityAccessControllerNative(helper));
        
        .put("java.net.InetAddress"
                       new JavaNetInetAddressNative(helper));
        .put("java.net.InetAddressImpl"
                       new JavaNetInetAddressImplNative(helper));
        .put("sun.misc.Signal",
                       new SunMiscSignalNative(helper));
        .put("sun.misc.NativeSignalHandler",
                       new SunMiscSignalHandlerNative(helper));
        .put("sun.misc.Unsafe",
                       new SunMiscUnsafeNative(helper));
    }
  private final boolean DEBUG = false;

  
The entry point of native method simulation.

Parameters:
method, must be a native method
thisVar, the variable represent @this, it can be null if the method is static
returnVar, the variable represent @return it is null if the method has no return
params, array of parameters.
  public boolean process(SootMethod method
				ReferenceVariable params[]) {
    String cname = method.getDeclaringClass().getName();
    NativeMethodClass clsSim = .get(cname);
//    G.v().out.println(method.toString());
    if (clsSim == null) {
	  //G.v().out.println("WARNING: it is unsafe to simulate the method ");
	  //G.v().out.println("         "+method.toString());	
      //throw new NativeMethodNotSupportedException(method);
      return true;
    } else {
      try {
	clsSim.simulateMethod(method,
			      thisVar,
			      returnVar,
			      params);
      } catch (NativeMethodNotSupportedException e) {
          if() {
              G.v()..println("WARNING: it is unsafe to simulate the method ");
              G.v()..println("         "+method.toString());	
          }
      }
      return true;
    }
  }
New to GrepCode? Check out our FAQ X