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); }
static gboolean is_system_type (MonoDomain *domain, MonoClass *klass) { if (domain->system_image == NULL) domain->system_image = mono_image_loaded ("System"); return klass->image == domain->system_image; }
static void disasm_method (Package *pkg) { xmono::DisasmMethodReq req; xmono::DisasmMethodRsp rsp; std::string str((char*)pkg->body, pkg->all_len - sizeof (Package)); //Fixme : 修复头部all_len是总长的问题 if (!req.ParseFromString (str)) { LOGD ("xmono::DisasmMethodReq ParseFromString err!"); return; } std::string err(""); MonoMethod *method = get_method_with_token (req.image_name ().c_str (), req.method_token ()); if (!method) err += helper_last_err (); MonoImage *image = mono_image_loaded (req.image_name ().c_str ()); if (!image) err += " image : " + req.image_name () + " can not be find!"; if (image && method) { MemWriter writer(4096); char const *mname = mono_method_full_name (method, 1); if (mname) { writer.sprintf ("//[%s]%s[%08X]\n", get_method_image_name (method), mname, mono_method_get_token (method)); g_free (mname); } MonoMethodHeader *header = mono_method_get_header (method); disassemble_cil (image, header, &writer); /*Fixme : disassemble_cil需要在失败时返回更多信息*/ rsp.set_err (true); LOGD ("writer : %s", writer.getBuffPtr ()); std::string s((char*)writer.getBuffPtr (), writer.getBuffSize ()); rsp.set_disasm_code (s); //这部分只是测试用的 uint32_t asm_size = 0; uint8_t const *p = mono_method_header_get_code (header, &asm_size, 0); std::string asm_code ((char const*)p, asm_size); rsp.set_asm_code (asm_code); } else { rsp.set_err (false); rsp.set_err_str (err); } std::string out; rsp.SerializeToString (&out); ecmd_send (XMONO_ID_DISASM_METHOD_RSP, (uint8_t const*)out.c_str (), out.size ()); return; }
/* * Note that we call it is_socket_type() where 'socket' refers to the image * that contains the System.Net.Sockets.Socket type. * For moonlight there is a System.Net.Sockets.Socket class in both System.dll and System.Net.dll. */ static gboolean is_socket_type (MonoDomain *domain, MonoClass *klass) { static const char *version = NULL; static gboolean moonlight; if (is_system_type (domain, klass)) return TRUE; /* If moonlight, check if the type is in System.Net.dll too */ if (version == NULL) { version = mono_get_runtime_info ()->framework_version; moonlight = !strcmp (version, "2.1"); } if (!moonlight) return FALSE; if (domain->system_net_dll == NULL) domain->system_net_dll = mono_image_loaded ("System.Net"); return klass->image == domain->system_net_dll; }
/* Entry point called by LdrLoadDll of ntdll.dll after _CorValidateImage. */ BOOL STDMETHODCALLTYPE _CorDllMain(HINSTANCE hInst, DWORD dwReason, LPVOID lpReserved) { MonoAssembly* assembly; MonoImage* image; gchar* file_name; gchar* error; switch (dwReason) { case DLL_PROCESS_ATTACH: DisableThreadLibraryCalls (hInst); file_name = mono_get_module_file_name (hInst); if (mono_get_root_domain ()) { image = mono_image_open_from_module_handle (hInst, mono_path_resolve_symlinks (file_name), TRUE, NULL); } else { init_from_coree = TRUE; mono_runtime_load (file_name, NULL); error = (gchar*) mono_check_corlib_version (); if (error) { g_free (error); g_free (file_name); mono_runtime_quit (); return FALSE; } image = mono_image_open (file_name, NULL); if (image) { image->has_entry_point = TRUE; mono_close_exe_image (); /* Decrement reference count to zero. (Image will not be closed.) */ mono_image_close (image); } } if (!image) { g_free (file_name); return FALSE; } /* * FIXME: Find a better way to call mono_image_fixup_vtable. Only * loader trampolines should be used and assembly loading should * probably be delayed until the first call to an exported function. */ if (image->tables [MONO_TABLE_ASSEMBLY].rows && ((MonoCLIImageInfo*) image->image_info)->cli_cli_header.ch_vtable_fixups.rva) assembly = mono_assembly_open (file_name, NULL); g_free (file_name); break; case DLL_PROCESS_DETACH: if (lpReserved != NULL) /* The process is terminating. */ return TRUE; file_name = mono_get_module_file_name (hInst); image = mono_image_loaded (file_name); if (image) mono_image_close (image); g_free (file_name); break; } return TRUE; }
static MonoImage* find_image (char *name) { return mono_image_loaded (name); }