static int dump_verify_info (MonoImage *image, int flags) { GSList *errors, *tmp; int count = 0, verifiable = 0; const char* desc [] = { "Ok", "Error", "Warning", NULL, "CLS", NULL, NULL, NULL, "Not Verifiable" }; if (verify_code) { /* verify code */ int i; MonoTableInfo *m = &image->tables [MONO_TABLE_METHOD]; for (i = 0; i < m->rows; ++i) { MonoMethod *method; MonoError error; method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i+1), NULL, NULL, &error); if (!method) { g_print ("Warning: Cannot lookup method with token 0x%08x due to %s\n", i + 1, mono_error_get_message (&error)); mono_error_cleanup (&error); continue; } errors = mono_method_verify (method, flags); if (errors) { MonoClass *klass = mono_method_get_class (method); char *name = mono_type_full_name (&klass->byval_arg); if (mono_method_signature (method) == NULL) { g_print ("In method: %s::%s(ERROR)\n", name, mono_method_get_name (method)); } else { char *sig; sig = mono_signature_get_desc (mono_method_signature (method), FALSE); g_print ("In method: %s::%s(%s)\n", name, mono_method_get_name (method), sig); g_free (sig); } g_free (name); } for (tmp = errors; tmp; tmp = tmp->next) { MonoVerifyInfo *info = (MonoVerifyInfo *)tmp->data; g_print ("%s: %s\n", desc [info->status], info->message); if (info->status == MONO_VERIFY_ERROR) { count++; verifiable = 3; } if(info->status == MONO_VERIFY_NOT_VERIFIABLE) { if (verifiable < 2) verifiable = 2; } } mono_free_verify_list (errors); } } if (count) g_print ("Error count: %d\n", count); return verifiable; }
static int mono_attach_load_agent (MonoDomain *domain, char *agent, char *args, MonoObject **exc) { MonoError error; MonoAssembly *agent_assembly; MonoImage *image; MonoMethod *method; guint32 entry; MonoArray *main_args; gpointer pa [1]; MonoImageOpenStatus open_status; agent_assembly = mono_assembly_open (agent, &open_status); if (!agent_assembly) { fprintf (stderr, "Cannot open agent assembly '%s': %s.\n", agent, mono_image_strerror (open_status)); g_free (agent); return 2; } /* * Can't use mono_jit_exec (), as it sets things which might confuse the * real Main method. */ image = mono_assembly_get_image (agent_assembly); entry = mono_image_get_entry_point (image); if (!entry) { g_print ("Assembly '%s' doesn't have an entry point.\n", mono_image_get_filename (image)); g_free (agent); return 1; } method = mono_get_method_checked (image, entry, NULL, NULL, &error); if (method == NULL){ g_print ("The entry point method of assembly '%s' could not be loaded due to %s\n", agent, mono_error_get_message (&error)); mono_error_cleanup (&error); g_free (agent); return 1; } if (args) { main_args = (MonoArray*)mono_array_new (domain, mono_defaults.string_class, 1); mono_array_set (main_args, MonoString*, 0, mono_string_new (domain, args)); } else {
MonoMethod* mono_method_desc_search_in_image (MonoMethodDesc *desc, MonoImage *image) { MonoClass *klass; const MonoTableInfo *methods; MonoMethod *method; int i; /* Handle short names for system classes */ if (!desc->name_space && image == mono_defaults.corlib) { klass = find_system_class (desc->klass); if (klass) return mono_method_desc_search_in_class (desc, klass); } if (desc->name_space && desc->klass) { klass = mono_class_try_load_from_name (image, desc->name_space, desc->klass); if (!klass) return NULL; return mono_method_desc_search_in_class (desc, klass); } /* FIXME: Is this call necessary? We don't use its result. */ mono_image_get_table_info (image, MONO_TABLE_TYPEDEF); methods = mono_image_get_table_info (image, MONO_TABLE_METHOD); for (i = 0; i < mono_table_info_get_rows (methods); ++i) { MonoError error; guint32 token = mono_metadata_decode_row_col (methods, i, MONO_METHOD_NAME); const char *n = mono_metadata_string_heap (image, token); if (strcmp (n, desc->name)) continue; method = mono_get_method_checked (image, MONO_TOKEN_METHOD_DEF | (i + 1), NULL, NULL, &error); if (!method) { mono_error_cleanup (&error); continue; } if (mono_method_desc_full_match (desc, method)) return method; } return NULL; }
__int32 STDMETHODCALLTYPE _CorExeMain(void) { ERROR_DECL (error); MonoDomain* domain; MonoAssembly* assembly; MonoImage* image; MonoMethod* method; guint32 entry; gchar* file_name; gchar* corlib_version_error; int argc; gunichar2** argvw; gchar** argv; int i; file_name = mono_get_module_file_name (NULL); init_from_coree = TRUE; domain = mono_runtime_load (file_name, NULL); corlib_version_error = (gchar*) mono_check_corlib_version (); if (corlib_version_error) { g_free (corlib_version_error); g_free (file_name); MessageBox (NULL, L"Corlib not in sync with this runtime.", NULL, MB_ICONERROR); mono_runtime_quit (); ExitProcess (1); } MonoAssemblyOpenRequest req; mono_assembly_request_prepare (&req.request, sizeof (req), MONO_ASMCTX_DEFAULT); assembly = mono_assembly_request_open (file_name, &req, NULL); mono_close_exe_image (); if (!assembly) { g_free (file_name); MessageBox (NULL, L"Cannot open assembly.", NULL, MB_ICONERROR); mono_runtime_quit (); ExitProcess (1); } image = assembly->image; entry = mono_image_get_entry_point (image); if (!entry) { g_free (file_name); MessageBox (NULL, L"Assembly doesn't have an entry point.", NULL, MB_ICONERROR); mono_runtime_quit (); ExitProcess (1); } method = mono_get_method_checked (image, entry, NULL, NULL, error); if (method == NULL) { g_free (file_name); mono_error_cleanup (error); /* FIXME don't swallow the error */ MessageBox (NULL, L"The entry point method could not be loaded.", NULL, MB_ICONERROR); mono_runtime_quit (); ExitProcess (1); } argvw = CommandLineToArgvW (GetCommandLine (), &argc); argv = g_new0 (gchar*, argc); argv [0] = file_name; for (i = 1; i < argc; ++i) argv [i] = g_utf16_to_utf8 (argvw [i], -1, NULL, NULL, NULL); LocalFree (argvw); mono_runtime_run_main_checked (method, argc, argv, error); mono_error_raise_exception_deprecated (error); /* OK, triggers unhandled exn handler */ mono_thread_manage (); mono_runtime_quit (); /* return does not terminate the process. */ ExitProcess (mono_environment_exitcode_get ()); }