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

Commit

Permalink
-Cleaned up code.
Browse files Browse the repository at this point in the history
-Added support for MRAID
  • Loading branch information
MSkjel committed May 26, 2019
1 parent 0ca77a1 commit 9b16e47
Show file tree
Hide file tree
Showing 79 changed files with 315 additions and 333 deletions.
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ android {
applicationId "tw.fatminmin.xposed.minminguard"
minSdkVersion 14
targetSdkVersion 28
versionCode 63
versionCode 64
versionName "2.0.5"
}
buildTypes {
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -33,11 +33,13 @@
<provider
android:name=".MinMinProvider"
android:authorities="tw.fatminmin.xposed.minminguard"
android:enabled="true"
android:exported="true"/>

<provider
android:name=".ModSettingsProvider"
android:authorities="tw.fatminmin.xposed.minminguard.modesettings"
android:enabled="true"
android:exported="true"/>

<meta-data
Expand Down
27 changes: 10 additions & 17 deletions app/src/main/java/tw/fatminmin/xposed/minminguard/Main.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,27 +14,26 @@
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 static de.robv.android.xposed.XposedHelpers.findAndHookMethod;

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

public static Blocker[] blockers = {
/* Popular adnetwork */
new Ad2iction(), new Adbert(), new Adcolony(), new Adfurikun(), new AdMarvel(), new GoogleAdmob(), new GoogleGms(), new Adtech(), new Amazon(), new Amobee(),
new Ad2iction(), new Adbert(), new Adcolony(), new Adfurikun(), new AdMarvel(), new AppodealMRAID(), new GoogleAdmob(), new GoogleGms(), new Adtech(), new Amazon(), new Amobee(),
new Aotter(), new AppBrain(), new Applovin(), new Appnext(), new Avocarrot(), new Bonzai(), new Chartboost(), new Clickforce(), new Domob(), new Facebook(),
new Freewheel(), new Flurry(), new GoogleGmsDoubleClick(), new Hodo(), new Inmobi(), new Intowow(), new Ironsource(), new KuAd(), new mAdserve(), new Madvertise(),
new MasAd(), new MdotM(), new Millennial(), new Mobclix(), new MobFox(), new MoPub(), new Nend(), new Og(), new Onelouder(), new OpenX(), new SmartAdserver(),
new Startapp(), new Tapfortap(), new TWMads(), new UnityAds(), new Vpadn(), new Vpon(), new Vungle(), new Waystorm(), new Yandex(),new Mraid(),new Mraid2(),
new MasAd(), new MdotM(), new Millennial(), new Mobclix(), new MobFox(), new MoPub(), new Nend(), new Og(), new Onelouder(), new OpenX(), new SmartAdserver(), new SourcekitMRAID(),
new Startapp(), new Tapfortap(), new TWMads(), new UnityAds(), new Vpadn(), new Vpon(), new Vungle(), new Waystorm(), new Yandex(),
/* Custom Mod*/
};

Expand Down Expand Up @@ -77,25 +76,19 @@ public void initZygote(StartupParam startupParam) throws Throwable
String[] sUrls = decoded.split("\n");
patterns = new HashSet<>();

for (String url : sUrls)
{
patterns.add(url);
}
Collections.addAll(patterns, sUrls);

array = XposedHelpers.assetAsByteArray(resources, "host/mmg_pattern");
decoded = new String(array);
sUrls = decoded.split("\n");

for (String url : sUrls)
{
patterns.add(url);
}
Collections.addAll(patterns, sUrls);

notifyWorker = Executors.newSingleThreadExecutor();
}

