2009-02-11 Bill Holmes <billholmes54@gmail.com>
[mono.git] / mono / metadata / pedump.c
1 /*
2  * pedump.c: Dumps the contents of an extended PE/COFF file
3  *
4  * Author:
5  *   Miguel de Icaza (miguel@ximian.com)
6  *
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/utils/mono-digest.h"
28 #include <mono/utils/mono-mmap.h>
29 #include <sys/types.h>
30 #include <sys/stat.h>
31 #ifdef HAVE_UNISTD_H
32 #include <unistd.h>
33 #endif
34
35 gboolean dump_data = TRUE;
36 gboolean verify_pe = FALSE;
37 gboolean verify_metadata = FALSE;
38 gboolean verify_code = FALSE;
39
40 /* unused
41 static void
42 hex_dump (const char *buffer, int base, int count)
43 {
44         int i;
45         
46         for (i = 0; i < count; i++){
47                 if ((i % 16) == 0)
48                         printf ("\n0x%08x: ", (unsigned char) base + i);
49
50                 printf ("%02x ", (unsigned char) (buffer [i]));
51         }
52 }
53 */
54
55 static void
56 hex8 (const char *label, unsigned char x)
57 {
58         printf ("\t%s: 0x%02x\n", label, (unsigned char) x);
59 }
60
61 static void
62 hex16 (const char *label, guint16 x)
63 {
64         printf ("\t%s: 0x%04x\n", label, x);
65 }
66
67 static void
68 hex32 (const char *label, guint32 x)
69 {
70         printf ("\t%s: 0x%08x\n", label, x);
71 }
72
73 static void
74 dump_coff_header (MonoCOFFHeader *coff)
75 {
76         printf ("\nCOFF Header:\n");
77         hex16 ("                Machine", coff->coff_machine);
78         hex16 ("               Sections", coff->coff_sections);
79         hex32 ("             Time stamp", coff->coff_time);
80         hex32 ("Pointer to Symbol Table", coff->coff_symptr);
81         hex32 ("           Symbol Count", coff->coff_symcount);
82         hex16 ("   Optional Header Size", coff->coff_opt_header_size);
83         hex16 ("        Characteristics", coff->coff_attributes);
84
85 }
86
87 static void
88 dump_pe_header (MonoPEHeader *pe)
89 {
90         printf ("\nPE Header:\n");
91         hex16 ("         Magic (0x010b)", pe->pe_magic);
92         hex8  ("             LMajor (6)", pe->pe_major);
93         hex8  ("             LMinor (0)", pe->pe_minor);
94         hex32 ("              Code Size", pe->pe_code_size);
95         hex32 ("  Initialized Data Size", pe->pe_data_size);
96         hex32 ("Uninitialized Data Size", pe->pe_uninit_data_size);
97         hex32 ("        Entry Point RVA", pe->pe_rva_entry_point);
98         hex32 ("          Code Base RVA", pe->pe_rva_code_base);
99         hex32 ("          Data Base RVA", pe->pe_rva_data_base);
100         printf ("\n");
101 }
102
103 static void
104 dump_nt_header (MonoPEHeaderNT *nt)
105 {
106         printf ("\nNT Header:\n");
107
108         hex32 ("   Image Base (0x400000)", nt->pe_image_base);
109         hex32 ("Section Alignment (8192)", nt->pe_section_align);
110         hex32 ("   File Align (512/4096)", nt->pe_file_alignment);
111         hex16 ("            OS Major (4)", nt->pe_os_major);
112         hex16 ("            OS Minor (0)", nt->pe_os_minor);
113         hex16 ("          User Major (0)", nt->pe_user_major);
114         hex16 ("          User Minor (0)", nt->pe_user_minor);
115         hex16 ("        Subsys major (4)", nt->pe_subsys_major);
116         hex16 ("        Subsys minor (0)", nt->pe_subsys_minor);
117         hex32 ("               Reserverd", nt->pe_reserved_1);
118         hex32 ("              Image Size", nt->pe_image_size);
119         hex32 ("             Header Size", nt->pe_header_size);
120         hex32 ("            Checksum (0)", nt->pe_checksum);
121         hex16 ("               Subsystem", nt->pe_subsys_required);
122         hex16 ("           DLL Flags (0)", nt->pe_dll_flags);
123         hex32 (" Stack Reserve Size (1M)", nt->pe_stack_reserve);
124         hex32 ("Stack commit Size (4096)", nt->pe_stack_commit);
125         hex32 ("  Heap Reserve Size (1M)", nt->pe_heap_reserve);
126         hex32 (" Heap Commit Size (4096)", nt->pe_heap_commit);
127         hex32 ("      Loader flags (0x1)", nt->pe_loader_flags);
128         hex32 ("   Data Directories (16)", nt->pe_data_dir_count);
129 }
130
131 static void
132 dent (const char *label, MonoPEDirEntry de)
133 {
134         printf ("\t%s: 0x%08x [0x%08x]\n", label, de.rva, de.size);
135 }
136
137 static void
138 dump_blob (const char *desc, const char* p, guint32 size)
139 {
140         int i;
141
142         printf ("%s", desc);
143         if (!p) {
144                 printf (" none\n");
145                 return;
146         }
147
148         for (i = 0; i < size; ++i) {
149                 if (!(i % 16))
150                         printf ("\n\t");
151                 printf (" %02X", p [i] & 0xFF);
152         }
153         printf ("\n");
154 }
155
156 static void
157 dump_public_key (MonoImage *m)
158 {
159         guint32 size;
160         const char *p;
161
162         p = mono_image_get_public_key (m, &size);
163         dump_blob ("\nPublic key:", p, size);
164 }
165
166 static void
167 dump_strong_name (MonoImage *m)
168 {
169         guint32 size;
170         const char *p;
171
172         p = mono_image_get_strong_name (m, &size);
173         dump_blob ("\nStrong name:", p, size);
174 }
175
176 static void
177 dump_datadir (MonoPEDatadir *dd)
178 {
179         printf ("\nData directories:\n");
180         dent ("     Export Table", dd->pe_export_table);
181         dent ("     Import Table", dd->pe_import_table);
182         dent ("   Resource Table", dd->pe_resource_table);
183         dent ("  Exception Table", dd->pe_exception_table);
184         dent ("Certificate Table", dd->pe_certificate_table);
185         dent ("      Reloc Table", dd->pe_reloc_table);
186         dent ("            Debug", dd->pe_debug);
187         dent ("        Copyright", dd->pe_copyright);
188         dent ("       Global Ptr", dd->pe_global_ptr);
189         dent ("        TLS Table", dd->pe_tls_table);
190         dent ("Load Config Table", dd->pe_load_config_table);
191         dent ("     Bound Import", dd->pe_bound_import);
192         dent ("              IAT", dd->pe_iat);
193         dent ("Delay Import Desc", dd->pe_delay_import_desc);
194         dent ("       CLI Header", dd->pe_cli_header);
195 }
196
197 static void
198 dump_dotnet_header (MonoDotNetHeader *header)
199 {
200         dump_coff_header (&header->coff);
201         dump_pe_header (&header->pe);
202         dump_nt_header (&header->nt);
203         dump_datadir (&header->datadir);
204 }
205
206 static void
207 dump_section_table (MonoSectionTable *st)
208 {
209         guint32 flags = st->st_flags;
210                 
211         printf ("\n\tName: %s\n", st->st_name);
212         hex32 ("   Virtual Size", st->st_virtual_size);
213         hex32 ("Virtual Address", st->st_virtual_address);
214         hex32 ("  Raw Data Size", st->st_raw_data_size);
215         hex32 ("   Raw Data Ptr", st->st_raw_data_ptr);
216         hex32 ("      Reloc Ptr", st->st_reloc_ptr);
217         hex32 ("     LineNo Ptr", st->st_lineno_ptr);
218         hex16 ("    Reloc Count", st->st_reloc_count);
219         hex16 ("     Line Count", st->st_line_count);
220
221         printf ("\tFlags: %s%s%s%s%s%s%s%s%s%s\n",
222                 (flags & SECT_FLAGS_HAS_CODE) ? "code, " : "",
223                 (flags & SECT_FLAGS_HAS_INITIALIZED_DATA) ? "data, " : "",
224                 (flags & SECT_FLAGS_HAS_UNINITIALIZED_DATA) ? "bss, " : "",
225                 (flags & SECT_FLAGS_MEM_DISCARDABLE) ? "discard, " : "",
226                 (flags & SECT_FLAGS_MEM_NOT_CACHED) ? "nocache, " : "",
227                 (flags & SECT_FLAGS_MEM_NOT_PAGED) ? "nopage, " : "",
228                 (flags & SECT_FLAGS_MEM_SHARED) ? "shared, " : "",
229                 (flags & SECT_FLAGS_MEM_EXECUTE) ? "exec, " : "",
230                 (flags & SECT_FLAGS_MEM_READ) ? "read, " : "",
231                 (flags & SECT_FLAGS_MEM_WRITE) ? "write" : "");
232 }
233
234 static void
235 dump_sections (MonoCLIImageInfo *iinfo)
236 {
237         const int top = iinfo->cli_header.coff.coff_sections;
238         int i;
239         
240         for (i = 0; i < top; i++)
241                 dump_section_table (&iinfo->cli_section_tables [i]);
242 }
243
244 static void
245 dump_cli_header (MonoCLIHeader *ch)
246 {
247         printf ("\n");
248         printf ("          CLI header size: %d\n", ch->ch_size);
249         printf ("         Runtime required: %d.%d\n", ch->ch_runtime_major, ch->ch_runtime_minor);
250         printf ("                    Flags: %s, %s, %s, %s\n",
251                 (ch->ch_flags & CLI_FLAGS_ILONLY ? "ilonly" : "contains native"),
252                 (ch->ch_flags & CLI_FLAGS_32BITREQUIRED ? "32bits" : "32/64"),
253                 (ch->ch_flags & CLI_FLAGS_ILONLY ? "trackdebug" : "no-trackdebug"),
254                 (ch->ch_flags & CLI_FLAGS_STRONGNAMESIGNED ? "strongnamesigned" : "notsigned"));
255         dent   ("         Metadata", ch->ch_metadata);
256         hex32  ("Entry Point Token", ch->ch_entry_point);
257         dent   ("     Resources at", ch->ch_resources);
258         dent   ("   Strong Name at", ch->ch_strong_name);
259         dent   ("  Code Manager at", ch->ch_code_manager_table);
260         dent   ("  VTableFixups at", ch->ch_vtable_fixups);
261         dent   ("     EAT jumps at", ch->ch_export_address_table_jumps);
262 }       
263
264 static void
265 dsh (const char *label, MonoImage *meta, MonoStreamHeader *sh)
266 {
267         printf ("%s: 0x%08x - 0x%08x [%d == 0x%08x]\n",
268                 label,
269                 (int)(sh->data - meta->raw_metadata), (int)(sh->data + sh->size - meta->raw_metadata),
270                 sh->size, sh->size);
271 }
272
273 static void
274 dump_metadata_header (MonoImage *meta)
275 {
276         printf ("\nMetadata header:\n");
277         printf ("           Version: %d.%d\n", meta->md_version_major, meta->md_version_minor);
278         printf ("    Version string: %s\n", meta->version);
279 }
280
281 static void
282 dump_metadata_ptrs (MonoImage *meta)
283 {
284         printf ("\nMetadata pointers:\n");
285         dsh ("\tTables (#~)", meta, &meta->heap_tables);
286         dsh ("\t    Strings", meta, &meta->heap_strings);
287         dsh ("\t       Blob", meta, &meta->heap_blob);
288         dsh ("\tUser string", meta, &meta->heap_us);
289         dsh ("\t       GUID", meta, &meta->heap_guid);
290 }
291
292 static void
293 dump_metadata (MonoImage *meta)
294 {
295         int table;
296
297         dump_metadata_header (meta);
298
299         dump_metadata_ptrs (meta);
300
301         printf ("Rows:\n");
302         for (table = 0; table < MONO_TABLE_NUM; table++){
303                 if (meta->tables [table].rows == 0)
304                         continue;
305                 printf ("Table %s: %d records (%d bytes, at %p)\n",
306                         mono_meta_table_name (table),
307                         meta->tables [table].rows,
308                         meta->tables [table].row_size,
309                         meta->tables [table].base
310                         );
311         }
312 }
313
314 static void
315 dump_methoddef (MonoImage *metadata, guint32 token)
316 {
317         const char *loc;
318
319         if (!token)
320                 return;
321         loc = mono_metadata_locate_token (metadata, token);
322
323         printf ("RVA for Entry Point: 0x%08x\n", read32 (loc));
324 }
325
326 static void
327 dump_dotnet_iinfo (MonoImage *image)
328 {
329         MonoCLIImageInfo *iinfo = image->image_info;
330
331         dump_dotnet_header (&iinfo->cli_header);
332         dump_sections (iinfo);
333         dump_cli_header (&iinfo->cli_cli_header);
334         dump_strong_name (image);
335         dump_public_key (image);
336         dump_metadata (image);
337
338         dump_methoddef (image, iinfo->cli_cli_header.ch_entry_point);
339 }
340
341 static int
342 dump_verify_info (MonoImage *image, int flags)
343 {
344         GSList *errors, *tmp;
345         int count = 0, verifiable = 0;
346         const char* desc [] = {
347                 "Ok", "Error", "Warning", NULL, "CLS", NULL, NULL, NULL, "Not Verifiable"
348         };
349
350         if (verify_metadata) {
351                 errors = mono_image_verify_tables (image, flags);
352         
353                 for (tmp = errors; tmp; tmp = tmp->next) {
354                         MonoVerifyInfo *info = tmp->data;
355                         g_print ("%s: %s\n", desc [info->status], info->message);
356                         if (info->status == MONO_VERIFY_ERROR)
357                                 count++;
358                 }
359                 mono_free_verify_list (errors);
360         }
361
362         if (verify_code) { /* verify code */
363                 int i;
364                 MonoTableInfo *m = &image->tables [MONO_TABLE_METHOD];
365
366                 for (i = 0; i < m->rows; ++i) {
367                         MonoMethod *method;
368                         method = mono_get_method (image, MONO_TOKEN_METHOD_DEF | (i+1), NULL);
369                         if (!method) {
370                                 g_print ("Warning: Cannot lookup method with token 0x%08x\n", i + 1);
371                                 continue;
372                         }
373                         errors = mono_method_verify (method, flags);
374                         if (errors) {
375                                 char *sig, *name;
376                                 MonoClass *klass = mono_method_get_class (method);
377                                 sig = mono_signature_get_desc (mono_method_signature (method), FALSE);
378                                 name = mono_type_full_name (&klass->byval_arg);
379                                 g_print ("In method: %s::%s(%s)\n", name, mono_method_get_name (method), sig);
380                                 g_free (name);
381                                 g_free (sig);
382                         }
383
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;
390                                 }
391                                 if(info->status == MONO_VERIFY_NOT_VERIFIABLE) {
392                                         if (verifiable < 2)
393                                                 verifiable = 2; 
394                                 }
395                         }
396                         mono_free_verify_list (errors);
397                 }
398         }
399
400         if (count)
401                 g_print ("Error count: %d\n", count);
402         return verifiable;
403 }
404
405 static void
406 usage (void)
407 {
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);
410 }
411
412 static int
413 verify_image_file (const char *fname)
414 {
415         FILE *filed;
416         struct stat stat_buf;
417         void *raw_data_handle;
418         char *raw_data;
419         GSList *errors, *tmp;
420         int count = 0;
421         const char* desc [] = {
422                 "Ok", "Error", "Warning", NULL, "CLS", NULL, NULL, NULL, "Not Verifiable"
423         };
424
425         if ((filed = fopen (fname, "rb")) == NULL) {
426                 fprintf (stderr, "Cannot open file %s\n", fname);
427                 exit (1);
428         }
429
430         if (fstat (fileno (filed), &stat_buf)) {
431                 fclose (filed);
432                 fprintf (stderr, "Cannot stat file %s\n", fname);
433                 exit (1);
434         }
435
436         raw_data = mono_file_map (stat_buf.st_size, MONO_MMAP_READ|MONO_MMAP_PRIVATE, fileno (filed), 0, &raw_data_handle);
437
438         if (!raw_data) {
439                 fprintf (stderr, "Could not mmap file %s\n", fname);
440                 exit (1);
441         }
442         fclose (filed);
443
444         errors = mono_image_verify (raw_data, stat_buf.st_size);
445         mono_file_unmap (raw_data, raw_data_handle);
446
447         if (!errors)
448                 return 0;
449
450         for (tmp = errors; tmp; tmp = tmp->next) {
451                 MonoVerifyInfo *info = tmp->data;
452                 g_print ("%s: %s\n", desc [info->status], info->message);
453                 if (info->status == MONO_VERIFY_ERROR)
454                         count++;
455         }
456         mono_free_verify_list (errors);
457         if (count)
458                 g_print ("Error count: %d\n", count);
459
460         return count > 0 ? 1 : 0;
461 }
462
463 static gboolean
464 try_load_from (MonoAssembly **assembly, const gchar *path1, const gchar *path2,
465                                         const gchar *path3, const gchar *path4, gboolean refonly)
466 {
467         gchar *fullpath;
468
469         *assembly = NULL;
470         fullpath = g_build_filename (path1, path2, path3, path4, NULL);
471         if (g_file_test (fullpath, G_FILE_TEST_IS_REGULAR))
472                 *assembly = mono_assembly_open_full (fullpath, NULL, refonly);
473
474         g_free (fullpath);
475         return (*assembly != NULL);
476 }
477
478 static MonoAssembly *
479 real_load (gchar **search_path, const gchar *culture, const gchar *name, gboolean refonly)
480 {
481         MonoAssembly *result = NULL;
482         gchar **path;
483         gchar *filename;
484         const gchar *local_culture;
485         gint len;
486
487         if (!culture || *culture == '\0') {
488                 local_culture = "";
489         } else {
490                 local_culture = culture;
491         }
492
493         filename =  g_strconcat (name, ".dll", NULL);
494         len = strlen (filename);
495
496         for (path = search_path; *path; path++) {
497                 if (**path == '\0')
498                         continue; /* Ignore empty ApplicationBase */
499
500                 /* See test cases in bug #58992 and bug #57710 */
501                 /* 1st try: [culture]/[name].dll (culture may be empty) */
502                 strcpy (filename + len - 4, ".dll");
503                 if (try_load_from (&result, *path, local_culture, "", filename, refonly))
504                         break;
505
506                 /* 2nd try: [culture]/[name].exe (culture may be empty) */
507                 strcpy (filename + len - 4, ".exe");
508                 if (try_load_from (&result, *path, local_culture, "", filename, refonly))
509                         break;
510
511                 /* 3rd try: [culture]/[name]/[name].dll (culture may be empty) */
512                 strcpy (filename + len - 4, ".dll");
513                 if (try_load_from (&result, *path, local_culture, name, filename, refonly))
514                         break;
515
516                 /* 4th try: [culture]/[name]/[name].exe (culture may be empty) */
517                 strcpy (filename + len - 4, ".exe");
518                 if (try_load_from (&result, *path, local_culture, name, filename, refonly))
519                         break;
520         }
521
522         g_free (filename);
523         return result;
524 }
525
526 /*
527  * Try to load referenced assemblies from assemblies_path.
528  */
529 static MonoAssembly *
530 pedump_preload (MonoAssemblyName *aname,
531                                  gchar **assemblies_path,
532                                  gpointer user_data)
533 {
534         MonoAssembly *result = NULL;
535         gboolean refonly = GPOINTER_TO_UINT (user_data);
536
537         if (assemblies_path && assemblies_path [0] != NULL) {
538                 result = real_load (assemblies_path, aname->culture, aname->name, refonly);
539         }
540
541         return result;
542 }
543
544 static GList *loaded_assemblies = NULL;
545
546 static void
547 pedump_assembly_load_hook (MonoAssembly *assembly, gpointer user_data)
548 {
549         loaded_assemblies = g_list_prepend (loaded_assemblies, assembly);
550 }
551
552 static MonoAssembly *
553 pedump_assembly_search_hook (MonoAssemblyName *aname, gpointer user_data)
554 {
555         GList *tmp;
556
557        for (tmp = loaded_assemblies; tmp; tmp = tmp->next) {
558                MonoAssembly *ass = tmp->data;
559                if (mono_assembly_names_equal (aname, &ass->aname))
560                        return ass;
561        }
562        return NULL;
563 }
564
565 #define VALID_ONLY_FLAG 0x08000000
566 #define VERIFY_CODE_ONLY MONO_VERIFY_ALL + 1 
567 #define VERIFY_METADATA_ONLY VERIFY_CODE_ONLY + 1
568
569 int
570 main (int argc, char *argv [])
571 {
572         MonoImage *image;
573         char *file = NULL;
574         char *flags = NULL;
575         MiniVerifierMode verifier_mode = MONO_VERIFIER_MODE_VERIFIABLE;
576         const char *flag_desc [] = {"error", "warn", "cls", "all", "code", "fail-on-verifiable", "non-strict", "valid-only", "metadata", NULL};
577         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, 0};
578         int i, verify_flags = MONO_VERIFY_REPORT_ALL_ERRORS, run_new_metadata_verifier = 0;
579         
580         for (i = 1; i < argc; i++){
581                 if (argv [i][0] != '-'){
582                         file = argv [i];
583                         continue;
584                 }
585
586                 if (strcmp (argv [i], "--help") == 0)
587                         usage ();
588                 else if (strcmp (argv [i], "--verify") == 0) {
589                         verify_pe = 1;
590                         dump_data = 0;
591                         ++i;
592                         flags = argv [i];
593                 } else {
594                         usage ();
595                 }
596         }
597         
598         if (!file)
599                 usage ();
600
601         mono_perfcounters_init ();
602         mono_metadata_init ();
603         mono_images_init ();
604         mono_assemblies_init ();
605         mono_loader_init ();
606  
607         if (verify_pe) {
608                 char *tok = strtok (flags, ",");
609
610                 verify_metadata = 1;
611                 verify_code = 0;
612                 while (tok) {
613                         for (i = 0; flag_desc [i]; ++i) {
614                                 if (strcmp (tok, flag_desc [i]) == 0) {
615                                         if (flag_vals [i] == VERIFY_CODE_ONLY) {
616                                                 verify_metadata = 0;
617                                                 verify_code = 1;
618                                         } else if(flag_vals [i] == MONO_VERIFY_ALL) {
619                                                 verify_code = 1;
620                                         } else if(flag_vals [i] == VERIFY_METADATA_ONLY) {
621                                                 verify_metadata = 0;
622                                                 run_new_metadata_verifier = 1;
623                                         }
624                                         if (flag_vals [i] == VALID_ONLY_FLAG)
625                                                 verifier_mode = MONO_VERIFIER_MODE_VALID;
626                                         else
627                                                 verify_flags |= flag_vals [i];
628                                         break;
629                                 }
630                         }
631                         if (!flag_desc [i])
632                                 g_print ("Unknown verify flag %s\n", tok);
633                         tok = strtok (NULL, ",");
634                 }
635
636                 mono_verifier_set_mode (verifier_mode);
637                 /**/
638         }
639
640         if (run_new_metadata_verifier)
641                 return verify_image_file (file);
642
643         image = mono_image_open (file, NULL);
644         if (!image){
645                 fprintf (stderr, "Cannot open image %s\n", file);
646                 exit (1);
647         }
648
649         if (dump_data)
650                 dump_dotnet_iinfo (image);
651         if (verify_pe) {
652                 MonoAssembly *assembly;
653
654                 mono_install_assembly_load_hook (pedump_assembly_load_hook, NULL);
655                 mono_install_assembly_search_hook (pedump_assembly_search_hook, NULL);
656
657                 mono_init_from_assembly (file, file);
658
659                 mono_install_assembly_preload_hook (pedump_preload, GUINT_TO_POINTER (FALSE));
660
661                 assembly = mono_assembly_open (file, NULL);
662
663                 if (!assembly) {
664                         g_print ("Could not open assembly %s\n", file);
665                         return 4;
666                 }
667
668                 return dump_verify_info (assembly->image, verify_flags);
669         } else
670                 mono_image_close (image);
671         
672         return 0;
673 }
674