Removing Bahamut App Ads by Modifying APK

發表於
分類於 Research
This article is LLM-translated by GPT-4o, so the translation may be inaccurate or complete. If you find any mistake, please let me know.

There was already a post {% post_link block-android-bahamut-ads %} on how to block ads in the Bahamut app. However, since Android 7, Android has imposed restrictions on user-added certificates, leading to incomplete HTTPS filtering. Devices with root access can use the Move Certs! app to convert AdGuard’s certificate into a system certificate, allowing AdGuard to continue filtering properly. Therefore, for non-rooted devices, other methods are needed to remove ads, which is the purpose of this article.

Source: ArguardForAndroid issue #334

The GitHub releases of Move Certs! only have the 1.0.1 apk. The latest version 1.0.2 might need to be found elsewhere, and its package name is com.nutomic.zertman.

Update: Users with Magisk can search for a Move Certificates module to install, which functions the same as Move Certs!

Preparation

  1. Install Java
  2. Install apktool (installation guide included)
  3. Obtain the original Bahamut apk (apkpure)

This article uses version

java=1.8.0_162
apktool=2.3.1
巴哈姆特apk=5.7.0

Modification

In the directory with bahamut.apk, enter the command apktool d bahamut.apk. Then open ./bahamut/smali/tw/com/gamer/android/ad/MobileAdView.smali. Find the line

.field private static final API:Ljava/lang/String; = "https://api.gamer.com.tw/mobile_app/ad/v2/mobile_ad.php"

You can open https://api.gamer.com.tw/mobile_app/ad/v2/mobile_ad.php in a browser and see that it is a JSON format ad list. The modification method is to use an online service (gist, pastebin, etc.) to return an empty ad list:

{"banner":{},"native_major":{"Android__":[],"iOS__":[]},"native_minor":{"Android__":[],"iOS__":[]}}

I have already created a gist with the above content. If you don’t want to create one yourself, you can directly copy: url. Then change the line above to:

.field private static final API:Ljava/lang/String; = "空廣告列表的網址"

Next, the second modification is also in MobileAdView.smali, around line 600, find

.method public static requestAd(/*這邊省略...*/)V
/*其他程式碼*/
/*在這邊應該能找到下方那一行,這個網址也要改*/

const-string v3, "https://api.gamer.com.tw/mobile_app/ad/v2/mobile_ad.php"

.end method

The modification here is also to change the API URL to the empty ad list URL.

Then return to the directory with bahamut.apk and execute the command apktool b bahamut -o bahamut_noads.apk. This will generate a Bahamut apk without ads: bahamut_noads.apk. However, this apk is not signed yet, so it cannot be installed directly (if you have core patching, you can skip the signing part).

Signing

If you already know how to sign an apk, you can skip this part. To simplify the signing process, we will use a third-party tool uber-apk-signer. Go to the Releases page and choose the latest version. Find uber-apk-signer-x.y.z.jar below and download it (x.y.z is the version number).

Then place the downloaded uber-apk-signer-x.y.z.jar in the same directory as bahamut_noads.apk and rename it to sign.jar. Execute the command java -jar sign.jar --apks ./bahamut_noads.apk. Finally, you will get bahamut_noads-aligned-debugSigned.apk, which can be transferred to your phone for installation. Make sure to remove the original Bahamut app before installing.

About Ad Removal

If possible, I hope Bahamut can offer a paid ad removal option like Anime1. However, as of now (2018/2/5 17:57), there is no such option. Of course, if you want to support Bahamut’s operations by watching ads, you can continue using the official app. If you, like me, find ads uncomfortable, please follow the method in this article to remove ads yourself. I do not intend to provide downloads for the modified apk.

Update Log

  • 2018/4/11 Update: Bahamut version 5.7.5 has significant changes. The latest version that can be modified is 5.7.3.
  • 2018/8/20 Update: Updated the Move Certs! link as it has disappeared from Google Play.