ToUInt32() public méthode

public ToUInt32 ( ) : uint
Résultat uint
Exemple #1
0
        private IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam)
        {
            if (nCode >= 0)
                if (wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_KEYDOWN ||
                    wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_KEYUP ||
                    wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_SYSKEYDOWN ||
                    wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_SYSKEYUP)
                    _hookedKeyboardCallbackAsync.BeginInvoke((InterceptKeys.KeyEvent)wParam.ToUInt32(), Marshal.ReadInt32(lParam), null, null);

            return InterceptKeys.CallNextHookEx(_hookId, nCode, wParam, lParam);
        }
Exemple #2
0
        /// <summary>
        /// Decompresses data with <paramref name="size"/> at <paramref name="offset"/> in <paramref name="buffer"/>
        /// </summary>
        /// <param name="buffer">The compressed data buffer</param>
        /// <param name="offset">The offset of the compressed data</param>
        /// <param name="size">The size of the compressed data</param>
        /// <param name="uncompressedSize">Uncompressed size of <paramref name="buffer"/></param>
        /// <returns>The uncompressed buffer</returns>
        /// <remarks>If you do not know the uncompressed size then it is recommended to use <see cref="ZstdStream"/></remarks>
        public static byte[] Decompress(byte[] buffer, int offset, int size, int uncompressedSize)
        {
            ValidateDecompressionArguments(buffer.Length, offset, size, uncompressedSize);

            // Allocate uncompressed buffer
            byte[] uncompressedBuffer = new byte[uncompressedSize];

            Size uncompressedBufferSize = Size.Zero;

            unsafe
            {
                fixed(byte *uncompressedBufferPtr = uncompressedBuffer)
                fixed(byte *compressedBufferPtr = buffer)
                {
                    uncompressedBufferSize = Native.ZSTD_decompress(
                        (IntPtr)uncompressedBufferPtr, (Size)uncompressedSize,
                        (IntPtr)(compressedBufferPtr + offset), (Size)size);
                }
            }

            // Check for errors
            ThrowOnError(uncompressedBufferSize);

            // Check for possiblity that user passed in higher than required uncompressed size
            if (uncompressedSize != uncompressedBufferSize.ToUInt32())
            {
                Array.Resize(ref uncompressedBuffer, (int)uncompressedBufferSize);
            }

            return(uncompressedBuffer);
        }
 public static UIntPtr KeyboardHook(int nCode, UIntPtr wParam, IntPtr lParam)
 {
     try
     {
         if (nCode == 0)
         {
             var wm = (WinAPI.WM)wParam.ToUInt32();
             Mubox.WinAPI.WindowHook.KBDLLHOOKSTRUCT keyboardHookStruct = (Mubox.WinAPI.WindowHook.KBDLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Mubox.WinAPI.WindowHook.KBDLLHOOKSTRUCT));
             if (OnKeyboardInputReceived(wm, keyboardHookStruct))
             {
                 return new UIntPtr(1);
             }
         }
     }
     catch (Exception ex)
     {
         ex.Log();
     }
     try
     {
         return Mubox.WinAPI.WindowHook.CallNextHookEx(hHook, nCode, wParam, lParam);
     }
     catch (Exception ex)
     {
         ex.Log();
     }
     return new UIntPtr(1);
 }
Exemple #4
0
		/// <include file='ManagedHooks.xml' path='Docs/KeyboardHook/HookCallback/*'/>
		protected override void HookCallback(int code, UIntPtr wparam, IntPtr lparam)
		{
            if (KeyboardEvent == null)
			{
				return;
			}

			int vkCode = 0;
			KeyboardEvents kEvent = (KeyboardEvents)wparam.ToUInt32();

			if (kEvent != KeyboardEvents.KeyDown		&&
				kEvent != KeyboardEvents.KeyUp			&&
				kEvent != KeyboardEvents.SystemKeyDown	&&
				kEvent != KeyboardEvents.SystemKeyUp)
			{
				return;
			}

			GetKeyboardReading(wparam, lparam, ref vkCode);
			VirtualKeys vk = (VirtualKeys)vkCode;
				
			System.Windows.Forms.Keys key  = ConvertKeyCode(vk);

			if (key == System.Windows.Forms.Keys.Attn)
			{
				return;
			}

			KeyboardEvent(kEvent, key);
		}
Exemple #5
0
        public static StatusMode ToStatus(UIntPtr wParam)
        {
            if (!Enum.IsDefined(StatusEnumType, (int)wParam.ToUInt32()))
                throw new ArgumentException("wParam", TextResources.ExceptionMsg_InvalidValueToTranslate);

            return (StatusMode)(wParam);
        }
