Esempio n. 1
0
void invoke_protected_memory_method (MonoArray *data, MonoObject *scope, gboolean encrypt)
{
    MonoClass *klass;
    MonoMethod *method;
    void *params [2];

    MONO_ARCH_SAVE_REGS;

    if (system_security_assembly == NULL) {
        system_security_assembly = mono_image_loaded ("System.Security");
        if (!system_security_assembly) {
            MonoAssembly *sa = mono_assembly_open ("System.Security.dll", NULL);
            if (!sa)
                g_assert_not_reached ();
            system_security_assembly = mono_assembly_get_image (sa);
        }
    }

    klass = mono_class_from_name (system_security_assembly,
                                  "System.Security.Cryptography", "ProtectedMemory");
    method = mono_class_get_method_from_name (klass, encrypt ? "Protect" : "Unprotect", 2);
    params [0] = data;
    params [1] = scope; /* MemoryProtectionScope.SameProcess */
    mono_runtime_invoke (method, NULL, params, NULL);
}
Esempio n. 2
0
static HRESULT RuntimeHost_GetIUnknownForDomain(RuntimeHost *This, MonoDomain *domain, IUnknown **punk)
{
    HRESULT hr;
    void *args[1];
    MonoAssembly *assembly;
    MonoImage *image;
    MonoClass *klass;
    MonoMethod *method;
    MonoObject *appdomain_object;
    IUnknown *unk;

    mono_thread_attach(domain);

    assembly = mono_domain_assembly_open(domain, "mscorlib");
    if (!assembly)
    {
        ERR("Cannot load mscorlib\n");
        return E_FAIL;
    }

    image = mono_assembly_get_image(assembly);
    if (!image)
    {
        ERR("Couldn't get assembly image\n");
        return E_FAIL;
    }

    klass = mono_class_from_name(image, "System", "AppDomain");
    if (!klass)
    {
        ERR("Couldn't get class from image\n");
        return E_FAIL;
    }

    method = mono_class_get_method_from_name(klass, "get_CurrentDomain", 0);
    if (!method)
    {
        ERR("Couldn't get method from class\n");
        return E_FAIL;
    }

    args[0] = NULL;
    appdomain_object = mono_runtime_invoke(method, NULL, args, NULL);
    if (!appdomain_object)
    {
        ERR("Couldn't get result pointer\n");
        return E_FAIL;
    }

    hr = RuntimeHost_GetIUnknownForObject(This, appdomain_object, &unk);

    if (SUCCEEDED(hr))
    {
        hr = IUnknown_QueryInterface(unk, &IID__AppDomain, (void**)punk);

        IUnknown_Release(unk);
    }

    return hr;
}
Esempio n. 3
0
MonoException *
mono_get_exception_runtime_wrapped_checked (MonoObject *wrapped_exception, MonoError *error)
{
	MonoClass *klass;
	MonoObject *o;
	MonoMethod *method;
	MonoDomain *domain = mono_domain_get ();
	gpointer params [16];

	klass = mono_class_load_from_name (mono_get_corlib (), "System.Runtime.CompilerServices", "RuntimeWrappedException");

	o = mono_object_new_checked (domain, klass, error);
	mono_error_assert_ok (error);
	g_assert (o != NULL);

	method = mono_class_get_method_from_name (klass, ".ctor", 1);
	g_assert (method);

	params [0] = wrapped_exception;

	mono_runtime_invoke_checked (method, o, params, error);
	return_val_if_nok (error, NULL);

	return (MonoException *)o;
}	
Esempio n. 4
0
MonoMethod* find_method(MonoClass* klass, const char* name)
{
	MonoMethod* method = mono_class_get_method_from_name(klass, name, -1);
	if (!method) return NULL;

	return method;
}
Esempio n. 5
0
void MonoEmbedding::Initialize()
{
    // Construct the absolute file path to MonoEmbedding.exe assuming
    // it is located next to edge.node
    Dl_info dlinfo;
    char fullPath[PATH_MAX];
    dladdr((void*)&MonoEmbedding::Initialize, &dlinfo);
    strcpy(fullPath, dlinfo.dli_fname);
    strcpy(fullPath, dirname(fullPath));
    strcat(fullPath, "/MonoEmbedding.exe");

    mono_jit_init (fullPath);
    assembly = mono_domain_assembly_open (mono_domain_get(), fullPath);
    MonoClass* klass = mono_class_from_name(mono_assembly_get_image(assembly), "", "MonoEmbedding");
    MonoMethod* main = mono_class_get_method_from_name(klass, "Main", -1);
    MonoException* exc;
    MonoArray* args = mono_array_new(mono_domain_get(), mono_get_string_class(), 0);
    mono_runtime_exec_main(main, args, (MonoObject**)&exc);

    mono_add_internal_call("ClrFuncInvokeContext::CompleteOnV8ThreadAsynchronousICall", (const void*)&ClrFuncInvokeContext::CompleteOnV8ThreadAsynchronous); 
    mono_add_internal_call("ClrFuncInvokeContext::CompleteOnCLRThreadICall", (const void*)&ClrFuncInvokeContext::CompleteOnCLRThread); 
    mono_add_internal_call("NodejsFuncInvokeContext::CallFuncOnV8ThreadInternal", (const void*)&NodejsFuncInvokeContext::CallFuncOnV8Thread); 
    mono_add_internal_call("NodejsFunc::ExecuteActionOnV8Thread", (const void*)&NodejsFunc::ExecuteActionOnV8Thread); 
    mono_add_internal_call("NodejsFunc::Release", (const void*)&NodejsFunc::Release); 
}
Esempio n. 6
0
MonoException *
mono_get_exception_runtime_wrapped (MonoObject *wrapped_exception)
{
	MonoError error;
	MonoClass *klass;
	MonoObject *o;
	MonoMethod *method;
	MonoDomain *domain = mono_domain_get ();
	gpointer params [16];

	klass = mono_class_load_from_name (mono_get_corlib (), "System.Runtime.CompilerServices", "RuntimeWrappedException");

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

	method = mono_class_get_method_from_name (klass, ".ctor", 1);
	g_assert (method);

	params [0] = wrapped_exception;

	mono_runtime_invoke_checked (method, o, params, &error);
	mono_error_raise_exception (&error); /* FIXME don't raise here */

	return (MonoException *)o;
}	
Esempio n. 7
0
/* Get an IUnknown pointer for a Mono object.
 *
 * This is just a "light" wrapper around
 * System.Runtime.InteropServices.Marshal:GetIUnknownForObject
 *
 * NOTE: The IUnknown* is created with a reference to the object.
 * Until they have a reference, objects must be in the stack to prevent the
 * garbage collector from freeing them.
 *
 * mono_thread_attach must have already been called for this thread. */
