X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=blobdiff_plain;f=mono%2Fmetadata%2Fpedump.c;h=b52f5d79dbcc50893b9980dadc5a27b7f3bf29e0;hb=3b5eb0cf5a2d48b362f64e0eaa351a56d7a0a065;hp=630c5e715a3a1497646a04000f5165262b49792a;hpb=340ce50eeab112681d35fdbe297339bb04d26918;p=mono.git diff --git a/mono/metadata/pedump.c b/mono/metadata/pedump.c index 630c5e715a3..b52f5d79dbc 100644 --- a/mono/metadata/pedump.c +++ b/mono/metadata/pedump.c @@ -13,16 +13,24 @@ #include "image.h" #include #include "cil-coff.h" -#include "private.h" #include "mono-endian.h" #include "verify.h" #include +#include +#include +#include +#include +#include +#include +#include +#include "mono/utils/mono-digest.h" gboolean dump_data = TRUE; gboolean verify_pe = FALSE; +/* unused static void -hex_dump (char *buffer, int base, int count) +hex_dump (const char *buffer, int base, int count) { int i; @@ -33,21 +41,22 @@ hex_dump (char *buffer, int base, int count) printf ("%02x ", (unsigned char) (buffer [i])); } } +*/ static void -hex8 (char *label, unsigned char x) +hex8 (const char *label, unsigned char x) { printf ("\t%s: 0x%02x\n", label, (unsigned char) x); } static void -hex16 (char *label, guint16 x) +hex16 (const char *label, guint16 x) { printf ("\t%s: 0x%04x\n", label, x); } static void -hex32 (char *label, guint32 x) +hex32 (const char *label, guint32 x) { printf ("\t%s: 0x%08x\n", label, x); } @@ -116,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) { @@ -190,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); @@ -204,11 +253,11 @@ dump_cli_header (MonoCLIHeader *ch) } static void -dsh (char *label, MonoImage *meta, MonoStreamHeader *sh) +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); } @@ -231,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", @@ -246,7 +295,7 @@ dump_metadata (MonoImage *meta) static void dump_methoddef (MonoImage *metadata, guint32 token) { - char *loc; + const char *loc; if (!token) return; @@ -263,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); @@ -272,6 +323,7 @@ static void dump_verify_info (MonoImage *image, int flags) { GSList *errors, *tmp; + int count = 0; const char* desc [] = { "Ok", "Error", "Warning", NULL, "CLS" }; @@ -281,14 +333,46 @@ dump_verify_info (MonoImage *image, int flags) for (tmp = errors; tmp; tmp = tmp->next) { MonoVerifyInfo *info = tmp->data; g_print ("%s: %s\n", desc [info->status], info->message); + if (info->status == MONO_VERIFY_ERROR) + count++; } mono_free_verify_list (errors); + + if (flags & (MONO_VERIFY_ALL + 1)) { /* verify code */ + int i; + MonoTableInfo *m = &image->tables [MONO_TABLE_METHOD]; + + for (i = 0; i < m->rows; ++i) { + MonoMethod *method; + + method = mono_get_method (image, MONO_TOKEN_METHOD_DEF | (i+1), NULL); + errors = mono_method_verify (method, flags); + if (errors) { + char *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); + } + + for (tmp = errors; tmp; tmp = tmp->next) { + MonoVerifyInfo *info = tmp->data; + g_print ("%s: %s\n", desc [info->status], info->message); + if (info->status == MONO_VERIFY_ERROR) + count++; + } + mono_free_verify_list (errors); + } + } + + if (count) + g_print ("Error count: %d\n", count); } static void usage (void) { - printf ("Usage is: pedump [--verify error,warn,cls,all] file.exe\n"); + printf ("Usage is: pedump [--verify error,warn,cls,all,code] file.exe\n"); exit (1); } @@ -298,8 +382,8 @@ main (int argc, char *argv []) MonoImage *image; char *file = NULL; char *flags = NULL; - char *flag_desc [] = {"error", "warn", "cls", "all", NULL}; - guint flag_vals [] = {MONO_VERIFY_ERROR, MONO_VERIFY_WARNING, MONO_VERIFY_CLS, MONO_VERIFY_ALL}; + const char *flag_desc [] = {"error", "warn", "cls", "all", "code", NULL}; + guint flag_vals [] = {MONO_VERIFY_ERROR, MONO_VERIFY_WARNING, MONO_VERIFY_CLS, MONO_VERIFY_ALL, MONO_VERIFY_ALL + 1}; int i; for (i = 1; i < argc; i++){ @@ -323,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); @@ -334,6 +424,7 @@ main (int argc, char *argv []) if (verify_pe) { int f = 0; char *tok = strtok (flags, ","); + MonoAssembly *assembly; while (tok) { for (i = 0; flag_desc [i]; ++i) { if (strcmp (tok, flag_desc [i]) == 0) { @@ -345,10 +436,11 @@ main (int argc, char *argv []) g_print ("Unknown verify flag %s\n", tok); tok = strtok (NULL, ","); } - dump_verify_info (image, f); - } - - mono_image_close (image); + mono_init (file); + assembly = mono_assembly_open (file, NULL); + dump_verify_info (assembly->image, f); + } else + mono_image_close (image); return 0; }