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