コード例 #1
0
        internal static IEnumerable<KeyPressEventArgsExt> FromRawDataGlobal(CallbackData data)
        {
            var wParam = data.WParam;
            var lParam = data.LParam;

            if ((int) wParam != Messages.WM_KEYDOWN)
            {
                yield break;
            }

            KeyboardHookStruct keyboardHookStruct =
                (KeyboardHookStruct) Marshal.PtrToStructure(lParam, typeof (KeyboardHookStruct));

            var virtualKeyCode = keyboardHookStruct.VirtualKeyCode;
            var scanCode = keyboardHookStruct.ScanCode;
            var fuState = keyboardHookStruct.Flags;

            if (virtualKeyCode == KeyboardNativeMethods.VK_PACKET)
            {
                var ch = (char) scanCode;
                yield return new KeyPressEventArgsExt(ch, keyboardHookStruct.Time);
            }
            else
            {
                char[] chars;
                KeyboardNativeMethods.TryGetCharFromKeyboardState(virtualKeyCode, scanCode, fuState, out chars);
                if (chars == null) yield break;
                foreach (var current in chars)
                {
                    yield return new KeyPressEventArgsExt(current, keyboardHookStruct.Time);
                }
            }
        }
コード例 #2
0
        internal static KeyEventArgsExt FromRawDataApp(CallbackData data)
        {
            var wParam = data.WParam;
            var lParam = data.LParam;

            //http://msdn.microsoft.com/en-us/library/ms644984(v=VS.85).aspx

            const uint maskKeydown = 0x40000000; // for bit 30
            const uint maskKeyup = 0x80000000; // for bit 31

            int timestamp = Environment.TickCount;

            var flags = (uint) lParam.ToInt64();

            //bit 30 Specifies the previous key state. The value is 1 if the key is down before the message is sent; it is 0 if the key is up.
            bool wasKeyDown = (flags & maskKeydown) > 0;
            //bit 31 Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released.
            bool isKeyReleased = (flags & maskKeyup) > 0;

            Keys keyData = AppendModifierStates((Keys) wParam);

            bool isKeyDown = !wasKeyDown && !isKeyReleased;
            bool isKeyUp = wasKeyDown && isKeyReleased;

            return new KeyEventArgsExt(keyData, timestamp, isKeyDown, isKeyUp);
        }
コード例 #3
0
ファイル: MouseListener.cs プロジェクト: yashodhank/QuasarRAT
        protected override bool Callback(CallbackData data)
        {
            var e = GetEventArgs(data);

            if (e.IsMouseKeyDown)
            {
                ProcessDown(ref e);
            }

            if (e.IsMouseKeyUp)
            {
                ProcessUp(ref e);
            }

            if (e.WheelScrolled)
            {
                ProcessWheel(ref e);
            }

            if (HasMoved(e.Point))
            {
                ProcessMove(ref e);
            }

            return !e.Handled;
        }
コード例 #4
0
        internal static MouseEventExtArgs FromRawDataApp(CallbackData data)
        {
            var wParam = data.WParam;
            var lParam = data.LParam;

            AppMouseStruct marshalledMouseStruct =
                (AppMouseStruct) Marshal.PtrToStructure(lParam, typeof (AppMouseStruct));
            return FromRawDataUniversal(wParam, marshalledMouseStruct.ToMouseStruct());
        }
コード例 #5
0
        internal static KeyEventArgsExt FromRawDataGlobal(CallbackData data)
        {
            var wParam = data.WParam;
            var lParam = data.LParam;
            var keyboardHookStruct =
                (KeyboardHookStruct) Marshal.PtrToStructure(lParam, typeof (KeyboardHookStruct));
            var keyData = AppendModifierStates((Keys) keyboardHookStruct.VirtualKeyCode);

            var keyCode = (int) wParam;
            bool isKeyDown = (keyCode == Messages.WM_KEYDOWN || keyCode == Messages.WM_SYSKEYDOWN);
            bool isKeyUp = (keyCode == Messages.WM_KEYUP || keyCode == Messages.WM_SYSKEYUP);

            return new KeyEventArgsExt(keyData, keyboardHookStruct.Time, isKeyDown, isKeyUp);
        }
