Main Page | Class Hierarchy | Class List | File List | Class Members | File Members

classview.cc

Go to the documentation of this file.
00001 /*
00002  *      HT Editor
00003  *      classview.cc
00004  *
00005  *      Copyright (C) 2001 Stanley Gambarin <stanleyg76@yahoo.com>
00006  *
00007  *      This program is free software; you can redistribute it and/or modify
00008  *      it under the terms of the GNU General Public License version 2 as
00009  *      published by the Free Software Foundation.
00010  *
00011  *      This program is distributed in the hope that it will be useful,
00012  *      but WITHOUT ANY WARRANTY; without even the implied warranty of
00013  *      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00014  *      GNU General Public License for more details.
00015  *
00016  *      You should have received a copy of the GNU General Public License
00017  *      along with this program; if not, write to the Free Software
00018  *      Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
00019  */
00020 
00021 #include <stdlib.h>
00022 
00023 #include "class.h"
00024 #include "classimg.h"
00025 #include "htatom.h"
00026 #include "httag.h"
00027 #include "snprintf.h"
00028 #include "stream.h"
00029 
00030 #define ATOM_CLS_ACCESS     0xcafebab0
00031 #define ATOM_CLS_ACCESS_STR  "cafebab0"
00032 #define ATOM_CLS_CPOOL      0xcafebab1
00033 #define ATOM_CLS_CPOOL_STR   "cafebab1"
00034 
00035 ht_tag_flags_s access_flags[] = 
00036 {
00037         { -1,  "access flags"},
00038         {8+0,  "[0x0001] public"},
00039         {8+1,  "[0x0002] private"},
00040         {8+2,  "[0x0004] protected"},
00041         {8+3,  "[0x0008] static"},
00042         {8+4,  "[0x0010] final"},
00043         {8+5,  "[0x0020] synchronized"},
00044         {8+6,  "[0x0040] volatile"},
00045         {8+7,  "[0x0080] transient"},
00046         {8+8,  "[0x0100] native"},
00047         {8+9,  "[0x0200] interface"},
00048         {8+10, "[0x0400] abstract"},
00049         {8+11, "[0x0800] strict"},
00050         {0, 0}
00051 };
00052 int_hash cpool_tags [] = 
00053 {
00054         { 1, "utf8"},
00055         { 2, "unknown type"},
00056         { 3, "integer"},
00057         { 4, "float"},
00058         { 5, "long"},
00059         { 6, "double"},
00060         { 7, "class"},
00061         { 8, "string"},
00062         { 9, "fieldref"},
00063         {10, "methodref"},
00064         {11, "interfacemethodref"},
00065         {12, "nameandtype"},
00066         {0, 0}
00067 };
00068 ht_mask_ptable cls_class1_hdr[] = 
00069 {
00070         {"magic",                      STATICTAG_EDIT_DWORD_BE("00000000")},
00071         {"minor version",              STATICTAG_EDIT_WORD_BE ("00000004")},
00072         {"major version",              STATICTAG_EDIT_WORD_BE ("00000006")},
00073         {"constant pool count",        STATICTAG_EDIT_WORD_BE ("00000008")},
00074         {0, 0}
00075 };
00076 ht_mask_ptable cls_class2_hdr[] = 
00077 {
00078         {"access flags",               STATICTAG_EDIT_WORD_BE ("00000000")
00079 " "STATICTAG_FLAGS("00000000", ATOM_CLS_ACCESS_STR)},
00080         {"this class",                 STATICTAG_EDIT_WORD_BE ("00000002")},
00081         {"super class",                STATICTAG_EDIT_WORD_BE ("00000004")},
00082         {"interfaces count",           STATICTAG_EDIT_WORD_BE ("00000006")},
00083         {0, 0}
00084 };
00085 ht_mask_ptable cpool_class[] = 
00086 {
00087         {"name index",                 STATICTAG_EDIT_WORD_BE("00000001")},
00088         {0, 0}
00089 };
00090 ht_mask_ptable cpool_fmi[] =
00091 {
00092         {"class index",                STATICTAG_EDIT_WORD_BE("00000001")},
00093         {"name and type index",        STATICTAG_EDIT_WORD_BE("00000003")},
00094         {0, 0}
00095 };
00096 ht_mask_ptable cpool_str[] =
00097 {
00098         {"string index",               STATICTAG_EDIT_WORD_BE("00000001")},
00099         {0, 0}
00100 };
00101 ht_mask_ptable cpool_if[] = 
00102 {
00103         {"bytes",                      STATICTAG_EDIT_DWORD_BE("00000001")},
00104         {0, 0}
00105 };
00106 ht_mask_ptable cpool_ld[] = 
00107 {
00108         {"high bytes",                 STATICTAG_EDIT_DWORD_BE("00000001")},
00109         {"low bytes",                  STATICTAG_EDIT_DWORD_BE("00000005")},
00110         {0, 0}
00111 };
00112 ht_mask_ptable cpool_nat[] = 
00113 {
00114         {"name index",                 STATICTAG_EDIT_WORD_BE("00000001")},
00115         {"descriptor index",           STATICTAG_EDIT_WORD_BE("00000003")},
00116         {0, 0}
00117 };
00118 ht_mask_ptable cpool_utf8[] = 
00119 {
00120         {"length",                     STATICTAG_EDIT_WORD_BE("00000001")},
00121         {0, 0}
00122 };
00123 ht_mask_ptable cpool_hdr[] = 
00124 { 
00125         {"tag",                        STATICTAG_EDIT_BYTE("00000000")
00126 " "STATICTAG_DESC_BYTE("00000000", ATOM_CLS_CPOOL_STR)},
00127         {0, 0}
00128 };
00129 ht_mask_ptable iface_hdr[] = 
00130 {
00131         {"class name index",           STATICTAG_EDIT_WORD_BE("00000000")},
00132         {0, 0}
00133 };
00134 ht_mask_ptable field_hdr[] = 
00135 {
00136         {"fields count",               STATICTAG_EDIT_WORD_BE("00000000")},
00137         {0, 0}
00138 };
00139 ht_mask_ptable method_hdr[] = 
00140 {
00141         {"methods count",              STATICTAG_EDIT_WORD_BE("00000000")},
00142         {0, 0}
00143 };
00144 ht_mask_ptable mf_hdr[] = 
00145 {
00146         {"access flags",               STATICTAG_EDIT_WORD_BE ("00000000")
00147 " "STATICTAG_FLAGS("00000000", ATOM_CLS_ACCESS_STR)},
00148         {"name index",                 STATICTAG_EDIT_WORD_BE ("00000002")},
00149         {"descriptor index",           STATICTAG_EDIT_WORD_BE ("00000004")},
00150         {"attributes count",           STATICTAG_EDIT_WORD_BE ("00000006")},
00151         {0, 0}
00152 };
00153 ht_mask_ptable atr_hdr[] = 
00154 {
00155         {"attributes count",           STATICTAG_EDIT_WORD_BE("00000000")},
00156         {0, 0}
00157 };
00158 ht_mask_ptable aexpt_hdr[] = 
00159 {
00160         {"exception table length",     STATICTAG_EDIT_WORD_BE("00000000")},
00161         {0, 0}
00162 };
00163 ht_mask_ptable aexpt_info[] = 
00164 {
00165         {"start pc",                   STATICTAG_EDIT_WORD_BE ("00000000")},
00166         {"end pc",                     STATICTAG_EDIT_WORD_BE ("00000002")},
00167         {"handler pc",                 STATICTAG_EDIT_WORD_BE ("00000004")},
00168         {"catch type",                 STATICTAG_EDIT_WORD_BE ("00000006")},
00169         {0, 0}
00170 }; 
00171 ht_mask_ptable ainn_info[] = 
00172 {
00173         {"inner class info index",     STATICTAG_EDIT_WORD_BE ("00000000")},
00174         {"outer class info index",     STATICTAG_EDIT_WORD_BE ("00000002")},
00175         {"inner name index",           STATICTAG_EDIT_WORD_BE ("00000004")},
00176         {"inner class access flags",   STATICTAG_EDIT_WORD_BE ("00000006")
00177 " "STATICTAG_FLAGS("00000006", ATOM_CLS_ACCESS_STR)},
00178         {0, 0}
00179 };
00180 ht_mask_ptable aline_info[] = 
00181 {
00182         {"start pc",                   STATICTAG_EDIT_WORD_BE ("00000000")},
00183         {"line number",                STATICTAG_EDIT_WORD_BE ("00000002")},
00184         {0, 0}
00185 }; 
00186 ht_mask_ptable aloc_info[] = 
00187 {
00188         {"start pc",                   STATICTAG_EDIT_WORD_BE ("00000000")},
00189         {"length",                     STATICTAG_EDIT_WORD_BE ("00000002")},
00190         {"name index",                 STATICTAG_EDIT_WORD_BE ("00000004")},
00191         {"descriptor index",           STATICTAG_EDIT_WORD_BE ("00000006")},
00192         {"index",                      STATICTAG_EDIT_WORD_BE ("00000008")},
00193         {0, 0}
00194 };
00195 ht_mask_ptable axpt_info[] = 
00196 {
00197         {"exception",                  STATICTAG_EDIT_WORD_BE ("00000000")},
00198         {0, 0}
00199 };
00200 ht_mask_ptable attrib_hdr[] = 
00201 {
00202         {"attribute name index",       STATICTAG_EDIT_WORD_BE ("00000000")},
00203         {"attribute length",           STATICTAG_EDIT_DWORD_BE("00000002")},
00204         {0, 0}
00205 };
00206 ht_mask_ptable aconst_hdr[] = 
00207 {
00208         {"constantvalue index",        STATICTAG_EDIT_WORD_BE ("00000006")},
00209         {0, 0}
00210 };
00211 ht_mask_ptable acode_hdr[] = 
00212 {
00213         {"max stack",                  STATICTAG_EDIT_WORD_BE ("00000006")},
00214         {"max locals",                 STATICTAG_EDIT_WORD_BE ("00000008")},
00215         {"code length",                STATICTAG_EDIT_DWORD_BE("0000000a")},
00216         {0, 0}
00217 };
00218 ht_mask_ptable axpt_hdr[] = 
00219 {
00220         {"number of exceptions",       STATICTAG_EDIT_WORD_BE ("00000006")},
00221         {0, 0}
00222 };
00223 ht_mask_ptable ainn_hdr[] = 
00224 {
00225         {"number of classes",          STATICTAG_EDIT_WORD_BE ("00000006")},
00226         {0, 0}
00227 };
00228 ht_mask_ptable asrc_hdr[] = 
00229 {
00230         {"sourcefile index",           STATICTAG_EDIT_WORD_BE ("00000006")},
00231         {0, 0}
00232 };
00233 ht_mask_ptable alin_hdr[] = 
00234 {
00235         {"line_number table length",   STATICTAG_EDIT_WORD_BE ("00000006")},
00236         {0, 0}
00237 };
00238 ht_mask_ptable aloc_hdr[] = 
00239 {
00240         {"local variable table length",STATICTAG_EDIT_WORD_BE ("00000006")},
00241         {0, 0}
00242 };
00243 
00244 static void attrib_view(ht_group_sub *g, ht_streamfile *f,
00245                   unsigned *idx, classfile *c, attrib_info *a)
00246 {
00247   ht_group_sub *g2, *g3;
00248   ht_mask_sub *s, *s2;
00249   ht_collapsable_sub *cs, *cs2;
00250   attrib_info *atr;
00251   u4 code_len = 0;
00252   u2 tabl_len = 0;
00253   u1 inp[4];
00254   unsigned i, j;
00255   char info[128];
00256 
00257   s = new ht_mask_sub();
00258   s->init(f, (*idx)++);
00259   s->add_staticmask_ptable(attrib_hdr, a->offset, true);
00260   g->insertsub(s);
00261   switch (a->tag) {
00262     case ATTRIB_SourceFile:
00263          s->add_staticmask_ptable(asrc_hdr, a->offset, true);
00264          break;
00265     case ATTRIB_Code:
00266          s->add_staticmask_ptable(acode_hdr, a->offset, true);
00267             j = a->offset + 10;
00268             f->seek(j);
00269             f->read(inp, 4);
00270             j += 4;
00271             code_len = (((((((u4)inp[0]<<8)|inp[1])<<8)|inp[2])<<8)|inp[3]);
00272             j += code_len;
00273 
00274             s2 = new ht_mask_sub();
00275             s2->init (f, (*idx)++);
00276             s2->add_staticmask_ptable(aexpt_hdr, j, true);
00277             g->insertsub (s2);
00278             f->seek(j);
00279             f->read(inp, 2);
00280             j += 2;
00281             tabl_len = (((u2)inp[0]<<8)|inp[1]);
00282             g2 = new ht_group_sub();
00283             g2->init (f);
00284             if (!tabl_len) {
00285                  s2 = new ht_mask_sub();
00286                  s2->init(f, (*idx)++);
00287                  s2->add_mask("<none>");
00288                  g2->insertsub (s2);
00289             }
00290             for (i=0; i<tabl_len; i++) {
00291                  s2 = new ht_mask_sub();
00292                  s2->init(f, (*idx)++);
00293                  s2->add_staticmask_ptable(aexpt_info, j+i*8, true);
00294                  cs = new ht_collapsable_sub();
00295                  ht_snprintf(info, sizeof info, "exception table entry [%08x]:", i);
00296                  cs->init(f, s2, 1, info, 1);
00297                  g2->insertsub (cs);
00298             }
00299             j += tabl_len * 8;
00300             cs2 = new ht_collapsable_sub();
00301             cs2->init(f, g2, 1, "exception table", 1);
00302             g->insertsub (cs2);
00303 
00304             s2 = new ht_mask_sub();
00305             s2->init (f, (*idx)++);
00306             s2->add_staticmask_ptable(atr_hdr, j, true);
00307             g->insertsub (s2);
00308             f->seek(j);
00309             f->read(inp, 2);
00310             j += 2;
00311             tabl_len = (((u2)inp[0]<<8)|inp[1]);
00312             g2 = new ht_group_sub();
00313             g2->init (f);
00314             if (!tabl_len) {
00315                  s2 = new ht_mask_sub();
00316                  s2->init(f, (*idx)++);
00317                  s2->add_mask("<none>");
00318                  g2->insertsub (s2);
00319             }
00320             for (i=0; i<tabl_len; i++) {
00321                  g3 = new ht_group_sub();
00322                  g3->init(f);
00323                  f->seek (j);
00324                  atr = attribute_read (f, c);
00325                  atr->offset = j;
00326                  j += atr->len + 6;
00327                  attrib_view(g3, f, idx, c, atr);
00328                  cs = new ht_collapsable_sub();
00329                  ht_snprintf(info, sizeof info, "attribute entry [%08x]: %s", i,
00330                             c->cpool[atr->name]->value.string); 
00331                  free (atr);
00332                  cs->init(f, g3, 1, info, 1);
00333                  g2->insertsub (cs);
00334             }
00335             cs2 = new ht_collapsable_sub();
00336             cs2->init(f, g2, 1, "attributes", 1);
00337             g->insertsub (cs2);
00338          break;
00339     case ATTRIB_ConstantValue:
00340          s->add_staticmask_ptable(aconst_hdr, a->offset, true);
00341             break;
00342     case ATTRIB_LineNumberTable:
00343          s->add_staticmask_ptable(alin_hdr, a->offset, true);
00344             f->seek(a->offset+6);
00345             f->read(inp, 2);
00346             j = a->offset + 6 + 2;
00347             tabl_len = (((u2)inp[0]<<8)|inp[1]);
00348             g2 = new ht_group_sub();
00349             g2->init (f);
00350             if (!tabl_len) {
00351                  s2 = new ht_mask_sub();
00352                  s2->init(f, (*idx)++);
00353                  s2->add_mask("<none>");
00354                  g2->insertsub (s2);
00355             }
00356             for (i=0; i<tabl_len; i++) {
00357                  s2 = new ht_mask_sub();
00358                  s2->init(f, (*idx)++);
00359                  s2->add_staticmask_ptable(aline_info, j+i*4, true);
00360                  cs = new ht_collapsable_sub();
00361                  ht_snprintf(info, sizeof info, "line number table entry [%08x]:", i);
00362                  cs->init(f, s2, 1, info, 1);
00363                  g2->insertsub (cs);
00364             }
00365             cs2 = new ht_collapsable_sub();
00366             cs2->init(f, g2, 1, "line number table", 1);
00367             g->insertsub (cs2);
00368             break;
00369     case ATTRIB_InnerClasses:
00370          s->add_staticmask_ptable(ainn_hdr, a->offset, true);
00371             f->seek(a->offset+6);
00372             f->read(inp, 2);
00373             j = a->offset + 6 + 2;
00374             tabl_len = (((u2)inp[0]<<8)|inp[1]);
00375             g2 = new ht_group_sub();
00376             g2->init (f);
00377             if (!tabl_len) {
00378                  s2 = new ht_mask_sub();
00379                  s2->init(f, (*idx)++);
00380                  s2->add_mask("<none>");
00381                  g2->insertsub (s2);
00382             }
00383             for (i=0; i<tabl_len; i++) {
00384                  s2 = new ht_mask_sub();
00385                  s2->init(f, (*idx)++);
00386                  s2->add_staticmask_ptable(ainn_info, j+i*8, true);
00387                  cs = new ht_collapsable_sub();
00388                  ht_snprintf(info, sizeof info, "classes entry [%08x]:", i);
00389                  cs->init(f, s2, 1, info, 1);
00390                  g2->insertsub (cs);
00391             }
00392             cs2 = new ht_collapsable_sub();
00393             cs2->init(f, g2, 1, "classes", 1);
00394             g->insertsub (cs2);
00395             break;
00396     case ATTRIB_Exceptions:
00397          s->add_staticmask_ptable(axpt_hdr, a->offset, true);
00398             f->seek(a->offset+6);
00399             f->read(inp, 2);
00400             j = a->offset + 6 + 2;
00401             tabl_len = (((u2)inp[0]<<8)|inp[1]);
00402             g2 = new ht_group_sub();
00403             g2->init (f);
00404             if (!tabl_len) {
00405                  s2 = new ht_mask_sub();
00406                  s2->init(f, (*idx)++);
00407                  s2->add_mask("<none>");
00408                  g2->insertsub (s2);
00409             }
00410             for (i=0; i<tabl_len; i++) {
00411                  s2 = new ht_mask_sub();
00412                  s2->init(f, (*idx)++);
00413                  s2->add_staticmask_ptable(ainn_info, j+i*2, true);
00414                  cs = new ht_collapsable_sub();
00415                  ht_snprintf(info, sizeof info, "exception index table entry [%08x]:", i);
00416                  cs->init(f, s2, 1, info, 1);
00417                  g2->insertsub (cs);
00418             }
00419             cs2 = new ht_collapsable_sub();
00420             cs2->init(f, g2, 1, "exception index table", 1);
00421             g->insertsub (cs2);
00422             break;
00423     case ATTRIB_LocalVariableTable:
00424          s->add_staticmask_ptable(aloc_hdr, a->offset, true);
00425             f->seek(a->offset+6);
00426             f->read(inp, 2);
00427             j = a->offset + 6 + 2;
00428             tabl_len = (((u2)inp[0]<<8)|inp[1]);
00429             g2 = new ht_group_sub();
00430             g2->init (f);
00431             if (!tabl_len) {
00432                  s2 = new ht_mask_sub();
00433                  s2->init(f, (*idx)++);
00434                  s2->add_mask("<none>");
00435                  g2->insertsub (s2);
00436             }
00437             for (i=0; i<tabl_len; i++) {
00438                  s2 = new ht_mask_sub();
00439                  s2->init(f, (*idx)++);
00440                  s2->add_staticmask_ptable(aloc_info, j+i*10, true);
00441                  cs = new ht_collapsable_sub();
00442                  ht_snprintf(info, sizeof info, "local variable table entry [%08x]:", i);
00443                  cs->init(f, s2, 1, info, 1);
00444                  g2->insertsub (cs);
00445             }
00446             cs2 = new ht_collapsable_sub();
00447             cs2->init(f, g2, 1, "local variable table", 1);
00448             g->insertsub (cs2);
00449             break;
00450     case ATTRIB_Synthetic:
00451     case ATTRIB_Deprecated:
00452     default:
00453          break;
00454   }
00455 }
00456 
00457 static void mf_view(ht_group_sub *g, ht_streamfile *f,
00458            unsigned *idx, classfile *c, mf_info *mf)
00459 {
00460         ht_group_sub *g2, *g3;
00461         ht_mask_sub *s;
00462         ht_collapsable_sub *cs, *cs2;
00463         char info[128];
00464 
00465         s = new ht_mask_sub();
00466         s->init(f, (*idx)++);
00467         s->add_staticmask_ptable(mf_hdr, mf->offset, true);
00468         g->insertsub(s);
00469 
00470         g2 = new ht_group_sub();
00471         g2->init (f);
00472         if (!mf->attribs_count) {
00473                 s = new ht_mask_sub();
00474                 s->init(f, (*idx)++);
00475                 s->add_mask("<none>");
00476                 g2->insertsub (s);
00477         }
00478         for (UINT i=0; i<mf->attribs_count; i++) {
00479                 g3 = new ht_group_sub();
00480                 g3->init(f);
00481                 attrib_view(g3, f, idx, c, mf->attribs[i]);
00482                 cs = new ht_collapsable_sub();
00483                 ht_snprintf(info, sizeof info, "attribute entry [%08x]: %s", i, c->cpool[mf->attribs[i]->name]->value.string);
00484                 cs->init(f, g3, 1, info, 1);
00485                 g2->insertsub (cs);
00486         }
00487         cs2 = new ht_collapsable_sub();
00488         cs2->init(f, g2, 1, "attributes", 1);
00489         g->insertsub (cs2);
00490 }
00491 
00492 static ht_view *class_view(bounds *b, ht_streamfile *file, ht_format_group *group)
00493 {
00494   ht_mask_sub *s;
00495   ht_collapsable_sub *cs, *cs2;
00496   ht_group_sub *g, *g2, *g3;
00497   classfile *clazz;
00498   char info[128];
00499   unsigned i, j, idx = 0;
00500 
00501   clazz = ((ht_class_shared_data *)group->get_shared_data())->file;
00502   if (clazz) {
00503     ht_uformat_viewer *v = new ht_uformat_viewer();
00504     v->init(b, DESC_JAVA_HEADERS, VC_EDIT, file, group);
00505     register_atom(ATOM_CLS_ACCESS, access_flags);
00506     register_atom(ATOM_CLS_CPOOL,  cpool_tags);
00507 
00508     g = new ht_group_sub();
00509     g->init(file);
00510   
00511     s = new ht_mask_sub();
00512     s->init(file, idx++);
00513     s->add_staticmask_ptable(cls_class1_hdr, clazz->offset, true);
00514     g->insertsub(s);
00515 
00516     g2 = new ht_group_sub();
00517     g2->init (file);
00518     for (i=1; i<clazz->cpool_count; i++) {
00519          s = new ht_mask_sub();
00520          s->init(file, idx++);
00521          s->add_staticmask_ptable(cpool_hdr, clazz->cpool[i]->offset, true);
00522          switch (clazz->cpool[i]->tag) {
00523          case CONSTANT_Utf8:
00524            s->add_staticmask_ptable(cpool_utf8, clazz->cpool[i]->offset, true);
00525            break;
00526          case CONSTANT_Integer:
00527          case CONSTANT_Float:
00528            s->add_staticmask_ptable(cpool_if, clazz->cpool[i]->offset, true);
00529            break;
00530          case CONSTANT_Long:
00531          case CONSTANT_Double:
00532            s->add_staticmask_ptable(cpool_ld, clazz->cpool[i]->offset, true);
00533            break;
00534          case CONSTANT_Class:
00535            s->add_staticmask_ptable(cpool_class, clazz->cpool[i]->offset, true);
00536            break;
00537          case CONSTANT_String:
00538            s->add_staticmask_ptable(cpool_str, clazz->cpool[i]->offset, true);
00539            break;
00540          case CONSTANT_Fieldref:
00541          case CONSTANT_Methodref:
00542          case CONSTANT_InterfaceMethodref:
00543            s->add_staticmask_ptable(cpool_fmi, clazz->cpool[i]->offset, true);
00544            break;
00545          case CONSTANT_NameAndType:
00546            s->add_staticmask_ptable(cpool_nat, clazz->cpool[i]->offset, true);
00547            break;
00548          }
00549          cs = new ht_collapsable_sub();
00550          ht_snprintf(info, sizeof info, "constant pool entry [%08x]: %s", i,
00551                     (clazz->cpool[i]->tag == CONSTANT_Utf8) 
00552                     ? clazz->cpool[i]->value.string : "");
00553          cs->init(file, s, 1, info, 1);
00554          g2->insertsub (cs);
00555                 if ((clazz->cpool[i]->tag == CONSTANT_Long) ||
00556                 (clazz->cpool[i]->tag == CONSTANT_Double)) {
00557                                 i++;
00558                 }
00559         }
00560     cs2 = new ht_collapsable_sub();
00561     cs2->init(file, g2, 1, "constant pool", 1);
00562     g->insertsub (cs2);
00563 
00564     s = new ht_mask_sub();
00565     s->init(file, idx++);
00566     s->add_staticmask_ptable(cls_class2_hdr, clazz->coffset, true);
00567     g->insertsub(s);
00568 
00569     g2 = new ht_group_sub();
00570     g2->init (file);
00571     if (!clazz->interfaces_count) {
00572          s = new ht_mask_sub();
00573          s->init(file, idx++);
00574          s->add_mask("<none>");
00575          g2->insertsub (s);
00576     }
00577     for (i=0; i<clazz->interfaces_count; i++) {
00578          s = new ht_mask_sub();
00579          s->init(file, idx++);
00580          s->add_staticmask_ptable(iface_hdr, clazz->coffset+8+i*2, true);
00581          cs = new ht_collapsable_sub();
00582          j = clazz->cpool[clazz->interfaces[i]]->value.llval[0];
00583          ht_snprintf(info, sizeof info, "interface entry [%08x]: %s", i,
00584                     clazz->cpool[j]->value.string);
00585          cs->init(file, s, 1, info, 1);
00586          g2->insertsub (cs);
00587     }
00588     cs2 = new ht_collapsable_sub();
00589     cs2->init(file, g2, 1, "interfaces", 1);
00590     g->insertsub (cs2);
00591 
00592     s = new ht_mask_sub();
00593     s->init(file, idx++);
00594     s->add_staticmask_ptable(field_hdr, clazz->foffset, true);
00595     g->insertsub(s);
00596     g2 = new ht_group_sub();
00597     g2->init (file);
00598     if (!clazz->fields_count) {
00599          s = new ht_mask_sub();
00600          s->init(file, idx++);
00601          s->add_mask("<none>");
00602          g2->insertsub (s);
00603     }
00604     for (i=0; i<clazz->fields_count; i++) {
00605          g3 = new ht_group_sub();
00606          g3->init(file);
00607          mf_view(g3, file, &idx, clazz, clazz->fields[i]);
00608          cs = new ht_collapsable_sub();
00609          ht_snprintf(info, sizeof info, "field entry [%08x]: %s", i, clazz->fields[i]->name);
00610          cs->init(file, g3, 1, info, 1);
00611          g2->insertsub (cs);
00612     }
00613     cs2 = new ht_collapsable_sub();
00614     cs2->init(file, g2, 1, "fields", 1);
00615     g->insertsub (cs2);
00616 
00617     s = new ht_mask_sub();
00618     s->init(file, idx++);
00619     s->add_staticmask_ptable(method_hdr, clazz->moffset, true);
00620     g->insertsub(s);
00621     g2 = new ht_group_sub();
00622     g2->init (file);
00623     if (!clazz->methods_count) {
00624          s = new ht_mask_sub();
00625          s->init(file, idx++);
00626          s->add_mask("<none>");
00627          g2->insertsub (s);
00628     }
00629     for (i=0; i<clazz->methods_count; i++) {
00630          g3 = new ht_group_sub();
00631          g3->init(file);
00632          mf_view(g3, file, &idx, clazz, clazz->methods[i]);
00633          cs = new ht_collapsable_sub();
00634          ht_snprintf(info, sizeof info, "method entry [%08x]: %s", i, clazz->methods[i]->name);
00635          cs->init(file, g3, 1, info, 1);
00636          g2->insertsub (cs);
00637     }
00638     cs2 = new ht_collapsable_sub();
00639     cs2->init(file, g2, 1, "methods", 1);
00640     g->insertsub (cs2);
00641 
00642     s = new ht_mask_sub();
00643     s->init(file, idx++);
00644     s->add_staticmask_ptable(atr_hdr, clazz->aoffset, true);
00645     g->insertsub(s);
00646     g2 = new ht_group_sub();
00647     g2->init (file);
00648     if (!clazz->attribs_count) {
00649          s = new ht_mask_sub();
00650          s->init(file, idx++);
00651          s->add_mask("<none>");
00652          g2->insertsub (s);
00653     }
00654     for (i=0; i<clazz->attribs_count; i++) {
00655          g3 = new ht_group_sub();
00656          g3->init(file);
00657          attrib_view(g3, file, &idx, clazz, clazz->attribs[i]);
00658          cs = new ht_collapsable_sub();
00659          j = clazz->attribs[i]->name;
00660          ht_snprintf(info, sizeof info, "attribute entry [%08x]: %s", i,
00661                     clazz->cpool[j]->value.string);
00662          cs->init(file, g3, 1, info, 1);
00663          g2->insertsub (cs);
00664     }
00665     cs2 = new ht_collapsable_sub();
00666     cs2->init(file, g2, 1, "attributes", 1);
00667     g->insertsub (cs2);
00668 
00669     v->insertsub(g);
00670     return v;
00671   } else {
00672     return NULL;
00673   }
00674 }
00675 
00676 void cview::init(bounds *b, ht_streamfile *f, format_viewer_if **ifs,
00677                   ht_format_group *g, FILEOFS header_ofs, void *shared)
00678 {
00679         ht_format_group::init(b, VO_SELECTABLE | VO_BROWSABLE | VO_RESIZE, DESC_JAVA, f, false, true, 0, g);
00680 
00681         shared_data = shared;
00682         ht_format_group::init_ifs(ifs);
00683 }
00684 
00685 void cview::done()
00686 {
00687         ht_format_group::done();
00688         ht_class_shared_data *clazz = (ht_class_shared_data *)shared_data;
00689         if (clazz) {
00690                 class_unread(clazz);
00691         }
00692 }
00693 
00694 static format_viewer_if htcls_cview = {
00695         &class_view,
00696         0
00697 };
00698 
00699 static format_viewer_if *htcls_ifs[] = {
00700         &htcls_cview,
00701         &htclassimage_if,
00702         0
00703 };
00704 
00705 static ht_view *class_init(bounds *b, ht_streamfile *file, ht_format_group *group)
00706 {
00707         u1 magic[4];
00708 
00709         file->seek(0);
00710         file->read(magic, 4);
00711         if ((magic[0] == 0xca) && (magic[1] == 0xfe)
00712         && (magic[2] == 0xba) && (magic[3] == 0xbe)) {
00713                 file->seek(0);
00714                 void *shared_data = (void*)class_read(file);
00715                 if (!shared_data) return NULL;
00716                 cview *c = new cview();
00717                 c->init(b, file, htcls_ifs, group, 0, shared_data);
00718                 return c;
00719         }
00720         return NULL;
00721 }
00722 
00723 format_viewer_if htcls_if = {
00724         &class_init,
00725         0
00726 };
00727 

Generated on Fri May 7 21:15:29 2004 by doxygen 1.3.5