Exemple #6
0
        /// <summary>
        /// Compresses data in <paramref name="memory"/> starting at <paramref name="offset"/> with <paramref name="size"/>
        /// using the specified <paramref name="compressionLevel"/>
        /// </summary>
        /// <param name="memory">The buffer to compress</param>
        /// <param name="offset">The offset at which the data to compress starts</param>
        /// <param name="size">The size of the data to compress</param>
        /// <param name="compressionLevel">The compression level to use</param>
        /// <returns>The compressed buffer wrapped in <see cref="Memory{Byte}"/></returns>
        public static Memory <byte> Compress(ReadOnlyMemory <byte> memory, int offset, int size, int compressionLevel = Native.ZSTD_CLEVEL_DEFAULT)
        {
            ValidateCompressionArguments(memory.Length, offset, size, compressionLevel);

            // Allocate compressed buffer
            Size compressionBound = Native.ZSTD_compressBound(new Size((uint)size));

            byte[] compressedBuffer = new byte[compressionBound.ToUInt32()];

            // Get handles to buffers
            using MemoryHandle compressedBufferHandle   = compressedBuffer.AsMemory().Pin();
            using MemoryHandle uncompressedBufferHandle = memory.Pin();

            unsafe
            {
                // Get raw pointers from handles
                IntPtr compressedBufferPointer   = new IntPtr(compressedBufferHandle.Pointer);
                IntPtr uncompressedBufferPointer = new IntPtr(uncompressedBufferHandle.Pointer);

                Size compressedBufferSize = Native.ZSTD_compress(
                    compressedBufferPointer, compressionBound,
                    uncompressedBufferPointer + offset, (Size)size,
                    compressionLevel);

                // Check for errors
                ThrowOnError(compressedBufferSize);

                return(compressedBuffer.AsMemory(0, (int)compressedBufferSize.ToUInt32()));
            }
        }
Exemple #7
0
        private IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam)
        {
            bool continues = true;

            if (nCode >= 0)
            {
                if (wParam.ToUInt32() == (int)KeyEvent.WM_KEYDOWN ||
                    wParam.ToUInt32() == (int)KeyEvent.WM_KEYUP ||
                    wParam.ToUInt32() == (int)KeyEvent.WM_SYSKEYDOWN ||
                    wParam.ToUInt32() == (int)KeyEvent.WM_SYSKEYUP)
                {
                    if (hookedKeyboardCallback != null)
                        continues = hookedKeyboardCallback((KeyEvent)wParam.ToUInt32(), Marshal.ReadInt32(lParam), CheckModifiers());
                }
            }

            if (continues)
            {
                return InterceptKeys.CallNextHookEx(hookId, nCode, wParam, lParam);
            }
            return (IntPtr)1;
        }
Exemple #8
0
        /// <summary>
        /// Compresses data in <paramref name="buffer"/> starting at <paramref name="offset"/> with <paramref name="size"/>
        /// using the specified <paramref name="compressionLevel"/> and parameters set on this <see cref="ZstdCompressionContext"/>
        /// </summary>
        /// <param name="buffer">The buffer to compress</param>
        /// <param name="offset">The offset at which the data to compress starts</param>
        /// <param name="size">The size of the data to compress</param>
        /// <param name="compressionLevel">The compression level to use</param>
        /// <returns>The compressed buffer</returns>
        /// <remarks>
        /// This method will usually cause a double heap allocation of the compressed buffer,
        /// it is recommended to use <see cref="Compress(ReadOnlyMemory{byte}, int, int, int)"/> if you want to avoid this
        /// </remarks>
        public byte[] Compress(byte[] buffer, int offset, int size, int compressionLevel = Native.ZSTD_CLEVEL_DEFAULT)
        {
            if (buffer == null)
            {
                throw new ArgumentNullException(nameof(buffer), $"{nameof(buffer)} cannot be null");
            }

            Zstd.ValidateCompressionArguments(buffer.Length, offset, size, compressionLevel);

            // Allocate compressed buffer
            Size compressionBound = Native.ZSTD_compressBound(new Size((uint)size));

            byte[] compressedBuffer = new byte[compressionBound.ToUInt32()];

            Size compressedBufferSize = Size.Zero;

            unsafe
            {
                fixed(byte *compressedBufferPointer = compressedBuffer)
                fixed(byte *uncompressedBufferPointer = buffer)
                {
                    if (this.Dictionary == null)
                    {
                        compressedBufferSize = Native.ZSTD_compress2(
                            this._context,
                            (IntPtr)compressedBufferPointer, compressionBound,
                            (IntPtr)(uncompressedBufferPointer + offset), (Size)size);
                    }
                    else
                    {
                        compressedBufferSize = Native.ZSTD_compress_usingCDict(
                            this._context,
                            (IntPtr)compressedBufferPointer, compressionBound,
                            (IntPtr)(uncompressedBufferPointer + offset), (Size)size,
                            this.Dictionary.GetCompressionDictionary(compressionLevel));
                    }
                }
            }

            // Check for errors
            Zstd.ThrowOnError(compressedBufferSize);

            // If compressionBound is same as the amount of compressed bytes then we can return the same array
            // otherwise we need to allocate a new one :/
            if (compressionBound != compressedBufferSize)
            {
                Array.Resize(ref compressedBuffer, (int)compressedBufferSize);
            }

            return(compressedBuffer);
        }
        internal static void InternalOnDataReceived(
            IntPtr room, IntPtr participant, IntPtr data, UIntPtr dataLength, bool isReliable,
            IntPtr userData)
        {
            GooglePlayGames.OurUtils.Logger.d("Entering InternalOnDataReceived: " + userData.ToInt64());

            var callback = Callbacks.IntPtrToPermanentCallback
            <Action<NativeRealTimeRoom, MultiplayerParticipant, byte[], bool>>(userData);

            using (var nativeRoom = NativeRealTimeRoom.FromPointer(room))
            {
                using (var nativeParticipant = MultiplayerParticipant.FromPointer(participant))
                {
                    if (callback == null)
                    {
                        return;
                    }

                    byte[] convertedData = null;

                    if (dataLength.ToUInt64() != 0)
                    {
                        convertedData = new byte[dataLength.ToUInt32()];
                        Marshal.Copy(data, convertedData, 0, (int)dataLength.ToUInt32());
                    }

                    try
                    {
                        callback(nativeRoom, nativeParticipant, convertedData, isReliable);
                    }
                    catch (Exception e)
                    {
                        GooglePlayGames.OurUtils.Logger.e("Error encountered executing InternalOnDataReceived. " +
                            "Smothering to avoid passing exception into Native: " + e);
                    }
                }
            }
        }
        /// <summary>
        /// Decompresses data with <paramref name="size"/> at <paramref name="offset"/> in <paramref name="buffer"/> using this <see cref="ZstdDecompressionContext"/>
        /// </summary>
        /// <param name="buffer">The compressed data buffer</param>
        /// <param name="offset">The offset of the compressed data</param>
        /// <param name="size">The size of the compressed data</param>
        /// <param name="uncompressedSize">Uncompressed size of <paramref name="buffer"/></param>
        /// <returns>The uncompressed buffer</returns>
        /// <remarks>If you do not know the uncompressed size then it is recommended to use <see cref="ZstdStream"/></remarks>
        public byte[] Decompress(byte[] buffer, int offset, int size, int uncompressedSize)
        {
            Zstd.ValidateDecompressionArguments(buffer.Length, offset, size, uncompressedSize);

            // Allocate uncompressed buffer
            byte[] uncompressedBuffer = new byte[uncompressedSize];

            Size uncompressedBufferSize = Size.Zero;

            unsafe
            {
                fixed(byte *uncompressedBufferPtr = uncompressedBuffer)
                fixed(byte *compressedBufferPtr = buffer)
                {
                    if (this.Dictionary == null)
                    {
                        uncompressedBufferSize = Native.ZSTD_decompressDCtx(
                            this._context,
                            (IntPtr)uncompressedBufferPtr, (Size)uncompressedSize,
                            (IntPtr)(compressedBufferPtr + offset), (Size)size);
                    }
                    else
                    {
                        uncompressedBufferSize = Native.ZSTD_decompress_usingDDict(
                            this._context,
                            (IntPtr)uncompressedBufferPtr, (Size)uncompressedSize,
                            (IntPtr)(compressedBufferPtr + offset), (Size)size,
                            this.Dictionary.GetDecompressionDictionary());
                    }
                }
            }

            // Check for errors
            Zstd.ThrowOnError(uncompressedBufferSize);

            // Check for possiblity that user passed in higher than required uncompressed size
            if (uncompressedSize != uncompressedBufferSize.ToUInt32())
            {
                Array.Resize(ref uncompressedBuffer, (int)uncompressedBufferSize);
            }

            return(uncompressedBuffer);
        }
