16

What are some ways to debug third party android apps (apps you don't have the source code to)? I would like to step through the APK instruction by instruction, and possibly set breakpoints on certain APIs or certain smali instructions.

I've tried decompiling with apktool, loading into netbeans, and the connecting to the emulator, and I've also tried using IDA Pro, but I always get errors along the lines of "JDWP error: Connection reset by peer". I've tried with both the default Android emulator and Genymotion with Android 5.0.1.

Has anyone had any success with this? Could you describe your setup and tools that you used?

gsgx
  • 400
  • 1
  • 4
  • 11

1 Answers1

16

To debug an APK without the source code, you need to perform the following:

  1. Enable debug mode in the APK (use apktool to achieve this)
  2. Sign the APK (use keytool and jarsigner)
  3. Install the app and identify the debug port of the app using Android Debug Monitor or DDMS
  4. Use an IDE with support for JDWP like NetBeans pointing to the project with the decompiled java or smali.

You can find the commands yo use in this blog (section 5 Dynamic analysis and debugging) First steps performing penetration testing on an Android application

3asm_
  • 506
  • 6
  • 15
  • I tried this, but I'm not able to set breakpoints. I made sure to both decompile and build in debug mode. Here's the error: Not able to submit breakpoint LineBreakpoint ChessFreeActivity$1.java : 28, reason: No executable location available at line 28 in class uk.co.aifactory.chessfree.ChessFreeActivity$1. – gsgx Sep 24 '15 at 06:51
  • It means the code in your project and the IDE is not in sync. Decompiled code will probably not allow this. Use the smali and try Intellij if it works. – 3asm_ Sep 24 '15 at 23:13
  • What do you mean by use the smali? I thought we had to use the "fake" Java code produced by apktool -d, otherwise the IDE wouldn't recognize it. Can you add smali as source files in Intellij? – gsgx Sep 24 '15 at 23:38
  • 2
    @gsingh2011 check this: https://github.com/JesusFreke/smali/wiki/smalidea – Behrouz.M Feb 27 '17 at 10:10
  • @pixar great tool, too bad it is not maintained anymore. – 3asm_ Jan 06 '18 at 13:27