private void DataOutgoing(object sender, InterceptedEventArgs e) { if (!IsHalted && ViewOutgoing) { PushToQueue(sender, e); } }
public void HandleIncoming(InterceptedEventArgs e) { if (!IsHalted) { PushToQueue(e); } }
public void Write(InterceptedEventArgs e) { if (InvokeRequired) { Invoke(_write, e); } else { bool toServer = (e.Packet.Destination == HDestination.Server); string directionArrow = (toServer ? "->" : "<-"); string packetType = (toServer ? "Outgoing" : "Incoming"); string dataLog = $"{packetType}({e.Replacement.Header}, {e.Replacement.Length}) {directionArrow} {e.Replacement}"; Color highlight = toServer ? OutgoingHighlight : IncomingHighlight; if (e.IsBlocked) { WriteHighlight("Blocked | ", BlockHighlight); } else if (e.WasReplaced) { WriteHighlight("Replaced | ", ReplaceHighlight); } string splitter = (DisplaySplitter ? "\n--------------------\n" : "\n"); WriteHighlight(dataLog + splitter, highlight); LoggerTxt.SelectionStart = LoggerTxt.TextLength; LoggerTxt.ScrollToCaret(); Application.DoEvents(); } }
public void HandleIncoming(InterceptedEventArgs e) { bool threwException = false; try { if (e.Packet.Length == 2) { _incomingOffset++; return; } switch (e.Step - _incomingOffset) { case 1: { InitializeKeys(); ReplaceRemoteSignedPrimes(e); break; } case 2: { ReplaceRemotePublicKey(e); break; } } } catch { threwException = true; } finally { FinalizeInterception(threwException, e); } }
protected virtual void HandleInterception(bool isOutgoing, InterceptedEventArgs e) { if (Extensions.Count < 1) { return; } ExtensionForm[] extensions = _extensions.ToArray(); foreach (ExtensionForm extension in extensions) { if (!extension.IsRunning) { continue; } if (isOutgoing) { extension.Triggers.HandleOutgoing(e); } else { extension.Triggers.HandleIncoming(e); } } }
private void PushToQueue(InterceptedEventArgs e) { Intercepted.Enqueue(e); if (_readQueueTask != null && _readQueueTask.IsCompleted) { _readQueueTask = Task.Factory.StartNew( RunDisplayQueueLoop, TaskCreationOptions.LongRunning); } }
/// <summary> /// Raises the <see cref="DataIncoming"/> event. /// </summary> /// <param name="e">An <see cref="InterceptedEventArgs"/> that contains the event data.</param> /// <returns></returns> protected virtual void OnDataIncoming(InterceptedEventArgs e) { EventHandler <InterceptedEventArgs> handler = DataIncoming; if (handler != null) { handler(this, e); } }
private void DataIncoming(object sender, InterceptedEventArgs e) { ProcessRemoveQueue(); foreach (IDataHandler dataHandler in _dataHandlers) { if (dataHandler.IsHandlingIncoming) { dataHandler.HandleIncoming(e); } } }
private void HandleIncoming(HMessage packet, int count) { var args = new InterceptedEventArgs(ReadIncomingAsync, count, packet); Triggers.HandleIncoming(args); OnDataIncoming(args); if (!args.WasContinued && IsReading) { Task readInTask = ReadIncomingAsync(); } }
private void ReplaceLocalPublicKey(InterceptedEventArgs e) { string localPublicKey = e.Packet.ReadString(); _localSharedKey = Local.Exchange.GetSharedKey(localPublicKey); // Use the same padding the client used when encrypting our public key. Remote.Exchange.Padding = Local.Exchange.Padding; string remotePublicKey = Remote.Exchange.GetPublicKey(); e.Replacement.ReplaceString(remotePublicKey, 0); }
private void HandleIncoming(byte[] data, int count) { var args = new InterceptedEventArgs(ReadIncomingAsync, count, data, HDestination.Client); Triggers.HandleIncoming(args); OnDataIncoming(args); if (!args.WasContinued && IsReading) { ReadIncomingAsync(); } }
private void PushToQueue(object sender, InterceptedEventArgs e) { if (e.IsBlocked && !DisplayBlocked) { return; } Intercepted.Enqueue(e); if (!_isReadingQueue) { _readQueueTask = Task.Factory.StartNew( RunDisplayQueueLoop, TaskCreationOptions.LongRunning); } }
private void ReplaceRemoteSignedPrimes(InterceptedEventArgs e) { string remoteP = e.Packet.ReadString(); string remoteG = e.Packet.ReadString(); Remote.Exchange.VerifyDHPrimes(remoteP, remoteG); // Use the same padding the server used when signing our generated primes. Local.Exchange.Padding = Remote.Exchange.Padding; string localP = Local.Exchange.GetSignedP(); string localG = Local.Exchange.GetSignedG(); e.Replacement = new HMessage(e.Packet.Header, localP, localG); }
private void HandleMessage(byte[] data, HDestination destination) { var args = new InterceptedEventArgs(ReadMessageAsync, 0, new HMessage(data, destination)); Task readTask = ReadMessageAsync(); // Keep reading. if (destination == HDestination.Server) { _extension.Triggers.HandleOutgoing(args); OnDataOutgoing(args); } else { _extension.Triggers.HandleIncoming(args); OnDataIncoming(args); } }
private void RunDisplayQueueLoop() { if (!_isReadingQueue && Monitor.TryEnter(Intercepted)) { _isReadingQueue = true; try { while (Intercepted.Count > 0) { InterceptedEventArgs e = Intercepted.Dequeue(); bool toServer = (e.Packet.Destination == HDestination.Server); if (toServer && !ViewOutgoing) { continue; } if (!toServer && !ViewIncoming) { continue; } if (e.IsBlocked && !DisplayBlocked) { continue; } while (!IsLoaded) { Thread.Sleep(100); } Write(e); } } finally { Monitor.Exit(Intercepted); _isReadingQueue = false; } } else { return; } }
private void ReplaceRemotePublicKey(InterceptedEventArgs e) { string remotePublicKey = e.Packet.ReadString(); _remoteSharedKey = Remote.Exchange.GetSharedKey(remotePublicKey); // Use the same padding the server used when signing our public key. Local.Exchange.Padding = Remote.Exchange.Padding; string localPublicKey = Local.Exchange.GetPublicKey(); e.Replacement.ReplaceString(localPublicKey, 0); Local.Exchange.Dispose(); Remote.Exchange.Dispose(); Local.Decrypter = new Rc4(_localSharedKey); Remote.Encrypter = new Rc4(_remoteSharedKey); }
private void AttachedIncoming(InterceptedEventArgs e) { // If we can't read a string, leave this method. if (!e.Packet.CanReadString()) { return; } string value = e.Packet.ReadString(); switch (value.ToLower()) { case "block": { e.IsBlocked = true; break; } case "replace": { // Replace the first string found in the packet. e.Replacement.RemoveString(0); e.Replacement.WriteString("Replaced!", 0); break; } case "freeze": { // Tell the contractor to continue reading data from local/remote endpoint. // Does not wait for this method to finish, but the packet being processed // can still be used: blocked/replaced if (e.IsAsyncCapable) { e.ContinueRead(); } // Simulate a long synchronous process for one second(1000ms). Thread.Sleep(1000); break; } } }
public async void getAwhisper(object sneder, InterceptedEventArgs e) { int playerIndex = e.Packet.ReadInteger(); string Username = e.Packet.ReadString(); string message = e.Packet.ReadString(); e.Packet.ReadInteger(); //bs e.Packet.ReadInteger(); //bs e.Packet.ReadInteger(); //bs switch (message) { case "test": { await Connection.SendToServerAsync(723, "Anthonyy", "test"); break; } } }
private void FinalizeInterception(bool threwException, InterceptedEventArgs e) { e.IsBlocked = false; bool isOutgoing = (e.Packet.Destination == HDestination.Server); if (threwException || (isOutgoing && e.Step == 2 && e.Packet.Length != 2)) { Local.Encrypter = null; Local.Decrypter = null; Remote.Encrypter = null; Remote.Decrypter = null; Local.Exchange.Dispose(); Remote.Exchange.Dispose(); DataManager.RemoveDataHandler(this); } }
private void Synthesizer_Intercepted(object sender, InterceptedEventArgs e) { var len = waveViewBuffer.GetLength(); if (len >= WaveBufferLength) { var buffer = SynthesizerBuffer ?? new AudioBuffer() { Floats = new float[WaveBufferLength], SampleRate = e.Format.SampleRate }; waveViewBuffer.Dequeue(buffer.Floats, WaveBufferLength); try { Dispatcher.CurrentDispatcher.Invoke(() => { if (SynthesizerBuffer == null) { SynthesizerBuffer = buffer; } else { SynthesizerBuffer = new AudioBuffer() { Floats = buffer.Floats, SampleRate = e.Format.SampleRate }; } }); } catch (TaskCanceledException) { } } waveViewBuffer.Enqueue(e.Buffer); }
public void HandleOutgoing(InterceptedEventArgs e) { bool threwException = false; try { switch (e.Step) { case 3: { ReplaceLocalPublicKey(e); break; } case 4: { FinalizeHandshake(); break; } } } catch { threwException = true; } finally { FinalizeInterception(threwException, e); } }
public void HandleOutgoing(InterceptedEventArgs e) { HandleInterception(true, e); }
public void HandleIncoming(InterceptedEventArgs e) { HandleInterception(false, e); }
public void HandleIncoming(InterceptedEventArgs e) { }
public void HandleOutgoing(InterceptedEventArgs e) { }
protected virtual void OnDataIncoming(InterceptedEventArgs e) { DataIncoming?.Invoke(this, e); }
private void DataIncoming(object sender, InterceptedEventArgs e) => HandleIncoming(e);
private void RunDisplayQueueLoop() { if (Monitor.TryEnter(Intercepted)) { try { while (Intercepted.Count > 0) { InterceptedEventArgs args = Intercepted.Dequeue(); bool toServer = (args.Packet.Destination == HDestination.Server); if (args.IsBlocked && !DisplayBlocked) { continue; } if (toServer && !IsHandlingOutgoing) { continue; } if (!toServer && !IsHandlingIncoming) { continue; } string packetLog = ExtractPacketLog(args.Replacement, toServer); Color packetLogHighlight = (toServer ? OutgoingHighlight : IncomingHighlight); if (args.IsBlocked) { WriteHighlight("Blocked ", BlockHighlight); } else if (args.WasReplaced) { WriteHighlight("Replaced ", ReplaceHighlight); } WriteHighlight(packetLog + "\r\n", packetLogHighlight); if (DisplayStructures) { string structureLog = ExtractStructureLog(args.Replacement, toServer); if (!string.IsNullOrWhiteSpace(structureLog)) { WriteHighlight(structureLog + "\r\n", PacketStructHighlight); } } if (args.Executions.Count > 0) { WriteHighlight("\r\n", BackColor); for (int i = 0; i < args.Executions.Count; i++) { HMessage packet = args.Executions[i]; WriteHighlight(ExtractPacketLog(packet, toServer) + "\r\n", packetLogHighlight); } } WriteHighlight("--------------------\r\n", packetLogHighlight); RefreshLog(); } } finally { Monitor.Exit(Intercepted); Application.DoEvents(); } } }
private void DataOutgoing(object sender, InterceptedEventArgs e) => HandleOutgoing(e);
private void DataIncoming(object sender, InterceptedEventArgs e) { try { switch (e.Step - _inStepOffset) { case 1: { if (RealExponent == 0) { RealExponent = DEFAULT_REAL_EXPONENT; } if (string.IsNullOrWhiteSpace(RealModulus)) { RealModulus = DEFAULT_REAL_MODULUS; } Remote.Exchange = new HKeyExchange(RealExponent, RealModulus); Local.Exchange = new HKeyExchange(FAKE_EXPONENT, FAKE_MODULUS, FAKE_PRIVATE_EXPONENT); string possibleSignedPrime = e.Packet.ReadString(); if (!e.Packet.CanRead <string>()) { _bannerToken = possibleSignedPrime; Eavesdropper.EavesdropperResponse += EavesdropperResponse; Eavesdropper.Initiate(8080); return; } string signedGenerator = e.Packet.ReadString(); Remote.Exchange.DoHandshake(possibleSignedPrime, signedGenerator); Local.Exchange.Rsa.Padding = Remote.Exchange.Rsa.Padding; e.Replacement = new HMessage(e.Packet.Header, Local.Exchange.GetSignedPrime(), Local.Exchange.GetSignedGenerator()); break; } case 2: { if (e.Packet.Length < 5) { _inStepOffset++; return; } _remoteKey = Remote.Exchange.GetSharedKey(e.Packet.ReadString()); if (_banner == null) { Local.Exchange.Rsa.Padding = Remote.Exchange.Rsa.Padding; e.Replacement.Replace <string>(0, Local.Exchange.GetPublicKey()); } else { e.Replacement = new HMessage(e.Packet.Header, "1"); } RealExponent = 0; RealModulus = string.Empty; Local.Exchange.Dispose(); Remote.Exchange.Dispose(); Local.Decrypter = new Rc4(_localKey); Remote.Decrypter = new Rc4(_remoteKey); break; } case 3: { if (Remote.IsDecryptionRequired) { Local.Encrypter = new Rc4(_localKey); } MainUI.Connection.DataIncoming -= DataIncoming; break; } } } catch { MainUI.Connection.DataIncoming -= DataIncoming; MainUI.Connection.DataOutgoing -= DataOutgoing; } finally { e.IsBlocked = false; } }