Exemple #11
0
        private IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam)
        {
            string chars = "";

            if (nCode >= 0)
                if (wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_KEYDOWN ||
                    wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_KEYUP ||
                    wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_SYSKEYDOWN ||
                    wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_SYSKEYUP)
                {
                    // Captures the character(s) pressed only on WM_KEYDOWN
                    chars = InterceptKeys.VKCodeToString((uint)Marshal.ReadInt32(lParam),
                        (wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_KEYDOWN ||
                        wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_SYSKEYDOWN));

                    hookedKeyboardCallbackAsync.BeginInvoke((InterceptKeys.KeyEvent)wParam.ToUInt32(), Marshal.ReadInt32(lParam), chars, null, null);
                }

            return InterceptKeys.CallNextHookEx(hookId, nCode, wParam, lParam);
        }
Exemple #12
0
 public void GetCommandString(
     UIntPtr idCmd,
     uint uFlags,
     IntPtr pReserved,
     StringBuilder pszName,
     uint cchMax)
 {
     int index = Convert.ToInt32(idCmd.ToUInt32());
     String[] texts = Constants.getLabels(currentActionDispacher.CurrentActions[index]);
     // To change
     switch ((GCS)uFlags)
     {
         case GCS.VERBW:
             pszName.Clear();
             pszName.Append(texts[1]);
             break;
         case GCS.HELPTEXTW:
             pszName.Clear();
             pszName.Append(texts[2]);
             break;
     }
 }
