KickJava   Java API By Example, From Geeks To Geeks.

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


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.net.InetAddressImpl
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 JavaNetInetAddressImplNative extends NativeMethodClass {
34     public JavaNetInetAddressImplNative( 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.String getLocalHostName()")){
49       java_net_InetAddressImpl_getLocalHostName(method, thisVar,
50                         returnVar, params);
51       return;
52
53     } else if (subSignature.equals("java.lang.String getHostByAddress(int)")){
54       java_net_InetAddressImpl_getHostByAddr(method, thisVar,
55                          returnVar, params);
56       return;
57
58     } else {
59       defaultMethod(method, thisVar, returnVar, params);
60       return;
61
62     }
63   }
64
65   /************************ java.net.InetAddressImpl *****************/
66   /**
67    * Returns a variable pointing to a string constant
68    *
69    * I am not sure if repeated calls of methods in this class will
70    * return the same object or not. A conservative approach would
71    * say YES, for definitely points-to, but NO for may points-to.
72    *
73    * We should avoid analyzing these unsafe native methods.
74    *
75    * native java.lang.String getLocalHostName()
76    * throws java.net.UnknownHostException;
77    */

78   public
79     void java_net_InetAddressImpl_getLocalHostName(
80                       SootMethod method,
81                                           ReferenceVariable thisVar,
82                       ReferenceVariable returnVar,
83                       ReferenceVariable params[]){
84     helper.assignObjectTo(returnVar, Environment.v().getStringObject());
85   }
86   
87   /**
88    * Create a string object
89    *
90    * native java.lang.String getHostByAddr(int)
91    * throws java.net.UnknownHostException;
92    */

93   public
94     void java_net_InetAddressImpl_getHostByAddr(SootMethod method,
95                         ReferenceVariable thisVar,
96                         ReferenceVariable returnVar,
97                         ReferenceVariable params[]) {
98     helper.assignObjectTo(returnVar, Environment.v().getStringObject());
99   }
100
101   /**
102    * NO side effects.
103    * native void makeAnyLocalAddress(java.net.InetAddress);
104    * native byte lookupAllHostAddr(java.lang.String)[][]
105    * throws java.net.UnknownHostException;
106    * native int getInetFamily();
107    *
108    * @see default(...)
109    */

110
111 }
112
Popular Tags