Esempio n. 1
0
        private void OnPacketArrival(object sender, CaptureEventArgs e)
        {
            var parsedPacket = Packet.ParsePacket(e.Packet.LinkLayerType, e.Packet.Data);
            var ethPacket    = (EthernetPacket)parsedPacket;
            var injector     = Locator.Current.GetService <IInjectorService>();

            if (InterceptedMacAddress.Length < 16)
            {
                InterceptedMacAddress = string.Join(":", Enumerable.Range(0, 6)
                                                    .Select(i => ethPacket.SourceHardwareAddress.ToString()
                                                            .Substring(i * 2, 2)));

                Stop();
                Start(InterceptedMacAddress, _deviceAddress);
                OnMacDetected?.Invoke(this, new MacDetectedEventArgs {
                    MacAddress = InterceptedMacAddress
                });

                injector.SetGamePacketTransferEnabled(true, ethPacket.SourceHardwareAddress.ToString());

                SendDebugMessage("Got mac address! " + InterceptedMacAddress + " enabling game packet transfer!");
            }

            _packetCount++;
            injector.Enqueue(ethPacket);
        }
Esempio n. 2
0
        private ICaptureDevice SetupPcap()
        {
            SendDebugMessage("Searching for network devices...");
            var devices = CaptureDeviceList.Instance;

            var device = devices.FirstOrDefault(d =>
            {
                d.Open();
                try
                {
                    var devMac = d.MacAddress?.ToString();
                    return(devMac.Equals(_deviceAddress));
                }
                catch (Exception) { }
                finally
                {
                    d.Close();
                }

                return(false);
            });

            if (device == null)
            {
                SendDebugMessage("Invalid network adapter. Please open settings and select a new one.");
                return(null);
            }

            SendDebugMessage(String.Format("Listening on {0}",
                                           ((LibPcapLiveDevice)device).Interface.FriendlyName));

            device.OnPacketArrival += OnPacketArrival;
            device.Open(DeviceMode.Promiscuous, 1);

            if (InterceptedMacAddress == null || InterceptedMacAddress.Length < 16)
            {
                device.Filter = BuildRangeFilter();
            }
            else
            {
                var           macParts = InterceptedMacAddress.Split(":");
                StringBuilder sBuilder = new StringBuilder();

                for (var i = 0; i < macParts.Length; i++)
                {
                    sBuilder.Append($"ether[{6 + i}]=0x{macParts[i]}");

                    if (i < macParts.Length - 1)
                    {
                        sBuilder.Append(" and ");
                    }
                }
                device.Filter = sBuilder.ToString();

                var injector = Locator.Current.GetService <IInjectorService>();
                injector.SetGamePacketTransferEnabled(true, InterceptedMacAddress);
                OnMacDetected?.Invoke(this, new MacDetectedEventArgs {
                    MacAddress = InterceptedMacAddress
                });
            }

            return(device);
        }