Exemple #13
0
 public static UIntPtr MouseHook(int nCode, UIntPtr wParam, IntPtr lParam)
 {
     try
     {
         if (nCode == 0)
         {
             var wm = (WinAPI.WM)wParam.ToUInt32();
             if (wm == WinAPI.WM.MOUSEMOVE)
             {
                 if (DateTime.Now.Ticks <= _nextMouseMoveAccept)
                 {
                     // a.k.a not handled
                     return Mubox.WinAPI.WindowHook.CallNextHookEx(hHook, nCode, wParam, lParam);
                 }
                 _nextMouseMoveAccept = DateTime.Now.AddMilliseconds(50).Ticks; // 20fps - we limit this to ease off of network and cpu utilization for mousemove, the framerate choice here is arbitrary
             }
             Mubox.WinAPI.WindowHook.MSLLHOOKSTRUCT mouseHookStruct = (Mubox.WinAPI.WindowHook.MSLLHOOKSTRUCT)Marshal.PtrToStructure(lParam, typeof(Mubox.WinAPI.WindowHook.MSLLHOOKSTRUCT));
             if (OnMouseInputReceived(wm, mouseHookStruct))
             {
                 return new UIntPtr(1); // handled
             }
         }
     }
     catch (Exception ex)
     {
         ex.Log();
     }
     try
     {
         return Mubox.WinAPI.WindowHook.CallNextHookEx(hHook, nCode, wParam, lParam);
     }
     catch (Exception ex)
     {
         ex.Log();
     }
     return UIntPtr.Zero;
 }
Exemple #14
0
        unsafe public byte *DecByteArr(byte[] inarr, ref int outLength)
        {
            byte[] outdata;

            byte *data = (byte *)Marshal.AllocHGlobal(inarr.Length);//stackalloc byte[inarr.Length]

            for (int i = 0; i < inarr.Length; i++)
            {
                data[i] = inarr[i];
            }

            size_t  outLen  = (size_t)0;
            size_t *outLenP = &outLen;

            uint  lessLen  = 0;
            uint *lessLenP = &lessLen;


            byte *os = decodeXOR(data, inarr.Length, outLenP, lessLenP);

            if (os == null)
            {
                return(null);
            }
            outLength = Convert.ToInt32(outLen.ToUInt32());
            outdata   = new byte[outLength];
            for (int i = 0; i < outLength; i++)
            {
                outdata[i] = os[i];
            }
            if (outLength == inarr.Length)
            {
                textBox1.AppendText("Wtf?\r\n");
            }

            return(os);
        }
Exemple #15
0
		/// <include file='ManagedHooks.xml' path='Docs/MouseHook/HookCallback/*'/>
		protected override void HookCallback(int code, UIntPtr wparam, IntPtr lparam)
		{
			if (MouseEvent == null)
			{
				return;
			}

			int x = 0, y = 0;
			MouseEvents mEvent = (MouseEvents)wparam.ToUInt32();

			switch(mEvent)
			{
				case MouseEvents.LeftButtonDown:
					GetMousePosition(wparam, lparam, ref x, ref y);
					break;
				case MouseEvents.LeftButtonUp:
					GetMousePosition(wparam, lparam, ref x, ref y);
					break;
				case MouseEvents.MouseWheel:
					break;
				case MouseEvents.Move:
					GetMousePosition(wparam, lparam, ref x, ref y);
					break;
				case MouseEvents.RightButtonDown:
					GetMousePosition(wparam, lparam, ref x, ref y);
					break;
				case MouseEvents.RightButtonUp:
					GetMousePosition(wparam, lparam, ref x, ref y);
					break;
				default:
					//System.Diagnostics.Trace.WriteLine("Unrecognized mouse event");
					break;
			}

			MouseEvent(mEvent, new Point(x, y));
		}
Exemple #16
0
 /// <summary>
 /// Write
 /// </summary>
 /// <param name="dataBuffer">Data buffer</param>
 /// <param name="numBytesToWrite">Number bytes to write</param>
 /// <param name="numBytesWritten">Number bytes written</param>
 /// <returns>A <see cref="FT_STATUS"/></returns>
 public FT_STATUS Write(byte[] dataBuffer, int numBytesToWrite, ref uint numBytesWritten)
 {
     FT_STATUS status = FT_STATUS.FT_OTHER_ERROR;
     UIntPtr written = new UIntPtr(0);
     try { status = FT_Write(_currentHandle, dataBuffer, numBytesToWrite, out written); } catch { }
     numBytesWritten = written.ToUInt32();
     return status;
 }
        private IntPtr LowLevelKeyboardCallback(int code, UIntPtr wParam, IntPtr lParam)
        {
            //catch the timing. if the call took too long, then there's a good chance we have disconnected the hook.
            var startTime = DateTime.UtcNow;

            var block = false;

            if (code >= 0 && (
                wParam.ToUInt32() == (int)KeyEvent.WM_KEYDOWN ||
                wParam.ToUInt32() == (int)KeyEvent.WM_KEYUP ||
                wParam.ToUInt32() == (int)KeyEvent.WM_SYSKEYDOWN ||
                wParam.ToUInt32() == (int)KeyEvent.WM_SYSKEYUP))
            {
                var keyEvent = (KeyEvent)wParam.ToUInt32();
                var virtualKeyCode = Marshal.ReadInt32(lParam);

                var key = KeyInterop.KeyFromVirtualKey(virtualKeyCode);
                switch (keyEvent)
                {
                    case KeyEvent.WM_KEYDOWN:
                        if (KeyDown != null)
                        {
                            KeyDown(this, new KeyEventArgument(virtualKeyCode), ref block);
                        }
                        break;

                    case KeyEvent.WM_KEYUP:
                        if (KeyDown != null)
                        {
                            KeyUp(this, new KeyEventArgument(virtualKeyCode), ref block);
                        }
                        break;
                }
            }

            var endTime = DateTime.UtcNow;
            var executionTime = endTime - startTime;

            const int Overhead = 25;
            if (executionTime.TotalMilliseconds + Overhead >= configuration.HookTimeout)
            {
                //reconnect the hook.
                Disconnect();
                Connect();

                //attempt to block the keystroke anyway.
                block = true;

                //signal the event.
                if (HookRecovered != null)
                {
                    HookRecovered(this, new HookRecoveredEventArgument());
                }
            }

            if (block)
            {
                return new IntPtr(-1);
            }

            return CallNextHookEx(hookId, code, wParam, lParam);
        }
