2005-12-23 Dick Porter <dick@ximian.com>
[mono.git] / mono / metadata / pedump.c
index f96dcace60dd6ec17bd462d65930b6f9861525b6..b52f5d79dbcc50893b9980dadc5a27b7f3bf29e0 100644 (file)
@@ -13,7 +13,6 @@
 #include "image.h"
 #include <glib.h>
 #include "cil-coff.h"
-#include "private.h"
 #include "mono-endian.h"
 #include "verify.h"
 #include <mono/metadata/class.h>
 #include <mono/metadata/tokentype.h>
 #include <mono/metadata/appdomain.h>
 #include <mono/metadata/assembly.h>
+#include <mono/metadata/metadata-internals.h>
+#include <mono/metadata/rawbuffer.h>
+#include <mono/metadata/class-internals.h>
+#include "mono/utils/mono-digest.h"
 
 gboolean dump_data = TRUE;
 gboolean verify_pe = FALSE;
@@ -122,6 +125,45 @@ dent (const char *label, MonoPEDirEntry de)
        printf ("\t%s: 0x%08x [0x%08x]\n", label, de.rva, de.size);
 }
 
+static void
+dump_blob (const char *desc, const char* p, guint32 size)
+{
+       int i;
+
+       printf ("%s", desc);
+       if (!p) {
+               printf (" none\n");
+               return;
+       }
+
+       for (i = 0; i < size; ++i) {
+               if (!(i % 16))
+                       printf ("\n\t");
+               printf (" %02X", p [i] & 0xFF);
+       }
+       printf ("\n");
+}
+
+static void
+dump_public_key (MonoImage *m)
+{
+       guint32 size;
+       const char *p;
+
+       p = mono_image_get_public_key (m, &size);
+       dump_blob ("\nPublic key:", p, size);
+}
+
+static void
+dump_strong_name (MonoImage *m)
+{
+       guint32 size;
+       const char *p;
+
+       p = mono_image_get_strong_name (m, &size);
+       dump_blob ("\nStrong name:", p, size);
+}
+
 static void
 dump_datadir (MonoPEDatadir *dd)
 {
@@ -196,10 +238,11 @@ dump_cli_header (MonoCLIHeader *ch)
        printf ("\n");
        printf ("          CLI header size: %d\n", ch->ch_size);
        printf ("         Runtime required: %d.%d\n", ch->ch_runtime_major, ch->ch_runtime_minor);
-       printf ("                    Flags: %s, %s, %s\n",
+       printf ("                    Flags: %s, %s, %s, %s\n",
                (ch->ch_flags & CLI_FLAGS_ILONLY ? "ilonly" : "contains native"),
                (ch->ch_flags & CLI_FLAGS_32BITREQUIRED ? "32bits" : "32/64"),
-               (ch->ch_flags & CLI_FLAGS_ILONLY ? "trackdebug" : "no-trackdebug"));
+               (ch->ch_flags & CLI_FLAGS_ILONLY ? "trackdebug" : "no-trackdebug"),
+               (ch->ch_flags & CLI_FLAGS_STRONGNAMESIGNED ? "strongnamesigned" : "notsigned"));
        dent   ("         Metadata", ch->ch_metadata);
        hex32  ("Entry Point Token", ch->ch_entry_point);
        dent   ("     Resources at", ch->ch_resources);
@@ -214,7 +257,7 @@ dsh (const char *label, MonoImage *meta, MonoStreamHeader *sh)
 {
        printf ("%s: 0x%08x - 0x%08x [%d == 0x%08x]\n",
                label,
-               sh->data - meta->raw_metadata, sh->data + sh->size - meta->raw_metadata,
+               (int)(sh->data - meta->raw_metadata), (int)(sh->data + sh->size - meta->raw_metadata),
                sh->size, sh->size);
 }
 
@@ -237,7 +280,7 @@ dump_metadata (MonoImage *meta)
        dump_metadata_ptrs (meta);
 
        printf ("Rows:\n");
-       for (table = 0; table < 64; table++){
+       for (table = 0; table < MONO_TABLE_NUM; table++){
                if (meta->tables [table].rows == 0)
                        continue;
                printf ("Table %s: %d records (%d bytes, at %p)\n",
@@ -269,6 +312,8 @@ dump_dotnet_iinfo (MonoImage *image)
        dump_dotnet_header (&iinfo->cli_header);
        dump_sections (iinfo);
        dump_cli_header (&iinfo->cli_cli_header);
+       dump_strong_name (image);
+       dump_public_key (image);
        dump_metadata (image);
 
        dump_methoddef (image, iinfo->cli_cli_header.ch_entry_point);
@@ -304,8 +349,9 @@ dump_verify_info (MonoImage *image, int flags)
                        errors = mono_method_verify (method, flags);
                        if (errors) {
                                char *sig;
-                               sig = mono_signature_get_desc (method->signature, FALSE);
-                               g_print ("In method: %s.%s::%s(%s)\n", method->klass->name_space, method->klass->name, method->name, sig);
+                               MonoClass *klass = mono_method_get_class (method);
+                               sig = mono_signature_get_desc (mono_method_signature (method), FALSE);
+                               g_print ("In method: %s.%s::%s(%s)\n", mono_class_get_namespace (klass), mono_class_get_name (klass), mono_method_get_name (method), sig);
                                g_free (sig);
                        }
 
@@ -361,6 +407,12 @@ main (int argc, char *argv [])
        if (!file)
                usage ();
 
+       mono_metadata_init ();
+        mono_raw_buffer_init ();
+        mono_images_init ();
+        mono_assemblies_init ();
+        mono_loader_init ();
        image = mono_image_open (file, NULL);
        if (!image){
                fprintf (stderr, "Can not open image %s\n", file);
@@ -387,9 +439,8 @@ main (int argc, char *argv [])
                mono_init (file);
                assembly = mono_assembly_open (file, NULL);
                dump_verify_info (assembly->image, f);
-       }
-       
-       mono_image_close (image);
+       } else
+               mono_image_close (image);
        
        return 0;
 }