public static void CreateHook(HookDescriptor hook) { try { SynchronizationHelper.BeginDescriptorUpdate(hook); switch (hook.HookType) { case HookType.EventHook: { HookEvent(hook); break; } case HookType.ServiceFunction: { CreateServiceFunction(hook); break; } default: throw new ArgumentException("descriptor"); } } finally { SynchronizationHelper.EndUpdate(hook); } }
private static void CreateServiceFunction(HookDescriptor hook) { if (!ServiceManager.ServiceExists(hook.Name)) { hook.MirandaHandle = MirandaContext.Current.PluginLink.NativePluginLink.CreateServiceFunction(hook.Name, hook.Callback); if (hook.MirandaHandle == IntPtr.Zero) throw new MirandaException(String.Format(TextResources.ExceptionMsg_Formatable1_ServiceFunctionCreationFailed, hook.Name)); } else { if (!hook.Owner.ServiceFunctions.Exists(delegate(HookDescriptor _hook) { return _hook.Equals(hook) && _hook.MirandaHandle != IntPtr.Zero; })) throw new InvalidOperationException(String.Format(TextResources.ExceptionMsg_Formatable1_ServiceFunctionAlreadyExists, hook.Name)); } }
public void AddHook(uint addr, Action<uint> hook) { lock(hooks) { if(!hooks.ContainsKey(addr)) { hooks[addr] = new HookDescriptor(this, addr); } hooks[addr].AddCallback(hook); this.DebugLog("Added hook @ 0x{0:X}", addr); } }
private static void HookEvent(HookDescriptor hook) { hook.MirandaHandle = MirandaContext.Current.PluginLink.NativePluginLink.HookEvent(hook.Name, hook.Callback); if (hook.MirandaHandle == IntPtr.Zero) throw new MirandaException(String.Format(TextResources.ExceptionMsg_Formatable1_EventHookingFailed, hook.Name)); }
private static void DestroyServiceFunction(HookDescriptor descriptor) { if (descriptor == null) throw new ArgumentNullException("descriptor"); if (descriptor.HookType != HookType.ServiceFunction) throw new ArgumentOutOfRangeException("descriptor"); if (descriptor.MirandaHandle == IntPtr.Zero) return; try { SynchronizationHelper.BeginDescriptorUpdate(descriptor); int result = MirandaContext.Current.PluginLink.NativePluginLink.DestroyServiceFunction(descriptor.MirandaHandle); Debug.Assert(result == 0); descriptor.MirandaHandle = IntPtr.Zero; } finally { SynchronizationHelper.EndUpdate(descriptor); } }