2 * dump.c: Dumping routines for the disassembler.
5 * Miguel de Icaza (miguel@ximian.com)
7 * (C) 2001 Ximian, Inc.
17 #include "mono/metadata/loader.h"
18 #include "mono/metadata/class.h"
21 dump_table_assembly (MonoImage *m)
23 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLY];
24 guint32 cols [MONO_ASSEMBLY_SIZE];
28 fprintf (output, "Assembly Table\n");
33 mono_metadata_decode_row (t, 0, cols, MONO_ASSEMBLY_SIZE);
35 fprintf (output, "Name: %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_NAME]));
36 fprintf (output, "Hash Algoritm: 0x%08x\n", cols [MONO_ASSEMBLY_HASH_ALG]);
37 fprintf (output, "Version: %d.%d.%d.%d\n", cols [MONO_ASSEMBLY_MAJOR_VERSION],
38 cols [MONO_ASSEMBLY_MINOR_VERSION],
39 cols [MONO_ASSEMBLY_BUILD_NUMBER],
40 cols [MONO_ASSEMBLY_REV_NUMBER]);
41 fprintf (output, "Flags: 0x%08x\n", cols [MONO_ASSEMBLY_FLAGS]);
42 fprintf (output, "PublicKey: BlobPtr (0x%08x)\n", cols [MONO_ASSEMBLY_PUBLIC_KEY]);
44 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLY_PUBLIC_KEY]);
45 len = mono_metadata_decode_value (ptr, &ptr);
47 fprintf (output, "\tDump:");
48 hex_dump (ptr, 0, len);
49 fprintf (output, "\n");
51 fprintf (output, "\tZero sized public key\n");
53 fprintf (output, "Culture: %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_CULTURE]));
54 fprintf (output, "\n");
58 dump_table_typeref (MonoImage *m)
60 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEREF];
63 fprintf (output, "Typeref Table\n");
65 for (i = 1; i <= t->rows; i++){
66 char *s = get_typeref (m, i);
68 fprintf (output, "%d: %s\n", i, s);
71 fprintf (output, "\n");
75 dump_table_typedef (MonoImage *m)
77 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEDEF];
80 fprintf (output, "Typedef Table\n");
82 for (i = 1; i <= t->rows; i++){
83 char *s = get_typedef (m, i);
84 guint32 cols [MONO_TYPEDEF_SIZE];
86 mono_metadata_decode_row (&m->tables [MONO_TABLE_TYPEDEF], i - 1, cols, MONO_TYPEDEF_SIZE);
88 fprintf (output, "%d: %s (flist=%d, mlist=%d, flags=0x%x, extends=0x%x)\n", i, s,
89 cols [MONO_TYPEDEF_FIELD_LIST], cols [MONO_TYPEDEF_METHOD_LIST],
90 cols [MONO_TYPEDEF_FLAGS], cols [MONO_TYPEDEF_EXTENDS]);
93 fprintf (output, "\n");
97 dump_table_typespec (MonoImage *m)
99 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPESPEC];
102 fprintf (output, "Typespec Table\n");
104 for (i = 1; i <= t->rows; i++){
105 char *typespec = get_typespec (m, i);
107 fprintf (output, "%d: %s\n", i, typespec);
110 fprintf (output, "\n");
114 dump_table_assemblyref (MonoImage *m)
116 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLYREF];
119 fprintf (output, "AssemblyRef Table\n");
121 for (i = 0; i < t->rows; i++){
124 guint32 cols [MONO_ASSEMBLYREF_SIZE];
126 mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
127 fprintf (output, "%d: Version=%d.%d.%d.%d\n\tName=%s\n", i + 1,
128 cols [MONO_ASSEMBLYREF_MAJOR_VERSION],
129 cols [MONO_ASSEMBLYREF_MINOR_VERSION],
130 cols [MONO_ASSEMBLYREF_BUILD_NUMBER],
131 cols [MONO_ASSEMBLYREF_REV_NUMBER],
132 mono_metadata_string_heap (m, cols [MONO_ASSEMBLYREF_NAME]));
133 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLYREF_PUBLIC_KEY]);
134 len = mono_metadata_decode_value (ptr, &ptr);
136 fprintf (output, "\tPublic Key:");
137 hex_dump (ptr, 0, len);
138 fprintf (output, "\n");
140 fprintf (output, "\tZero sized public key\n");
143 fprintf (output, "\n");
147 dump_table_param (MonoImage *m)
149 MonoTableInfo *t = &m->tables [MONO_TABLE_PARAM];
152 fprintf (output, "Param Table\n");
154 for (i = 0; i < t->rows; i++){
155 guint32 cols [MONO_PARAM_SIZE];
157 mono_metadata_decode_row (t, i, cols, MONO_PARAM_SIZE);
158 fprintf (output, "%d: 0x%04x %d %s\n",
160 cols [MONO_PARAM_FLAGS], cols [MONO_PARAM_SEQUENCE],
161 mono_metadata_string_heap (m, cols [MONO_PARAM_NAME]));
163 fprintf (output, "\n");
167 dump_table_field (MonoImage *m)
169 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELD];
170 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
171 MonoTableInfo *fl = &m->tables [MONO_TABLE_FIELDLAYOUT];
172 MonoTableInfo *rva = &m->tables [MONO_TABLE_FIELDRVA];
173 int i, current_type, offset_row, rva_row;
174 guint32 first_m, last_m;
176 fprintf (output, "Field Table (1..%d)\n", t->rows);
178 rva_row = offset_row = current_type = 1;
179 last_m = first_m = 1;
180 for (i = 1; i <= t->rows; i++){
181 guint32 cols [MONO_FIELD_SIZE];
185 * Find the next type.
187 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_FIELD_LIST))) {
191 fprintf (output, "########## %s.%s\n",
192 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
193 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
196 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_SIZE);
197 sig = get_field_signature (m, cols [MONO_FIELD_SIGNATURE]);
198 flags = field_flags (cols [MONO_FIELD_FLAGS]);
199 fprintf (output, "%d: %s %s: %s\n",
202 mono_metadata_string_heap (m, cols [MONO_FIELD_NAME]),
206 if (offset_row <= fl->rows && (mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_FIELD) == i)) {
207 fprintf (output, "\texplicit offset: %d\n", mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_OFFSET));
210 if (rva_row <= rva->rows && (mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_FIELD) == i)) {
211 fprintf (output, "\trva: %d\n", mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_RVA));
215 fprintf (output, "\n");
219 dump_table_memberref (MonoImage *m)
221 MonoTableInfo *t = &m->tables [MONO_TABLE_MEMBERREF];
225 const char *blob, *ks;
227 fprintf (output, "MemberRef Table (1..%d)\n", t->rows);
229 for (i = 0; i < t->rows; i++){
230 guint32 cols [MONO_MEMBERREF_SIZE];
232 mono_metadata_decode_row (t, i, cols, MONO_MEMBERREF_SIZE);
234 kind = cols [MONO_MEMBERREF_CLASS] & 7;
235 idx = cols [MONO_MEMBERREF_CLASS] >> 3;
237 x = g_strdup ("UNHANDLED CASE");
241 ks = "TypeDef"; break;
244 xx = get_typeref (m, idx);
245 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
249 ks = "ModuleRef"; break;
251 ks = "MethodDef"; break;
254 xx = get_typespec (m, idx);
255 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
259 g_error ("Unknown tag: %d\n", kind);
261 blob = mono_metadata_blob_heap (m, cols [MONO_MEMBERREF_SIGNATURE]);
262 mono_metadata_decode_blob_size (blob, &blob);
263 if (*blob == 0x6) { /* it's a field */
264 sig = get_field_signature (m, cols [MONO_MEMBERREF_SIGNATURE]);
266 sig = get_methodref_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL);
268 fprintf (output, "%d: %s[%d] %s\n\tResolved: %s\n\tSignature: %s\n\t\n",
271 mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]),
282 dump_table_class_layout (MonoImage *m)
284 MonoTableInfo *t = &m->tables [MONO_TABLE_CLASSLAYOUT];
286 fprintf (output, "ClassLayout Table (1..%d)\n", t->rows);
288 for (i = 0; i < t->rows; i++){
289 guint32 cols [MONO_CLASS_LAYOUT_SIZE];
291 mono_metadata_decode_row (t, i, cols, MONO_CLASS_LAYOUT_SIZE);
293 fprintf (output, "%d: PackingSize=%d ClassSize=%d Parent=%s\n",
294 i + 1, cols [MONO_CLASS_LAYOUT_PACKING_SIZE],
295 cols [MONO_CLASS_LAYOUT_CLASS_SIZE],
296 get_typedef (m, cols [MONO_CLASS_LAYOUT_PARENT]));
301 dump_table_constant (MonoImage *m)
303 MonoTableInfo *t = &m->tables [MONO_TABLE_CONSTANT];
305 const char *desc [] = {
311 fprintf (output, "Constant Table (1..%d)\n", t->rows);
313 for (i = 0; i < t->rows; i++){
314 guint32 cols [MONO_CONSTANT_SIZE];
315 const char *parent = desc [cols [MONO_CONSTANT_PARENT] & HASCONSTANT_MASK];
317 mono_metadata_decode_row (t, i, cols, MONO_CONSTANT_SIZE);
319 fprintf (output, "%d: Parent= %s: %d %s\n",
320 i + 1, parent, cols [MONO_CONSTANT_PARENT] >> HASCONSTANT_BITS,
321 get_constant (m, (MonoTypeEnum) cols [MONO_CONSTANT_TYPE], cols [MONO_CONSTANT_VALUE]));
327 dump_table_property_map (MonoImage *m)
329 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTYMAP];
333 fprintf (output, "Property Map Table (1..%d)\n", t->rows);
335 for (i = 0; i < t->rows; i++){
336 guint32 cols [MONO_PROPERTY_MAP_SIZE];
338 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_MAP_SIZE);
339 s = get_typedef (m, cols [MONO_PROPERTY_MAP_PARENT]);
340 fprintf (output, "%d: %s (%d) %d\n", i + 1, s, cols [MONO_PROPERTY_MAP_PARENT], cols [MONO_PROPERTY_MAP_PROPERTY_LIST]);
346 dump_table_property (MonoImage *m)
348 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTY];
353 fprintf (output, "Property Table (1..%d)\n", t->rows);
355 for (i = 0; i < t->rows; i++){
356 guint32 cols [MONO_PROPERTY_SIZE];
361 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_SIZE);
363 prop_flags = cols [MONO_PROPERTY_FLAGS];
364 if (prop_flags & 0x0200)
365 strcat (flags, "special ");
366 if (prop_flags & 0x0400)
367 strcat (flags, "runtime ");
368 if (prop_flags & 0x1000)
369 strcat (flags, "hasdefault ");
371 ptr = mono_metadata_blob_heap (m, cols [MONO_PROPERTY_TYPE]);
372 bsize = mono_metadata_decode_blob_size (ptr, &ptr);
373 /* ECMA claims 0x08 ... */
374 if (*ptr != 0x28 && *ptr != 0x08)
375 g_warning("incorrect signature in propert blob: 0x%x", *ptr);
377 pcount = mono_metadata_decode_value (ptr, &ptr);
378 ptr = get_type (m, ptr, &type);
379 fprintf (output, "%d: %s %s (",
380 i + 1, type, mono_metadata_string_heap (m, cols [MONO_PROPERTY_NAME]));
383 for (j = 0; j < pcount; j++){
384 ptr = get_param (m, ptr, &type);
385 fprintf (output, "%s%s", j > 0? ", " : "",type);
388 fprintf (output, ") %s\n", flags);
393 dump_table_event (MonoImage *m)
395 MonoTableInfo *t = &m->tables [MONO_TABLE_EVENT];
397 fprintf (output, "Event Table (1..%d)\n", t->rows);
399 for (i = 0; i < t->rows; i++){
400 guint32 cols [MONO_EVENT_SIZE];
404 mono_metadata_decode_row (t, i, cols, MONO_EVENT_SIZE);
406 name = mono_metadata_string_heap (m, cols [MONO_EVENT_NAME]);
407 type = get_typedef_or_ref (m, cols [MONO_EVENT_TYPE]);
408 fprintf (output, "%d: %s %s %s\n", i + 1, type, name,
409 cols [MONO_EVENT_FLAGS] & 0x200 ? "specialname " : "");
416 dump_table_file (MonoImage *m)
418 MonoTableInfo *t = &m->tables [MONO_TABLE_FILE];
420 fprintf (output, "File Table (1..%d)\n", t->rows);
422 for (i = 0; i < t->rows; i++){
423 guint32 cols [MONO_FILE_SIZE];
424 const char *name, *hash;
426 mono_metadata_decode_row (t, i, cols, MONO_FILE_SIZE);
428 name = mono_metadata_string_heap (m, cols [MONO_FILE_NAME]);
429 fprintf (output, "%d: %s %s [", i + 1, name,
430 cols [MONO_FILE_FLAGS] & 0x1 ? "nometadata" : "containsmetadata");
431 hash = mono_metadata_blob_heap (m, cols [MONO_FILE_HASH_VALUE]);
432 len = mono_metadata_decode_blob_size (hash, &hash);
433 for (j = 0; j < len; ++j)
434 fprintf (output, "%s%02X", j? " ": "", hash [j] & 0xff);
435 fprintf (output, "]\n");
441 get_manifest_implementation (MonoImage *m, guint32 idx)
444 const char* table = "";
446 return g_strdup ("current module");
447 row = idx >> IMPLEMENTATION_BITS;
448 switch (idx & IMPLEMENTATION_MASK) {
449 case IMPLEMENTATION_FILE:
452 case IMPLEMENTATION_ASSEMBLYREF:
453 table = "assemblyref";
455 case IMPLEMENTATION_EXP_TYPE:
456 table = "exportedtype";
459 g_assert_not_reached ();
461 return g_strdup_printf ("%s %d", table, row);
465 get_manifest_flags (guint32 mf)
469 case 1: return "public";
470 case 2: return "private";
477 dump_table_manifest (MonoImage *m)
479 MonoTableInfo *t = &m->tables [MONO_TABLE_MANIFESTRESOURCE];
481 fprintf (output, "Manifestresource Table (1..%d)\n", t->rows);
483 for (i = 0; i < t->rows; i++){
484 guint32 cols [MONO_MANIFEST_SIZE];
485 const char *name, *mf;
488 mono_metadata_decode_row (t, i, cols, MONO_MANIFEST_SIZE);
490 name = mono_metadata_string_heap (m, cols [MONO_MANIFEST_NAME]);
491 mf = get_manifest_flags (cols [MONO_MANIFEST_FLAGS]);
492 impl = get_manifest_implementation (m, cols [MONO_MANIFEST_IMPLEMENTATION]);
493 fprintf (output, "%d: %s '%s' at offset %u in %s\n", i + 1, mf, name, cols [MONO_MANIFEST_OFFSET], impl);
500 dump_table_moduleref (MonoImage *m)
502 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULEREF];
504 fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
506 for (i = 0; i < t->rows; i++){
507 guint32 cols [MONO_MODULEREF_SIZE];
510 mono_metadata_decode_row (t, i, cols, MONO_MODULEREF_SIZE);
512 name = mono_metadata_string_heap (m, cols [MONO_MODULEREF_NAME]);
513 fprintf (output, "%d: %s\n", i + 1, name);
519 dump_table_module (MonoImage *m)
521 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULE];
523 fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
525 for (i = 0; i < t->rows; i++){
526 guint32 cols [MONO_MODULE_SIZE];
530 mono_metadata_decode_row (t, i, cols, MONO_MODULE_SIZE);
532 name = mono_metadata_string_heap (m, cols [MONO_MODULE_NAME]);
533 guid = get_guid (m, cols [MONO_MODULE_MVID]);
534 fprintf (output, "%d: %s %d %s\n", i + 1, name, cols [MONO_MODULE_MVID], guid);
539 dump_table_method (MonoImage *m)
541 MonoTableInfo *t = &m->tables [MONO_TABLE_METHOD];
542 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
544 guint32 first_m, last_m;
545 fprintf (output, "Method Table (1..%d)\n", t->rows);
548 last_m = first_m = 1;
549 for (i = 1; i <= t->rows; i++){
550 guint32 cols [MONO_METHOD_SIZE];
553 MonoMethodSignature *method;
556 * Find the next type.
558 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_METHOD_LIST))) {
562 fprintf (output, "########## %s.%s\n",
563 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
564 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
567 mono_metadata_decode_row (t, i - 1, cols, MONO_METHOD_SIZE);
568 sigblob = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
569 mono_metadata_decode_blob_size (sigblob, &sigblob);
570 method = mono_metadata_parse_method_signature (m, i, sigblob, &sigblob);
571 sig = dis_stringify_method_signature (m, method, i, FALSE);
572 fprintf (output, "%d: %s (param: %d)\n", i, sig, cols [MONO_METHOD_PARAMLIST]);
574 mono_metadata_free_method_signature (method);
580 dump_table_implmap (MonoImage *m)
582 MonoTableInfo *t = &m->tables [MONO_TABLE_IMPLMAP];
583 MonoTableInfo *td = &m->tables [MONO_TABLE_MODULEREF];
586 fprintf (output, "ImplMap Table (1..%d)\n", t->rows);
588 for (i = 1; i <= t->rows; i++){
589 guint32 cols [MONO_IMPLMAP_SIZE];
592 mono_metadata_decode_row (t, i - 1, cols, MONO_IMPLMAP_SIZE);
594 method = get_method (m, MONO_TOKEN_METHOD_DEF | (cols [MONO_IMPLMAP_MEMBER] >> MEMBERFORWD_BITS));
596 fprintf (output, "%d: %s %d (%s %s)\n", i,
598 cols [MONO_IMPLMAP_FLAGS],
599 mono_metadata_string_heap (m, cols [MONO_IMPLMAP_NAME]),
600 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, cols [MONO_IMPLMAP_SCOPE] - 1, MONO_MODULEREF_NAME)));
605 method_dor_to_token (guint32 idx) {
606 switch (idx & METHODDEFORREF_MASK) {
607 case METHODDEFORREF_METHODDEF:
608 return MONO_TOKEN_METHOD_DEF | (idx >> METHODDEFORREF_BITS);
609 case METHODDEFORREF_METHODREF:
610 return MONO_TOKEN_MEMBER_REF | (idx >> METHODDEFORREF_BITS);
616 dump_table_methodimpl (MonoImage *m)
618 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODIMPL];
619 /*MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];*/
622 fprintf (output, "MethodImpl Table (1..%d)\n", t->rows);
624 for (i = 1; i <= t->rows; i++){
625 guint32 cols [MONO_METHODIMPL_SIZE];
626 char *class, *impl, *decl;
628 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODIMPL_SIZE);
629 class = get_typedef (m, cols [MONO_METHODIMPL_CLASS]);
630 impl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_BODY]));
631 decl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_DECLARATION]));
632 fprintf (output, "%d: %s\n\tdecl: %s\n\timpl: %s\n", i, class, decl, impl);
640 static map_t semantics_map [] = {
651 dump_table_methodsem (MonoImage *m)
653 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSEMANTICS];
654 int i, is_property, index;
655 const char *semantics;
657 fprintf (output, "Method Semantics Table (1..%d)\n", t->rows);
658 for (i = 1; i <= t->rows; i++){
659 guint32 cols [MONO_METHOD_SEMA_SIZE];
661 mono_metadata_decode_row (t, i - 1, cols, MONO_METHOD_SEMA_SIZE);
662 semantics = flags (cols [MONO_METHOD_SEMA_SEMANTICS], semantics_map);
663 is_property = cols [MONO_METHOD_SEMA_ASSOCIATION] & HAS_SEMANTICS_MASK;
664 index = cols [MONO_METHOD_SEMA_ASSOCIATION] >> HAS_SEMANTICS_BITS;
665 fprintf (output, "%d: [%d] %s method: %d %s %d\n", i, cols [MONO_METHOD_SEMA_ASSOCIATION], semantics,
666 cols [MONO_METHOD_SEMA_METHOD] - 1,
667 is_property? "property" : "event",
673 dump_table_interfaceimpl (MonoImage *m)
675 MonoTableInfo *t = &m->tables [MONO_TABLE_INTERFACEIMPL];
678 fprintf (output, "Interface Implementation Table (1..%d)\n", t->rows);
679 for (i = 1; i <= t->rows; i++) {
680 guint32 cols [MONO_INTERFACEIMPL_SIZE];
682 mono_metadata_decode_row (t, i - 1, cols, MONO_INTERFACEIMPL_SIZE);
683 fprintf (output, "%d: %s implements %s\n", i,
684 get_typedef (m, cols [MONO_INTERFACEIMPL_CLASS]),
685 get_typedef_or_ref (m, cols [MONO_INTERFACEIMPL_INTERFACE]));
690 has_cattr_get_table (MonoImage *m, guint32 val)
692 guint32 t = val & CUSTOM_ATTR_MASK;
693 guint32 index = val >> CUSTOM_ATTR_BITS;
697 case CUSTOM_ATTR_METHODDEF:
700 case CUSTOM_ATTR_FIELDDEF:
703 case CUSTOM_ATTR_TYPEREF:
706 case CUSTOM_ATTR_TYPEDEF:
709 case CUSTOM_ATTR_PARAMDEF:
712 case CUSTOM_ATTR_INTERFACE:
713 table = "InterfaceImpl";
715 case CUSTOM_ATTR_MEMBERREF:
718 case CUSTOM_ATTR_MODULE:
721 case CUSTOM_ATTR_PERMISSION:
722 table = "DeclSecurity?";
724 case CUSTOM_ATTR_PROPERTY:
727 case CUSTOM_ATTR_EVENT:
730 case CUSTOM_ATTR_SIGNATURE:
731 table = "StandAloneSignature";
733 case CUSTOM_ATTR_MODULEREF:
736 case CUSTOM_ATTR_TYPESPEC:
739 case CUSTOM_ATTR_ASSEMBLY:
742 case CUSTOM_ATTR_ASSEMBLYREF:
743 table = "AssemblyRef";
745 case CUSTOM_ATTR_FILE:
748 case CUSTOM_ATTR_EXP_TYPE:
749 table = "ExportedType";
751 case CUSTOM_ATTR_MANIFEST:
759 * FIXME: we should decode the index into something more uman-friendly.
761 return g_strdup_printf ("%s: %d", table, index);
765 custom_attr_params (MonoImage *m, MonoMethodSignature* sig, const char* value)
767 int len, i, slen, type;
770 const char *p = value;
772 len = mono_metadata_decode_value (p, &p);
773 if (len < 2 || read16 (p) != 0x0001) /* Prolog */
774 return g_strdup ("");
778 res = g_string_new ("");
779 for (i = 0; i < sig->param_count; ++i) {
781 g_string_append (res, ", ");
782 type = sig->params [i]->type;
786 g_string_sprintfa (res, "%d", (unsigned int)*p);
790 g_string_sprintfa (res, "%d", *p);
793 case MONO_TYPE_BOOLEAN:
794 g_string_sprintfa (res, "%s", *p?"true":"false");
798 g_string_sprintfa (res, "'%c'", read16 (p));
802 g_string_sprintfa (res, "%d", read16 (p));
806 g_string_sprintfa (res, "%d", (gint16)read16 (p));
810 g_string_sprintfa (res, "%d", read32 (p));
814 g_string_sprintfa (res, "%d", (gint32)read32 (p));
818 g_string_sprintfa (res, "%lld", read64 (p));
822 g_string_sprintfa (res, "%lld", (gint64)read64 (p));
828 g_string_sprintfa (res, "%g", val);
835 g_string_sprintfa (res, "%g", val);
839 case MONO_TYPE_VALUETYPE:
840 if (sig->params [i]->data.klass->enumtype) {
841 type = sig->params [i]->data.klass->enum_basetype->type;
844 g_warning ("generic valutype not handled in custom attr value decoding");
847 case MONO_TYPE_CLASS: /* It must be a Type: check? */
848 case MONO_TYPE_STRING:
849 if (*p == (char)0xff) {
850 g_string_append (res, "null");
854 slen = mono_metadata_decode_value (p, &p);
855 g_string_append_c (res, '"');
856 g_string_append (res, p);
857 g_string_append_c (res, '"');
861 g_warning ("Type %02x not handled in custom attr value decoding", sig->params [i]->type);
867 g_string_sprintfa (res, " %d named args: (", slen);
868 slen = len - (p - value) + 1;
869 for (i = 0; i < slen; ++i) {
870 g_string_sprintfa (res, " %02X", (p [i] & 0xff));
872 g_string_append_c (res, ')');
875 g_string_free (res, FALSE);
880 dump_table_customattr (MonoImage *m)
882 MonoTableInfo *t = &m->tables [MONO_TABLE_CUSTOMATTRIBUTE];
885 fprintf (output, "Custom Attributes Table (1..%d)\n", t->rows);
886 for (i = 1; i <= t->rows; i++) {
887 guint32 cols [MONO_CUSTOM_ATTR_SIZE];
894 mono_metadata_decode_row (t, i - 1, cols, MONO_CUSTOM_ATTR_SIZE);
895 desc = has_cattr_get_table (m, cols [MONO_CUSTOM_ATTR_PARENT]);
896 mtoken = cols [MONO_CUSTOM_ATTR_TYPE] >> CUSTOM_ATTR_TYPE_BITS;
897 switch (cols [MONO_CUSTOM_ATTR_TYPE] & CUSTOM_ATTR_TYPE_MASK) {
898 case CUSTOM_ATTR_TYPE_METHODDEF:
899 mtoken |= MONO_TOKEN_METHOD_DEF;
901 case CUSTOM_ATTR_TYPE_MEMBERREF:
902 mtoken |= MONO_TOKEN_MEMBER_REF;
905 g_warning ("Unknown table for custom attr type %08x", cols [MONO_CUSTOM_ATTR_TYPE]);
908 method = get_method (m, mtoken);
909 meth = mono_get_method (m, mtoken, NULL);
910 params = custom_attr_params (m, meth->signature, mono_metadata_blob_heap (m, cols [MONO_CUSTOM_ATTR_VALUE]));
911 fprintf (output, "%d: %s: %s [%s]\n", i, desc, method, params);
919 dump_table_nestedclass (MonoImage *m)
921 MonoTableInfo *t = &m->tables [MONO_TABLE_NESTEDCLASS];
922 guint32 cols [MONO_NESTED_CLASS_SIZE];
924 char *nested, *nesting;
925 fprintf (output, "NestedClass Table (1..%d)\n", t->rows);
927 for (i = 1; i <= t->rows; i++){
928 mono_metadata_decode_row (t, i - 1, cols, MONO_NESTED_CLASS_SIZE);
929 nested = get_typedef (m, cols [MONO_NESTED_CLASS_NESTED]);
930 nesting = get_typedef (m, cols [MONO_NESTED_CLASS_ENCLOSING]);
931 fprintf (output, "%d: %d %d: %s in %s\n", i,
932 cols [MONO_NESTED_CLASS_NESTED],
933 cols [MONO_NESTED_CLASS_ENCLOSING], nested, nesting);
941 dump_table_exported (MonoImage *m)
943 MonoTableInfo *t = &m->tables [MONO_TABLE_EXPORTEDTYPE];
944 guint32 cols [MONO_EXP_TYPE_SIZE];
946 const char *name, *nspace;
949 fprintf (output, "ExportedType Table (1..%d)\n", t->rows);
951 for (i = 1; i <= t->rows; i++) {
952 mono_metadata_decode_row (t, i - 1, cols, MONO_EXP_TYPE_SIZE);
953 name = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAME]);
954 nspace = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAMESPACE]);
955 impl = get_manifest_implementation (m, cols [MONO_EXP_TYPE_IMPLEMENTATION]);
956 index = cols [MONO_EXP_TYPE_TYPEDEF];
957 fprintf (output, "%d: %s%s%s is in %s, token %x\n", i, nspace, *nspace ? "." : "", name, impl, index);
964 dump_table_field_marshal (MonoImage *m)
966 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELDMARSHAL];
967 guint32 cols [MONO_FIELD_MARSHAL_SIZE];
968 int i, is_field, idx;
972 fprintf (output, "FieldMarshal Table (1..%d)\n", t->rows);
974 for (i = 1; i <= t->rows; i++) {
975 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_MARSHAL_SIZE);
976 blob = mono_metadata_blob_heap (m, cols [MONO_FIELD_MARSHAL_NATIVE_TYPE]);
977 native = get_marshal_info (m, blob);
978 is_field = (cols [MONO_FIELD_MARSHAL_PARENT] & HAS_FIELD_MARSHAL_MASK) == HAS_FIELD_MARSHAL_FIELDSREF;
979 idx = cols [MONO_FIELD_MARSHAL_PARENT] >> HAS_FIELD_MARSHAL_BITS;
980 fprintf (output, "%d: (0x%04x) %s %d: %s\n", i, cols [MONO_FIELD_MARSHAL_PARENT], is_field? "Field" : "Param", idx, native);
987 get_security_action (int val) {
988 static char buf [32];
991 case SECURITY_ACTION_DEMAND:
993 case SECURITY_ACTION_ASSERT:
995 case SECURITY_ACTION_DENY:
997 case SECURITY_ACTION_PERMITONLY:
999 case SECURITY_ACTION_LINKDEMAND:
1000 return "LinkDemand";
1001 case SECURITY_ACTION_INHERITDEMAND:
1002 return "InheritanceDemand";
1003 case SECURITY_ACTION_REQMIN:
1004 return "RequestMinimum";
1005 case SECURITY_ACTION_REQOPT:
1006 return "RequestOptional";
1007 case SECURITY_ACTION_REQREFUSE:
1008 return "RequestRefuse";
1010 g_snprintf (buf, sizeof (buf), "0x%04X", val);
1016 dump_table_declsec (MonoImage *m)
1018 MonoTableInfo *t = &m->tables [MONO_TABLE_DECLSECURITY];
1019 guint32 cols [MONO_DECL_SECURITY_SIZE];
1022 const char *blob, *action;
1023 const char* parent[] = {
1024 "TypeDef", "MethodDef", "Assembly", ""
1027 fprintf (output, "DeclSecurity Table (1..%d)\n", t->rows);
1029 for (i = 1; i <= t->rows; i++) {
1030 mono_metadata_decode_row (t, i - 1, cols, MONO_DECL_SECURITY_SIZE);
1031 blob = mono_metadata_blob_heap (m, cols [MONO_DECL_SECURITY_PERMISSIONSET]);
1032 len = mono_metadata_decode_blob_size (blob, &blob);
1033 action = get_security_action (cols [MONO_DECL_SECURITY_ACTION]);
1034 idx = cols [MONO_DECL_SECURITY_PARENT];
1035 fprintf (output, "%d: %s on %s %d%s", i, action, parent [idx & HAS_DECL_SECURITY_MASK], idx >> HAS_DECL_SECURITY_BITS, len? ":\n\t":"\n");
1038 for (idx = 0; idx < len; ++idx)
1039 fprintf (output, "%c", blob [idx]);
1040 fprintf (output, "\n");
1045 dump_table_genericpar (MonoImage *m)
1047 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAM];
1048 guint32 cols [MONO_GENERICPARAM_SIZE];
1051 fprintf (output, "GenericParameters (1..%d)\n", t->rows);
1053 for (i = 1; i <= t->rows; i++) {
1055 mono_metadata_decode_row (t, i - 1, cols, MONO_GENERICPARAM_SIZE);
1057 sig = get_type_or_methdef (m, cols [MONO_GENERICPARAM_OWNER]);
1058 fprintf (output, "%d: %d, flags=%d, owner=%s %s\n", i,
1059 cols [MONO_GENERICPARAM_NUMBER],
1060 cols [MONO_GENERICPARAM_FLAGS], sig,
1061 mono_metadata_string_heap (m, cols [MONO_GENERICPARAM_NAME]));
1067 dump_table_methodspec (MonoImage *m)
1069 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSPEC];
1070 guint32 cols [MONO_METHODSPEC_SIZE];
1073 fprintf (output, "MethodSpec (1..%d)\n", t->rows);
1075 for (i = 1; i <= t->rows; i++) {
1080 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODSPEC_SIZE);
1082 // build a methodspec token to get the method
1083 token = MONO_TOKEN_METHOD_SPEC | i;
1084 method = get_method (m, token);
1086 sig = get_method_type_param (m, cols [MONO_METHODSPEC_SIGNATURE]);
1087 fprintf (output, "%d: %s, %s\n", i, method, sig);
1094 dump_table_parconstraint (MonoImage *m)
1096 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAMCONSTRAINT];
1097 guint32 cols [MONO_GENPARCONSTRAINT_SIZE];
1100 fprintf (output, "Generic Param Constraint (1..%d)\n", t->rows);
1102 for (i = 1; i <= t->rows; i++) {
1104 mono_metadata_decode_row (t, i - 1, cols, MONO_GENPARCONSTRAINT_SIZE);
1106 sig = get_typedef_or_ref (m, cols [MONO_GENPARCONSTRAINT_CONSTRAINT]);
1107 fprintf (output, "%d: gen-par=%d, Constraint=%s\n", i,
1108 cols [MONO_GENPARCONSTRAINT_GENERICPAR], sig);