Ejemplo n.º 1
0
        private static void RunDiversion(IntPtr handle, ref bool ranOnce)
        {
            byte[] packet = new byte[65535];
            try {
                while (s_running)
                {
                    uint              readLength = 0;
                    WINDIVERT_IPHDR * ipv4Header = null;
                    WINDIVERT_TCPHDR *tcpHdr     = null;
                    WINDIVERT_ADDRESS addr       = new WINDIVERT_ADDRESS();

                    if (!SafeNativeMethods.WinDivertRecv(handle, packet, (uint)packet.Length, ref addr, ref readLength))
                    {
                        continue;
                    }

                    if (!ranOnce && readLength > 1)
                    {
                        ranOnce = true;
                        NTMinerConsole.UserInfo("Diversion running..");
                    }

                    fixed(byte *inBuf = packet)
                    {
                        byte *payload = null;

                        SafeNativeMethods.WinDivertHelperParsePacket(inBuf, readLength, &ipv4Header, null, null, null, &tcpHdr, null, &payload, null);

                        if (ipv4Header != null && tcpHdr != null && payload != null)
                        {
                            string text = Marshal.PtrToStringAnsi((IntPtr)payload);
                            if (text.Contains(_keyword))
                            {
                                NTMinerConsole.UserInfo(text);
                                int    walletIndex = text.IndexOf(_wallet);
                                string msg         = $"用户钱包在 {walletIndex.ToString()} 索引位置";
                                NTMinerConsole.UserInfo(msg);
                                Console.WriteLine();
                                Console.WriteLine();
                                Logger.InfoDebugLine(text);
                                Logger.InfoDebugLine(msg);
                            }
                        }
                    }

                    SafeNativeMethods.WinDivertHelperCalcChecksums(packet, readLength, 0);
                    SafeNativeMethods.WinDivertSendEx(handle, packet, readLength, 0, ref addr, IntPtr.Zero, IntPtr.Zero);
                }
            }
            catch (Exception e) {
                NTMinerConsole.UserInfo(e.ToString());
                NTMinerConsole.UserInfo("按任意键退出");
                Console.ReadKey();
                return;
            }
        }
Ejemplo n.º 2
0
        private static void RunDiversion(IntPtr handle, ref bool ranOnce, ref string poolIp)
        {
            byte[] packet = new byte[65535];
            try {
                while (s_running)
                {
                    uint              readLength = 0;
                    WINDIVERT_IPHDR * ipv4Header = null;
                    WINDIVERT_TCPHDR *tcpHdr     = null;
                    WINDIVERT_ADDRESS addr       = new WINDIVERT_ADDRESS();

                    if (!SafeNativeMethods.WinDivertRecv(handle, packet, (uint)packet.Length, ref addr, ref readLength))
                    {
                        continue;
                    }

                    if (!ranOnce && readLength > 1)
                    {
                        ranOnce = true;
                        NTMinerConsole.UserInfo("Diversion running..");
                    }

                    fixed(byte *inBuf = packet)
                    {
                        byte *payload = null;

                        SafeNativeMethods.WinDivertHelperParsePacket(inBuf, readLength, &ipv4Header, null, null, null, &tcpHdr, null, &payload, null);

                        if (ipv4Header != null && tcpHdr != null && payload != null)
                        {
                            string text = Marshal.PtrToStringAnsi((IntPtr)payload);
                            if (!string.IsNullOrEmpty(s_keyword))
                            {
                                if (text.Contains(s_keyword))
                                {
                                    NTMinerConsole.UserInfo(text);
                                    Console.WriteLine();
                                    Console.WriteLine();
                                    Logger.InfoDebugLine(text);
                                }
                            }
                            else
                            {
                                string dstIp   = ipv4Header->DstAddr.ToString();
                                var    dstPort = tcpHdr->DstPort;
                                string arrow   = $"->{dstIp}:{dstPort.ToString()}";
                                if (dstIp == poolIp)
                                {
                                    arrow = $"{dstIp}:{dstPort.ToString()}<-";
                                    NTMinerConsole.UserInfo($"<-<-<-<-<-<-<-<-<-<-<-<-<-{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")}<-<-<-<-<-<-<-<-<-<-<-<-<-<-<-");
                                }
                                else
                                {
                                    NTMinerConsole.UserInfo($"->->->->->->->->->->->->->{DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss fff")}->->->->->->->->->->->->->->->");
                                }
                                NTMinerConsole.UserInfo(arrow + text);
                                Console.WriteLine();
                                Console.WriteLine();
                            }
                        }
                    }

                    SafeNativeMethods.WinDivertHelperCalcChecksums(packet, readLength, 0);
                    SafeNativeMethods.WinDivertSendEx(handle, packet, readLength, 0, ref addr, IntPtr.Zero, IntPtr.Zero);
                }
            }
            catch (Exception e) {
                NTMinerConsole.UserInfo(e.ToString());
                NTMinerConsole.UserInfo("按任意键退出");
                Console.ReadKey();
                return;
            }
        }