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 fprintf (output, "\tFlags=0x%08x\n", cols [MONO_ASSEMBLYREF_FLAGS]);
146 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLYREF_PUBLIC_KEY]);
147 len = mono_metadata_decode_value (ptr, &ptr);
149 fprintf (output, "\tPublic Key:");
150 hex_dump (ptr, 0, len);
151 fprintf (output, "\n");
153 fprintf (output, "\tZero sized public key\n");
156 fprintf (output, "\n");
160 dump_table_param (MonoImage *m)
162 MonoTableInfo *t = &m->tables [MONO_TABLE_PARAM];
165 fprintf (output, "Param Table\n");
167 for (i = 0; i < t->rows; i++){
168 guint32 cols [MONO_PARAM_SIZE];
170 mono_metadata_decode_row (t, i, cols, MONO_PARAM_SIZE);
171 fprintf (output, "%d: 0x%04x %d %s\n",
173 cols [MONO_PARAM_FLAGS], cols [MONO_PARAM_SEQUENCE],
174 mono_metadata_string_heap (m, cols [MONO_PARAM_NAME]));
176 fprintf (output, "\n");
180 dump_table_field (MonoImage *m)
182 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELD];
183 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
184 MonoTableInfo *fl = &m->tables [MONO_TABLE_FIELDLAYOUT];
185 MonoTableInfo *rva = &m->tables [MONO_TABLE_FIELDRVA];
186 int i, current_type, offset_row, rva_row;
187 guint32 first_m, last_m;
189 fprintf (output, "Field Table (1..%d)\n", t->rows);
191 rva_row = offset_row = current_type = 1;
192 last_m = first_m = 1;
193 for (i = 1; i <= t->rows; i++){
194 guint32 cols [MONO_FIELD_SIZE];
198 * Find the next type.
200 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_FIELD_LIST))) {
204 fprintf (output, "########## %s.%s\n",
205 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
206 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
209 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_SIZE);
210 sig = get_field_signature (m, cols [MONO_FIELD_SIGNATURE], NULL);
211 flags = field_flags (cols [MONO_FIELD_FLAGS]);
212 fprintf (output, "%d: %s %s: %s\n",
215 mono_metadata_string_heap (m, cols [MONO_FIELD_NAME]),
219 if (offset_row <= fl->rows && (mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_FIELD) == i)) {
220 fprintf (output, "\texplicit offset: %d\n", mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_OFFSET));
223 if (rva_row <= rva->rows && (mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_FIELD) == i)) {
224 fprintf (output, "\trva: %d\n", mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_RVA));
228 fprintf (output, "\n");
232 dump_table_memberref (MonoImage *m)
234 MonoTableInfo *t = &m->tables [MONO_TABLE_MEMBERREF];
238 const char *blob, *ks = NULL;
240 fprintf (output, "MemberRef Table (1..%d)\n", t->rows);
242 for (i = 0; i < t->rows; i++){
243 guint32 cols [MONO_MEMBERREF_SIZE];
245 mono_metadata_decode_row (t, i, cols, MONO_MEMBERREF_SIZE);
247 kind = cols [MONO_MEMBERREF_CLASS] & 7;
248 idx = cols [MONO_MEMBERREF_CLASS] >> 3;
250 x = g_strdup ("UNHANDLED CASE");
255 xx = get_typedef (m, idx);
256 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
261 xx = get_typeref (m, idx);
262 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
266 ks = "ModuleRef"; break;
269 x = get_methoddef (m, idx);
273 xx = get_typespec (m, idx, FALSE, NULL);
274 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
278 g_error ("Unknown tag: %d\n", kind);
280 blob = mono_metadata_blob_heap (m, cols [MONO_MEMBERREF_SIGNATURE]);
281 mono_metadata_decode_blob_size (blob, &blob);
282 if (*blob == 0x6) { /* it's a field */
283 sig = get_field_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL);
285 sig = get_methodref_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL);
287 fprintf (output, "%d: %s[%d] %s\n\tResolved: %s\n\tSignature: %s\n\t\n",
290 mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]),
301 dump_table_class_layout (MonoImage *m)
303 MonoTableInfo *t = &m->tables [MONO_TABLE_CLASSLAYOUT];
305 fprintf (output, "ClassLayout Table (1..%d)\n", t->rows);
307 for (i = 0; i < t->rows; i++){
308 guint32 cols [MONO_CLASS_LAYOUT_SIZE];
310 mono_metadata_decode_row (t, i, cols, MONO_CLASS_LAYOUT_SIZE);
312 fprintf (output, "%d: PackingSize=%d ClassSize=%d Parent=%s\n",
313 i + 1, cols [MONO_CLASS_LAYOUT_PACKING_SIZE],
314 cols [MONO_CLASS_LAYOUT_CLASS_SIZE],
315 get_typedef (m, cols [MONO_CLASS_LAYOUT_PARENT]));
320 dump_table_constant (MonoImage *m)
322 MonoTableInfo *t = &m->tables [MONO_TABLE_CONSTANT];
324 const char *desc [] = {
330 fprintf (output, "Constant Table (1..%d)\n", t->rows);
332 for (i = 0; i < t->rows; i++){
333 guint32 cols [MONO_CONSTANT_SIZE];
335 mono_metadata_decode_row (t, i, cols, MONO_CONSTANT_SIZE);
336 parent = desc [cols [MONO_CONSTANT_PARENT] & MONO_HASCONSTANT_MASK];
338 fprintf (output, "%d: Parent= %s: %d %s\n",
339 i + 1, parent, cols [MONO_CONSTANT_PARENT] >> MONO_HASCONSTANT_BITS,
340 get_constant (m, (MonoTypeEnum) cols [MONO_CONSTANT_TYPE], cols [MONO_CONSTANT_VALUE]));
346 dump_table_property_map (MonoImage *m)
348 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTYMAP];
352 fprintf (output, "Property Map Table (1..%d)\n", t->rows);
354 for (i = 0; i < t->rows; i++){
355 guint32 cols [MONO_PROPERTY_MAP_SIZE];
357 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_MAP_SIZE);
358 s = get_typedef (m, cols [MONO_PROPERTY_MAP_PARENT]);
359 fprintf (output, "%d: %s (%d) %d\n", i + 1, s, cols [MONO_PROPERTY_MAP_PARENT], cols [MONO_PROPERTY_MAP_PROPERTY_LIST]);
365 dump_table_property (MonoImage *m)
367 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTY];
372 fprintf (output, "Property Table (1..%d)\n", t->rows);
374 for (i = 0; i < t->rows; i++){
375 guint32 cols [MONO_PROPERTY_SIZE];
380 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_SIZE);
382 prop_flags = cols [MONO_PROPERTY_FLAGS];
383 if (prop_flags & 0x0200)
384 strcat (flags, "special ");
385 if (prop_flags & 0x0400)
386 strcat (flags, "runtime ");
387 if (prop_flags & 0x1000)
388 strcat (flags, "hasdefault ");
390 ptr = mono_metadata_blob_heap (m, cols [MONO_PROPERTY_TYPE]);
391 bsize = mono_metadata_decode_blob_size (ptr, &ptr);
392 /* ECMA claims 0x08 ... */
393 if (*ptr != 0x28 && *ptr != 0x08)
394 g_warning("incorrect signature in propert blob: 0x%x", *ptr);
396 pcount = mono_metadata_decode_value (ptr, &ptr);
397 ptr = get_type (m, ptr, &type, FALSE, NULL);
398 fprintf (output, "%d: %s %s (",
399 i + 1, type, mono_metadata_string_heap (m, cols [MONO_PROPERTY_NAME]));
402 for (j = 0; j < pcount; j++){
403 ptr = get_param (m, ptr, &type, NULL);
404 fprintf (output, "%s%s", j > 0? ", " : "",type);
407 fprintf (output, ") %s\n", flags);
412 dump_table_event (MonoImage *m)
414 MonoTableInfo *t = &m->tables [MONO_TABLE_EVENT];
416 fprintf (output, "Event Table (1..%d)\n", t->rows);
418 for (i = 0; i < t->rows; i++){
419 guint32 cols [MONO_EVENT_SIZE];
423 mono_metadata_decode_row (t, i, cols, MONO_EVENT_SIZE);
425 name = mono_metadata_string_heap (m, cols [MONO_EVENT_NAME]);
426 type = get_typedef_or_ref (m, cols [MONO_EVENT_TYPE], NULL);
427 fprintf (output, "%d: %s %s %s\n", i + 1, type, name,
428 cols [MONO_EVENT_FLAGS] & 0x200 ? "specialname " : "");
435 dump_table_file (MonoImage *m)
437 MonoTableInfo *t = &m->tables [MONO_TABLE_FILE];
439 fprintf (output, "File Table (1..%d)\n", t->rows);
441 for (i = 0; i < t->rows; i++){
442 guint32 cols [MONO_FILE_SIZE];
443 const char *name, *hash;
445 mono_metadata_decode_row (t, i, cols, MONO_FILE_SIZE);
447 name = mono_metadata_string_heap (m, cols [MONO_FILE_NAME]);
448 fprintf (output, "%d: %s %s [", i + 1, name,
449 cols [MONO_FILE_FLAGS] & 0x1 ? "nometadata" : "containsmetadata");
450 hash = mono_metadata_blob_heap (m, cols [MONO_FILE_HASH_VALUE]);
451 len = mono_metadata_decode_blob_size (hash, &hash);
452 for (j = 0; j < len; ++j)
453 fprintf (output, "%s%02X", j? " ": "", hash [j] & 0xff);
454 fprintf (output, "]\n");
460 get_manifest_implementation (MonoImage *m, guint32 idx)
463 const char* table = "";
465 return g_strdup ("current module");
466 row = idx >> MONO_IMPLEMENTATION_BITS;
467 switch (idx & MONO_IMPLEMENTATION_MASK) {
468 case MONO_IMPLEMENTATION_FILE:
471 case MONO_IMPLEMENTATION_ASSEMBLYREF:
472 table = "assemblyref";
474 case MONO_IMPLEMENTATION_EXP_TYPE:
475 table = "exportedtype";
478 g_assert_not_reached ();
480 return g_strdup_printf ("%s %d", table, row);
484 get_manifest_flags (guint32 mf)
488 case 1: return "public";
489 case 2: return "private";
496 dump_table_manifest (MonoImage *m)
498 MonoTableInfo *t = &m->tables [MONO_TABLE_MANIFESTRESOURCE];
500 fprintf (output, "Manifestresource Table (1..%d)\n", t->rows);
502 for (i = 0; i < t->rows; i++){
503 guint32 cols [MONO_MANIFEST_SIZE];
504 const char *name, *mf;
507 mono_metadata_decode_row (t, i, cols, MONO_MANIFEST_SIZE);
509 name = mono_metadata_string_heap (m, cols [MONO_MANIFEST_NAME]);
510 mf = get_manifest_flags (cols [MONO_MANIFEST_FLAGS]);
511 impl = get_manifest_implementation (m, cols [MONO_MANIFEST_IMPLEMENTATION]);
512 fprintf (output, "%d: %s '%s' at offset %u in %s\n", i + 1, mf, name, cols [MONO_MANIFEST_OFFSET], impl);
519 dump_table_moduleref (MonoImage *m)
521 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULEREF];
523 fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
525 for (i = 0; i < t->rows; i++){
526 guint32 cols [MONO_MODULEREF_SIZE];
529 mono_metadata_decode_row (t, i, cols, MONO_MODULEREF_SIZE);
531 name = mono_metadata_string_heap (m, cols [MONO_MODULEREF_NAME]);
532 fprintf (output, "%d: %s\n", i + 1, name);
538 dump_table_module (MonoImage *m)
540 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULE];
542 fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
544 for (i = 0; i < t->rows; i++){
545 guint32 cols [MONO_MODULE_SIZE];
549 mono_metadata_decode_row (t, i, cols, MONO_MODULE_SIZE);
551 name = mono_metadata_string_heap (m, cols [MONO_MODULE_NAME]);
552 guid = get_guid (m, cols [MONO_MODULE_MVID]);
553 fprintf (output, "%d: %s %d %s\n", i + 1, name, cols [MONO_MODULE_MVID], guid);
558 dump_table_method (MonoImage *m)
560 MonoTableInfo *t = &m->tables [MONO_TABLE_METHOD];
561 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
563 guint32 first_m, last_m;
564 /* Generic container for Type & method */
565 MonoGenericContainer *type_container = NULL, *method_container = NULL;
567 fprintf (output, "Method Table (1..%d)\n", t->rows);
570 last_m = first_m = 1;
571 for (i = 1; i <= t->rows; i++){
572 guint32 cols [MONO_METHOD_SIZE];
575 MonoMethodSignature *method;
578 * Find the next type.
580 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_METHOD_LIST))) {
584 fprintf (output, "########## %s.%s\n",
585 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
586 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
588 type_container = mono_metadata_load_generic_params (m, MONO_TOKEN_TYPE_DEF | (current_type - 1), NULL);
590 mono_metadata_load_generic_param_constraints (m, MONO_TOKEN_TYPE_DEF | (current_type - 1), type_container);
593 method_container = mono_metadata_load_generic_params (m, MONO_TOKEN_METHOD_DEF | i, type_container);
594 if (method_container)
595 mono_metadata_load_generic_param_constraints (m, MONO_TOKEN_METHOD_DEF | i, method_container);
596 mono_metadata_decode_table_row (m, MONO_TABLE_METHOD, i - 1, cols, MONO_METHOD_SIZE);
597 sigblob = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
598 mono_metadata_decode_blob_size (sigblob, &sigblob);
599 method = mono_metadata_parse_method_signature_full (m, method_container ? method_container : type_container, i, sigblob, &sigblob);
600 sig = dis_stringify_method_signature (m, method, i, method_container ? method_container : type_container, FALSE);
601 fprintf (output, "%d: %s (param: %d)\n", i, sig, cols [MONO_METHOD_PARAMLIST]);
603 mono_metadata_free_method_signature (method);
609 dump_table_implmap (MonoImage *m)
611 MonoTableInfo *t = &m->tables [MONO_TABLE_IMPLMAP];
612 MonoTableInfo *td = &m->tables [MONO_TABLE_MODULEREF];
615 fprintf (output, "ImplMap Table (1..%d)\n", t->rows);
617 for (i = 1; i <= t->rows; i++){
618 guint32 cols [MONO_IMPLMAP_SIZE];
621 mono_metadata_decode_row (t, i - 1, cols, MONO_IMPLMAP_SIZE);
623 method = get_method (m, MONO_TOKEN_METHOD_DEF | (cols [MONO_IMPLMAP_MEMBER] >> MONO_MEMBERFORWD_BITS), NULL);
625 fprintf (output, "%d: %s %d (%s %s)\n", i,
627 cols [MONO_IMPLMAP_FLAGS],
628 mono_metadata_string_heap (m, cols [MONO_IMPLMAP_NAME]),
629 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, cols [MONO_IMPLMAP_SCOPE] - 1, MONO_MODULEREF_NAME)));
634 dump_table_methodimpl (MonoImage *m)
636 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODIMPL];
637 /*MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];*/
640 fprintf (output, "MethodImpl Table (1..%d)\n", t->rows);
642 for (i = 1; i <= t->rows; i++){
643 guint32 cols [MONO_METHODIMPL_SIZE];
644 char *class, *impl, *decl;
646 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODIMPL_SIZE);
647 class = get_typedef (m, cols [MONO_METHODIMPL_CLASS]);
648 impl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_BODY]), NULL);
649 decl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_DECLARATION]), NULL);
650 fprintf (output, "%d: %s\n\tdecl: %s\n\timpl: %s\n", i, class, decl, impl);
658 static dis_map_t semantics_map [] = {
669 dump_table_methodsem (MonoImage *m)
671 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSEMANTICS];
672 int i, is_property, index;
673 const char *semantics;
675 fprintf (output, "Method Semantics Table (1..%d)\n", t->rows);
676 for (i = 1; i <= t->rows; i++){
677 guint32 cols [MONO_METHOD_SEMA_SIZE];
679 mono_metadata_decode_row (t, i - 1, cols, MONO_METHOD_SEMA_SIZE);
680 semantics = flags (cols [MONO_METHOD_SEMA_SEMANTICS], semantics_map);
681 is_property = cols [MONO_METHOD_SEMA_ASSOCIATION] & MONO_HAS_SEMANTICS_MASK;
682 index = cols [MONO_METHOD_SEMA_ASSOCIATION] >> MONO_HAS_SEMANTICS_BITS;
683 fprintf (output, "%d: [%d] %s method: %d %s %d\n", i, cols [MONO_METHOD_SEMA_ASSOCIATION], semantics,
684 cols [MONO_METHOD_SEMA_METHOD] - 1,
685 is_property? "property" : "event",
691 dump_table_interfaceimpl (MonoImage *m)
693 MonoTableInfo *t = &m->tables [MONO_TABLE_INTERFACEIMPL];
696 fprintf (output, "Interface Implementation Table (1..%d)\n", t->rows);
697 for (i = 1; i <= t->rows; i++) {
698 guint32 cols [MONO_INTERFACEIMPL_SIZE];
700 mono_metadata_decode_row (t, i - 1, cols, MONO_INTERFACEIMPL_SIZE);
701 fprintf (output, "%d: %s implements %s\n", i,
702 get_typedef (m, cols [MONO_INTERFACEIMPL_CLASS]),
703 get_typedef_or_ref (m, cols [MONO_INTERFACEIMPL_INTERFACE], NULL));
708 has_cattr_get_table (MonoImage *m, guint32 val)
710 guint32 t = val & MONO_CUSTOM_ATTR_MASK;
711 guint32 index = val >> MONO_CUSTOM_ATTR_BITS;
715 case MONO_CUSTOM_ATTR_METHODDEF:
718 case MONO_CUSTOM_ATTR_FIELDDEF:
721 case MONO_CUSTOM_ATTR_TYPEREF:
724 case MONO_CUSTOM_ATTR_TYPEDEF:
727 case MONO_CUSTOM_ATTR_PARAMDEF:
730 case MONO_CUSTOM_ATTR_INTERFACE:
731 table = "InterfaceImpl";
733 case MONO_CUSTOM_ATTR_MEMBERREF:
736 case MONO_CUSTOM_ATTR_MODULE:
739 case MONO_CUSTOM_ATTR_PERMISSION:
740 table = "DeclSecurity?";
742 case MONO_CUSTOM_ATTR_PROPERTY:
745 case MONO_CUSTOM_ATTR_EVENT:
748 case MONO_CUSTOM_ATTR_SIGNATURE:
749 table = "StandAloneSignature";
751 case MONO_CUSTOM_ATTR_MODULEREF:
754 case MONO_CUSTOM_ATTR_TYPESPEC:
757 case MONO_CUSTOM_ATTR_ASSEMBLY:
760 case MONO_CUSTOM_ATTR_ASSEMBLYREF:
761 table = "AssemblyRef";
763 case MONO_CUSTOM_ATTR_FILE:
766 case MONO_CUSTOM_ATTR_EXP_TYPE:
767 table = "ExportedType";
769 case MONO_CUSTOM_ATTR_MANIFEST:
772 case MONO_CUSTOM_ATTR_GENERICPAR:
773 table = "GenericParam";
780 * FIXME: we should decode the index into something more uman-friendly.
782 return g_strdup_printf ("%s: %d", table, index);
786 custom_attr_params (MonoImage *m, MonoMethodSignature* sig, const char* value)
788 int len, i, slen, type;
791 const char *p = value;
793 len = mono_metadata_decode_value (p, &p);
794 if (len < 2 || read16 (p) != 0x0001) /* Prolog */
795 return g_strdup ("");
799 res = g_string_new ("");
800 for (i = 0; i < sig->param_count; ++i) {
802 g_string_append (res, ", ");
803 type = sig->params [i]->type;
807 g_string_sprintfa (res, "%d", (unsigned int)*p);
811 g_string_sprintfa (res, "%d", *p);
814 case MONO_TYPE_BOOLEAN:
815 g_string_sprintfa (res, "%s", *p?"true":"false");
819 g_string_sprintfa (res, "'%c'", read16 (p));
823 g_string_sprintfa (res, "%d", read16 (p));
827 g_string_sprintfa (res, "%d", (gint16)read16 (p));
831 g_string_sprintfa (res, "%d", read32 (p));
835 g_string_sprintfa (res, "%d", (gint32)read32 (p));
839 g_string_sprintfa (res, "%lld", (long long)read64 (p));
843 g_string_sprintfa (res, "%lld", (long long)read64 (p));
852 g_string_sprintfa (res, "(00 00 80 ff)"); /* negative infinity */
854 g_string_sprintfa (res, "(00 00 80 7f)"); /* positive infinity */
855 else if (isnan (val))
856 g_string_sprintfa (res, "(00 00 c0 ff)"); /* NaN */
858 g_string_sprintfa (res, "%g", val);
869 g_string_sprintfa (res, "(00 00 00 00 00 00 f0 ff)"); /* negative infinity */
871 g_string_sprintfa (res, "(00 00 00 00 00 00 f0 7f)"); /* positive infinity */
872 else if (isnan (val))
873 g_string_sprintfa (res, "(00 00 00 00 00 00 f8 ff)"); /* NaN */
875 g_string_sprintfa (res, "%g", val);
879 case MONO_TYPE_VALUETYPE:
880 if (mono_class_is_enum (sig->params [i]->data.klass)) {
881 type = mono_class_enum_basetype (sig->params [i]->data.klass)->type;
884 g_warning ("generic valutype not handled in custom attr value decoding");
887 case MONO_TYPE_CLASS: /* It must be a Type: check? */
888 case MONO_TYPE_STRING:
889 if (*p == (char)0xff) {
890 g_string_append (res, "null");
894 slen = mono_metadata_decode_value (p, &p);
895 g_string_append_c (res, '"');
896 g_string_append (res, p);
897 g_string_append_c (res, '"');
901 g_warning ("Type %02x not handled in custom attr value decoding", sig->params [i]->type);
907 g_string_sprintfa (res, " %d named args: (", slen);
908 slen = len - (p - value) + 1;
909 for (i = 0; i < slen; ++i) {
910 g_string_sprintfa (res, " %02X", (p [i] & 0xff));
912 g_string_append_c (res, ')');
915 g_string_free (res, FALSE);
920 dump_table_customattr (MonoImage *m)
922 MonoTableInfo *t = &m->tables [MONO_TABLE_CUSTOMATTRIBUTE];
925 fprintf (output, "Custom Attributes Table (1..%d)\n", t->rows);
926 for (i = 1; i <= t->rows; i++) {
927 guint32 cols [MONO_CUSTOM_ATTR_SIZE];
934 mono_metadata_decode_row (t, i - 1, cols, MONO_CUSTOM_ATTR_SIZE);
935 desc = has_cattr_get_table (m, cols [MONO_CUSTOM_ATTR_PARENT]);
936 mtoken = cols [MONO_CUSTOM_ATTR_TYPE] >> MONO_CUSTOM_ATTR_TYPE_BITS;
937 switch (cols [MONO_CUSTOM_ATTR_TYPE] & MONO_CUSTOM_ATTR_TYPE_MASK) {
938 case MONO_CUSTOM_ATTR_TYPE_METHODDEF:
939 mtoken |= MONO_TOKEN_METHOD_DEF;
941 case MONO_CUSTOM_ATTR_TYPE_MEMBERREF:
942 mtoken |= MONO_TOKEN_MEMBER_REF;
945 g_warning ("Unknown table for custom attr type %08x", cols [MONO_CUSTOM_ATTR_TYPE]);
948 method = get_method (m, mtoken, NULL);
949 meth = mono_get_method (m, mtoken, NULL);
950 params = custom_attr_params (m, mono_method_signature (meth), mono_metadata_blob_heap (m, cols [MONO_CUSTOM_ATTR_VALUE]));
951 fprintf (output, "%d: %s: %s [%s]\n", i, desc, method, params);
959 dump_table_nestedclass (MonoImage *m)
961 MonoTableInfo *t = &m->tables [MONO_TABLE_NESTEDCLASS];
962 guint32 cols [MONO_NESTED_CLASS_SIZE];
964 char *nested, *nesting;
965 fprintf (output, "NestedClass Table (1..%d)\n", t->rows);
967 for (i = 1; i <= t->rows; i++){
968 mono_metadata_decode_row (t, i - 1, cols, MONO_NESTED_CLASS_SIZE);
969 nested = get_typedef (m, cols [MONO_NESTED_CLASS_NESTED]);
970 nesting = get_typedef (m, cols [MONO_NESTED_CLASS_ENCLOSING]);
971 fprintf (output, "%d: %d %d: %s in %s\n", i,
972 cols [MONO_NESTED_CLASS_NESTED],
973 cols [MONO_NESTED_CLASS_ENCLOSING], nested, nesting);
981 dump_table_exported (MonoImage *m)
983 MonoTableInfo *t = &m->tables [MONO_TABLE_EXPORTEDTYPE];
984 guint32 cols [MONO_EXP_TYPE_SIZE];
986 const char *name, *nspace;
989 fprintf (output, "ExportedType Table (1..%d)\n", t->rows);
991 for (i = 1; i <= t->rows; i++) {
992 mono_metadata_decode_row (t, i - 1, cols, MONO_EXP_TYPE_SIZE);
993 name = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAME]);
994 nspace = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAMESPACE]);
995 impl = get_manifest_implementation (m, cols [MONO_EXP_TYPE_IMPLEMENTATION]);
996 index = cols [MONO_EXP_TYPE_TYPEDEF];
997 fprintf (output, "%d: %s%s%s is in %s, token %x\n", i, nspace, *nspace ? "." : "", name, impl, index);
1004 dump_blob (MonoImage *m, const char* blob)
1008 bsize = mono_metadata_decode_blob_size (blob, &blob);
1010 for (j = 0; j < bsize; j++) {
1011 fprintf (output, "%02x ", blob [j] & 0xff);
1016 dump_table_field_marshal (MonoImage *m)
1018 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELDMARSHAL];
1019 guint32 cols [MONO_FIELD_MARSHAL_SIZE];
1020 int i, is_field, idx;
1024 fprintf (output, "FieldMarshal Table (1..%d)\n", t->rows);
1026 for (i = 1; i <= t->rows; i++) {
1027 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_MARSHAL_SIZE);
1028 blob = mono_metadata_blob_heap (m, cols [MONO_FIELD_MARSHAL_NATIVE_TYPE]);
1029 native = get_marshal_info (m, blob);
1030 is_field = (cols [MONO_FIELD_MARSHAL_PARENT] & MONO_HAS_FIELD_MARSHAL_MASK) == MONO_HAS_FIELD_MARSHAL_FIELDSREF;
1031 idx = cols [MONO_FIELD_MARSHAL_PARENT] >> MONO_HAS_FIELD_MARSHAL_BITS;
1032 fprintf (output, "%d: (0x%04x) %s %d: %s\n", i, cols [MONO_FIELD_MARSHAL_PARENT], is_field? "Field" : "Param", idx, native);
1033 fprintf (output, "\tblob encoding: ");
1034 dump_blob (m, blob);
1035 fprintf (output, "\n");
1042 get_security_action (int val) {
1043 static char buf [32];
1046 case SECURITY_ACTION_DEMAND:
1048 case SECURITY_ACTION_ASSERT:
1050 case SECURITY_ACTION_DENY:
1052 case SECURITY_ACTION_PERMITONLY:
1053 return "PermitOnly";
1054 case SECURITY_ACTION_LINKDEMAND:
1055 return "LinkDemand";
1056 case SECURITY_ACTION_INHERITDEMAND:
1057 return "InheritanceDemand";
1058 case SECURITY_ACTION_REQMIN:
1059 return "RequestMinimum";
1060 case SECURITY_ACTION_REQOPT:
1061 return "RequestOptional";
1062 case SECURITY_ACTION_REQREFUSE:
1063 return "RequestRefuse";
1064 /* Special actions (for non CAS permissions) */
1065 case SECURITY_ACTION_NONCASDEMAND:
1066 return "NonCasDemand";
1067 case SECURITY_ACTION_NONCASLINKDEMAND:
1068 return "NonCasLinkDemand";
1069 case SECURITY_ACTION_NONCASINHERITANCE:
1070 return "NonCasInheritance";
1071 /* Fx 2.0 actions (for both CAS and non-CAS permissions) */
1072 case SECURITY_ACTION_LINKDEMANDCHOICE:
1073 return "LinkDemandChoice";
1074 case SECURITY_ACTION_INHERITDEMANDCHOICE:
1075 return "InheritanceDemandChoice";
1076 case SECURITY_ACTION_DEMANDCHOICE:
1077 return "DemandChoice";
1079 g_snprintf (buf, sizeof (buf), "0x%04X", val);
1085 dump_table_declsec (MonoImage *m)
1087 MonoTableInfo *t = &m->tables [MONO_TABLE_DECLSECURITY];
1088 guint32 cols [MONO_DECL_SECURITY_SIZE];
1091 const char *blob, *action;
1092 const char* parent[] = {
1093 "TypeDef", "MethodDef", "Assembly", ""
1096 fprintf (output, "DeclSecurity Table (1..%d)\n", t->rows);
1098 for (i = 1; i <= t->rows; i++) {
1099 mono_metadata_decode_row (t, i - 1, cols, MONO_DECL_SECURITY_SIZE);
1100 blob = mono_metadata_blob_heap (m, cols [MONO_DECL_SECURITY_PERMISSIONSET]);
1101 len = mono_metadata_decode_blob_size (blob, &blob);
1102 action = get_security_action (cols [MONO_DECL_SECURITY_ACTION]);
1103 idx = cols [MONO_DECL_SECURITY_PARENT];
1104 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");
1107 if (blob [0] == MONO_DECLSEC_FORMAT_20) {
1108 /* 2.0 declarative security format */
1109 char *declsec = dump_declsec_entry20 (m, blob, "\t");
1110 fprintf (output, "%s", declsec);
1113 /* 1.0 declarative security format - Unicode XML */
1114 for (idx = 0; idx < len; ++idx)
1115 fprintf (output, "%c", blob [idx]);
1117 fprintf (output, "\n");
1122 dump_table_genericpar (MonoImage *m)
1124 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAM];
1125 guint32 cols [MONO_GENERICPARAM_SIZE];
1128 fprintf (output, "GenericParameters (1..%d)\n", t->rows);
1130 for (i = 1; i <= t->rows; i++) {
1132 mono_metadata_decode_row (t, i - 1, cols, MONO_GENERICPARAM_SIZE);
1134 // sig = get_type_or_methdef (m, cols [MONO_GENERICPARAM_OWNER]);
1135 sig = g_strdup_printf ("%x", cols [MONO_GENERICPARAM_OWNER]);
1136 fprintf (output, "%d: %d, flags=%d, owner=%s %s\n", i,
1137 cols [MONO_GENERICPARAM_NUMBER],
1138 cols [MONO_GENERICPARAM_FLAGS], sig,
1139 mono_metadata_string_heap (m, cols [MONO_GENERICPARAM_NAME]));
1145 dump_table_methodspec (MonoImage *m)
1147 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSPEC];
1148 guint32 cols [MONO_METHODSPEC_SIZE];
1151 fprintf (output, "MethodSpec (1..%d)\n", t->rows);
1153 for (i = 1; i <= t->rows; i++) {
1158 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODSPEC_SIZE);
1160 /* build a methodspec token to get the method */
1161 token = MONO_TOKEN_METHOD_SPEC | i;
1162 method = get_method (m, token, NULL);
1164 sig = get_method_type_param (m, cols [MONO_METHODSPEC_SIGNATURE], NULL);
1165 fprintf (output, "%d: %s, %s\n", i, method, sig);
1172 dump_table_parconstraint (MonoImage *m)
1174 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAMCONSTRAINT];
1175 guint32 cols [MONO_GENPARCONSTRAINT_SIZE];
1178 fprintf (output, "Generic Param Constraint (1..%d)\n", t->rows);
1180 for (i = 1; i <= t->rows; i++) {
1182 mono_metadata_decode_row (t, i - 1, cols, MONO_GENPARCONSTRAINT_SIZE);
1184 // sig = get_typedef_or_ref (m, cols [MONO_GENPARCONSTRAINT_CONSTRAINT], NULL);
1185 sig = g_strdup_printf ("%x", cols [MONO_GENPARCONSTRAINT_CONSTRAINT]);
1186 fprintf (output, "%d: gen-par=%d, Constraint=%s\n", i,
1187 cols [MONO_GENPARCONSTRAINT_GENERICPAR], sig);
1193 dump_stream_blob (MonoImage *m)
1197 fprintf (output, "Blob heap contents\n");
1199 for (i = 0; i < m->heap_blob.size; i++) {
1202 fprintf (output, "\n");
1203 else if ((i % 8) == 0)
1204 fprintf (output, "- ");
1206 fprintf (output, "%02x ", m->heap_blob.data [i] & 0xff);
1209 fprintf (output, "\n");
1213 dump_table_standalonesig (MonoImage *m)
1215 MonoTableInfo *t = &m->tables [MONO_TABLE_STANDALONESIG];
1216 guint32 cols [MONO_STAND_ALONE_SIGNATURE_SIZE];
1219 fprintf (output, "Stand alone signature (1..%d)\n", t->rows);
1221 for (i = 1; i <= t->rows; i++) {
1222 const char *locals_ptr;
1225 mono_metadata_decode_row (t, i - 1, cols, MONO_STAND_ALONE_SIGNATURE_SIZE);
1227 locals_ptr = mono_metadata_blob_heap (m, cols [MONO_STAND_ALONE_SIGNATURE]);
1228 bsize = mono_metadata_decode_blob_size (locals_ptr, &locals_ptr);
1230 fprintf (output, "%d: blob[0x%x] = ", i, cols [MONO_STAND_ALONE_SIGNATURE]);
1232 for (j = 0; j < bsize; j++) {
1233 fprintf (output, "%02x ", locals_ptr [j] & 0xff);
1235 fprintf (output, "\n");
1240 dump_table_ptr (MonoImage *m, int table, const char *name)
1242 MonoTableInfo *t = &m->tables [table];
1246 fprintf (output, "%s (1..%d)\n", name, t->rows);
1248 for (i = 1; i <= t->rows; i++) {
1249 mono_metadata_decode_row (t, i - 1, cols, 1);
1251 fprintf (output, "%d: %d\n", i, cols [0]);
1256 dump_table_methodptr (MonoImage *m)
1258 dump_table_ptr (m, MONO_TABLE_METHOD_POINTER, "Method Ptr");
1262 dump_table_fieldptr (MonoImage *m)
1264 dump_table_ptr (m, MONO_TABLE_FIELD_POINTER, "Field Ptr");
1268 dump_table_paramptr (MonoImage *m)
1270 dump_table_ptr (m, MONO_TABLE_PARAM_POINTER, "Param Ptr");
1274 dump_table_eventptr (MonoImage *m)
1276 dump_table_ptr (m, MONO_TABLE_EVENT_POINTER, "Event Ptr");
1280 dump_table_propertyptr (MonoImage *m)
1282 dump_table_ptr (m, MONO_TABLE_PROPERTY_POINTER, "Property Ptr");