Exemple #18
0
        /// <summary>
        /// Gets a human-readable name for the protocol.
        /// </summary>
        /// <param name="capacity">The number of characters in the buffer.</param>
        /// <param name="pBuffer">Buffer pointer.</param>
        /// <returns>Returns 0 on success, nonzero on failure.</returns>
        private unsafe int PSGetName(UIntPtr capacity, IntPtr pBuffer)
        {
            if (namePtr == IntPtr.Zero)
            {
                byte[] nameBytes = Encoding.Default.GetBytes(Name ?? String.Empty);
                NameCapacity = nameBytes.Length + 1;

                namePtr = Marshal.AllocHGlobal(NameCapacity);
                Marshal.Copy(nameBytes, 0, namePtr, nameBytes.Length);

                *(((byte*)namePtr) + nameBytes.Length) = 0;
            }

            uint count = capacity.ToUInt32();

            for (long i = 0; i < count && i < NameCapacity; i++)
                *(byte*)(pBuffer.ToInt64() + i) = *(byte*)(namePtr.ToInt64() + i);

            return 0;
        }
Exemple #19
0
        private static void VerifyPointer(UIntPtr ptr, ulong expected)
        {
            Assert.Equal(expected, ptr.ToUInt64());

            uint expected32 = (uint)expected;
            if (expected32 != expected)
            {
                Assert.Throws<OverflowException>(() => ptr.ToUInt32());
                return;
            }

            Assert.Equal(expected32, ptr.ToUInt32());

            Assert.Equal(expected.ToString(), ptr.ToString());

            Assert.Equal(ptr, new UIntPtr(expected));
            Assert.True(ptr == new UIntPtr(expected));
            Assert.False(ptr != new UIntPtr(expected));

            Assert.NotEqual(ptr, new UIntPtr(expected + 1));
            Assert.False(ptr == new UIntPtr(expected + 1));
            Assert.True(ptr != new UIntPtr(expected + 1));
        }
Exemple #20
0
        private int LowLevelKeyboardProc(int nCode, UIntPtr wParam, ref InterceptKeys.KBDLLHOOKSTRUCT lParam)
        {
            string chars = "";

            if (nCode >= 0)
                if (wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_KEYDOWN ||
                    wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_KEYUP ||
                    wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_SYSKEYDOWN ||
                    wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_SYSKEYUP)
                {
                    // Captures the character(s) pressed only on WM_KEYDOWN
                    chars = InterceptKeys.VKCodeToString((uint)lParam.vkCode,
                        (wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_KEYDOWN ||
                        wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_SYSKEYDOWN));

                    hookedKeyboardCallbackAsync.BeginInvoke((InterceptKeys.KeyEvent)wParam.ToUInt32(), lParam.vkCode, chars, null, null);
                }

            //---My Block
            uint iwParam = wParam.ToUInt32();
            Debug.WriteLine(iwParam);
            if (iwParam == 256) // key down message
            {
                if (lParam.vkCode == 162) // control key down
                {
                    ctrl_pressed = true;
                }
            }
            if (iwParam == 257) // key up message
            {
                if (lParam.vkCode == 162) // control key up
                {
                    ctrl_pressed = false;
                }
            }

            bool forbidden = ForbiddenInput(lParam.vkCode, lParam.flags);
            if (ForbiddenInput(lParam.vkCode, lParam.flags))
                return 1;
            //---end

            return InterceptKeys.CallNextHookEx(hookId, nCode, wParam, ref lParam);
        }
Exemple #21
0
 /// <summary>
 /// Read
 /// </summary>
 /// <param name="dataBuffer">Data buffer</param>
 /// <param name="numBytesToRead">Number bytes to read</param>
 /// <param name="numBytesRead">Number bytes read</param>
 /// <returns>A <see cref="FT_STATUS"/></returns>
 public FT_STATUS Read(byte[] dataBuffer, uint numBytesToRead, ref uint numBytesRead)
 {
     FT_STATUS status = FT_STATUS.FT_OTHER_ERROR;
     UIntPtr read = new UIntPtr(0);
     try { status = FT_Read(_currentHandle, dataBuffer, numBytesToRead, out read); } catch { }
     numBytesRead = read.ToUInt32();
     return status;
 }
