Ejemplo n.º 1
0
        internal bool removeUserHook(UserHook hook)
        {
            if (!isConnected)
            {
                return(false);
            }
            if (!Settings.session.removeUserHook(hook))
            {
                return(false);
            }
            bool   ok             = true;
            Thread removingThread = new Thread(new ThreadStart(() => {
                if (isCompat)
                {
                    ok = TextHookInteropCompat.TextHookRemoveHook(hook.addr) == OK;
                }
                else
                {
                    ok = TextHookInterop.TextHookRemoveHook(hook.addr) == OK;
                }
            }));

            removingThread.IsBackground = true;
            removingThread.Start();
            if (removingThread.Join(1000))
            {
                return(ok);
            }
            else
            {
                removingThread.Abort();
                Logger.log("Freeze trying to remove hook: " + hook.code);
                return(true);
            }
        }
Ejemplo n.º 2
0
        internal bool addUserHook(UserHook userHook)
        {
            if (!isConnected)
            {
                return(false);
            }
            if (Settings.session.isHookAlreadyInstalled(userHook))
            {
                return(false);
            }
            bool ok;

            if (isCompat)
            {
                ok = TextHookInteropCompat.TextHookAddHook(ref userHook.hookParam, userHook.getName()) == OK;
            }
            else
            {
                ok = TextHookInterop.TextHookAddHook(ref userHook.hookParam, userHook.getName()) == OK;
            }
            if (ok)
            {
                Settings.session.addUserHook(userHook);
            }
            return(ok);
        }
Ejemplo n.º 3
0
 public int init(bool isCompat)
 {
     lock (this) {
         if (isInitialized)
         {
             if (this.isCompat == isCompat)
             {
                 return(TextHook.OK);
             }
             else
             {
                 throw new MyException("Initialization error. Please restart Chiitrans Lite and try again.");
             }
         }
         else
         {
             this.isCompat = isCompat;
             try {
                 handleCreateThreadDelegate = new TextHookInterop.OnCreateThreadFunc(handleCreateThread);
                 handleRemoveThreadDelegate = new TextHookInterop.OnRemoveThreadFunc(handleRemoveThread);
                 handleConnectDelegate      = new TextHookInterop.CallbackFunc(handleConnect);
                 handleDisconnectDelegate   = new TextHookInterop.CallbackFunc(handleDisconnect);
                 handleInputDelegate        = new TextHookInterop.OnInputFunc(handleInput);
                 int res;
                 if (isCompat)
                 {
                     TextHookInteropCompat.TextHookOnConnect(handleConnectDelegate);
                     TextHookInteropCompat.TextHookOnCreateThread(handleCreateThreadDelegate);
                     TextHookInteropCompat.TextHookOnRemoveThread(handleRemoveThreadDelegate);
                     TextHookInteropCompat.TextHookOnDisconnect(handleDisconnectDelegate);
                     TextHookInteropCompat.TextHookOnInput(handleInputDelegate);
                     res           = TextHookInteropCompat.TextHookInit();
                     isInitialized = res == TextHook.OK;
                     return(res);
                 }
                 else
                 {
                     TextHookInterop.TextHookOnConnect(handleConnectDelegate);
                     TextHookInterop.TextHookOnCreateThread(handleCreateThreadDelegate);
                     TextHookInterop.TextHookOnRemoveThread(handleRemoveThreadDelegate);
                     TextHookInterop.TextHookOnDisconnect(handleDisconnectDelegate);
                     TextHookInterop.TextHookOnInput(handleInputDelegate);
                     res           = TextHookInterop.TextHookInit();
                     isInitialized = res == TextHook.OK;
                     return(res);
                 }
             } catch (Exception ex) {
                 Logger.logException(ex);
                 return(1);
             }
         }
     }
 }
Ejemplo n.º 4
0
 private void installHooks()
 {
     foreach (UserHook h in Settings.session.getHookList())
     {
         if (isCompat)
         {
             TextHookInteropCompat.TextHookAddHook(ref h.hookParam, h.getName());
         }
         else
         {
             TextHookInterop.TextHookAddHook(ref h.hookParam, h.getName());
         }
     }
 }
Ejemplo n.º 5
0
 public bool connect(int pid)
 {
     if (!isInitialized)
     {
         return(false);
     }
     else
     {
         if (isCompat)
         {
             TextHookInteropCompat.TextHookConnect(pid); // cannot determine success :(
         }
         else
         {
             TextHookInterop.TextHookConnect(pid);
         }
         contexts.Clear();
         isConnected = true;
         return(true);
     }
 }