public static T MethodHook <T>(Class cls, Selector sel, T imp) where T : class { if (imp is Delegate) { MethodHookInfo info; string name = cls.Name + "|" + sel.Name; if (_mHookList.ContainsKey(name)) { info = _mHookList[name]; info.hook_imp = imp as Delegate; Objc.class_replaceMethod(cls.Handle, sel.Handle, Marshal.GetFunctionPointerForDelegate(info.hook_imp), "@:"); } else { info = new MethodHookInfo(); info.imp_type = typeof(T); info.hook_imp = imp as Delegate; info.old_imp = Objc.class_replaceMethod(cls.Handle, sel.Handle, Marshal.GetFunctionPointerForDelegate(info.hook_imp), "@:"); _mHookList.Add(name, info); } if (info.old_imp != IntPtr.Zero) { return(Marshal.GetDelegateForFunctionPointer(info.old_imp, typeof(T)) as T); } } return(null); }
public static Class GetClass(string name) { IntPtr cls = Objc.objc_getClass(name); if (cls != IntPtr.Zero) { return(new Class(cls)); } return(null); }
public static void MethodUnhook(Class cls, Selector sel) { string name = cls.Name + "|" + sel.Name; if (_mHookList.ContainsKey(name)) { MethodHookInfo info = _mHookList[name]; Objc.class_replaceMethod(cls.Handle, sel.Handle, info.old_imp, "@:"); _mHookList.Remove(name); } }
public static Method[] GetMethods(Class cls) { List <Method> list = new List <Method>(); int count; IntPtr pList = Objc.class_copyMethodList(cls.Handle, out count); if (pList != IntPtr.Zero) { for (int i = 0; i < count; i++) { IntPtr m = Marshal.ReadIntPtr(pList, i * IntPtr.Size); list.Add(new Method(m)); } Objc.free(pList); } return(list.ToArray()); }
public static void NSLog(string format, params object[] args) { NSString s = new NSString(string.Format(format, args)); Objc.NSLog(s.Handle); }