Exemple #22
0
 /// <summary>
 /// GetDeviceList
 /// </summary>
 /// <param name="deviceList">Device list</param>
 /// <returns>A <see cref="FT_STATUS"/></returns>
 public FT_STATUS GetDeviceList(FT_DEVICE_INFO_NODE[] deviceList)
 {
     FT_STATUS status = FT_STATUS.FT_OTHER_ERROR;
     UIntPtr flags = new UIntPtr(0);
     UIntPtr type = new UIntPtr(0);
     UIntPtr id = new UIntPtr(0);
     UIntPtr locId = new UIntPtr(0);
     byte[] description = new byte[64];
     byte[] serialNumber = new byte[16];
     IntPtr handle = new IntPtr(0);
     if (deviceList != null && deviceList.Length == _devicesCount)
     {
         for (uint i = 0; i < _devicesCount; i++)
         {
             FT_DEVICE_INFO_NODE newNode = new FT_DEVICE_INFO_NODE();
             try
             {
                 status = FT_GetDeviceInfoDetail(i, out flags, out type, out id, out locId, serialNumber, description, handle);
                 newNode.Flags = flags.ToUInt32();
                 newNode.Type = type.ToUInt32();
                 newNode.ID = id.ToUInt32();
                 newNode.LocId = locId.ToUInt32();
                 newNode.SerialNumber = System.Text.ASCIIEncoding.Default.GetString(serialNumber);
                 newNode.Description = System.Text.ASCIIEncoding.Default.GetString(description);
                 newNode.ftHandle = handle;
             }
             catch { }
             deviceList[i] = newNode;
         }
     }
     return status;
 }
Exemple #23
0
        public void Refresh()
        {
            StringBuilder sb = new StringBuilder();

            // get caption
            sb.EnsureCapacity(10240);

            bool WindowTimedOut = false;

            UIntPtr lRes = new UIntPtr(1860);
            int lResult = SendMessageTimeout(Handle, WM_GETTEXT, 10240, sb, SMTO_ABORTIFHUNG, 1000, out lRes);
            if (lResult == 0)
            {
                Trace.TraceError("SendMessageTimeout() failed with {0}", Marshal.GetLastWin32Error());
                WindowTimedOut = true;
                Objects[(int)WindowItemTypes.Title] = "?";
            }
            else
            {
                //Trace.TraceInformation("lResult: {0}, lRes: {1}", lResult, lRes.ToUInt32());
                Objects[(int)WindowItemTypes.Title] = sb.ToString();
            }

            // get class name
            sb = new StringBuilder();
            sb.EnsureCapacity(10240);
            GetClassName(Handle, sb, 10240);
            Objects[(int)WindowItemTypes.Class] = sb.ToString();

            uint style = GetWindowLong(Handle, GWL_STYLE);
            Objects[(int)WindowItemTypes.Style] = DecodeWindowStyle(style);
            Objects[(int)WindowItemTypes.ExStyle] = GetWindowLong(Handle, GWL_EXSTYLE);
            Objects[(int)WindowItemTypes.ID] = GetWindowLong(Handle, GWL_ID);

            RECT r = new RECT();
            GetWindowRect(Handle, ref r);

            Objects[(int)WindowItemTypes.Size] = string.Format("({0}, {1})", r.Width, r.Height);
            Objects[(int)WindowItemTypes.Position] = string.Format("({0}, {1})", r.Top, r.Left);

            UIntPtr ProcessID = new UIntPtr(0);
            uint ThreadID = GetWindowThreadProcessId(Handle, out ProcessID);
            Objects[(int)WindowItemTypes.TID] = ThreadID;
            Objects[(int)WindowItemTypes.PID] = ProcessID.ToUInt32();

            ForegroundColor = Color.Black;
            if ((r.Width == r.Height) && (r.Width == 0))
            {
                ForegroundColor = Color.Gray;
            }
            if ((style & WS_VISIBLE) == 0)
            {
                ForegroundColor = Color.Gray;
            }
            if (WindowTimedOut)
            {
                ForegroundColor = Color.Red;
            }
        }
Exemple #24
0
 public override void EnumCodeContextsOfPosition(UIntPtr sourceContext, uint offset, uint length, out IEnumDebugCodeContexts enumContexts)
 {
     var del = RawCOMHelpers.GetMethodDelegate<RawEnumCodeContextsOfPosition>(pActiveScriptDebug, 5);
     RawCOMHelpers.HResult.Check(del(pActiveScriptDebug, sourceContext.ToUInt32(), offset, length, out enumContexts));
 }
Exemple #25
0
		public IDebuggerValue CreateBox(UIntPtr value) {
			return debugger.Dispatcher.UI(() => {
				var refBoxValue = CreateNoConstructorUI(appDomain.UIntPtr);
				if (value != UIntPtr.Zero) {
					var boxedValue = refBoxValue.CorValue.DereferencedValue.BoxedValue;
					var bytes = UIntPtr.Size == 4 ?
							BitConverter.GetBytes(value.ToUInt32()) :
							BitConverter.GetBytes(value.ToUInt64());
					boxedValue.WriteGenericValue(bytes);
				}
				return refBoxValue;
			});
		}
