Shou dumpling dance · 2015/07/22 16:52

Smalidea is a plugin for IntelliJ IDEA/Android Studio

Existing function


  • Syntax highlighting/error
  • Bytecode level debugging
    • The breakpoint
    • Step through
    • Register view
    • Java syntax is supported in local Windows, as well as debug mode
  • Supports jumps for easy tracking of variables/functions/classes (Xref also supports this).
  • Find the usage
  • rename
  • Reference the Smali class from Java code
  • False feedback…

The installation


  • Download the plugin Smalidea
  • Go to IntelliJ IDEA/Android Studio to install the plugin, go to Settings->Plugins clickInstall plugin from diskSelect the downloaded package.
  • Click on theapply

Enabling Application Debugging


To debug the dex code in an APK, either of the following two conditions must be met:

  • The Application tag in the Androidmanifest.xml file in APK contains the attribute Android :debuggable= “true”.
  • The value of the ro.debuggable in /default.prop is 1

Options:

  • Insert android:debuggable= “true” in androidmanifest.xml
  • hook system debug (Xinstaller)
  • Modify the boot img

Personally feel to change boot.img and two packaging more trouble, so here the hook way to open all application debugging purposes, Xposed plug-in code is as follows

#!java
public class Debug implements IXposedHookLoadPackage {

    public boolean debugApps = true ;
    public static final int DEBUG_ENABLE_DEBUGGER = 0x1;
    public String tag = "IDG";

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

        if(lpparam.appInfo == null ||
                (lpparam.appInfo.flags & (ApplicationInfo.FLAG_SYSTEM | ApplicationInfo.FLAG_UPDATED_SYSTEM_APP)) !=0){
            return;
        }

        tag = tag + lpparam.packageName;

        XposedBridge.hookAllMethods(Process.class, "start", new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam param) throws Throwable {

                int id = 5;
                int flags = (Integer) param.args[id];

                Log.d(tag,"flags is : "+flags);

                if (debugApps) {
                    if ((flags & DEBUG_ENABLE_DEBUGGER) == 0) {
                        flags |= DEBUG_ENABLE_DEBUGGER;
                    }
                }

                param.args[id] = flags;
                Log.d(tag,"flags changed : "+flags);

            }
        });
    }

}
Copy the code

The effect is shown below.

If you encounter the following error

Adb rejected connection to client
Copy the code

This can be resolved by restarting adb Server

adb kill-server

adb start-server
Copy the code

If you encounter any of the following errors during debugging, be sure to disable the other IDE or DDMS to remove the port

To debug the application


Note: Single-step debugging is supported only in IDEA 14.1 and later versions

  • Decompile the application using Baksmali

    baksmali myapp.apk -o ~/projects/myapp/src
    Copy the code
  • Go to IDEA, import the new project, and select the previous directory

    ~/projects/myapp
    Copy the code

  • Select Create Project from Existing Sources when importing

  • After successfully importing the project, right-click the SRC Directory and set Mark Directory As->Sources Root

  • Open the JDK for Module Setting

  • Installing the Debug application

    adb install com.zkj.guimi.apk
    Copy the code
  • Locate the Debug application process and start the application

    If you do not use DDMS, you can use the following steps:

    » adb shell am start - D - W - n com. ZKJ, guimi /. UI. The SplashScreen » adb shell ps | grep guimi 1 ↵ u0_a157, 9879, 242, 883420 36360 FFFFFFFF 00000000 S com.zKJ.guimi » ADB Forward TCP :8700 JDWP :9879Copy the code
  • Configure remote debugging in IDEA (Run->Edit Configurations) to change the debug port to 8700

  • Run->Debug

    Connected to the target VM, address: ‘localhost:8700’, transport: ‘socket’

  • Once a breakpoint is triggered, step debugging is possible

reference


www.kanxue.com/bbs/showthr…

Github.com/JesusFreke/…

Github.com/pylerSM/XIn…