去除某些APP广告弹窗
学习笔记二:对APP内的弹窗广告以及APP初始化的广告进行去除
一、对需要去除广告的APK进行安装,查看其原始状态
以下为该APP初始化以及加密方式切换后会弹出的广告
二、利用Android kill 对该APK进行反编译
1、通过反编译我们发现其Activity中存在youmi(一个移动广告平台)的工程,因此我们查看其AndroidManifest.xml文件,发现存在多个与youmi有关的信息,我们将其删除后进行重新编译发现广告并未删除。
<?xml version="1.0" encoding="utf-8" standalone="no"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android" package="lbchs.mtedit">
<uses-permission android:name="android.permission.INTERNET"/>
<uses-permission android:name="android.permission.READ_PHONE_STATE"/>
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
<uses-permission android:name="android.permission.ACCESS_WIFI_STATE"/>
<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE"/>
<uses-permission android:name="android.permission.GET_TASKS"/>
<uses-permission android:name="com.android.launcher.permission.INSTALL_SHORTCUT"/>
<uses-permission android:name="android.permission.CHANGE_CONFIGURATION"/>
<application android:allowBackup="true" android:icon="@drawable/ic_launcher" android:label="@string/app_name" android:theme="@android:style/Theme.Holo.Light">
<activity android:configChanges="keyboardHidden|orientation" android:label="@string/app_name" android:name=".WelcomeActivity">
<intent-filter>
<action android:name="android.intent.action.MAIN"/>
<category android:name="android.intent.category.LAUNCHER"/>
</intent-filter>
</activity>
<activity android:name=".MainActivity"/>
<activity android:name=".TwoActivity"/>
<service android:name="net.youmi.android.AdService"/>
<activity android:name="net.youmi.android.AdBrowser" android:theme="@android:style/Theme.NoTitleBar"/>
<receiver android:name="net.youmi.android.AdReceiver">
<intent-filter>
<action android:name="android.intent.action.PACKAGE_ADDED"/>
<action android:name="android.intent.action.PACKAGE_INSTALL"/>
<data android:scheme="package"/>
</intent-filter>
</receiver>
<meta-data android:name="YOUMI_CHANNEL" android:value="0"/>
</application>
</manifest>
2、继续对反编译后的APK进行分析。我们首先查看其工程信息中的 .MainActivity,通过JD-jui来查看 .MainActivity所对应的Java源码,发现其中存在“youmi、广告、展示”等关键词,他们对应的方法为 showBanner与cc两个私有方法。通过追踪其上级调用方法,发现最终在onCreate方法中找到它们的最初调用—-setSpotAd()与showBanner()。
...省略...
private void cc()
{
SpotManager.getInstance(this.context).showSpotAds(this.context, new SpotDialogListener()
{
@Override
public void onShowFailed()
{
Log.i("YoumiAdDemo", "展示失败");
}
@Override
public void onShowSuccess()
{
Log.i("YoumiAdDemo", "展示成功");
}
@Override
public void onSpotClick()
{
Log.i("YoumiAdDemo", "插屏点击");
}
@Override
public void onSpotClosed()
{
Log.i("YoumiAdDemo", "展示关闭");
}
});
private void setSpotAd()
{
SpotManager.getInstance(this.context).loadSpotAds();
SpotManager.getInstance(this.context).setAnimationType(SpotManager.ANIM_ADVANCE);
SpotManager.getInstance(this.context).setSpotOrientation(0);
cc();
}
private void showBanner()
{
FrameLayout.LayoutParams localLayoutParams = new FrameLayout.LayoutParams(-2, -2);
localLayoutParams.gravity = 85;
AdView localAdView = new AdView(this.context, AdSize.FIT_SCREEN);
localAdView.setAdListener(new AdViewListener()
{
@Override
public void onFailedToReceivedAd(AdView paramAnonymousAdView)
{
Log.i("YoumiAdDemo", "请求广告失败");
}
@Override
public void onReceivedAd(AdView paramAnonymousAdView)
{
Log.i("YoumiAdDemo", "请求广告成功");
}
@Override
public void onSwitchedAd(AdView paramAnonymousAdView)
{
Log.i("YoumiAdDemo", "广告条切换");
}
});
((Activity)this.context).addContentView(localAdView, localLayoutParams);
}
@Override
public void onCreate(Bundle paramBundle)
{
ADRTLogCatReader.onContext(this, "com.aide.ui");
super.onCreate(paramBundle);
super.setContentView(2130903040);
this.context = this;
setSpotAd();
showBanner();
this.yuanw = ((EditText)findViewById(2131230721));
...省略...
3、将上述两个方法的调用进行注释。保存后进行编译安装运行,发现其初始化时的广告并未去除。其次对 WelcomeActivity.class进行分析,通过jd-jui发现其中也存在广告的关键词(位于oncreate方法的try catch)中。
4、在WelcomeActivity.smali中尝试注释try catch来消除广告,发现缺少返回值,APP无法运行,尝试在try catch中添加return-viod,结果无广告但不进入程序主体中。
:try_start_0
const-string v10, "lbchs.mtedit.MainActivity"
invoke-static {v10}, Ljava/lang/Class;->forName(Ljava/lang/String;)Ljava/lang/Class;
:try_end_0
.catch Ljava/lang/ClassNotFoundException; {:try_start_0 .. :try_end_0} :catch_0
5、在WelcomeActivity.class中进入try catch的主体中查看其具体方法调用,发现有用方法两个( this.splashLayout.setVisibility和this.splashLayout.addView)前者为设置显示具体时间,后者为插入的广告图片。
try
{
Class localClass = Class.forName("lbchs.mtedit.MainActivity")
paramBundle = new Intent(paramBundle, localClass)
this.splashView.setIntent(paramBundle)
this.splashView.setIsJumpTargetWhenFail(true)
this.splash = this.splashView.getSplashView()
setContentView(2130903043)
this.splashLayout = ((RelativeLayout)findViewById(2131230738))
this.splashLayout.setVisibility(8)
paramBundle = new RelativeLayout.LayoutParams(-1, -1)
paramBundle.addRule(2, 2131230739)
this.splashLayout.addView(this.splash, paramBundle)
SpotManager.getInstance(this.context).showSplashSpotAds(this.context, this.splashView, new SpotDialogListener()
{
@Override
public void onShowFailed()
---省略---
}
}
将上述两个方法对应的invoke进行注释,保存、编译运行后发现广告顺利消除。
三、总结:至此对该APP的广告去除结束,在对一个APK进行分析的过程中会出现许多莫名的错误,需要我们不断的回头去查漏补缺。对修改的结果要不断的进行尝试才会得到正确的效果。