Have the app wait for debugger on launch of "Application"

11 views
Skip to first unread message

Cryptax

unread,
Feb 24, 2022, 3:17:25 AMFeb 24
to JEB Decompiler
We can have the app wait for debugger in an activity with : `adb shell am start -D -S -n <packageName>/<activityName>`. However, sometimes we want to debug BEFORE an activity is launched. This is the case especially for packers.
I'd like to debug the class which extends Application, and which is called before anything else.
How can we launch the app and have it stop there?


For example, this is what I have in the manifest:

 <application android:allowBackup="true" android:debuggable="true" android:hardwareAccelerated="false" android:icon="@mipmap/ic_launcher" android:installLocation="0" android:label="@string/app_name" android:largeHeap="true" android:name="com.android.protector.ProtectApplication" android:supportsRtl="false" android:theme=...

I'd like to debug ProtectApplication class.

Thanks

Axelle.

Nicolas Falliere

unread,
Feb 24, 2022, 11:23:18 PMFeb 24
to Cryptax, JEB Decompiler
Hello Axelle,

The proper way would be to start your app with the option to wait for a debugger to attach before running.

- With am, you can use the options -D (to enable debugging) and -W (to wait for a debugger). Start the main activity as usual (with -n).
- Then attach your app with JEB, make sure to keep the threads suspended.
- Place the breakpoint on the custom Application static initializer code or a constructor code.
- Run the threads.

Best regards,
--
Nicolas Falliere (ni...@pnfsoftware.com)
JEB Decompiler, Founder and Architect


--
You received this message because you are subscribed to the Google Groups "JEB Decompiler" group.
To unsubscribe from this group and stop receiving emails from it, send an email to jeb-decompile...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/jeb-decompiler/f9e987a2-fa2e-45d2-b443-db3865c6f9d2n%40googlegroups.com.

Axelle Apvrille

unread,
Feb 25, 2022, 8:54:40 AMFeb 25
to JEB Decompiler
Oh thanks! Indeed that works! The documentation for "am start" is misleading on Android, because it gives the impression you *must* start an activity. But no. You can do `am start -D -W packagename` and that works fine. And then, I can set breakpoints in the class I want and reach that.

A bit strange though : why doesn't JEB see the values of each local type? See the attached screenshot.
v0 is of type StringBuilder, and should have something in it, but JEB returns "void" for it.
Same for v2, which should be a File. 
Is that a bug? or am I not using it correctly?

Thanks,

-- Axelle

jeb-debug-session.png

Nicolas Falliere

unread,
Feb 25, 2022, 12:45:11 PMFeb 25
to Axelle Apvrille, JEB Decompiler
On Android P and Q, the values of variables without a valid DebugInfo descriptor are not provided by the debugging server. This blog explains things in more detail: https://www.pnfsoftware.com/blog/debugging-android-apps-on-android-pie-and-above/
The problem was fixed for Android R and above. For instance, on current Android (Android 12 / API level 31), you should be able to see the values of all variables, including those that were not declared in DebugInfo.
To see what DebugInfo you have in your APK, right-click in your Assembly view, Rendering Options, enable Show Debug Directives. The debug variables are declared with ".local vX ..."

Thanks,
--
Nicolas Falliere (ni...@pnfsoftware.com)
JEB Decompiler, Founder and Architect

Nicolas Falliere

unread,
Feb 25, 2022, 2:10:44 PMFeb 25
to Axelle Apvrille, JEB Decompiler

Axelle Apvrille

unread,
Mar 1, 2022, 3:52:21 AMMar 1
to JEB Decompiler
ok thanks!
Reply all
Reply to author
Forward
0 new messages