Exemple #26
0
		public IDebuggerValue Create(UIntPtr value) {
			return debugger.Dispatcher.UI(() => {
				var res = CreateNoConstructorUI(appDomain.UIntPtr).CorValue;
				Keep(res);
				Debug.Assert(res.DereferencedValue != null && res.DereferencedValue.BoxedValue != null);
				res = res.DereferencedValue.BoxedValue;
				if (value != UIntPtr.Zero) {
					var bytes = UIntPtr.Size == 4 ?
							BitConverter.GetBytes(value.ToUInt32()) :
							BitConverter.GetBytes(value.ToUInt64());
					res.WriteGenericValue(bytes);
				}
				return new DebuggerValue(debugger, res);
			});
		}
        private IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam)
        {
            /* TODO: Change BeginInvoke to Invoke to block windows from handling things like the start key */
                if (nCode >= 0)
                    if (wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_KEYDOWN ||
                        wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_KEYUP ||
                        wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_SYSKEYDOWN ||
                        wParam.ToUInt32() == (int)InterceptKeys.KeyEvent.WM_SYSKEYUP)
                        hookedKeyboardCallbackAsync.BeginInvoke((InterceptKeys.KeyEvent)wParam.ToUInt32(), Marshal.ReadInt32(lParam), null, null);

                return InterceptKeys.CallNextHookEx(hookId, nCode, wParam, lParam);
        }
        private IntPtr LowLevelKeyboardProc(int nCode, UIntPtr wParam, IntPtr lParam)
        {
            bool block = false;

            if (nCode >= 0)
            {
                if (wParam.ToUInt32() == (int)KeyEvent.WM_KEYDOWN ||
                    wParam.ToUInt32() == (int)KeyEvent.WM_KEYUP ||
                    wParam.ToUInt32() == (int)KeyEvent.WM_SYSKEYDOWN ||
                    wParam.ToUInt32() == (int)KeyEvent.WM_SYSKEYUP)
                {
                    _hookedKeyboardCallback((KeyEvent)wParam.ToUInt32(), Marshal.ReadInt32(lParam), ref block);
                }
            }

            if (block)
            {
                return new IntPtr(-1);
            }

            return CallNextHookEx(_hookId, nCode, wParam, lParam);
        }
        private void OnWmDeviceChange(UIntPtr wParam, IntPtr lParam)
        {
            DEV_BROADCAST_HDR dbh = (DEV_BROADCAST_HDR)Marshal.PtrToStructure(lParam, typeof(DEV_BROADCAST_HDR));
            if (dbh.dbch_devicetype != DBT_DEVTYP_DEVICEINTERFACE)
            {
                return;
            }

            DEV_BROADCAST_DEVICEINTERFACE dbi = (DEV_BROADCAST_DEVICEINTERFACE)Marshal.PtrToStructure(lParam, typeof(DEV_BROADCAST_DEVICEINTERFACE));

            UInt32 eventType = wParam.ToUInt32();

            if (DBT_DEVICEARRIVAL == eventType)
            {
                if (this.DeviceConnected != null)
                {
                    this.DeviceConnected(this, new DeviceManagementNotificationsEventArgs(true, dbi.dbcc_classguid, dbi.dbcc_name));
                }
            }
            else if (DBT_DEVICEREMOVECOMPLETE == eventType)
            {
                if (this.DeviceDisconnected != null)
                {
                    this.DeviceDisconnected(this, new DeviceManagementNotificationsEventArgs(false, dbi.dbcc_classguid, dbi.dbcc_name));
                }
            }
        }
Exemple #30
0
 public override void ParseScriptText(string code, string itemName, object context, string delimiter, UIntPtr sourceContext, uint startingLineNumber, ScriptTextFlags flags, IntPtr pVarResult, out EXCEPINFO excepInfo)
 {
     activeScriptParse.ParseScriptText(code, itemName, context, delimiter, sourceContext.ToUInt32(), startingLineNumber, flags, pVarResult, out excepInfo);
 }
		public static IntPtr SetWindowLongPtr (HandleRef hWnd, int nIndex, UIntPtr dwNewLong) {
			if (IntPtr.Size == 8)
				return SetWindowLongPtr64(hWnd, nIndex, dwNewLong);
			else
				return new IntPtr(SetWindowLong32(hWnd, nIndex, dwNewLong.ToUInt32()));
		}
 public static void GetWindowThreadProcessId(int hwnd, out int ProcessID, out int ThreadID)
 {
     UIntPtr _ProcessID = new UIntPtr(0);
     ThreadID = (int) GetWindowThreadProcessId(hwnd, out _ProcessID);
     ProcessID = (int) _ProcessID.ToUInt32();
 }
        /// <summary>
        /// Get information about a shortcut menu command, including the help string 
        /// and the language-independent, or canonical, name for the command.
        /// </summary>
        /// <param name="idCmd">Menu command identifier offset.</param>
        /// <param name="uFlags">
        /// Flags specifying the information to return. This parameter can have one 
        /// of the following values: GCS_HELPTEXTA, GCS_HELPTEXTW, GCS_VALIDATEA, 
        /// GCS_VALIDATEW, GCS_VERBA, GCS_VERBW.
        /// </param>
        /// <param name="pReserved">Reserved. Must be IntPtr.Zero</param>
        /// <param name="pszName">
        /// The address of the buffer to receive the null-terminated string being 
        /// retrieved.
        /// </param>
        /// <param name="cchMax">
        /// Size of the buffer, in characters, to receive the null-terminated string.
        /// </param>
        public void GetCommandString(
            UIntPtr idCmd,
            uint uFlags,
            IntPtr pReserved,
            StringBuilder pszName,
            uint cchMax)
        {
            var menu = MenuManager.Instance.Menus.Find(f => f.Id == idCmd.ToUInt32());
            if (menu != null)
            {

                switch ((GCS)uFlags)
                {
                    case GCS.GCS_VERBW:
                        if (menu.VerbCanonicalName.Length > cchMax - 1)
                        {
                            Marshal.ThrowExceptionForHR(WinError.STRSAFE_E_INSUFFICIENT_BUFFER);
                        }
                        else
                        {
                            pszName.Clear();
                            pszName.Append(menu.VerbCanonicalName);
                        }
                        break;

                    case GCS.GCS_HELPTEXTW:
                        if (menu.VerbHelpText.Length > cchMax - 1)
                        {
                            Marshal.ThrowExceptionForHR(WinError.STRSAFE_E_INSUFFICIENT_BUFFER);
                        }
                        else
                        {
                            pszName.Clear();
                            pszName.Append(menu.VerbHelpText);
                        }
                        break;
                }
            }
        }