HRESULT RuntimeHost_GetIUnknownForObject(RuntimeHost *This, MonoObject *obj,
    IUnknown **ppUnk)
{
    MonoDomain *domain;
    MonoAssembly *assembly;
    MonoImage *image;
    MonoClass *klass;
    MonoMethod *method;
    MonoObject *result;
    void *args[2];

    domain = mono_object_get_domain(obj);

    assembly = mono_domain_assembly_open(domain, "mscorlib");
    if (!assembly)
    {
        ERR("Cannot load mscorlib\n");
        return E_FAIL;
    }

    image = mono_assembly_get_image(assembly);
    if (!image)
    {
        ERR("Couldn't get assembly image\n");
        return E_FAIL;
    }

    klass = mono_class_from_name(image, "System.Runtime.InteropServices", "Marshal");
    if (!klass)
    {
        ERR("Couldn't get class from image\n");
        return E_FAIL;
    }

    method = mono_class_get_method_from_name(klass, "GetIUnknownForObject", 1);
    if (!method)
    {
        ERR("Couldn't get method from class\n");
        return E_FAIL;
    }

    args[0] = obj;
    args[1] = NULL;
    result = mono_runtime_invoke(method, NULL, args, NULL);
    if (!result)
    {
        ERR("Couldn't get result pointer\n");
        return E_FAIL;
    }

    *ppUnk = *(IUnknown**)mono_object_unbox(result);
    if (!*ppUnk)
    {
        ERR("GetIUnknownForObject returned 0\n");
        return E_FAIL;
    }

    return S_OK;
}
Esempio n. 8
0
MonoString* MonoEmbedding::ToString(MonoObject* o, MonoException** exc)
{
    static MonoMethod* method;
    *exc = NULL;

    if (!method)
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "ObjectToString", -1);

    void* args[] = { o };

    return (MonoString*)mono_runtime_invoke(method, NULL, args, (MonoObject**)exc);
}
Esempio n. 9
0
MonoString* MonoEmbedding::TryConvertPrimitiveOrDecimal(MonoObject* obj, MonoException** exc)
{
    static MonoMethod* method;
    *exc = NULL;

    if (!method)
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "TryConvertPrimitiveOrDecimal", -1);

    void* args[] = { obj };

    return (MonoString*)mono_runtime_invoke(method, NULL, args, (MonoObject**)exc);
}
Esempio n. 10
0
MonoObject* NodejsFunc::GetFunc()
{
    static MonoMethod* method;

    if (!method)
        method = mono_class_get_method_from_name(GetNodejsFuncClass(), "GetFunc", -1);

    MonoException* exc = NULL;
    MonoObject* func = mono_runtime_invoke(method, mono_gchandle_get_target(_this), NULL, (MonoObject**)&exc);

    return func;
}
Esempio n. 11
0
void RuntimeHost_ExitProcess(RuntimeHost *This, INT exitcode)
{
    HRESULT hr;
    void *args[2];
    MonoDomain *domain;
    MonoAssembly *assembly;
    MonoImage *image;
    MonoClass *klass;
    MonoMethod *method;

    hr = RuntimeHost_GetDefaultDomain(This, &domain);
    if (FAILED(hr))
    {
        ERR("Cannot get domain, hr=%x\n", hr);
        return;
    }

    mono_thread_attach(domain);

    assembly = mono_domain_assembly_open(domain, "mscorlib");
    if (!assembly)
    {
        ERR("Cannot load mscorlib\n");
        return;
    }

    image = mono_assembly_get_image(assembly);
    if (!image)
    {
        ERR("Couldn't get assembly image\n");
        return;
    }

    klass = mono_class_from_name(image, "System", "Environment");
    if (!klass)
    {
        ERR("Couldn't get class from image\n");
        return;
    }

    method = mono_class_get_method_from_name(klass, "Exit", 1);
    if (!method)
    {
        ERR("Couldn't get method from class\n");
        return;
    }

    args[0] = &exitcode;
    args[1] = NULL;
    mono_runtime_invoke(method, NULL, args, NULL);

    ERR("Process should have exited\n");
}
Esempio n. 12
0
G_MODULE_EXPORT void
theme_exit ()
{
    MaigreMonoBridge *bridge = maigre_mono_bridge ();
    MonoClass *klass;
    MonoMethod *method;

    if (bridge != NULL &&
        (klass = mono_class_from_name (bridge->image, "Maigre", "ThemeModule")) != NULL &&
        (method = mono_class_get_method_from_name (klass, "Exit", 0)) != NULL) {
        mono_runtime_invoke (method, NULL, NULL, NULL);
   }
}
Esempio n. 13
0
MonoObject* MonoEmbedding::CreateExpandoObject()
{
    static MonoMethod* method;
    MonoException* exc = NULL;

    if (!method)
    {
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "CreateExpandoObject", -1);
    }
    MonoObject* dictionary = mono_runtime_invoke(method, NULL, NULL, (MonoObject**)&exc);

    return dictionary;
}
Esempio n. 14
0
void MonoEmbedding::ContinueTask(MonoObject* task, MonoObject* state, MonoException** exc)
{
    static MonoMethod* method;
    *exc = NULL;

    if (!method)
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "ContinueTask", -1);

    void* args[2];
    args[0] = task;
    args[1] = state;
    mono_runtime_invoke(method, NULL, args, (MonoObject**)exc);
}
Esempio n. 15
0
MonoClass* MonoEmbedding::GetFuncClass()
{
    static MonoMethod* method;
    MonoException* exc = NULL;

    if (!method)
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "GetFuncType", -1);

    MonoReflectionType* typeObject = (MonoReflectionType*)mono_runtime_invoke(method, NULL, NULL, (MonoObject**)&exc);
    MonoType* type = mono_reflection_type_get_type(typeObject);
    MonoClass* klass = mono_class_from_mono_type(type);
    return klass;
}
Esempio n. 16
0
void CPipeServer::FindMethod()
{
	void *klass=(void *)ReadQword();
	WORD length=ReadWord();
	char *methodname=(char *)malloc(length+1);
	void *method=NULL;
	if (length)
		Read(methodname, length);
	methodname[length]=0;

	
	method=mono_class_get_method_from_name(klass, methodname, -1);
	WriteQword((UINT_PTR)method);
}
Esempio n. 17
0
double MonoEmbedding::Int64ToDouble(MonoObject* i64, MonoException** exc)
{
    static MonoMethod* method;
    *exc = NULL;

    if (!method)
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "Int64ToDouble", -1);

    void* args[] = { mono_object_unbox(i64) };

    MonoObject* obj = mono_runtime_invoke(method, NULL, args, (MonoObject**)exc);
    if (*exc)
        return 0.0;
    return *(double*)mono_object_unbox(obj);
}
Esempio n. 18
0
MonoArray* MonoEmbedding::IDictionaryToFlatArray(MonoObject* dictionary, MonoException** exc)
{
    static MonoMethod* method;
    *exc = NULL;

    if (!method)
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "IDictionaryToFlatArray", -1);

    void* args[1];
    args[0] = dictionary;
    MonoArray* values = (MonoArray*)mono_runtime_invoke(method, NULL, args, (MonoObject**)exc);
    if(*exc)
        return NULL;
    return values;
}
Esempio n. 19
0
void Dictionary::Add(MonoObject* _this, const char* name, MonoObject* value)
{
    static MonoMethod* add;
    
    if(!add) {
        add = mono_class_get_method_from_name(mono_object_get_class(_this), 
            "System.Collections.Generic.IDictionary<string,object>.Add", -1);
    }

    void* params[2];
    params[0] = mono_string_new(mono_domain_get(), name);
    params[1] = value;

    mono_runtime_invoke(add, _this, params, NULL);
}
Esempio n. 20
0
MonoObject* MonoEmbedding::CreateDateTime(double ticks) 
{
    static MonoMethod* method;
    MonoException* exc = NULL;

    if (!method)
    {
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "CreateDateTime", -1);
    }

    void* args[] = { &ticks };
    MonoObject* ret = mono_runtime_invoke(method, NULL, args, (MonoObject**)&exc);

    return ret;
}
Esempio n. 21
0
void ClrFuncInvokeContext::InitializeAsyncOperation()
{
    // Create a uv_edge_async instance representing V8 async operation that will complete 
    // when the CLR function completes. The ClrActionContext is used to ensure the ClrFuncInvokeContext
    // remains GC-rooted while the CLR function executes.

    static MonoMethod* getAction = NULL;
    if (!getAction)
        getAction = mono_class_get_method_from_name(
            GetClrFuncInvokeContextClass(), "GetCompleteOnV8ThreadAsynchronousAction", -1);
    
    ClrActionContext* data = new ClrActionContext;
    data->action = mono_gchandle_new( // released in ClrActionContext::ActionCallback
        mono_runtime_invoke(getAction, mono_gchandle_get_target(this->_this), NULL, NULL), FALSE);
    this->uv_edge_async = V8SynchronizationContext::RegisterAction(ClrActionContext::ActionCallback, data);
}
Esempio n. 22
0
/*
 * Context propagation is required when:
 * (a) the security manager is active (1.x and later)
 * (b) other contexts needs to be propagated (2.x and later)
 *
 * returns NULL if no context propagation is required, else the returns the
 * MonoMethod to call to Capture the ExecutionContext.
 */
