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()"); }
/// <summary> /// Walk the file tree starting at a set of roots. /// Collect files in bunches by matching their filenames (without extensions) /// Determine what kind of files they are (packet, frame) and then iterate. /// </summary> /// <param name="roots"></param> /// <returns></returns> public static IEnumerable <byte[]> PacketsFromFileTree(IEnumerable <string> roots) { var fullnames = new List <string>(); var filenames = new List <string>(); foreach (var root in roots) { foreach (var f in FileWalker.WalkITOSFiles(root)) { var filename = Path.GetFileNameWithoutExtension(f); if (filenames.Count < 1 || filenames[filenames.Count - 1].Equals(filename)) { filenames.Add(filename); fullnames.Add(f); } else { // Release files that were buffered foreach (var p in PacketFilter.MaybeUniqueByteArray(FilesToStream(fullnames).Iterator())) { yield return(p); } filenames.Clear(); fullnames.Clear(); filenames.Add(filename); fullnames.Add(f); } } } // Flush any files that were buffered foreach (var p in PacketFilter.MaybeUniqueByteArray(FilesToStream(fullnames).Iterator())) { yield return(p); } }
public OpCodeFunction(Type type, GenericDelegate operation, PacketType packetType = PacketType.Nothing, PacketFilter filter = PacketFilter.LoggedIn, PacketProtectionLevel protectionLevel = PacketProtectionLevel.Admin) { this.type = type; this.operation = operation; this.packetType = packetType; this.filter = filter; this.protectionLevel = protectionLevel; }
private void Listening() { discardedPackets = 0; packetNum = 0; serverRunning = true; destination = new IPEndPoint(IPAddress.Any, (int)destPortBox.Value); // Set up the checker/filter if (discardCheckBox.Checked) { filter = new MagicNumberPacketFilter() { MagicWord = magicWord, AcceptableDestinationPort = (int)destPortBox.Value, AcceptableSourcePort = (int)srcPortBox.Value } } ; else { filter = null; } // Choose the handler. try { logHandler = new PacketLogWriter(logFileBox.Text) { HeaderBytesToRemove = 8 }; } catch { logHandler = null; } handlers.Clear(); if (logHandler != null) { handlers.Add(logHandler); } else { handlers.Add(consoleHandler); } //Create the server. udpClient = new UdpClient(destination); Console.WriteLine("listening on " + destination + "..."); //Listening loop. udpClient.BeginReceive(new AsyncCallback(ReceiveCallback), udpClient); while (serverRunning) { //Sleep for UI to work. Thread.Sleep(500); } if (logHandler != null) { logHandler.Dispose(); } logHandler = null; }
public MainWindow() { try { InitializeComponent(); //Opcode Section PacketTranslator.Init(); pp = new PacketProcessor(this); cap = new Capture(this); filter = new PacketFilter(); pp.Init(); //Serverlist List <ServerInfo> servers = MiscFuncs.LoadServerlistFile(Directory.GetCurrentDirectory() + "\\serverlist.xml"); if (servers != null && servers.Count > 0) { //We got a custom serverlist.xml loaded.... boxServers.Items.Clear(); foreach (var server in servers) { ComboBoxItem item = new ComboBoxItem { Tag = server, Content = server.ToString() }; int index = boxServers.Items.Add(item); if (server.Focus) { boxServers.SelectedIndex = index; } if (server.AutoStart) { btnStartStop_Click(null, null); } } } //Print Info string info = String.Format("Loaded {0} Opcodes. \n" + "Loaded {1} servers.\n" + "Github of this Project: https://github.com/GoneUp/Tera_PacketViewer\n" + "Released at Ragezone: http://forum.ragezone.com/f797/release-tera-live-packet-sniffer-1052922/\n" + "Uses code of the TeraDamageMeter by gothos-folly: https://github.com/gothos-folly/TeraDamageMeter\n" + "Have Fun ;)", PacketTranslator.PacketNames.Count, boxServers.Items.Count); SetText(info); } catch (Exception ex) { string info = "Startup FAIL! Is WinPcap installed? \n " + ex; SetText(info); } }
public void Run() { var s = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp); var target = IPAddress.Parse(_host); var ep = new IPEndPoint(target, _port); foreach (var packet in PacketFilter.BitsPerSecond(_bitsPerSecond, _source)) { //Console.WriteLine(@"sending apid {0}", PacketAccessor.APID(packet)); s.SendTo(packet, PacketAccessor.Length(packet) + 7, SocketFlags.None, ep); //Thread.Sleep(1); } }
public GameClient(ClientWrapper socket) { Queue = new ConcurrentPacketQueue(); PacketFilter = new PacketFilter() { { 10010, 10 }, { 10005, 7 }, { 2064, 4 }, { 2032, 3 }, { 1027, 2 } }; Attackable = false; Action = 0; _socket = socket; Cryptography = new GameCryptography(System.Text.Encoding.Default.GetBytes(Constants.GameCryptographyKey)); DHKeyExchange = new DHKeyExchange.ServerKeyExchange(); }
public bool Update(uint diff, PacketFilter updater) { // Update Timeout timer. UpdateTimeOutTime(diff); // Before we process anything: // If necessary, kick the player from the character select screen if (IsConnectionIdle()) { m_Socket[(int)ConnectionType.Realm].CloseSocket(); } WorldPacket firstDelayedPacket = null; uint processedPackets = 0; long currentTime = Time.UnixTime; WorldPacket packet; //Check for any packets they was not recived yet. while (m_Socket[(int)ConnectionType.Realm] != null && !_recvQueue.IsEmpty && (_recvQueue.TryPeek(out packet, updater) && packet != firstDelayedPacket) && _recvQueue.TryDequeue(out packet)) { try { var handler = PacketManager.GetHandler((ClientOpcodes)packet.GetOpcode()); switch (handler.sessionStatus) { case SessionStatus.Loggedin: if (!_player) { if (!m_playerRecentlyLogout) { if (firstDelayedPacket == null) { firstDelayedPacket = packet; } QueuePacket(packet); Log.outDebug(LogFilter.Network, "Re-enqueueing packet with opcode {0} with with status OpcodeStatus.Loggedin. Player is currently not in world yet.", (ClientOpcodes)packet.GetOpcode()); } break; } else if (_player.IsInWorld && AntiDOS.EvaluateOpcode(packet, currentTime)) { handler.Invoke(this, packet); } break; case SessionStatus.LoggedinOrRecentlyLogout: if (!_player && !m_playerRecentlyLogout && !m_playerLogout) { LogUnexpectedOpcode(packet, handler.sessionStatus, "the player has not logged in yet and not recently logout"); } else if (AntiDOS.EvaluateOpcode(packet, currentTime)) { handler.Invoke(this, packet); } break; case SessionStatus.Transfer: if (!_player) { LogUnexpectedOpcode(packet, handler.sessionStatus, "the player has not logged in yet"); } else if (_player.IsInWorld) { LogUnexpectedOpcode(packet, handler.sessionStatus, "the player is still in world"); } else if (AntiDOS.EvaluateOpcode(packet, currentTime)) { handler.Invoke(this, packet); } break; case SessionStatus.Authed: // prevent cheating with skip queue wait if (m_inQueue) { LogUnexpectedOpcode(packet, handler.sessionStatus, "the player not pass queue yet"); break; } if ((ClientOpcodes)packet.GetOpcode() == ClientOpcodes.EnumCharacters) { m_playerRecentlyLogout = false; } if (AntiDOS.EvaluateOpcode(packet, currentTime)) { handler.Invoke(this, packet); } break; default: Log.outError(LogFilter.Network, "Received not handled opcode {0} from {1}", (ClientOpcodes)packet.GetOpcode(), GetPlayerInfo()); break; } } catch (InternalBufferOverflowException ex) { Log.outError(LogFilter.Network, "InternalBufferOverflowException: {0} while parsing {1} from {2}.", ex.Message, (ClientOpcodes)packet.GetOpcode(), GetPlayerInfo()); } catch (EndOfStreamException) { Log.outError(LogFilter.Network, "WorldSession:Update EndOfStreamException occured while parsing a packet (opcode: {0}) from client {1}, accountid={2}. Skipped packet.", (ClientOpcodes)packet.GetOpcode(), GetRemoteAddress(), GetAccountId()); } processedPackets++; if (processedPackets > 100) { break; } } if (m_Socket[(int)ConnectionType.Realm] != null && m_Socket[(int)ConnectionType.Realm].IsOpen() && _warden != null) { _warden.Update(); } ProcessQueryCallbacks(); if (updater.ProcessUnsafe()) { long currTime = Time.UnixTime; // If necessary, log the player out if (ShouldLogOut(currTime) && m_playerLoading.IsEmpty()) { LogoutPlayer(true); } if (m_Socket[(int)ConnectionType.Realm] != null && GetPlayer() && _warden != null) { _warden.Update(); } //- Cleanup socket if need if ((m_Socket[(int)ConnectionType.Realm] != null && !m_Socket[(int)ConnectionType.Realm].IsOpen()) || (m_Socket[(int)ConnectionType.Instance] != null && !m_Socket[(int)ConnectionType.Instance].IsOpen())) { expireTime -= expireTime > diff ? diff : expireTime; if (expireTime < diff || forceExit || !GetPlayer()) { if (m_Socket[(int)ConnectionType.Realm] != null) { m_Socket[(int)ConnectionType.Realm].CloseSocket(); m_Socket[(int)ConnectionType.Realm] = null; } if (m_Socket[(int)ConnectionType.Instance] != null) { m_Socket[(int)ConnectionType.Instance].CloseSocket(); m_Socket[(int)ConnectionType.Instance] = null; } } } if (m_Socket[(int)ConnectionType.Realm] == null) { return(false); //Will remove this session from the world session map } } return(true); }
public void SetFilterAndPortectionlevel(PacketFilter packetFilter, PacketProtectionLevel packetProtectionLevel) { this.packetFilter = packetFilter; this.packetProtectionLevel = packetProtectionLevel; }