private IntPtr OpenImageFromData(byte[] assembly) { IntPtr statusPtr = _memory.Allocate(4); IntPtr addr = Native.VirtualAllocEx(_handle, IntPtr.Zero, assembly.Length, AllocationType.MEM_COMMIT, MemoryProtection.PAGE_READWRITE); if (addr == IntPtr.Zero) { throw new InjectorException("Failed to allocate process memory", new Win32Exception(Marshal.GetLastWin32Error())); } _memory.Write(addr, assembly); IntPtr rawImage = Execute(Exports[mono_image_open_from_data], addr, (IntPtr)assembly.Length, (IntPtr)0, statusPtr ); MonoImageOpenStatus status = (MonoImageOpenStatus)_memory.ReadInt(statusPtr); if (status != MonoImageOpenStatus.MONO_IMAGE_OK) { IntPtr messagePtr = Execute(Exports[mono_image_strerror], (IntPtr)status); string message = _memory.ReadString(messagePtr, 256, Encoding.UTF8); throw new InjectorException($"{mono_image_open_from_data}() failed: {message}"); } _memory.Write(addr, new byte[ClearHeaderBytes]); return(rawImage); }
private IntPtr OpenAssemblyFromImage(IntPtr image) { IntPtr statusPtr = _memory.Allocate(4); IntPtr assembly = Execute(Exports[mono_assembly_load_from_full], image, _memory.AllocateAndWrite(new byte[1]), statusPtr, IntPtr.Zero); MonoImageOpenStatus status = (MonoImageOpenStatus)_memory.ReadInt(statusPtr); if (status != MonoImageOpenStatus.MONO_IMAGE_OK) { IntPtr messagePtr = Execute(Exports[mono_image_strerror], (IntPtr)status); string message = _memory.ReadString(messagePtr, 256, Encoding.UTF8); throw new InjectorException($"{mono_assembly_load_from_full}() failed: {message}"); } return(assembly); }
private IntPtr OpenImageFromData(byte[] assembly) { IntPtr statusPtr = _memory.Allocate(4); IntPtr rawImage = Execute(Exports[mono_image_open_from_data], _memory.AllocateAndWrite(assembly), (IntPtr)assembly.Length, (IntPtr)1, statusPtr); MonoImageOpenStatus status = (MonoImageOpenStatus)_memory.ReadInt(statusPtr); if (status != MonoImageOpenStatus.MONO_IMAGE_OK) { IntPtr messagePtr = Execute(Exports[mono_image_strerror], (IntPtr)status); string message = _memory.ReadString(messagePtr, 256, Encoding.UTF8); throw new InjectorException($"{mono_image_open_from_data}() failed: {message}"); } return(rawImage); }