diff options
Diffstat (limited to 'OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs')
-rw-r--r-- | OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs | 1006 |
1 files changed, 503 insertions, 503 deletions
diff --git a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs index f821f52..f151b7e 100644 --- a/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs +++ b/OpenSim/Region/Environment/Scenes/scripting/Engines/JVMEngine/JVM/ClassRecord.cs | |||
@@ -1,503 +1,503 @@ | |||
1 | /* | 1 | /* |
2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ | 2 | * Copyright (c) Contributors, http://www.openmetaverse.org/ |
3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. | 3 | * See CONTRIBUTORS.TXT for a full list of copyright holders. |
4 | * | 4 | * |
5 | * Redistribution and use in source and binary forms, with or without | 5 | * Redistribution and use in source and binary forms, with or without |
6 | * modification, are permitted provided that the following conditions are met: | 6 | * modification, are permitted provided that the following conditions are met: |
7 | * * Redistributions of source code must retain the above copyright | 7 | * * Redistributions of source code must retain the above copyright |
8 | * notice, this list of conditions and the following disclaimer. | 8 | * notice, this list of conditions and the following disclaimer. |
9 | * * Redistributions in binary form must reproduce the above copyright | 9 | * * Redistributions in binary form must reproduce the above copyright |
10 | * notice, this list of conditions and the following disclaimer in the | 10 | * notice, this list of conditions and the following disclaimer in the |
11 | * documentation and/or other materials provided with the distribution. | 11 | * documentation and/or other materials provided with the distribution. |
12 | * * Neither the name of the OpenSim Project nor the | 12 | * * Neither the name of the OpenSim Project nor the |
13 | * names of its contributors may be used to endorse or promote products | 13 | * names of its contributors may be used to endorse or promote products |
14 | * derived from this software without specific prior written permission. | 14 | * derived from this software without specific prior written permission. |
15 | * | 15 | * |
16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY | 16 | * THIS SOFTWARE IS PROVIDED BY THE DEVELOPERS ``AS IS AND ANY |
17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 17 | * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 18 | * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY | 19 | * DISCLAIMED. IN NO EVENT SHALL THE CONTRIBUTORS BE LIABLE FOR ANY |
20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 20 | * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 21 | * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 22 | * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 23 | * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS | 24 | * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS |
25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 25 | * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
26 | * | 26 | * |
27 | */ | 27 | */ |
28 | using System; | 28 | using System; |
29 | using System.IO; | 29 | using System.IO; |
30 | using System.Collections.Generic; | 30 | using System.Collections.Generic; |
31 | using System.Text; | 31 | using System.Text; |
32 | using OpenSim.Region.Scripting.EmbeddedJVM.Types; | 32 | using OpenSim.Region.Scripting.EmbeddedJVM.Types; |
33 | 33 | ||
34 | namespace OpenSim.Region.Scripting.EmbeddedJVM | 34 | namespace OpenSim.Region.Scripting.EmbeddedJVM |
35 | { | 35 | { |
36 | public class ClassRecord | 36 | public class ClassRecord |
37 | { | 37 | { |
38 | private ushort _majorVersion; | 38 | private ushort _majorVersion; |
39 | private ushort _minorVersion; | 39 | private ushort _minorVersion; |
40 | private ushort _constantPoolCount; | 40 | private ushort _constantPoolCount; |
41 | private ushort _accessFlags; | 41 | private ushort _accessFlags; |
42 | private ushort _thisClass; | 42 | private ushort _thisClass; |
43 | private ushort _supperClass; | 43 | private ushort _supperClass; |
44 | private ushort _interfaceCount; | 44 | private ushort _interfaceCount; |
45 | private ushort _fieldCount; | 45 | private ushort _fieldCount; |
46 | private ushort _methodCount; | 46 | private ushort _methodCount; |
47 | //private ushort _attributeCount; | 47 | //private ushort _attributeCount; |
48 | //private string _name; | 48 | //private string _name; |
49 | public Dictionary<string, BaseType> StaticFields = new Dictionary<string, BaseType>(); | 49 | public Dictionary<string, BaseType> StaticFields = new Dictionary<string, BaseType>(); |
50 | public PoolClass mClass; | 50 | public PoolClass mClass; |
51 | 51 | ||
52 | public List<PoolItem> _constantsPool = new List<PoolItem>(); | 52 | public List<PoolItem> _constantsPool = new List<PoolItem>(); |
53 | private List<MethodInfo> _methodsList = new List<MethodInfo>(); | 53 | private List<MethodInfo> _methodsList = new List<MethodInfo>(); |
54 | private List<FieldInfo> _fieldList = new List<FieldInfo>(); | 54 | private List<FieldInfo> _fieldList = new List<FieldInfo>(); |
55 | 55 | ||
56 | public ClassRecord() | 56 | public ClassRecord() |
57 | { | 57 | { |
58 | 58 | ||
59 | } | 59 | } |
60 | 60 | ||
61 | public ClassInstance CreateNewInstance() | 61 | public ClassInstance CreateNewInstance() |
62 | { | 62 | { |
63 | return new ClassInstance(); | 63 | return new ClassInstance(); |
64 | } | 64 | } |
65 | 65 | ||
66 | public void LoadClassFromFile(string fileName) | 66 | public void LoadClassFromFile(string fileName) |
67 | { | 67 | { |
68 | Console.WriteLine("loading script " + fileName); | 68 | Console.WriteLine("loading script " + fileName); |
69 | FileStream fs = File.OpenRead(fileName); | 69 | FileStream fs = File.OpenRead(fileName); |
70 | this.LoadClassFromBytes(ReadFully(fs)); | 70 | this.LoadClassFromBytes(ReadFully(fs)); |
71 | fs.Close(); | 71 | fs.Close(); |
72 | } | 72 | } |
73 | 73 | ||
74 | public void LoadClassFromBytes(byte[] data) | 74 | public void LoadClassFromBytes(byte[] data) |
75 | { | 75 | { |
76 | int i = 0; | 76 | int i = 0; |
77 | i += 4; | 77 | i += 4; |
78 | _minorVersion = (ushort)((data[i++] << 8) + data[i++] ); | 78 | _minorVersion = (ushort)((data[i++] << 8) + data[i++] ); |
79 | _majorVersion = (ushort)((data[i++] << 8) + data[i++] ); | 79 | _majorVersion = (ushort)((data[i++] << 8) + data[i++] ); |
80 | _constantPoolCount = (ushort)((data[i++] << 8) + data[i++] ); | 80 | _constantPoolCount = (ushort)((data[i++] << 8) + data[i++] ); |
81 | // Console.WriteLine("there should be " + _constantPoolCount + " items in the pool"); | 81 | // Console.WriteLine("there should be " + _constantPoolCount + " items in the pool"); |
82 | for (int count = 0; count < _constantPoolCount -1 ; count++) | 82 | for (int count = 0; count < _constantPoolCount -1 ; count++) |
83 | { | 83 | { |
84 | //read in the constant pool | 84 | //read in the constant pool |
85 | byte pooltype = data[i++]; | 85 | byte pooltype = data[i++]; |
86 | //Console.WriteLine("#" +count +": new constant type = " +pooltype); | 86 | //Console.WriteLine("#" +count +": new constant type = " +pooltype); |
87 | //Console.WriteLine("start position is: " + i); | 87 | //Console.WriteLine("start position is: " + i); |
88 | switch (pooltype) | 88 | switch (pooltype) |
89 | { | 89 | { |
90 | case 1: //Utf8 | 90 | case 1: //Utf8 |
91 | ushort uLength = (ushort)((data[i++] << 8) + data[i++] ); | 91 | ushort uLength = (ushort)((data[i++] << 8) + data[i++] ); |
92 | 92 | ||
93 | // Console.WriteLine("new utf8 type, length is " + uLength); | 93 | // Console.WriteLine("new utf8 type, length is " + uLength); |
94 | PoolUtf8 utf8 = new PoolUtf8(); | 94 | PoolUtf8 utf8 = new PoolUtf8(); |
95 | utf8.readValue(data, ref i, uLength); | 95 | utf8.readValue(data, ref i, uLength); |
96 | this._constantsPool.Add(utf8); | 96 | this._constantsPool.Add(utf8); |
97 | break; | 97 | break; |
98 | case 3: //Int | 98 | case 3: //Int |
99 | break; | 99 | break; |
100 | case 7: //Class | 100 | case 7: //Class |
101 | PoolClass pClass = new PoolClass(this); | 101 | PoolClass pClass = new PoolClass(this); |
102 | pClass.readValue(data, ref i); | 102 | pClass.readValue(data, ref i); |
103 | this._constantsPool.Add(pClass); | 103 | this._constantsPool.Add(pClass); |
104 | break; | 104 | break; |
105 | case 10: //Method | 105 | case 10: //Method |
106 | PoolMethodRef pMeth = new PoolMethodRef(this); | 106 | PoolMethodRef pMeth = new PoolMethodRef(this); |
107 | pMeth.readValue(data, ref i); | 107 | pMeth.readValue(data, ref i); |
108 | this._constantsPool.Add(pMeth); | 108 | this._constantsPool.Add(pMeth); |
109 | break; | 109 | break; |
110 | case 12: //NamedType | 110 | case 12: //NamedType |
111 | PoolNamedType pNamed = new PoolNamedType(this); | 111 | PoolNamedType pNamed = new PoolNamedType(this); |
112 | pNamed.readValue(data, ref i); | 112 | pNamed.readValue(data, ref i); |
113 | this._constantsPool.Add(pNamed); | 113 | this._constantsPool.Add(pNamed); |
114 | break; | 114 | break; |
115 | } | 115 | } |
116 | } | 116 | } |
117 | 117 | ||
118 | _accessFlags = (ushort)((data[i++] << 8) + data[i++] ); | 118 | _accessFlags = (ushort)((data[i++] << 8) + data[i++] ); |
119 | _thisClass = (ushort)((data[i++] << 8) + data[i++] ); | 119 | _thisClass = (ushort)((data[i++] << 8) + data[i++] ); |
120 | _supperClass = (ushort)((data[i++] << 8) + data[i++] ); | 120 | _supperClass = (ushort)((data[i++] << 8) + data[i++] ); |
121 | 121 | ||
122 | if (this._constantsPool[this._thisClass - 1] is PoolClass) | 122 | if (this._constantsPool[this._thisClass - 1] is PoolClass) |
123 | { | 123 | { |
124 | this.mClass = ((PoolClass)this._constantsPool[this._thisClass - 1]); | 124 | this.mClass = ((PoolClass)this._constantsPool[this._thisClass - 1]); |
125 | } | 125 | } |
126 | 126 | ||
127 | _interfaceCount = (ushort)((data[i++] << 8) + data[i++]); | 127 | _interfaceCount = (ushort)((data[i++] << 8) + data[i++]); |
128 | //should now read in the info for each interface | 128 | //should now read in the info for each interface |
129 | _fieldCount = (ushort)((data[i++] << 8) + data[i++]); | 129 | _fieldCount = (ushort)((data[i++] << 8) + data[i++]); |
130 | //should now read in the info for each field | 130 | //should now read in the info for each field |
131 | _methodCount = (ushort)((data[i++] << 8) + data[i++]); | 131 | _methodCount = (ushort)((data[i++] << 8) + data[i++]); |
132 | for (int count = 0; count < _methodCount; count++) | 132 | for (int count = 0; count < _methodCount; count++) |
133 | { | 133 | { |
134 | MethodInfo methInf = new MethodInfo(this); | 134 | MethodInfo methInf = new MethodInfo(this); |
135 | methInf.ReadData(data, ref i); | 135 | methInf.ReadData(data, ref i); |
136 | this._methodsList.Add(methInf); | 136 | this._methodsList.Add(methInf); |
137 | } | 137 | } |
138 | } | 138 | } |
139 | 139 | ||
140 | public void AddMethodsToMemory(MethodMemory memory) | 140 | public void AddMethodsToMemory(MethodMemory memory) |
141 | { | 141 | { |
142 | for (int count = 0; count < _methodCount; count++) | 142 | for (int count = 0; count < _methodCount; count++) |
143 | { | 143 | { |
144 | this._methodsList[count].AddMethodCode(memory); | 144 | this._methodsList[count].AddMethodCode(memory); |
145 | } | 145 | } |
146 | } | 146 | } |
147 | 147 | ||
148 | public bool StartMethod(Thread thread, string methodName) | 148 | public bool StartMethod(Thread thread, string methodName) |
149 | { | 149 | { |
150 | for (int count = 0; count < _methodCount; count++) | 150 | for (int count = 0; count < _methodCount; count++) |
151 | { | 151 | { |
152 | if (this._constantsPool[this._methodsList[count].NameIndex-1] is PoolUtf8) | 152 | if (this._constantsPool[this._methodsList[count].NameIndex-1] is PoolUtf8) |
153 | { | 153 | { |
154 | if (((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex-1]).Value == methodName) | 154 | if (((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex-1]).Value == methodName) |
155 | { | 155 | { |
156 | //Console.WriteLine("found method: " + ((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex - 1]).Value); | 156 | //Console.WriteLine("found method: " + ((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex - 1]).Value); |
157 | thread.SetPC(this._methodsList[count].CodePointer); | 157 | thread.SetPC(this._methodsList[count].CodePointer); |
158 | return true; | 158 | return true; |
159 | } | 159 | } |
160 | } | 160 | } |
161 | } | 161 | } |
162 | return false; | 162 | return false; |
163 | } | 163 | } |
164 | 164 | ||
165 | public void PrintToConsole() | 165 | public void PrintToConsole() |
166 | { | 166 | { |
167 | Console.WriteLine("Class File:"); | 167 | Console.WriteLine("Class File:"); |
168 | Console.WriteLine("Major version: " + _majorVersion); | 168 | Console.WriteLine("Major version: " + _majorVersion); |
169 | Console.WriteLine("Minor version: " + _minorVersion); | 169 | Console.WriteLine("Minor version: " + _minorVersion); |
170 | Console.WriteLine("Pool size: " + _constantPoolCount); | 170 | Console.WriteLine("Pool size: " + _constantPoolCount); |
171 | 171 | ||
172 | for (int i = 0; i < _constantsPool.Count; i++) | 172 | for (int i = 0; i < _constantsPool.Count; i++) |
173 | { | 173 | { |
174 | this._constantsPool[i].Print(); | 174 | this._constantsPool[i].Print(); |
175 | } | 175 | } |
176 | 176 | ||
177 | Console.WriteLine("Access flags: " + _accessFlags); | 177 | Console.WriteLine("Access flags: " + _accessFlags); |
178 | Console.WriteLine("This class: " + _thisClass ); | 178 | Console.WriteLine("This class: " + _thisClass ); |
179 | Console.WriteLine("Super class: " + _supperClass); | 179 | Console.WriteLine("Super class: " + _supperClass); |
180 | 180 | ||
181 | for (int count = 0; count < _methodCount; count++) | 181 | for (int count = 0; count < _methodCount; count++) |
182 | { | 182 | { |
183 | Console.WriteLine(); | 183 | Console.WriteLine(); |
184 | this._methodsList[count].Print(); | 184 | this._methodsList[count].Print(); |
185 | } | 185 | } |
186 | 186 | ||
187 | Console.WriteLine("class name is " + this.mClass.Name.Value); | 187 | Console.WriteLine("class name is " + this.mClass.Name.Value); |
188 | } | 188 | } |
189 | 189 | ||
190 | public static byte[] ReadFully(Stream stream) | 190 | public static byte[] ReadFully(Stream stream) |
191 | { | 191 | { |
192 | byte[] buffer = new byte[1024]; | 192 | byte[] buffer = new byte[1024]; |
193 | using (MemoryStream ms = new MemoryStream()) | 193 | using (MemoryStream ms = new MemoryStream()) |
194 | { | 194 | { |
195 | while (true) | 195 | while (true) |
196 | { | 196 | { |
197 | int read = stream.Read(buffer, 0, buffer.Length); | 197 | int read = stream.Read(buffer, 0, buffer.Length); |
198 | if (read <= 0) | 198 | if (read <= 0) |
199 | return ms.ToArray(); | 199 | return ms.ToArray(); |
200 | ms.Write(buffer, 0, read); | 200 | ms.Write(buffer, 0, read); |
201 | } | 201 | } |
202 | } | 202 | } |
203 | } | 203 | } |
204 | 204 | ||
205 | #region nested classes | 205 | #region nested classes |
206 | public class PoolItem | 206 | public class PoolItem |
207 | { | 207 | { |
208 | public virtual void Print() | 208 | public virtual void Print() |
209 | { | 209 | { |
210 | 210 | ||
211 | } | 211 | } |
212 | } | 212 | } |
213 | 213 | ||
214 | public class PoolUtf8 : PoolItem | 214 | public class PoolUtf8 : PoolItem |
215 | { | 215 | { |
216 | public string Value = ""; | 216 | public string Value = ""; |
217 | 217 | ||
218 | public void readValue(byte[] data,ref int pointer , int length) | 218 | public void readValue(byte[] data,ref int pointer , int length) |
219 | { | 219 | { |
220 | for (int i = 0; i < length; i++) | 220 | for (int i = 0; i < length; i++) |
221 | { | 221 | { |
222 | int a =(int) data[pointer++]; | 222 | int a =(int) data[pointer++]; |
223 | if ((a & 0x80) == 0) | 223 | if ((a & 0x80) == 0) |
224 | { | 224 | { |
225 | Value = Value + (char)a; | 225 | Value = Value + (char)a; |
226 | } | 226 | } |
227 | else if ((a & 0x20) == 0) | 227 | else if ((a & 0x20) == 0) |
228 | { | 228 | { |
229 | int b = (int) data[pointer++]; | 229 | int b = (int) data[pointer++]; |
230 | Value = Value + (char)(((a & 0x1f) << 6) + (b & 0x3f)); | 230 | Value = Value + (char)(((a & 0x1f) << 6) + (b & 0x3f)); |
231 | } | 231 | } |
232 | else | 232 | else |
233 | { | 233 | { |
234 | int b = (int)data[pointer++]; | 234 | int b = (int)data[pointer++]; |
235 | int c = (int)data[pointer++]; | 235 | int c = (int)data[pointer++]; |
236 | Value = Value + (char)(((a & 0xf) << 12) + ((b & 0x3f) << 6) + (c & 0x3f)); | 236 | Value = Value + (char)(((a & 0xf) << 12) + ((b & 0x3f) << 6) + (c & 0x3f)); |
237 | } | 237 | } |
238 | } | 238 | } |
239 | } | 239 | } |
240 | 240 | ||
241 | public override void Print() | 241 | public override void Print() |
242 | { | 242 | { |
243 | Console.WriteLine("Utf8 type: " + Value); | 243 | Console.WriteLine("Utf8 type: " + Value); |
244 | } | 244 | } |
245 | } | 245 | } |
246 | 246 | ||
247 | private class PoolInt : PoolItem | 247 | private class PoolInt : PoolItem |
248 | { | 248 | { |
249 | 249 | ||
250 | } | 250 | } |
251 | 251 | ||
252 | public class PoolClass : PoolItem | 252 | public class PoolClass : PoolItem |
253 | { | 253 | { |
254 | //public string name = ""; | 254 | //public string name = ""; |
255 | public ushort namePointer = 0; | 255 | public ushort namePointer = 0; |
256 | private ClassRecord parent; | 256 | private ClassRecord parent; |
257 | public PoolUtf8 Name; | 257 | public PoolUtf8 Name; |
258 | 258 | ||
259 | public PoolClass(ClassRecord paren) | 259 | public PoolClass(ClassRecord paren) |
260 | { | 260 | { |
261 | parent = paren; | 261 | parent = paren; |
262 | } | 262 | } |
263 | 263 | ||
264 | public void readValue(byte[] data, ref int pointer) | 264 | public void readValue(byte[] data, ref int pointer) |
265 | { | 265 | { |
266 | namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); | 266 | namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); |
267 | } | 267 | } |
268 | 268 | ||
269 | public override void Print() | 269 | public override void Print() |
270 | { | 270 | { |
271 | this.Name = ((PoolUtf8)this.parent._constantsPool[namePointer - 1]); | 271 | this.Name = ((PoolUtf8)this.parent._constantsPool[namePointer - 1]); |
272 | Console.Write("Class type: " + namePointer); | 272 | Console.Write("Class type: " + namePointer); |
273 | Console.WriteLine(" // " + ((PoolUtf8)this.parent._constantsPool[namePointer - 1]).Value); | 273 | Console.WriteLine(" // " + ((PoolUtf8)this.parent._constantsPool[namePointer - 1]).Value); |
274 | 274 | ||
275 | } | 275 | } |
276 | } | 276 | } |
277 | 277 | ||
278 | public class PoolMethodRef : PoolItem | 278 | public class PoolMethodRef : PoolItem |
279 | { | 279 | { |
280 | public ushort classPointer = 0; | 280 | public ushort classPointer = 0; |
281 | public ushort nameTypePointer = 0; | 281 | public ushort nameTypePointer = 0; |
282 | public PoolNamedType mNameType; | 282 | public PoolNamedType mNameType; |
283 | public PoolClass mClass; | 283 | public PoolClass mClass; |
284 | private ClassRecord parent; | 284 | private ClassRecord parent; |
285 | 285 | ||
286 | public PoolMethodRef(ClassRecord paren) | 286 | public PoolMethodRef(ClassRecord paren) |
287 | { | 287 | { |
288 | parent = paren; | 288 | parent = paren; |
289 | } | 289 | } |
290 | 290 | ||
291 | public void readValue(byte[] data, ref int pointer) | 291 | public void readValue(byte[] data, ref int pointer) |
292 | { | 292 | { |
293 | classPointer = (ushort)((data[pointer++] << 8) + data[pointer++]); | 293 | classPointer = (ushort)((data[pointer++] << 8) + data[pointer++]); |
294 | nameTypePointer = (ushort)((data[pointer++] << 8) + data[pointer++]); | 294 | nameTypePointer = (ushort)((data[pointer++] << 8) + data[pointer++]); |
295 | } | 295 | } |
296 | 296 | ||
297 | public override void Print() | 297 | public override void Print() |
298 | { | 298 | { |
299 | this.mNameType = ((PoolNamedType)this.parent._constantsPool[nameTypePointer - 1]); | 299 | this.mNameType = ((PoolNamedType)this.parent._constantsPool[nameTypePointer - 1]); |
300 | this.mClass = ((PoolClass)this.parent._constantsPool[classPointer - 1]); | 300 | this.mClass = ((PoolClass)this.parent._constantsPool[classPointer - 1]); |
301 | Console.WriteLine("MethodRef type: " + classPointer + " , " + nameTypePointer); | 301 | Console.WriteLine("MethodRef type: " + classPointer + " , " + nameTypePointer); |
302 | } | 302 | } |
303 | } | 303 | } |
304 | 304 | ||
305 | public class PoolNamedType : PoolItem | 305 | public class PoolNamedType : PoolItem |
306 | { | 306 | { |
307 | public ushort namePointer = 0; | 307 | public ushort namePointer = 0; |
308 | public ushort typePointer = 0; | 308 | public ushort typePointer = 0; |
309 | private ClassRecord parent; | 309 | private ClassRecord parent; |
310 | public PoolUtf8 Name; | 310 | public PoolUtf8 Name; |
311 | public PoolUtf8 Type; | 311 | public PoolUtf8 Type; |
312 | 312 | ||
313 | public PoolNamedType(ClassRecord paren) | 313 | public PoolNamedType(ClassRecord paren) |
314 | { | 314 | { |
315 | parent = paren; | 315 | parent = paren; |
316 | } | 316 | } |
317 | 317 | ||
318 | public void readValue(byte[] data, ref int pointer) | 318 | public void readValue(byte[] data, ref int pointer) |
319 | { | 319 | { |
320 | namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); | 320 | namePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); |
321 | typePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); | 321 | typePointer = (ushort)((data[pointer++] << 8) + data[pointer++] ); |
322 | } | 322 | } |
323 | 323 | ||
324 | public override void Print() | 324 | public override void Print() |
325 | { | 325 | { |
326 | Name = ((PoolUtf8)this.parent._constantsPool[namePointer-1]); | 326 | Name = ((PoolUtf8)this.parent._constantsPool[namePointer-1]); |
327 | Type = ((PoolUtf8)this.parent._constantsPool[typePointer-1]); | 327 | Type = ((PoolUtf8)this.parent._constantsPool[typePointer-1]); |
328 | Console.Write("Named type: " + namePointer + " , " + typePointer ); | 328 | Console.Write("Named type: " + namePointer + " , " + typePointer ); |
329 | Console.WriteLine(" // "+ ((PoolUtf8)this.parent._constantsPool[namePointer-1]).Value); | 329 | Console.WriteLine(" // "+ ((PoolUtf8)this.parent._constantsPool[namePointer-1]).Value); |
330 | } | 330 | } |
331 | } | 331 | } |
332 | 332 | ||
333 | //*********************** | 333 | //*********************** |
334 | public class MethodInfo | 334 | public class MethodInfo |
335 | { | 335 | { |
336 | public ushort AccessFlags = 0; | 336 | public ushort AccessFlags = 0; |
337 | public ushort NameIndex = 0; | 337 | public ushort NameIndex = 0; |
338 | public string Name = ""; | 338 | public string Name = ""; |
339 | public ushort DescriptorIndex = 0; | 339 | public ushort DescriptorIndex = 0; |
340 | public ushort AttributeCount = 0; | 340 | public ushort AttributeCount = 0; |
341 | public List<MethodAttribute> Attributes = new List<MethodAttribute>(); | 341 | public List<MethodAttribute> Attributes = new List<MethodAttribute>(); |
342 | private ClassRecord parent; | 342 | private ClassRecord parent; |
343 | public int CodePointer = 0; | 343 | public int CodePointer = 0; |
344 | 344 | ||
345 | public MethodInfo(ClassRecord paren) | 345 | public MethodInfo(ClassRecord paren) |
346 | { | 346 | { |
347 | parent = paren; | 347 | parent = paren; |
348 | } | 348 | } |
349 | 349 | ||
350 | public void AddMethodCode(MethodMemory memory) | 350 | public void AddMethodCode(MethodMemory memory) |
351 | { | 351 | { |
352 | Array.Copy(this.Attributes[0].Code, 0, memory.MethodBuffer, memory.NextMethodPC, this.Attributes[0].Code.Length); | 352 | Array.Copy(this.Attributes[0].Code, 0, memory.MethodBuffer, memory.NextMethodPC, this.Attributes[0].Code.Length); |
353 | memory.Methodcount++; | 353 | memory.Methodcount++; |
354 | this.CodePointer = memory.NextMethodPC; | 354 | this.CodePointer = memory.NextMethodPC; |
355 | memory.NextMethodPC += this.Attributes[0].Code.Length; | 355 | memory.NextMethodPC += this.Attributes[0].Code.Length; |
356 | } | 356 | } |
357 | 357 | ||
358 | public void ReadData(byte[] data, ref int pointer) | 358 | public void ReadData(byte[] data, ref int pointer) |
359 | { | 359 | { |
360 | AccessFlags = (ushort)((data[pointer++] << 8) + data[pointer++]); | 360 | AccessFlags = (ushort)((data[pointer++] << 8) + data[pointer++]); |
361 | NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); | 361 | NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); |
362 | DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); | 362 | DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); |
363 | AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]); | 363 | AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]); |
364 | for(int i =0; i< AttributeCount; i++) | 364 | for(int i =0; i< AttributeCount; i++) |
365 | { | 365 | { |
366 | MethodAttribute attri = new MethodAttribute(this.parent); | 366 | MethodAttribute attri = new MethodAttribute(this.parent); |
367 | attri.ReadData(data, ref pointer); | 367 | attri.ReadData(data, ref pointer); |
368 | this.Attributes.Add(attri); | 368 | this.Attributes.Add(attri); |
369 | } | 369 | } |
370 | } | 370 | } |
371 | 371 | ||
372 | public void Print() | 372 | public void Print() |
373 | { | 373 | { |
374 | Console.WriteLine("Method Info Struct: "); | 374 | Console.WriteLine("Method Info Struct: "); |
375 | Console.WriteLine("AccessFlags: " + AccessFlags); | 375 | Console.WriteLine("AccessFlags: " + AccessFlags); |
376 | Console.WriteLine("NameIndex: " + NameIndex +" // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value); | 376 | Console.WriteLine("NameIndex: " + NameIndex +" // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value); |
377 | Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[DescriptorIndex-1]).Value); | 377 | Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[DescriptorIndex-1]).Value); |
378 | Console.WriteLine("Attribute Count:" + AttributeCount); | 378 | Console.WriteLine("Attribute Count:" + AttributeCount); |
379 | for (int i = 0; i < AttributeCount; i++) | 379 | for (int i = 0; i < AttributeCount; i++) |
380 | { | 380 | { |
381 | this.Attributes[i].Print(); | 381 | this.Attributes[i].Print(); |
382 | } | 382 | } |
383 | } | 383 | } |
384 | 384 | ||
385 | public class MethodAttribute | 385 | public class MethodAttribute |
386 | { | 386 | { |
387 | public ushort NameIndex = 0; | 387 | public ushort NameIndex = 0; |
388 | public string Name = ""; | 388 | public string Name = ""; |
389 | public Int32 Length = 0; | 389 | public Int32 Length = 0; |
390 | //for now only support code attribute | 390 | //for now only support code attribute |
391 | public ushort MaxStack = 0; | 391 | public ushort MaxStack = 0; |
392 | public ushort MaxLocals = 0; | 392 | public ushort MaxLocals = 0; |
393 | public Int32 CodeLength = 0; | 393 | public Int32 CodeLength = 0; |
394 | public byte[] Code; | 394 | public byte[] Code; |
395 | public ushort ExceptionTableLength = 0; | 395 | public ushort ExceptionTableLength = 0; |
396 | public ushort SubAttributeCount = 0; | 396 | public ushort SubAttributeCount = 0; |
397 | public List<SubAttribute> SubAttributes = new List<SubAttribute>(); | 397 | public List<SubAttribute> SubAttributes = new List<SubAttribute>(); |
398 | private ClassRecord parent; | 398 | private ClassRecord parent; |
399 | 399 | ||
400 | public MethodAttribute(ClassRecord paren) | 400 | public MethodAttribute(ClassRecord paren) |
401 | { | 401 | { |
402 | parent = paren; | 402 | parent = paren; |
403 | } | 403 | } |
404 | 404 | ||
405 | public void ReadData(byte[] data, ref int pointer) | 405 | public void ReadData(byte[] data, ref int pointer) |
406 | { | 406 | { |
407 | NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); | 407 | NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); |
408 | Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); | 408 | Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); |
409 | MaxStack = (ushort)((data[pointer++] << 8) + data[pointer++]); | 409 | MaxStack = (ushort)((data[pointer++] << 8) + data[pointer++]); |
410 | MaxLocals = (ushort)((data[pointer++] << 8) + data[pointer++]); | 410 | MaxLocals = (ushort)((data[pointer++] << 8) + data[pointer++]); |
411 | CodeLength = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); | 411 | CodeLength = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); |
412 | Code = new byte[CodeLength]; | 412 | Code = new byte[CodeLength]; |
413 | for (int i = 0; i < CodeLength; i++) | 413 | for (int i = 0; i < CodeLength; i++) |
414 | { | 414 | { |
415 | Code[i] = data[pointer++]; | 415 | Code[i] = data[pointer++]; |
416 | } | 416 | } |
417 | ExceptionTableLength = (ushort)((data[pointer++] << 8) + data[pointer++]); | 417 | ExceptionTableLength = (ushort)((data[pointer++] << 8) + data[pointer++]); |
418 | SubAttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]); | 418 | SubAttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]); |
419 | for (int i = 0; i < SubAttributeCount; i++) | 419 | for (int i = 0; i < SubAttributeCount; i++) |
420 | { | 420 | { |
421 | SubAttribute subAttri = new SubAttribute(this.parent); | 421 | SubAttribute subAttri = new SubAttribute(this.parent); |
422 | subAttri.ReadData(data, ref pointer); | 422 | subAttri.ReadData(data, ref pointer); |
423 | this.SubAttributes.Add(subAttri); | 423 | this.SubAttributes.Add(subAttri); |
424 | } | 424 | } |
425 | } | 425 | } |
426 | 426 | ||
427 | public void Print() | 427 | public void Print() |
428 | { | 428 | { |
429 | Console.WriteLine("Method Attribute: "); | 429 | Console.WriteLine("Method Attribute: "); |
430 | Console.WriteLine("Name Index: " + NameIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value); | 430 | Console.WriteLine("Name Index: " + NameIndex + " // "+ ((PoolUtf8)this.parent._constantsPool[NameIndex-1]).Value); |
431 | Console.WriteLine("Length: " + Length); | 431 | Console.WriteLine("Length: " + Length); |
432 | Console.WriteLine("MaxStack: " + MaxStack); | 432 | Console.WriteLine("MaxStack: " + MaxStack); |
433 | Console.WriteLine("MaxLocals: " + MaxLocals); | 433 | Console.WriteLine("MaxLocals: " + MaxLocals); |
434 | Console.WriteLine("CodeLength: " + CodeLength); | 434 | Console.WriteLine("CodeLength: " + CodeLength); |
435 | for (int i = 0; i < Code.Length; i++) | 435 | for (int i = 0; i < Code.Length; i++) |
436 | { | 436 | { |
437 | Console.WriteLine("OpCode #" + i + " is: " + Code[i]); | 437 | Console.WriteLine("OpCode #" + i + " is: " + Code[i]); |
438 | } | 438 | } |
439 | Console.WriteLine("SubAttributes: " + SubAttributeCount); | 439 | Console.WriteLine("SubAttributes: " + SubAttributeCount); |
440 | for (int i = 0; i < SubAttributeCount; i++) | 440 | for (int i = 0; i < SubAttributeCount; i++) |
441 | { | 441 | { |
442 | this.SubAttributes[i].Print(); | 442 | this.SubAttributes[i].Print(); |
443 | } | 443 | } |
444 | } | 444 | } |
445 | 445 | ||
446 | public class SubAttribute | 446 | public class SubAttribute |
447 | { | 447 | { |
448 | public ushort NameIndex = 0; | 448 | public ushort NameIndex = 0; |
449 | public string Name = ""; | 449 | public string Name = ""; |
450 | public Int32 Length = 0; | 450 | public Int32 Length = 0; |
451 | public byte[] Data; | 451 | public byte[] Data; |
452 | private ClassRecord parent; | 452 | private ClassRecord parent; |
453 | 453 | ||
454 | public SubAttribute(ClassRecord paren) | 454 | public SubAttribute(ClassRecord paren) |
455 | { | 455 | { |
456 | parent = paren; | 456 | parent = paren; |
457 | } | 457 | } |
458 | 458 | ||
459 | public void ReadData(byte[] data, ref int pointer) | 459 | public void ReadData(byte[] data, ref int pointer) |
460 | { | 460 | { |
461 | NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); | 461 | NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); |
462 | Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); | 462 | Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); |
463 | Data = new byte[Length]; | 463 | Data = new byte[Length]; |
464 | for (int i = 0; i < Length; i++) | 464 | for (int i = 0; i < Length; i++) |
465 | { | 465 | { |
466 | Data[i] = data[pointer++]; | 466 | Data[i] = data[pointer++]; |
467 | } | 467 | } |
468 | } | 468 | } |
469 | 469 | ||
470 | public void Print() | 470 | public void Print() |
471 | { | 471 | { |
472 | Console.WriteLine("SubAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value); | 472 | Console.WriteLine("SubAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent._constantsPool[NameIndex - 1]).Value); |
473 | } | 473 | } |
474 | 474 | ||
475 | } | 475 | } |
476 | } | 476 | } |
477 | 477 | ||
478 | } | 478 | } |
479 | private class InterfaceInfo | 479 | private class InterfaceInfo |
480 | { | 480 | { |
481 | public void ReadData(byte[] data, ref int i) | 481 | public void ReadData(byte[] data, ref int i) |
482 | { | 482 | { |
483 | 483 | ||
484 | } | 484 | } |
485 | } | 485 | } |
486 | private class FieldInfo | 486 | private class FieldInfo |
487 | { | 487 | { |
488 | public void ReadData(byte[] data, ref int i) | 488 | public void ReadData(byte[] data, ref int i) |
489 | { | 489 | { |
490 | 490 | ||
491 | } | 491 | } |
492 | } | 492 | } |
493 | private class AttributeInfo | 493 | private class AttributeInfo |
494 | { | 494 | { |
495 | public void ReadData(byte[] data, ref int i) | 495 | public void ReadData(byte[] data, ref int i) |
496 | { | 496 | { |
497 | 497 | ||
498 | } | 498 | } |
499 | } | 499 | } |
500 | #endregion | 500 | #endregion |
501 | 501 | ||
502 | } | 502 | } |
503 | } | 503 | } |