示例#1
0
        private async void Connected(object sender, ConnectedEventArgs e)
        {
            if (InvokeRequired)
            {
                Invoke(_connected, sender, e);
                return;
            }

            HMessage remoteEndPointPkt = await Connection.Local.ReceivePacketAsync();

            e.HotelServer           = ConnectionPg.HotelServer = HotelEndPoint.Parse(remoteEndPointPkt.ReadString().Split('\0')[0], remoteEndPointPkt.ReadInteger());
            e.IsFakingPolicyRequest = (e.HotelServer.Hotel == HHotel.Unknown);
            e.HotelServerSource.SetResult(e.HotelServer);

            ConnectionPg.IsReceiving = true;
            Text    = $"Tanji ~ Connected[{e.HotelServer}]";
            TopMost = PacketLoggerUI.TopMost;

            PacketLoggerUI.RevisionTxt.Text = ("Revision: " + Game.Revision);

            PacketLoggerUI.Show();
            PacketLoggerUI.WindowState = FormWindowState.Normal;

            BringToFront();
        }
示例#2
0
 public async Task Start()
 {
     _connection               = new HConnection();
     _connection.Connected    += OnConnect;
     _connection.DataIncoming += OnIncomingData;
     _connection.DataOutgoing += OnOutgoingData;
     await _connection.InterceptAsync(HotelEndPoint.Parse(_host, _port));
 }
示例#3
0
    public void HotelEndPoint_ShouldCreateForValidHostname()
    {
        const string HOSTNAME = "game-us.habbo.com";

        var endpoint = HotelEndPoint.Create(HOSTNAME);

        Assert.Equal(HOSTNAME, endpoint.Host);
        Assert.Equal(HHotel.US, endpoint.Hotel);
    }
示例#4
0
 private void InterceptConnection()
 {
     string[] ports = Program.GameData.InfoPort.Split(',');
     if (ports.Length == 0 || !ushort.TryParse(ports[0], out ushort port) ||
         !HotelEndPoint.TryParse(Program.GameData.InfoHost, port, out HotelEndPoint endpoint))
     {
         throw new Exception("Failed to parse: " + Program.GameData.InfoPort);
     }
     Program.Connection.Intercept(endpoint);
 }
示例#5
0
        private void InjectGameClient(object sender, RequestInterceptedEventArgs e)
        {
            if (e.Request.RequestUri.Query.StartsWith("?Tanji-"))
            {
                Eavesdropper.RequestIntercepted -= InjectGameClient;

                Uri    remoteUrl  = e.Request.RequestUri;
                string clientPath = Path.GetFullPath($"Modified Clients/{remoteUrl.Host}/{remoteUrl.LocalPath}");
                if (!string.IsNullOrWhiteSpace(CustomClientPath))
                {
                    clientPath = CustomClientPath;
                }
#if !NO_CACHE
                if (!File.Exists(clientPath))
#else
                if (true)
#endif
                {
                    Status = INTERCEPTING_CLIENT;
                    Eavesdropper.ResponseIntercepted += InterceptGameClient;
                }
                else
                {
                    Status          = DISASSEMBLING_CLIENT;
                    App.Master.Game = new HGame(clientPath);
                    App.Master.Game.Disassemble();

                    if (App.Master.Game.IsPostShuffle)
                    {
                        Status = GENERATING_MESSAGE_HASHES;
                        App.Master.Game.GenerateMessageHashes();
                    }

                    if (App.Master.GameData.Hotel == HHotel.Unknown && IsAutomaticServerExtraction)
                    {
                        Tuple <string, int?> endPoint = App.Master.Game.ExtractEndPoint();
                        if (!string.IsNullOrWhiteSpace(endPoint.Item1) || endPoint.Item2 != null)
                        {
                            string host = (!string.IsNullOrWhiteSpace(endPoint.Item1) ?
                                           endPoint.Item1 : HotelServer.Host);

                            HotelServer = HotelEndPoint.Parse(host, endPoint.Item2 ?? HotelServer.Port);
                        }
                    }

                    Status = SYNCHRONIZING_GAME;
                    App.Master.Synchronize(App.Master.Game);

                    TerminateProxy();
                    InterceptConnection();
                    e.Request = WebRequest.Create(new Uri(clientPath));
                }
            }
        }
