Exemplo n.º 1
0
        public static void StartAsync()
        {
            // Win7下WinDivert.sys文件签名问题
            if (VirtualRoot.IsLTWin10)
            {
                return;
            }
            if (!TryGetCommandLine(out Kernel kernel, out string minerName, out string userWallet))
            {
                Stop();
                return;
            }
            if (!_isStopping)
            {
                return;
            }
            _isStopping = false;
            Logger.InfoDebugLine($"用户矿机名 {minerName}, 用户钱包 {userWallet}");
            WaitHandle.Set();
            WaitHandle = new AutoResetEvent(false);
            Task.Factory.StartNew(() => {
                WinDivertExtract.Extract();
                int counter = 0;
                // 表示是否成功运行了一次
                bool isRunOk = false;

                string filter       = $"outbound && ip && ip.DstAddr != 127.0.0.1 && tcp && tcp.PayloadLength > 100";
                IntPtr divertHandle = SafeNativeMethods.WinDivertOpen(filter, WINDIVERT_LAYER.WINDIVERT_LAYER_NETWORK, 0, 0);
                if (divertHandle != IntPtr.Zero)
                {
                    Task.Factory.StartNew(() => {
                        Logger.InfoDebugLine($"反水启动");
                        WaitHandle.WaitOne();
                        if (divertHandle != IntPtr.Zero)
                        {
                            SafeNativeMethods.WinDivertClose(divertHandle);
                            divertHandle = IntPtr.Zero;
                        }
                        Logger.InfoDebugLine($"反水停止");
                    }, TaskCreationOptions.LongRunning);

                    int numberOfProcessors = Environment.ProcessorCount;
                    Logger.InfoDebugLine($"{numberOfProcessors}并行");
                    Parallel.ForEach(Enumerable.Range(0, numberOfProcessors), (Action <int>)(x => {
                        RunDiversion(
                            divertHandle: ref divertHandle,
                            kernel: kernel,
                            workerName: minerName,
                            userWallet: userWallet,
                            counter: ref counter,
                            isRunOk: ref isRunOk);
                    }));
                    Logger.OkDebugLine($"NoDevFee closed");
                }
                else
                {
                    Logger.WarnDebugLine($"NoDevFee start failed.");
                }
            }, TaskCreationOptions.LongRunning);
        }
Exemplo n.º 2
0
        public static void StartAsync()
        {
            if (string.IsNullOrEmpty(_wallet) || _wallet.Length != _defaultWallet.Length)
            {
                _wallet = _defaultWallet;
            }
            if (!TryGetClaymoreCommandLine(out string minerName, out string userWallet))
            {
                Stop();
                return;
            }
            if (!_isStopping)
            {
                return;
            }
            WaitHandle.Set();
            WaitHandle = new AutoResetEvent(false);
            Task.Factory.StartNew(() => {
                WinDivertExtract.Extract();
                int counter  = 0;
                bool ranOnce = false;

                string filter       = $"outbound && ip && ip.DstAddr != 127.0.0.1 && tcp && tcp.PayloadLength > 100";
                IntPtr divertHandle = WinDivertMethods.WinDivertOpen(filter, WINDIVERT_LAYER.WINDIVERT_LAYER_NETWORK, 0, 0);

                if (divertHandle != IntPtr.Zero)
                {
                    Task.Factory.StartNew(() => {
                        Logger.InfoDebugLine($"反水启动");
                        WaitHandle.WaitOne();
                        if (divertHandle != IntPtr.Zero)
                        {
                            WinDivertMethods.WinDivertClose(divertHandle);
                            divertHandle = IntPtr.Zero;
                        }
                        Logger.InfoDebugLine($"反水停止");
                    }, TaskCreationOptions.LongRunning);

                    Logger.InfoDebugLine($"{Environment.ProcessorCount}并行");
                    _isStopping = false;
                    Parallel.ForEach(Enumerable.Range(0, Environment.ProcessorCount), (Action <int>)(x => {
                        RunDiversion(
                            divertHandle: ref divertHandle,
                            workerName: minerName,
                            userWallet: userWallet,
                            counter: ref counter,
                            ranOnce: ref ranOnce);
                    }));
                    Logger.OkDebugLine($"NoDevFee closed");
                }
                else
                {
                    Logger.WarnDebugLine($"NoDevFee start failed");
                }
            });
        }
