Ejemplo n.º 1
0
/**
 * mono_exception_from_token_two_strings:
 *
 *   Same as mono_exception_from_name_two_strings, but lookup the exception class using
 * IMAGE and TOKEN.
 */
MonoException *
mono_exception_from_token_two_strings (MonoImage *image, guint32 token,
									   MonoString *a1, MonoString *a2)
{
	MonoError error;
	MonoClass *klass = mono_class_get_checked (image, token, &error);
	g_assert (mono_error_ok (&error)); /* FIXME handle the error. */

	return create_exception_two_strings (klass, a1, a2);
}
Ejemplo n.º 2
0
/**
 * mono_exception_from_token_two_strings_checked:
 *
 *   Same as mono_exception_from_name_two_strings, but lookup the exception class using
 * IMAGE and TOKEN.
 */
MonoException *
mono_exception_from_token_two_strings_checked (MonoImage *image, guint32 token,
					       MonoString *a1, MonoString *a2,
					       MonoError *error)
{
	MonoClass *klass;

	mono_error_init (error);

	klass = mono_class_get_checked (image, token, error);
	mono_error_assert_ok (error); /* FIXME handle the error. */

	return create_exception_two_strings (klass, a1, a2, error);
}
Ejemplo n.º 3
0
/**
 * mono_exception_from_token_two_strings_checked:
 *
 *   Same as mono_exception_from_name_two_strings, but lookup the exception class using
 * IMAGE and TOKEN.
 */
MonoExceptionHandle
mono_exception_from_token_two_strings_checked (MonoImage *image, guint32 token,
					       MonoStringHandle a1, MonoStringHandle a2,
					       MonoError *error)
{
	HANDLE_FUNCTION_ENTER ();

	MonoClass *klass;

	error_init (error);

	klass = mono_class_get_checked (image, token, error);
	mono_error_assert_ok (error); /* FIXME handle the error. */

	HANDLE_FUNCTION_RETURN_REF (MonoException, create_exception_two_strings (klass, a1, a2, error));
}
Ejemplo n.º 4
0
/**
 * mono_exception_from_token_two_strings:
 *
 *   Same as mono_exception_from_name_two_strings, but lookup the exception class using
 * IMAGE and TOKEN.
 */
MonoException *
mono_exception_from_token_two_strings (MonoImage *image, guint32 token,
									   MonoString *a1, MonoString *a2)
{
	MonoError error;
	MonoClass *klass;
	MonoException *ret;

	klass = mono_class_get_checked (image, token, &error);
	mono_error_assert_ok (&error); /* FIXME handle the error. */

	ret = create_exception_two_strings (klass, a1, a2, &error);
	mono_error_raise_exception (&error); /* FIXME don't raise here */

	return ret;
}
Ejemplo n.º 5
0
/**
 * mono_exception_from_token:
 * @image: the Mono image where to look for the class
 * @token: The type token of the class
 *
 * Creates an exception of the type given by @token.
 *
 * Returns: the initialized exception instance.
 */
MonoException *
mono_exception_from_token (MonoImage *image, guint32 token)
{
	MonoError error;
	MonoClass *klass;
	MonoObject *o;

	klass = mono_class_get_checked (image, token, &error);
	g_assert (mono_error_ok (&error)); /* FIXME handle the error. */

	o = mono_object_new_checked (mono_domain_get (), klass, &error);
	g_assert (o != NULL && mono_error_ok (&error)); /* FIXME don't swallow the error */
	
	mono_runtime_object_init (o);

	return (MonoException *)o;
}
Ejemplo n.º 6
0
/**
 * mono_exception_from_token:
 * @image: the Mono image where to look for the class
 * @token: The type token of the class
 *
 * Creates an exception of the type given by @token.
 *
 * Returns: the initialized exception instance.
 */
MonoException *
mono_exception_from_token (MonoImage *image, guint32 token)
{
	MonoError error;
	MonoClass *klass;
	MonoObject *o;

	klass = mono_class_get_checked (image, token, &error);
	mono_error_assert_ok (&error);

	o = mono_object_new_checked (mono_domain_get (), klass, &error);
	mono_error_assert_ok (&error);
	
	mono_runtime_object_init_checked (o, &error);
	mono_error_assert_ok (&error);

	return (MonoException *)o;
}
Ejemplo n.º 7
0
/**
 * mono_exception_from_token:
 * \param image the Mono image where to look for the class
 * \param token The type token of the class
 *
 * Creates an exception of the type given by \p token.
 *
 * \returns the initialized exception instance.
 */
