Exemplo n.º 1
1
        public Main( RemoteHooking.IContext InContext, string serverName )
        {
            mySendClientQueue = new Queue<Packet>();
            mySendClientLock = new object();
            mySendServerQueue = new Queue<Packet>();
            mySendServerLock = new object();
            myRecvFilter = new bool[256];
            mySendFilter = new bool[256];
            myRecvDelegate = new dSendRecv( ReceiveHook );
            mySendDelegate = new dSendRecv( SendHook );
            myPID = RemoteHooking.GetCurrentProcessId();
            myThreadID = RemoteHooking.GetCurrentThreadId();
            myDateStamp = GetDateStamp();
            myServerSendBuffer = Marshal.AllocHGlobal( 65536 );
            myClientSendBuffer = Marshal.AllocHGlobal( 65536 );
            myServerBufferAddress = BitConverter.GetBytes( myServerSendBuffer.ToInt32() );
            myClientBufferAddress = BitConverter.GetBytes( myClientSendBuffer.ToInt32() );

            myClientInstance = new ClientInstance( serverName, true );
            myClientInstance.SendCommand( Command.ClientID, myPID );
            myClientInstance.SendPacketEvent += new dSendPacket( myClientInstance_sendPacketEvent );
            myClientInstance.PingEvent += new dPing( myClientInstance_pingEvent );
            myClientInstance.AddRecvFilterEvent += new dAddRecvFilter( myClientInstance_addRecvFilterEvent );
            myClientInstance.AddSendFilterEvent += new dAddSendFilter( myClientInstance_addSendFilterEvent );
            myClientInstance.RemoveRecvFilterEvent += new dRemoveRecvFilter( myClientInstance_removeRecvFilterEvent );
            myClientInstance.RemoveSendFilterEvent += new dRemoveSendFilter( myClientInstance_removeSendFilterEvent );
            myClientInstance.ClearRecvFilterEvent += new dClearRecvFilter( myClientInstance_clearRecvFilterEvent );
            myClientInstance.ClearSendFilterEvent += new dClearSendFilter( myClientInstance_clearSendFilterEvent );
        }
        public void Test()
        {
            ServerInstance si = new ServerInstance( UOM.ServerName, false, 0, 32 );

            ClientInstance ci = new ClientInstance( UOM.ServerName, false );
            ci.AddRecvFilterEvent += Ci_AddRecvFilterEvent;

            si.SendCommand( Command.AddRecvFilterConditional, new PacketFilterInfo(0xF3, new PacketFilterCondition[] { new PacketFilterCondition( 0, new byte[] { 0xF3 }, 1 ) } ).Serialize());

            while (true) ;
        }
Exemplo n.º 3
0
        public static void Initialize(ClientInstance clientInstance)
        {
            myWindowHandle = Process.GetCurrentProcess().MainWindowHandle;
            myClientInstance = clientInstance;
            myMsgHook = new NativeMethods.HookProc(MsgHook);
            myWindowMsgHook = new NativeMethods.HookProc(WindowMsgHook);
            Process p = Process.GetProcessById(EasyHook.RemoteHooking.GetCurrentProcessId());
            uint x;
            uint threadID = NativeMethods.GetWindowThreadProcessId(p.MainWindowHandle, out x);

            /* Use user32.dll as SetWindowHookEx hMod as per http://stackoverflow.com/questions/17897646/gma-useractivitymonitor-setwindowshookex-error-126 */
            IntPtr user32 = NativeMethods.LoadLibrary("user32.dll");
            myMsgHookHandle = NativeMethods.SetWindowsHookEx(NativeMethods.WH_GETMESSAGE,
                Marshal.GetFunctionPointerForDelegate(myMsgHook),
                /*Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0])*/user32,
                    threadID);
            #if DEBUG
            if (myMsgHookHandle == IntPtr.Zero)
            {
                clientInstance.SendCommand(Command.Message, "Error installing WH_GETMESSAGE hook, GetLastError = " + Marshal.GetLastWin32Error().ToString());
            }
            #endif
            myWindowMsgHookHandle = NativeMethods.SetWindowsHookEx(NativeMethods.WH_CALLWNDPROC,
                Marshal.GetFunctionPointerForDelegate(myWindowMsgHook),
                /*Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0])*/user32,
                    threadID);
            #if DEBUG
            if (myWindowMsgHookHandle == IntPtr.Zero)
            {
                clientInstance.SendCommand(Command.Message, "Error installing WH_CALLWNDPROC hook, GetLastError = " + Marshal.GetLastWin32Error().ToString());
            }
            #endif
            NativeMethods.WINDOWPLACEMENT wp = new NativeMethods.WINDOWPLACEMENT();
            if (NativeMethods.GetWindowPlacement(myWindowHandle, ref wp))
            {
                MessageHook.myWindowX = wp.rcNormalPosition.X;
                MessageHook.myWindowY = wp.rcNormalPosition.Y;
            }
            if (myMsgHookHandle == IntPtr.Zero || myWindowMsgHookHandle == IntPtr.Zero)
            {
                clientInstance.SendCommand(Command.Message, "Error installing WH_GETMESSAGE\\WH_CALLWNDPROC hooks!");
            }
        }
Exemplo n.º 4
0
        public void PacketFilterTest()
        {
            ServerInstance si = new ServerInstance( UOM.ServerName, false, 0, 32 );
            ClientInstance ci = new ClientInstance( UOM.ServerName, false );
            ci.AddRecvFilterEvent += Ci_AddRecvFilterEvent;
            ci.SendPacketEvent += Ci_SendPacketEvent;

            si.SendCommand( Command.AddRecvFilterConditional, new PacketFilterInfo( 0xFF, new PacketFilterCondition[] { new PacketFilterCondition( 2, new byte[] { 0x12, 0x34, 0x56, 0x78 }, 4 ) } ).Serialize() );

            byte[] packet = new byte[]
            {
                0xFF,
                0x01,
                0x12,
                0x34,
                0x56,
                0x78,
            };

            byte[] packet2 = new byte[]
            {
                0xFF,
                0x00,
                0x78,
                0x56,
                0x34,
                0x12,
            };

            si.SendCommand( Command.SendPacket, 0, (byte) PacketType.Server, packet );
            si.SendCommand( Command.SendPacket, 0, (byte) PacketType.Server, packet2 );

            lock (m_FinishedLock)
            {
                Monitor.Wait( m_FinishedLock );
            }

            ci.Dispose();
            si.Dispose();
        }