Skip to content

Commit

Permalink
- Support new obfuscated Google Drive index (@googledrive/index)
Browse files Browse the repository at this point in the history
  • Loading branch information
KoalaBear84 committed Nov 14, 2021
1 parent 1699705 commit 329b1a8
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 23 deletions.
3 changes: 2 additions & 1 deletion src/OpenDirectoryDownloader/DirectoryParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,8 @@ public static async Task<WebDirectory> ParseHtml(WebDirectory webDirectory, stri
htmlDocument.QuerySelector("script[src*=\"/sawankumar/Google-Drive-Index-III\" i]") != null ||
htmlDocument.QuerySelector("script[src*=\"/goIndex-theme-nexmoe\" i]") != null ||
htmlDocument.QuerySelector("script[src*=\"/cheems/GDIndex\" i]") != null ||
htmlDocument.QuerySelector("script[src*=\"/cheems/goindex-extended\" i]") != null)
htmlDocument.QuerySelector("script[src*=\"/cheems/goindex-extended\" i]") != null ||
htmlDocument.QuerySelector("script[src*=\"/@googledrive/index\" i]") != null)
{
return await BhadooIndexParser.ParseIndex(htmlDocument, httpClient, webDirectory);
}
Expand Down
60 changes: 44 additions & 16 deletions src/OpenDirectoryDownloader/Site/GoIndex/BhadooIndexParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ public static class BhadooIndexParser
private static readonly RateLimiter RateLimiter = new RateLimiter(1, TimeSpan.FromSeconds(1));

private static Engine JintEngine { get; set; }
private static bool Obfuscated { get; set; }

public static async Task<WebDirectory> ParseIndex(IHtmlDocument htmlDocument, HttpClient httpClient, WebDirectory webDirectory)
{
Expand All @@ -41,12 +42,13 @@ public static async Task<WebDirectory> ParseIndex(IHtmlDocument htmlDocument, Ht
OpenDirectoryIndexer.Session.Parameters[Constants.Parameters_Password] = "@ttu001";

Dictionary<string, string> postValues = new Dictionary<string, string>
{
{ "password", OpenDirectoryIndexer.Session.Parameters[Constants.Parameters_Password] },
{ "page_token", string.Empty },
{ "page_index", "0" },
{ "q", "" }
};
{
{ "password", OpenDirectoryIndexer.Session.Parameters[Constants.Parameters_Password] },
{ "page_token", string.Empty },
{ "page_index", "0" },
{ "q", "" }
};

HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, webDirectory.Uri) { Content = new FormUrlEncodedContent(postValues) };
HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(httpRequestMessage);

Expand Down Expand Up @@ -96,17 +98,42 @@ private static async Task<string> DecodeResponse(IHtmlDocument htmlDocument, Htt
{
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);
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 = await httpClient.GetStringAsync(appJsScript.Source.Replace("obf.", string.Empty));
List<JavaScriptHelper.Function> functions = JavaScriptHelper.Parse(appJsSource);
JavaScriptHelper.Function readFunction = functions.FirstOrDefault(f => f.Name == "read");

JintEngine = new Engine();
JintEngine.Execute(readFunction.Body);

JintEngine.Execute(functions.FirstOrDefault(f => f.Name == "read").Body);

if (Obfuscated)
{
Func<string, string> atob = str => Encoding.UTF8.GetString(Convert.FromBase64String(str));
JintEngine.SetValue("atob", atob);

JintEngine.Execute(functions.FirstOrDefault(f => f.Name == "gdidecode").Body);
}
}

JsValue jsValue = JintEngine.Invoke("read", responseString);
responseJson = Encoding.UTF8.GetString(Convert.FromBase64String(jsValue.ToString()));

if (Obfuscated)
{
jsValue = JintEngine.Invoke("gdidecode", jsValue.ToString());
responseJson = jsValue.ToString();
}
else
{
responseJson = Encoding.UTF8.GetString(Convert.FromBase64String(jsValue.ToString()));
}
}

return responseJson;
Expand Down Expand Up @@ -137,11 +164,12 @@ private static async Task<WebDirectory> ScanAsync(IHtmlDocument htmlDocument, Ht
Logger.Warn($"Retrieving listings for {webDirectory.Uri}, page {pageIndex + 1}");

Dictionary<string, string> postValues = new Dictionary<string, string>
{
{ "password", OpenDirectoryIndexer.Session.Parameters[Constants.Parameters_Password] },
{ "page_token", nextPageToken },
{ "page_index", pageIndex.ToString() }
};
{
{ "password", OpenDirectoryIndexer.Session.Parameters[Constants.Parameters_Password] },
{ "page_token", nextPageToken },
{ "page_index", pageIndex.ToString() }
};

HttpRequestMessage httpRequestMessage = new HttpRequestMessage(HttpMethod.Post, webDirectory.Uri) { Content = new FormUrlEncodedContent(postValues) };
HttpResponseMessage httpResponseMessage = await httpClient.SendAsync(httpRequestMessage);

Expand Down
12 changes: 6 additions & 6 deletions src/OpenDirectoryDownloader/Site/GoIndex/GdIndexParser.cs
Original file line number Diff line number Diff line change
Expand Up @@ -63,12 +63,12 @@ public static async Task<WebDirectory> ParseIndex(HttpClient httpClient, WebDire
Logger.Info($"Using password: {OpenDirectoryIndexer.Session.Parameters[Constants.Parameters_Password]}");

httpResponseMessage = await httpClient.PostAsync($"{webDirectory.Uri}?rootId={rootId}", new StringContent(JsonConvert.SerializeObject(new Dictionary<string, object>
{
{ "page_index", 0 },
{ "page_token", null },
{ "password", OpenDirectoryIndexer.Session.Parameters[Constants.Parameters_Password] },
{ "q", "" }
})));
{
{ "page_index", 0 },
{ "page_token", null },
{ "password", OpenDirectoryIndexer.Session.Parameters[Constants.Parameters_Password] },
{ "q", "" }
})));

if (httpResponseMessage.IsSuccessStatusCode)
{
Expand Down

0 comments on commit 329b1a8

Please sign in to comment.