2 * main.c: Sample disassembler
5 * Miguel de Icaza (miguel@ximian.com)
7 * (C) 2001 Ximian, Inc.
10 * Investigate how interface inheritance works and how it should be dumped.
11 * Structs are not being labeled as `valuetype' classes
13 * How are fields with literals mapped to constants?
26 #include <mono/metadata/loader.h>
27 #include <mono/metadata/assembly.h>
28 #include <mono/metadata/appdomain.h>
32 /* True if you want to get a dump of the header data */
33 gboolean dump_header_data_p = FALSE;
35 gboolean substitute_with_mscorlib_p = FALSE;
40 dump_header_data (MonoImage *img)
42 if (!dump_header_data_p)
46 "// Ximian's CIL disassembler, version 1.0\n"
47 "// Copyright (C) 2001 Ximian, Inc.\n\n");
51 dump_cattrs_list (GList *list, const char *indent)
55 for (tmp = list; tmp; tmp = tmp->next) {
56 fprintf (output, "%s%s\n", indent, (char*)tmp->data);
63 dump_cattrs (MonoImage *m, guint32 token, const char *indent)
67 list = dis_get_custom_attrs (m, token);
68 dump_cattrs_list (list, indent);
72 get_il_security_action (int val)
77 case SECURITY_ACTION_DEMAND:
79 case SECURITY_ACTION_ASSERT:
81 case SECURITY_ACTION_DENY:
83 case SECURITY_ACTION_PERMITONLY:
85 case SECURITY_ACTION_LINKDEMAND:
87 case SECURITY_ACTION_INHERITDEMAND:
88 return "inheritcheck";
89 case SECURITY_ACTION_REQMIN:
91 case SECURITY_ACTION_REQOPT:
93 case SECURITY_ACTION_REQREFUSE:
95 /* Special actions (for non CAS permissions) */
96 case SECURITY_ACTION_NONCASDEMAND:
97 return "noncasdemand";
98 case SECURITY_ACTION_NONCASLINKDEMAND:
99 return "noncaslinkdemand";
100 case SECURITY_ACTION_NONCASINHERITANCE:
101 return "noncasinheritance";
102 /* Fx 2.0 actions (for both CAS and non-CAS permissions) */
103 case SECURITY_ACTION_LINKDEMANDCHOICE:
104 return "linkdemandor";
105 case SECURITY_ACTION_INHERITDEMANDCHOICE:
106 return "inheritancedemandor";
107 case SECURITY_ACTION_DEMANDCHOICE:
110 g_snprintf (buf, sizeof (buf), "0x%04X", val);
115 #define OBJECT_TYPE_TYPEDEF 0
116 #define OBJECT_TYPE_METHODDEF 1
117 #define OBJECT_TYPE_ASSEMBLYDEF 2
120 dump_declarative_security (MonoImage *m, guint32 objectType, guint32 token, const char *indent)
122 MonoTableInfo *t = &m->tables [MONO_TABLE_DECLSECURITY];
123 guint32 cols [MONO_DECL_SECURITY_SIZE];
126 const char *blob, *action;
128 for (i = 1; i <= t->rows; i++) {
129 mono_metadata_decode_row (t, i - 1, cols, MONO_DECL_SECURITY_SIZE);
130 blob = mono_metadata_blob_heap (m, cols [MONO_DECL_SECURITY_PERMISSIONSET]);
131 len = mono_metadata_decode_blob_size (blob, &blob);
132 action = get_il_security_action (cols [MONO_DECL_SECURITY_ACTION]);
133 idx = cols [MONO_DECL_SECURITY_PARENT];
134 if (((idx & MONO_HAS_DECL_SECURITY_MASK) == objectType) && ((idx >> MONO_HAS_DECL_SECURITY_BITS) == token)) {
135 char *dump = data_dump (blob, len, indent);
136 fprintf (output, "%s.permissionset %s = %s", indent, action, dump);
143 dis_directive_assembly (MonoImage *m)
145 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLY];
146 guint32 cols [MONO_ASSEMBLY_SIZE];
151 mono_metadata_decode_row (t, 0, cols, MONO_ASSEMBLY_SIZE);
153 fprintf (output, ".assembly '%s'\n{\n",
154 mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_NAME]));
155 dump_cattrs (m, MONO_TOKEN_ASSEMBLY | 1, " ");
156 dump_declarative_security (m, OBJECT_TYPE_ASSEMBLYDEF, 1, " ");
158 " .hash algorithm 0x%08x\n"
159 " .ver %d:%d:%d:%d\n",
160 cols [MONO_ASSEMBLY_HASH_ALG],
161 cols [MONO_ASSEMBLY_MAJOR_VERSION], cols [MONO_ASSEMBLY_MINOR_VERSION],
162 cols [MONO_ASSEMBLY_BUILD_NUMBER], cols [MONO_ASSEMBLY_REV_NUMBER]);
163 if (cols [MONO_ASSEMBLY_CULTURE])
164 fprintf (output, " .locale %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLY_CULTURE]));
165 if (cols [MONO_ASSEMBLY_PUBLIC_KEY]) {
166 const char* b = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLY_PUBLIC_KEY]);
167 int len = mono_metadata_decode_blob_size (b, &b);
168 char *dump = data_dump (b, len, "\t\t");
169 fprintf (output, " .publickey =%s", dump);
172 fprintf (output, "}\n");
176 dis_directive_assemblyref (MonoImage *m)
178 MonoTableInfo *t = &m->tables [MONO_TABLE_ASSEMBLYREF];
179 guint32 cols [MONO_ASSEMBLYREF_SIZE];
185 for (i = 0; i < t->rows; i++){
188 mono_metadata_decode_row (t, i, cols, MONO_ASSEMBLYREF_SIZE);
190 esc = get_escaped_name (mono_metadata_string_heap (m, cols [MONO_ASSEMBLYREF_NAME]));
193 ".assembly extern %s\n"
195 " .ver %d:%d:%d:%d\n",
197 cols [MONO_ASSEMBLYREF_MAJOR_VERSION], cols [MONO_ASSEMBLYREF_MINOR_VERSION],
198 cols [MONO_ASSEMBLYREF_BUILD_NUMBER], cols [MONO_ASSEMBLYREF_REV_NUMBER]
200 if (cols [MONO_ASSEMBLYREF_CULTURE]){
201 fprintf (output, " .locale %s\n", mono_metadata_string_heap (m, cols [MONO_ASSEMBLYREF_CULTURE]));
203 if (cols [MONO_ASSEMBLYREF_PUBLIC_KEY]){
204 const char* b = mono_metadata_blob_heap (m, cols [MONO_ASSEMBLYREF_PUBLIC_KEY]);
205 int len = mono_metadata_decode_blob_size (b, &b);
206 char *dump = data_dump (b, len, "\t\t");
207 fprintf (output, " .publickeytoken =%s", dump);
210 fprintf (output, "}\n");
216 dis_directive_module (MonoImage *m)
218 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULE];
221 for (i = 0; i < t->rows; i++){
222 guint32 cols [MONO_MODULE_SIZE];
226 mono_metadata_decode_row (t, i, cols, MONO_MODULE_SIZE);
228 name = mono_metadata_string_heap (m, cols [MONO_MODULE_NAME]);
229 ename = get_escaped_name (name);
230 guid = get_guid (m, cols [MONO_MODULE_MVID]);
231 fprintf (output, ".module %s // GUID = %s\n\n", ename, guid);
234 dump_cattrs (m, MONO_TOKEN_MODULE | (i + 1), "");
239 dis_directive_moduleref (MonoImage *m)
241 MonoTableInfo *t = &m->tables [MONO_TABLE_MODULEREF];
244 for (i = 0; i < t->rows; i++){
245 guint32 cols [MONO_MODULEREF_SIZE];
248 mono_metadata_decode_row (t, i, cols, MONO_MODULEREF_SIZE);
250 name = mono_metadata_string_heap (m, cols [MONO_MODULEREF_NAME]);
251 fprintf (output, ".module extern %s\n", name);
257 dis_directive_file (MonoImage *m)
259 MonoTableInfo *t = &m->tables [MONO_TABLE_FILE];
263 entry_point = mono_image_get_entry_point (m);
265 for (i = 0; i < t->rows; i++){
266 guint32 cols [MONO_FILE_SIZE];
267 const char *name, *hash;
270 mono_metadata_decode_row (t, i, cols, MONO_FILE_SIZE);
272 name = mono_metadata_string_heap (m, cols [MONO_FILE_NAME]);
274 hash = mono_metadata_blob_heap (m, cols [MONO_FILE_HASH_VALUE]);
275 len = mono_metadata_decode_blob_size (hash, &hash);
277 fprintf (output, ".file %s%s .hash = (", name,
278 cols [MONO_FILE_FLAGS] & FILE_CONTAINS_NO_METADATA ? " nometadata" : "");
280 for (j = 0; j < len; ++j)
281 fprintf (output, " %02X", hash [j] & 0xff);
283 token = mono_metadata_make_token (MONO_TABLE_FILE, i + 1);
284 fprintf (output, " )%s\n", (token == entry_point) ? " .entrypoint" : "");
289 static dis_map_t visibility_map [] = {
290 { TYPE_ATTRIBUTE_NOT_PUBLIC, "private " },
291 { TYPE_ATTRIBUTE_PUBLIC, "public " },
292 { TYPE_ATTRIBUTE_NESTED_PUBLIC, "nested public " },
293 { TYPE_ATTRIBUTE_NESTED_PRIVATE, "nested private " },
294 { TYPE_ATTRIBUTE_NESTED_FAMILY, "nested family " },
295 { TYPE_ATTRIBUTE_NESTED_ASSEMBLY, "nested assembly " },
296 { TYPE_ATTRIBUTE_NESTED_FAM_AND_ASSEM, "nested famandassem " },
297 { TYPE_ATTRIBUTE_NESTED_FAM_OR_ASSEM, "nested famorassem " },
301 static dis_map_t layout_map [] = {
302 { TYPE_ATTRIBUTE_AUTO_LAYOUT, "auto " },
303 { TYPE_ATTRIBUTE_SEQUENTIAL_LAYOUT, "sequential " },
304 { TYPE_ATTRIBUTE_EXPLICIT_LAYOUT, "explicit " },
308 static dis_map_t format_map [] = {
309 { TYPE_ATTRIBUTE_ANSI_CLASS, "ansi " },
310 { TYPE_ATTRIBUTE_UNICODE_CLASS, "unicode " },
311 { TYPE_ATTRIBUTE_AUTO_CLASS, "auto " },
316 typedef_flags (guint32 flags)
318 static char buffer [1024];
319 int visibility = flags & TYPE_ATTRIBUTE_VISIBILITY_MASK;
320 int layout = flags & TYPE_ATTRIBUTE_LAYOUT_MASK;
321 int format = flags & TYPE_ATTRIBUTE_STRING_FORMAT_MASK;
325 strcat (buffer, map (visibility, visibility_map));
326 strcat (buffer, map (layout, layout_map));
327 strcat (buffer, map (format, format_map));
329 if (flags & TYPE_ATTRIBUTE_ABSTRACT)
330 strcat (buffer, "abstract ");
331 if (flags & TYPE_ATTRIBUTE_SEALED)
332 strcat (buffer, "sealed ");
333 if (flags & TYPE_ATTRIBUTE_SPECIAL_NAME)
334 strcat (buffer, "special-name ");
335 if (flags & TYPE_ATTRIBUTE_IMPORT)
336 strcat (buffer, "import ");
337 if (flags & TYPE_ATTRIBUTE_SERIALIZABLE)
338 strcat (buffer, "serializable ");
339 if (flags & TYPE_ATTRIBUTE_BEFORE_FIELD_INIT)
340 strcat (buffer, "beforefieldinit ");
347 * @m: metadata context
348 * @start: starting index into the Field Table.
349 * @end: ending index into Field table.
351 * This routine displays all the decoded fields from @start to @end
354 dis_field_list (MonoImage *m, guint32 start, guint32 end)
356 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELD];
357 guint32 cols [MONO_FIELD_SIZE];
363 if (end > t->rows + 1) {
364 g_warning ("ERROR index out of range in fields");
368 for (i = start; i < end; i++){
369 char *sig, *flags, *attrs = NULL;
370 guint32 field_offset = -1;
372 mono_metadata_decode_row (t, i, cols, MONO_FIELD_SIZE);
373 sig = get_field_signature (m, cols [MONO_FIELD_SIGNATURE]);
374 flags = field_flags (cols [MONO_FIELD_FLAGS]);
376 if (cols [MONO_FIELD_FLAGS] & FIELD_ATTRIBUTE_HAS_FIELD_RVA) {
377 mono_metadata_field_info (m, i, NULL, &rva, NULL);
378 g_snprintf (rva_desc, sizeof (rva_desc), " at D_%08x", rva);
383 mono_metadata_field_info (m, i, &field_offset, NULL, NULL);
384 if (field_offset != -1)
385 attrs = g_strdup_printf ("[%d]", field_offset);
386 esname = get_escaped_name (mono_metadata_string_heap (m, cols [MONO_FIELD_NAME]));
387 if (cols [MONO_FIELD_FLAGS] & FIELD_ATTRIBUTE_LITERAL){
389 guint32 const_cols [MONO_CONSTANT_SIZE];
392 if ((crow = mono_metadata_get_constant_index (m, MONO_TOKEN_FIELD_DEF | (i+1), 0))) {
393 mono_metadata_decode_row (&m->tables [MONO_TABLE_CONSTANT], crow-1, const_cols, MONO_CONSTANT_SIZE);
394 lit = get_constant (m, const_cols [MONO_CONSTANT_TYPE], const_cols [MONO_CONSTANT_VALUE]);
396 lit = g_strdup ("not found");
400 fprintf (output, " .field %s %s %s = ",
402 fprintf (output, "%s\n", lit);
405 fprintf (output, " .field %s %s %s %s%s\n",
406 attrs? attrs: "", flags, sig, esname, rva_desc);
411 dump_cattrs (m, MONO_TOKEN_FIELD_DEF | (i + 1), " ");
415 static dis_map_t method_access_map [] = {
416 { METHOD_ATTRIBUTE_COMPILER_CONTROLLED, "compilercontrolled " },
417 { METHOD_ATTRIBUTE_PRIVATE, "private " },
418 { METHOD_ATTRIBUTE_FAM_AND_ASSEM, "famandassem " },
419 { METHOD_ATTRIBUTE_ASSEM, "assembly " },
420 { METHOD_ATTRIBUTE_FAMILY, "family " },
421 { METHOD_ATTRIBUTE_FAM_OR_ASSEM, "famorassem " },
422 { METHOD_ATTRIBUTE_PUBLIC, "public " },
426 static dis_map_t method_flags_map [] = {
427 { METHOD_ATTRIBUTE_STATIC, "static " },
428 { METHOD_ATTRIBUTE_FINAL, "final " },
429 { METHOD_ATTRIBUTE_VIRTUAL, "virtual " },
430 { METHOD_ATTRIBUTE_HIDE_BY_SIG, "hidebysig " },
431 { METHOD_ATTRIBUTE_VTABLE_LAYOUT_MASK, "newslot " },
432 { METHOD_ATTRIBUTE_ABSTRACT, "abstract " },
433 { METHOD_ATTRIBUTE_SPECIAL_NAME, "specialname " },
434 { METHOD_ATTRIBUTE_RT_SPECIAL_NAME, "rtspecialname " },
435 { METHOD_ATTRIBUTE_UNMANAGED_EXPORT, "export " },
436 /* MS ilasm doesn't compile this statement - is must be added automagically when permissionset are present */
437 /* { METHOD_ATTRIBUTE_HAS_SECURITY, "hassecurity" }, */
438 { METHOD_ATTRIBUTE_REQUIRE_SEC_OBJECT, "requiresecobj" },
439 { METHOD_ATTRIBUTE_PINVOKE_IMPL, "pinvokeimpl " },
446 * Returns a stringified version of the Method's flags
449 method_flags (guint32 f)
451 GString *str = g_string_new ("");
452 int access = f & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK;
455 g_string_append (str, map (access, method_access_map));
456 g_string_append (str, flags (f, method_flags_map));
459 g_string_free (str, FALSE);
464 static dis_map_t pinvoke_flags_map [] = {
465 { PINVOKE_ATTRIBUTE_NO_MANGLE , "nomangle " },
466 { PINVOKE_ATTRIBUTE_SUPPORTS_LAST_ERROR, "lasterr " },
467 { PINVOKE_ATTRIBUTE_BEST_FIT_ENABLED, "bestfit:on" },
468 { PINVOKE_ATTRIBUTE_BEST_FIT_DISABLED, "bestfit:off" },
469 { PINVOKE_ATTRIBUTE_THROW_ON_UNMAPPABLE_ENABLED, "charmaperror:on" },
470 { PINVOKE_ATTRIBUTE_THROW_ON_UNMAPPABLE_DISABLED, "charmaperror:off" },
474 static dis_map_t pinvoke_call_conv_map [] = {
475 { PINVOKE_ATTRIBUTE_CALL_CONV_WINAPI, "winapi " },
476 { PINVOKE_ATTRIBUTE_CALL_CONV_CDECL, "cdecl " },
477 { PINVOKE_ATTRIBUTE_CALL_CONV_STDCALL, "stdcall " },
478 { PINVOKE_ATTRIBUTE_CALL_CONV_THISCALL, "thiscall " },
479 { PINVOKE_ATTRIBUTE_CALL_CONV_FASTCALL, "fastcall " },
483 static dis_map_t pinvoke_char_set_map [] = {
484 { PINVOKE_ATTRIBUTE_CHAR_SET_NOT_SPEC, "" },
485 { PINVOKE_ATTRIBUTE_CHAR_SET_ANSI, "ansi " },
486 { PINVOKE_ATTRIBUTE_CHAR_SET_UNICODE , "unicode " },
487 { PINVOKE_ATTRIBUTE_CHAR_SET_AUTO, "autochar " },
494 * Returns a stringified version of the Method's pinvoke flags
497 pinvoke_flags (guint32 f)
499 GString *str = g_string_new ("");
500 int cset = f & PINVOKE_ATTRIBUTE_CHAR_SET_MASK;
501 int cconv = f & PINVOKE_ATTRIBUTE_CALL_CONV_MASK;
504 g_string_append (str, map (cset, pinvoke_char_set_map));
505 g_string_append (str, map (cconv, pinvoke_call_conv_map));
506 g_string_append (str, flags (f, pinvoke_flags_map));
508 s = g_strdup(str->str);
509 g_string_free (str, FALSE);
514 static dis_map_t method_impl_map [] = {
515 { METHOD_IMPL_ATTRIBUTE_IL, "cil " },
516 { METHOD_IMPL_ATTRIBUTE_NATIVE, "native " },
517 { METHOD_IMPL_ATTRIBUTE_OPTIL, "optil " },
518 { METHOD_IMPL_ATTRIBUTE_RUNTIME, "runtime " },
522 static dis_map_t managed_type_map [] = {
523 { METHOD_IMPL_ATTRIBUTE_UNMANAGED, "unmanaged " },
524 { METHOD_IMPL_ATTRIBUTE_MANAGED, "managed " },
528 static dis_map_t managed_impl_flags [] = {
529 { METHOD_IMPL_ATTRIBUTE_FORWARD_REF, "fwdref " },
530 { METHOD_IMPL_ATTRIBUTE_PRESERVE_SIG, "preservesig " },
531 { METHOD_IMPL_ATTRIBUTE_INTERNAL_CALL, "internalcall " },
532 { METHOD_IMPL_ATTRIBUTE_SYNCHRONIZED, "synchronized " },
533 { METHOD_IMPL_ATTRIBUTE_NOINLINING, "noinline " },
538 method_impl_flags (guint32 f)
540 GString *str = g_string_new ("");
542 int code_type = f & METHOD_IMPL_ATTRIBUTE_CODE_TYPE_MASK;
543 int managed_type = f & METHOD_IMPL_ATTRIBUTE_MANAGED_MASK;
545 g_string_append (str, map (code_type, method_impl_map));
546 g_string_append (str, map (managed_type, managed_type_map));
547 g_string_append (str, flags (f, managed_impl_flags));
550 g_string_free (str, FALSE);
555 dis_locals (MonoImage *m, MonoMethodHeader *mh, const char *ptr)
560 unsigned char flags = *(const unsigned char *) ptr;
561 unsigned char format = flags & METHOD_HEADER_FORMAT_MASK;
563 guint32 local_var_sig_tok, max_stack, code_size, init_locals;
566 g_assert (format == METHOD_HEADER_FAT_FORMAT);
567 fat_flags = read16 (ptr);
569 hsize = (fat_flags >> 12) & 0xf;
570 max_stack = read16 (ptr);
572 code_size = read32 (ptr);
574 local_var_sig_tok = read32 (ptr);
577 if (fat_flags & METHOD_HEADER_INIT_LOCALS)
582 fprintf(output, "\t.locals /*%08x*/ %s(\n",
583 local_var_sig_tok, init_locals ? "init " : "");
585 fprintf(output, "\t.locals %s(\n", mh->init_locals ? "init " : "");
587 for (i=0; i < mh->num_locals; ++i) {
590 fprintf(output, ",\n");
591 /* print also byref and pinned attributes */
592 desc = dis_stringify_type (m, mh->locals[i]);
593 fprintf(output, "\t\t%s\tV_%d", desc, i);
596 fprintf(output, ")\n");
600 dis_code (MonoImage *m, guint32 token, guint32 rva)
602 MonoMethodHeader *mh;
603 const char *ptr = mono_image_rva_map (m, rva);
611 override = get_method_override (m, token);
613 fprintf (output, "\t.override %s\n", override);
617 mh = mono_metadata_parse_mh (m, ptr);
618 if ((entry_point = mono_image_get_entry_point (m))){
619 loc = mono_metadata_locate_token (m, entry_point);
620 if (rva == read32 (loc))
621 fprintf (output, "\t.entrypoint\n");
624 fprintf (output, "\t// Code size %d (0x%x)\n", mh->code_size, mh->code_size);
625 fprintf (output, "\t.maxstack %d\n", mh->max_stack);
627 dis_locals (m, mh, ptr);
628 dissasemble_cil (m, mh);
631 hex_dump (mh->code, 0, mh->code_size);
632 printf ("\nAfter the code\n");
633 hex_dump (mh->code + mh->code_size, 0, 64);
635 mono_metadata_free_mh (mh);
639 pinvoke_info (MonoImage *m, guint32 mindex)
641 MonoTableInfo *im = &m->tables [MONO_TABLE_IMPLMAP];
642 MonoTableInfo *mr = &m->tables [MONO_TABLE_MODULEREF];
643 guint32 im_cols [MONO_IMPLMAP_SIZE];
644 guint32 mr_cols [MONO_MODULEREF_SIZE];
645 const char *import, *scope;
649 for (i = 0; i < im->rows; i++) {
651 mono_metadata_decode_row (im, i, im_cols, MONO_IMPLMAP_SIZE);
653 if ((im_cols [MONO_IMPLMAP_MEMBER] >> 1) == mindex + 1) {
655 flags = pinvoke_flags (im_cols [MONO_IMPLMAP_FLAGS]);
657 import = mono_metadata_string_heap (m, im_cols [MONO_IMPLMAP_NAME]);
659 mono_metadata_decode_row (mr, im_cols [MONO_IMPLMAP_SCOPE] - 1,
660 mr_cols, MONO_MODULEREF_SIZE);
662 scope = mono_metadata_string_heap (m, mr_cols [MONO_MODULEREF_NAME]);
664 return g_strdup_printf ("(\"%s\" as \"%s\" %s)", scope, import,
674 dump_cattrs_for_method_params (MonoImage *m, guint32 midx, MonoMethodSignature *sig) {
675 MonoTableInfo *methodt;
676 MonoTableInfo *paramt;
677 guint param_index, lastp, i;
679 methodt = &m->tables [MONO_TABLE_METHOD];
680 paramt = &m->tables [MONO_TABLE_PARAM];
681 param_index = mono_metadata_decode_row_col (methodt, midx, MONO_METHOD_PARAMLIST);
682 if (midx + 1 < methodt->rows)
683 lastp = mono_metadata_decode_row_col (methodt, midx + 1, MONO_METHOD_PARAMLIST);
685 lastp = paramt->rows + 1;
686 for (i = param_index; i < lastp; ++i) {
689 guint32 param_cols [MONO_PARAM_SIZE];
692 list = dis_get_custom_attrs (m, MONO_TOKEN_PARAM_DEF | i);
694 mono_metadata_decode_row (paramt, i-1, param_cols, MONO_PARAM_SIZE);
695 if (!(param_cols[MONO_PARAM_FLAGS] & PARAM_ATTRIBUTE_HAS_DEFAULT)) {
697 fprintf (output, "\t.param [%d]\n", param_cols[MONO_PARAM_SEQUENCE]);
699 fprintf (output, "\t.param [%d] = ", param_cols[MONO_PARAM_SEQUENCE]);
701 if ((crow = mono_metadata_get_constant_index(m, MONO_TOKEN_PARAM_DEF | i, 0))) {
702 guint32 const_cols [MONO_CONSTANT_SIZE];
703 mono_metadata_decode_row( &m->tables[MONO_TABLE_CONSTANT], crow-1, const_cols, MONO_CONSTANT_SIZE);
704 lit = get_constant(m, const_cols [MONO_CONSTANT_TYPE], const_cols [MONO_CONSTANT_VALUE]);
707 lit = g_strdup ("not found");
709 fprintf(output, "%s\n", lit);
712 dump_cattrs_list (list, "\t");
718 * @m: metadata context
719 * @start: starting index into the Method Table.
720 * @end: ending index into Method table.
722 * This routine displays the methods in the Method Table from @start to @end
725 dis_method_list (const char *klass_name, MonoImage *m, guint32 start, guint32 end)
727 MonoTableInfo *t = &m->tables [MONO_TABLE_METHOD];
728 guint32 cols [MONO_METHOD_SIZE];
732 fprintf (output, "ERROR index out of range in methods");
737 for (i = start; i < end; i++){
738 MonoMethodSignature *ms;
739 char *flags, *impl_flags;
744 mono_metadata_decode_row (t, i, cols, MONO_METHOD_SIZE);
746 flags = method_flags (cols [MONO_METHOD_FLAGS]);
747 impl_flags = method_impl_flags (cols [MONO_METHOD_IMPLFLAGS]);
749 sig = mono_metadata_blob_heap (m, cols [MONO_METHOD_SIGNATURE]);
750 mono_metadata_decode_blob_size (sig, &sig);
751 ms = mono_metadata_parse_method_signature (m, i + 1, sig, &sig);
752 sig_str = dis_stringify_method_signature (m, ms, i + 1, FALSE);
754 fprintf (output, " // method line %d\n", i + 1);
755 fprintf (output, " .method %s", flags);
757 if ((cols [MONO_METHOD_FLAGS] & METHOD_ATTRIBUTE_PINVOKE_IMPL) && (cols [MONO_METHOD_RVA] == 0)) {
758 gchar *pi = pinvoke_info (m, i);
760 fprintf (output, "%s", pi);
765 fprintf (output, "\n %s", sig_str);
766 fprintf (output, " %s\n", impl_flags);
770 token = MONO_TOKEN_METHOD_DEF | (i + 1);
772 fprintf (output, " {\n");
773 dump_cattrs (m, token, " ");
774 dump_cattrs_for_method_params (m, i, ms);
775 /* FIXME: need to sump also param custom attributes */
776 fprintf (output, " // Method begins at RVA 0x%x\n", cols [MONO_METHOD_RVA]);
777 dump_declarative_security (m, OBJECT_TYPE_METHODDEF, i + 1, " ");
778 if (cols [MONO_METHOD_IMPLFLAGS] & METHOD_IMPL_ATTRIBUTE_NATIVE)
779 fprintf (output, " // Disassembly of native methods is not supported\n");
781 dis_code (m, token, cols [MONO_METHOD_RVA]);
782 fprintf (output, " } // end of method %s::%s\n\n", klass_name, sig_str);
783 mono_metadata_free_method_signature (ms);
796 table_locator (const void *a, const void *b)
798 plocator_t *loc = (plocator_t *) a;
799 const char *bb = (const char *) b;
800 guint32 table_index = (bb - loc->t->base) / loc->t->row_size;
803 col = mono_metadata_decode_row_col (loc->t, table_index, loc->col_idx);
805 if (loc->idx == col) {
806 loc->result = table_index;
816 dis_property_methods (MonoImage *m, guint32 prop)
819 MonoTableInfo *msemt = &m->tables [MONO_TABLE_METHODSEMANTICS];
820 guint32 cols [MONO_METHOD_SEMA_SIZE];
822 const char *type[] = {NULL, ".set", ".get", NULL, ".other"};
824 start = mono_metadata_methods_from_property (m, prop, &end);
825 while (start < end) {
826 mono_metadata_decode_row (msemt, start, cols, MONO_METHOD_SEMA_SIZE);
827 sig = dis_stringify_method_signature (m, NULL, cols [MONO_METHOD_SEMA_METHOD], TRUE);
828 fprintf (output, "\t\t%s %s\n", type [cols [MONO_METHOD_SEMA_SEMANTICS]], sig);
834 dis_property_signature (MonoImage *m, guint32 prop_idx)
836 MonoTableInfo *propt = &m->tables [MONO_TABLE_PROPERTY];
839 guint32 cols [MONO_PROPERTY_SIZE];
845 GString *res = g_string_new ("");
847 mono_metadata_decode_row (propt, prop_idx, cols, MONO_PROPERTY_SIZE);
848 name = mono_metadata_string_heap (m, cols [MONO_PROPERTY_NAME]);
849 prop_flags = cols [MONO_PROPERTY_FLAGS];
850 ptr = mono_metadata_blob_heap (m, cols [MONO_PROPERTY_TYPE]);
851 mono_metadata_decode_blob_size (ptr, &ptr);
852 /* ECMA claims 0x08 ... */
853 if (*ptr != 0x28 && *ptr != 0x08)
854 g_warning("incorrect signature in propert blob: 0x%x", *ptr);
856 pcount = mono_metadata_decode_value (ptr, &ptr);
857 type = mono_metadata_parse_type (m, MONO_PARSE_TYPE, 0, ptr, &ptr);
858 blurb = dis_stringify_type (m, type);
859 if (prop_flags & 0x0200)
860 g_string_append (res, "specialname ");
861 if (prop_flags & 0x0400)
862 g_string_append (res, "rtspecialname ");
863 qk = get_escaped_name (name);
864 g_string_sprintfa (res, "%s %s (", blurb, qk);
867 mono_metadata_free_type (type);
868 for (i = 0; i < pcount; i++) {
870 g_string_append (res, ", ");
871 param = mono_metadata_parse_param (m, ptr, &ptr);
872 blurb = dis_stringify_param (m, param);
873 g_string_append (res, blurb);
874 mono_metadata_free_type (param);
877 g_string_append_c (res, ')');
879 g_string_free (res, FALSE);
885 dis_property_list (MonoImage *m, guint32 typedef_row)
888 start = mono_metadata_properties_from_typedef (m, typedef_row, &end);
890 for (i = start; i < end; ++i) {
891 char *sig = dis_property_signature (m, i);
892 fprintf (output, "\t.property %s\n\t{\n", sig);
893 dump_cattrs (m, MONO_TOKEN_PROPERTY | (i + 1), "\t\t");
894 dis_property_methods (m, i);
895 fprintf (output, "\t}\n");
901 dis_event_signature (MonoImage *m, guint32 event_idx)
903 MonoTableInfo *et = &m->tables [MONO_TABLE_EVENT];
904 char *type, *result, *esname;
905 guint32 cols [MONO_EVENT_SIZE];
907 GString *res = g_string_new ("");
909 mono_metadata_decode_row (et, event_idx, cols, MONO_EVENT_SIZE);
910 esname = get_escaped_name (mono_metadata_string_heap (m, cols [MONO_EVENT_NAME]));
911 type = get_typedef_or_ref (m, cols [MONO_EVENT_TYPE]);
912 event_flags = cols [MONO_EVENT_FLAGS];
914 if (event_flags & 0x0200)
915 g_string_append (res, "specialname ");
916 if (event_flags & 0x0400)
917 g_string_append (res, "rtspecialname ");
918 g_string_sprintfa (res, "%s %s", type, esname);
923 g_string_free (res, FALSE);
928 dis_event_methods (MonoImage *m, guint32 event)
931 MonoTableInfo *msemt = &m->tables [MONO_TABLE_METHODSEMANTICS];
932 guint32 cols [MONO_METHOD_SEMA_SIZE];
934 const char *type = "";
936 start = mono_metadata_methods_from_event (m, event, &end);
937 while (start < end) {
938 mono_metadata_decode_row (msemt, start, cols, MONO_METHOD_SEMA_SIZE);
939 sig = dis_stringify_method_signature (m, NULL, cols [MONO_METHOD_SEMA_METHOD], TRUE);
940 switch (cols [MONO_METHOD_SEMA_SEMANTICS]) {
941 case METHOD_SEMANTIC_OTHER:
942 type = ".other"; break;
943 case METHOD_SEMANTIC_ADD_ON:
944 type = ".addon"; break;
945 case METHOD_SEMANTIC_REMOVE_ON:
946 type = ".removeon"; break;
947 case METHOD_SEMANTIC_FIRE:
948 type = ".fire"; break;
952 fprintf (output, "\t\t%s %s\n", type, sig);
959 dis_event_list (MonoImage *m, guint32 typedef_row)
962 start = mono_metadata_events_from_typedef (m, typedef_row, &end);
964 for (i = start; i < end; ++i) {
965 char *sig = dis_event_signature (m, i);
966 fprintf (output, "\t.event %s\n\t{\n", sig);
967 dump_cattrs (m, MONO_TOKEN_EVENT | (i + 1), "\t\t");
968 dis_event_methods (m, i);
969 fprintf (output, "\t}\n");
975 dis_interfaces (MonoImage *m, guint32 typedef_row)
979 gboolean first_interface = 1;
980 guint32 cols [MONO_INTERFACEIMPL_SIZE];
982 MonoTableInfo *table = &m->tables [MONO_TABLE_INTERFACEIMPL];
988 loc.col_idx = MONO_INTERFACEIMPL_CLASS;
989 loc.idx = typedef_row;
991 if (!bsearch (&loc, table->base, table->rows, table->row_size, table_locator))
996 * We may end up in the middle of the rows...
999 if (loc.idx == mono_metadata_decode_row_col (table, start - 1, MONO_INTERFACEIMPL_CLASS))
1004 while (start < table->rows) {
1005 mono_metadata_decode_row (table, start, cols, MONO_INTERFACEIMPL_SIZE);
1006 if (cols [MONO_INTERFACEIMPL_CLASS] != loc.idx)
1008 intf = get_typedef_or_ref (m, cols [MONO_INTERFACEIMPL_INTERFACE]);
1009 if (first_interface) {
1010 fprintf (output, " \timplements %s", intf);
1011 first_interface = 0;
1013 fprintf (output, ", %s", intf);
1021 * dis_generic_param_and_constraints:
1022 * @m: metadata context
1023 * @table_type: Type of table (0 for typedef, 1 for methoddef)
1024 * @row: Row in table
1026 * Dissasembles the generic parameters for this type or method, also
1027 * returns an allocated GString containing the generic constraints NULL
1028 * if their are no generic constraints.
1031 dis_generic_param_and_constraints (MonoImage *m, int table_type, guint32 typedef_row)
1033 MonoTableInfo *t = &m->tables [MONO_TABLE_GENERICPARAM];
1034 MonoTableInfo *ct = &m->tables [MONO_TABLE_GENERICPARAMCONSTRAINT];
1035 GString* cnst_block = NULL;
1036 guint32 cols [MONO_GENERICPARAM_SIZE];
1037 guint32 ccols [MONO_GENPARCONSTRAINT_SIZE];
1038 int i, own_tok, table, idx, found_count, cnst_start, cnst_ind;
1040 g_assert (table_type != MONO_TYPEORMETHOD_TYPE || table_type != MONO_TYPEORMETHOD_METHOD);
1042 found_count = cnst_start = 0;
1043 for (i = 1; i <= t->rows; i++) {
1044 mono_metadata_decode_row (t, i-1, cols, MONO_GENERICPARAM_SIZE);
1045 own_tok = cols [MONO_GENERICPARAM_OWNER];
1046 table = own_tok & MONO_TYPEORMETHOD_MASK;
1047 idx = own_tok >> MONO_TYPEORMETHOD_BITS;
1049 if (table != table_type || idx != typedef_row)
1052 if (found_count == 0)
1053 fprintf (output, "<");
1055 fprintf (output, ", ");
1057 for (cnst_ind = cnst_start; cnst_ind < ct->rows; cnst_ind++) {
1059 mono_metadata_decode_row (ct, cnst_ind, ccols, MONO_GENPARCONSTRAINT_SIZE);
1060 if (ccols [MONO_GENPARCONSTRAINT_GENERICPAR] != i)
1062 if (cnst_block == NULL)
1063 cnst_block = g_string_new ("");
1064 sig = get_typedef_or_ref (m, ccols [MONO_GENPARCONSTRAINT_CONSTRAINT]);
1065 fprintf (output, "(%s) ", sig);
1067 cnst_start = cnst_ind;
1070 fprintf (output, "%s", mono_metadata_string_heap (m, cols [MONO_GENERICPARAM_NAME]));
1076 fprintf (output, ">");
1083 * @m: metadata context
1084 * @n: index of type to disassemble
1086 * Disassembles the type whose index in the TypeDef table is @n.
1089 dis_type (MonoImage *m, int n)
1091 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEDEF];
1092 GString *cnst_block = NULL;
1093 guint32 cols [MONO_TYPEDEF_SIZE];
1094 guint32 cols_next [MONO_TYPEDEF_SIZE];
1095 const char *name, *nspace;
1097 guint32 packing_size, class_size;
1098 gboolean next_is_valid, last;
1101 mono_metadata_decode_row (t, n, cols, MONO_TYPEDEF_SIZE);
1103 if (t->rows > n + 1) {
1104 mono_metadata_decode_row (t, n + 1, cols_next, MONO_TYPEDEF_SIZE);
1109 name = mono_metadata_string_heap (m, cols [MONO_TYPEDEF_NAME]);
1110 nspace = mono_metadata_string_heap (m, cols [MONO_TYPEDEF_NAMESPACE]);
1112 fprintf (output, ".namespace %s\n{\n", nspace);
1114 esname = get_escaped_name (name);
1115 if ((cols [MONO_TYPEDEF_FLAGS] & TYPE_ATTRIBUTE_CLASS_SEMANTIC_MASK) == TYPE_ATTRIBUTE_CLASS){
1116 fprintf (output, " .class %s%s", typedef_flags (cols [MONO_TYPEDEF_FLAGS]), esname);
1118 cnst_block = dis_generic_param_and_constraints (m, MONO_TYPEORMETHOD_TYPE, n+1);
1119 fprintf (output, "\n");
1120 if (cols [MONO_TYPEDEF_EXTENDS]) {
1121 char *base = get_typedef_or_ref (m, cols [MONO_TYPEDEF_EXTENDS]);
1122 fprintf (output, " \textends %s\n", base);
1126 fprintf (output, " .class interface %s%s", typedef_flags (cols [MONO_TYPEDEF_FLAGS]), esname);
1128 cnst_block = dis_generic_param_and_constraints (m, MONO_TYPEORMETHOD_TYPE, n+1);
1129 fprintf (output, "\n");
1133 dis_interfaces (m, n + 1);
1134 fprintf (output, " {\n");
1136 fprintf (output, "%s", cnst_block->str);
1137 g_string_free (cnst_block, TRUE);
1139 dump_cattrs (m, MONO_TOKEN_TYPE_DEF | (n + 1), " ");
1140 dump_declarative_security (m, OBJECT_TYPE_TYPEDEF, (n + 1), " ");
1142 if (mono_metadata_packing_from_typedef (m, n + 1, &packing_size, &class_size)) {
1143 fprintf (output, " .pack %d\n", packing_size);
1144 fprintf (output, " .size %d\n", class_size);
1147 * The value in the table is always valid, we know we have fields
1148 * if the value stored is different than the next record.
1152 last = cols_next [MONO_TYPEDEF_FIELD_LIST] - 1;
1154 last = m->tables [MONO_TABLE_FIELD].rows;
1156 if (cols [MONO_TYPEDEF_FIELD_LIST] && cols [MONO_TYPEDEF_FIELD_LIST] <= m->tables [MONO_TABLE_FIELD].rows)
1157 dis_field_list (m, cols [MONO_TYPEDEF_FIELD_LIST] - 1, last);
1158 fprintf (output, "\n");
1161 last = cols_next [MONO_TYPEDEF_METHOD_LIST] - 1;
1163 last = m->tables [MONO_TABLE_METHOD].rows;
1165 if (cols [MONO_TYPEDEF_METHOD_LIST] && cols [MONO_TYPEDEF_METHOD_LIST] <= m->tables [MONO_TABLE_METHOD].rows)
1166 dis_method_list (name, m, cols [MONO_TYPEDEF_METHOD_LIST] - 1, last);
1168 dis_property_list (m, n);
1169 dis_event_list (m, n);
1171 t = &m->tables [MONO_TABLE_NESTEDCLASS];
1172 nested = mono_metadata_nesting_typedef (m, n + 1, 1);
1174 dis_type (m, mono_metadata_decode_row_col (t, nested - 1, MONO_NESTED_CLASS_NESTED) - 1);
1175 nested = mono_metadata_nesting_typedef (m, n + 1, nested + 1);
1178 fprintf (output, " } // end of class %s%s%s\n", nspace, *nspace? ".": "", name);
1180 fprintf (output, "}\n");
1181 fprintf (output, "\n");
1187 * @m: metadata context
1189 * disassembles all the global fields and methods
1192 dis_globals (MonoImage *m)
1194 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEDEF];
1195 guint32 cols [MONO_TYPEDEF_SIZE];
1196 guint32 cols_next [MONO_TYPEDEF_SIZE];
1197 gboolean next_is_valid, last;
1200 name = g_strdup ("<Module>");
1202 mono_metadata_decode_row (t, 0, cols, MONO_TYPEDEF_SIZE);
1205 mono_metadata_decode_row (t, 1, cols_next, MONO_TYPEDEF_SIZE);
1211 * The value in the table is always valid, we know we have fields
1212 * if the value stored is different than the next record.
1216 last = cols_next [MONO_TYPEDEF_FIELD_LIST] - 1;
1218 last = m->tables [MONO_TABLE_FIELD].rows;
1220 if (cols [MONO_TYPEDEF_FIELD_LIST] && cols [MONO_TYPEDEF_FIELD_LIST] <= m->tables [MONO_TABLE_FIELD].rows)
1221 dis_field_list (m, cols [MONO_TYPEDEF_FIELD_LIST] - 1, last);
1222 fprintf (output, "\n");
1225 last = cols_next [MONO_TYPEDEF_METHOD_LIST] - 1;
1227 last = m->tables [MONO_TABLE_METHOD].rows;
1229 if (cols [MONO_TYPEDEF_METHOD_LIST] && cols [MONO_TYPEDEF_METHOD_LIST] <= m->tables [MONO_TABLE_METHOD].rows)
1230 dis_method_list (name, m, cols [MONO_TYPEDEF_METHOD_LIST] - 1, last);
1236 * @m: metadata context
1238 * disassembles all types in the @m context
1241 dis_types (MonoImage *m)
1243 MonoTableInfo *t = &m->tables [MONO_TABLE_TYPEDEF];
1249 for (i = 1; i < t->rows; i++) {
1250 flags = mono_metadata_decode_row_col (t, i, MONO_TYPEDEF_FLAGS);
1251 flags &= TYPE_ATTRIBUTE_VISIBILITY_MASK;
1252 if (flags == TYPE_ATTRIBUTE_PUBLIC || flags == TYPE_ATTRIBUTE_NOT_PUBLIC)
1259 * @m: metadata context
1261 * disassembles all data blobs references in the FieldRVA table in the @m context
1264 dis_data (MonoImage *m)
1266 MonoTableInfo *t = &m->tables [MONO_TABLE_FIELDRVA];
1267 MonoTableInfo *ft = &m->tables [MONO_TABLE_FIELD];
1269 const char *rva, *sig;
1270 guint32 align, size;
1271 guint32 cols [MONO_FIELD_RVA_SIZE];
1274 for (i = 0; i < t->rows; i++) {
1275 mono_metadata_decode_row (t, i, cols, MONO_FIELD_RVA_SIZE);
1276 rva = mono_image_rva_map (m, cols [MONO_FIELD_RVA_RVA]);
1277 sig = mono_metadata_blob_heap (m, mono_metadata_decode_row_col (ft, cols [MONO_FIELD_RVA_FIELD] -1, MONO_FIELD_SIGNATURE));
1278 mono_metadata_decode_value (sig, &sig);
1279 /* FIELD signature == 0x06 */
1280 g_assert (*sig == 0x06);
1281 type = mono_metadata_parse_field_type (m, 0, sig + 1, &sig);
1282 mono_class_init (mono_class_from_mono_type (type));
1283 size = mono_type_size (type, &align);
1284 fprintf (output, ".data D_%08x = bytearray (", cols [MONO_FIELD_RVA_RVA]);
1285 for (b = 0; b < size; ++b) {
1287 fprintf (output, "\n\t");
1288 fprintf (output, " %02X", rva [b] & 0xff);
1290 fprintf (output, ") // size: %d\n", size);
1297 void (*dumper) (MonoImage *m);
1299 { "--assembly", MONO_TABLE_ASSEMBLY, dump_table_assembly },
1300 { "--assemblyref", MONO_TABLE_ASSEMBLYREF, dump_table_assemblyref },
1301 { "--classlayout", MONO_TABLE_CLASSLAYOUT, dump_table_class_layout },
1302 { "--constant", MONO_TABLE_CONSTANT, dump_table_constant },
1303 { "--customattr", MONO_TABLE_CUSTOMATTRIBUTE, dump_table_customattr },
1304 { "--declsec", MONO_TABLE_DECLSECURITY, dump_table_declsec },
1305 { "--event", MONO_TABLE_EVENT, dump_table_event },
1306 { "--exported", MONO_TABLE_EXPORTEDTYPE, dump_table_exported },
1307 { "--fields", MONO_TABLE_FIELD, dump_table_field },
1308 { "--file", MONO_TABLE_FILE, dump_table_file },
1309 { "--genericpar", MONO_TABLE_GENERICPARAM, dump_table_genericpar },
1310 { "--interface", MONO_TABLE_INTERFACEIMPL, dump_table_interfaceimpl },
1311 { "--manifest", MONO_TABLE_MANIFESTRESOURCE, dump_table_manifest },
1312 { "--marshal", MONO_TABLE_FIELDMARSHAL, dump_table_field_marshal },
1313 { "--memberref", MONO_TABLE_MEMBERREF, dump_table_memberref },
1314 { "--method", MONO_TABLE_METHOD, dump_table_method },
1315 { "--methodimpl", MONO_TABLE_METHODIMPL, dump_table_methodimpl },
1316 { "--methodsem", MONO_TABLE_METHODSEMANTICS, dump_table_methodsem },
1317 { "--methodspec", MONO_TABLE_METHODSPEC, dump_table_methodspec },
1318 { "--moduleref", MONO_TABLE_MODULEREF, dump_table_moduleref },
1319 { "--module", MONO_TABLE_MODULE, dump_table_module },
1320 { "--nested", MONO_TABLE_NESTEDCLASS, dump_table_nestedclass },
1321 { "--param", MONO_TABLE_PARAM, dump_table_param },
1322 { "--parconst", MONO_TABLE_GENERICPARAMCONSTRAINT, dump_table_parconstraint },
1323 { "--property", MONO_TABLE_PROPERTY, dump_table_property },
1324 { "--propertymap", MONO_TABLE_PROPERTYMAP, dump_table_property_map },
1325 { "--typedef", MONO_TABLE_TYPEDEF, dump_table_typedef },
1326 { "--typeref", MONO_TABLE_TYPEREF, dump_table_typeref },
1327 { "--typespec", MONO_TABLE_TYPESPEC, dump_table_typespec },
1328 { "--implmap", MONO_TABLE_IMPLMAP, dump_table_implmap },
1329 { "--standalonesig", MONO_TABLE_STANDALONESIG, dump_table_standalonesig },
1330 { "--blob", 0, dump_stream_blob },
1336 * @file: file containing CIL code.
1338 * Disassembles the @file file.
1341 disassemble_file (const char *file)
1344 MonoImageOpenStatus status;
1347 ass = mono_assembly_open (file, &status);
1349 fprintf (stderr, "Error while trying to process %s\n", file);
1355 if (dump_table != -1){
1356 (*table_list [dump_table].dumper) (img);
1358 dump_header_data (img);
1360 dis_directive_assemblyref (img);
1361 dis_directive_assembly (img);
1362 dis_directive_file (img);
1363 dis_directive_module (img);
1364 dis_directive_moduleref (img);
1369 mono_image_close (img);
1375 GString *args = g_string_new ("[--output=filename] [--help] [--mscorlib]\n");
1378 for (i = 0; table_list [i].name != NULL; i++){
1379 g_string_append (args, "[");
1380 g_string_append (args, table_list [i].name);
1381 g_string_append (args, "] ");
1382 if (((i-2) % 5) == 0)
1383 g_string_append_c (args, '\n');
1386 "Usage is: monodis %s file ..\n", args->str);
1391 main (int argc, char *argv [])
1393 GList *input_files = NULL, *l;
1398 for (i = 1; i < argc; i++){
1399 if (argv [i][0] == '-'){
1400 if (argv [i][1] == 'h')
1402 else if (argv [i][1] == 'd')
1403 dump_header_data_p = TRUE;
1404 else if (strcmp (argv [i], "--mscorlib") == 0) {
1405 substitute_with_mscorlib_p = TRUE;
1407 } else if (strcmp (argv [i], "--show-method-tokens") == 0) {
1408 show_method_tokens = TRUE;
1410 } else if (strcmp (argv [i], "--show-tokens") == 0) {
1413 } else if (strncmp (argv [i], "--output=", 9) == 0) {
1414 output = fopen (argv [i]+9, "w");
1415 if (output == NULL) {
1416 fprintf (stderr, "Can't open output file `%s': %s\n",
1417 argv [i]+9, strerror (errno));
1421 } else if (strcmp (argv [i], "--help") == 0)
1423 for (j = 0; table_list [j].name != NULL; j++) {
1424 if (strcmp (argv [i], table_list [j].name) == 0)
1430 input_files = g_list_append (input_files, argv [i]);
1433 if (input_files == NULL)
1437 * If we just have one file, use the corlib version it requires.
1439 if (!input_files->next) {
1440 char *filename = input_files->data;
1442 mono_init_from_assembly (argv [0], filename);
1443 disassemble_file (filename);
1445 mono_init (argv [0]);
1447 for (l = input_files; l; l = l->next)
1448 disassemble_file (l->data);