示例#1
0
        public Main(RemoteHooking.IContext InContext, string serverName)
        {
            mySendClientQueue     = new Queue <Packet>();
            mySendClientLock      = new object();
            mySendServerQueue     = new Queue <Packet>();
            mySendServerLock      = new object();
            myRecvFilter          = new PacketFilter();
            mySendFilter          = new PacketFilter();
            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);

            myClientInstance.SendCommand(Command.Message, "ClientHook Main()");
        }
示例#2
0
        public static void Initialize(ClientInstance clientInstance)
        {
            myWindowHandle   = Process.GetCurrentProcess().MainWindowHandle;
            myClientInstance = clientInstance;
            myMsgHook        = new HookProc(MsgHook);
            myWindowMsgHook  = new HookProc(WindowMsgHook);
            Process p = Process.GetProcessById(EasyHook.RemoteHooking.GetCurrentProcessId());
            uint    x;
            uint    threadID = GetWindowThreadProcessId(p.MainWindowHandle, out x);

            myMsgHookHandle = SetWindowsHookEx(WH_GETMESSAGE,
                                               Marshal.GetFunctionPointerForDelegate(myMsgHook),
                                               Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),
                                               threadID);
            myWindowMsgHookHandle = SetWindowsHookEx(WH_CALLWNDPROC,
                                                     Marshal.GetFunctionPointerForDelegate(myWindowMsgHook),
                                                     Marshal.GetHINSTANCE(Assembly.GetExecutingAssembly().GetModules()[0]),
                                                     threadID);
            WINDOWPLACEMENT wp = new WINDOWPLACEMENT();

            if (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!");
            }
        }
示例#3
0
        public static int SendHook(IntPtr buf, int len)
        {
            byte[] buffer = new byte[len];
            Marshal.Copy(buf, buffer, 0, len);
#if FILTER_TEST
            if (buf.ToInt32() != myServerSendBuffer.ToInt32())
            {
                myClientInstance.SendCommand(Command.OutgoingPacket, buffer);
                if (mySendFilter[buffer[0]])
                {
                    return(1);
                }
            }

            if (buffer[0] == 0xB1)
            {
                bool found  = false;
                int  serial = buffer[3] << 24 | buffer[4] << 16 | buffer[5] << 8 | buffer[6];
                int  gumpid = buffer[7] << 24 | buffer[8] << 16 | buffer[9] << 8 | buffer[10];

                myClientInstance.SendCommand(Command.Message, String.Format("Gump Response: 0x{0:x} 0x{1:x}", serial, (uint)serial));

                foreach (GumpResponseFilter gf in myGumpResponseFilter)
                {
                    if ((gf.Serial == (uint)serial) && (gf.GumpID == (uint)gumpid))
                    {
                        found = true;
                    }

                    if (found)
                    {
                        break;
                    }
                }

                if (found)
                {
                    return(1);
                }
            }
#else
            myClientInstance.SendCommand(Command.OutgoingPacket, buffer);
#endif
            return(0);
        }
示例#4
0
 public static int SendHook(IntPtr buf, int len)
 {
     byte[] buffer = new byte[len];
     Marshal.Copy(buf, buffer, 0, len);
     myClientInstance.SendCommand(Command.OutgoingPacket, buffer);
     if (mySendFilter[buffer[0]])
     {
         return(1);
     }
     return(0);
 }
示例#5
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!");
            }
        }
示例#6
0
        public static int SendHook(IntPtr buf, int len)
        {
            byte[] buffer = new byte[len];
            Marshal.Copy(buf, buffer, 0, len);
#if FILTER_TEST
            if (buf.ToInt32() != myServerSendBuffer.ToInt32())
            {
                myClientInstance.SendCommand(Command.OutgoingPacket, buffer);
                if (mySendFilter.MatchFilter(buffer))
                {
                    return(1);
                }
            }
#else
            myClientInstance.SendCommand(Command.OutgoingPacket, buffer);
#endif
            return(0);
        }
示例#7
0
        public Main(RemoteHooking.IContext InContext, string serverName)
        {
            mySocketReady         = false;
            myRecvFilter          = new bool[256];
            mySendFilter          = new bool[256];
            mySocket              = 0;
            myRecvDelegate        = new dSendRecv(ReceiveHook);
            mySendDelegate        = new dSendRecv(SendHook);
            mySocketDelegate      = new dSocket(SocketHook);
            myCloseSocketDelegate = new dCloseSocket(SocketCloseHook);
            myClientSendLock      = new object();
            myPID       = RemoteHooking.GetCurrentProcessId();
            myThreadID  = RemoteHooking.GetCurrentThreadId();
            myDateStamp = GetDateStamp();
            if (myDateStamp >= 1183740939)
            {
                myNewStylePackets = true;
            }
            else
            {
                myNewStylePackets = false;
            }
            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);
            BuildDefaultPacketFilters();
        }