示例#6
0
    public async Task HotelEndPoint_ShouldParseValidHostnameAsync()
    {
        const string HOSTNAME = "game-us.habbo.com";
        const int    PORT     = 30001;

        var endpoint = await HotelEndPoint.ParseAsync(HOSTNAME, PORT);

        Assert.Equal(PORT, endpoint.Port);
        Assert.Equal(HOSTNAME, endpoint.Host);
        Assert.Equal(HHotel.US, endpoint.Hotel);
    }
        private void ConnectionOpened(object sender, ConnectedEventArgs e)
        {
            HPacket endPointPkt = Connection.Local.ReceivePacketAsync().Result;

            e.HotelServer = HotelServer = HotelEndPoint.Parse(endPointPkt.ReadUTF8().Split('\0')[0], endPointPkt.ReadInt32());

            e.HotelServerSource.SetResult(HotelServer);

            _ui.SetStatusMessage(Constants.CONNECTED);

            Invoke((MethodInvoker) delegate
            {
                SearchBtn.Enabled = true;
                Resources.RenderButtonState(SearchBtn, SearchBtn.Enabled);
            });
        }
示例#8
0
        private void ExtractVariables()
        {
            _variables.Clear();
            MatchCollection matches = Regex.Matches(Source, FLASH_VAR_PATTERN, RegexOptions.Multiline);

            foreach (Match match in matches)
            {
                string value    = match.Groups["value"].Value;
                string variable = match.Groups["variable"].Value;
                if (value.Contains("\\/"))
                {
                    value = value.Replace("\\/", "/");
                }
                _variables[variable] = value;
            }
            Hotel = HotelEndPoint.GetHotel(InfoHost);
        }
示例#9
0
        public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string address = value.ToString();

            string[] points = address.Split(':');

            HotelEndPoint endpoint = null;

            if (points.Length == 2)
            {
                string[] ports = points[1].Split(',');
                if (ports.Length > 0 && ushort.TryParse(ports[0], out ushort port))
                {
                    HotelEndPoint.TryParse(points[0], port, out endpoint);
                }
            }
            return(endpoint);
        }
示例#10
0
        private void InterceptClientPage(object sender, ResponseInterceptedEventArgs e)
        {
            if (!e.Response.ContentType.Contains("text/html"))
            {
                return;
            }
            string body = Encoding.UTF8.GetString(e.Payload);

            if (!body.Contains("info.host") && !body.Contains("info.port"))
            {
                return;
            }

            Eavesdropper.ResponseIntercepted -= InterceptClientPage;
            App.Master.GameData.Source        = body;

            if (IsAutomaticServerExtraction)
            {
                string[] ports = App.Master.GameData.InfoPort.Split(',');
                if (ports.Length == 0 ||
                    !ushort.TryParse(ports[0], out ushort port) ||
                    !HotelEndPoint.TryParse(App.Master.GameData.InfoHost, port, out HotelEndPoint endpoint))
                {
                    Cancel(null);
                    return;
                }
                HotelServer = endpoint;
            }

            if (App.Master.GameData.Hotel != HHotel.Unknown)
            {
                body = body.Replace(App.Master.GameData.InfoHost, "127.0.0.1");
            }
            body = body.Replace(".swf", $".swf?Tanji-{DateTime.Now.Ticks}");

            Status = SYNCHRONIZING_GAME_DATA;
            App.Master.Synchronize(App.Master.GameData);

            e.Payload = Encoding.UTF8.GetBytes(body);

            Status = INJECTING_CLIENT;
            Eavesdropper.RequestIntercepted += InjectGameClient;
        }
示例#11
0
        public override object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture)
        {
            string address = value.ToString();

            string[] points = address.Split(':');

            if (points.Length < 2)
            {
                return(null);
            }

            ushort        port     = 0;
            HotelEndPoint endpoint = null;

            if (!ushort.TryParse(points[1], out port) ||
                !HotelEndPoint.TryParse(points[0], port, out endpoint))
            {
                return(null);
            }
            return(endpoint);
        }
