jadxでAPKをデコンパイルし中身を確認する


前提

macOS Big Sur 11.3
Homebrew 3.1.9

仕事でやる機会があったので記事にしておきます。

jadxについてはリポジトリのREADMEを参照ください。
GitHub - skylot/jadx: Dex to Java decompiler

目標

APKをデコンパイルし中身を確認する。
こちらの記事↓のAPKをデコンパイルしてみます。
https://kwn1125.hatenablog.com/entry/2021/05/17/210000_1kwn1125.hatenablog.com

jadxのインストールと起動

インストール手順は下記コマンドの実行のみです。

brew install jadx


バージョンだけ確認。

jadx --version
1.2.0


インストール後、下記コマンドを実行するとjadxが起動します。

jadx-gui


中身を確認

起動後、デコンパイルしたいAPKを選択すると次のような画面になりました。



元のコードとデコンパイル後のコードを見てみます。
下記が元のコードです。

package com.example.testapplication;

import android.content.Intent
import android.os.Bundle
import android.util.Log
import androidx.core.app.NotificationCompat
import androidx.core.app.NotificationManagerCompat
import com.google.firebase.messaging.FirebaseMessagingService

class MyFirebaseMessagingService : FirebaseMessagingService() {
    companion object {
        private const val TAG = "MyFirebaseMessagingService"
    }

    override fun handleIntent(intent: Intent) {
        Log.d(TAG, "handleIntent")

        intent.extras?.also {
            showNotification(it)
        } ?: Log.w(TAG, "intent.extras is null")
    }

    private fun showNotification(extras: Bundle) {
        val notification = NotificationCompat.Builder(this, "channel_1")
            .setSmallIcon(R.drawable.ic_notification)
            .setContentTitle(extras.getString("gcm.notification.title"))
            .setContentText(extras.getString("gcm.notification.body"))
            .build()
        val notificationManager = NotificationManagerCompat.from(this)
        notificationManager.notify(0, notification)
    }

    override fun onNewToken(token: String) {
        Log.d(TAG, "Refreshed token: $token")
    }
}


下記がデコンパイル後のコードです。READMEに書いてあった通り、元のコードはKotlinですがデコンパイル後はJavaです。

package com.example.testapplication;

import android.app.Notification;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import androidx.core.app.NotificationCompat;
import androidx.core.app.NotificationManagerCompat;
import com.google.firebase.messaging.FirebaseMessagingService;
import kotlin.Metadata;
import kotlin.jvm.internal.DefaultConstructorMarker;
import kotlin.jvm.internal.Intrinsics;

@Metadata(bv = {1, 0, 3}, d1 = {"\u0000*\n\u0002\u0018\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u0002\n\u0000\n\u0002\u0018\u0002\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0002\b\u0002\n\u0002\u0018\u0002\n\u0002\b\u0002\u0018\u0000 \r2\u00020\u0001:\u0001\rB\u0005¢\u0006\u0002\u0010\u0002J\u0010\u0010\u0003\u001a\u00020\u00042\u0006\u0010\u0005\u001a\u00020\u0006H\u0016J\u0010\u0010\u0007\u001a\u00020\u00042\u0006\u0010\b\u001a\u00020\tH\u0016J\u0010\u0010\n\u001a\u00020\u00042\u0006\u0010\u000b\u001a\u00020\fH\u0002¨\u0006\u000e"}, d2 = {"Lcom/example/testapplication/MyFirebaseMessagingService;", "Lcom/google/firebase/messaging/FirebaseMessagingService;", "()V", "handleIntent", "", "intent", "Landroid/content/Intent;", "onNewToken", "token", "", "showNotification", "extras", "Landroid/os/Bundle;", "Companion", "app_debug"}, k = 1, mv = {1, 1, 16})
/* compiled from: MyFirebaseMessagingService.kt */
public final class MyFirebaseMessagingService extends FirebaseMessagingService {
    public static final Companion Companion = new Companion(null);
    private static final String TAG = "MyFirebaseMessagingService";

    @Metadata(bv = {1, 0, 3}, d1 = {"\u0000\u0012\n\u0002\u0018\u0002\n\u0002\u0010\u0000\n\u0002\b\u0002\n\u0002\u0010\u000e\n\u0000\b\u0003\u0018\u00002\u00020\u0001B\u0007\b\u0002¢\u0006\u0002\u0010\u0002R\u000e\u0010\u0003\u001a\u00020\u0004XT¢\u0006\u0002\n\u0000¨\u0006\u0005"}, d2 = {"Lcom/example/testapplication/MyFirebaseMessagingService$Companion;", "", "()V", "TAG", "", "app_debug"}, k = 1, mv = {1, 1, 16})
    /* compiled from: MyFirebaseMessagingService.kt */
    public static final class Companion {
        private Companion() {
        }

        public /* synthetic */ Companion(DefaultConstructorMarker $constructor_marker) {
            this();
        }
    }

    @Override // com.google.firebase.messaging.EnhancedIntentService, com.google.firebase.messaging.FirebaseMessagingService
    public void handleIntent(Intent intent) {
        Intrinsics.checkParameterIsNotNull(intent, "intent");
        Log.d(TAG, "handleIntent");
        Bundle it = intent.getExtras();
        if (it != null) {
            Intrinsics.checkExpressionValueIsNotNull(it, "it");
            showNotification(it);
            if (it != null) {
                return;
            }
        }
        Integer.valueOf(Log.w(TAG, "intent.extras is null"));
    }

    private final void showNotification(Bundle extras) {
        Notification notification = new NotificationCompat.Builder(this, "channel_1").setSmallIcon(R.drawable.ic_notification).setContentTitle(extras.getString("gcm.notification.title")).setContentText(extras.getString("gcm.notification.body")).build();
        NotificationManagerCompat notificationManager = NotificationManagerCompat.from(this);
        Intrinsics.checkExpressionValueIsNotNull(notificationManager, "NotificationManagerCompat.from(this)");
        notificationManager.notify(0, notification);
    }

    @Override // com.google.firebase.messaging.FirebaseMessagingService
    public void onNewToken(String token) {
        Intrinsics.checkParameterIsNotNull(token, "token");
        Log.d(TAG, "Refreshed token: " + token);
    }
}