2 * dump.c: Dumping routines for the disassembler.
5 * Miguel de Icaza (miguel@ximian.com)
7 * (C) 2001 Ximian, Inc.
18 #include "mono/metadata/loader.h"
19 #include "mono/metadata/class.h"
20 #include "mono/metadata/class-internals.h"
21 #include "mono/utils/mono-compiler.h"
26 extern int isinf (double);
32 dump_table_assembly (MonoImage *m)
34 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLY];
35 guint32 cols [MONO_ASSEMBLY_SIZE];
39 fprintf (output, "Assembly Table\n");
44 mono_metadata_decode_row (t, 0, cols, MONO_ASSEMBLY_SIZE);
46 fprintf (output, "Name: %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_NAME]));
47 fprintf (output, "Hash Algoritm: 0x%08x\n", cols [MONO_ASSEMBLY_HASH_ALG]);
48 fprintf (output, "Version: %d.%d.%d.%d\n", cols [MONO_ASSEMBLY_MAJOR_VERSION],
49 cols [MONO_ASSEMBLY_MINOR_VERSION],
50 cols [MONO_ASSEMBLY_BUILD_NUMBER],
51 cols [MONO_ASSEMBLY_REV_NUMBER]);
52 fprintf (output, "Flags: 0x%08x\n", cols [MONO_ASSEMBLY_FLAGS]);
53 fprintf (output, "PublicKey: BlobPtr (0x%08x)\n", cols [MONO_ASSEMBLY_PUBLIC_KEY]);
55 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLY_PUBLIC_KEY]);
56 len = mono_metadata_decode_value (ptr, &ptr);
58 fprintf (output, "\tDump:");
59 hex_dump (ptr, 0, len);
60 fprintf (output, "\n");
62 fprintf (output, "\tZero sized public key\n");
64 fprintf (output, "Culture: %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_CULTURE]));
65 fprintf (output, "\n");
69 dump_table_typeref (MonoImage *m)
71 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEREF];
74 fprintf (output, "Typeref Table\n");
76 for (i = 1; i <= t->rows; i++){
77 char *s = get_typeref (m, i);
79 fprintf (output, "%d: %s\n", i, s);
82 fprintf (output, "\n");
86 dump_table_typedef (MonoImage *m)
88 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEDEF];
91 fprintf (output, "Typedef Table\n");
93 for (i = 1; i <= t->rows; i++){
94 char *s = get_typedef (m, i);
95 guint32 cols [MONO_TYPEDEF_SIZE];
97 mono_metadata_decode_row (&m->tables [MONO_TABLE_TYPEDEF], i - 1, cols, MONO_TYPEDEF_SIZE);
99 fprintf (output, "%d: %s (flist=%d, mlist=%d, flags=0x%x, extends=0x%x)\n", i, s,
100 cols [MONO_TYPEDEF_FIELD_LIST], cols [MONO_TYPEDEF_METHOD_LIST],
101 cols [MONO_TYPEDEF_FLAGS], cols [MONO_TYPEDEF_EXTENDS]);
104 fprintf (output, "\n");
108 dump_table_typespec (MonoImage *m)
110 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPESPEC];
113 fprintf (output, "Typespec Table\n");
115 for (i = 1; i <= t->rows; i++){
116 char *typespec = get_typespec (m, i, TRUE, NULL);
118 fprintf (output, "%d: %s\n", i, typespec);
121 fprintf (output, "\n");
125 dump_table_assemblyref (MonoImage *m)
127 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLYREF];
130 fprintf (output, "AssemblyRef Table\n");
132 for (i = 0; i < t->rows; i++){
135 guint32 cols [MONO_ASSEMBLYREF_SIZE];
137 mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
138 fprintf (output, "%d: Version=%d.%d.%d.%d\n\tName=%s\n", i + 1,
139 cols [MONO_ASSEMBLYREF_MAJOR_VERSION],
140 cols [MONO_ASSEMBLYREF_MINOR_VERSION],
141 cols [MONO_ASSEMBLYREF_BUILD_NUMBER],
142 cols [MONO_ASSEMBLYREF_REV_NUMBER],
143 mono_metadata_string_heap (m, cols [MONO_ASSEMBLYREF_NAME]));
144 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLYREF_PUBLIC_KEY]);
145 len = mono_metadata_decode_value (ptr, &ptr);
147 fprintf (output, "\tPublic Key:");
148 hex_dump (ptr, 0, len);
149 fprintf (output, "\n");
151 fprintf (output, "\tZero sized public key\n");
154 fprintf (output, "\n");
158 dump_table_param (MonoImage *m)
160 MonoTableInfo *t = &m->tables [MONO_TABLE_PARAM];
163 fprintf (output, "Param Table\n");
165 for (i = 0; i < t->rows; i++){
166 guint32 cols [MONO_PARAM_SIZE];
168 mono_metadata_decode_row (t, i, cols, MONO_PARAM_SIZE);
169 fprintf (output, "%d: 0x%04x %d %s\n",
171 cols [MONO_PARAM_FLAGS], cols [MONO_PARAM_SEQUENCE],
172 mono_metadata_string_heap (m, cols [MONO_PARAM_NAME]));
174 fprintf (output, "\n");
178 dump_table_field (MonoImage *m)
180 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELD];
181 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
182 MonoTableInfo *fl = &m->tables [MONO_TABLE_FIELDLAYOUT];
183 MonoTableInfo *rva = &m->tables [MONO_TABLE_FIELDRVA];
184 int i, current_type, offset_row, rva_row;
185 guint32 first_m, last_m;
187 fprintf (output, "Field Table (1..%d)\n", t->rows);
189 rva_row = offset_row = current_type = 1;
190 last_m = first_m = 1;
191 for (i = 1; i <= t->rows; i++){
192 guint32 cols [MONO_FIELD_SIZE];
196 * Find the next type.
198 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_FIELD_LIST))) {
202 fprintf (output, "########## %s.%s\n",
203 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
204 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
207 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_SIZE);
208 sig = get_field_signature (m, cols [MONO_FIELD_SIGNATURE], NULL);
209 flags = field_flags (cols [MONO_FIELD_FLAGS]);
210 fprintf (output, "%d: %s %s: %s\n",
213 mono_metadata_string_heap (m, cols [MONO_FIELD_NAME]),
217 if (offset_row <= fl->rows && (mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_FIELD) == i)) {
218 fprintf (output, "\texplicit offset: %d\n", mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_OFFSET));
221 if (rva_row <= rva->rows && (mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_FIELD) == i)) {
222 fprintf (output, "\trva: %d\n", mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_RVA));
226 fprintf (output, "\n");
230 dump_table_memberref (MonoImage *m)
232 MonoTableInfo *t = &m->tables [MONO_TABLE_MEMBERREF];
236 const char *blob, *ks = NULL;
238 fprintf (output, "MemberRef Table (1..%d)\n", t->rows);
240 for (i = 0; i < t->rows; i++){
241 guint32 cols [MONO_MEMBERREF_SIZE];
243 mono_metadata_decode_row (t, i, cols, MONO_MEMBERREF_SIZE);
245 kind = cols [MONO_MEMBERREF_CLASS] & 7;
246 idx = cols [MONO_MEMBERREF_CLASS] >> 3;
248 x = g_strdup ("UNHANDLED CASE");
253 xx = get_typedef (m, idx);
254 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
259 xx = get_typeref (m, idx);
260 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
264 ks = "ModuleRef"; break;
267 x = get_methoddef (m, idx);
271 xx = get_typespec (m, idx, FALSE, NULL);
272 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
276 g_error ("Unknown tag: %d\n", kind);
278 blob = mono_metadata_blob_heap (m, cols [MONO_MEMBERREF_SIGNATURE]);
279 mono_metadata_decode_blob_size (blob, &blob);
280 if (*blob == 0x6) { /* it's a field */
281 sig = get_field_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL);
283 sig = get_methodref_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL, NULL);
285 fprintf (output, "%d: %s[%d] %s\n\tResolved: %s\n\tSignature: %s\n\t\n",
288 mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]),
299 dump_table_class_layout (MonoImage *m)
301 MonoTableInfo *t = &m->tables [MONO_TABLE_CLASSLAYOUT];
303 fprintf (output, "ClassLayout Table (1..%d)\n", t->rows);
305 for (i = 0; i < t->rows; i++){
306 guint32 cols [MONO_CLASS_LAYOUT_SIZE];
308 mono_metadata_decode_row (t, i, cols, MONO_CLASS_LAYOUT_SIZE);
310 fprintf (output, "%d: PackingSize=%d ClassSize=%d Parent=%s\n",
311 i + 1, cols [MONO_CLASS_LAYOUT_PACKING_SIZE],
312 cols [MONO_CLASS_LAYOUT_CLASS_SIZE],
313 get_typedef (m, cols [MONO_CLASS_LAYOUT_PARENT]));
318 dump_table_constant (MonoImage *m)
320 MonoTableInfo *t = &m->tables [MONO_TABLE_CONSTANT];
322 const char *desc [] = {
328 fprintf (output, "Constant Table (1..%d)\n", t->rows);
330 for (i = 0; i < t->rows; i++){
331 guint32 cols [MONO_CONSTANT_SIZE];
333 mono_metadata_decode_row (t, i, cols, MONO_CONSTANT_SIZE);
334 parent = desc [cols [MONO_CONSTANT_PARENT] & MONO_HASCONSTANT_MASK];
336 fprintf (output, "%d: Parent= %s: %d %s\n",
337 i + 1, parent, cols [MONO_CONSTANT_PARENT] >> MONO_HASCONSTANT_BITS,
338 get_constant (m, (MonoTypeEnum) cols [MONO_CONSTANT_TYPE], cols [MONO_CONSTANT_VALUE]));
344 dump_table_property_map (MonoImage *m)
346 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTYMAP];
350 fprintf (output, "Property Map Table (1..%d)\n", t->rows);
352 for (i = 0; i < t->rows; i++){
353 guint32 cols [MONO_PROPERTY_MAP_SIZE];
355 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_MAP_SIZE);
356 s = get_typedef (m, cols [MONO_PROPERTY_MAP_PARENT]);
357 fprintf (output, "%d: %s (%d) %d\n", i + 1, s, cols [MONO_PROPERTY_MAP_PARENT], cols [MONO_PROPERTY_MAP_PROPERTY_LIST]);
363 dump_table_property (MonoImage *m)
365 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTY];
370 fprintf (output, "Property Table (1..%d)\n", t->rows);
372 for (i = 0; i < t->rows; i++){
373 guint32 cols [MONO_PROPERTY_SIZE];
378 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_SIZE);
380 prop_flags = cols [MONO_PROPERTY_FLAGS];
381 if (prop_flags & 0x0200)
382 strcat (flags, "special ");
383 if (prop_flags & 0x0400)
384 strcat (flags, "runtime ");
385 if (prop_flags & 0x1000)
386 strcat (flags, "hasdefault ");
388 ptr = mono_metadata_blob_heap (m, cols [MONO_PROPERTY_TYPE]);
389 bsize = mono_metadata_decode_blob_size (ptr, &ptr);
390 /* ECMA claims 0x08 ... */
391 if (*ptr != 0x28 && *ptr != 0x08)
392 g_warning("incorrect signature in propert blob: 0x%x", *ptr);
394 pcount = mono_metadata_decode_value (ptr, &ptr);
395 ptr = get_type (m, ptr, &type, NULL);
396 fprintf (output, "%d: %s %s (",
397 i + 1, type, mono_metadata_string_heap (m, cols [MONO_PROPERTY_NAME]));
400 for (j = 0; j < pcount; j++){
401 ptr = get_param (m, ptr, &type, NULL);
402 fprintf (output, "%s%s", j > 0? ", " : "",type);
405 fprintf (output, ") %s\n", flags);
410 dump_table_event (MonoImage *m)
412 MonoTableInfo *t = &m->tables [MONO_TABLE_EVENT];
414 fprintf (output, "Event Table (1..%d)\n", t->rows);
416 for (i = 0; i < t->rows; i++){
417 guint32 cols [MONO_EVENT_SIZE];
421 mono_metadata_decode_row (t, i, cols, MONO_EVENT_SIZE);
423 name = mono_metadata_string_heap (m, cols [MONO_EVENT_NAME]);
424 type = get_typedef_or_ref (m, cols [MONO_EVENT_TYPE], NULL);
425 fprintf (output, "%d: %s %s %s\n", i + 1, type, name,
426 cols [MONO_EVENT_FLAGS] & 0x200 ? "specialname " : "");
433 dump_table_file (MonoImage *m)
435 MonoTableInfo *t = &m->tables [MONO_TABLE_FILE];
437 fprintf (output, "File Table (1..%d)\n", t->rows);
439 for (i = 0; i < t->rows; i++){
440 guint32 cols [MONO_FILE_SIZE];
441 const char *name, *hash;
443 mono_metadata_decode_row (t, i, cols, MONO_FILE_SIZE);
445 name = mono_metadata_string_heap (m, cols [MONO_FILE_NAME]);
446 fprintf (output, "%d: %s %s [", i + 1, name,
447 cols [MONO_FILE_FLAGS] & 0x1 ? "nometadata" : "containsmetadata");
448 hash = mono_metadata_blob_heap (m, cols [MONO_FILE_HASH_VALUE]);
449 len = mono_metadata_decode_blob_size (hash, &hash);
450 for (j = 0; j < len; ++j)
451 fprintf (output, "%s%02X", j? " ": "", hash [j] & 0xff);
452 fprintf (output, "]\n");
458 get_manifest_implementation (MonoImage *m, guint32 idx)
461 const char* table = "";
463 return g_strdup ("current module");
464 row = idx >> MONO_IMPLEMENTATION_BITS;
465 switch (idx & MONO_IMPLEMENTATION_MASK) {
466 case MONO_IMPLEMENTATION_FILE:
469 case MONO_IMPLEMENTATION_ASSEMBLYREF:
470 table = "assemblyref";
472 case MONO_IMPLEMENTATION_EXP_TYPE:
473 table = "exportedtype";
476 g_assert_not_reached ();
478 return g_strdup_printf ("%s %d", table, row);
482 get_manifest_flags (guint32 mf)
486 case 1: return "public";
487 case 2: return "private";
494 dump_table_manifest (MonoImage *m)
496 MonoTableInfo *t = &m->tables [MONO_TABLE_MANIFESTRESOURCE];
498 fprintf (output, "Manifestresource Table (1..%d)\n", t->rows);
500 for (i = 0; i < t->rows; i++){
501 guint32 cols [MONO_MANIFEST_SIZE];
502 const char *name, *mf;
505 mono_metadata_decode_row (t, i, cols, MONO_MANIFEST_SIZE);
507 name = mono_metadata_string_heap (m, cols [MONO_MANIFEST_NAME]);
508 mf = get_manifest_flags (cols [MONO_MANIFEST_FLAGS]);
509 impl = get_manifest_implementation (m, cols [MONO_MANIFEST_IMPLEMENTATION]);
510 fprintf (output, "%d: %s '%s' at offset %u in %s\n", i + 1, mf, name, cols [MONO_MANIFEST_OFFSET], impl);
517 dump_table_moduleref (MonoImage *m)
519 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULEREF];
521 fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
523 for (i = 0; i < t->rows; i++){
524 guint32 cols [MONO_MODULEREF_SIZE];
527 mono_metadata_decode_row (t, i, cols, MONO_MODULEREF_SIZE);
529 name = mono_metadata_string_heap (m, cols [MONO_MODULEREF_NAME]);
530 fprintf (output, "%d: %s\n", i + 1, name);
536 dump_table_module (MonoImage *m)
538 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULE];
540 fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
542 for (i = 0; i < t->rows; i++){
543 guint32 cols [MONO_MODULE_SIZE];
547 mono_metadata_decode_row (t, i, cols, MONO_MODULE_SIZE);
549 name = mono_metadata_string_heap (m, cols [MONO_MODULE_NAME]);
550 guid = get_guid (m, cols [MONO_MODULE_MVID]);
551 fprintf (output, "%d: %s %d %s\n", i + 1, name, cols [MONO_MODULE_MVID], guid);
556 dump_table_method (MonoImage *m)
558 MonoTableInfo *t = &m->tables [MONO_TABLE_METHOD];
559 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
561 guint32 first_m, last_m;
562 /* Generic container for Type & method */
563 MonoGenericContainer *type_container = NULL, *method_container = NULL;
565 fprintf (output, "Method Table (1..%d)\n", t->rows);
568 last_m = first_m = 1;
569 for (i = 1; i <= t->rows; i++){
570 guint32 cols [MONO_METHOD_SIZE];
573 MonoMethodSignature *method;
576 * Find the next type.
578 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_METHOD_LIST))) {
582 fprintf (output, "########## %s.%s\n",
583 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
584 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
586 type_container = mono_metadata_load_generic_params (m, MONO_TOKEN_TYPE_DEF | (current_type - 1), NULL);
589 method_container = mono_metadata_load_generic_params (m, MONO_TOKEN_METHOD_DEF | i, type_container);
590 mono_metadata_decode_row (t, i - 1, cols, MONO_METHOD_SIZE);
591 sigblob = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
592 mono_metadata_decode_blob_size (sigblob, &sigblob);
593 method = mono_metadata_parse_method_signature_full (m, method_container ? method_container : type_container, i, sigblob, &sigblob);
594 sig = dis_stringify_method_signature (m, method, i, (MonoGenericContext *) (method_container ? method_container : type_container), FALSE);
595 fprintf (output, "%d: %s (param: %d)\n", i, sig, cols [MONO_METHOD_PARAMLIST]);
597 mono_metadata_free_method_signature (method);
603 dump_table_implmap (MonoImage *m)
605 MonoTableInfo *t = &m->tables [MONO_TABLE_IMPLMAP];
606 MonoTableInfo *td = &m->tables [MONO_TABLE_MODULEREF];
609 fprintf (output, "ImplMap Table (1..%d)\n", t->rows);
611 for (i = 1; i <= t->rows; i++){
612 guint32 cols [MONO_IMPLMAP_SIZE];
615 mono_metadata_decode_row (t, i - 1, cols, MONO_IMPLMAP_SIZE);
617 method = get_method (m, MONO_TOKEN_METHOD_DEF | (cols [MONO_IMPLMAP_MEMBER] >> MONO_MEMBERFORWD_BITS), NULL);
619 fprintf (output, "%d: %s %d (%s %s)\n", i,
621 cols [MONO_IMPLMAP_FLAGS],
622 mono_metadata_string_heap (m, cols [MONO_IMPLMAP_NAME]),
623 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, cols [MONO_IMPLMAP_SCOPE] - 1, MONO_MODULEREF_NAME)));
628 dump_table_methodimpl (MonoImage *m)
630 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODIMPL];
631 /*MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];*/
634 fprintf (output, "MethodImpl Table (1..%d)\n", t->rows);
636 for (i = 1; i <= t->rows; i++){
637 guint32 cols [MONO_METHODIMPL_SIZE];
638 char *class, *impl, *decl;
640 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODIMPL_SIZE);
641 class = get_typedef (m, cols [MONO_METHODIMPL_CLASS]);
642 impl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_BODY]), NULL);
643 decl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_DECLARATION]), NULL);
644 fprintf (output, "%d: %s\n\tdecl: %s\n\timpl: %s\n", i, class, decl, impl);
652 static dis_map_t semantics_map [] = {
663 dump_table_methodsem (MonoImage *m)
665 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSEMANTICS];
666 int i, is_property, index;
667 const char *semantics;
669 fprintf (output, "Method Semantics Table (1..%d)\n", t->rows);
670 for (i = 1; i <= t->rows; i++){
671 guint32 cols [MONO_METHOD_SEMA_SIZE];
673 mono_metadata_decode_row (t, i - 1, cols, MONO_METHOD_SEMA_SIZE);
674 semantics = flags (cols [MONO_METHOD_SEMA_SEMANTICS], semantics_map);
675 is_property = cols [MONO_METHOD_SEMA_ASSOCIATION] & MONO_HAS_SEMANTICS_MASK;
676 index = cols [MONO_METHOD_SEMA_ASSOCIATION] >> MONO_HAS_SEMANTICS_BITS;
677 fprintf (output, "%d: [%d] %s method: %d %s %d\n", i, cols [MONO_METHOD_SEMA_ASSOCIATION], semantics,
678 cols [MONO_METHOD_SEMA_METHOD] - 1,
679 is_property? "property" : "event",
685 dump_table_interfaceimpl (MonoImage *m)
687 MonoTableInfo *t = &m->tables [MONO_TABLE_INTERFACEIMPL];
690 fprintf (output, "Interface Implementation Table (1..%d)\n", t->rows);
691 for (i = 1; i <= t->rows; i++) {
692 guint32 cols [MONO_INTERFACEIMPL_SIZE];
694 mono_metadata_decode_row (t, i - 1, cols, MONO_INTERFACEIMPL_SIZE);
695 fprintf (output, "%d: %s implements %s\n", i,
696 get_typedef (m, cols [MONO_INTERFACEIMPL_CLASS]),
697 get_typedef_or_ref (m, cols [MONO_INTERFACEIMPL_INTERFACE], NULL));
702 has_cattr_get_table (MonoImage *m, guint32 val)
704 guint32 t = val & MONO_CUSTOM_ATTR_MASK;
705 guint32 index = val >> MONO_CUSTOM_ATTR_BITS;
709 case MONO_CUSTOM_ATTR_METHODDEF:
712 case MONO_CUSTOM_ATTR_FIELDDEF:
715 case MONO_CUSTOM_ATTR_TYPEREF:
718 case MONO_CUSTOM_ATTR_TYPEDEF:
721 case MONO_CUSTOM_ATTR_PARAMDEF:
724 case MONO_CUSTOM_ATTR_INTERFACE:
725 table = "InterfaceImpl";
727 case MONO_CUSTOM_ATTR_MEMBERREF:
730 case MONO_CUSTOM_ATTR_MODULE:
733 case MONO_CUSTOM_ATTR_PERMISSION:
734 table = "DeclSecurity?";
736 case MONO_CUSTOM_ATTR_PROPERTY:
739 case MONO_CUSTOM_ATTR_EVENT:
742 case MONO_CUSTOM_ATTR_SIGNATURE:
743 table = "StandAloneSignature";
745 case MONO_CUSTOM_ATTR_MODULEREF:
748 case MONO_CUSTOM_ATTR_TYPESPEC:
751 case MONO_CUSTOM_ATTR_ASSEMBLY:
754 case MONO_CUSTOM_ATTR_ASSEMBLYREF:
755 table = "AssemblyRef";
757 case MONO_CUSTOM_ATTR_FILE:
760 case MONO_CUSTOM_ATTR_EXP_TYPE:
761 table = "ExportedType";
763 case MONO_CUSTOM_ATTR_MANIFEST:
771 * FIXME: we should decode the index into something more uman-friendly.
773 return g_strdup_printf ("%s: %d", table, index);
777 custom_attr_params (MonoImage *m, MonoMethodSignature* sig, const char* value)
779 int len, i, slen, type;
782 const char *p = value;
784 len = mono_metadata_decode_value (p, &p);
785 if (len < 2 || read16 (p) != 0x0001) /* Prolog */
786 return g_strdup ("");
790 res = g_string_new ("");
791 for (i = 0; i < sig->param_count; ++i) {
793 g_string_append (res, ", ");
794 type = sig->params [i]->type;
798 g_string_sprintfa (res, "%d", (unsigned int)*p);
802 g_string_sprintfa (res, "%d", *p);
805 case MONO_TYPE_BOOLEAN:
806 g_string_sprintfa (res, "%s", *p?"true":"false");
810 g_string_sprintfa (res, "'%c'", read16 (p));
814 g_string_sprintfa (res, "%d", read16 (p));
818 g_string_sprintfa (res, "%d", (gint16)read16 (p));
822 g_string_sprintfa (res, "%d", read32 (p));
826 g_string_sprintfa (res, "%d", (gint32)read32 (p));
830 g_string_sprintfa (res, "%lld", (long long)read64 (p));
834 g_string_sprintfa (res, "%lld", (long long)read64 (p));
843 g_string_sprintfa (res, "(00 00 80 ff)"); /* negative infinity */
845 g_string_sprintfa (res, "(00 00 80 7f)"); /* positive infinity */
846 else if (isnan (val))
847 g_string_sprintfa (res, "(00 00 c0 ff)"); /* NaN */
849 g_string_sprintfa (res, "%g", val);
860 g_string_sprintfa (res, "(00 00 00 00 00 00 f0 ff)"); /* negative infinity */
862 g_string_sprintfa (res, "(00 00 00 00 00 00 f0 7f)"); /* positive infinity */
863 else if (isnan (val))
864 g_string_sprintfa (res, "(00 00 00 00 00 00 f8 ff)"); /* NaN */
866 g_string_sprintfa (res, "%g", val);
870 case MONO_TYPE_VALUETYPE:
871 if (mono_class_is_enum (sig->params [i]->data.klass)) {
872 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
875 g_warning ("generic valutype not handled in custom attr value decoding");
878 case MONO_TYPE_CLASS: /* It must be a Type: check? */
879 case MONO_TYPE_STRING:
880 if (*p == (char)0xff) {
881 g_string_append (res, "null");
885 slen = mono_metadata_decode_value (p, &p);
886 g_string_append_c (res, '"');
887 g_string_append (res, p);
888 g_string_append_c (res, '"');
892 g_warning ("Type %02x not handled in custom attr value decoding", sig->params [i]->type);
898 g_string_sprintfa (res, " %d named args: (", slen);
899 slen = len - (p - value) + 1;
900 for (i = 0; i < slen; ++i) {
901 g_string_sprintfa (res, " %02X", (p [i] & 0xff));
903 g_string_append_c (res, ')');
906 g_string_free (res, FALSE);
911 dump_table_customattr (MonoImage *m)
913 MonoTableInfo *t = &m->tables [MONO_TABLE_CUSTOMATTRIBUTE];
916 fprintf (output, "Custom Attributes Table (1..%d)\n", t->rows);
917 for (i = 1; i <= t->rows; i++) {
918 guint32 cols [MONO_CUSTOM_ATTR_SIZE];
925 mono_metadata_decode_row (t, i - 1, cols, MONO_CUSTOM_ATTR_SIZE);
926 desc = has_cattr_get_table (m, cols [MONO_CUSTOM_ATTR_PARENT]);
927 mtoken = cols [MONO_CUSTOM_ATTR_TYPE] >> MONO_CUSTOM_ATTR_TYPE_BITS;
928 switch (cols [MONO_CUSTOM_ATTR_TYPE] & MONO_CUSTOM_ATTR_TYPE_MASK) {
929 case MONO_CUSTOM_ATTR_TYPE_METHODDEF:
930 mtoken |= MONO_TOKEN_METHOD_DEF;
932 case MONO_CUSTOM_ATTR_TYPE_MEMBERREF:
933 mtoken |= MONO_TOKEN_MEMBER_REF;
936 g_warning ("Unknown table for custom attr type %08x", cols [MONO_CUSTOM_ATTR_TYPE]);
939 method = get_method (m, mtoken, NULL);
940 meth = mono_get_method (m, mtoken, NULL);
941 params = custom_attr_params (m, mono_method_signature (meth), mono_metadata_blob_heap (m, cols [MONO_CUSTOM_ATTR_VALUE]));
942 fprintf (output, "%d: %s: %s [%s]\n", i, desc, method, params);
950 dump_table_nestedclass (MonoImage *m)
952 MonoTableInfo *t = &m->tables [MONO_TABLE_NESTEDCLASS];
953 guint32 cols [MONO_NESTED_CLASS_SIZE];
955 char *nested, *nesting;
956 fprintf (output, "NestedClass Table (1..%d)\n", t->rows);
958 for (i = 1; i <= t->rows; i++){
959 mono_metadata_decode_row (t, i - 1, cols, MONO_NESTED_CLASS_SIZE);
960 nested = get_typedef (m, cols [MONO_NESTED_CLASS_NESTED]);
961 nesting = get_typedef (m, cols [MONO_NESTED_CLASS_ENCLOSING]);
962 fprintf (output, "%d: %d %d: %s in %s\n", i,
963 cols [MONO_NESTED_CLASS_NESTED],
964 cols [MONO_NESTED_CLASS_ENCLOSING], nested, nesting);
972 dump_table_exported (MonoImage *m)
974 MonoTableInfo *t = &m->tables [MONO_TABLE_EXPORTEDTYPE];
975 guint32 cols [MONO_EXP_TYPE_SIZE];
977 const char *name, *nspace;
980 fprintf (output, "ExportedType Table (1..%d)\n", t->rows);
982 for (i = 1; i <= t->rows; i++) {
983 mono_metadata_decode_row (t, i - 1, cols, MONO_EXP_TYPE_SIZE);
984 name = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAME]);
985 nspace = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAMESPACE]);
986 impl = get_manifest_implementation (m, cols [MONO_EXP_TYPE_IMPLEMENTATION]);
987 index = cols [MONO_EXP_TYPE_TYPEDEF];
988 fprintf (output, "%d: %s%s%s is in %s, token %x\n", i, nspace, *nspace ? "." : "", name, impl, index);
995 dump_blob (MonoImage *m, const char* blob)
999 bsize = mono_metadata_decode_blob_size (blob, &blob);
1001 for (j = 0; j < bsize; j++) {
1002 fprintf (output, "%02x ", blob [j] & 0xff);
1007 dump_table_field_marshal (MonoImage *m)
1009 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELDMARSHAL];
1010 guint32 cols [MONO_FIELD_MARSHAL_SIZE];
1011 int i, is_field, idx;
1015 fprintf (output, "FieldMarshal Table (1..%d)\n", t->rows);
1017 for (i = 1; i <= t->rows; i++) {
1018 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_MARSHAL_SIZE);
1019 blob = mono_metadata_blob_heap (m, cols [MONO_FIELD_MARSHAL_NATIVE_TYPE]);
1020 native = get_marshal_info (m, blob);
1021 is_field = (cols [MONO_FIELD_MARSHAL_PARENT] & MONO_HAS_FIELD_MARSHAL_MASK) == MONO_HAS_FIELD_MARSHAL_FIELDSREF;
1022 idx = cols [MONO_FIELD_MARSHAL_PARENT] >> MONO_HAS_FIELD_MARSHAL_BITS;
1023 fprintf (output, "%d: (0x%04x) %s %d: %s\n", i, cols [MONO_FIELD_MARSHAL_PARENT], is_field? "Field" : "Param", idx, native);
1024 fprintf (output, "\tblob encoding: ");
1025 dump_blob (m, blob);
1026 fprintf (output, "\n");
1033 get_security_action (int val) {
1034 static char buf [32];
1037 case SECURITY_ACTION_DEMAND:
1039 case SECURITY_ACTION_ASSERT:
1041 case SECURITY_ACTION_DENY:
1043 case SECURITY_ACTION_PERMITONLY:
1044 return "PermitOnly";
1045 case SECURITY_ACTION_LINKDEMAND:
1046 return "LinkDemand";
1047 case SECURITY_ACTION_INHERITDEMAND:
1048 return "InheritanceDemand";
1049 case SECURITY_ACTION_REQMIN:
1050 return "RequestMinimum";
1051 case SECURITY_ACTION_REQOPT:
1052 return "RequestOptional";
1053 case SECURITY_ACTION_REQREFUSE:
1054 return "RequestRefuse";
1055 /* Special actions (for non CAS permissions) */
1056 case SECURITY_ACTION_NONCASDEMAND:
1057 return "NonCasDemand";
1058 case SECURITY_ACTION_NONCASLINKDEMAND:
1059 return "NonCasLinkDemand";
1060 case SECURITY_ACTION_NONCASINHERITANCE:
1061 return "NonCasInheritance";
1062 /* Fx 2.0 actions (for both CAS and non-CAS permissions) */
1063 case SECURITY_ACTION_LINKDEMANDCHOICE:
1064 return "LinkDemandChoice";
1065 case SECURITY_ACTION_INHERITDEMANDCHOICE:
1066 return "InheritanceDemandChoice";
1067 case SECURITY_ACTION_DEMANDCHOICE:
1068 return "DemandChoice";
1070 g_snprintf (buf, sizeof (buf), "0x%04X", val);
1076 dump_table_declsec (MonoImage *m)
1078 MonoTableInfo *t = &m->tables [MONO_TABLE_DECLSECURITY];
1079 guint32 cols [MONO_DECL_SECURITY_SIZE];
1082 const char *blob, *action;
1083 const char* parent[] = {
1084 "TypeDef", "MethodDef", "Assembly", ""
1087 fprintf (output, "DeclSecurity Table (1..%d)\n", t->rows);
1089 for (i = 1; i <= t->rows; i++) {
1090 mono_metadata_decode_row (t, i - 1, cols, MONO_DECL_SECURITY_SIZE);
1091 blob = mono_metadata_blob_heap (m, cols [MONO_DECL_SECURITY_PERMISSIONSET]);
1092 len = mono_metadata_decode_blob_size (blob, &blob);
1093 action = get_security_action (cols [MONO_DECL_SECURITY_ACTION]);
1094 idx = cols [MONO_DECL_SECURITY_PARENT];
1095 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");
1098 for (idx = 0; idx < len; ++idx)
1099 fprintf (output, "%c", blob [idx]);
1100 fprintf (output, "\n");
1105 dump_table_genericpar (MonoImage *m)
1107 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAM];
1108 guint32 cols [MONO_GENERICPARAM_SIZE];
1111 fprintf (output, "GenericParameters (1..%d)\n", t->rows);
1113 for (i = 1; i <= t->rows; i++) {
1115 mono_metadata_decode_row (t, i - 1, cols, MONO_GENERICPARAM_SIZE);
1117 // sig = get_type_or_methdef (m, cols [MONO_GENERICPARAM_OWNER]);
1118 sig = g_strdup_printf ("%x", cols [MONO_GENERICPARAM_OWNER]);
1119 fprintf (output, "%d: %d, flags=%d, owner=%s %s\n", i,
1120 cols [MONO_GENERICPARAM_NUMBER],
1121 cols [MONO_GENERICPARAM_FLAGS], sig,
1122 mono_metadata_string_heap (m, cols [MONO_GENERICPARAM_NAME]));
1128 dump_table_methodspec (MonoImage *m)
1130 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSPEC];
1131 guint32 cols [MONO_METHODSPEC_SIZE];
1134 fprintf (output, "MethodSpec (1..%d)\n", t->rows);
1136 for (i = 1; i <= t->rows; i++) {
1141 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODSPEC_SIZE);
1143 /* build a methodspec token to get the method */
1144 token = MONO_TOKEN_METHOD_SPEC | i;
1145 method = get_method (m, token, NULL);
1147 sig = get_method_type_param (m, cols [MONO_METHODSPEC_SIGNATURE], NULL);
1148 fprintf (output, "%d: %s, %s\n", i, method, sig);
1155 dump_table_parconstraint (MonoImage *m)
1157 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAMCONSTRAINT];
1158 guint32 cols [MONO_GENPARCONSTRAINT_SIZE];
1161 fprintf (output, "Generic Param Constraint (1..%d)\n", t->rows);
1163 for (i = 1; i <= t->rows; i++) {
1165 mono_metadata_decode_row (t, i - 1, cols, MONO_GENPARCONSTRAINT_SIZE);
1167 // sig = get_typedef_or_ref (m, cols [MONO_GENPARCONSTRAINT_CONSTRAINT], NULL);
1168 sig = g_strdup_printf ("%x", cols [MONO_GENPARCONSTRAINT_CONSTRAINT]);
1169 fprintf (output, "%d: gen-par=%d, Constraint=%s\n", i,
1170 cols [MONO_GENPARCONSTRAINT_GENERICPAR], sig);
1176 dump_stream_blob (MonoImage *m)
1180 fprintf (output, "Blob heap contents\n");
1182 for (i = 0; i < m->heap_blob.size; i++) {
1185 fprintf (output, "\n");
1186 else if ((i % 8) == 0)
1187 fprintf (output, "- ");
1189 fprintf (output, "%02x ", m->heap_blob.data [i] & 0xff);
1192 fprintf (output, "\n");
1196 dump_table_standalonesig (MonoImage *m)
1198 MonoTableInfo *t = &m->tables [MONO_TABLE_STANDALONESIG];
1199 guint32 cols [MONO_STAND_ALONE_SIGNATURE_SIZE];
1202 fprintf (output, "Stand alone signature (1..%d)\n", t->rows);
1204 for (i = 1; i <= t->rows; i++) {
1205 const char *locals_ptr;
1208 mono_metadata_decode_row (t, i - 1, cols, MONO_STAND_ALONE_SIGNATURE_SIZE);
1210 locals_ptr = mono_metadata_blob_heap (m, cols [MONO_STAND_ALONE_SIGNATURE]);
1211 bsize = mono_metadata_decode_blob_size (locals_ptr, &locals_ptr);
1213 fprintf (output, "%d: blob[0x%x] = ", i, cols [MONO_STAND_ALONE_SIGNATURE]);
1215 for (j = 0; j < bsize; j++) {
1216 fprintf (output, "%02x ", locals_ptr [j] & 0xff);
1218 fprintf (output, "\n");