KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > soot > jimple > toolkits > pointer > nativemethods > JavaLangSecurityManagerNative


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

19
20 /**
21  * Simulates the native method side effects in class java.lang.SecurityManager
22  *
23  * @author Feng Qian
24  * @author <XXX>
25  */

26
27 package soot.jimple.toolkits.pointer.nativemethods;
28
29 import soot.*;
30 import soot.jimple.toolkits.pointer.representations.*;
31 import soot.jimple.toolkits.pointer.util.*;
32
33 public class JavaLangSecurityManagerNative extends NativeMethodClass {
34     public JavaLangSecurityManagerNative( NativeHelper helper ) { super(helper); }
35
36   /**
37    * Implements the abstract method simulateMethod.
38    * It distributes the request to the corresponding methods
39    * by signatures.
40    */

41   public void simulateMethod(SootMethod method,
42                  ReferenceVariable thisVar,
43                  ReferenceVariable returnVar,
44                  ReferenceVariable params[]){
45
46     String JavaDoc subSignature = method.getSubSignature();
47
48     if (subSignature.equals("java.lang.Class[] getClassContext()")) {
49       java_lang_SecurityManager_getClassContext(method, thisVar,
50                         returnVar, params);
51       return;
52
53     } else if (subSignature.equals("java.lang.ClassLoader currentClassLoader0()")){
54       java_lang_SecurityManager_currentClassLoader0(method,
55                             thisVar,
56                             returnVar,
57                             params);
58       return;
59
60     } else if (subSignature.equals("java.lang.Class currentLoadedClass0()")){
61       java_lang_SecurityManager_currentLoadedClass0(method,
62                             thisVar,
63                             returnVar,
64                             params);
65       return;
66
67     } else {
68       defaultMethod(method, thisVar, returnVar, params);
69       return;
70
71     }
72   }
73   /************************* java.lang.SecurityManager ***************/
74   /**
75    * Returns the current execution stack as an array of classes.
76    *
77    * NOTE: an array of object may be created.
78    *
79    * protected native java.lang.Class getClassContext()[];
80    */

81   public
82     void java_lang_SecurityManager_getClassContext(SootMethod method,
83                            ReferenceVariable thisVar,
84                            ReferenceVariable returnVar,
85                            ReferenceVariable params[]){
86     helper.assignObjectTo(returnVar, Environment.v().getLeastArrayObject());
87   }
88
89   /**
90    * Returns the class loader of the most recently executing method
91    * from a class defined using a non-system class loader. A
92    * non-system class loader is defined as being a class loader that
93    * is not equal to the system class loader (as returned by
94    * ClassLoader.getSystemClassLoader()) or one of its ancestors.
95    *
96    * NOTE: returns a variable pointing to the only class loader object.
97    *
98    * private native java.lang.ClassLoader currentClassLoader0();
99    */

100   public
101     void java_lang_SecurityManager_currentClassLoader0(
102                 SootMethod method,
103                 ReferenceVariable thisVar,
104                 ReferenceVariable returnVar,
105                 ReferenceVariable params[]) {
106     helper.assignObjectTo(returnVar, Environment.v().getClassLoaderObject());
107   }
108
109   /**
110    * Returns a variable pointing to all class objects.
111    *
112    * private native java.lang.Class currentLoadedClass0();
113    */

114   public
115     void java_lang_SecurityManager_currentLoadedClass0(
116                      SootMethod method,
117                      ReferenceVariable thisVar,
118                      ReferenceVariable returnVar,
119                      ReferenceVariable params[]) {
120     helper.assignObjectTo(returnVar, Environment.v().getClassObject());
121   }
122
123   /**
124    * Both methods have NO side effects.
125    *
126    * protected native int classDepth(java.lang.String);
127    * private native int classLoaderDepth0();
128    */

129
130 }
131
Popular Tags