Пример #1
0
/*
 * Load an IL image from an input stream and verify all of its methods.
 */
static int verify(const char *filename, ILContext *context, int allowUnsafe)
{
	ILImage *image;
	ILMethod *method;
	ILMethodCode code;
	int result;
	unsigned char *start;

	/* Attempt to load the image into memory */
	if(ILImageLoadFromFile(filename, context, &image,
						   IL_LOADFLAG_FORCE_32BIT, 1) != 0)
	{
		return 0;
	}

	/* Scan the entire MethodDef table and verify everything we find */
	method = 0;
	while((method = (ILMethod *)ILImageNextToken
				(image, IL_META_TOKEN_METHOD_DEF, (void *)method)) != 0)
	{
		/* Skip this method if it does not have IL bytecode */
		if(!ILMethod_RVA(method))
		{
			continue;
		}

		/* Get the IL bytecode for the method */
		if(!ILMethodGetCode(method, &code))
		{
			printError(image, method, "malformed code");
			continue;
		}

		/* Verify the method */
		result = _ILVerify(&_ILNullCoder, &start, method,
						   &code, allowUnsafe, 0);
		if(!result)
		{
			printError(image, method, "could not verify code");
		}
	}

	/* Clean up and exit */
	ILImageDestroy(image);
	return 0;
}
Пример #2
0
/*
 * private static void CreateAppDomain(ref Object appDomain);
 */
void _IL_AppDomain_CreateAppDomain(ILExecThread *thread, ILObject **appDomain)
{
#ifdef IL_CONFIG_APPDOMAINS
	ILExecProcess *process = ILExecProcessCreate(0, 0);
	
	if (process)
	{
		int error;
		ILImage *corlibImage;
		/* load the same corlib assembly as the default appdomain */
		/* first get the corlib image of the default appdomain */
		ILImage *image = ILContextGetSystem(ILExecEngineInstance()->defaultProcess->context);

		if((error = ILImageLoadFromFile(ILImageGetFileName(image),
										process->context,
										&corlibImage,
										process->loadFlags, 0)))
		{
			ILExecThreadThrowSystem(thread, "System.IO.FileNotFoundException", 0);
		}
		else
		{
			 _ILExecProcessLoadStandard(process, corlibImage);
			/* return the new process */
			*appDomain = (ILObject *)process;
		}
	}
	else
	{
		ILExecThreadThrowOutOfMemory(thread);
	}
#else
	/* we don't support multiple Appdomains so return the current process of the thread */
	*appDomain = (ILNativeInt)((void *)thread->process);
#endif
}
Пример #3
0
/*
 * internal static Assembly LoadFromFile(String name, out int error,
 *										 Assembly parent);
 */
ILObject *_IL_AppDomain_LoadFromFile(ILExecThread *thread,
									ILObject *appDomain,
									ILString *name,
									ILInt32 *error,
									ILObject *parent)
{
	if(!IsAppDomainUnloaded(thread, (ILExecProcess *)appDomain))
	{
		char *filename;
		ILImage *image;
		int loadError;

		/* Convert the name into a NUL-terminated filename string */
		filename = ILStringToAnsi(thread, name);
		if(!filename)
		{
			*error = LoadError_FileNotFound;
			return 0;
		}

		/* TODO: validate the pathname */
		if(*filename == '\0')
		{
			*error = LoadError_InvalidName;
			return 0;
		}

		/* TODO: check security permissions */

		/* Load from context if it exists already */

		image = ILContextGetFile(((ILExecProcess *)appDomain)->context, filename);

		if(image != NULL)
		{
			*error = LoadError_OK;
			return ImageToAssembly(thread, image);
		}

		/* Attempt to load the file */
		loadError = ILImageLoadFromFile(filename, ((ILExecProcess *)appDomain)->context,
									&image, IL_LOADFLAG_FORCE_32BIT, 0);
		if(loadError == 0)
		{
			*error = LoadError_OK;
			return ImageToAssembly(thread, image);
		}

		/* Convert the error code into something the C# library knows about */
		if(loadError == -1)
		{
			*error = LoadError_FileNotFound;
		}
		else if(loadError == IL_LOADERR_MEMORY)
		{
			*error = LoadError_FileNotFound;
			ILExecThreadThrowOutOfMemory(thread);
		}
		else
		{
			*error = LoadError_BadImage;
		}
	}
	return 0;
}