示例#12
0
        public async Task InterceptAsync(HotelEndPoint endpoint)
        {
            _isIntercepting = true;
            int interceptCount = 0;

            while (!IsConnected && _isIntercepting)
            {
                try
                {
                    Local = await HNode.AcceptAsync(endpoint.Port).ConfigureAwait(false);

                    if (!_isIntercepting)
                    {
                        break;
                    }

                    if (++interceptCount == SocketSkip)
                    {
                        interceptCount = 0;
                        continue;
                    }

                    byte[] buffer = await Local.PeekAsync(6).ConfigureAwait(false);

                    if (!_isIntercepting)
                    {
                        break;
                    }

                    if (buffer.Length == 0)
                    {
                        interceptCount--;
                        continue;
                    }

                    Remote = await HNode.ConnectNewAsync(endpoint).ConfigureAwait(false);

                    if (!_isIntercepting)
                    {
                        break;
                    }

                    if (HFormat.WedgieOut.GetId(buffer) == 206)
                    {
                        Local.InFormat  = HFormat.WedgieOut;
                        Local.OutFormat = HFormat.WedgieIn;

                        Remote.InFormat  = HFormat.WedgieIn;
                        Remote.OutFormat = HFormat.WedgieOut;
                    }
                    else if (HFormat.EvaWire.GetId(buffer) == 4000)
                    {
                        Local.InFormat  = HFormat.EvaWire;
                        Local.OutFormat = HFormat.EvaWire;

                        Remote.InFormat  = HFormat.EvaWire;
                        Remote.OutFormat = HFormat.EvaWire;
                    }
                    else
                    {
                        buffer = await Local.ReceiveAsync(512).ConfigureAwait(false);

                        await Remote.SendAsync(buffer).ConfigureAwait(false);

                        buffer = await Remote.ReceiveAsync(1024).ConfigureAwait(false);

                        await Local.SendAsync(buffer).ConfigureAwait(false);

                        continue;
                    }
                    if (!_isIntercepting)
                    {
                        break;
                    }

                    IsConnected = true;
                    OnConnected(EventArgs.Empty);

                    _inSteps  = 0;
                    _outSteps = 0;
                    Task interceptOutgoingTask = InterceptOutgoingAsync();
                    Task interceptIncomingTask = InterceptIncomingAsync();
                }
                finally
                {
                    if (!IsConnected)
                    {
                        Local?.Dispose();
                        Remote?.Dispose();
                    }
                }
            }
            HNode.StopListeners(endpoint.Port);
            _isIntercepting = false;
        }
示例#13
0
 public Task InterceptAsync(string host, int port)
 {
     return(InterceptAsync(HotelEndPoint.Parse(host, port)));
 }
示例#14
0
 public static async Task <HProfile> GetProfileAsync(string uniqueId) => HProfile.Create(await ReadContentAsync <string>(HotelEndPoint.GetHotel(uniqueId).ToUri(), $"/api/public/users/{uniqueId}/profile"));