コード例 #6
0
ファイル: KeyListener.cs プロジェクト: GeekGalaxy/QuasarRAT
        protected override bool Callback(CallbackData data)
        {
            var eDownUp = GetDownUpEventArgs(data);
            var pressEventArgs = GetPressEventArgs(data);

            InvokeKeyDown(eDownUp);
            foreach (var pressEventArg in pressEventArgs)
            {
                InvokeKeyPress(pressEventArg);    
            }
            
            InvokeKeyUp(eDownUp);

            return !eDownUp.Handled;
        }
コード例 #7
0
ファイル: HookHelper.cs プロジェクト: GeekGalaxy/QuasarRAT
        private static IntPtr HookProcedure(int nCode, IntPtr wParam, IntPtr lParam, Callback callback)
        {
            var passThrough = nCode != 0;
            if (passThrough)
            {
                return CallNextHookEx(nCode, wParam, lParam);
            }

            var callbackData = new CallbackData(wParam, lParam);
            var continueProcessing = callback(callbackData);

            if (!continueProcessing)
            {
                return new IntPtr(-1);
            }

            return CallNextHookEx(nCode, wParam, lParam);
        }
コード例 #8
0
        internal static IEnumerable<KeyPressEventArgsExt> FromRawDataApp(CallbackData data)
        {
            var wParam = data.WParam;
            var lParam = data.LParam;

            //http://msdn.microsoft.com/en-us/library/ms644984(v=VS.85).aspx

            const uint maskKeydown = 0x40000000; // for bit 30
            const uint maskKeyup = 0x80000000; // for bit 31
            const uint maskScanCode = 0xff0000; // for bit 23-16

            var flags = (uint) lParam.ToInt64();

            //bit 30 Specifies the previous key state. The value is 1 if the key is down before the message is sent; it is 0 if the key is up.
            var wasKeyDown = (flags & maskKeydown) > 0;
            //bit 31 Specifies the transition state. The value is 0 if the key is being pressed and 1 if it is being released.
            var isKeyReleased = (flags & maskKeyup) > 0;

            if (!wasKeyDown && !isKeyReleased)
            {
                yield break;
            }

            var virtualKeyCode = (int) wParam;
            var scanCode = checked((int) (flags & maskScanCode));
            const int fuState = 0;

            char[] chars;

            KeyboardNativeMethods.TryGetCharFromKeyboardState(virtualKeyCode, scanCode, fuState, out chars);
            if (chars == null) yield break;
            foreach (var ch in chars)
            {
                yield return new KeyPressEventArgsExt(ch);
            }
        }
コード例 #9
0
 protected override MouseEventExtArgs GetEventArgs(CallbackData data)
 {
     return MouseEventExtArgs.FromRawDataGlobal(data);
 }
コード例 #10
0
ファイル: KeyListener.cs プロジェクト: GeekGalaxy/QuasarRAT
 protected abstract KeyEventArgsExt GetDownUpEventArgs(CallbackData data);
コード例 #11
0
ファイル: KeyListener.cs プロジェクト: GeekGalaxy/QuasarRAT
 protected abstract IEnumerable<KeyPressEventArgsExt> GetPressEventArgs(CallbackData data);
コード例 #12
0
 protected override KeyEventArgsExt GetDownUpEventArgs(CallbackData data)
 {
     return KeyEventArgsExt.FromRawDataGlobal(data);
 }
コード例 #13
0
 protected override IEnumerable<KeyPressEventArgsExt> GetPressEventArgs(CallbackData data)
 {
     return KeyPressEventArgsExt.FromRawDataGlobal(data);
 }
コード例 #14
0
ファイル: BaseListener.cs プロジェクト: yashodhank/QuasarRAT
 protected abstract bool Callback(CallbackData data);
コード例 #15
0
ファイル: MouseListener.cs プロジェクト: yashodhank/QuasarRAT
 protected abstract MouseEventExtArgs GetEventArgs(CallbackData data);