2 * dump.c: Dumping routines for the disassembler.
5 * Miguel de Icaza (miguel@ximian.com)
7 * (C) 2001 Ximian, Inc.
19 #include "mono/metadata/loader.h"
20 #include "mono/metadata/class.h"
21 #include "mono/metadata/class-internals.h"
22 #include "mono/utils/mono-compiler.h"
27 extern int isinf (double);
33 dump_table_assembly (MonoImage *m)
35 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLY];
36 guint32 cols [MONO_ASSEMBLY_SIZE];
40 fprintf (output, "Assembly Table\n");
45 mono_metadata_decode_row (t, 0, cols, MONO_ASSEMBLY_SIZE);
47 fprintf (output, "Name: %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_NAME]));
48 fprintf (output, "Hash Algoritm: 0x%08x\n", cols [MONO_ASSEMBLY_HASH_ALG]);
49 fprintf (output, "Version: %d.%d.%d.%d\n", cols [MONO_ASSEMBLY_MAJOR_VERSION],
50 cols [MONO_ASSEMBLY_MINOR_VERSION],
51 cols [MONO_ASSEMBLY_BUILD_NUMBER],
52 cols [MONO_ASSEMBLY_REV_NUMBER]);
53 fprintf (output, "Flags: 0x%08x\n", cols [MONO_ASSEMBLY_FLAGS]);
54 fprintf (output, "PublicKey: BlobPtr (0x%08x)\n", cols [MONO_ASSEMBLY_PUBLIC_KEY]);
56 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLY_PUBLIC_KEY]);
57 len = mono_metadata_decode_value (ptr, &ptr);
59 fprintf (output, "\tDump:");
60 hex_dump (ptr, 0, len);
61 fprintf (output, "\n");
63 fprintf (output, "\tZero sized public key\n");
65 fprintf (output, "Culture: %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_CULTURE]));
66 fprintf (output, "\n");
70 dump_table_typeref (MonoImage *m)
72 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEREF];
75 fprintf (output, "Typeref Table\n");
77 for (i = 1; i <= t->rows; i++){
78 char *s = get_typeref (m, i);
80 fprintf (output, "%d: %s\n", i, s);
83 fprintf (output, "\n");
87 dump_table_typedef (MonoImage *m)
89 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEDEF];
92 fprintf (output, "Typedef Table\n");
94 for (i = 1; i <= t->rows; i++){
95 char *s = get_typedef (m, i);
96 guint32 cols [MONO_TYPEDEF_SIZE];
98 mono_metadata_decode_row (&m->tables [MONO_TABLE_TYPEDEF], i - 1, cols, MONO_TYPEDEF_SIZE);
100 fprintf (output, "%d: %s (flist=%d, mlist=%d, flags=0x%x, extends=0x%x)\n", i, s,
101 cols [MONO_TYPEDEF_FIELD_LIST], cols [MONO_TYPEDEF_METHOD_LIST],
102 cols [MONO_TYPEDEF_FLAGS], cols [MONO_TYPEDEF_EXTENDS]);
105 fprintf (output, "\n");
109 dump_table_typespec (MonoImage *m)
111 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPESPEC];
114 fprintf (output, "Typespec Table\n");
116 for (i = 1; i <= t->rows; i++){
117 char *typespec = get_typespec (m, i, TRUE, NULL);
119 fprintf (output, "%d: %s\n", i, typespec);
122 fprintf (output, "\n");
126 dump_table_assemblyref (MonoImage *m)
128 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLYREF];
131 fprintf (output, "AssemblyRef Table\n");
133 for (i = 0; i < t->rows; i++){
136 guint32 cols [MONO_ASSEMBLYREF_SIZE];
138 mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
139 fprintf (output, "%d: Version=%d.%d.%d.%d\n\tName=%s\n", i + 1,
140 cols [MONO_ASSEMBLYREF_MAJOR_VERSION],
141 cols [MONO_ASSEMBLYREF_MINOR_VERSION],
142 cols [MONO_ASSEMBLYREF_BUILD_NUMBER],
143 cols [MONO_ASSEMBLYREF_REV_NUMBER],
144 mono_metadata_string_heap (m, cols [MONO_ASSEMBLYREF_NAME]));
145 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLYREF_PUBLIC_KEY]);
146 len = mono_metadata_decode_value (ptr, &ptr);
148 fprintf (output, "\tPublic Key:");
149 hex_dump (ptr, 0, len);
150 fprintf (output, "\n");
152 fprintf (output, "\tZero sized public key\n");
155 fprintf (output, "\n");
159 dump_table_param (MonoImage *m)
161 MonoTableInfo *t = &m->tables [MONO_TABLE_PARAM];
164 fprintf (output, "Param Table\n");
166 for (i = 0; i < t->rows; i++){
167 guint32 cols [MONO_PARAM_SIZE];
169 mono_metadata_decode_row (t, i, cols, MONO_PARAM_SIZE);
170 fprintf (output, "%d: 0x%04x %d %s\n",
172 cols [MONO_PARAM_FLAGS], cols [MONO_PARAM_SEQUENCE],
173 mono_metadata_string_heap (m, cols [MONO_PARAM_NAME]));
175 fprintf (output, "\n");
179 dump_table_field (MonoImage *m)
181 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELD];
182 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
183 MonoTableInfo *fl = &m->tables [MONO_TABLE_FIELDLAYOUT];
184 MonoTableInfo *rva = &m->tables [MONO_TABLE_FIELDRVA];
185 int i, current_type, offset_row, rva_row;
186 guint32 first_m, last_m;
188 fprintf (output, "Field Table (1..%d)\n", t->rows);
190 rva_row = offset_row = current_type = 1;
191 last_m = first_m = 1;
192 for (i = 1; i <= t->rows; i++){
193 guint32 cols [MONO_FIELD_SIZE];
197 * Find the next type.
199 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_FIELD_LIST))) {
203 fprintf (output, "########## %s.%s\n",
204 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
205 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
208 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_SIZE);
209 sig = get_field_signature (m, cols [MONO_FIELD_SIGNATURE], NULL);
210 flags = field_flags (cols [MONO_FIELD_FLAGS]);
211 fprintf (output, "%d: %s %s: %s\n",
214 mono_metadata_string_heap (m, cols [MONO_FIELD_NAME]),
218 if (offset_row <= fl->rows && (mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_FIELD) == i)) {
219 fprintf (output, "\texplicit offset: %d\n", mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_OFFSET));
222 if (rva_row <= rva->rows && (mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_FIELD) == i)) {
223 fprintf (output, "\trva: %d\n", mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_RVA));
227 fprintf (output, "\n");
231 dump_table_memberref (MonoImage *m)
233 MonoTableInfo *t = &m->tables [MONO_TABLE_MEMBERREF];
237 const char *blob, *ks = NULL;
239 fprintf (output, "MemberRef Table (1..%d)\n", t->rows);
241 for (i = 0; i < t->rows; i++){
242 guint32 cols [MONO_MEMBERREF_SIZE];
244 mono_metadata_decode_row (t, i, cols, MONO_MEMBERREF_SIZE);
246 kind = cols [MONO_MEMBERREF_CLASS] & 7;
247 idx = cols [MONO_MEMBERREF_CLASS] >> 3;
249 x = g_strdup ("UNHANDLED CASE");
254 xx = get_typedef (m, idx);
255 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
260 xx = get_typeref (m, idx);
261 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
265 ks = "ModuleRef"; break;
268 x = get_methoddef (m, idx);
272 xx = get_typespec (m, idx, FALSE, NULL);
273 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
277 g_error ("Unknown tag: %d\n", kind);
279 blob = mono_metadata_blob_heap (m, cols [MONO_MEMBERREF_SIGNATURE]);
280 mono_metadata_decode_blob_size (blob, &blob);
281 if (*blob == 0x6) { /* it's a field */
282 sig = get_field_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL);
284 sig = get_methodref_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL);
286 fprintf (output, "%d: %s[%d] %s\n\tResolved: %s\n\tSignature: %s\n\t\n",
289 mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]),
300 dump_table_class_layout (MonoImage *m)
302 MonoTableInfo *t = &m->tables [MONO_TABLE_CLASSLAYOUT];
304 fprintf (output, "ClassLayout Table (1..%d)\n", t->rows);
306 for (i = 0; i < t->rows; i++){
307 guint32 cols [MONO_CLASS_LAYOUT_SIZE];
309 mono_metadata_decode_row (t, i, cols, MONO_CLASS_LAYOUT_SIZE);
311 fprintf (output, "%d: PackingSize=%d ClassSize=%d Parent=%s\n",
312 i + 1, cols [MONO_CLASS_LAYOUT_PACKING_SIZE],
313 cols [MONO_CLASS_LAYOUT_CLASS_SIZE],
314 get_typedef (m, cols [MONO_CLASS_LAYOUT_PARENT]));
319 dump_table_constant (MonoImage *m)
321 MonoTableInfo *t = &m->tables [MONO_TABLE_CONSTANT];
323 const char *desc [] = {
329 fprintf (output, "Constant Table (1..%d)\n", t->rows);
331 for (i = 0; i < t->rows; i++){
332 guint32 cols [MONO_CONSTANT_SIZE];
334 mono_metadata_decode_row (t, i, cols, MONO_CONSTANT_SIZE);
335 parent = desc [cols [MONO_CONSTANT_PARENT] & MONO_HASCONSTANT_MASK];
337 fprintf (output, "%d: Parent= %s: %d %s\n",
338 i + 1, parent, cols [MONO_CONSTANT_PARENT] >> MONO_HASCONSTANT_BITS,
339 get_constant (m, (MonoTypeEnum) cols [MONO_CONSTANT_TYPE], cols [MONO_CONSTANT_VALUE]));
345 dump_table_property_map (MonoImage *m)
347 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTYMAP];
351 fprintf (output, "Property Map Table (1..%d)\n", t->rows);
353 for (i = 0; i < t->rows; i++){
354 guint32 cols [MONO_PROPERTY_MAP_SIZE];
356 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_MAP_SIZE);
357 s = get_typedef (m, cols [MONO_PROPERTY_MAP_PARENT]);
358 fprintf (output, "%d: %s (%d) %d\n", i + 1, s, cols [MONO_PROPERTY_MAP_PARENT], cols [MONO_PROPERTY_MAP_PROPERTY_LIST]);
364 dump_table_property (MonoImage *m)
366 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTY];
371 fprintf (output, "Property Table (1..%d)\n", t->rows);
373 for (i = 0; i < t->rows; i++){
374 guint32 cols [MONO_PROPERTY_SIZE];
379 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_SIZE);
381 prop_flags = cols [MONO_PROPERTY_FLAGS];
382 if (prop_flags & 0x0200)
383 strcat (flags, "special ");
384 if (prop_flags & 0x0400)
385 strcat (flags, "runtime ");
386 if (prop_flags & 0x1000)
387 strcat (flags, "hasdefault ");
389 ptr = mono_metadata_blob_heap (m, cols [MONO_PROPERTY_TYPE]);
390 bsize = mono_metadata_decode_blob_size (ptr, &ptr);
391 /* ECMA claims 0x08 ... */
392 if (*ptr != 0x28 && *ptr != 0x08)
393 g_warning("incorrect signature in propert blob: 0x%x", *ptr);
395 pcount = mono_metadata_decode_value (ptr, &ptr);
396 ptr = get_type (m, ptr, &type, FALSE, NULL);
397 fprintf (output, "%d: %s %s (",
398 i + 1, type, mono_metadata_string_heap (m, cols [MONO_PROPERTY_NAME]));
401 for (j = 0; j < pcount; j++){
402 ptr = get_param (m, ptr, &type, NULL);
403 fprintf (output, "%s%s", j > 0? ", " : "",type);
406 fprintf (output, ") %s\n", flags);
411 dump_table_event (MonoImage *m)
413 MonoTableInfo *t = &m->tables [MONO_TABLE_EVENT];
415 fprintf (output, "Event Table (1..%d)\n", t->rows);
417 for (i = 0; i < t->rows; i++){
418 guint32 cols [MONO_EVENT_SIZE];
422 mono_metadata_decode_row (t, i, cols, MONO_EVENT_SIZE);
424 name = mono_metadata_string_heap (m, cols [MONO_EVENT_NAME]);
425 type = get_typedef_or_ref (m, cols [MONO_EVENT_TYPE], NULL);
426 fprintf (output, "%d: %s %s %s\n", i + 1, type, name,
427 cols [MONO_EVENT_FLAGS] & 0x200 ? "specialname " : "");
434 dump_table_file (MonoImage *m)
436 MonoTableInfo *t = &m->tables [MONO_TABLE_FILE];
438 fprintf (output, "File Table (1..%d)\n", t->rows);
440 for (i = 0; i < t->rows; i++){
441 guint32 cols [MONO_FILE_SIZE];
442 const char *name, *hash;
444 mono_metadata_decode_row (t, i, cols, MONO_FILE_SIZE);
446 name = mono_metadata_string_heap (m, cols [MONO_FILE_NAME]);
447 fprintf (output, "%d: %s %s [", i + 1, name,
448 cols [MONO_FILE_FLAGS] & 0x1 ? "nometadata" : "containsmetadata");
449 hash = mono_metadata_blob_heap (m, cols [MONO_FILE_HASH_VALUE]);
450 len = mono_metadata_decode_blob_size (hash, &hash);
451 for (j = 0; j < len; ++j)
452 fprintf (output, "%s%02X", j? " ": "", hash [j] & 0xff);
453 fprintf (output, "]\n");
459 get_manifest_implementation (MonoImage *m, guint32 idx)
462 const char* table = "";
464 return g_strdup ("current module");
465 row = idx >> MONO_IMPLEMENTATION_BITS;
466 switch (idx & MONO_IMPLEMENTATION_MASK) {
467 case MONO_IMPLEMENTATION_FILE:
470 case MONO_IMPLEMENTATION_ASSEMBLYREF:
471 table = "assemblyref";
473 case MONO_IMPLEMENTATION_EXP_TYPE:
474 table = "exportedtype";
477 g_assert_not_reached ();
479 return g_strdup_printf ("%s %d", table, row);
483 get_manifest_flags (guint32 mf)
487 case 1: return "public";
488 case 2: return "private";
495 dump_table_manifest (MonoImage *m)
497 MonoTableInfo *t = &m->tables [MONO_TABLE_MANIFESTRESOURCE];
499 fprintf (output, "Manifestresource Table (1..%d)\n", t->rows);
501 for (i = 0; i < t->rows; i++){
502 guint32 cols [MONO_MANIFEST_SIZE];
503 const char *name, *mf;
506 mono_metadata_decode_row (t, i, cols, MONO_MANIFEST_SIZE);
508 name = mono_metadata_string_heap (m, cols [MONO_MANIFEST_NAME]);
509 mf = get_manifest_flags (cols [MONO_MANIFEST_FLAGS]);
510 impl = get_manifest_implementation (m, cols [MONO_MANIFEST_IMPLEMENTATION]);
511 fprintf (output, "%d: %s '%s' at offset %u in %s\n", i + 1, mf, name, cols [MONO_MANIFEST_OFFSET], impl);
518 dump_table_moduleref (MonoImage *m)
520 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULEREF];
522 fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
524 for (i = 0; i < t->rows; i++){
525 guint32 cols [MONO_MODULEREF_SIZE];
528 mono_metadata_decode_row (t, i, cols, MONO_MODULEREF_SIZE);
530 name = mono_metadata_string_heap (m, cols [MONO_MODULEREF_NAME]);
531 fprintf (output, "%d: %s\n", i + 1, name);
537 dump_table_module (MonoImage *m)
539 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULE];
541 fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
543 for (i = 0; i < t->rows; i++){
544 guint32 cols [MONO_MODULE_SIZE];
548 mono_metadata_decode_row (t, i, cols, MONO_MODULE_SIZE);
550 name = mono_metadata_string_heap (m, cols [MONO_MODULE_NAME]);
551 guid = get_guid (m, cols [MONO_MODULE_MVID]);
552 fprintf (output, "%d: %s %d %s\n", i + 1, name, cols [MONO_MODULE_MVID], guid);
557 dump_table_method (MonoImage *m)
559 MonoTableInfo *t = &m->tables [MONO_TABLE_METHOD];
560 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
562 guint32 first_m, last_m;
563 /* Generic container for Type & method */
564 MonoGenericContainer *type_container = NULL, *method_container = NULL;
566 fprintf (output, "Method Table (1..%d)\n", t->rows);
569 last_m = first_m = 1;
570 for (i = 1; i <= t->rows; i++){
571 guint32 cols [MONO_METHOD_SIZE];
574 MonoMethodSignature *method;
577 * Find the next type.
579 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_METHOD_LIST))) {
583 fprintf (output, "########## %s.%s\n",
584 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
585 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
587 type_container = mono_metadata_load_generic_params (m, MONO_TOKEN_TYPE_DEF | (current_type - 1), NULL);
589 mono_metadata_load_generic_param_constraints (m, MONO_TOKEN_TYPE_DEF | (current_type - 1), type_container);
592 method_container = mono_metadata_load_generic_params (m, MONO_TOKEN_METHOD_DEF | i, type_container);
593 if (method_container)
594 mono_metadata_load_generic_param_constraints (m, MONO_TOKEN_METHOD_DEF | i, method_container);
595 mono_metadata_decode_row (t, i - 1, cols, MONO_METHOD_SIZE);
596 sigblob = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
597 mono_metadata_decode_blob_size (sigblob, &sigblob);
598 method = mono_metadata_parse_method_signature_full (m, method_container ? method_container : type_container, i, sigblob, &sigblob);
599 sig = dis_stringify_method_signature (m, method, i, (MonoGenericContext *) (method_container ? method_container : type_container), FALSE);
600 fprintf (output, "%d: %s (param: %d)\n", i, sig, cols [MONO_METHOD_PARAMLIST]);
602 mono_metadata_free_method_signature (method);
608 dump_table_implmap (MonoImage *m)
610 MonoTableInfo *t = &m->tables [MONO_TABLE_IMPLMAP];
611 MonoTableInfo *td = &m->tables [MONO_TABLE_MODULEREF];
614 fprintf (output, "ImplMap Table (1..%d)\n", t->rows);
616 for (i = 1; i <= t->rows; i++){
617 guint32 cols [MONO_IMPLMAP_SIZE];
620 mono_metadata_decode_row (t, i - 1, cols, MONO_IMPLMAP_SIZE);
622 method = get_method (m, MONO_TOKEN_METHOD_DEF | (cols [MONO_IMPLMAP_MEMBER] >> MONO_MEMBERFORWD_BITS), NULL);
624 fprintf (output, "%d: %s %d (%s %s)\n", i,
626 cols [MONO_IMPLMAP_FLAGS],
627 mono_metadata_string_heap (m, cols [MONO_IMPLMAP_NAME]),
628 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, cols [MONO_IMPLMAP_SCOPE] - 1, MONO_MODULEREF_NAME)));
633 dump_table_methodimpl (MonoImage *m)
635 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODIMPL];
636 /*MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];*/
639 fprintf (output, "MethodImpl Table (1..%d)\n", t->rows);
641 for (i = 1; i <= t->rows; i++){
642 guint32 cols [MONO_METHODIMPL_SIZE];
643 char *class, *impl, *decl;
645 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODIMPL_SIZE);
646 class = get_typedef (m, cols [MONO_METHODIMPL_CLASS]);
647 impl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_BODY]), NULL);
648 decl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_DECLARATION]), NULL);
649 fprintf (output, "%d: %s\n\tdecl: %s\n\timpl: %s\n", i, class, decl, impl);
657 static dis_map_t semantics_map [] = {
668 dump_table_methodsem (MonoImage *m)
670 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSEMANTICS];
671 int i, is_property, index;
672 const char *semantics;
674 fprintf (output, "Method Semantics Table (1..%d)\n", t->rows);
675 for (i = 1; i <= t->rows; i++){
676 guint32 cols [MONO_METHOD_SEMA_SIZE];
678 mono_metadata_decode_row (t, i - 1, cols, MONO_METHOD_SEMA_SIZE);
679 semantics = flags (cols [MONO_METHOD_SEMA_SEMANTICS], semantics_map);
680 is_property = cols [MONO_METHOD_SEMA_ASSOCIATION] & MONO_HAS_SEMANTICS_MASK;
681 index = cols [MONO_METHOD_SEMA_ASSOCIATION] >> MONO_HAS_SEMANTICS_BITS;
682 fprintf (output, "%d: [%d] %s method: %d %s %d\n", i, cols [MONO_METHOD_SEMA_ASSOCIATION], semantics,
683 cols [MONO_METHOD_SEMA_METHOD] - 1,
684 is_property? "property" : "event",
690 dump_table_interfaceimpl (MonoImage *m)
692 MonoTableInfo *t = &m->tables [MONO_TABLE_INTERFACEIMPL];
695 fprintf (output, "Interface Implementation Table (1..%d)\n", t->rows);
696 for (i = 1; i <= t->rows; i++) {
697 guint32 cols [MONO_INTERFACEIMPL_SIZE];
699 mono_metadata_decode_row (t, i - 1, cols, MONO_INTERFACEIMPL_SIZE);
700 fprintf (output, "%d: %s implements %s\n", i,
701 get_typedef (m, cols [MONO_INTERFACEIMPL_CLASS]),
702 get_typedef_or_ref (m, cols [MONO_INTERFACEIMPL_INTERFACE], NULL));
707 has_cattr_get_table (MonoImage *m, guint32 val)
709 guint32 t = val & MONO_CUSTOM_ATTR_MASK;
710 guint32 index = val >> MONO_CUSTOM_ATTR_BITS;
714 case MONO_CUSTOM_ATTR_METHODDEF:
717 case MONO_CUSTOM_ATTR_FIELDDEF:
720 case MONO_CUSTOM_ATTR_TYPEREF:
723 case MONO_CUSTOM_ATTR_TYPEDEF:
726 case MONO_CUSTOM_ATTR_PARAMDEF:
729 case MONO_CUSTOM_ATTR_INTERFACE:
730 table = "InterfaceImpl";
732 case MONO_CUSTOM_ATTR_MEMBERREF:
735 case MONO_CUSTOM_ATTR_MODULE:
738 case MONO_CUSTOM_ATTR_PERMISSION:
739 table = "DeclSecurity?";
741 case MONO_CUSTOM_ATTR_PROPERTY:
744 case MONO_CUSTOM_ATTR_EVENT:
747 case MONO_CUSTOM_ATTR_SIGNATURE:
748 table = "StandAloneSignature";
750 case MONO_CUSTOM_ATTR_MODULEREF:
753 case MONO_CUSTOM_ATTR_TYPESPEC:
756 case MONO_CUSTOM_ATTR_ASSEMBLY:
759 case MONO_CUSTOM_ATTR_ASSEMBLYREF:
760 table = "AssemblyRef";
762 case MONO_CUSTOM_ATTR_FILE:
765 case MONO_CUSTOM_ATTR_EXP_TYPE:
766 table = "ExportedType";
768 case MONO_CUSTOM_ATTR_MANIFEST:
771 case MONO_CUSTOM_ATTR_GENERICPAR:
772 table = "GenericParam";
779 * FIXME: we should decode the index into something more uman-friendly.
781 return g_strdup_printf ("%s: %d", table, index);
785 custom_attr_params (MonoImage *m, MonoMethodSignature* sig, const char* value)
787 int len, i, slen, type;
790 const char *p = value;
792 len = mono_metadata_decode_value (p, &p);
793 if (len < 2 || read16 (p) != 0x0001) /* Prolog */
794 return g_strdup ("");
798 res = g_string_new ("");
799 for (i = 0; i < sig->param_count; ++i) {
801 g_string_append (res, ", ");
802 type = sig->params [i]->type;
806 g_string_sprintfa (res, "%d", (unsigned int)*p);
810 g_string_sprintfa (res, "%d", *p);
813 case MONO_TYPE_BOOLEAN:
814 g_string_sprintfa (res, "%s", *p?"true":"false");
818 g_string_sprintfa (res, "'%c'", read16 (p));
822 g_string_sprintfa (res, "%d", read16 (p));
826 g_string_sprintfa (res, "%d", (gint16)read16 (p));
830 g_string_sprintfa (res, "%d", read32 (p));
834 g_string_sprintfa (res, "%d", (gint32)read32 (p));
838 g_string_sprintfa (res, "%lld", (long long)read64 (p));
842 g_string_sprintfa (res, "%lld", (long long)read64 (p));
851 g_string_sprintfa (res, "(00 00 80 ff)"); /* negative infinity */
853 g_string_sprintfa (res, "(00 00 80 7f)"); /* positive infinity */
854 else if (isnan (val))
855 g_string_sprintfa (res, "(00 00 c0 ff)"); /* NaN */
857 g_string_sprintfa (res, "%g", val);
868 g_string_sprintfa (res, "(00 00 00 00 00 00 f0 ff)"); /* negative infinity */
870 g_string_sprintfa (res, "(00 00 00 00 00 00 f0 7f)"); /* positive infinity */
871 else if (isnan (val))
872 g_string_sprintfa (res, "(00 00 00 00 00 00 f8 ff)"); /* NaN */
874 g_string_sprintfa (res, "%g", val);
878 case MONO_TYPE_VALUETYPE:
879 if (mono_class_is_enum (sig->params [i]->data.klass)) {
880 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
883 g_warning ("generic valutype not handled in custom attr value decoding");
886 case MONO_TYPE_CLASS: /* It must be a Type: check? */
887 case MONO_TYPE_STRING:
888 if (*p == (char)0xff) {
889 g_string_append (res, "null");
893 slen = mono_metadata_decode_value (p, &p);
894 g_string_append_c (res, '"');
895 g_string_append (res, p);
896 g_string_append_c (res, '"');
900 g_warning ("Type %02x not handled in custom attr value decoding", sig->params [i]->type);
906 g_string_sprintfa (res, " %d named args: (", slen);
907 slen = len - (p - value) + 1;
908 for (i = 0; i < slen; ++i) {
909 g_string_sprintfa (res, " %02X", (p [i] & 0xff));
911 g_string_append_c (res, ')');
914 g_string_free (res, FALSE);
919 dump_table_customattr (MonoImage *m)
921 MonoTableInfo *t = &m->tables [MONO_TABLE_CUSTOMATTRIBUTE];
924 fprintf (output, "Custom Attributes Table (1..%d)\n", t->rows);
925 for (i = 1; i <= t->rows; i++) {
926 guint32 cols [MONO_CUSTOM_ATTR_SIZE];
933 mono_metadata_decode_row (t, i - 1, cols, MONO_CUSTOM_ATTR_SIZE);
934 desc = has_cattr_get_table (m, cols [MONO_CUSTOM_ATTR_PARENT]);
935 mtoken = cols [MONO_CUSTOM_ATTR_TYPE] >> MONO_CUSTOM_ATTR_TYPE_BITS;
936 switch (cols [MONO_CUSTOM_ATTR_TYPE] & MONO_CUSTOM_ATTR_TYPE_MASK) {
937 case MONO_CUSTOM_ATTR_TYPE_METHODDEF:
938 mtoken |= MONO_TOKEN_METHOD_DEF;
940 case MONO_CUSTOM_ATTR_TYPE_MEMBERREF:
941 mtoken |= MONO_TOKEN_MEMBER_REF;
944 g_warning ("Unknown table for custom attr type %08x", cols [MONO_CUSTOM_ATTR_TYPE]);
947 method = get_method (m, mtoken, NULL);
948 meth = mono_get_method (m, mtoken, NULL);
949 params = custom_attr_params (m, mono_method_signature (meth), mono_metadata_blob_heap (m, cols [MONO_CUSTOM_ATTR_VALUE]));
950 fprintf (output, "%d: %s: %s [%s]\n", i, desc, method, params);
958 dump_table_nestedclass (MonoImage *m)
960 MonoTableInfo *t = &m->tables [MONO_TABLE_NESTEDCLASS];
961 guint32 cols [MONO_NESTED_CLASS_SIZE];
963 char *nested, *nesting;
964 fprintf (output, "NestedClass Table (1..%d)\n", t->rows);
966 for (i = 1; i <= t->rows; i++){
967 mono_metadata_decode_row (t, i - 1, cols, MONO_NESTED_CLASS_SIZE);
968 nested = get_typedef (m, cols [MONO_NESTED_CLASS_NESTED]);
969 nesting = get_typedef (m, cols [MONO_NESTED_CLASS_ENCLOSING]);
970 fprintf (output, "%d: %d %d: %s in %s\n", i,
971 cols [MONO_NESTED_CLASS_NESTED],
972 cols [MONO_NESTED_CLASS_ENCLOSING], nested, nesting);
980 dump_table_exported (MonoImage *m)
982 MonoTableInfo *t = &m->tables [MONO_TABLE_EXPORTEDTYPE];
983 guint32 cols [MONO_EXP_TYPE_SIZE];
985 const char *name, *nspace;
988 fprintf (output, "ExportedType Table (1..%d)\n", t->rows);
990 for (i = 1; i <= t->rows; i++) {
991 mono_metadata_decode_row (t, i - 1, cols, MONO_EXP_TYPE_SIZE);
992 name = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAME]);
993 nspace = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAMESPACE]);
994 impl = get_manifest_implementation (m, cols [MONO_EXP_TYPE_IMPLEMENTATION]);
995 index = cols [MONO_EXP_TYPE_TYPEDEF];
996 fprintf (output, "%d: %s%s%s is in %s, token %x\n", i, nspace, *nspace ? "." : "", name, impl, index);
1003 dump_blob (MonoImage *m, const char* blob)
1007 bsize = mono_metadata_decode_blob_size (blob, &blob);
1009 for (j = 0; j < bsize; j++) {
1010 fprintf (output, "%02x ", blob [j] & 0xff);
1015 dump_table_field_marshal (MonoImage *m)
1017 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELDMARSHAL];
1018 guint32 cols [MONO_FIELD_MARSHAL_SIZE];
1019 int i, is_field, idx;
1023 fprintf (output, "FieldMarshal Table (1..%d)\n", t->rows);
1025 for (i = 1; i <= t->rows; i++) {
1026 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_MARSHAL_SIZE);
1027 blob = mono_metadata_blob_heap (m, cols [MONO_FIELD_MARSHAL_NATIVE_TYPE]);
1028 native = get_marshal_info (m, blob);
1029 is_field = (cols [MONO_FIELD_MARSHAL_PARENT] & MONO_HAS_FIELD_MARSHAL_MASK) == MONO_HAS_FIELD_MARSHAL_FIELDSREF;
1030 idx = cols [MONO_FIELD_MARSHAL_PARENT] >> MONO_HAS_FIELD_MARSHAL_BITS;
1031 fprintf (output, "%d: (0x%04x) %s %d: %s\n", i, cols [MONO_FIELD_MARSHAL_PARENT], is_field? "Field" : "Param", idx, native);
1032 fprintf (output, "\tblob encoding: ");
1033 dump_blob (m, blob);
1034 fprintf (output, "\n");
1041 get_security_action (int val) {
1042 static char buf [32];
1045 case SECURITY_ACTION_DEMAND:
1047 case SECURITY_ACTION_ASSERT:
1049 case SECURITY_ACTION_DENY:
1051 case SECURITY_ACTION_PERMITONLY:
1052 return "PermitOnly";
1053 case SECURITY_ACTION_LINKDEMAND:
1054 return "LinkDemand";
1055 case SECURITY_ACTION_INHERITDEMAND:
1056 return "InheritanceDemand";
1057 case SECURITY_ACTION_REQMIN:
1058 return "RequestMinimum";
1059 case SECURITY_ACTION_REQOPT:
1060 return "RequestOptional";
1061 case SECURITY_ACTION_REQREFUSE:
1062 return "RequestRefuse";
1063 /* Special actions (for non CAS permissions) */
1064 case SECURITY_ACTION_NONCASDEMAND:
1065 return "NonCasDemand";
1066 case SECURITY_ACTION_NONCASLINKDEMAND:
1067 return "NonCasLinkDemand";
1068 case SECURITY_ACTION_NONCASINHERITANCE:
1069 return "NonCasInheritance";
1070 /* Fx 2.0 actions (for both CAS and non-CAS permissions) */
1071 case SECURITY_ACTION_LINKDEMANDCHOICE:
1072 return "LinkDemandChoice";
1073 case SECURITY_ACTION_INHERITDEMANDCHOICE:
1074 return "InheritanceDemandChoice";
1075 case SECURITY_ACTION_DEMANDCHOICE:
1076 return "DemandChoice";
1078 g_snprintf (buf, sizeof (buf), "0x%04X", val);
1084 dump_table_declsec (MonoImage *m)
1086 MonoTableInfo *t = &m->tables [MONO_TABLE_DECLSECURITY];
1087 guint32 cols [MONO_DECL_SECURITY_SIZE];
1090 const char *blob, *action;
1091 const char* parent[] = {
1092 "TypeDef", "MethodDef", "Assembly", ""
1095 fprintf (output, "DeclSecurity Table (1..%d)\n", t->rows);
1097 for (i = 1; i <= t->rows; i++) {
1098 mono_metadata_decode_row (t, i - 1, cols, MONO_DECL_SECURITY_SIZE);
1099 blob = mono_metadata_blob_heap (m, cols [MONO_DECL_SECURITY_PERMISSIONSET]);
1100 len = mono_metadata_decode_blob_size (blob, &blob);
1101 action = get_security_action (cols [MONO_DECL_SECURITY_ACTION]);
1102 idx = cols [MONO_DECL_SECURITY_PARENT];
1103 fprintf (output, "%d: %s on %s %d%s", i, action, parent [idx & MONO_HAS_DECL_SECURITY_MASK], idx >> MONO_HAS_DECL_SECURITY_BITS, len? ":\n\t":"\n");
1106 if (blob [0] == MONO_DECLSEC_FORMAT_20) {
1107 /* 2.0 declarative security format */
1108 char *declsec = dump_declsec_entry20 (m, blob, "\t");
1109 fprintf (output, "%s", declsec);
1112 /* 1.0 declarative security format - Unicode XML */
1113 for (idx = 0; idx < len; ++idx)
1114 fprintf (output, "%c", blob [idx]);
1116 fprintf (output, "\n");
1121 dump_table_genericpar (MonoImage *m)
1123 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAM];
1124 guint32 cols [MONO_GENERICPARAM_SIZE];
1127 fprintf (output, "GenericParameters (1..%d)\n", t->rows);
1129 for (i = 1; i <= t->rows; i++) {
1131 mono_metadata_decode_row (t, i - 1, cols, MONO_GENERICPARAM_SIZE);
1133 // sig = get_type_or_methdef (m, cols [MONO_GENERICPARAM_OWNER]);
1134 sig = g_strdup_printf ("%x", cols [MONO_GENERICPARAM_OWNER]);
1135 fprintf (output, "%d: %d, flags=%d, owner=%s %s\n", i,
1136 cols [MONO_GENERICPARAM_NUMBER],
1137 cols [MONO_GENERICPARAM_FLAGS], sig,
1138 mono_metadata_string_heap (m, cols [MONO_GENERICPARAM_NAME]));
1144 dump_table_methodspec (MonoImage *m)
1146 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSPEC];
1147 guint32 cols [MONO_METHODSPEC_SIZE];
1150 fprintf (output, "MethodSpec (1..%d)\n", t->rows);
1152 for (i = 1; i <= t->rows; i++) {
1157 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODSPEC_SIZE);
1159 /* build a methodspec token to get the method */
1160 token = MONO_TOKEN_METHOD_SPEC | i;
1161 method = get_method (m, token, NULL);
1163 sig = get_method_type_param (m, cols [MONO_METHODSPEC_SIGNATURE], NULL);
1164 fprintf (output, "%d: %s, %s\n", i, method, sig);
1171 dump_table_parconstraint (MonoImage *m)
1173 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAMCONSTRAINT];
1174 guint32 cols [MONO_GENPARCONSTRAINT_SIZE];
1177 fprintf (output, "Generic Param Constraint (1..%d)\n", t->rows);
1179 for (i = 1; i <= t->rows; i++) {
1181 mono_metadata_decode_row (t, i - 1, cols, MONO_GENPARCONSTRAINT_SIZE);
1183 // sig = get_typedef_or_ref (m, cols [MONO_GENPARCONSTRAINT_CONSTRAINT], NULL);
1184 sig = g_strdup_printf ("%x", cols [MONO_GENPARCONSTRAINT_CONSTRAINT]);
1185 fprintf (output, "%d: gen-par=%d, Constraint=%s\n", i,
1186 cols [MONO_GENPARCONSTRAINT_GENERICPAR], sig);
1192 dump_stream_blob (MonoImage *m)
1196 fprintf (output, "Blob heap contents\n");
1198 for (i = 0; i < m->heap_blob.size; i++) {
1201 fprintf (output, "\n");
1202 else if ((i % 8) == 0)
1203 fprintf (output, "- ");
1205 fprintf (output, "%02x ", m->heap_blob.data [i] & 0xff);
1208 fprintf (output, "\n");
1212 dump_table_standalonesig (MonoImage *m)
1214 MonoTableInfo *t = &m->tables [MONO_TABLE_STANDALONESIG];
1215 guint32 cols [MONO_STAND_ALONE_SIGNATURE_SIZE];
1218 fprintf (output, "Stand alone signature (1..%d)\n", t->rows);
1220 for (i = 1; i <= t->rows; i++) {
1221 const char *locals_ptr;
1224 mono_metadata_decode_row (t, i - 1, cols, MONO_STAND_ALONE_SIGNATURE_SIZE);
1226 locals_ptr = mono_metadata_blob_heap (m, cols [MONO_STAND_ALONE_SIGNATURE]);
1227 bsize = mono_metadata_decode_blob_size (locals_ptr, &locals_ptr);
1229 fprintf (output, "%d: blob[0x%x] = ", i, cols [MONO_STAND_ALONE_SIGNATURE]);
1231 for (j = 0; j < bsize; j++) {
1232 fprintf (output, "%02x ", locals_ptr [j] & 0xff);
1234 fprintf (output, "\n");