示例#15
0
        public virtual void OnConnected(HPacket packet)
        {
            HotelServer      = HotelEndPoint.Parse(packet.ReadUTF8(), packet.ReadInt32());
            ClientVersion    = packet.ReadUTF8();
            ClientIdentifier = packet.ReadUTF8();
            ClientType       = packet.ReadUTF8();
            try
            {
                MessagesInfoIncoming = new List <HMessage>();
                MessagesInfoOutgoing = new List <HMessage>();
                Out = new Outgoing(new List <HMessage>());
                In  = new Incoming(new List <HMessage>());
                int MessagesInfoLenght = packet.ReadInt32();
                foreach (var i in Enumerable.Range(0, MessagesInfoLenght))
                {
                    int    CurrentMessageID         = packet.ReadInt32();
                    string CurrentMessageHash       = packet.ReadUTF8();
                    string CurrentMessageName       = packet.ReadUTF8();
                    string CurrentMessageStructure  = packet.ReadUTF8();
                    bool   CurrentMessageIsOutgoing = packet.ReadBoolean();
                    string CurrentMessageSource     = packet.ReadUTF8();
                    if (string.IsNullOrWhiteSpace(CurrentMessageHash) || CurrentMessageHash == "NULL")
                    {
                        CurrentMessageHash = CurrentMessageName;
                    }
                    CurrentMessageHash = CurrentMessageSource + "_" + CurrentMessageHash;
                    HMessage CurrentHMessage = new HMessage((ushort)CurrentMessageID, CurrentMessageHash, CurrentMessageName, CurrentMessageStructure);
                    if (CurrentMessageIsOutgoing)
                    {
                        MessagesInfoOutgoing.Add(CurrentHMessage);
                    }
                    else
                    {
                        MessagesInfoIncoming.Add(CurrentHMessage);
                    }
                }
                List <HMessage> GeodeOut = new List <HMessage>();
                List <HMessage> GeodeIn  = new List <HMessage>();
                foreach (PropertyInfo GeodeOutProperty in Out.GetType().GetProperties())
                {
                    try
                    {
                        if (GeodeOutProperty.PropertyType == typeof(HMessage))
                        {
                            GeodeOut.Add(MessagesInfoOutgoing.First(x => x.Name == GeodeOutProperty.Name));
                        }
                    }
                    catch { Console.WriteLine("MessageInfo not found for: " + GeodeOutProperty.Name); }
                }
                foreach (PropertyInfo GeodeInProperty in In.GetType().GetProperties())
                {
                    try
                    {
                        if (GeodeInProperty.PropertyType == typeof(HMessage))
                        {
                            GeodeIn.Add(MessagesInfoIncoming.First(x => x.Name == GeodeInProperty.Name));
                        }
                    }
                    catch { Console.WriteLine("MessageInfo not found for: " + GeodeInProperty.Name); }
                }
                Out = new Outgoing(GeodeOut);
                In  = new Incoming(GeodeIn);
            }
            catch (Exception ex)
            {
                Console.WriteLine("Critical MessagesInfo exception: " + ex.Message);
                MessagesInfo_Failed = true;
            }

            IsConnected = true;
            if (DisableEventHandlers == false)
            {
                try { OnConnectedEvent.Invoke(this, packet); } catch { };//Invoke event handler
            }
        }
示例#16
0
        private void InterceptGameClient(object sender, ResponseInterceptedEventArgs e)
        {
            if (!e.Response.ResponseUri.Query.StartsWith("?Tanji-"))
            {
                return;
            }
            if (e.Response.ContentType != "application/x-shockwave-flash")
            {
                return;
            }
            Eavesdropper.ResponseIntercepted -= InterceptGameClient;

            Uri    remoteUrl  = e.Response.ResponseUri;
            string clientPath = Path.GetFullPath($"Modified Clients/{remoteUrl.Host}/{remoteUrl.LocalPath}");

            string clientDirectory = Path.GetDirectoryName(clientPath);

            Directory.CreateDirectory(clientDirectory);

            Status                   = DISASSEMBLING_CLIENT;
            App.Master.Game          = new HGame(e.Payload);
            App.Master.Game.Location = clientPath;
            App.Master.Game.Disassemble();

            if (App.Master.Game.IsPostShuffle)
            {
                Status = GENERATING_MESSAGE_HASHES;
                App.Master.Game.GenerateMessageHashes();

                Status = MODIFYING_CLIENT;
                App.Master.Game.DisableHostChecks();
                App.Master.Game.InjectKeyShouter(4001);
            }

            if (App.Master.GameData.Hotel == HHotel.Unknown)
            {
                if (IsAutomaticServerExtraction)
                {
                    Tuple <string, int?> endPoint = App.Master.Game.ExtractEndPoint();
                    if (!string.IsNullOrWhiteSpace(endPoint.Item1) || endPoint.Item2 != null)
                    {
                        string host = (!string.IsNullOrWhiteSpace(endPoint.Item1) ?
                                       endPoint.Item1 : HotelServer.Host);

                        HotelServer = HotelEndPoint.Parse(host, endPoint.Item2 ?? HotelServer.Port);
                    }
                }

                Status = MODIFYING_CLIENT;
                App.Master.Game.InjectEndPoint("127.0.0.1", HotelServer.Port);
            }

            Status = SYNCHRONIZING_GAME;
            App.Master.Synchronize(App.Master.Game);

            CompressionKind compression = CompressionKind.ZLIB;

#if DEBUG
            compression = CompressionKind.None;
#endif

            Status    = ASSEMBLING_CLIENT;
            e.Payload = App.Master.Game.ToArray(compression);
            using (var clientStream = File.Open(clientPath, FileMode.Create, FileAccess.Write))
            {
                clientStream.Write(e.Payload, 0, e.Payload.Length);
            }

            TerminateProxy();
            InterceptConnection();
        }