Exemple #34
0
        /// <summary>
        /// Get information about a shortcut menu command, including the help string 
        /// and the language-independent, or canonical, name for the command.
        /// </summary>
        /// <param name="idCmd">Menu command identifier offset.</param>
        /// <param name="uFlags">
        /// Flags specifying the information to return. This parameter can have one 
        /// of the following values: GCS_HELPTEXTA, GCS_HELPTEXTW, GCS_VALIDATEA, 
        /// GCS_VALIDATEW, GCS_VERBA, GCS_VERBW.
        /// </param>
        /// <param name="pReserved">Reserved. Must be IntPtr.Zero</param>
        /// <param name="pszName">
        /// The address of the buffer to receive the null-terminated string being 
        /// retrieved.
        /// </param>
        /// <param name="cchMax">
        /// Size of the buffer, in characters, to receive the null-terminated string.
        /// </param>
        public void GetCommandString(
            UIntPtr idCmd,
            uint uFlags,
            IntPtr pReserved,
            StringBuilder pszName,
            uint cchMax)
        {
            if (idCmd.ToUInt32() == IDM_DISPLAY)
            {
                switch ((GCS)uFlags)
                {
                    case GCS.GCS_VERBW:
                        if (this.verbCanonicalName.Length > cchMax - 1)
                        {
                            Marshal.ThrowExceptionForHR(WinError.STRSAFE_E_INSUFFICIENT_BUFFER);
                        }
                        else
                        {
                            pszName.Clear();
                            pszName.Append(this.verbCanonicalName);
                        }
                        break;

                    case GCS.GCS_HELPTEXTW:
                        if (this.verbHelpText.Length > cchMax - 1)
                        {
                            Marshal.ThrowExceptionForHR(WinError.STRSAFE_E_INSUFFICIENT_BUFFER);
                        }
                        else
                        {
                            pszName.Clear();
                            pszName.Append(this.verbHelpText);
                        }
                        break;
                }
            }
        }
        /// <summary>
        /// Get information about a shortcut menu command, including the help string 
        /// and the language-independent, or canonical, name for the command.
        /// </summary>
        /// <param name="idCmd">Menu command identifier offset.</param>
        /// <param name="uFlags">
        /// Flags specifying the information to return. This parameter can have one 
        /// of the following values: GCS_HELPTEXTA, GCS_HELPTEXTW, GCS_VALIDATEA, 
        /// GCS_VALIDATEW, GCS_VERBA, GCS_VERBW.
        /// </param>
        /// <param name="pReserved">Reserved. Must be IntPtr.Zero</param>
        /// <param name="pszName">
        /// The address of the buffer to receive the null-terminated string being 
        /// retrieved.
        /// </param>
        /// <param name="cchMax">
        /// Size of the buffer, in characters, to receive the null-terminated string.
        /// </param>
        public void GetCommandString(
            UIntPtr idCmd,
            uint uFlags,
            IntPtr pReserved,
            StringBuilder pszName,
            uint cchMax)
        {
            return;
               Debug.WriteLine("Get Command String");

              // MessageBox(0, "GetCommandString", "Information", 0);
              // MessageBox(0, idCmd.ToString(), "Information", 0);
            //if (idCmd.ToUInt32() == IDM_DISPLAY)
            if (idCmd.ToUInt32() < 10)
            {
                Debug.WriteLine("Switch Get Command String");

                switch ((GCS)uFlags)
                {
                    case GCS.GCS_VERBW:
                        if (this.verbCanonicalName.Length > cchMax - 1)
                        {
                            Marshal.ThrowExceptionForHR(WinError.STRSAFE_E_INSUFFICIENT_BUFFER);
                        }
                        else
                        {
                            pszName.Clear();
                            pszName.Append(this.syncVerbCanonicalName[idCmd.ToUInt32()]);
                        }
                        break;

                    case GCS.GCS_HELPTEXTW:
                        if (this.verbHelpText.Length > cchMax - 1)
                        {
                            Marshal.ThrowExceptionForHR(WinError.STRSAFE_E_INSUFFICIENT_BUFFER);
                        }
                        else
                        {
                            pszName.Clear();
                            pszName.Append(this.verbHelpText);
                        }
                        break;
                }
            }
             //   MessageBox(0, pszName.ToString(), "Info", 0);
        }