Source Code Cross Referenced for CPool.java in  » Development » jdec » net » sf » jdec » constantpool » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Development » jdec » net.sf.jdec.constantpool 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  CPool.java Copyright (c) 2006,07 Swaroop Belur 
003:         *  
004:         * This program is free software; you can redistribute it and/or
005:         * modify it under the terms of the GNU General Public License
006:         * as published by the Free Software Foundation; either version 2
007:         * of the License, or (at your option) any later version.
008:
009:         * This program is distributed in the hope that it will be useful,
010:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
011:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
012:         * GNU General Public License for more details.
013:
014:         * You should have received a copy of the GNU General Public License
015:         * along with this program; if not, write to the Free Software
016:         * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
017:         *
018:         */
019:
020:        package net.sf.jdec.constantpool;
021:
022:        import java.io.DataInputStream;
023:        import java.io.IOException;
024:        import java.util.ArrayList;
025:        import java.util.Iterator;
026:
027:        import net.sf.jdec.main.ConsoleLauncher;
028:        import net.sf.jdec.ui.main.UILauncher;
029:        import net.sf.jdec.util.Constants;
030:        import net.sf.jdec.config.Configuration;
031:
032:        public class CPool {
033:
034:            // Storage For Class Contents
035:
036:            private static ArrayList AllMethodRefs = new ArrayList();
037:            private static ArrayList AllFieldRefs = new ArrayList();
038:            private static ArrayList AllInterfaceMethodRefs = new ArrayList();
039:            private static ArrayList AllIntegers = new ArrayList();
040:            private static ArrayList AllFloats = new ArrayList();
041:            private static ArrayList AllLongs = new ArrayList();
042:            private static ArrayList AllDoubles = new ArrayList();
043:            private static ArrayList AllStrings = new ArrayList();
044:            private static ArrayList AllUtf8 = new ArrayList();
045:            private static ArrayList AllClassInfos = new ArrayList();
046:            private static ArrayList AllNameAndTypes = new ArrayList();
047:            private static java.lang.String constantPoolDescription = "";
048:            private static java.lang.String temp[] = new java.lang.String[5];
049:
050:            public static void createConstantPool(DataInputStream dis)
051:                    throws IOException {
052:                int poolCount = dis.readUnsignedShort();
053:                ConsoleLauncher.setPoolCount(poolCount);
054:                for (int counter = 1; counter < poolCount; counter++) {
055:                    int tag = dis.readByte();
056:                    switch (tag) {
057:
058:                    case Constants.CONSTANT_UTF8:
059:                        registerUTF8(dis, tag, counter);
060:                        break;
061:
062:                    case Constants.CONSTANT_INTEGER:
063:                        registerInteger(dis, tag, counter);
064:                        break;
065:
066:                    case Constants.CONSTANT_FLOAT:
067:                        registerFloat(dis, tag, counter);
068:                        break;
069:
070:                    case Constants.CONSTANT_LONG:
071:                        registerLong(dis, tag, counter);
072:                        counter++;
073:                        break;
074:
075:                    case Constants.CONSTANT_DOUBLE:
076:                        registerDouble(dis, tag, counter);
077:                        counter++;
078:                        break;
079:
080:                    case Constants.CONSTANT_STRING:
081:                        registerString(dis, tag, counter);
082:                        break;
083:
084:                    case Constants.CONSTANT_CLASS:
085:                        registerClass(dis, tag, counter);
086:                        break;
087:
088:                    case Constants.CONSTANT_FIELDREF:
089:                        registerFieldRef(dis, tag, counter);
090:                        break;
091:
092:                    case Constants.CONSTANT_METHODREF:
093:                        registerMethodRef(dis, tag, counter);
094:                        break;
095:
096:                    case Constants.CONSTANT_INTERFACEMETHODREF:
097:                        registerInterfaceMethodRef(dis, tag, counter);
098:                        break;
099:
100:                    case Constants.CONSTANT_NAMEANDTYPE:
101:                        registerNameAndType(dis, tag, counter);
102:                        break;
103:                    }
104:                }
105:
106:                linkAllReferences(dis);
107:                if (UILauncher.getUIutil() != null
108:                        && Configuration.getDecompileroption().equals("vcp"))
109:                    UILauncher.getUIutil().setcpdescription(cpdescription);
110:            }
111:
112:            private static void registerFieldRef(DataInputStream dis, int tag,
113:                    int counter) throws IOException {
114:                int classIndexPointer = dis.readUnsignedShort();
115:                int nameAndTypePointer = dis.readUnsignedShort();
116:
117:                // Store values
118:                net.sf.jdec.constantpool.FieldRef fref = new FieldRef();
119:                fref.setCppos(counter);
120:                fref.setClassPointer(classIndexPointer);
121:                fref.setDescriptionPointer(nameAndTypePointer);
122:                fref.setTag(tag);
123:                AllFieldRefs.add(fref);
124:
125:                temp[0] = "" + counter;
126:
127:                temp[1] = "TAG_FREF ";
128:
129:                temp[2] = "" + classIndexPointer;
130:                temp[3] = "" + nameAndTypePointer;
131:                temp[4] = "_";
132:                if (Configuration.getDecompileroption().equals("vcp"))
133:                    describeConstantPool(temp);
134:            }
135:
136:            private static void registerMethodRef(DataInputStream dis, int tag,
137:                    int counter) throws IOException {
138:
139:                int classIndexPointer = dis.readUnsignedShort();
140:                int nameAndTypePointer = dis.readUnsignedShort();
141:
142:                // Store values
143:                MethodRef mref = new MethodRef();
144:                mref.setCppos(counter);
145:                mref.setClassPointer(classIndexPointer);
146:                mref.setDescriptionPointer(nameAndTypePointer);
147:                mref.setTag(tag);
148:                AllMethodRefs.add(mref);
149:
150:                temp[0] = "" + counter;
151:                temp[1] = "TAG_MREF ";
152:                temp[2] = "" + classIndexPointer;
153:                temp[3] = "" + nameAndTypePointer;
154:                temp[4] = "_";
155:                if (Configuration.getDecompileroption().equals("vcp"))
156:                    describeConstantPool(temp);
157:
158:            }
159:
160:            private static void registerInterfaceMethodRef(DataInputStream dis,
161:                    int tag, int counter) throws IOException {
162:                int classIndexPointer = dis.readUnsignedShort();
163:                int nameAndTypePointer = dis.readUnsignedShort();
164:
165:                // Store values
166:                InterfaceMethodRef iref = new InterfaceMethodRef();
167:                iref.setCppos(counter);
168:                iref.setClassPointer(classIndexPointer);
169:                iref.setDescriptionPointer(nameAndTypePointer);
170:                iref.setTag(tag);
171:                AllInterfaceMethodRefs.add(iref);
172:
173:                //		Add to the description of constant pool
174:
175:                temp[0] = "" + counter;
176:                temp[1] = "TAG_IMREF";
177:                temp[2] = "" + classIndexPointer;
178:                temp[3] = "" + nameAndTypePointer;
179:                temp[4] = "_";
180:                if (Configuration.getDecompileroption().equals("vcp"))
181:                    describeConstantPool(temp);
182:
183:            }
184:
185:            private static void registerClass(DataInputStream dis, int tag,
186:                    int counter) throws IOException {
187:
188:                int utf8_pointer = dis.readUnsignedShort();
189:                ClassInfo cinfo = new ClassInfo();
190:                cinfo.setUtf8pointer(utf8_pointer);
191:                cinfo.setTag(tag);
192:                cinfo.setCppos(counter);
193:                AllClassInfos.add(cinfo);
194:
195:                //Add to the description of constant pool
196:
197:                temp[0] = "" + counter;
198:                temp[1] = "TAG_CLASS";
199:                temp[2] = "" + utf8_pointer;
200:                temp[3] = "_";
201:                temp[4] = "_";
202:
203:                if (Configuration.getDecompileroption().equals("vcp"))
204:                    describeConstantPool(temp);
205:                //CharacterData
206:
207:            }
208:
209:            private static void registerUTF8(DataInputStream dis, int tag,
210:                    int counter) throws IOException {
211:                /*int length=dis.readUnsignedShort();
212:                byte[] contents=new byte[length];
213:                for(int count=0;count<length;count++)
214:                {
215:                	byte content=dis.readByte();
216:                	contents[count]=content;
217:                }*/
218:                //  byte[] buf = new byte [length];
219:                //  dis.readFully (contents, 0, length);
220:                //java.lang.String val=dis.readUTF();
221:                java.lang.String utfs = dis.readUTF();
222:                UTF8 utf8 = new UTF8();
223:                utf8.setLength(utfs.length());
224:                utf8.initialize(utfs.getBytes());
225:                utf8.setTag(tag);
226:
227:                utf8.setCppos(counter);
228:                //java.lang.String s2=new java.lang.String(utfs,"UTF-8");
229:                //java.lang.String str = interpretUTF8ByteArray(utfs);  
230:                //	new java.lang.String(contents,"UTF-8");
231:                utf8.setStringValue(utfs);
232:                AllUtf8.add(utf8);
233:
234:                // Add to the description of constant pool
235:
236:                temp[0] = "" + counter;
237:                temp[1] = "TAG_UTF8  ";
238:                temp[2] = "_";
239:                temp[3] = "_";
240:                temp[4] = utfs;//new java.lang.String(utfs);
241:                if (Configuration.getDecompileroption().equals("vcp"))
242:                    describeConstantPool(temp);
243:
244:            }
245:
246:            private static void registerInteger(DataInputStream dis, int tag,
247:                    int counter) throws IOException {
248:                int value = dis.readInt();
249:                IntPrimitive intobj = new IntPrimitive();
250:                intobj.setValue(value);
251:                intobj.setTag(tag);
252:                intobj.setCppos(counter);
253:                AllIntegers.add(intobj);
254:
255:                // Add to the description of constant pool
256:
257:                temp[0] = "" + counter;
258:                temp[1] = "TAG_INT  ";
259:                temp[2] = "_";
260:                temp[3] = "_";
261:                temp[4] = "_";
262:                if (Configuration.getDecompileroption().equals("vcp"))
263:                    describeConstantPool(temp);
264:
265:            }
266:
267:            private static void registerFloat(DataInputStream dis, int tag,
268:                    int counter) throws IOException {
269:                float value = dis.readFloat();
270:                FloatPrimitive floatobj = new FloatPrimitive();
271:                floatobj.setValue(value);
272:                floatobj.setTag(tag);
273:                floatobj.setCppos(counter);
274:                AllFloats.add(floatobj);
275:
276:                //		Add to the description of constant pool
277:
278:                temp[0] = "" + counter;
279:                temp[1] = "TAG_FLOAT";
280:                temp[2] = "_";
281:                temp[3] = "_";
282:                temp[4] = "_";
283:                if (Configuration.getDecompileroption().equals("vcp"))
284:                    describeConstantPool(temp);
285:
286:            }
287:
288:            private static void registerDouble(DataInputStream dis, int tag,
289:                    int counter) throws IOException {
290:                double value = dis.readDouble();
291:                DoublePrimitive dbobj = new DoublePrimitive();
292:                dbobj.setValue(value);
293:                dbobj.setTag(tag);
294:                dbobj.setCppos(counter);
295:                AllDoubles.add(dbobj);
296:
297:                temp[0] = "" + counter;
298:                temp[1] = "TAG_DBL  ";
299:                temp[2] = "_";
300:                temp[3] = "_";
301:                temp[4] = "_";
302:                if (Configuration.getDecompileroption().equals("vcp"))
303:                    describeConstantPool(temp);
304:
305:            }
306:
307:            private static void registerLong(DataInputStream dis, int tag,
308:                    int counter) throws IOException {
309:                long lvalue = dis.readLong();
310:                LongPrimitive lngobj = new LongPrimitive();
311:                /*lngobj.setUppervalue(hvalue);
312:                 lngobj.setLowervalue(lvalue);*/
313:                lngobj.setTag(tag);
314:                lngobj.setCppos(counter);
315:                lngobj.setValue(lvalue);
316:                AllLongs.add(lngobj);
317:
318:                //		Add to the description of constant pool
319:
320:                temp[0] = "" + counter;
321:                temp[1] = new java.lang.String("TAG_LONG ");
322:                temp[2] = "_";
323:                temp[3] = "_";
324:                temp[4] = "_";
325:                if (Configuration.getDecompileroption().equals("vcp"))
326:                    describeConstantPool(temp);
327:
328:            }
329:
330:            private static void registerString(DataInputStream dis, int tag,
331:                    int counter) throws IOException {
332:                int utf8_pointer = dis.readUnsignedShort();
333:                CPString strobj = new CPString();
334:                strobj.setUtf8pointer(utf8_pointer);
335:                strobj.setTag(tag);
336:                strobj.setCppos(counter);
337:                AllStrings.add(strobj);
338:                //		Add to the description of constant pool
339:
340:                temp[0] = "" + counter;
341:                temp[1] = "TAG_STR  ";
342:                temp[2] = "" + utf8_pointer;
343:                temp[3] = "_";
344:                temp[4] = "_";
345:                if (Configuration.getDecompileroption().equals("vcp"))
346:                    describeConstantPool(temp);
347:
348:            }
349:
350:            private static void registerNameAndType(DataInputStream dis,
351:                    int tag, int counter) throws IOException {
352:                int name_index = dis.readUnsignedShort();
353:                int descriptor_index = dis.readUnsignedShort();
354:
355:                NameAndType nmobj = new NameAndType();
356:                nmobj.setUtf8pointer(name_index);
357:                nmobj.setDescription(descriptor_index);
358:                nmobj.setTag(tag);
359:                nmobj.setCppos(counter);
360:                AllNameAndTypes.add(nmobj);
361:
362:                temp[0] = "" + counter;
363:                temp[1] = "TAG_NTYPE";
364:                temp[2] = "" + name_index;
365:                temp[3] = "" + descriptor_index;
366:                temp[4] = "_";
367:                if (Configuration.getDecompileroption().equals("vcp"))
368:                    describeConstantPool(temp);
369:
370:            }
371:
372:            private static void linkAllReferences(DataInputStream dis)
373:                    throws IOException {
374:                resolveFieldRefs();
375:                resolveMethodRefs();
376:                resolveInterfaceMethodRefs();
377:                getClassName();
378:                getAllFields();
379:
380:            }
381:
382:            private static void resolveInterfaceMethodRefs() {
383:                Iterator mrefs = AllInterfaceMethodRefs.iterator();
384:                while (mrefs.hasNext()) {
385:                    InterfaceMethodRef mrefobj = (InterfaceMethodRef) mrefs
386:                            .next();
387:                    int classpointer = mrefobj.getClassPointer();
388:                    int descpointer = mrefobj.getDescriptionPointer();
389:                    findClassOrInterfaceAndNameTypeInfo(classpointer, mrefobj,
390:                            descpointer);
391:
392:                }
393:
394:            }
395:
396:            private static void resolveMethodRefs() {
397:                Iterator mrefs = AllMethodRefs.iterator();
398:                while (mrefs.hasNext()) {
399:                    MethodRef mrefobj = (MethodRef) mrefs.next();
400:                    int classpointer = mrefobj.getClassPointer();
401:                    int descpointer = mrefobj.getDescriptionPointer();
402:                    findClassOrInterfaceAndNameTypeInfo(classpointer, mrefobj,
403:                            descpointer);
404:
405:                }
406:
407:            }
408:
409:            private static void resolveFieldRefs() {
410:
411:                Iterator frefs = AllFieldRefs.iterator();
412:                while (frefs.hasNext()) {
413:                    FieldRef fref = (FieldRef) frefs.next();
414:                    int classpointer = fref.getClassPointer();
415:                    int nmtypepointer = fref.getDescriptionPointer();
416:                    findClassOrInterfaceAndNameTypeInfo(classpointer, fref,
417:                            nmtypepointer);
418:                }
419:
420:            }
421:
422:            private static void findClassOrInterfaceAndNameTypeInfo(
423:                    int classpointer, MethodRef mrefobj, int descpointer) {
424:                Iterator allclinfos = AllClassInfos.iterator();
425:                ClassInfo reqdClassInfo = null;
426:                NameAndType nmtReqd = null;
427:                while (allclinfos.hasNext()) {
428:                    ClassInfo cinfo = (ClassInfo) allclinfos.next();
429:                    if (cinfo.getCppos() == classpointer) {
430:                        reqdClassInfo = cinfo;
431:                        break;
432:                    }
433:                }
434:                Iterator allnmtypes = AllNameAndTypes.iterator();
435:                while (allnmtypes.hasNext()) {
436:                    NameAndType nmt = (NameAndType) allnmtypes.next();
437:                    if (nmt.getCppos() == descpointer) {
438:                        nmtReqd = nmt;
439:                        break;
440:                    }
441:                }
442:
443:                storeMethodRefDetails(mrefobj, reqdClassInfo, nmtReqd);
444:
445:            }
446:
447:            private static void findClassOrInterfaceAndNameTypeInfo(
448:                    int classpointer, InterfaceMethodRef mrefobj,
449:                    int descpointer) {
450:                Iterator allclinfos = AllClassInfos.iterator();
451:                ClassInfo reqdClassInfo = null;
452:                NameAndType nmtReqd = null;
453:                while (allclinfos.hasNext()) {
454:                    ClassInfo cinfo = (ClassInfo) allclinfos.next();
455:                    if (cinfo.getCppos() == classpointer) {
456:                        reqdClassInfo = cinfo;
457:                        break;
458:                    }
459:                }
460:                Iterator allnmtypes = AllNameAndTypes.iterator();
461:                while (allnmtypes.hasNext()) {
462:                    NameAndType nmt = (NameAndType) allnmtypes.next();
463:                    if (nmt.getCppos() == descpointer) {
464:                        nmtReqd = nmt;
465:                        break;
466:                    }
467:                }
468:
469:                storeInterfaceMethodRefDetails(mrefobj, reqdClassInfo, nmtReqd);
470:
471:            }
472:
473:            // TODO: Check The logic Once
474:            private static void storeInterfaceMethodRefDetails(
475:                    InterfaceMethodRef mref, ClassInfo cinfo, NameAndType nmtype) {
476:                java.lang.String className = "";
477:                java.lang.String[] nameAndType = new java.lang.String[2];
478:                java.lang.String name_index = "";
479:
480:                int cinfo_utf8 = cinfo.getUtf8pointer();
481:
482:                // Find CLass Name or Interface Name for field
483:                Iterator utf8s = AllUtf8.iterator();
484:                while (utf8s.hasNext()) {
485:                    UTF8 utf8obj = (UTF8) utf8s.next();
486:                    int cppos = utf8obj.getCppos();
487:                    if (cppos == cinfo_utf8) {
488:                        className = utf8obj.getStringVal();//new java.lang.String(utf8obj.getBytes());
489:                        break;
490:                    }
491:                }
492:                int nmtype_utf8 = nmtype.getUtf8pointer();
493:                int nmtype_desc_utf8 = nmtype.getDescription();
494:
495:                utf8s = AllUtf8.iterator();
496:                while (utf8s.hasNext()) {
497:                    UTF8 utf8obj = (UTF8) utf8s.next();
498:                    int cppos = utf8obj.getCppos();
499:                    if (nmtype_utf8 == cppos) {
500:                        nameAndType[0] = utf8obj.getStringVal();//new java.lang.String(utf8obj.getBytes());
501:                        break;
502:                    }
503:                }
504:
505:                utf8s = AllUtf8.iterator();
506:                while (utf8s.hasNext()) {
507:                    UTF8 utf8obj = (UTF8) utf8s.next();
508:                    int cppos = utf8obj.getCppos();
509:                    if (nmtype_desc_utf8 == cppos) {
510:                        nameAndType[1] = utf8obj.getStringVal();//new java.lang.String(utf8obj.getBytes());
511:                        break;
512:                    }
513:                }
514:
515:                mref.setClassName(className);
516:                mref.setClassRef(cinfo);
517:                mref.setType(nameAndType[1]);
518:                mref.setMethodName(nameAndType[0]);
519:                mref.setKey(nameAndType[0] + ";" + nameAndType[1]);
520:            }
521:
522:            private static void storeMethodRefDetails(MethodRef mref,
523:                    ClassInfo cinfo, NameAndType nmtype) {
524:                java.lang.String className = "";
525:                java.lang.String[] nameAndType = new java.lang.String[2];
526:                java.lang.String name_index = "";
527:
528:                int cinfo_utf8 = cinfo.getUtf8pointer();
529:
530:                // Find CLass Name or Interface Name for field
531:                Iterator utf8s = AllUtf8.iterator();
532:                while (utf8s.hasNext()) {
533:                    UTF8 utf8obj = (UTF8) utf8s.next();
534:                    int cppos = utf8obj.getCppos();
535:                    if (cppos == cinfo_utf8) {
536:                        className = utf8obj.getStringVal();//new java.lang.String(utf8obj.getBytes());
537:                        break;
538:                    }
539:                }
540:                int nmtype_utf8 = nmtype.getUtf8pointer();
541:                int nmtype_desc_utf8 = nmtype.getDescription();
542:
543:                utf8s = AllUtf8.iterator();
544:                while (utf8s.hasNext()) {
545:                    UTF8 utf8obj = (UTF8) utf8s.next();
546:                    int cppos = utf8obj.getCppos();
547:                    if (nmtype_utf8 == cppos) {
548:                        nameAndType[0] = utf8obj.getStringVal();//new java.lang.String(utf8obj.getBytes());
549:                        break;
550:                    }
551:                }
552:
553:                utf8s = AllUtf8.iterator();
554:                while (utf8s.hasNext()) {
555:                    UTF8 utf8obj = (UTF8) utf8s.next();
556:                    int cppos = utf8obj.getCppos();
557:                    if (nmtype_desc_utf8 == cppos) {
558:                        nameAndType[1] = utf8obj.getStringVal();//new java.lang.String(utf8obj.getBytes());
559:                        break;
560:                    }
561:                }
562:
563:                mref.setClassName(className);
564:                mref.setClassRef(cinfo);
565:                mref.setType(nameAndType[1]);
566:                mref.setMethodName(nameAndType[0]);
567:                mref.setKey(nameAndType[0] + ";" + nameAndType[1]);
568:            }
569:
570:            private static void findClassOrInterfaceAndNameTypeInfo(
571:                    int classpointer, FieldRef fref, int nmtypepointer) {
572:                Iterator allclinfos = AllClassInfos.iterator();
573:                ClassInfo reqdClassInfo = null;
574:                NameAndType nmtReqd = null;
575:                while (allclinfos.hasNext()) {
576:                    ClassInfo cinfo = (ClassInfo) allclinfos.next();
577:                    if (cinfo.getCppos() == classpointer) {
578:                        reqdClassInfo = cinfo;
579:                        break;
580:                    }
581:                }
582:                Iterator allnmtypes = AllNameAndTypes.iterator();
583:                while (allnmtypes.hasNext()) {
584:                    NameAndType nmt = (NameAndType) allnmtypes.next();
585:                    if (nmt.getCppos() == nmtypepointer) {
586:                        nmtReqd = nmt;
587:                        break;
588:                    }
589:                }
590:
591:                storeFieldRefDetails(fref, reqdClassInfo, nmtReqd);
592:
593:            }
594:
595:            private static void storeFieldRefDetails(FieldRef fref,
596:                    ClassInfo cinfo, NameAndType nmtype) {
597:                java.lang.String className = "";
598:                java.lang.String[] nameAndType = new java.lang.String[2];
599:                java.lang.String name_index = "";
600:
601:                int cinfo_utf8 = cinfo.getUtf8pointer();
602:
603:                // Find CLass Name or Interface Name for field
604:                Iterator utf8s = AllUtf8.iterator();
605:                while (utf8s.hasNext()) {
606:                    UTF8 utf8obj = (UTF8) utf8s.next();
607:                    int cppos = utf8obj.getCppos();
608:                    if (cppos == cinfo_utf8) {
609:                        className = utf8obj.getStringVal();//new java.lang.String(utf8obj.getBytes());
610:                        break;
611:                    }
612:                }
613:                int nmtype_utf8 = nmtype.getUtf8pointer();
614:                int nmtype_desc_utf8 = nmtype.getDescription();
615:
616:                utf8s = AllUtf8.iterator();
617:                while (utf8s.hasNext()) {
618:                    UTF8 utf8obj = (UTF8) utf8s.next();
619:                    int cppos = utf8obj.getCppos();
620:                    if (nmtype_utf8 == cppos) {
621:                        nameAndType[0] = utf8obj.getStringVal();//new java.lang.String(utf8obj.getBytes());
622:                        break;
623:                    }
624:                }
625:
626:                utf8s = AllUtf8.iterator();
627:                while (utf8s.hasNext()) {
628:                    UTF8 utf8obj = (UTF8) utf8s.next();
629:                    int cppos = utf8obj.getCppos();
630:                    if (nmtype_desc_utf8 == cppos) {
631:                        nameAndType[1] = utf8obj.getStringVal();//new java.lang.String(utf8obj.getBytes());
632:                        break;
633:                    }
634:                }
635:
636:                fref.setClassName(className);
637:                fref.setClassRef(cinfo);
638:                fref.setType(nameAndType[1]);
639:                fref.setFieldName(nameAndType[0]);
640:
641:            }
642:
643:            private static void getAllFields() {
644:                getAllPrimitives();
645:                getAllObjectReferences();
646:
647:            }
648:
649:            private static void getAllPrimitives() {
650:                getIntegers();
651:                getLongs();
652:                getFloats();
653:                getDoubles();
654:
655:            }
656:
657:            private static void getIntegers() {
658:                Iterator integers = AllIntegers.iterator();
659:
660:                while (integers.hasNext()) {
661:                    IntPrimitive intobj = (IntPrimitive) integers.next();
662:
663:                }
664:            }
665:
666:            private static void getFloats() {
667:                Iterator floats = AllFloats.iterator();
668:
669:                while (floats.hasNext()) {
670:                    FloatPrimitive fltobj = (FloatPrimitive) floats.next();
671:
672:                }
673:            }
674:
675:            private static void getLongs() {
676:
677:            }
678:
679:            private static void getDoubles() {
680:
681:            }
682:
683:            private static void getAllObjectReferences() {
684:
685:            }
686:
687:            private static void getClassName() {
688:                Iterator iterator = AllClassInfos.iterator();
689:                while (iterator.hasNext()) {
690:                    ClassInfo cinfo = (ClassInfo) iterator.next();
691:                    int utf8_pointer = cinfo.getUtf8pointer();
692:                    findClassName(utf8_pointer);
693:
694:                }
695:
696:            }
697:
698:            private static void findClassName(int utf8_pointer) {
699:                Iterator iterator = AllUtf8.iterator();
700:                while (iterator.hasNext()) {
701:                    UTF8 utf8obj = (UTF8) iterator.next();
702:                    if (utf8obj.getCppos() == utf8_pointer) {
703:                        //	System.out.println(" The Class Name is = "+new java.lang.String(utf8obj.getBytes()));
704:                    }
705:                }
706:            }
707:
708:            public static ArrayList getAllClassInfos() {
709:                return AllClassInfos;
710:            }
711:
712:            public static void setAllClassInfos(ArrayList allClassInfos) {
713:                AllClassInfos = allClassInfos;
714:            }
715:
716:            public static ArrayList getAllDoubles() {
717:                return AllDoubles;
718:            }
719:
720:            public static void setAllDoubles(ArrayList allDoubles) {
721:                AllDoubles = allDoubles;
722:            }
723:
724:            public static ArrayList getAllFieldRefs() {
725:                return AllFieldRefs;
726:            }
727:
728:            public static void setAllFieldRefs(ArrayList allFieldRefs) {
729:                AllFieldRefs = allFieldRefs;
730:            }
731:
732:            public static ArrayList getAllFloats() {
733:                return AllFloats;
734:            }
735:
736:            public static void setAllFloats(ArrayList allFloats) {
737:                AllFloats = allFloats;
738:            }
739:
740:            public static ArrayList getAllIntegers() {
741:                return AllIntegers;
742:            }
743:
744:            public static void setAllIntegers(ArrayList allIntegers) {
745:                AllIntegers = allIntegers;
746:            }
747:
748:            public static ArrayList getAllInterfaceMethodRefs() {
749:                return AllInterfaceMethodRefs;
750:            }
751:
752:            public static void setAllInterfaceMethodRefs(
753:                    ArrayList allInterfaceMethodRefs) {
754:                AllInterfaceMethodRefs = allInterfaceMethodRefs;
755:            }
756:
757:            public static ArrayList getAllLongs() {
758:                return AllLongs;
759:            }
760:
761:            public static void setAllLongs(ArrayList allLongs) {
762:                AllLongs = allLongs;
763:            }
764:
765:            public static ArrayList getAllMethodRefs() {
766:                return AllMethodRefs;
767:            }
768:
769:            public static void setAllMethodRefs(ArrayList allMethodRefs) {
770:                AllMethodRefs = allMethodRefs;
771:            }
772:
773:            public static ArrayList getAllNameAndTypes() {
774:                return AllNameAndTypes;
775:            }
776:
777:            public static void setAllNameAndTypes(ArrayList allNameAndTypes) {
778:                AllNameAndTypes = allNameAndTypes;
779:            }
780:
781:            public static ArrayList getAllStrings() {
782:                return AllStrings;
783:            }
784:
785:            public static void setAllStrings(ArrayList allStrings) {
786:                AllStrings = allStrings;
787:            }
788:
789:            public static ArrayList getAllUtf8() {
790:                return AllUtf8;
791:            }
792:
793:            public static void setAllUtf8(ArrayList allUtf8) {
794:                AllUtf8 = allUtf8;
795:            }
796:
797:            public static void describeConstantPool(java.lang.String al[]) {
798:
799:                int count = 1;
800:                java.lang.String s2[] = new java.lang.String[5];
801:                int counter = 0;
802:                while (counter < al.length) {
803:
804:                    Object s = al[counter];
805:
806:                    s2[counter++] = s.toString();
807:                    constantPoolDescription += s.toString() + "\t";
808:                    if (count == 1) {
809:                        constantPoolDescription += "  ";
810:
811:                    }
812:                    if (count > 1) {
813:                        constantPoolDescription += "         ";
814:
815:                    }
816:                    count++;
817:
818:                }
819:                cpdescription.add(s2);
820:                //nullifyAllValues(al);
821:            }
822:
823:            private static void nullifyAllValues(java.lang.String[] al) {
824:
825:                al = new java.lang.String[5];
826:                constantPoolDescription += "\n";
827:
828:            }
829:
830:            public static java.lang.String returnConstantPoolDesc() {
831:                return constantPoolDescription;
832:            }
833:
834:            private static ArrayList cpdescription = new ArrayList();
835:
836:            public static void resetCpoolDesc() {
837:                cpdescription = new ArrayList();
838:            }
839:
840:            private static java.lang.String interpretUTF8ByteArray(byte[] b) {
841:                int strLen = 0;
842:                int c, d, e;
843:                int index = 0;
844:                int endIndex = b.length;
845:                char buf[] = new char[endIndex];
846:
847:                while (index < endIndex) {
848:                    c = b[index++] & 0xFF;
849:                    switch (c >> 4) {
850:                    case 0:
851:                    case 1:
852:                    case 2:
853:                    case 3:
854:                    case 4:
855:                    case 5:
856:                    case 6:
857:                    case 7:
858:                        // 0xxxxxxx
859:                        buf[strLen++] = (char) c;
860:                        break;
861:                    case 12:
862:                    case 13:
863:                        // 110x xxxx 10xx xxxx
864:                        d = b[index++];
865:                        buf[strLen++] = (char) (((c & 0x1F) << 6) | (d & 0x3F));
866:                        break;
867:                    default:
868:                        // 1110 xxxx 10xx xxxx 10xx xxxx
869:                        d = b[index++];
870:                        e = b[index++];
871:                        buf[strLen++] = (char) (((c & 0x0F) << 12)
872:                                | ((d & 0x3F) << 6) | (e & 0x3F));
873:                        break;
874:                    }
875:                }
876:                //        /CharacterData
877:                java.lang.String str = new java.lang.String(buf, 0, strLen);
878:                return str;
879:            }
880:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.