Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Detect Android App Is Running In Debug Mode

Without recompiling the app, user are able to make the app debuggable using xposed to debug/heapdump the app

Is there any method (root or non root) to detect the app is currently:

  • Running in debug mode

or

  • The app is started using debuggable flag in zygote

or

  • App is being heap dumped

Using BuildConfig.DEBUG and ApplicationInfo, and check the flags field for FLAG_DEBUGGABLE doesn't works since the app started by zygote with debug flag directly

Below is the code that hook the process class

    try {
        Method start = Process.class.getMethod(
                "start", String.class, String.class, Integer.TYPE, Integer.TYPE, int[].class,
                Integer.TYPE, Integer.TYPE, Integer.TYPE, String.class, String[].class);
        XposedBridge.log("start hook, appInfo: " + loadPackageParam.appInfo);
        XposedBridge.hookMethod(start, new XC_MethodHook() {
            @Override
            protected void beforeHookedMethod(MethodHookParam methodHookParam) throws Throwable {
                    int id = 5;
                    int flags = (Integer) methodHookParam.args[id];
                    if ((flags & 0x1) == 0) {
                        flags |= 0x1;
                    }
                    methodHookParam.args[id] = flags;
                    }
            }
        });
    } catch (NoSuchMethodException e) {
        e.printStackTrace();
    }

all apps is debuggable

like image 326
xDragonZ Avatar asked Aug 22 '16 14:08

xDragonZ


1 Answers

boolean isConnected = new Debug().isDebuggerConnected();

Determine if a debugger is currently attached. Documentation of Debug class

like image 66
jobinrjohnson Avatar answered Sep 19 '22 00:09

jobinrjohnson