Beispiel #1
0
MonoPPDBFile*
mono_ppdb_load_file (MonoImage *image, const guint8 *raw_contents, int size)
{
	MonoImage *ppdb_image = NULL;
	const char *filename;
	char *s, *ppdb_filename;
	MonoImageOpenStatus status;
	guint8 pe_guid [16];
	gint32 pe_age;
	gint32 pe_timestamp;
	MonoPPDBFile *ppdb;

	if (raw_contents) {
		if (size > 4 && strncmp ((char*)raw_contents, "BSJB", 4) == 0)
			ppdb_image = mono_image_open_from_data_internal ((char*)raw_contents, size, TRUE, &status, FALSE, TRUE, NULL);
	} else {
		/* ppdb files drop the .exe/.dll extension */
		filename = mono_image_get_filename (image);
		if (strlen (filename) > 4 && (!strcmp (filename + strlen (filename) - 4, ".exe") || !strcmp (filename + strlen (filename) - 4, ".dll"))) {
			s = g_strdup (filename);
			s [strlen (filename) - 4] = '\0';
			ppdb_filename = g_strdup_printf ("%s.pdb", s);
			g_free (s);
		} else {
			ppdb_filename = g_strdup_printf ("%s.pdb", filename);
		}

		ppdb_image = mono_image_open_metadata_only (ppdb_filename, &status);
		if (!ppdb_image)
			g_free (ppdb_filename);
	}
	if (!ppdb_image)
		return NULL;

	/*
	 * Check that the images match.
	 * The same id is stored in the Debug Directory of the PE file, and in the
	 * #Pdb stream in the ppdb file.
	 */
	if (get_pe_debug_guid (image, pe_guid, &pe_age, &pe_timestamp)) {
		PdbStreamHeader *pdb_stream = (PdbStreamHeader*)ppdb_image->heap_pdb.data;

		g_assert (pdb_stream);

		/* The pdb id is a concentation of the pe guid and the timestamp */
		if (memcmp (pe_guid, pdb_stream->guid, 16) != 0 || memcmp (&pe_timestamp, pdb_stream->guid + 16, 4) != 0) {
			g_warning ("Symbol file %s doesn't match image %s", ppdb_image->name,
					   image->name);
			mono_image_close (ppdb_image);
			return NULL;
		}
	}

	ppdb = g_new0 (MonoPPDBFile, 1);
	ppdb->image = ppdb_image;
	ppdb->doc_hash = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) doc_free);
	ppdb->method_hash = g_hash_table_new_full (NULL, NULL, NULL, (GDestroyNotify) g_free);

	return ppdb;
}
Beispiel #2
0
static void
init_test_set (test_set_t *test_set)
{
	MonoImageOpenStatus status;
	if (test_set->init)
		return;
	test_set->assembly_data = read_whole_file_and_close (test_set->assembly, &test_set->assembly_size);
	test_set->image = mono_image_open_from_data_internal (test_set->assembly_data, test_set->assembly_size, FALSE, &status, FALSE, FALSE, NULL);
	if (!test_set->image || status != MONO_IMAGE_OK) {
		printf ("Could not parse image %s\n", test_set->assembly);
		exit (INVALID_BAD_FILE);
	}
	
	test_set->init = 1;
}