Skip to content
This repository has been archived by the owner on Nov 25, 2023. It is now read-only.

Commit

Permalink
Patch ResourceNotFoundException caused by EdXposed on certain devices
Browse files Browse the repository at this point in the history
  • Loading branch information
MSkjel committed Jun 3, 2019
1 parent 09216fc commit 3a4587c
Show file tree
Hide file tree
Showing 4 changed files with 89 additions and 17 deletions.
4 changes: 2 additions & 2 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,8 @@ android {
applicationId "tw.fatminmin.xposed.minminguard"
minSdkVersion 14
targetSdkVersion 28
versionCode 66
versionName "2.0.7"
versionCode 67
versionName "2.0.8"
}
buildTypes {
release {
Expand Down
93 changes: 78 additions & 15 deletions app/src/main/java/tw/fatminmin/xposed/minminguard/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,29 +2,93 @@

import android.content.Context;
import android.content.SharedPreferences;
import android.content.res.Configuration;
import android.content.res.Resources;
import android.content.res.XModuleResources;
import android.os.Build;

import androidx.annotation.RequiresApi;

import com.crossbowffs.remotepreferences.RemotePreferences;
import de.robv.android.xposed.*;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
import tw.fatminmin.xposed.minminguard.blocker.*;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.*;
import tw.fatminmin.xposed.minminguard.blocker.custom_mod.NextMedia;
import tw.fatminmin.xposed.minminguard.blocker.custom_mod.OneWeather;
import tw.fatminmin.xposed.minminguard.blocker.custom_mod.Viafree;
import tw.fatminmin.xposed.minminguard.blocker.custom_mod._2chMate;

import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

import de.robv.android.xposed.IXposedHookLoadPackage;
import de.robv.android.xposed.IXposedHookZygoteInit;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XC_MethodReplacement;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage.LoadPackageParam;
import tw.fatminmin.xposed.minminguard.blocker.ApiBlocking;
import tw.fatminmin.xposed.minminguard.blocker.Blocker;
import tw.fatminmin.xposed.minminguard.blocker.NameBlocking;
import tw.fatminmin.xposed.minminguard.blocker.UrlFiltering;
import tw.fatminmin.xposed.minminguard.blocker.Util;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Ad2iction;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.AdMarvel;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Adbert;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Adcolony;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Adfurikun;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Adtech;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Amazon;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Amobee;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Aotter;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.AppBrain;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Applovin;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Appnext;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.AppodealMRAID;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Avocarrot;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Bonzai;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Chartboost;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Clickforce;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Domob;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Facebook;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Flurry;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Freewheel;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.GoogleAdmob;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.GoogleGms;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.GoogleGmsDoubleClick;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Hodo;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Inmobi;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Intowow;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Ironsource;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.KuAd;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Madvertise;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.MasAd;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.MdotM;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Millennial;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.MoPub;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.MobFox;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Mobclix;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Nend;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Og;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Onelouder;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.OpenX;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.SmartAdserver;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.SourcekitMRAID;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Startapp;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.TWMads;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Tapfortap;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.UnityAds;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Vpadn;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Vpon;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Vungle;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Waystorm;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.Yandex;
import tw.fatminmin.xposed.minminguard.blocker.adnetwork.mAdserve;
import tw.fatminmin.xposed.minminguard.blocker.custom_mod.NextMedia;
import tw.fatminmin.xposed.minminguard.blocker.custom_mod.OneWeather;
import tw.fatminmin.xposed.minminguard.blocker.custom_mod.Viafree;
import tw.fatminmin.xposed.minminguard.blocker.custom_mod._2chMate;

public class Main implements IXposedHookZygoteInit, IXposedHookLoadPackage
{
private static final String MY_PACKAGE_NAME = Main.class.getPackage().getName();
private static String MODULE_PATH = null;
public static Set<String> patterns;
public static Set<String> patterns = new HashSet<>();
public static Resources resources;

public static Blocker[] blockers = {
Expand Down Expand Up @@ -69,12 +133,11 @@ private static void appSpecific(String packageName, LoadPackageParam lpparam)
public void initZygote(StartupParam startupParam) throws Throwable
{
MODULE_PATH = startupParam.modulePath;

resources = XModuleResources.createInstance(MODULE_PATH, null);
byte[] array = XposedHelpers.assetAsByteArray(resources, "host/output_file");
//Workaround for EdXposed
//resources = XModuleResources.createInstance(MODULE_PATH, null);
/*byte[] array = XposedHelpers.assetAsByteArray(resources, "host/output_file");
String decoded = new String(array);
String[] sUrls = decoded.split("\n");
patterns = new HashSet<>();
Collections.addAll(patterns, sUrls);
Expand All @@ -84,7 +147,7 @@ public void initZygote(StartupParam startupParam) throws Throwable
Collections.addAll(patterns, sUrls);
notifyWorker = Executors.newSingleThreadExecutor();
notifyWorker = Executors.newSingleThreadExecutor();*/
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package tw.fatminmin.xposed.minminguard.blocker;

import android.util.DisplayMetrics;
import android.view.Display;
import android.view.View;
import android.view.ViewGroup;
import tw.fatminmin.xposed.minminguard.Main;
Expand Down Expand Up @@ -61,6 +62,9 @@ public void run()

private static float convertPixelsToDp(float px)
{
if(Main.resources == null)
return 0;

DisplayMetrics metrics = Main.resources.getDisplayMetrics();

return px / (metrics.densityDpi / 160f);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
import android.graphics.drawable.Drawable;
import android.net.Uri;
import android.os.AsyncTask;
import android.os.Build;
import android.os.Bundle;
import com.google.android.material.navigation.NavigationView;
import com.google.android.material.tabs.TabLayout;
Expand All @@ -23,6 +24,7 @@
import android.view.Menu;
import android.view.MenuItem;
import tw.fatminmin.xposed.minminguard.Common;
import tw.fatminmin.xposed.minminguard.Main;
import tw.fatminmin.xposed.minminguard.R;
import tw.fatminmin.xposed.minminguard.ui.adapter.ModeFragmentAdapter;
import tw.fatminmin.xposed.minminguard.ui.dialog.SettingsDialogFragment;
Expand Down Expand Up @@ -80,6 +82,9 @@ protected void onCreate(Bundle savedInstanceState)
{
super.onCreate(savedInstanceState);

//Workaround for EdXposed
Main.resources = getResources();

uiPref = getSharedPreferences(Common.UI_PREFS, MODE_PRIVATE);
modPref = getSharedPreferences(Common.MOD_PREFS, MODE_PRIVATE);

Expand Down

0 comments on commit 3a4587c

Please sign in to comment.