MonoException *
mono_exception_from_token (MonoImage *image, guint32 token)
{
	HANDLE_FUNCTION_ENTER ();
	ERROR_DECL (error);
	MonoClass *klass;

	klass = mono_class_get_checked (image, token, error);
	mono_error_assert_ok (error);

	MonoObjectHandle o = mono_object_new_handle (mono_domain_get (), klass, error);
	mono_error_assert_ok (error);

	mono_runtime_object_init_handle (o, error);
	mono_error_assert_ok (error);

	HANDLE_FUNCTION_RETURN_OBJ (MONO_HANDLE_CAST (MonoException, o));
}
Ejemplo n.º 8
0
static int
verify_image_file (const char *fname)
{
	GSList *errors = NULL, *tmp;
	MonoImage *image;
	MonoTableInfo *table;
	MonoAssembly *assembly;
	MonoImageOpenStatus status;
	int i, count = 0;
	const char* desc [] = {
		"Ok", "Error", "Warning", NULL, "CLS", NULL, NULL, NULL, "Not Verifiable"
	};

	image = mono_image_open_raw (fname, &status);
	if (!image) {
		printf ("Could not open %s\n", fname);
		return 1;
	}

	if (!mono_verifier_verify_pe_data (image, &errors))
		goto invalid_image;

	if (!mono_image_load_pe_data (image)) {
		printf ("Could not load pe data for assembly %s\n", fname);
		return 1;
	}

	if (!mono_verifier_verify_cli_data (image, &errors))
		goto invalid_image;

	if (!mono_image_load_cli_data (image)) {
		printf ("Could not load cli data for assembly %s\n", fname);
		return 1;
	}

	if (!mono_verifier_verify_table_data (image, &errors))
		goto invalid_image;

	mono_image_load_names (image);

	/*fake an assembly for class loading to work*/
	assembly = g_new0 (MonoAssembly, 1);
	assembly->in_gac = FALSE;
	assembly->image = image;
	image->assembly = assembly;
	mono_assembly_fill_assembly_name (image, &assembly->aname);

	/*Finish initializing the runtime*/
	mono_install_assembly_load_hook (pedump_assembly_load_hook, NULL);
	mono_install_assembly_search_hook (pedump_assembly_search_hook, NULL);

	mono_init_version ("pedump", image->version);

	mono_install_assembly_preload_hook (pedump_preload, GUINT_TO_POINTER (FALSE));

	mono_icall_init ();
	mono_marshal_init ();


	if (!verify_partial_md && !mono_verifier_verify_full_table_data (image, &errors))
		goto invalid_image;


	table = &image->tables [MONO_TABLE_TYPEDEF];
	for (i = 1; i <= table->rows; ++i) {
		MonoError error;
		guint32 token = i | MONO_TOKEN_TYPE_DEF;
		MonoClass *klass = mono_class_get_checked (image, token, &error);
		if (!klass) {
			printf ("Could not load class with token %x due to %s\n", token, mono_error_get_message (&error));
			mono_error_cleanup (&error);
			continue;
		}
		mono_class_init (klass);
		if (mono_class_has_failure (klass)) {
			printf ("Error verifying class(0x%08x) %s.%s a type load error happened\n", token, klass->name_space, klass->name);
			++count;
		}

		mono_class_setup_vtable (klass);
		if (mono_class_has_failure (klass)) {
			printf ("Error verifying class(0x%08x) %s.%s a type load error happened\n", token, klass->name_space, klass->name);
			++count;
		}
	}
	if (count)
		return 5;
	return 0;

invalid_image:
	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++;
	}
	mono_free_verify_list (errors);
	if (count)
		g_print ("Error count: %d\n", count);
	return 1;
}
Ejemplo n.º 9
0
static int
verify_image_file (const char *fname)
{
	ERROR_DECL (error);

	MonoImage *image;
	MonoTableInfo *table;
	MonoAssembly *assembly;
	MonoImageOpenStatus status;
	int i, count = 0;

	if (!strstr (fname, "mscorlib.dll")) {
		image = mono_image_open_raw (fname, &status);
		if (!image) {
			printf ("Could not open %s\n", fname);
			return 1;
		}

		if (!mono_verifier_verify_pe_data (image, error))
			goto invalid_image;

		if (!mono_image_load_pe_data (image)) {
			printf ("Could not load pe data for assembly %s\n", fname);
			return 1;
		}

		if (!mono_verifier_verify_cli_data (image, error))
			goto invalid_image;

		if (!mono_image_load_cli_data (image)) {
			printf ("Could not load cli data for assembly %s\n", fname);
			return 1;
		}

		if (!mono_verifier_verify_table_data (image, error))
			goto invalid_image;

		mono_image_load_names (image);

		/*fake an assembly for class loading to work*/
		assembly = g_new0 (MonoAssembly, 1);
		assembly->in_gac = FALSE;
		assembly->image = image;
		image->assembly = assembly;
		mono_assembly_fill_assembly_name (image, &assembly->aname);

		/*Finish initializing the runtime*/
		mono_install_assembly_load_hook (pedump_assembly_load_hook, NULL);
		mono_install_assembly_search_hook (pedump_assembly_search_hook, NULL);

		mono_init_version ("pedump", image->version);

		mono_install_assembly_preload_hook (pedump_preload, GUINT_TO_POINTER (FALSE));

		mono_icall_init ();
		mono_marshal_init ();
	} else {
		/*Finish initializing the runtime*/
		mono_install_assembly_load_hook (pedump_assembly_load_hook, NULL);
		mono_install_assembly_search_hook (pedump_assembly_search_hook, NULL);

		mono_init_version ("pedump", NULL);

		mono_install_assembly_preload_hook (pedump_preload, GUINT_TO_POINTER (FALSE));

		mono_icall_init ();
		mono_marshal_init ();
		image = mono_get_corlib ();

		if (!mono_verifier_verify_pe_data (image, error))
			goto invalid_image;

		if (!mono_image_load_pe_data (image)) {
			printf ("Could not load pe data for assembly %s\n", fname);
			return 1;
		}

		if (!mono_verifier_verify_cli_data (image, error))
			goto invalid_image;

		if (!mono_image_load_cli_data (image)) {
			printf ("Could not load cli data for assembly %s\n", fname);
			return 1;
		}

		if (!mono_verifier_verify_table_data (image, error))
			goto invalid_image;
	}

	if (!verify_partial_md && !mono_verifier_verify_full_table_data (image, error))
		goto invalid_image;


	table = &image->tables [MONO_TABLE_TYPEDEF];
	for (i = 1; i <= table->rows; ++i) {
		ERROR_DECL (error);
		guint32 token = i | MONO_TOKEN_TYPE_DEF;
		MonoClass *klass = mono_class_get_checked (image, token, error);
		if (!klass) {
			printf ("Could not load class with token %x due to %s\n", token, mono_error_get_message (error));
			mono_error_cleanup (error);
			continue;
		}
		mono_class_init_internal (klass);
		if (mono_class_has_failure (klass)) {
			ERROR_DECL (type_load_error);
			mono_error_set_for_class_failure (type_load_error, klass);
			printf ("Could not initialize class(0x%08x) %s.%s due to %s\n", token, m_class_get_name_space (klass), m_class_get_name (klass), mono_error_get_message (type_load_error));
			mono_error_cleanup (type_load_error);
			++count;
		}

		mono_class_setup_vtable (klass);
		if (mono_class_has_failure (klass)) {
			ERROR_DECL (type_load_error);
			mono_error_set_for_class_failure (type_load_error, klass);
			printf ("Could not initialize vtable of class(0x%08x) %s.%s due to %s\n", token, m_class_get_name_space (klass), m_class_get_name (klass), mono_error_get_message (type_load_error));
			mono_error_cleanup (type_load_error);
			++count;
		}
	}
	if (count)
		return 5;
	return 0;

invalid_image:
	if (!is_ok (error)) {
		g_print ("FAIL: %s\n", mono_error_get_message (error));
		mono_error_cleanup (error);
		++count;
	}
	if (count)
		g_print ("Error count: %d\n", count);
	return 1;
}