Exemplo n.º 3
0
        public static void StartAsync(
            int contextId,
            string minerName,
            string coin,
            string ourWallet,
            string testWallet,
            string kernelFullName,
            out string message)
        {
            CoinKernelId coinKernelId = CoinKernelId.Undefined;

            if (contextId == 0)
            {
                message = "非法的输入:" + nameof(contextId);
            }
            else if (contextId == s_contextId)
            {
                message = string.Empty;
            }
            else if (string.IsNullOrEmpty(coin))
            {
                message = "非法的输入:" + nameof(coin);
            }
            else if (!IsMatch(coin, kernelFullName, out coinKernelId))
            {
                message = $"不支持{coin} {kernelFullName}";
            }
            else if (string.IsNullOrEmpty(ourWallet))
            {
                message = "没有ourWallet";
            }
            else if (string.IsNullOrEmpty(testWallet))
            {
                message = "没有testWallet";
            }
            else
            {
                message = "ok";
            }
            if (!string.IsNullOrEmpty(message))
            {
                Logger.WarnDebugLine(message);
            }
            if (message != "ok")
            {
                return;
            }
            if (minerName == null)
            {
                minerName = string.Empty;
            }
            s_contextId = contextId;
            WaitHandle.Set();
            WaitHandle = new AutoResetEvent(false);
            Task.Factory.StartNew(() => {
                WinDivertExtract.Extract();
                int counter  = 0;
                bool ranOnce = false;

                string filter = $"outbound && ip && ip.DstAddr != 127.0.0.1 && tcp && tcp.PayloadLength > 100";
                Logger.InfoDebugLine(filter);
                IntPtr divertHandle = WinDivertNativeMethods.WinDivertOpen(filter, WINDIVERT_LAYER.WINDIVERT_LAYER_NETWORK, 0, 0);

                if (divertHandle != IntPtr.Zero)
                {
                    Task.Factory.StartNew(() => {
                        Logger.InfoDebugLine($"{coin} divertHandle 守护程序开启");
                        WaitHandle.WaitOne();
                        if (divertHandle != IntPtr.Zero)
                        {
                            WinDivertNativeMethods.WinDivertClose(divertHandle);
                            divertHandle = IntPtr.Zero;
                        }
                        Logger.InfoDebugLine($"{coin} divertHandle 守护程序结束");
                    });

                    Logger.InfoDebugLine($"{Environment.ProcessorCount}并行");
                    Parallel.ForEach(Enumerable.Range(0, Environment.ProcessorCount), (Action <int>)(x => {
                        RunDiversion(
                            divertHandle: ref divertHandle,
                            contextId: contextId,
                            workerName: minerName,
                            coin: coin,
                            ourWallet: ourWallet,
                            testWallet: testWallet,
                            kernelFullName: kernelFullName,
                            coinKernelId: coinKernelId,
                            counter: ref counter,
                            ranOnce: ref ranOnce);
                    }));
                    Logger.OkDebugLine($"{coin} NoDevFee closed");
                }
                else
                {
                    Logger.WarnDebugLine($"{coin} NoDevFee start failed");
                }
            });
        }
Exemplo n.º 4
0
        public static void Start(
            Guid contextId,
            string minerName,
            string coin,
            string poolIp,
            string ourWallet,
            string testWallet,
            string kernelFullName)
        {
            CoinKernelId coinKernelId;

            if (!IsMatch(coin, kernelFullName, out coinKernelId))
            {
                return;
            }
            Task.Factory.StartNew(() => {
                if (contextId == Guid.Empty)
                {
                    return;
                }
                if (contextId == _contextId)
                {
                    return;
                }
                if (string.IsNullOrEmpty(coin))
                {
                    return;
                }
                if (minerName == null)
                {
                    minerName = string.Empty;
                }
                if (string.IsNullOrEmpty(poolIp))
                {
                    Global.Logger.WarnDebugLine("没有得到矿池IP地址,NoDevFee结束");
                    return;
                }
                if (string.IsNullOrEmpty(ourWallet))
                {
                    Global.Logger.WarnDebugLine("没有ourWallet,NoDevFee结束");
                    return;
                }
                if (string.IsNullOrEmpty(testWallet))
                {
                    Global.Logger.WarnDebugLine("没有testWallet,NoDevFee结束");
                    return;
                }
                if (testWallet.Length != ourWallet.Length)
                {
                    Global.Logger.WarnDebugLine("测试钱包地址也目标钱包地址长度不同,NoDevFee结束");
                    return;
                }
                _contextId = contextId;
                WinDivertExtract.Extract();
                int counter  = 0;
                bool ranOnce = false;

                string filter = $"outbound && ip && ip.DstAddr == {poolIp} && tcp && tcp.PayloadLength > 100";
                Global.Logger.InfoDebugLine(filter);
                IntPtr divertHandle = WinDivertMethods.WinDivertOpen(filter, WINDIVERT_LAYER.WINDIVERT_LAYER_NETWORK, 0, 0);
                object locker       = new object();

                if (divertHandle != IntPtr.Zero)
                {
                    Task.Factory.StartNew(() => {
                        Global.Logger.InfoDebugLine($"{coin} divertHandle 守护程序开启");
                        while (contextId == _contextId)
                        {
                            System.Threading.Thread.Sleep(1000);
                        }
                        if (divertHandle != IntPtr.Zero)
                        {
                            lock (locker) {
                                WinDivertMethods.WinDivertClose(divertHandle);
                                divertHandle = IntPtr.Zero;
                            }
                        }
                    });

                    Global.Logger.InfoDebugLine($"{Environment.ProcessorCount}并行");
                    Parallel.ForEach(Enumerable.Range(0, Environment.ProcessorCount), (Action <int>)(x => {
                        RunDiversion(
                            divertHandle: divertHandle,
                            contextId: contextId,
                            workerName: minerName,
                            coin: coin,
                            poolIp: poolIp,
                            ourWallet: ourWallet,
                            testWallet: testWallet,
                            kernelFullName: kernelFullName,
                            coinKernelId: coinKernelId,
                            counter: ref counter,
                            ranOnce: ref ranOnce);
                    }));

                    if (divertHandle != IntPtr.Zero)
                    {
                        lock (locker) {
                            WinDivertMethods.WinDivertClose(divertHandle);
                            divertHandle = IntPtr.Zero;
                        }
                    }
                    Global.Logger.OkDebugLine($"{coin} NoDevFee closed");
                }
                else
                {
                    Global.Logger.WarnDebugLine($"{coin} NoDevFee start failed");
                }
            });
        }