@Override
public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable
public void handleLoadPackage(final LoadPackageParam lpparam)
{

if (lpparam.packageName.equals(MY_PACKAGE_NAME))
Expand All @@ -108,7 +101,7 @@ public void handleLoadPackage(final LoadPackageParam lpparam) throws Throwable
XposedHelpers.findAndHookMethod("android.app.Application", lpparam.classLoader, "onCreate", new XC_MethodHook()
{
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable
protected void afterHookedMethod(MethodHookParam param)
{
final String packageName = lpparam.packageName;
Context context = Util.getCurrentApplication();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ public static boolean removeBannerWithResult(final String packageName, final Str
Util.hookAllMethods(bannerClass, lpparam.classLoader, bannerFunc, new XC_MethodHook()
{
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{
String debugMsg = String.format("removeBannerWithResult: Detect %s %s in %s", bannerClass, bannerFunc, packageName);

Expand Down Expand Up @@ -87,7 +87,7 @@ public static boolean blockAdFunction(final String packageName, final String adC
{

@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{
String debugMsg = String.format("blockAdFunction: Detect %s %s in %s", adClass, adFunc, packageName);

Expand Down Expand Up @@ -118,7 +118,7 @@ public static boolean blockAdFunctionExact(final String packageName, final Strin
XposedHelpers.findAndHookMethod(adClass, lpparam.classLoader, adFunc, parameter, new XC_MethodHook()
{
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{
String debugMsg = String.format("Detect %s %s(%s) in %s", adClass, adFunc, parameter.toString(), packageName);

Expand Down Expand Up @@ -150,7 +150,7 @@ public static boolean blockAdFunctionExact(final String packageName, final Strin
XposedHelpers.findAndHookMethod(adClass, lpparam.classLoader, adFunc, parameter1, parameter2, new XC_MethodHook()
{
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{
String debugMsg = String.format("Detect %s %s(%s, %s) in %s", adClass, adFunc, parameter1.toString(), parameter2.toString(), packageName);

Expand Down Expand Up @@ -182,7 +182,7 @@ public static boolean blockAdFunctionExact(final String packageName, final Strin
XposedHelpers.findAndHookMethod(adClass, lpparam.classLoader, adFunc, parameter1, parameter2, parameter3, new XC_MethodHook()
{
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{
String debugMsg = String.format("Detect %s %s(%s, %s, %s) in %s", adClass, adFunc, parameter1.toString(), parameter2.toString(), parameter3.toString(), packageName);

Expand Down Expand Up @@ -215,7 +215,7 @@ public static boolean blockAdFunctionWithResult(final String packageName, final
{

@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{
String debugMsg = String.format("blockAdFunctionWithResult: Detect %s %s in %s", adClass, adFunc, packageName);

Expand Down Expand Up @@ -249,7 +249,7 @@ public static boolean blockAdFunctionWithResultExact(final String packageName, f
{

@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{
String debugMsg = String.format("Detect %s %s(%s) in %s", adClass, adFunc, parameter.toString(), packageName);

Expand Down Expand Up @@ -283,7 +283,7 @@ public static boolean blockAdFunctionWithResultExact(final String packageName, f
{

@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{
String debugMsg = String.format("Detect %s %s(%s, %s) in %s", adClass, adFunc, parameter1.toString(), parameter2.toString(), packageName);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public static void block(XC_LoadPackage.LoadPackageParam lpparam)
XposedBridge.hookAllConstructors(socketClz, new XC_MethodHook()
{
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{
Object obj = param.args[0];
String host = "";
Expand All @@ -50,7 +50,7 @@ else if (obj.getClass().getName().equals("java.net.InetAddress"))
XC_MethodHook inetAddrHookSingleResult = new XC_MethodHook()
{
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{
String host = (String) param.args[0];

Expand All @@ -63,7 +63,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable
}

@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable
protected void afterHookedMethod(MethodHookParam param)
{
String host = (String) param.args[0];

Expand All @@ -84,7 +84,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable
XposedBridge.hookAllConstructors(inetSockAddrClz, new XC_MethodHook()
{
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{
String host = (String) param.args[0];
if (Main.patterns.contains(host))
Expand All @@ -103,7 +103,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable
XC_MethodHook ioBridgeHook = new XC_MethodHook()
{
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{
InetAddress addr = (InetAddress) param.args[1];
String host = addr.getHostName();
Expand All @@ -119,7 +119,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable
}

@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable
protected void afterHookedMethod(MethodHookParam param)
{
InetAddress addr = (InetAddress) param.args[1];
String host = addr.getHostName();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,6 @@
import android.view.View;
import android.view.ViewGroup;
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import tw.fatminmin.xposed.minminguard.Main;

Expand All @@ -24,12 +22,7 @@ private static boolean matchBannerName(String clazzName, String banner, String b
return true;
}

if (bannerPrefix != null && clazzName.startsWith(bannerPrefix))
{
return true;
}

return false;
return bannerPrefix != null && clazzName.startsWith(bannerPrefix);
}

// return adnetwork name
Expand Down Expand Up @@ -79,7 +72,7 @@ private static Boolean isAdView(Context context, String pkgName, View view)
return false;
}

public static void clearAdViewInLayout(final String packageName, final View view)
private static void clearAdViewInLayout(final String packageName, final View view)
{

if (isAdView(view.getContext(), packageName, view))
Expand All @@ -105,7 +98,7 @@ public static void nameBasedBlocking(final String pkgName, final XC_LoadPackage.
{

@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{
View view = (View) param.args[0];

Expand All @@ -117,7 +110,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable
}

@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable
protected void afterHookedMethod(MethodHookParam param)
{
View view = (View) param.args[0];

Expand All @@ -132,7 +125,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable
Util.hookAllMethods("android.app.Activity", lpparam.classLoader, "setContentView", new XC_MethodHook()
{
@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable
protected void afterHookedMethod(MethodHookParam param)
{
Activity ac = (Activity) (param.thisObject);
ViewGroup root = ac.getWindow().getDecorView().findViewById(android.R.id.content);
Expand All @@ -157,7 +150,7 @@ protected void afterHookedMethod(MethodHookParam param) throws Throwable
*/

@Override
protected void afterHookedMethod(MethodHookParam param) throws Throwable
protected void afterHookedMethod(MethodHookParam param)
{
View root = (View) param.getResult();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ static public boolean removeWebViewAds(final String packageName, LoadPackagePara
XposedBridge.hookAllMethods(adView, "loadUrl", new XC_MethodHook()
{
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{

String url = (String) param.args[0];
Expand All @@ -44,7 +44,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable
{

@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{

String data = (String) param.args[0];
Expand All @@ -59,7 +59,7 @@ protected void beforeHookedMethod(MethodHookParam param) throws Throwable
XposedBridge.hookAllMethods(adView, "loadDataWithBaseURL", new XC_MethodHook()
{
@Override
protected void beforeHookedMethod(MethodHookParam param) throws Throwable
protected void beforeHookedMethod(MethodHookParam param)
{
String url = (String) param.args[0];
String data = (String) param.args[1];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import de.robv.android.xposed.XC_MethodHook;
import de.robv.android.xposed.XposedBridge;
import de.robv.android.xposed.XposedHelpers;
import de.robv.android.xposed.callbacks.XC_LoadPackage;
import tw.fatminmin.xposed.minminguard.BuildConfig;
import tw.fatminmin.xposed.minminguard.Common;
import tw.fatminmin.xposed.minminguard.Main;
Expand All @@ -24,7 +23,7 @@ public final class Util
public static boolean DEBUG = BuildConfig.DEBUG;

public static final String TAG = "MinMinGuard";
public static final String PACKAGE = "tw.fatminmin.xposed.minminguard";
private static final String PACKAGE = "tw.fatminmin.xposed.minminguard";

private Util() throws InstantiationException
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ public static void removeAdView(String packageName, View view)
removeAdView(packageName, view, true, 51);
}

public static void removeAdView(final String packageName, final View view, final boolean first, final float heightLimit)
private static void removeAdView(final String packageName, final View view, final boolean first, final float heightLimit)
{
float adHeight = convertPixelsToDp(view.getHeight());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@

public class Ad2iction extends Blocker
{
public static final String BANNER = "com.ad2iction.mobileads.Ad2ictionView";
public static final String BANNER_PREFIX = "com.ad2iction.mobileads";
private static final String BANNER = "com.ad2iction.mobileads.Ad2ictionView";
private static final String BANNER_PREFIX = "com.ad2iction.mobileads";

public static final String INTER_ADS = "com.ad2iction.mobileads.Ad2ictionInterstitial";
private static final String INTER_ADS = "com.ad2iction.mobileads.Ad2ictionInterstitial";

public boolean handleLoadPackage(final String packageName, XC_LoadPackage.LoadPackageParam lpparam)
{
boolean result = false;

result |= ApiBlocking.removeBanner(packageName, BANNER, "loadAd", lpparam);
result = ApiBlocking.removeBanner(packageName, BANNER, "loadAd", lpparam);
result |= ApiBlocking.blockAdFunction(packageName, INTER_ADS, "load", lpparam);

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,16 @@
public class AdMarvel extends Blocker
{

public static final String BANNER = "com.admarvel.android.ads.AdMarvelView";
public static final String BANNER_PREFIX = "com.admarvel.android.ads";
private static final String BANNER = "com.admarvel.android.ads.AdMarvelView";
private static final String BANNER_PREFIX = "com.admarvel.android.ads";

public static final String INTER_ADS = "com.admarvel.android.ads.AdMarvelInterstitialAds";
private static final String INTER_ADS = "com.admarvel.android.ads.AdMarvelInterstitialAds";

public boolean handleLoadPackage(final String packageName, LoadPackageParam lpparam)
{
boolean result = false;

result |= ApiBlocking.removeBanner(packageName, BANNER, "requestNewAd", lpparam);
result = ApiBlocking.removeBanner(packageName, BANNER, "requestNewAd", lpparam);
result |= ApiBlocking.blockAdFunction(packageName, INTER_ADS, "requestNewInterstitialAd", lpparam);

return result;
Expand Down
Loading

0 comments on commit 9b16e47

Please sign in to comment.