Browse Source

Removed CloudFlare email deobfuscation

pull/68/head
Ezerous 5 years ago
parent
commit
6e2c123a59
  1. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java
  2. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java
  3. 4
      app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java
  4. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java
  5. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForReplyTask.java
  6. 3
      app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java
  7. 5
      app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java
  8. 2
      app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java
  9. 50
      app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java
  10. 3
      app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseTask.java

3
app/src/main/java/gr/thmmy/mthmmy/activities/profile/latestPosts/LatestPostsFragment.java

@ -32,8 +32,6 @@ import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import timber.log.Timber; import timber.log.Timber;
import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.deobfuscateElements;
/** /**
* Use the {@link LatestPostsFragment#newInstance} factory method to create an instance of this fragment. * Use the {@link LatestPostsFragment#newInstance} factory method to create an instance of this fragment.
*/ */
@ -205,7 +203,6 @@ public class LatestPostsFragment extends BaseFragment implements LatestPostsAdap
return true; return true;
} }
deobfuscateElements(latestPostsRows, false);
for (Element row : latestPostsRows) { for (Element row : latestPostsRows) {
String pTopicUrl, pTopicTitle, pDateTime, pPost; String pTopicUrl, pTopicTitle, pDateTime, pPost;
if (Integer.parseInt(row.attr("cellpadding")) == 4) { if (Integer.parseInt(row.attr("cellpadding")) == 4) {

3
app/src/main/java/gr/thmmy/mthmmy/activities/profile/stats/StatsFragment.java

@ -46,8 +46,6 @@ import okhttp3.Request;
import okhttp3.Response; import okhttp3.Response;
import timber.log.Timber; import timber.log.Timber;
import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.deobfuscateElements;
public class StatsFragment extends Fragment { public class StatsFragment extends Fragment {
/** /**
* The key to use when putting profile's url String to {@link StatsFragment}'s Bundle. * The key to use when putting profile's url String to {@link StatsFragment}'s Bundle.
@ -173,7 +171,6 @@ public class StatsFragment extends Fragment {
return false; return false;
{ {
Elements titleRows = statsPage.select("table.bordercolor[align]>tbody>tr.titlebg"); Elements titleRows = statsPage.select("table.bordercolor[align]>tbody>tr.titlebg");
deobfuscateElements(titleRows, false);
generalStatisticsTitle = titleRows.first().text(); generalStatisticsTitle = titleRows.first().text();
if (userHasPosts) { if (userHasPosts) {
postingActivityByTimeTitle = titleRows.get(1).text(); postingActivityByTimeTitle = titleRows.get(1).text();

4
app/src/main/java/gr/thmmy/mthmmy/activities/profile/summary/SummaryFragment.java

@ -27,9 +27,6 @@ import gr.thmmy.mthmmy.R;
import gr.thmmy.mthmmy.utils.parsing.ParseHelpers; import gr.thmmy.mthmmy.utils.parsing.ParseHelpers;
import timber.log.Timber; import timber.log.Timber;
import static gr.thmmy.mthmmy.utils.parsing.ParseHelpers.deobfuscateElements;
/** /**
* Use the {@link SummaryFragment#newInstance} factory method to create an instance of this fragment. * Use the {@link SummaryFragment#newInstance} factory method to create an instance of this fragment.
*/ */
@ -135,7 +132,6 @@ public class SummaryFragment extends Fragment {
//Contains all summary's rows //Contains all summary's rows
Elements summaryRows = profile.select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) tr"); Elements summaryRows = profile.select(".bordercolor > tbody:nth-child(1) > tr:nth-child(2) tr");
deobfuscateElements(summaryRows, false);
for (Element summaryRow : summaryRows) { for (Element summaryRow : summaryRows) {
String rowText = summaryRow.text(), pHtml = ""; String rowText = summaryRow.text(), pHtml = "";

3
app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForEditTask.java

@ -2,6 +2,7 @@ package gr.thmmy.mthmmy.activities.topic.tasks;
import android.os.AsyncTask; import android.os.AsyncTask;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
import org.jsoup.select.Selector; import org.jsoup.select.Selector;
@ -46,7 +47,7 @@ public class PrepareForEditTask extends AsyncTask<String, Void, PrepareForEditRe
String postText, commitEditURL, numReplies, seqnum, sc, topic, icon; String postText, commitEditURL, numReplies, seqnum, sc, topic, icon;
OkHttpClient client = BaseApplication.getInstance().getClient(); OkHttpClient client = BaseApplication.getInstance().getClient();
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
document = ParseHelpers.parse(response.body().string()); document = Jsoup.parse(response.body().string());
Element form = document.select("form#postmodify").first(); Element form = document.select("form#postmodify").first();

3
app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/PrepareForReplyTask.java

@ -2,6 +2,7 @@ package gr.thmmy.mthmmy.activities.topic.tasks;
import android.os.AsyncTask; import android.os.AsyncTask;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.parser.Parser; import org.jsoup.parser.Parser;
import org.jsoup.select.Selector; import org.jsoup.select.Selector;
@ -43,7 +44,7 @@ public class PrepareForReplyTask extends AsyncTask<Integer, Void, PrepareForRepl
String numReplies, seqnum, sc, topic; String numReplies, seqnum, sc, topic;
try { try {
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
document = ParseHelpers.parse(response.body().string()); document = Jsoup.parse(response.body().string());
numReplies = replyPageUrl.substring(replyPageUrl.indexOf("num_replies=") + 12); numReplies = replyPageUrl.substring(replyPageUrl.indexOf("num_replies=") + 12);
seqnum = document.select("input[name=seqnum]").first().attr("value"); seqnum = document.select("input[name=seqnum]").first().attr("value");

3
app/src/main/java/gr/thmmy/mthmmy/activities/topic/tasks/TopicTask.java

@ -2,6 +2,7 @@ package gr.thmmy.mthmmy.activities.topic.tasks;
import android.os.AsyncTask; import android.os.AsyncTask;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.nodes.Element; import org.jsoup.nodes.Element;
@ -72,7 +73,7 @@ public class TopicTask extends AsyncTask<String, Void, TopicTaskResult> {
.build(); .build();
try { try {
Response response = BaseApplication.getInstance().getClient().newCall(request).execute(); Response response = BaseApplication.getInstance().getClient().newCall(request).execute();
topic = ParseHelpers.parse(response.body().string()); topic = Jsoup.parse(response.body().string());
ParseHelpers.Language language = ParseHelpers.Language.getLanguage(topic); ParseHelpers.Language language = ParseHelpers.Language.getLanguage(topic);

5
app/src/main/java/gr/thmmy/mthmmy/session/SessionManager.java

@ -8,6 +8,7 @@ import androidx.annotation.Nullable;
import com.franmontiel.persistentcookiejar.PersistentCookieJar; import com.franmontiel.persistentcookiejar.PersistentCookieJar;
import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor; import com.franmontiel.persistentcookiejar.persistence.SharedPrefsCookiePersistor;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import org.jsoup.select.Elements; import org.jsoup.select.Elements;
@ -112,7 +113,7 @@ public class SessionManager {
try { try {
//Make request & handle response //Make request & handle response
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
Document document = ParseHelpers.parse(response.body().string()); Document document = Jsoup.parse(response.body().string());
if (validateRetrievedCookies()) if (validateRetrievedCookies())
{ {
@ -218,7 +219,7 @@ public class SessionManager {
try { try {
//Make request & handle response //Make request & handle response
Response response = client.newCall(request).execute(); Response response = client.newCall(request).execute();
Document document = ParseHelpers.parse(response.body().string()); Document document = Jsoup.parse(response.body().string());
Elements loginButton = document.select("[value=Login]"); //Attempt to find login button Elements loginButton = document.select("[value=Login]"); //Attempt to find login button
if (!loginButton.isEmpty()) //If login button exists, logout was successful if (!loginButton.isEmpty()) //If login button exists, logout was successful

2
app/src/main/java/gr/thmmy/mthmmy/utils/NetworkTask.java

@ -54,7 +54,7 @@ public abstract class NetworkTask<T> extends ExternalAsyncTask<String, Parcel<T>
return new Parcel<>(NetworkResultCodes.NETWORK_ERROR, null); return new Parcel<>(NetworkResultCodes.NETWORK_ERROR, null);
} }
try { try {
T data = performTask(ParseHelpers.parse(responseBodyString), response); T data = performTask(Jsoup.parse(responseBodyString), response);
int resultCode = getResultCode(response, data); int resultCode = getResultCode(response, data);
return new Parcel<>(resultCode, data); return new Parcel<>(resultCode, data);
} catch (ParseException pe) { } catch (ParseException pe) {

50
app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseHelpers.java

@ -188,56 +188,6 @@ public class ParseHelpers {
else return ""; else return "";
} }
/**
* Method that replaces CloudFlare-obfuscated emails with deobfuscated ones
* Replace Jsoup.parse with this wherever needed
*
* @param html html to parse
* @return a document with deobfuscated emails
*/
public static Document parse(String html) {
Document document = Jsoup.parse(html);
deobfuscateElements(document.select("span.__cf_email__,a.__cf_email__"), true);
return document;
}
/**
* Use this method instead of parse() if you are targeting specific elements
*/
public static void deobfuscateElements(Elements elements, boolean found) {
if (!found)
elements = elements.select("span.__cf_email__,a.__cf_email__");
for (Element obfuscatedElement : elements) {
String deobfuscatedEmail = deobfuscateEmail(obfuscatedElement.attr("data-cfemail"));
if (obfuscatedElement.is("span")) {
Element parent = obfuscatedElement.parent();
if (parent.is("a") && parent.attr("href").contains("email-protection"))
parent.attr("href", "mailto:" + deobfuscatedEmail);
} else if (obfuscatedElement.attr("href").contains("email-protection"))
obfuscatedElement.attr("href", "mailto:" + deobfuscatedEmail);
obfuscatedElement.replaceWith(new TextNode(deobfuscatedEmail, ""));
}
}
/**
* @param obfuscatedEmail CloudFlare-obfuscated email
* @return deobfuscated email
*/
private static String deobfuscateEmail(String obfuscatedEmail) {
//Deobfuscate
final StringBuilder stringBuilder = new StringBuilder();
final int r = Integer.parseInt(obfuscatedEmail.substring(0, 2), 16);
for (int n = 2; n < obfuscatedEmail.length(); n += 2) {
final int i = Integer.parseInt(obfuscatedEmail.substring(n, n + 2), 16) ^ r;
stringBuilder.append(Character.toString((char) i));
}
Timber.d("Email deobfuscated.");
return stringBuilder.toString();
}
public static String emojiTagToHtml(String emojiTagedString) { public static String emojiTagToHtml(String emojiTagedString) {
HashMap<Pattern, String> tagToHtmlMap = new HashMap<>(); HashMap<Pattern, String> tagToHtmlMap = new HashMap<>();

3
app/src/main/java/gr/thmmy/mthmmy/utils/parsing/ParseTask.java

@ -3,6 +3,7 @@ package gr.thmmy.mthmmy.utils.parsing;
import android.os.AsyncTask; import android.os.AsyncTask;
import android.widget.Toast; import android.widget.Toast;
import org.jsoup.Jsoup;
import org.jsoup.nodes.Document; import org.jsoup.nodes.Document;
import java.io.IOException; import java.io.IOException;
@ -41,7 +42,7 @@ public abstract class ParseTask extends AsyncTask<String, Void, ParseTask.Result
Request request = prepareRequest(params); Request request = prepareRequest(params);
try { try {
Response response = BaseApplication.getInstance().getClient().newCall(request).execute(); Response response = BaseApplication.getInstance().getClient().newCall(request).execute();
Document document = ParseHelpers.parse(response.body().string()); Document document = Jsoup.parse(response.body().string());
parse(document); parse(document);
postParsing(); postParsing();
return ResultCode.SUCCESS; return ResultCode.SUCCESS;

Loading…
Cancel
Save