private static async Task <string> DecodeResponse(IHtmlDocument htmlDocument, HttpClient httpClient, HttpResponseMessage httpResponseMessage) { string responseString = await httpResponseMessage.Content.ReadAsStringAsync(); string responseJson = string.Empty; if (responseString.StartsWith("{")) { responseJson = responseString; } else { if (JintEngine == null) { IHtmlScriptElement appJsScript = htmlDocument.Scripts.FirstOrDefault(s => s.Source?.Contains("app.js") == true || s.Source?.Contains("app.min.js") == true); string appJsSource = await httpClient.GetStringAsync(appJsScript.Source); List <JavaScriptHelper.Function> functions = JavaScriptHelper.Parse(appJsSource); JavaScriptHelper.Function readFunction = functions.FirstOrDefault(f => f.Name == "read"); JintEngine = new Engine(); JintEngine.Execute(readFunction.Body); } JsValue jsValue = JintEngine.Invoke("read", responseString); responseJson = Encoding.UTF8.GetString(Convert.FromBase64String(jsValue.ToString())); } return(responseJson); }
private static async Task <string> DecodeResponse(IHtmlDocument htmlDocument, HttpClient httpClient, HttpResponseMessage httpResponseMessage) { string responseString = await httpResponseMessage.Content.ReadAsStringAsync(); string responseJson = string.Empty; if (responseString.StartsWith("{")) { responseJson = responseString; } else { lock (DecodeResponseLock) { if (JintEngine == null) { IHtmlScriptElement appJsScript = htmlDocument.Scripts.FirstOrDefault(s => s.Source?.Contains("app.js") == true || s.Source?.Contains("app.min.js") == true || s.Source?.Contains("app.obf.js") == true || s.Source?.Contains("app.obf.min.js") == true ); Obfuscated = appJsScript.Source.Contains("obf."); string appJsSource = httpClient.GetStringAsync(appJsScript.Source.Replace("obf.", string.Empty)).GetAwaiter().GetResult(); List <JavaScriptHelper.Function> functions = JavaScriptHelper.Parse(appJsSource); JintEngine = new Engine(); JintEngine.Execute(functions.FirstOrDefault(f => f.Name == "read").Body); if (Obfuscated) { Func <string, string> atob = str => Encoding.Latin1.GetString(Convert.FromBase64String(str)); JintEngine.SetValue("atob", atob); JintEngine.Execute(functions.FirstOrDefault(f => f.Name == "gdidecode").Body); } } JsValue jsValue = JintEngine.Invoke("read", responseString); if (Obfuscated) { jsValue = JintEngine.Invoke("gdidecode", jsValue.ToString()); responseJson = jsValue.ToString(); } else { responseJson = Encoding.UTF8.GetString(Convert.FromBase64String(jsValue.ToString())); } } } return(responseJson); }