aboutsummaryrefslogtreecommitdiffstatshomepage
path: root/OpenSim/Region/ExtensionsScriptModule/Engines/JVMEngine/JVM/ClassRecord.cs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--OpenSim/Region/ExtensionsScriptModule/Engines/JVMEngine/JVM/ClassRecord.cs1278
1 files changed, 639 insertions, 639 deletions
diff --git a/OpenSim/Region/ExtensionsScriptModule/Engines/JVMEngine/JVM/ClassRecord.cs b/OpenSim/Region/ExtensionsScriptModule/Engines/JVMEngine/JVM/ClassRecord.cs
index 348a452..5c3629c 100644
--- a/OpenSim/Region/ExtensionsScriptModule/Engines/JVMEngine/JVM/ClassRecord.cs
+++ b/OpenSim/Region/ExtensionsScriptModule/Engines/JVMEngine/JVM/ClassRecord.cs
@@ -1,640 +1,640 @@
1/* 1/*
2* Copyright (c) Contributors, http://opensimulator.org/ 2* Copyright (c) Contributors, http://opensimulator.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*/
28using System; 28using System;
29using System.IO; 29using System.IO;
30using System.Collections.Generic; 30using System.Collections.Generic;
31using System.Text; 31using System.Text;
32using OpenSim.Region.ExtensionsScriptModule.JVMEngine.Types; 32using OpenSim.Region.ExtensionsScriptModule.JVMEngine.Types;
33using OpenSim.Region.ExtensionsScriptModule.JVMEngine.Types.PrimitiveTypes; 33using OpenSim.Region.ExtensionsScriptModule.JVMEngine.Types.PrimitiveTypes;
34 34
35namespace OpenSim.Region.ExtensionsScriptModule.JVMEngine.JVM 35namespace OpenSim.Region.ExtensionsScriptModule.JVMEngine.JVM
36{ 36{
37 public class ClassRecord 37 public class ClassRecord
38 { 38 {
39 private ushort m_majorVersion; 39 private ushort m_majorVersion;
40 private ushort m_minorVersion; 40 private ushort m_minorVersion;
41 private ushort m_constantPoolCount; 41 private ushort m_constantPoolCount;
42 private ushort m_accessFlags; 42 private ushort m_accessFlags;
43 private ushort m_thisClass; 43 private ushort m_thisClass;
44 private ushort m_supperClass; 44 private ushort m_supperClass;
45 private ushort m_interfaceCount; 45 private ushort m_interfaceCount;
46 private ushort m_fieldCount; 46 private ushort m_fieldCount;
47 private ushort m_methodCount; 47 private ushort m_methodCount;
48 //private ushort _attributeCount; 48 //private ushort _attributeCount;
49 //private string _name; 49 //private string _name;
50 public Dictionary<string, BaseType> StaticFields = new Dictionary<string, BaseType>(); 50 public Dictionary<string, BaseType> StaticFields = new Dictionary<string, BaseType>();
51 public PoolClass MClass; 51 public PoolClass MClass;
52 52
53 public List<PoolItem> m_constantsPool = new List<PoolItem>(); 53 public List<PoolItem> m_constantsPool = new List<PoolItem>();
54 private List<MethodInfo> m_methodsList = new List<MethodInfo>(); 54 private List<MethodInfo> m_methodsList = new List<MethodInfo>();
55 private List<FieldInfo> m_fieldList = new List<FieldInfo>(); 55 private List<FieldInfo> m_fieldList = new List<FieldInfo>();
56 56
57 public ClassRecord() 57 public ClassRecord()
58 { 58 {
59 59
60 } 60 }
61 61
62 public ClassInstance CreateNewInstance() 62 public ClassInstance CreateNewInstance()
63 { 63 {
64 ClassInstance classInst = new ClassInstance(); 64 ClassInstance classInst = new ClassInstance();
65 classInst.ClassRec = this; 65 classInst.ClassRec = this;
66 //TODO: set fields 66 //TODO: set fields
67 67
68 return classInst; 68 return classInst;
69 } 69 }
70 70
71 public void LoadClassFromFile(string fileName) 71 public void LoadClassFromFile(string fileName)
72 { 72 {
73 Console.WriteLine("loading script " + fileName); 73 Console.WriteLine("loading script " + fileName);
74 FileStream fs = File.OpenRead(fileName); 74 FileStream fs = File.OpenRead(fileName);
75 this.LoadClassFromBytes(ReadFully(fs)); 75 this.LoadClassFromBytes(ReadFully(fs));
76 fs.Close(); 76 fs.Close();
77 } 77 }
78 78
79 public void LoadClassFromBytes(byte[] data) 79 public void LoadClassFromBytes(byte[] data)
80 { 80 {
81 int i = 0; 81 int i = 0;
82 i += 4; 82 i += 4;
83 m_minorVersion = (ushort)((data[i++] << 8) + data[i++]); 83 m_minorVersion = (ushort)((data[i++] << 8) + data[i++]);
84 m_majorVersion = (ushort)((data[i++] << 8) + data[i++]); 84 m_majorVersion = (ushort)((data[i++] << 8) + data[i++]);
85 m_constantPoolCount = (ushort)((data[i++] << 8) + data[i++]); 85 m_constantPoolCount = (ushort)((data[i++] << 8) + data[i++]);
86 Console.WriteLine("there should be " + m_constantPoolCount + " items in the pool"); 86 Console.WriteLine("there should be " + m_constantPoolCount + " items in the pool");
87 for (int count = 0; count < (m_constantPoolCount - 1); count++) 87 for (int count = 0; count < (m_constantPoolCount - 1); count++)
88 { 88 {
89 //read in the constant pool 89 //read in the constant pool
90 byte pooltype = data[i++]; 90 byte pooltype = data[i++];
91 Console.WriteLine("#" + count + ": new constant type = " + pooltype); 91 Console.WriteLine("#" + count + ": new constant type = " + pooltype);
92 //Console.WriteLine("start position is: " + i); 92 //Console.WriteLine("start position is: " + i);
93 switch (pooltype) 93 switch (pooltype)
94 { 94 {
95 case 1: //Utf8 95 case 1: //Utf8
96 ushort uLength = (ushort)((data[i++] << 8) + data[i++]); 96 ushort uLength = (ushort)((data[i++] << 8) + data[i++]);
97 97
98 // Console.WriteLine("new utf8 type, length is " + uLength); 98 // Console.WriteLine("new utf8 type, length is " + uLength);
99 PoolUtf8 utf8 = new PoolUtf8(); 99 PoolUtf8 utf8 = new PoolUtf8();
100 utf8.readValue(data, ref i, uLength); 100 utf8.readValue(data, ref i, uLength);
101 this.m_constantsPool.Add(utf8); 101 this.m_constantsPool.Add(utf8);
102 break; 102 break;
103 case 3: //Int 103 case 3: //Int
104 break; 104 break;
105 case 4: //Float 105 case 4: //Float
106 break; 106 break;
107 case 7: //Class 107 case 7: //Class
108 PoolClass pClass = new PoolClass(this); 108 PoolClass pClass = new PoolClass(this);
109 pClass.readValue(data, ref i); 109 pClass.readValue(data, ref i);
110 this.m_constantsPool.Add(pClass); 110 this.m_constantsPool.Add(pClass);
111 break; 111 break;
112 case 9: //FieldRef 112 case 9: //FieldRef
113 PoolFieldRef pField = new PoolFieldRef(this); 113 PoolFieldRef pField = new PoolFieldRef(this);
114 pField.readValue(data, ref i); 114 pField.readValue(data, ref i);
115 this.m_constantsPool.Add(pField); 115 this.m_constantsPool.Add(pField);
116 break; 116 break;
117 case 10: //Method 117 case 10: //Method
118 PoolMethodRef pMeth = new PoolMethodRef(this); 118 PoolMethodRef pMeth = new PoolMethodRef(this);
119 pMeth.readValue(data, ref i); 119 pMeth.readValue(data, ref i);
120 this.m_constantsPool.Add(pMeth); 120 this.m_constantsPool.Add(pMeth);
121 break; 121 break;
122 case 12: //NamedType 122 case 12: //NamedType
123 PoolNamedType pNamed = new PoolNamedType(this); 123 PoolNamedType pNamed = new PoolNamedType(this);
124 pNamed.readValue(data, ref i); 124 pNamed.readValue(data, ref i);
125 this.m_constantsPool.Add(pNamed); 125 this.m_constantsPool.Add(pNamed);
126 break; 126 break;
127 } 127 }
128 } 128 }
129 129
130 m_accessFlags = (ushort)((data[i++] << 8) + data[i++]); 130 m_accessFlags = (ushort)((data[i++] << 8) + data[i++]);
131 m_thisClass = (ushort)((data[i++] << 8) + data[i++]); 131 m_thisClass = (ushort)((data[i++] << 8) + data[i++]);
132 m_supperClass = (ushort)((data[i++] << 8) + data[i++]); 132 m_supperClass = (ushort)((data[i++] << 8) + data[i++]);
133 133
134 if (this.m_constantsPool[this.m_thisClass - 1] is PoolClass) 134 if (this.m_constantsPool[this.m_thisClass - 1] is PoolClass)
135 { 135 {
136 this.MClass = ((PoolClass)this.m_constantsPool[this.m_thisClass - 1]); 136 this.MClass = ((PoolClass)this.m_constantsPool[this.m_thisClass - 1]);
137 } 137 }
138 138
139 m_interfaceCount = (ushort)((data[i++] << 8) + data[i++]); 139 m_interfaceCount = (ushort)((data[i++] << 8) + data[i++]);
140 //should now read in the info for each interface 140 //should now read in the info for each interface
141 141
142 m_fieldCount = (ushort)((data[i++] << 8) + data[i++]); 142 m_fieldCount = (ushort)((data[i++] << 8) + data[i++]);
143 //should now read in the info for each field 143 //should now read in the info for each field
144 for (int count = 0; count < m_fieldCount; count++) 144 for (int count = 0; count < m_fieldCount; count++)
145 { 145 {
146 FieldInfo fieldInf = new FieldInfo(this); 146 FieldInfo fieldInf = new FieldInfo(this);
147 fieldInf.ReadData(data, ref i); 147 fieldInf.ReadData(data, ref i);
148 this.m_fieldList.Add(fieldInf); 148 this.m_fieldList.Add(fieldInf);
149 } 149 }
150 150
151 m_methodCount = (ushort)((data[i++] << 8) + data[i++]); 151 m_methodCount = (ushort)((data[i++] << 8) + data[i++]);
152 for (int count = 0; count < m_methodCount; count++) 152 for (int count = 0; count < m_methodCount; count++)
153 { 153 {
154 MethodInfo methInf = new MethodInfo(this); 154 MethodInfo methInf = new MethodInfo(this);
155 methInf.ReadData(data, ref i); 155 methInf.ReadData(data, ref i);
156 this.m_methodsList.Add(methInf); 156 this.m_methodsList.Add(methInf);
157 } 157 }
158 } 158 }
159 159
160 public void AddMethodsToMemory(MethodMemory memory) 160 public void AddMethodsToMemory(MethodMemory memory)
161 { 161 {
162 for (int count = 0; count < m_methodCount; count++) 162 for (int count = 0; count < m_methodCount; count++)
163 { 163 {
164 this.m_methodsList[count].AddMethodCode(memory); 164 this.m_methodsList[count].AddMethodCode(memory);
165 } 165 }
166 } 166 }
167 167
168 public bool StartMethod(Thread thread, string methodName) 168 public bool StartMethod(Thread thread, string methodName)
169 { 169 {
170 for (int count = 0; count < m_methodCount; count++) 170 for (int count = 0; count < m_methodCount; count++)
171 { 171 {
172 if (this.m_constantsPool[this.m_methodsList[count].NameIndex - 1] is PoolUtf8) 172 if (this.m_constantsPool[this.m_methodsList[count].NameIndex - 1] is PoolUtf8)
173 { 173 {
174 if (((PoolUtf8)this.m_constantsPool[this.m_methodsList[count].NameIndex - 1]).Value == methodName) 174 if (((PoolUtf8)this.m_constantsPool[this.m_methodsList[count].NameIndex - 1]).Value == methodName)
175 { 175 {
176 //Console.WriteLine("found method: " + ((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex - 1]).Value); 176 //Console.WriteLine("found method: " + ((PoolUtf8)this._constantsPool[this._methodsList[count].NameIndex - 1]).Value);
177 thread.SetPC(this.m_methodsList[count].CodePointer); 177 thread.SetPC(this.m_methodsList[count].CodePointer);
178 return true; 178 return true;
179 } 179 }
180 } 180 }
181 } 181 }
182 return false; 182 return false;
183 } 183 }
184 184
185 public void PrintToConsole() 185 public void PrintToConsole()
186 { 186 {
187 Console.WriteLine("Class File:"); 187 Console.WriteLine("Class File:");
188 Console.WriteLine("Major version: " + m_majorVersion); 188 Console.WriteLine("Major version: " + m_majorVersion);
189 Console.WriteLine("Minor version: " + m_minorVersion); 189 Console.WriteLine("Minor version: " + m_minorVersion);
190 Console.WriteLine("Pool size: " + m_constantPoolCount); 190 Console.WriteLine("Pool size: " + m_constantPoolCount);
191 191
192 for (int i = 0; i < m_constantsPool.Count; i++) 192 for (int i = 0; i < m_constantsPool.Count; i++)
193 { 193 {
194 this.m_constantsPool[i].Print(); 194 this.m_constantsPool[i].Print();
195 } 195 }
196 196
197 Console.WriteLine("Access flags: " + m_accessFlags); 197 Console.WriteLine("Access flags: " + m_accessFlags);
198 Console.WriteLine("This class: " + m_thisClass); 198 Console.WriteLine("This class: " + m_thisClass);
199 Console.WriteLine("Super class: " + m_supperClass); 199 Console.WriteLine("Super class: " + m_supperClass);
200 200
201 for (int count = 0; count < m_fieldCount; count++) 201 for (int count = 0; count < m_fieldCount; count++)
202 { 202 {
203 Console.WriteLine(); 203 Console.WriteLine();
204 this.m_fieldList[count].Print(); 204 this.m_fieldList[count].Print();
205 } 205 }
206 206
207 for (int count = 0; count < m_methodCount; count++) 207 for (int count = 0; count < m_methodCount; count++)
208 { 208 {
209 Console.WriteLine(); 209 Console.WriteLine();
210 this.m_methodsList[count].Print(); 210 this.m_methodsList[count].Print();
211 } 211 }
212 212
213 Console.WriteLine("class name is " + this.MClass.Name.Value); 213 Console.WriteLine("class name is " + this.MClass.Name.Value);
214 } 214 }
215 215
216 public static byte[] ReadFully(Stream stream) 216 public static byte[] ReadFully(Stream stream)
217 { 217 {
218 byte[] buffer = new byte[1024]; 218 byte[] buffer = new byte[1024];
219 using (MemoryStream ms = new MemoryStream()) 219 using (MemoryStream ms = new MemoryStream())
220 { 220 {
221 while (true) 221 while (true)
222 { 222 {
223 int read = stream.Read(buffer, 0, buffer.Length); 223 int read = stream.Read(buffer, 0, buffer.Length);
224 if (read <= 0) 224 if (read <= 0)
225 return ms.ToArray(); 225 return ms.ToArray();
226 ms.Write(buffer, 0, read); 226 ms.Write(buffer, 0, read);
227 } 227 }
228 } 228 }
229 } 229 }
230 230
231 #region nested classes 231 #region nested classes
232 public class PoolItem 232 public class PoolItem
233 { 233 {
234 public virtual void Print() 234 public virtual void Print()
235 { 235 {
236 236
237 } 237 }
238 } 238 }
239 239
240 public class PoolUtf8 : PoolItem 240 public class PoolUtf8 : PoolItem
241 { 241 {
242 public string Value = ""; 242 public string Value = "";
243 243
244 public void readValue(byte[] data, ref int pointer, int length) 244 public void readValue(byte[] data, ref int pointer, int length)
245 { 245 {
246 for (int i = 0; i < length; i++) 246 for (int i = 0; i < length; i++)
247 { 247 {
248 int a = (int)data[pointer++]; 248 int a = (int)data[pointer++];
249 if ((a & 0x80) == 0) 249 if ((a & 0x80) == 0)
250 { 250 {
251 Value = Value + (char)a; 251 Value = Value + (char)a;
252 } 252 }
253 else if ((a & 0x20) == 0) 253 else if ((a & 0x20) == 0)
254 { 254 {
255 int b = (int)data[pointer++]; 255 int b = (int)data[pointer++];
256 Value = Value + (char)(((a & 0x1f) << 6) + (b & 0x3f)); 256 Value = Value + (char)(((a & 0x1f) << 6) + (b & 0x3f));
257 } 257 }
258 else 258 else
259 { 259 {
260 int b = (int)data[pointer++]; 260 int b = (int)data[pointer++];
261 int c = (int)data[pointer++]; 261 int c = (int)data[pointer++];
262 Value = Value + (char)(((a & 0xf) << 12) + ((b & 0x3f) << 6) + (c & 0x3f)); 262 Value = Value + (char)(((a & 0xf) << 12) + ((b & 0x3f) << 6) + (c & 0x3f));
263 } 263 }
264 } 264 }
265 } 265 }
266 266
267 public override void Print() 267 public override void Print()
268 { 268 {
269 Console.WriteLine("Utf8 type: " + Value); 269 Console.WriteLine("Utf8 type: " + Value);
270 } 270 }
271 } 271 }
272 272
273 private class PoolInt : PoolItem 273 private class PoolInt : PoolItem
274 { 274 {
275 275
276 } 276 }
277 277
278 public class PoolClass : PoolItem 278 public class PoolClass : PoolItem
279 { 279 {
280 //public string name = ""; 280 //public string name = "";
281 public ushort namePointer = 0; 281 public ushort namePointer = 0;
282 private ClassRecord parent; 282 private ClassRecord parent;
283 public PoolUtf8 Name; 283 public PoolUtf8 Name;
284 284
285 public PoolClass(ClassRecord paren) 285 public PoolClass(ClassRecord paren)
286 { 286 {
287 parent = paren; 287 parent = paren;
288 } 288 }
289 289
290 public void readValue(byte[] data, ref int pointer) 290 public void readValue(byte[] data, ref int pointer)
291 { 291 {
292 namePointer = (ushort)((data[pointer++] << 8) + data[pointer++]); 292 namePointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
293 } 293 }
294 294
295 public override void Print() 295 public override void Print()
296 { 296 {
297 this.Name = ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]); 297 this.Name = ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]);
298 Console.Write("Class type: " + namePointer); 298 Console.Write("Class type: " + namePointer);
299 Console.WriteLine(" // " + ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]).Value); 299 Console.WriteLine(" // " + ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]).Value);
300 300
301 } 301 }
302 } 302 }
303 303
304 public class PoolFieldRef : PoolItem 304 public class PoolFieldRef : PoolItem
305 { 305 {
306 public ushort classPointer = 0; 306 public ushort classPointer = 0;
307 public ushort nameTypePointer = 0; 307 public ushort nameTypePointer = 0;
308 public PoolNamedType mNameType; 308 public PoolNamedType mNameType;
309 public PoolClass mClass; 309 public PoolClass mClass;
310 private ClassRecord parent; 310 private ClassRecord parent;
311 311
312 public PoolFieldRef(ClassRecord paren) 312 public PoolFieldRef(ClassRecord paren)
313 { 313 {
314 parent = paren; 314 parent = paren;
315 } 315 }
316 316
317 public void readValue(byte[] data, ref int pointer) 317 public void readValue(byte[] data, ref int pointer)
318 { 318 {
319 classPointer = (ushort)((data[pointer++] << 8) + data[pointer++]); 319 classPointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
320 nameTypePointer = (ushort)((data[pointer++] << 8) + data[pointer++]); 320 nameTypePointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
321 } 321 }
322 322
323 public override void Print() 323 public override void Print()
324 { 324 {
325 this.mNameType = ((PoolNamedType)this.parent.m_constantsPool[nameTypePointer - 1]); 325 this.mNameType = ((PoolNamedType)this.parent.m_constantsPool[nameTypePointer - 1]);
326 this.mClass = ((PoolClass)this.parent.m_constantsPool[classPointer - 1]); 326 this.mClass = ((PoolClass)this.parent.m_constantsPool[classPointer - 1]);
327 Console.WriteLine("FieldRef type: " + classPointer + " , " + nameTypePointer); 327 Console.WriteLine("FieldRef type: " + classPointer + " , " + nameTypePointer);
328 } 328 }
329 } 329 }
330 330
331 public class PoolMethodRef : PoolItem 331 public class PoolMethodRef : PoolItem
332 { 332 {
333 public ushort classPointer = 0; 333 public ushort classPointer = 0;
334 public ushort nameTypePointer = 0; 334 public ushort nameTypePointer = 0;
335 public PoolNamedType mNameType; 335 public PoolNamedType mNameType;
336 public PoolClass mClass; 336 public PoolClass mClass;
337 private ClassRecord parent; 337 private ClassRecord parent;
338 338
339 public PoolMethodRef(ClassRecord paren) 339 public PoolMethodRef(ClassRecord paren)
340 { 340 {
341 parent = paren; 341 parent = paren;
342 } 342 }
343 343
344 public void readValue(byte[] data, ref int pointer) 344 public void readValue(byte[] data, ref int pointer)
345 { 345 {
346 classPointer = (ushort)((data[pointer++] << 8) + data[pointer++]); 346 classPointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
347 nameTypePointer = (ushort)((data[pointer++] << 8) + data[pointer++]); 347 nameTypePointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
348 } 348 }
349 349
350 public override void Print() 350 public override void Print()
351 { 351 {
352 this.mNameType = ((PoolNamedType)this.parent.m_constantsPool[nameTypePointer - 1]); 352 this.mNameType = ((PoolNamedType)this.parent.m_constantsPool[nameTypePointer - 1]);
353 this.mClass = ((PoolClass)this.parent.m_constantsPool[classPointer - 1]); 353 this.mClass = ((PoolClass)this.parent.m_constantsPool[classPointer - 1]);
354 Console.WriteLine("MethodRef type: " + classPointer + " , " + nameTypePointer); 354 Console.WriteLine("MethodRef type: " + classPointer + " , " + nameTypePointer);
355 } 355 }
356 } 356 }
357 357
358 public class PoolNamedType : PoolItem 358 public class PoolNamedType : PoolItem
359 { 359 {
360 public ushort namePointer = 0; 360 public ushort namePointer = 0;
361 public ushort typePointer = 0; 361 public ushort typePointer = 0;
362 private ClassRecord parent; 362 private ClassRecord parent;
363 public PoolUtf8 Name; 363 public PoolUtf8 Name;
364 public PoolUtf8 Type; 364 public PoolUtf8 Type;
365 365
366 public PoolNamedType(ClassRecord paren) 366 public PoolNamedType(ClassRecord paren)
367 { 367 {
368 parent = paren; 368 parent = paren;
369 } 369 }
370 370
371 public void readValue(byte[] data, ref int pointer) 371 public void readValue(byte[] data, ref int pointer)
372 { 372 {
373 namePointer = (ushort)((data[pointer++] << 8) + data[pointer++]); 373 namePointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
374 typePointer = (ushort)((data[pointer++] << 8) + data[pointer++]); 374 typePointer = (ushort)((data[pointer++] << 8) + data[pointer++]);
375 } 375 }
376 376
377 public override void Print() 377 public override void Print()
378 { 378 {
379 Name = ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]); 379 Name = ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]);
380 Type = ((PoolUtf8)this.parent.m_constantsPool[typePointer - 1]); 380 Type = ((PoolUtf8)this.parent.m_constantsPool[typePointer - 1]);
381 Console.Write("Named type: " + namePointer + " , " + typePointer); 381 Console.Write("Named type: " + namePointer + " , " + typePointer);
382 Console.WriteLine(" // " + ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]).Value); 382 Console.WriteLine(" // " + ((PoolUtf8)this.parent.m_constantsPool[namePointer - 1]).Value);
383 } 383 }
384 } 384 }
385 385
386 //*********************** 386 //***********************
387 public class MethodInfo 387 public class MethodInfo
388 { 388 {
389 public ushort AccessFlags = 0; 389 public ushort AccessFlags = 0;
390 public ushort NameIndex = 0; 390 public ushort NameIndex = 0;
391 public string Name = ""; 391 public string Name = "";
392 public ushort DescriptorIndex = 0; 392 public ushort DescriptorIndex = 0;
393 public ushort AttributeCount = 0; 393 public ushort AttributeCount = 0;
394 public List<MethodAttribute> Attributes = new List<MethodAttribute>(); 394 public List<MethodAttribute> Attributes = new List<MethodAttribute>();
395 private ClassRecord parent; 395 private ClassRecord parent;
396 public int CodePointer = 0; 396 public int CodePointer = 0;
397 397
398 public MethodInfo(ClassRecord paren) 398 public MethodInfo(ClassRecord paren)
399 { 399 {
400 parent = paren; 400 parent = paren;
401 } 401 }
402 402
403 public void AddMethodCode(MethodMemory memory) 403 public void AddMethodCode(MethodMemory memory)
404 { 404 {
405 Array.Copy(this.Attributes[0].Code, 0, memory.MethodBuffer, memory.NextMethodPC, this.Attributes[0].Code.Length); 405 Array.Copy(this.Attributes[0].Code, 0, memory.MethodBuffer, memory.NextMethodPC, this.Attributes[0].Code.Length);
406 memory.Methodcount++; 406 memory.Methodcount++;
407 this.CodePointer = memory.NextMethodPC; 407 this.CodePointer = memory.NextMethodPC;
408 memory.NextMethodPC += this.Attributes[0].Code.Length; 408 memory.NextMethodPC += this.Attributes[0].Code.Length;
409 } 409 }
410 410
411 public void ReadData(byte[] data, ref int pointer) 411 public void ReadData(byte[] data, ref int pointer)
412 { 412 {
413 AccessFlags = (ushort)((data[pointer++] << 8) + data[pointer++]); 413 AccessFlags = (ushort)((data[pointer++] << 8) + data[pointer++]);
414 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); 414 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
415 DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); 415 DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
416 AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]); 416 AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]);
417 for (int i = 0; i < AttributeCount; i++) 417 for (int i = 0; i < AttributeCount; i++)
418 { 418 {
419 MethodAttribute attri = new MethodAttribute(this.parent); 419 MethodAttribute attri = new MethodAttribute(this.parent);
420 attri.ReadData(data, ref pointer); 420 attri.ReadData(data, ref pointer);
421 this.Attributes.Add(attri); 421 this.Attributes.Add(attri);
422 } 422 }
423 } 423 }
424 424
425 public void Print() 425 public void Print()
426 { 426 {
427 Console.WriteLine("Method Info Struct: "); 427 Console.WriteLine("Method Info Struct: ");
428 Console.WriteLine("AccessFlags: " + AccessFlags); 428 Console.WriteLine("AccessFlags: " + AccessFlags);
429 Console.WriteLine("NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value); 429 Console.WriteLine("NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value);
430 Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[DescriptorIndex - 1]).Value); 430 Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[DescriptorIndex - 1]).Value);
431 Console.WriteLine("Attribute Count:" + AttributeCount); 431 Console.WriteLine("Attribute Count:" + AttributeCount);
432 for (int i = 0; i < AttributeCount; i++) 432 for (int i = 0; i < AttributeCount; i++)
433 { 433 {
434 this.Attributes[i].Print(); 434 this.Attributes[i].Print();
435 } 435 }
436 } 436 }
437 437
438 public class MethodAttribute 438 public class MethodAttribute
439 { 439 {
440 public ushort NameIndex = 0; 440 public ushort NameIndex = 0;
441 public string Name = ""; 441 public string Name = "";
442 public Int32 Length = 0; 442 public Int32 Length = 0;
443 //for now only support code attribute 443 //for now only support code attribute
444 public ushort MaxStack = 0; 444 public ushort MaxStack = 0;
445 public ushort MaxLocals = 0; 445 public ushort MaxLocals = 0;
446 public Int32 CodeLength = 0; 446 public Int32 CodeLength = 0;
447 public byte[] Code; 447 public byte[] Code;
448 public ushort ExceptionTableLength = 0; 448 public ushort ExceptionTableLength = 0;
449 public ushort SubAttributeCount = 0; 449 public ushort SubAttributeCount = 0;
450 public List<SubAttribute> SubAttributes = new List<SubAttribute>(); 450 public List<SubAttribute> SubAttributes = new List<SubAttribute>();
451 private ClassRecord parent; 451 private ClassRecord parent;
452 452
453 public MethodAttribute(ClassRecord paren) 453 public MethodAttribute(ClassRecord paren)
454 { 454 {
455 parent = paren; 455 parent = paren;
456 } 456 }
457 457
458 public void ReadData(byte[] data, ref int pointer) 458 public void ReadData(byte[] data, ref int pointer)
459 { 459 {
460 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); 460 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
461 Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); 461 Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
462 MaxStack = (ushort)((data[pointer++] << 8) + data[pointer++]); 462 MaxStack = (ushort)((data[pointer++] << 8) + data[pointer++]);
463 MaxLocals = (ushort)((data[pointer++] << 8) + data[pointer++]); 463 MaxLocals = (ushort)((data[pointer++] << 8) + data[pointer++]);
464 CodeLength = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); 464 CodeLength = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
465 Code = new byte[CodeLength]; 465 Code = new byte[CodeLength];
466 for (int i = 0; i < CodeLength; i++) 466 for (int i = 0; i < CodeLength; i++)
467 { 467 {
468 Code[i] = data[pointer++]; 468 Code[i] = data[pointer++];
469 } 469 }
470 ExceptionTableLength = (ushort)((data[pointer++] << 8) + data[pointer++]); 470 ExceptionTableLength = (ushort)((data[pointer++] << 8) + data[pointer++]);
471 SubAttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]); 471 SubAttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]);
472 for (int i = 0; i < SubAttributeCount; i++) 472 for (int i = 0; i < SubAttributeCount; i++)
473 { 473 {
474 SubAttribute subAttri = new SubAttribute(this.parent); 474 SubAttribute subAttri = new SubAttribute(this.parent);
475 subAttri.ReadData(data, ref pointer); 475 subAttri.ReadData(data, ref pointer);
476 this.SubAttributes.Add(subAttri); 476 this.SubAttributes.Add(subAttri);
477 } 477 }
478 } 478 }
479 479
480 public void Print() 480 public void Print()
481 { 481 {
482 Console.WriteLine("Method Attribute: "); 482 Console.WriteLine("Method Attribute: ");
483 Console.WriteLine("Name Index: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value); 483 Console.WriteLine("Name Index: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value);
484 Console.WriteLine("Length: " + Length); 484 Console.WriteLine("Length: " + Length);
485 Console.WriteLine("MaxStack: " + MaxStack); 485 Console.WriteLine("MaxStack: " + MaxStack);
486 Console.WriteLine("MaxLocals: " + MaxLocals); 486 Console.WriteLine("MaxLocals: " + MaxLocals);
487 Console.WriteLine("CodeLength: " + CodeLength); 487 Console.WriteLine("CodeLength: " + CodeLength);
488 for (int i = 0; i < Code.Length; i++) 488 for (int i = 0; i < Code.Length; i++)
489 { 489 {
490 Console.WriteLine("OpCode #" + i + " is: " + Code[i]); 490 Console.WriteLine("OpCode #" + i + " is: " + Code[i]);
491 } 491 }
492 Console.WriteLine("SubAttributes: " + SubAttributeCount); 492 Console.WriteLine("SubAttributes: " + SubAttributeCount);
493 for (int i = 0; i < SubAttributeCount; i++) 493 for (int i = 0; i < SubAttributeCount; i++)
494 { 494 {
495 this.SubAttributes[i].Print(); 495 this.SubAttributes[i].Print();
496 } 496 }
497 } 497 }
498 498
499 public class SubAttribute 499 public class SubAttribute
500 { 500 {
501 public ushort NameIndex = 0; 501 public ushort NameIndex = 0;
502 public string Name = ""; 502 public string Name = "";
503 public Int32 Length = 0; 503 public Int32 Length = 0;
504 public byte[] Data; 504 public byte[] Data;
505 private ClassRecord parent; 505 private ClassRecord parent;
506 506
507 public SubAttribute(ClassRecord paren) 507 public SubAttribute(ClassRecord paren)
508 { 508 {
509 parent = paren; 509 parent = paren;
510 } 510 }
511 511
512 public void ReadData(byte[] data, ref int pointer) 512 public void ReadData(byte[] data, ref int pointer)
513 { 513 {
514 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); 514 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
515 Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); 515 Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
516 Data = new byte[Length]; 516 Data = new byte[Length];
517 for (int i = 0; i < Length; i++) 517 for (int i = 0; i < Length; i++)
518 { 518 {
519 Data[i] = data[pointer++]; 519 Data[i] = data[pointer++];
520 } 520 }
521 } 521 }
522 522
523 public void Print() 523 public void Print()
524 { 524 {
525 Console.WriteLine("SubAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value); 525 Console.WriteLine("SubAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value);
526 } 526 }
527 527
528 } 528 }
529 } 529 }
530 530
531 } 531 }
532 private class InterfaceInfo 532 private class InterfaceInfo
533 { 533 {
534 public void ReadData(byte[] data, ref int i) 534 public void ReadData(byte[] data, ref int i)
535 { 535 {
536 536
537 } 537 }
538 } 538 }
539 539
540 public class FieldInfo 540 public class FieldInfo
541 { 541 {
542 public ushort AccessFlags = 0; 542 public ushort AccessFlags = 0;
543 public ushort NameIndex = 0; 543 public ushort NameIndex = 0;
544 public string Name = ""; 544 public string Name = "";
545 public ushort DescriptorIndex = 0; 545 public ushort DescriptorIndex = 0;
546 public ushort AttributeCount = 0; 546 public ushort AttributeCount = 0;
547 public List<FieldAttribute> Attributes = new List<FieldAttribute>(); 547 public List<FieldAttribute> Attributes = new List<FieldAttribute>();
548 private ClassRecord parent; 548 private ClassRecord parent;
549 549
550 public FieldInfo(ClassRecord paren) 550 public FieldInfo(ClassRecord paren)
551 { 551 {
552 parent = paren; 552 parent = paren;
553 } 553 }
554 554
555 public void ReadData(byte[] data, ref int pointer) 555 public void ReadData(byte[] data, ref int pointer)
556 { 556 {
557 AccessFlags = (ushort)((data[pointer++] << 8) + data[pointer++]); 557 AccessFlags = (ushort)((data[pointer++] << 8) + data[pointer++]);
558 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); 558 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
559 DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); 559 DescriptorIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
560 AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]); 560 AttributeCount = (ushort)((data[pointer++] << 8) + data[pointer++]);
561 for (int i = 0; i < AttributeCount; i++) 561 for (int i = 0; i < AttributeCount; i++)
562 { 562 {
563 FieldAttribute attri = new FieldAttribute(this.parent); 563 FieldAttribute attri = new FieldAttribute(this.parent);
564 attri.ReadData(data, ref pointer); 564 attri.ReadData(data, ref pointer);
565 this.Attributes.Add(attri); 565 this.Attributes.Add(attri);
566 } 566 }
567 } 567 }
568 568
569 public void Print() 569 public void Print()
570 { 570 {
571 Console.WriteLine("Field Info Struct: "); 571 Console.WriteLine("Field Info Struct: ");
572 Console.WriteLine("AccessFlags: " + AccessFlags); 572 Console.WriteLine("AccessFlags: " + AccessFlags);
573 Console.WriteLine("NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value); 573 Console.WriteLine("NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value);
574 Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[DescriptorIndex - 1]).Value); 574 Console.WriteLine("DescriptorIndex: " + DescriptorIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[DescriptorIndex - 1]).Value);
575 Console.WriteLine("Attribute Count:" + AttributeCount); 575 Console.WriteLine("Attribute Count:" + AttributeCount);
576 //if static, add to static field list 576 //if static, add to static field list
577 // if (this.AccessFlags == 9) //public and static 577 // if (this.AccessFlags == 9) //public and static
578 if ((this.AccessFlags & 0x08) != 0) 578 if ((this.AccessFlags & 0x08) != 0)
579 { 579 {
580 switch (((PoolUtf8)this.parent.m_constantsPool[DescriptorIndex - 1]).Value) 580 switch (((PoolUtf8)this.parent.m_constantsPool[DescriptorIndex - 1]).Value)
581 { 581 {
582 case "I": 582 case "I":
583 Int newin = new Int(); 583 Int newin = new Int();
584 this.parent.StaticFields.Add(((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value, newin); 584 this.parent.StaticFields.Add(((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value, newin);
585 break; 585 break;
586 case "F": 586 case "F":
587 Float newfl = new Float(); 587 Float newfl = new Float();
588 this.parent.StaticFields.Add(((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value, newfl); 588 this.parent.StaticFields.Add(((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value, newfl);
589 break; 589 break;
590 } 590 }
591 591
592 } 592 }
593 for (int i = 0; i < AttributeCount; i++) 593 for (int i = 0; i < AttributeCount; i++)
594 { 594 {
595 this.Attributes[i].Print(); 595 this.Attributes[i].Print();
596 } 596 }
597 } 597 }
598 598
599 public class FieldAttribute 599 public class FieldAttribute
600 { 600 {
601 public ushort NameIndex = 0; 601 public ushort NameIndex = 0;
602 public string Name = ""; 602 public string Name = "";
603 public Int32 Length = 0; 603 public Int32 Length = 0;
604 public byte[] Data; 604 public byte[] Data;
605 private ClassRecord parent; 605 private ClassRecord parent;
606 606
607 public FieldAttribute(ClassRecord paren) 607 public FieldAttribute(ClassRecord paren)
608 { 608 {
609 parent = paren; 609 parent = paren;
610 } 610 }
611 611
612 public void ReadData(byte[] data, ref int pointer) 612 public void ReadData(byte[] data, ref int pointer)
613 { 613 {
614 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]); 614 NameIndex = (ushort)((data[pointer++] << 8) + data[pointer++]);
615 Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]); 615 Length = (Int32)((data[pointer++] << 24) + (data[pointer++] << 16) + (data[pointer++] << 8) + data[pointer++]);
616 Data = new byte[Length]; 616 Data = new byte[Length];
617 for (int i = 0; i < Length; i++) 617 for (int i = 0; i < Length; i++)
618 { 618 {
619 Data[i] = data[pointer++]; 619 Data[i] = data[pointer++];
620 } 620 }
621 } 621 }
622 622
623 public void Print() 623 public void Print()
624 { 624 {
625 Console.WriteLine("FieldAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value); 625 Console.WriteLine("FieldAttribute: NameIndex: " + NameIndex + " // " + ((PoolUtf8)this.parent.m_constantsPool[NameIndex - 1]).Value);
626 } 626 }
627 } 627 }
628 } 628 }
629 629
630 private class AttributeInfo 630 private class AttributeInfo
631 { 631 {
632 public void ReadData(byte[] data, ref int i) 632 public void ReadData(byte[] data, ref int i)
633 { 633 {
634 634
635 } 635 }
636 } 636 }
637 #endregion 637 #endregion
638 638
639 } 639 }
640} \ No newline at end of file 640} \ No newline at end of file