static void analyze_parents (void) { unsigned short dtype; printf ("Analyzing Parents\n"); if (rchar ()) { fprintf (mfp,"Has parent table : YES\n"); } else { fprintf (mfp,"Has parent table : NO\n"); return; } for (;;) { dtype = rshort (); if (dtype == TERMINATOR) break; /* Read number of parents. */ (void) rshort (); /* Read number of generics. */ (void) rshort (); /* Read dynamic type */ fprintf (mfp, "[%d, ", rshort ()); if (rchar ()) fprintf (mfp, "E, "); /* Expanded */ else fprintf (mfp, " "); /* Not expanded */ dtype = rshort(); while (dtype != TERMINATOR) { if (dtype == PARENT_TYPE_SEPARATOR) { fprintf (mfp, "| "); } else { fprintf (mfp, "%d ", dtype); } dtype = rshort (); } fprintf (mfp, "]\n"); } print_line (); analyze_cecil (); }
static ssize_t rinteger(struct rcontext* context) { ssize_t r; if (rchar(context) != 'i') { longjmp(context->error, 0); } r = ri(context); if (rchar(context) != 'e') { longjmp(context->error, 0); } return r; }
ssize_t proto_decode(struct proto* proto, const char* in, ssize_t length) { struct rcontext context; context.p = (char*)in; context.e = (char*)in + length; if (setjmp(context.error) > 0) { return 0; } memset(proto, 0, sizeof(struct proto)); if (rchar(&context) == 'd') { struct lv name; while (rchar(&context) != 'e') { --context.p; rlv(&context, &name); if (lv_eq("type", &name)) { proto->type = rinteger(&context); } if (lv_eq("id", &name)) { rlv(&context, &proto->id); } if (lv_eq("rid", &name)) { rlv(&context, &proto->rid); } if (lv_eq("key", &name)) { rlv(&context, &proto->key); } if (lv_eq("weight", &name)) { proto->parameters.weight = rinteger(&context); } if (lv_eq("priority", &name)) { proto->parameters.priority = rinteger(&context); } if (lv_eq("hwaddr", &name)) { struct lv lv; rlv(&context, &lv); if (lv.length == sizeof(proto->parameters.hwaddr)) { memcpy(&proto->parameters.hwaddr, lv.value, lv.length); } } } } else { proto->type = PROTO_DATA; proto->data.value = context.p; proto->data.length = context.e - context.p; context.p = context.e; } return context.p - in; }
/*------------------------------------------------------------------*/ static void analyze_root (void) { uint32 nb_roots, i, slen; nb_roots = rlong(); fprintf(mfp, "Number of roots is %d\n", nb_roots); for (i = 0; i < nb_roots; i++) { fprintf(mfp, "Root class/feature name: "); slen = rlong(); while (slen--) { fprintf (mfp, "%c", rchar()); ++i; } fprintf (mfp,"\nRoot class routine ID: %d\n", rlong ()); /* Root type computation */ (void) rlong (); /* Read dynamic type of ANY. */ fprintf (mfp,"Root type description: "); { short t; fprintf (mfp, "{"); while ((t = rshort())!=-1) { fprintf (mfp, "%d, ", (int) t); } fprintf (mfp, "-1}"); fprintf (mfp, "\n"); } fprintf (mfp,"Root class arguments : %d\n", rlong ()); } }
static void analyze_options (void) { short dtype, dbcount, slen, i; char dbg_level; printf ("Analyzing Options\n"); for (;;) { dtype = rshort (); if (dtype == -1) break; fprintf (mfp,"Dynamic type : %d\n", (int) dtype); fprintf (mfp,"Assertion kind : %d\n", (int) rshort ()); dbg_level = rchar (); if (dbg_level == BCDB_TAG || dbg_level == BCDB_UNNAMED) { dbcount = rshort (); fprintf (mfp,"Debug keys : %d\n", (int) dbcount); i = dbcount; while (i--) { fprintf (mfp," Name : "); slen = rshort (); while (slen--) fprintf (mfp,"%c", rchar ()); fprintf (mfp,"\n"); } } fprintf (mfp,"Trace level : %d\n", (int) rchar ()); fprintf (mfp,"Profile level : %d\n", (int) rchar ()); } print_line (); }
static void analyze_file (void) { if (rchar ()) { fprintf (mfp, "Needs update : YES\n"); } else { fprintf (mfp,"Needs update : NO\n"); return; } print_line (); if (rchar ()) { fprintf (mfp, "Non-IEEE comparison for floating points\n"); } else { fprintf (mfp, "IEEE comparison for floating points\n"); } fprintf (mfp,"Nr. of class types : %d\n", rlong ()); fprintf (mfp,"Nr. of classes : %d\n", rlong ()); fprintf (mfp,"Nr. of original routine bodies : %d\n", rlong ()); print_line (); fprintf (mfp,"Profile level : %d\n", rlong ()); print_line (); analyze_cnodes (); read_byte_code (); analyze_parents (); analyze_options (); analyze_routinfo (); analyze_desc (); analyze_root (); print_line (); }
static void rlv(struct rcontext* context, struct lv* lv) { lv->length = ri(context); if (rchar(context) != ':') { longjmp(context->error, 0); } lv->value = context->p; if (context->p + lv->length >= context->e) { longjmp(context->error, 0); } context->p += lv->length; }
static void analyze_cecil (void) { int i, j; short slen, tsize, nb_generics, nb_types, dynamic_type; char *s; printf ("Analyzing Cecil\n"); /* Print two tables: non-gneric and generic */ for (j = 0, s = "Non generic table size : %d\n"; j < 2; j ++, s = "Generic table size : %d\n") { tsize = rshort (); fprintf (mfp, s, (int) tsize); i = (int) tsize; while (i--) { fprintf (mfp," Name : "); slen = rshort (); while (slen--) { fprintf (mfp,"%c", rchar ()); } fprintf (mfp,"\n"); } i = (int) tsize; while (i--) { nb_generics = rshort (); dynamic_type = rshort (); fprintf (mfp," Dynamic type : %d, Generics : %d\n", (int) dynamic_type, (int) nb_generics); if (nb_generics) { nb_types = rshort (); fprintf (mfp," Types : %d\n", (int) nb_types); rseq ((int) (nb_generics * nb_types * sizeof (int32))); rseq ((int) (nb_types * sizeof (int16))); } } } print_line (); }
static void analyze_desc (void) { long count, tid, info, type, offset, i, j; short org_count, info_count, org_id; short *dinfo; char c; printf ("Analyzing Desc\n"); fprintf (mfp,"Descriptors : (desc_tab)\n"); while ((count = rlong()) != -1L) { while (count-- > 0) { tid = (long) rshort (); org_count = rshort (); while (org_count-- > 0) { org_id = rshort (); fprintf (mfp,"Origin_id %5d Dtype_id %8ld\n", (int) org_id, tid); info_count = rshort (); dinfo = NULL; if (info_count < 0) { panic(); } else if (info_count > 0) { dinfo = (short *) malloc (3*info_count * sizeof (short)); if (dinfo == (short *) 0) { fprintf (stderr,"Out of memory\n"); panic (); } } i = 0; j = info_count; while (j--) { c = rchar(); type = (long) rshort(); if (c && (type != -1)) { while (rshort() != -1) { } } info = (long) rbody_index (); offset = (long) ruint32 (); dinfo [i++] = (short) info; dinfo [i++] = (short) offset; dinfo [i++] = (short) type; } fprintf (mfp, "desc_tab [%d][%ld] = ", org_id, tid-1); for (i = 0; i < info_count; ++i) { if ((i % 8) == 0) { fprintf (mfp, "\n "); } fprintf (mfp, "%ld: (%d,%d,%d) ", i, dinfo [3*i], dinfo [3*i+1], dinfo [3 * i + 2]); } fprintf (mfp, "\n"); if (dinfo != (short *) 0) { free ((char *) dinfo); } } } } print_line (); }
static void analyze_cnodes (void) { long count, acount, pers_acount, i; short slen, dtype; char *dname; printf ("Analyzing Cnodes\n"); count = rlong (); fprintf (mfp,"Cnode update entries : %ld\n", count); if (!count) print_line (); while (count--) { dtype = rshort (); fprintf (mfp,"Dynamic class type : %d\n", (int) dtype); fprintf (mfp,"Generating class : "); slen = rshort (); dname = malloc (slen + 2); if (dname == (char *) 0) { fprintf (stderr, "Out of memory\n"); panic (); } i = 0; while (slen--) { dname [i] = rchar (); fprintf (mfp,"%c", dname [i]); ++i; } dname [i] = '\0'; fprintf (mfp,"\n"); acount = rlong (); pers_acount = rlong (); fprintf (mfp,"Nr. of attributes : %ld\n", acount); fprintf (mfp,"Nr. of persistent attributes : %ld\n", pers_acount); i = acount; while (i--) { fprintf (mfp," Attribute name : "); slen = rshort (); while (slen--) fprintf (mfp,"%c", rchar ()); fprintf (mfp,"\n"); } i = acount; while (i--) { fprintf (mfp," Attribute type : "); print_dtype (ruint32()); fprintf (mfp, "\n"); } /* Read attribute flags. */ i = acount; while (i--) { fprintf (mfp," Attribute flags: "); fprintf (mfp, "%d ", (int) rshort()); } fprintf (mfp, "\n"); i = acount; while (i--) { fprintf (mfp," Full Attribute type : "); if (rshort ()) { short t; fprintf (mfp, "{"); while ((t = rshort())!=-1) fprintf (mfp, "%d, ", (int) t); fprintf (mfp, "-1}"); } fprintf (mfp, "\n"); } fprintf (mfp,"Skeleton flags are : 0x%x\n", (int) rshort ()); fprintf (mfp,"Attribute ids : %ld\n", acount); i = acount; while (i--) { fprintf (mfp," Id : %d\n", ruint32 ()); } fprintf (mfp,"Reference number : %d\n", rlong ()); fprintf (mfp,"Node size : %d\n", rlong ()); fprintf (mfp,"Routine creation id: %d\n", ruint32 ()); fprintf (mfp,"Version : "); slen = rshort (); if (slen) { while (slen--) { fprintf (mfp,"%c", rchar ()); } } else { fprintf (mfp, "NULL"); } fprintf (mfp, "\n"); print_line (); } }
static void prepare_types (void) { long count, acount, i; short slen, dtype; char *dname; (void) rchar (); /* Is there something to read */ (void) rchar (); /* Are we biding to IEEE arithmetic .*/ (void) rlong (); /* class types count */ (void) rlong (); /* class count */ (void) rlong (); /* number of original routine bodies */ (void) rlong (); /* prof enabled */ dtype_size = MAX_TYPE; dtype_max = -1; dtype_names = (char **) malloc (dtype_size * sizeof (char *)); if (dtype_names == (char **) 0) { fprintf (stderr, "Out of memory\n"); panic (); } else { memset (dtype_names, 0, dtype_size * sizeof (char *)); } ctype_size = MAX_TYPE; ctype_max = -1; ctype_names = (char **) malloc (ctype_size * sizeof (char *)); if (ctype_names == (char **) 0) { fprintf (stderr, "Out of memory\n"); panic (); } else { memset (ctype_names, 0, ctype_size * sizeof (char *)); } count = rlong (); /* Number of feature table update. */ if (count < 0) { panic (); } while (count--) { dtype = rshort (); if (dtype < 0) { panic (); } slen = rshort (); dname = malloc (slen + 2); if (dname == (char *) 0) { fprintf (stderr, "Out of memory\n"); panic (); } i = 0; while (slen--) { dname [i] = rchar (); ++i; } dname [i] = '\0'; if (dtype > dtype_max) dtype_max = dtype; if (dtype >= dtype_size) { int old_size = dtype_size; dtype_size = dtype + 256; dtype_names = (char **) realloc ((char *) dtype_names, dtype_size * sizeof (char *)); if (dtype_names == (char **) 0) { fprintf (stderr, "Out of memory\n"); panic (); } else { memset (dtype_names + old_size, 0, (dtype_size - old_size) * sizeof (char *)); } } dtype_names [dtype] = dname; acount = rlong (); /* Number of attributes. */ (void) rlong (); /* Number of persistent attributes. */ i = acount; /* Read attribute name. */ while (i--) { slen = rshort (); while (slen--) (void) rchar (); } i = acount; /* Read attribute types. */ while (i--) { (void) ruint32 (); } i = acount; /* Read attribute flags. */ while (i--) { (void) rshort (); } i = acount; /* Read attribute full types. */ while (i--) { while (rshort() != -1) ; } (void) rshort(); /* Skeleton flags */ i = acount; /* Read attribute routine ID array. */ while (i--) (void) ruint32 (); (void) rlong (); /* Number of references. */ (void) rlong (); /* Size of node. */ (void) ruint32 (); /* Creation Routine ID. */ /* Read Version info if any. */ slen = rshort (); while (slen--) { (void) rchar (); } } }