MonoMethod*
mono_get_context_capture_method (void)
{
	static MonoMethod *method = NULL;

	if (mono_image_get_assembly (mono_defaults.corlib)->aname.major < 2)
		return NULL;

	/* older corlib revisions won't have the class (nor the method) */
	MonoClass *execution_context = mono_class_try_get_execution_context_class ();
	if (execution_context && !method) {
		mono_class_init (execution_context);
		method = mono_class_get_method_from_name (execution_context, "Capture", 0);
	}

	return method;
}
Esempio n. 23
0
void MonoEmbedding::NormalizeException(MonoException** e) 
{
    static MonoMethod* method;

    if (!method)
    {
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "NormalizeException", -1);
    }

    void *params[] = { *e };
    MonoException *exc = NULL;
    MonoException *en = (MonoException*)mono_runtime_invoke(method, NULL, params, (MonoObject**)exc);
    if (NULL == exc)
    {
        *e = en;
    }
}
Esempio n. 24
0
/*
 * plmono_trigger_build_args
 *
 *     Create TableRow object based trigger's "OLD" row tuple
 */
void
plmono_trigger_build_args(TriggerData *trigdata, MonoObject *cols)
{
	MonoClass *rowklass;
	MonoClass *objklass;
	MonoMethod* additem;
	TupleDesc resdesc;
	gpointer kvpair[2];
	char *attname;
	Oid atttype;
	Datum *atts;
	bool *nulls;
	gpointer val;
	int i;

	resdesc = trigdata->tg_relation->rd_att;

	if (!(atts = palloc(resdesc->natts * sizeof(Datum))))
		elog(ERROR, "Not enough memory");

	if (!(nulls = palloc(resdesc->natts * sizeof(bool))))
		elog(ERROR, "Not enough memory");

	heap_deform_tuple(trigdata->tg_trigtuple, resdesc, atts, nulls);

	rowklass = mono_object_get_class(cols);
	additem = mono_class_get_method_from_name(rowklass, "Add", 2);

	for (i = 0; i < resdesc->natts; i++)
	{
		attname = NameStr(resdesc->attrs[i]->attname);
		atttype = resdesc->attrs[i]->atttypid;
		val = plmono_datum_to_obj(atts[i], atttype);

		objklass = plmono_typeoid_to_class(atttype);
		kvpair[0] = mono_string_new(plmono_get_domain(), attname); /* attribute name */
		//elog(ERROR, "Val %p ObjClass %p", val, objklass);

		if (atttype != TEXTOID)
			kvpair[1] = mono_value_box(plmono_get_domain(), objklass, val); /* attribute value */
		else
			kvpair[1] = val;

		mono_runtime_invoke(additem, cols, kvpair, NULL);
	}
}
Esempio n. 25
0
MonoObject* MonoEmbedding::GetClrFuncReflectionWrapFunc(const char* assemblyFile, const char* typeName, const char* methodName, MonoException ** exc)
{
    static MonoMethod* method;
    void* params[3];

    if (!method)
    {
        method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "GetFunc", 3);
    }

    params[0] = mono_string_new(mono_domain_get(), assemblyFile);
    params[1] = mono_string_new(mono_domain_get(), typeName);
    params[2] = mono_string_new(mono_domain_get(), methodName);
    MonoObject* action = mono_runtime_invoke(method, NULL, params, (MonoObject**)exc);

    return action;
}
Esempio n. 26
0
static void
do_console_cancel_event (void)
{
	static MonoClassField *cancel_handler_field;
	MonoError error;
	MonoDomain *domain = mono_domain_get ();
	MonoClass *klass;
	MonoDelegate *load_value;
	MonoMethod *method;
	MonoVTable *vtable;

	/* FIXME: this should likely iterate all the domains, instead */
	if (!domain->domain)
		return;

	klass = mono_class_try_load_from_name (mono_defaults.corlib, "System", "Console");
	if (klass == NULL)
		return;

	if (cancel_handler_field == NULL) {
		cancel_handler_field = mono_class_get_field_from_name (klass, "cancel_handler");
		g_assert (cancel_handler_field);
	}

	vtable = mono_class_vtable_full (domain, klass, &error);
	if (vtable == NULL || !is_ok (&error)) {
		mono_error_cleanup (&error);
		return;
	}
	mono_field_static_get_value_checked (vtable, cancel_handler_field, &load_value, &error);
	if (load_value == NULL || !is_ok (&error)) {
		mono_error_cleanup (&error);
		return;
	}

	klass = load_value->object.vtable->klass;
	method = mono_class_get_method_from_name (klass, "BeginInvoke", -1);
	g_assert (method != NULL);

	mono_threadpool_ms_begin_invoke (domain, (MonoObject*) load_value, method, NULL, &error);
	if (!is_ok (&error)) {
		g_warning ("Couldn't invoke System.Console cancel handler due to %s", mono_error_get_message (&error));
		mono_error_cleanup (&error);
	}
}
Esempio n. 27
0
NodejsFunc::NodejsFunc(Handle<Function> function)
{
    DBG("NodejsFunc::NodejsFunc");

    static MonoMethod* ctor;
    if (!ctor)
        ctor = mono_class_get_method_from_name(GetNodejsFuncClass(), ".ctor", -1);

    this->Func = new Persistent<Function>;
    NanAssignPersistent(*(this->Func), function);

    MonoObject* thisObj = mono_object_new(mono_domain_get(), GetNodejsFuncClass());
    MonoException* exc = NULL;
    void *thisPtr = this;
    void *args[] = { &thisPtr };
    mono_runtime_invoke(ctor, thisObj, args, (MonoObject**)&exc);
    _this = mono_gchandle_new_weakref(thisObj, FALSE);
}
Esempio n. 28
0
MonoClass* MonoEmbedding::GetUriClass(MonoException** exc) 
{
    static MonoClass* klass;
    *exc = NULL;

    if (!klass)
    {
        MonoMethod* method = mono_class_get_method_from_name(MonoEmbedding::GetClass(), "GetUriType", -1);
        MonoReflectionType* typeObject = (MonoReflectionType*)mono_runtime_invoke(method, NULL, NULL, (MonoObject**)exc);
        if(*exc)
            return NULL;

        MonoType* type = mono_reflection_type_get_type(typeObject);
        klass = mono_class_from_mono_type(type);
    }

    return klass;    
}
bool SharpSource::SDK_OnLoad(char *error, size_t maxlength, bool late)
{
  domain = mono_jit_init(library);
  assembly = mono_domain_assembly_open(domain, library);
  char cwd[1024];

  if (!assembly) {
    strcpy(error, "Can't find the .NET assembly file in the sharpmod directory");
    return false;
  }

  MonoImage *image = mono_assembly_get_image(assembly);
  if (!image) {
    strcpy(error, "Can't load the assembly image");
    return false;
  }

  MonoClass *metamod_class = mono_class_from_name(image, "AlliedMods", "Core");

  if (!metamod_class) {
    strcpy(error, "Can't find the class SharpSource::MainClass in the provided assembly");
    return false;
  }

  MonoMethod *init = mono_class_get_method_from_name(metamod_class, "Init", 5);

  if (!init) {
    strcpy(error, "Can't find the method Init in MainClass");
    return false;
  }

  void *args[5];
  args[0] = &smutils;
  args[1] = &sharesys;
  args[2] = &myself;
  args[3] = &playerhelpers;
  args[4] = &timersys;
  mono_runtime_invoke(init, NULL, args, NULL);

  return true;
}
Esempio n. 30
0
G_MODULE_EXPORT void
theme_init (GTypeModule *module)
{
    MaigreMonoBridge *bridge = maigre_mono_bridge ();
    MonoClass *klass;
    MonoMethod *method;

    if (bridge == NULL) {
        g_warning ("Maigre failed to initialize. Default internal "
            "GtkRcStyle/GtkStyle will be used.");
        return;
    }

    maigre_rc_style_register_types (module);

    if (bridge != NULL &&
        (klass = mono_class_from_name (bridge->image, "Maigre", "ThemeModule")) != NULL &&
        (method = mono_class_get_method_from_name (klass, "Init", 0)) != NULL) {
        mono_runtime_invoke (method, NULL, NULL, NULL);
   }
}