[mono-api-html] Add filter for new namespaces/types
[mono-project.git] / mono / metadata / pedump.c
blob496c3c7f5ff9e66909157c08f3c7dd0a5c381ce6
1 /*
2 * pedump.c: Dumps the contents of an extended PE/COFF file
4 * Author:
5 * Miguel de Icaza (miguel@ximian.com)
7 * Copyright 2001-2003 Ximian, Inc (http://www.ximian.com)
8 * Copyright 2004-2009 Novell, Inc (http://www.novell.com)
9 */
10 #include <config.h>
11 #include <stdio.h>
12 #include <stdlib.h>
13 #include <string.h>
14 #include "image.h"
15 #include <glib.h>
16 #include "cil-coff.h"
17 #include "mono-endian.h"
18 #include "verify.h"
19 #include <mono/metadata/class.h>
20 #include <mono/metadata/debug-helpers.h>
21 #include <mono/metadata/tokentype.h>
22 #include <mono/metadata/appdomain.h>
23 #include <mono/metadata/assembly.h>
24 #include <mono/metadata/metadata-internals.h>
25 #include <mono/metadata/class-internals.h>
26 #include <mono/metadata/verify-internals.h>
27 #include <mono/metadata/marshal.h>
28 #include "mono/utils/mono-digest.h"
29 #include <mono/utils/mono-mmap.h>
30 #include <sys/types.h>
31 #include <sys/stat.h>
32 #ifdef HAVE_UNISTD_H
33 #include <unistd.h>
34 #endif
36 gboolean dump_data = TRUE;
37 gboolean verify_pe = FALSE;
38 gboolean verify_metadata = FALSE;
39 gboolean verify_code = FALSE;
40 gboolean verify_partial_md = FALSE;
42 static MonoAssembly *pedump_preload (MonoAssemblyName *aname, gchar **assemblies_path, gpointer user_data);
43 static void pedump_assembly_load_hook (MonoAssembly *assembly, gpointer user_data);
44 static MonoAssembly *pedump_assembly_search_hook (MonoAssemblyName *aname, gpointer user_data);
46 /* unused
47 static void
48 hex_dump (const char *buffer, int base, int count)
50 int i;
52 for (i = 0; i < count; i++){
53 if ((i % 16) == 0)
54 printf ("\n0x%08x: ", (unsigned char) base + i);
56 printf ("%02x ", (unsigned char) (buffer [i]));
61 static void
62 hex8 (const char *label, unsigned char x)
64 printf ("\t%s: 0x%02x\n", label, (unsigned char) x);
67 static void
68 hex16 (const char *label, guint16 x)
70 printf ("\t%s: 0x%04x\n", label, x);
73 static void
74 hex32 (const char *label, guint32 x)
76 printf ("\t%s: 0x%08x\n", label, x);
79 static void
80 dump_coff_header (MonoCOFFHeader *coff)
82 printf ("\nCOFF Header:\n");
83 hex16 (" Machine", coff->coff_machine);
84 hex16 (" Sections", coff->coff_sections);
85 hex32 (" Time stamp", coff->coff_time);
86 hex32 ("Pointer to Symbol Table", coff->coff_symptr);
87 hex32 (" Symbol Count", coff->coff_symcount);
88 hex16 (" Optional Header Size", coff->coff_opt_header_size);
89 hex16 (" Characteristics", coff->coff_attributes);
93 static void
94 dump_pe_header (MonoPEHeader *pe)
96 printf ("\nPE Header:\n");
97 hex16 (" Magic (0x010b)", pe->pe_magic);
98 hex8 (" LMajor (6)", pe->pe_major);
99 hex8 (" LMinor (0)", pe->pe_minor);
100 hex32 (" Code Size", pe->pe_code_size);
101 hex32 (" Initialized Data Size", pe->pe_data_size);
102 hex32 ("Uninitialized Data Size", pe->pe_uninit_data_size);
103 hex32 (" Entry Point RVA", pe->pe_rva_entry_point);
104 hex32 (" Code Base RVA", pe->pe_rva_code_base);
105 hex32 (" Data Base RVA", pe->pe_rva_data_base);
106 printf ("\n");
109 static void
110 dump_nt_header (MonoPEHeaderNT *nt)
112 printf ("\nNT Header:\n");
114 hex32 (" Image Base (0x400000)", nt->pe_image_base);
115 hex32 ("Section Alignment (8192)", nt->pe_section_align);
116 hex32 (" File Align (512/4096)", nt->pe_file_alignment);
117 hex16 (" OS Major (4)", nt->pe_os_major);
118 hex16 (" OS Minor (0)", nt->pe_os_minor);
119 hex16 (" User Major (0)", nt->pe_user_major);
120 hex16 (" User Minor (0)", nt->pe_user_minor);
121 hex16 (" Subsys major (4)", nt->pe_subsys_major);
122 hex16 (" Subsys minor (0)", nt->pe_subsys_minor);
123 hex32 (" Reserverd", nt->pe_reserved_1);
124 hex32 (" Image Size", nt->pe_image_size);
125 hex32 (" Header Size", nt->pe_header_size);
126 hex32 (" Checksum (0)", nt->pe_checksum);
127 hex16 (" Subsystem", nt->pe_subsys_required);
128 hex16 (" DLL Flags (0)", nt->pe_dll_flags);
129 hex32 (" Stack Reserve Size (1M)", nt->pe_stack_reserve);
130 hex32 ("Stack commit Size (4096)", nt->pe_stack_commit);
131 hex32 (" Heap Reserve Size (1M)", nt->pe_heap_reserve);
132 hex32 (" Heap Commit Size (4096)", nt->pe_heap_commit);
133 hex32 (" Loader flags (0x1)", nt->pe_loader_flags);
134 hex32 (" Data Directories (16)", nt->pe_data_dir_count);
137 static void
138 dent (const char *label, MonoPEDirEntry de)
140 printf ("\t%s: 0x%08x [0x%08x]\n", label, de.rva, de.size);
143 static void
144 dump_blob (const char *desc, const char* p, guint32 size)
146 int i;
148 printf ("%s", desc);
149 if (!p) {
150 printf (" none\n");
151 return;
154 for (i = 0; i < size; ++i) {
155 if (!(i % 16))
156 printf ("\n\t");
157 printf (" %02X", p [i] & 0xFF);
159 printf ("\n");
162 static void
163 dump_public_key (MonoImage *m)
165 guint32 size;
166 const char *p;
168 p = mono_image_get_public_key (m, &size);
169 dump_blob ("\nPublic key:", p, size);
172 static void
173 dump_strong_name (MonoImage *m)
175 guint32 size;
176 const char *p;
178 p = mono_image_get_strong_name (m, &size);
179 dump_blob ("\nStrong name:", p, size);
182 static void
183 dump_datadir (MonoPEDatadir *dd)
185 printf ("\nData directories:\n");
186 dent (" Export Table", dd->pe_export_table);
187 dent (" Import Table", dd->pe_import_table);
188 dent (" Resource Table", dd->pe_resource_table);
189 dent (" Exception Table", dd->pe_exception_table);
190 dent ("Certificate Table", dd->pe_certificate_table);
191 dent (" Reloc Table", dd->pe_reloc_table);
192 dent (" Debug", dd->pe_debug);
193 dent (" Copyright", dd->pe_copyright);
194 dent (" Global Ptr", dd->pe_global_ptr);
195 dent (" TLS Table", dd->pe_tls_table);
196 dent ("Load Config Table", dd->pe_load_config_table);
197 dent (" Bound Import", dd->pe_bound_import);
198 dent (" IAT", dd->pe_iat);
199 dent ("Delay Import Desc", dd->pe_delay_import_desc);
200 dent (" CLI Header", dd->pe_cli_header);
203 static void
204 dump_dotnet_header (MonoDotNetHeader *header)
206 dump_coff_header (&header->coff);
207 dump_pe_header (&header->pe);
208 dump_nt_header (&header->nt);
209 dump_datadir (&header->datadir);
212 static void
213 dump_section_table (MonoSectionTable *st)
215 guint32 flags = st->st_flags;
217 printf ("\n\tName: %s\n", st->st_name);
218 hex32 (" Virtual Size", st->st_virtual_size);
219 hex32 ("Virtual Address", st->st_virtual_address);
220 hex32 (" Raw Data Size", st->st_raw_data_size);
221 hex32 (" Raw Data Ptr", st->st_raw_data_ptr);
222 hex32 (" Reloc Ptr", st->st_reloc_ptr);
223 hex32 (" LineNo Ptr", st->st_lineno_ptr);
224 hex16 (" Reloc Count", st->st_reloc_count);
225 hex16 (" Line Count", st->st_line_count);
227 printf ("\tFlags: %s%s%s%s%s%s%s%s%s%s\n",
228 (flags & SECT_FLAGS_HAS_CODE) ? "code, " : "",
229 (flags & SECT_FLAGS_HAS_INITIALIZED_DATA) ? "data, " : "",
230 (flags & SECT_FLAGS_HAS_UNINITIALIZED_DATA) ? "bss, " : "",
231 (flags & SECT_FLAGS_MEM_DISCARDABLE) ? "discard, " : "",
232 (flags & SECT_FLAGS_MEM_NOT_CACHED) ? "nocache, " : "",
233 (flags & SECT_FLAGS_MEM_NOT_PAGED) ? "nopage, " : "",
234 (flags & SECT_FLAGS_MEM_SHARED) ? "shared, " : "",
235 (flags & SECT_FLAGS_MEM_EXECUTE) ? "exec, " : "",
236 (flags & SECT_FLAGS_MEM_READ) ? "read, " : "",
237 (flags & SECT_FLAGS_MEM_WRITE) ? "write" : "");
240 static void
241 dump_sections (MonoCLIImageInfo *iinfo)
243 const int top = iinfo->cli_header.coff.coff_sections;
244 int i;
246 for (i = 0; i < top; i++)
247 dump_section_table (&iinfo->cli_section_tables [i]);
250 static void
251 dump_cli_header (MonoCLIHeader *ch)
253 printf ("\n");
254 printf (" CLI header size: %d\n", ch->ch_size);
255 printf (" Runtime required: %d.%d\n", ch->ch_runtime_major, ch->ch_runtime_minor);
256 printf (" Flags: %s, %s, %s, %s\n",
257 (ch->ch_flags & CLI_FLAGS_ILONLY ? "ilonly" : "contains native"),
258 (ch->ch_flags & CLI_FLAGS_32BITREQUIRED ? "32bits" : "32/64"),
259 (ch->ch_flags & CLI_FLAGS_TRACKDEBUGDATA ? "trackdebug" : "no-trackdebug"),
260 (ch->ch_flags & CLI_FLAGS_STRONGNAMESIGNED ? "strongnamesigned" : "notsigned"));
261 dent (" Metadata", ch->ch_metadata);
262 hex32 ("Entry Point Token", ch->ch_entry_point);
263 dent (" Resources at", ch->ch_resources);
264 dent (" Strong Name at", ch->ch_strong_name);
265 dent (" Code Manager at", ch->ch_code_manager_table);
266 dent (" VTableFixups at", ch->ch_vtable_fixups);
267 dent (" EAT jumps at", ch->ch_export_address_table_jumps);
270 static void
271 dsh (const char *label, MonoImage *meta, MonoStreamHeader *sh)
273 printf ("%s: 0x%08x - 0x%08x [%d == 0x%08x]\n",
274 label,
275 (int)(sh->data - meta->raw_metadata), (int)(sh->data + sh->size - meta->raw_metadata),
276 sh->size, sh->size);
279 static void
280 dump_metadata_header (MonoImage *meta)
282 printf ("\nMetadata header:\n");
283 printf (" Version: %d.%d\n", meta->md_version_major, meta->md_version_minor);
284 printf (" Version string: %s\n", meta->version);
287 static void
288 dump_metadata_ptrs (MonoImage *meta)
290 printf ("\nMetadata pointers:\n");
291 dsh ("\tTables (#~)", meta, &meta->heap_tables);
292 dsh ("\t Strings", meta, &meta->heap_strings);
293 dsh ("\t Blob", meta, &meta->heap_blob);
294 dsh ("\tUser string", meta, &meta->heap_us);
295 dsh ("\t GUID", meta, &meta->heap_guid);
298 static void
299 dump_metadata (MonoImage *meta)
301 int table;
303 dump_metadata_header (meta);
305 dump_metadata_ptrs (meta);
307 printf ("Rows:\n");
308 for (table = 0; table < MONO_TABLE_NUM; table++){
309 if (meta->tables [table].rows == 0)
310 continue;
311 printf ("Table %s: %d records (%d bytes, at %x)\n",
312 mono_meta_table_name (table),
313 meta->tables [table].rows,
314 meta->tables [table].row_size,
315 (unsigned int)(meta->tables [table].base - meta->raw_data)
320 static void
321 dump_methoddef (MonoImage *metadata, guint32 token)
323 const char *loc;
325 if (!token)
326 return;
327 loc = mono_metadata_locate_token (metadata, token);
329 printf ("RVA for Entry Point: 0x%08x\n", read32 (loc));
332 static void
333 dump_dotnet_iinfo (MonoImage *image)
335 MonoCLIImageInfo *iinfo = image->image_info;
337 dump_dotnet_header (&iinfo->cli_header);
338 dump_sections (iinfo);
339 dump_cli_header (&iinfo->cli_cli_header);
340 dump_strong_name (image);
341 dump_public_key (image);
342 dump_metadata (image);
344 dump_methoddef (image, iinfo->cli_cli_header.ch_entry_point);
347 static int
348 dump_verify_info (MonoImage *image, int flags)
350 GSList *errors, *tmp;
351 int count = 0, verifiable = 0;
352 const char* desc [] = {
353 "Ok", "Error", "Warning", NULL, "CLS", NULL, NULL, NULL, "Not Verifiable"
356 if (verify_code) { /* verify code */
357 int i;
358 MonoTableInfo *m = &image->tables [MONO_TABLE_METHOD];
360 for (i = 0; i < m->rows; ++i) {
361 MonoMethod *method;
362 mono_loader_clear_error ();
364 method = mono_get_method (image, MONO_TOKEN_METHOD_DEF | (i+1), NULL);
365 if (!method) {
366 g_print ("Warning: Cannot lookup method with token 0x%08x\n", i + 1);
367 continue;
369 errors = mono_method_verify (method, flags);
370 if (errors) {
371 MonoClass *klass = mono_method_get_class (method);
372 char *name = mono_type_full_name (&klass->byval_arg);
373 if (mono_method_signature (method) == NULL) {
374 g_print ("In method: %s::%s(ERROR)\n", name, mono_method_get_name (method));
375 } else {
376 char *sig;
377 sig = mono_signature_get_desc (mono_method_signature (method), FALSE);
378 g_print ("In method: %s::%s(%s)\n", name, mono_method_get_name (method), sig);
379 g_free (sig);
381 g_free (name);
384 for (tmp = errors; tmp; tmp = tmp->next) {
385 MonoVerifyInfo *info = tmp->data;
386 g_print ("%s: %s\n", desc [info->status], info->message);
387 if (info->status == MONO_VERIFY_ERROR) {
388 count++;
389 verifiable = 3;
391 if(info->status == MONO_VERIFY_NOT_VERIFIABLE) {
392 if (verifiable < 2)
393 verifiable = 2;
396 mono_free_verify_list (errors);
400 if (count)
401 g_print ("Error count: %d\n", count);
402 return verifiable;
405 static void
406 usage (void)
408 printf ("Usage is: pedump [--verify error,warn,cls,all,code,fail-on-verifiable,non-strict,valid-only,metadata] file.exe\n");
409 exit (1);
412 static int
413 verify_image_file (const char *fname)
415 GSList *errors = NULL, *tmp;
416 MonoImage *image;
417 MonoTableInfo *table;
418 MonoAssembly *assembly;
419 MonoImageOpenStatus status;
420 int i, count = 0;
421 const char* desc [] = {
422 "Ok", "Error", "Warning", NULL, "CLS", NULL, NULL, NULL, "Not Verifiable"
425 image = mono_image_open_raw (fname, &status);
426 if (!image) {
427 printf ("Could not open %s\n", fname);
428 return 1;
431 if (!mono_verifier_verify_pe_data (image, &errors))
432 goto invalid_image;
434 if (!mono_image_load_pe_data (image)) {
435 printf ("Could not load pe data for assembly %s\n", fname);
436 return 1;
439 if (!mono_verifier_verify_cli_data (image, &errors))
440 goto invalid_image;
442 if (!mono_image_load_cli_data (image)) {
443 printf ("Could not load cli data for assembly %s\n", fname);
444 return 1;
447 if (!mono_verifier_verify_table_data (image, &errors))
448 goto invalid_image;
450 mono_image_load_names (image);
452 /*fake an assembly for class loading to work*/
453 assembly = g_new0 (MonoAssembly, 1);
454 assembly->in_gac = FALSE;
455 assembly->image = image;
456 image->assembly = assembly;
457 mono_assembly_fill_assembly_name (image, &assembly->aname);
459 /*Finish initializing the runtime*/
460 mono_install_assembly_load_hook (pedump_assembly_load_hook, NULL);
461 mono_install_assembly_search_hook (pedump_assembly_search_hook, NULL);
463 mono_init_version ("pedump", image->version);
465 mono_install_assembly_preload_hook (pedump_preload, GUINT_TO_POINTER (FALSE));
467 mono_marshal_init ();
470 if (!verify_partial_md && !mono_verifier_verify_full_table_data (image, &errors))
471 goto invalid_image;
474 table = &image->tables [MONO_TABLE_TYPEDEF];
475 for (i = 1; i <= table->rows; ++i) {
476 guint32 token = i | MONO_TOKEN_TYPE_DEF;
477 MonoClass *class = mono_class_get (image, token);
478 if (!class) {
479 printf ("Could not load class with token %x\n", token);
480 continue;
482 mono_class_init (class);
483 if (class->exception_type != MONO_EXCEPTION_NONE || mono_loader_get_last_error ()) {
484 printf ("Error verifying class(0x%08x) %s.%s a type load error happened\n", token, class->name_space, class->name);
485 mono_loader_clear_error ();
486 ++count;
489 mono_class_setup_vtable (class);
490 if (class->exception_type != MONO_EXCEPTION_NONE || mono_loader_get_last_error ()) {
491 printf ("Error verifying class(0x%08x) %s.%s a type load error happened\n", token, class->name_space, class->name);
492 mono_loader_clear_error ();
493 ++count;
496 if (count)
497 return 5;
498 return 0;
500 invalid_image:
501 for (tmp = errors; tmp; tmp = tmp->next) {
502 MonoVerifyInfo *info = tmp->data;
503 g_print ("%s: %s\n", desc [info->status], info->message);
504 if (info->status == MONO_VERIFY_ERROR)
505 count++;
507 mono_free_verify_list (errors);
508 if (count)
509 g_print ("Error count: %d\n", count);
510 return 1;
513 static gboolean
514 try_load_from (MonoAssembly **assembly, const gchar *path1, const gchar *path2,
515 const gchar *path3, const gchar *path4, gboolean refonly)
517 gchar *fullpath;
519 *assembly = NULL;
520 fullpath = g_build_filename (path1, path2, path3, path4, NULL);
521 if (g_file_test (fullpath, G_FILE_TEST_IS_REGULAR))
522 *assembly = mono_assembly_open_full (fullpath, NULL, refonly);
524 g_free (fullpath);
525 return (*assembly != NULL);
528 static MonoAssembly *
529 real_load (gchar **search_path, const gchar *culture, const gchar *name, gboolean refonly)
531 MonoAssembly *result = NULL;
532 gchar **path;
533 gchar *filename;
534 const gchar *local_culture;
535 gint len;
537 if (!culture || *culture == '\0') {
538 local_culture = "";
539 } else {
540 local_culture = culture;
543 filename = g_strconcat (name, ".dll", NULL);
544 len = strlen (filename);
546 for (path = search_path; *path; path++) {
547 if (**path == '\0')
548 continue; /* Ignore empty ApplicationBase */
550 /* See test cases in bug #58992 and bug #57710 */
551 /* 1st try: [culture]/[name].dll (culture may be empty) */
552 strcpy (filename + len - 4, ".dll");
553 if (try_load_from (&result, *path, local_culture, "", filename, refonly))
554 break;
556 /* 2nd try: [culture]/[name].exe (culture may be empty) */
557 strcpy (filename + len - 4, ".exe");
558 if (try_load_from (&result, *path, local_culture, "", filename, refonly))
559 break;
561 /* 3rd try: [culture]/[name]/[name].dll (culture may be empty) */
562 strcpy (filename + len - 4, ".dll");
563 if (try_load_from (&result, *path, local_culture, name, filename, refonly))
564 break;
566 /* 4th try: [culture]/[name]/[name].exe (culture may be empty) */
567 strcpy (filename + len - 4, ".exe");
568 if (try_load_from (&result, *path, local_culture, name, filename, refonly))
569 break;
572 g_free (filename);
573 return result;
577 * Try to load referenced assemblies from assemblies_path.
579 static MonoAssembly *
580 pedump_preload (MonoAssemblyName *aname,
581 gchar **assemblies_path,
582 gpointer user_data)
584 MonoAssembly *result = NULL;
585 gboolean refonly = GPOINTER_TO_UINT (user_data);
587 if (assemblies_path && assemblies_path [0] != NULL) {
588 result = real_load (assemblies_path, aname->culture, aname->name, refonly);
591 return result;
594 static GList *loaded_assemblies = NULL;
596 static void
597 pedump_assembly_load_hook (MonoAssembly *assembly, gpointer user_data)
599 loaded_assemblies = g_list_prepend (loaded_assemblies, assembly);
602 static MonoAssembly *
603 pedump_assembly_search_hook (MonoAssemblyName *aname, gpointer user_data)
605 GList *tmp;
607 for (tmp = loaded_assemblies; tmp; tmp = tmp->next) {
608 MonoAssembly *ass = tmp->data;
609 if (mono_assembly_names_equal (aname, &ass->aname))
610 return ass;
612 return NULL;
615 #define VALID_ONLY_FLAG 0x08000000
616 #define VERIFY_CODE_ONLY MONO_VERIFY_ALL + 1
617 #define VERIFY_METADATA_ONLY VERIFY_CODE_ONLY + 1
618 #define VERIFY_PARTIAL_METADATA VERIFY_CODE_ONLY + 2
621 main (int argc, char *argv [])
623 int image_result = 0;
624 MonoImage *image;
625 char *file = NULL;
626 char *flags = NULL;
627 MiniVerifierMode verifier_mode = MONO_VERIFIER_MODE_VERIFIABLE;
628 const char *flag_desc [] = {"error", "warn", "cls", "all", "code", "fail-on-verifiable", "non-strict", "valid-only", "metadata", "partial-md", NULL};
629 guint flag_vals [] = {MONO_VERIFY_ERROR, MONO_VERIFY_WARNING, MONO_VERIFY_CLS, MONO_VERIFY_ALL, VERIFY_CODE_ONLY, MONO_VERIFY_FAIL_FAST, MONO_VERIFY_NON_STRICT, VALID_ONLY_FLAG, VERIFY_METADATA_ONLY, VERIFY_PARTIAL_METADATA, 0};
630 int i, verify_flags = MONO_VERIFY_REPORT_ALL_ERRORS, run_new_metadata_verifier = 0;
632 for (i = 1; i < argc; i++){
633 if (argv [i][0] != '-'){
634 file = argv [i];
635 continue;
638 if (strcmp (argv [i], "--help") == 0)
639 usage ();
640 else if (strcmp (argv [i], "--verify") == 0) {
641 verify_pe = 1;
642 dump_data = 0;
643 ++i;
644 flags = argv [i];
645 } else {
646 usage ();
650 if (!file)
651 usage ();
653 #ifndef DISABLE_PERFCOUNTERS
654 mono_perfcounters_init ();
655 #endif
656 mono_metadata_init ();
657 mono_images_init ();
658 mono_assemblies_init ();
659 mono_loader_init ();
661 if (verify_pe) {
662 char *tok = strtok (flags, ",");
664 verify_metadata = 1;
665 verify_code = 0;
666 while (tok) {
667 for (i = 0; flag_desc [i]; ++i) {
668 if (strcmp (tok, flag_desc [i]) == 0) {
669 if (flag_vals [i] == VERIFY_CODE_ONLY) {
670 verify_metadata = 0;
671 verify_code = 1;
672 } else if(flag_vals [i] == MONO_VERIFY_ALL) {
673 verify_code = 1;
674 } else if(flag_vals [i] == VERIFY_METADATA_ONLY) {
675 verify_metadata = 0;
676 run_new_metadata_verifier = 1;
677 } else if(flag_vals [i] == VERIFY_PARTIAL_METADATA) {
678 verify_partial_md = 1;
680 if (flag_vals [i] == VALID_ONLY_FLAG)
681 verifier_mode = MONO_VERIFIER_MODE_VALID;
682 else
683 verify_flags |= flag_vals [i];
684 break;
687 if (!flag_desc [i])
688 g_print ("Unknown verify flag %s\n", tok);
689 tok = strtok (NULL, ",");
692 mono_verifier_set_mode (verifier_mode);
693 /**/
696 if (verify_pe || run_new_metadata_verifier) {
697 run_new_metadata_verifier = 1;
700 if (run_new_metadata_verifier) {
701 mono_verifier_set_mode (verifier_mode);
703 image_result = verify_image_file (file);
704 if (image_result == 1 || !verify_code)
705 return image_result;
708 image = mono_image_open (file, NULL);
709 if (!image){
710 fprintf (stderr, "Cannot open image %s\n", file);
711 exit (1);
714 if (dump_data)
715 dump_dotnet_iinfo (image);
716 if (verify_pe) {
717 MonoAssembly *assembly;
718 MonoImage *image;
719 MonoImageOpenStatus status;
720 int code_result;
722 mono_verifier_set_mode (verifier_mode);
724 assembly = mono_assembly_open (file, NULL);
725 /*fake an assembly for netmodules so the verifier works*/
726 if (!assembly && (image = mono_image_open (file, &status)) && image->tables [MONO_TABLE_ASSEMBLY].rows == 0) {
727 assembly = g_new0 (MonoAssembly, 1);
728 assembly->in_gac = FALSE;
729 assembly->image = image;
730 image->assembly = assembly;
733 if (!assembly) {
734 g_print ("Could not open assembly %s\n", file);
735 return 4;
738 code_result = dump_verify_info (assembly->image, verify_flags);
739 return code_result ? code_result : image_result;
740 } else
741 mono_image_close (image);
743 return 0;