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 mono_metadata_decode_row (t, 0, cols, MONO_ASSEMBLY_SIZE);
29 fprintf (output, "Assembly Table\n");
31 fprintf (output, "Name: %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_NAME]));
32 fprintf (output, "Hash Algoritm: 0x%08x\n", cols [MONO_ASSEMBLY_HASH_ALG]);
33 fprintf (output, "Version: %d.%d.%d.%d\n", cols [MONO_ASSEMBLY_MAJOR_VERSION],
34 cols [MONO_ASSEMBLY_MINOR_VERSION],
35 cols [MONO_ASSEMBLY_BUILD_NUMBER],
36 cols [MONO_ASSEMBLY_REV_NUMBER]);
37 fprintf (output, "Flags: 0x%08x\n", cols [MONO_ASSEMBLY_FLAGS]);
38 fprintf (output, "PublicKey: BlobPtr (0x%08x)\n", cols [MONO_ASSEMBLY_PUBLIC_KEY]);
40 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLY_PUBLIC_KEY]);
41 len = mono_metadata_decode_value (ptr, &ptr);
43 fprintf (output, "\tDump:");
44 hex_dump (ptr, 0, len);
45 fprintf (output, "\n");
47 fprintf (output, "\tZero sized public key\n");
49 fprintf (output, "Culture: %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_CULTURE]));
50 fprintf (output, "\n");
54 dump_table_typeref (MonoImage *m)
56 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEREF];
59 fprintf (output, "Typeref Table\n");
61 for (i = 1; i <= t->rows; i++){
62 char *s = get_typeref (m, i);
64 fprintf (output, "%d: %s\n", i, s);
67 fprintf (output, "\n");
71 dump_table_typedef (MonoImage *m)
73 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEDEF];
76 fprintf (output, "Typedef Table\n");
78 for (i = 1; i <= t->rows; i++){
79 char *s = get_typedef (m, i);
80 guint32 cols [MONO_TYPEDEF_SIZE];
82 mono_metadata_decode_row (&m->tables [MONO_TABLE_TYPEDEF], i - 1, cols, MONO_TYPEDEF_SIZE);
84 fprintf (output, "%d: %s (flist=%d, mlist=%d, flags=0x%x, extends=0x%x)\n", i, s,
85 cols [MONO_TYPEDEF_FIELD_LIST], cols [MONO_TYPEDEF_METHOD_LIST],
86 cols [MONO_TYPEDEF_FLAGS], cols [MONO_TYPEDEF_EXTENDS]);
89 fprintf (output, "\n");
93 dump_table_assemblyref (MonoImage *m)
95 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLYREF];
98 fprintf (output, "AssemblyRef Table\n");
100 for (i = 0; i < t->rows; i++){
103 guint32 cols [MONO_ASSEMBLYREF_SIZE];
105 mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
106 fprintf (output, "%d: Version=%d.%d.%d.%d\n\tName=%s\n", i + 1,
107 cols [MONO_ASSEMBLYREF_MAJOR_VERSION],
108 cols [MONO_ASSEMBLYREF_MINOR_VERSION],
109 cols [MONO_ASSEMBLYREF_BUILD_NUMBER],
110 cols [MONO_ASSEMBLYREF_REV_NUMBER],
111 mono_metadata_string_heap (m, cols [MONO_ASSEMBLYREF_NAME]));
112 ptr = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLYREF_PUBLIC_KEY]);
113 len = mono_metadata_decode_value (ptr, &ptr);
115 fprintf (output, "\tPublic Key:");
116 hex_dump (ptr, 0, len);
117 fprintf (output, "\n");
119 fprintf (output, "\tZero sized public key\n");
122 fprintf (output, "\n");
126 dump_table_param (MonoImage *m)
128 MonoTableInfo *t = &m->tables [MONO_TABLE_PARAM];
131 fprintf (output, "Param Table\n");
133 for (i = 0; i < t->rows; i++){
134 guint32 cols [MONO_PARAM_SIZE];
136 mono_metadata_decode_row (t, i, cols, CSIZE (cols));
137 fprintf (output, "%d: 0x%04x %d %s\n",
139 cols [MONO_PARAM_FLAGS], cols [MONO_PARAM_SEQUENCE],
140 mono_metadata_string_heap (m, cols [MONO_PARAM_NAME]));
142 fprintf (output, "\n");
146 dump_table_field (MonoImage *m)
148 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELD];
149 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
150 MonoTableInfo *fl = &m->tables [MONO_TABLE_FIELDLAYOUT];
151 MonoTableInfo *rva = &m->tables [MONO_TABLE_FIELDRVA];
152 int i, current_type, offset_row, rva_row;
153 guint32 first_m, last_m;
155 fprintf (output, "Field Table (1..%d)\n", t->rows);
157 rva_row = offset_row = current_type = 1;
158 last_m = first_m = 1;
159 for (i = 1; i <= t->rows; i++){
160 guint32 cols [MONO_FIELD_SIZE];
164 * Find the next type.
166 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_FIELD_LIST))) {
170 fprintf (output, "########## %s.%s\n",
171 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
172 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
175 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_SIZE);
176 sig = get_field_signature (m, cols [MONO_FIELD_SIGNATURE]);
177 flags = field_flags (cols [MONO_FIELD_FLAGS]);
178 fprintf (output, "%d: %s %s: %s\n",
181 mono_metadata_string_heap (m, cols [MONO_FIELD_NAME]),
185 if (offset_row <= fl->rows && (mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_FIELD) == i)) {
186 fprintf (output, "\texplicit offset: %d\n", mono_metadata_decode_row_col (fl, offset_row - 1, MONO_FIELD_LAYOUT_OFFSET));
189 if (rva_row <= rva->rows && (mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_FIELD) == i)) {
190 fprintf (output, "\trva: %d\n", mono_metadata_decode_row_col (rva, rva_row - 1, MONO_FIELD_RVA_RVA));
194 fprintf (output, "\n");
198 dump_table_memberref (MonoImage *m)
200 MonoTableInfo *t = &m->tables [MONO_TABLE_MEMBERREF];
204 const char *blob, *ks;
206 fprintf (output, "MemberRef Table (1..%d)\n", t->rows);
208 for (i = 0; i < t->rows; i++){
209 guint32 cols [MONO_MEMBERREF_SIZE];
211 mono_metadata_decode_row (t, i, cols, MONO_MEMBERREF_SIZE);
213 kind = cols [MONO_MEMBERREF_CLASS] & 7;
214 idx = cols [MONO_MEMBERREF_CLASS] >> 3;
216 x = g_strdup ("UNHANDLED CASE");
220 ks = "TypeDef"; break;
223 xx = get_typeref (m, idx);
224 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
228 ks = "ModuleRef"; break;
230 ks = "MethodDef"; break;
233 xx = get_typespec (m, idx);
234 x = g_strconcat (xx, ".", mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]), NULL);
238 g_error ("Unknown tag: %d\n", kind);
240 blob = mono_metadata_blob_heap (m, cols [MONO_MEMBERREF_SIGNATURE]);
241 mono_metadata_decode_blob_size (blob, &blob);
242 if (*blob == 0x6) { /* it's a field */
243 sig = get_field_signature (m, cols [MONO_MEMBERREF_SIGNATURE]);
245 sig = get_methodref_signature (m, cols [MONO_MEMBERREF_SIGNATURE], NULL);
247 fprintf (output, "%d: %s[%d] %s\n\tResolved: %s\n\tSignature: %s\n\t\n",
250 mono_metadata_string_heap (m, cols [MONO_MEMBERREF_NAME]),
261 dump_table_class_layout (MonoImage *m)
263 MonoTableInfo *t = &m->tables [MONO_TABLE_CLASSLAYOUT];
265 fprintf (output, "ClassLayout Table (1..%d)\n", t->rows);
267 for (i = 0; i < t->rows; i++){
268 guint32 cols [MONO_CLASS_LAYOUT_SIZE];
270 mono_metadata_decode_row (t, i, cols, CSIZE (cols));
272 fprintf (output, "%d: PackingSize=%d ClassSize=%d Parent=%s\n",
273 i + 1, cols [MONO_CLASS_LAYOUT_PACKING_SIZE],
274 cols [MONO_CLASS_LAYOUT_CLASS_SIZE],
275 get_typedef (m, cols [MONO_CLASS_LAYOUT_PARENT]));
280 dump_table_constant (MonoImage *m)
282 MonoTableInfo *t = &m->tables [MONO_TABLE_CONSTANT];
284 const char *desc [] = {
290 fprintf (output, "Constant Table (1..%d)\n", t->rows);
292 for (i = 0; i < t->rows; i++){
293 guint32 cols [MONO_CONSTANT_SIZE];
294 const char *parent = desc [cols [MONO_CONSTANT_PARENT] & HASCONSTANT_MASK];
296 mono_metadata_decode_row (t, i, cols, MONO_CONSTANT_SIZE);
298 fprintf (output, "%d: Parent= %s: %d %s\n",
299 i + 1, parent, cols [MONO_CONSTANT_PARENT] >> HASCONSTANT_BITS,
300 get_constant (m, (MonoTypeEnum) cols [MONO_CONSTANT_TYPE], cols [MONO_CONSTANT_VALUE]));
306 dump_table_property_map (MonoImage *m)
308 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTYMAP];
312 fprintf (output, "Property Map Table (1..%d)\n", t->rows);
314 for (i = 0; i < t->rows; i++){
315 guint32 cols [MONO_PROPERTY_MAP_SIZE];
317 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_MAP_SIZE);
318 s = get_typedef (m, cols [MONO_PROPERTY_MAP_PARENT]);
319 fprintf (output, "%d: %s %d\n", i + 1, s, cols [MONO_PROPERTY_MAP_PROPERTY_LIST]);
325 dump_table_property (MonoImage *m)
327 MonoTableInfo *t = &m->tables [MONO_TABLE_PROPERTY];
332 fprintf (output, "Property Table (1..%d)\n", t->rows);
334 for (i = 0; i < t->rows; i++){
335 guint32 cols [MONO_PROPERTY_SIZE];
340 mono_metadata_decode_row (t, i, cols, MONO_PROPERTY_SIZE);
342 prop_flags = cols [MONO_PROPERTY_FLAGS];
343 if (prop_flags & 0x0200)
344 strcat (flags, "special ");
345 if (prop_flags & 0x0400)
346 strcat (flags, "runtime ");
347 if (prop_flags & 0x1000)
348 strcat (flags, "hasdefault ");
350 ptr = mono_metadata_blob_heap (m, cols [MONO_PROPERTY_TYPE]);
351 bsize = mono_metadata_decode_blob_size (ptr, &ptr);
352 /* ECMA claims 0x08 ... */
353 if (*ptr != 0x28 && *ptr != 0x08)
354 g_warning("incorrect signature in propert blob: 0x%x", *ptr);
356 pcount = mono_metadata_decode_value (ptr, &ptr);
357 ptr = get_type (m, ptr, &type);
358 fprintf (output, "%d: %s %s (",
359 i + 1, type, mono_metadata_string_heap (m, cols [MONO_PROPERTY_NAME]));
362 for (j = 0; j < pcount; j++){
363 ptr = get_param (m, ptr, &type);
364 fprintf (output, "%s%s", j > 0? ", " : "",type);
367 fprintf (output, ") %s\n", flags);
372 dump_table_event (MonoImage *m)
374 MonoTableInfo *t = &m->tables [MONO_TABLE_EVENT];
376 fprintf (output, "Event Table (1..%d)\n", t->rows);
378 for (i = 0; i < t->rows; i++){
379 guint32 cols [MONO_EVENT_SIZE];
383 mono_metadata_decode_row (t, i, cols, MONO_EVENT_SIZE);
385 name = mono_metadata_string_heap (m, cols [MONO_EVENT_NAME]);
386 type = get_typedef_or_ref (m, cols [MONO_EVENT_TYPE]);
387 fprintf (output, "%d: %s %s %s\n", i + 1, type, name,
388 cols [MONO_EVENT_FLAGS] & 0x200 ? "specialname " : "");
395 dump_table_file (MonoImage *m)
397 MonoTableInfo *t = &m->tables [MONO_TABLE_FILE];
399 fprintf (output, "File Table (1..%d)\n", t->rows);
401 for (i = 0; i < t->rows; i++){
402 guint32 cols [MONO_FILE_SIZE];
403 const char *name, *hash;
405 mono_metadata_decode_row (t, i, cols, MONO_FILE_SIZE);
407 name = mono_metadata_string_heap (m, cols [MONO_FILE_NAME]);
408 fprintf (output, "%d: %s %s [", i + 1, name,
409 cols [MONO_FILE_FLAGS] & 0x1 ? "nometadata" : "containsmetadata");
410 hash = mono_metadata_blob_heap (m, cols [MONO_FILE_HASH_VALUE]);
411 len = mono_metadata_decode_blob_size (hash, &hash);
412 for (j = 0; j < len; ++j)
413 fprintf (output, "%s%02X", j? " ": "", hash [j] & 0xff);
414 fprintf (output, "]\n");
420 get_manifest_implementation (MonoImage *m, guint32 idx)
423 const char* table = "";
425 return g_strdup ("current module");
426 row = idx >> IMPLEMENTATION_BITS;
427 switch (idx & IMPLEMENTATION_MASK) {
428 case IMPLEMENTATION_FILE:
431 case IMPLEMENTATION_ASSEMBLYREF:
432 table = "assemblyref";
434 case IMPLEMENTATION_EXP_TYPE:
436 g_assert_not_reached ();
438 return g_strdup_printf ("%s %d", table, row);
442 get_manifest_flags (guint32 mf)
446 case 1: return "public";
447 case 2: return "private";
454 dump_table_manifest (MonoImage *m)
456 MonoTableInfo *t = &m->tables [MONO_TABLE_MANIFESTRESOURCE];
458 fprintf (output, "Manifestresource Table (1..%d)\n", t->rows);
460 for (i = 0; i < t->rows; i++){
461 guint32 cols [MONO_MANIFEST_SIZE];
462 const char *name, *mf;
465 mono_metadata_decode_row (t, i, cols, MONO_MANIFEST_SIZE);
467 name = mono_metadata_string_heap (m, cols [MONO_MANIFEST_NAME]);
468 mf = get_manifest_flags (cols [MONO_MANIFEST_FLAGS]);
469 impl = get_manifest_implementation (m, cols [MONO_MANIFEST_IMPLEMENTATION]);
470 fprintf (output, "%d: %s '%s' at offset %u in %s\n", i + 1, mf, name, cols [MONO_MANIFEST_OFFSET], impl);
477 dump_table_moduleref (MonoImage *m)
479 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULEREF];
481 fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
483 for (i = 0; i < t->rows; i++){
484 guint32 cols [MONO_MODULEREF_SIZE];
487 mono_metadata_decode_row (t, i, cols, MONO_MODULEREF_SIZE);
489 name = mono_metadata_string_heap (m, cols [MONO_MODULEREF_NAME]);
490 fprintf (output, "%d: %s\n", i + 1, name);
496 dump_table_module (MonoImage *m)
498 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULE];
500 fprintf (output, "ModuleRef Table (1..%d)\n", t->rows);
502 for (i = 0; i < t->rows; i++){
503 guint32 cols [MONO_MODULE_SIZE];
507 mono_metadata_decode_row (t, i, cols, MONO_MODULE_SIZE);
509 name = mono_metadata_string_heap (m, cols [MONO_MODULE_NAME]);
510 guid = get_guid (m, cols [MONO_MODULE_MVID]);
511 fprintf (output, "%d: %s %d %s\n", i + 1, name, cols [MONO_MODULE_MVID], guid);
517 dump_table_method (MonoImage *m)
519 MonoTableInfo *t = &m->tables [MONO_TABLE_METHOD];
520 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
522 guint32 first_m, last_m;
523 fprintf (output, "Method Table (1..%d)\n", t->rows);
526 last_m = first_m = 1;
527 for (i = 1; i <= t->rows; i++){
528 guint32 cols [MONO_METHOD_SIZE];
531 MonoMethodSignature *method;
534 * Find the next type.
536 while (current_type <= td->rows && i >= (last_m = mono_metadata_decode_row_col (td, current_type - 1, MONO_TYPEDEF_METHOD_LIST))) {
540 fprintf (output, "########## %s.%s\n",
541 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAMESPACE)),
542 mono_metadata_string_heap (m, mono_metadata_decode_row_col (td, current_type - 2, MONO_TYPEDEF_NAME)));
545 mono_metadata_decode_row (t, i - 1, cols, MONO_METHOD_SIZE);
546 sigblob = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
547 mono_metadata_decode_blob_size (sigblob, &sigblob);
548 method = mono_metadata_parse_method_signature (m, i, sigblob, &sigblob);
549 sig = dis_stringify_method_signature (m, method, i);
550 fprintf (output, "%d: %s (param: %d)\n", i, sig, cols [MONO_METHOD_PARAMLIST]);
552 mono_metadata_free_method_signature (method);
558 method_dor_to_token (guint32 idx) {
559 switch (idx & METHODDEFORREF_MASK) {
560 case METHODDEFORREF_METHODDEF:
561 return MONO_TOKEN_METHOD_DEF | (idx >> METHODDEFORREF_BITS);
562 case METHODDEFORREF_METHODREF:
563 return MONO_TOKEN_MEMBER_REF | (idx >> METHODDEFORREF_BITS);
569 dump_table_methodimpl (MonoImage *m)
571 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODIMPL];
572 MonoTableInfo *td = &m->tables [MONO_TABLE_TYPEDEF];
575 fprintf (output, "MethodImpl Table (1..%d)\n", t->rows);
577 for (i = 1; i <= t->rows; i++){
578 guint32 cols [MONO_METHODIMPL_SIZE];
579 char *class, *impl, *decl;
581 mono_metadata_decode_row (t, i - 1, cols, MONO_METHODIMPL_SIZE);
582 class = get_typedef (m, cols [MONO_METHODIMPL_CLASS]);
583 impl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_BODY]));
584 decl = get_method (m, method_dor_to_token (cols [MONO_METHODIMPL_DECLARATION]));
585 fprintf (output, "%d: %s\n\tdecl: %s\n\timpl: %s\n", i, class, decl, impl);
593 static map_t semantics_map [] = {
604 dump_table_methodsem (MonoImage *m)
606 MonoTableInfo *t = &m->tables [MONO_TABLE_METHODSEMANTICS];
607 int i, is_property, index;
608 const char *semantics;
610 fprintf (output, "Method Semantics Table (1..%d)\n", t->rows);
611 for (i = 1; i <= t->rows; i++){
612 guint32 cols [MONO_METHOD_SEMA_SIZE];
614 mono_metadata_decode_row (t, i - 1, cols, MONO_METHOD_SEMA_SIZE);
615 semantics = flags (cols [MONO_METHOD_SEMA_SEMANTICS], semantics_map);
616 is_property = cols [MONO_METHOD_SEMA_ASSOCIATION] & HAS_SEMANTICS_MASK;
617 index = cols [MONO_METHOD_SEMA_ASSOCIATION] >> HAS_SEMANTICS_BITS;
618 fprintf (output, "%d: [%d] %s method: %d %s %d\n", i, cols [MONO_METHOD_SEMA_ASSOCIATION], semantics,
619 cols [MONO_METHOD_SEMA_METHOD] - 1,
620 is_property? "property" : "event",
626 dump_table_interfaceimpl (MonoImage *m)
628 MonoTableInfo *t = &m->tables [MONO_TABLE_INTERFACEIMPL];
631 fprintf (output, "Interface Implementation Table (1..%d)\n", t->rows);
632 for (i = 1; i <= t->rows; i++) {
633 guint32 cols [MONO_INTERFACEIMPL_SIZE];
635 mono_metadata_decode_row (t, i - 1, cols, MONO_INTERFACEIMPL_SIZE);
636 fprintf (output, "%d: %s implements %s\n", i,
637 get_typedef (m, cols [MONO_INTERFACEIMPL_CLASS]),
638 get_typedef_or_ref (m, cols [MONO_INTERFACEIMPL_INTERFACE]));
643 has_cattr_get_table (MonoImage *m, guint32 val)
645 guint32 t = val & CUSTOM_ATTR_MASK;
646 guint32 index = val >> CUSTOM_ATTR_BITS;
650 case CUSTOM_ATTR_METHODDEF:
653 case CUSTOM_ATTR_FIELDDEF:
656 case CUSTOM_ATTR_TYPEREF:
659 case CUSTOM_ATTR_TYPEDEF:
662 case CUSTOM_ATTR_PARAMDEF:
665 case CUSTOM_ATTR_INTERFACE:
666 table = "InterfaceImpl";
668 case CUSTOM_ATTR_MEMBERREF:
671 case CUSTOM_ATTR_MODULE:
674 case CUSTOM_ATTR_PERMISSION:
675 table = "DeclSecurity?";
677 case CUSTOM_ATTR_PROPERTY:
680 case CUSTOM_ATTR_EVENT:
683 case CUSTOM_ATTR_SIGNATURE:
684 table = "StandAloneSignature";
686 case CUSTOM_ATTR_MODULEREF:
689 case CUSTOM_ATTR_TYPESPEC:
692 case CUSTOM_ATTR_ASSEMBLY:
695 case CUSTOM_ATTR_ASSEMBLYREF:
696 table = "AssemblyRef";
698 case CUSTOM_ATTR_FILE:
701 case CUSTOM_ATTR_EXP_TYPE:
702 table = "ExportedType";
704 case CUSTOM_ATTR_MANIFEST:
712 * FIXME: we should decode the index into something more uman-friendly.
714 return g_strdup_printf ("%s: %d", table, index);
718 custom_attr_params (MonoImage *m, MonoMethodSignature* sig, const char* value)
720 int len, i, slen, type;
723 const char *p = value;
725 len = mono_metadata_decode_value (p, &p);
726 if (len < 2 || read16 (p) != 0x0001) /* Prolog */
727 return g_strdup ("");
731 res = g_string_new ("");
732 for (i = 0; i < sig->param_count; ++i) {
734 g_string_append (res, ", ");
735 type = sig->params [i]->type;
739 g_string_sprintfa (res, "%d", (unsigned int)*p);
743 g_string_sprintfa (res, "%d", *p);
746 case MONO_TYPE_BOOLEAN:
747 g_string_sprintfa (res, "%s", *p?"true":"false");
751 g_string_sprintfa (res, "'%c'", read16 (p));
755 g_string_sprintfa (res, "%d", read16 (p));
759 g_string_sprintfa (res, "%d", (gint16)read16 (p));
763 g_string_sprintfa (res, "%d", read32 (p));
767 g_string_sprintfa (res, "%d", (gint32)read32 (p));
771 g_string_sprintfa (res, "%lld", read64 (p));
775 g_string_sprintfa (res, "%lld", (gint64)read64 (p));
781 g_string_sprintfa (res, "%g", val);
788 g_string_sprintfa (res, "%g", val);
792 case MONO_TYPE_VALUETYPE:
793 if (sig->params [i]->data.klass->enumtype) {
794 type = sig->params [i]->data.klass->enum_basetype->type;
797 g_warning ("generic valutype not handled in custom attr value decoding");
800 case MONO_TYPE_CLASS: /* It must be a Type: check? */
801 case MONO_TYPE_STRING:
802 slen = mono_metadata_decode_value (p, &p);
803 g_string_append_c (res, '"');
804 g_string_append (res, p);
805 g_string_append_c (res, '"');
809 g_warning ("Type %02x not handled in custom attr value decoding", sig->params [i]->type);
815 g_string_sprintfa (res, " %d named args: (", slen);
816 slen = len - (p - value) + 1;
817 for (i = 0; i < slen; ++i) {
818 g_string_sprintfa (res, " %02X", (p [i] & 0xff));
820 g_string_append_c (res, ')');
823 g_string_free (res, FALSE);
828 dump_table_customattr (MonoImage *m)
830 MonoTableInfo *t = &m->tables [MONO_TABLE_CUSTOMATTRIBUTE];
833 fprintf (output, "Custom Attributes Table (1..%d)\n", t->rows);
834 for (i = 1; i <= t->rows; i++) {
835 guint32 cols [MONO_CUSTOM_ATTR_SIZE];
842 mono_metadata_decode_row (t, i - 1, cols, MONO_CUSTOM_ATTR_SIZE);
843 desc = has_cattr_get_table (m, cols [MONO_CUSTOM_ATTR_PARENT]);
844 mtoken = cols [MONO_CUSTOM_ATTR_TYPE] >> CUSTOM_ATTR_TYPE_BITS;
845 switch (cols [MONO_CUSTOM_ATTR_TYPE] & CUSTOM_ATTR_TYPE_MASK) {
846 case CUSTOM_ATTR_TYPE_METHODDEF:
847 mtoken |= MONO_TOKEN_METHOD_DEF;
849 case CUSTOM_ATTR_TYPE_MEMBERREF:
850 mtoken |= MONO_TOKEN_MEMBER_REF;
853 g_warning ("Unknown table for custom attr type %08x", cols [MONO_CUSTOM_ATTR_TYPE]);
856 method = get_method (m, mtoken);
857 meth = mono_get_method (m, mtoken, NULL);
858 params = custom_attr_params (m, meth->signature, mono_metadata_blob_heap (m, cols [MONO_CUSTOM_ATTR_VALUE]));
859 fprintf (output, "%d: %s: %s [%s]\n", i, desc, method, params);
867 dump_table_nestedclass (MonoImage *m)
869 MonoTableInfo *t = &m->tables [MONO_TABLE_NESTEDCLASS];
870 guint32 cols [MONO_NESTED_CLASS_SIZE];
872 char *nested, *nesting;
873 fprintf (output, "NestedClass Table (1..%d)\n", t->rows);
875 for (i = 1; i <= t->rows; i++){
876 mono_metadata_decode_row (t, i - 1, cols, MONO_NESTED_CLASS_SIZE);
877 nested = get_typedef (m, cols [MONO_NESTED_CLASS_NESTED]);
878 nesting = get_typedef (m, cols [MONO_NESTED_CLASS_ENCLOSING]);
879 fprintf (output, "%d: %d %d: %s in %s\n", i,
880 cols [MONO_NESTED_CLASS_NESTED],
881 cols [MONO_NESTED_CLASS_ENCLOSING], nested, nesting);
889 dump_table_exported (MonoImage *m)
891 MonoTableInfo *t = &m->tables [MONO_TABLE_EXPORTEDTYPE];
892 guint32 cols [MONO_EXP_TYPE_SIZE];
894 const char *name, *nspace;
895 fprintf (output, "ExportedType Table (1..%d)\n", t->rows);
897 for (i = 1; i <= t->rows; i++) {
898 mono_metadata_decode_row (t, i - 1, cols, MONO_EXP_TYPE_SIZE);
899 name = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAME]);
900 nspace = mono_metadata_string_heap (m, cols [MONO_EXP_TYPE_NAMESPACE]);
901 fprintf (output, "%d: %s %s\n", i, name, nspace);
907 dump_table_field_marshal (MonoImage *m)
909 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELDMARSHAL];
910 guint32 cols [MONO_FIELD_MARSHAL_SIZE];
911 int i, is_field, idx;
915 fprintf (output, "FieldMarshal Table (1..%d)\n", t->rows);
917 for (i = 1; i <= t->rows; i++) {
918 mono_metadata_decode_row (t, i - 1, cols, MONO_FIELD_MARSHAL_SIZE);
919 blob = mono_metadata_blob_heap (m, cols [MONO_FIELD_MARSHAL_NATIVE_TYPE]);
920 native = get_marshal_info (m, blob);
921 is_field = (cols [MONO_FIELD_MARSHAL_PARENT] & HAS_FIELD_MARSHAL_MASK) == HAS_FIELD_MARSHAL_FIELDSREF;
922 idx = cols [MONO_FIELD_MARSHAL_PARENT] >> HAS_FIELD_MARSHAL_BITS;
923 fprintf (output, "%d: (0x%04x) %s %d: %s\n", i, cols [MONO_FIELD_MARSHAL_PARENT], is_field? "Field" : "Param", idx, native);
930 get_security_action (int val) {
931 static char buf [32];
934 case SECURITY_ACTION_DEMAND:
936 case SECURITY_ACTION_ASSERT:
938 case SECURITY_ACTION_DENY:
940 case SECURITY_ACTION_PERMITONLY:
942 case SECURITY_ACTION_LINKDEMAND:
944 case SECURITY_ACTION_INHERITDEMAND:
945 return "InheritanceDemand";
946 case SECURITY_ACTION_REQMIN:
947 return "RequestMinimum";
948 case SECURITY_ACTION_REQOPT:
949 return "RequestOptional";
950 case SECURITY_ACTION_REQREFUSE:
951 return "RequestRefuse";
953 g_snprintf (buf, sizeof (buf), "0x%04X", val);
959 dump_table_declsec (MonoImage *m)
961 MonoTableInfo *t = &m->tables [MONO_TABLE_DECLSECURITY];
962 guint32 cols [MONO_DECL_SECURITY_SIZE];
965 const char *blob, *action;
966 const char* parent[] = {
967 "TypeDef", "MethodDef", "Assembly", ""
970 fprintf (output, "DeclSecurity Table (1..%d)\n", t->rows);
972 for (i = 1; i <= t->rows; i++) {
973 mono_metadata_decode_row (t, i - 1, cols, MONO_DECL_SECURITY_SIZE);
974 blob = mono_metadata_blob_heap (m, cols [MONO_DECL_SECURITY_PERMISSIONSET]);
975 len = mono_metadata_decode_blob_size (blob, &blob);
976 action = get_security_action (cols [MONO_DECL_SECURITY_ACTION]);
977 idx = cols [MONO_DECL_SECURITY_PARENT];
978 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");
981 for (idx = 0; idx < len; ++idx)
982 fprintf (output, "%c", blob [idx]);
983 fprintf (output, "\n");