use of com.squareup.duktape.Duktape in project MiMangaNu by raulhaag.
the class KissManga method chapterInit.
@Override
public void chapterInit(Chapter chapter) throws Exception {
if (chapter.getPages() == 0) {
int pages = 0;
String source = getNavigatorAndFlushParameters().get(HOST + chapter.getPath().replaceAll("[^!-z]+", ""));
String ca = getNavigatorAndFlushParameters().get(HOST + "/Scripts/ca.js");
String lo = getNavigatorAndFlushParameters().get(HOST + "/Scripts/lo.js");
try (Duktape duktape = Duktape.create()) {
duktape.evaluate(ca);
duktape.evaluate(lo);
Pattern p = Pattern.compile("javascript\">(.+?)<", Pattern.DOTALL);
Matcher m = p.matcher(source);
while (m.find()) {
if (m.group(1).contains("CryptoJS")) {
duktape.evaluate(m.group(1));
}
}
p = Pattern.compile("lstImages.push\\((.+?\\))\\)", Pattern.DOTALL);
m = p.matcher(source);
String images = "";
String image;
while (m.find()) {
pages++;
image = (String) duktape.evaluate(m.group(1) + ".toString()");
images = images + "|" + image;
}
chapter.setExtra(images);
}
chapter.setPages(pages);
}
}
use of com.squareup.duktape.Duktape in project MiMangaNu by raulhaag.
the class CFInterceptor method resolveOverCF.
public Response resolveOverCF(Chain chain, Response response) throws IOException {
try {
Thread.sleep(4000);
} catch (InterruptedException e) {
e.printStackTrace();
}
Request request = response.request();
String content = response.body().string();
String domain = request.url().host().trim();
String rawOperation = getFirstMatch(OPERATION_PATTERN, content);
String challenge = getFirstMatch(CHALLENGE_PATTERN, content);
String challengePass = getFirstMatch(PASS_PATTERN, content);
if (rawOperation == null || challengePass == null || challenge == null) {
Log.e("CFI", "couldn't resolve over cloudflare");
// returning null here is not a good idea since it could stop a download ~xtj-9182
return response;
}
String operation = rawOperation.replaceAll("a\\.value =(.+?) \\+ .+?;.*", "$1").replaceAll("\\s{3,}[a-z](?: = |\\.).+", "");
String js = operation.replace("\n", "");
Duktape duktape = Duktape.create();
long result = 0;
try {
String res = (String) duktape.evaluate(js + ".toString()");
result = Long.parseLong(res);
} catch (Exception e) {
e.printStackTrace();
} finally {
duktape.close();
}
String answer = String.valueOf(result + domain.length());
String url = new HttpUrl.Builder().scheme("http").host(domain).addPathSegment("cdn-cgi").addPathSegment("l").addPathSegment("chk_jschl").addEncodedQueryParameter("jschl_vc", challenge).addEncodedQueryParameter("pass", challengePass).addEncodedQueryParameter("jschl_answer", answer).build().toString();
Request request1 = new Request.Builder().url(url).header("User-Agent", Navigator.USER_AGENT).header("Referer", request.url().toString()).build();
response.body().close();
// generate the cookie
response = chain.proceed(request1);
response.body().close();
try {
// give it a time and complete the 5 seconds
Thread.sleep(1000);
} catch (InterruptedException e) {
e.printStackTrace();
}
response = chain.proceed(request.newBuilder().build());
return response;
}
Aggregations