Ejemplo n.º 1
0
        private void ReplaceResources(object sender, ResponseInterceptedEventArgs e)
        {
            string absoluteUri = e.Response.ResponseUri.AbsoluteUri;

            if (ResourceReplacements.ContainsKey(absoluteUri))
            {
                var    httpResponse   = (HttpWebResponse)e.Response;
                string replacementUrl = ResourceReplacements[absoluteUri];

                if (httpResponse.StatusCode == HttpStatusCode.TemporaryRedirect)
                {
                    ResourceReplacements.Remove(absoluteUri);
                    absoluteUri = httpResponse.Headers[HttpResponseHeader.Location];
                    ResourceReplacements[absoluteUri] = replacementUrl;
                    return;
                }

                if (replacementUrl.StartsWith("http"))
                {
                    using (var webClient = new WebClient())
                        e.Payload = webClient.DownloadData(replacementUrl);
                }
                else
                {
                    e.Payload = File.ReadAllBytes(replacementUrl);
                }

                ResourceReplacements.Remove(absoluteUri);
                if (ResourceReplacements.Count < 1)
                {
                    Halt();
                    SetStatus(TanjiState.StandingBy);
                }
            }
        }
Ejemplo n.º 2
0
        private void CoTVariablesVw_ItemChecked(object sender, ItemCheckedEventArgs e)
        {
            string name        = e.Item.Text;
            string value       = e.Item.SubItems[1].Text;
            bool   updateValue = (e.Item.Checked && !string.IsNullOrWhiteSpace(value));

            if (updateValue)
            {
                ResourceReplacements[name] = value;
            }
            else if (ResourceReplacements.ContainsKey(name))
            {
                ResourceReplacements.Remove(name);
            }
        }
Ejemplo n.º 3
0
        private void ExtractGameData(object sender, ResponseInterceptedEventArgs e)
        {
            if (e.Response.ContentType != "text/html")
            {
                return;
            }
            if (GameData != null)
            {
                return;
            }

            string responseBody = Encoding.UTF8.GetString(e.Payload);

            if (responseBody.Contains("swfobject.embedSWF") &&
                responseBody.Contains("connection.info.host"))
            {
                Eavesdropper.ResponseIntercepted -= ExtractGameData;
                try
                {
                    GameData = new HGameData(responseBody);
                    Hotel    = SKore.ToHotel(GameData.InfoHost);

                    var    clientUri  = new Uri(GameData["flash.client.url"]);
                    string clientPath = clientUri.Segments[2].TrimEnd('/');

                    Task <bool> gameClientVerifierTask =
                        VerifyGameClientAsync($"{_modifiedClientsDir.FullName}\\{clientPath}\\Habbo.swf");

                    if (e.Response.ResponseUri.Segments.Length > 2)
                    {
                        // TODO: Set uniqueId somewhere.
                        //GameData.UniqueId =
                        //    e.Response.ResponseUri.Segments[2].TrimEnd('/');
                    }

                    string embeddedSwf  = responseBody.GetChild("embedSWF(", ',');
                    string nonCachedSwf = $"{embeddedSwf} + \"?{DateTime.Now.Ticks}-Tanji\"";

                    responseBody = responseBody.Replace(
                        "embedSWF(" + embeddedSwf, "embedSWF(" + nonCachedSwf);
                    e.Payload = Encoding.UTF8.GetBytes(responseBody);

                    var resourceKeys = ResourceReplacements.Keys.ToArray();
                    foreach (string resourceKey in resourceKeys)
                    {
                        string realValue = GameData[resourceKey]
                                           .Replace("\\/", "/");

                        string fakeValue =
                            ResourceReplacements[resourceKey];

                        ResourceReplacements.Remove(resourceKey);
                        ResourceReplacements[realValue] = fakeValue;
                    }
                    if (gameClientVerifierTask.Result)
                    {
                        SetStatus(TanjiState.InjectingClient);
                        Eavesdropper.RequestIntercepted += InjectClient;
                    }
                    else
                    {
                        SetStatus(TanjiState.InterceptingClient);
                        Eavesdropper.ResponseIntercepted += ReplaceClient;
                    }
                }
                catch (Exception ex) { WriteLog(ex); }
                finally
                {
                    if (GameData == null)
                    {
                        Eavesdropper.ResponseIntercepted += ExtractGameData;
                    }
                }
            }
        }