diff options
Diffstat (limited to 'mono/metadata/pedump.c')
-rw-r--r-- | mono/metadata/pedump.c | 109 |
1 files changed, 100 insertions, 9 deletions
diff --git a/mono/metadata/pedump.c b/mono/metadata/pedump.c index 94ed15dffb4..eec1b6b9ef6 100644 --- a/mono/metadata/pedump.c +++ b/mono/metadata/pedump.c @@ -17,6 +17,14 @@ #include "mono-endian.h" #include "verify.h" #include <mono/metadata/class.h> +#include <mono/metadata/debug-helpers.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; @@ -119,6 +127,45 @@ dent (const char *label, MonoPEDirEntry de) } 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) { printf ("\nData directories:\n"); @@ -192,10 +239,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); @@ -265,6 +313,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); @@ -274,6 +324,7 @@ static void dump_verify_info (MonoImage *image, int flags) { GSList *errors, *tmp; + int count = 0; const char* desc [] = { "Ok", "Error", "Warning", NULL, "CLS" }; @@ -283,14 +334,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); } @@ -300,8 +383,8 @@ main (int argc, char *argv []) MonoImage *image; char *file = NULL; char *flags = NULL; - const 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++){ @@ -325,6 +408,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); @@ -336,6 +425,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) { @@ -347,10 +437,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; } |