示例#17
0
        public async Task InterceptAsync(HotelEndPoint endpoint)
        {
            _isIntercepting = true;
            int interceptCount = 0;

            while (!IsConnected && _isIntercepting)
            {
                try
                {
                    Local = await HNode.AcceptAsync(ListenPort).ConfigureAwait(false);

                    if (!_isIntercepting)
                    {
                        break;
                    }

                    if (++interceptCount == SocketSkip)
                    {
                        interceptCount = 0;
                        continue;
                    }

                    byte[] buffer = await Local.PeekAsync(6).ConfigureAwait(false);

                    if (!_isIntercepting)
                    {
                        break;
                    }

                    if (buffer.Length == 0)
                    {
                        interceptCount--;
                        continue;
                    }

                    Remote = new HNode();
                    if (BigEndian.ToUInt16(buffer, 4) != 4000)
                    {
                        buffer = await Local.ReceiveAsync(512).ConfigureAwait(false);

                        if (!_isIntercepting)
                        {
                            break;
                        }

                        if (Encoding.UTF8.GetString(buffer) == CROSS_DOMAIN_POLICY_REQUEST)
                        {
                            await Local.SendAsync(Encoding.UTF8.GetBytes(CROSS_DOMAIN_POLICY_RESPONSE)).ConfigureAwait(false);
                        }
                        else
                        {
                            throw new Exception("Expected cross-domain policy request.");
                        }
                        continue;
                    }

                    var args = new ConnectedEventArgs(endpoint);
                    OnConnected(args);

                    endpoint = (args.HotelServer ?? endpoint);
                    if (args.IsFakingPolicyRequest)
                    {
                        using (var tempRemote = await HNode.ConnectNewAsync(endpoint).ConfigureAwait(false))
                        {
                            await tempRemote.SendAsync(Encoding.UTF8.GetBytes(CROSS_DOMAIN_POLICY_REQUEST)).ConfigureAwait(false);
                        }
                    }

                    if (!await Remote.ConnectAsync(endpoint).ConfigureAwait(false))
                    {
                        break;
                    }
                    IsConnected = true;

                    _inSteps  = 0;
                    _outSteps = 0;
                    Task interceptOutgoingTask = InterceptOutgoingAsync();
                    Task interceptIncomingTask = InterceptIncomingAsync();
                }
                finally
                {
                    if (!IsConnected)
                    {
                        Local?.Dispose();
                        Remote?.Dispose();
                    }
                }
            }
            HNode.StopListeners(ListenPort);
            _isIntercepting = false;
        }
 public override HHotel Read(ref Utf8JsonReader reader, Type typeToConvert, JsonSerializerOptions options)
 {
     return(reader.TokenType == JsonTokenType.String ?
            HotelEndPoint.GetHotel(reader.GetString()) : HHotel.Unknown);
 }
示例#19
0
 public ConnectedEventArgs(HotelEndPoint hotelServer)
 {
     HotelServer       = hotelServer;
     HotelServerSource = new TaskCompletionSource <HotelEndPoint>();
 }
 public override void Write(Utf8JsonWriter writer, HHotel value, JsonSerializerOptions options)
 {
     writer.WriteStringValue(HotelEndPoint.GetRegion(value));
 }
示例#21
0
文件: HAPI.cs 项目: xnumad/Sulakore
 public static Task <HProfile> GetProfileAsync(string uniqueId) => ReadContentAsync <HProfile>(HotelEndPoint.GetHotel(uniqueId).ToUri(), $"/api/public/users/{uniqueId}/profile");
示例#22
0
 public ConnectedEventArgs(HotelEndPoint hotelServer)
 {
     HotelServer = hotelServer;
 }
示例#23
0
 public async Task Start()
 {
     await Connection.InterceptAsync(HotelEndPoint.Parse(_host, _port));
 }