Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to open "adb shell" in context of application being debugged (on non-rooted device)?

Tags:

android

adb

uid

When I just run adb shell, I get shell running from uid=2000(shell) gid=2000(shell), without ptrace access to my application.

How to open a shell with the same UID as launched application?

like image 614
Vi. Avatar asked Dec 12 '25 23:12

Vi.


2 Answers

Use run-as <your package name> to switch to your app's UID or run-as <your package name> <command> to run a single command with your app's UID.

like image 65
Alex P. Avatar answered Dec 16 '25 22:12

Alex P.


From this answer:

  • The packages.xml file present in /data/system
  • The packages.list file present in /data/system

Contain the list of applications installed and their corresponding UID's.

Another answer in the same question suggests:

adb shell dumpsys package com.example.myapp | grep userId=

You can then open your shell as normal and run:

$ su <UID>

You should then have the same access and privileges as the app that uses that UID.

like image 38
indivisible Avatar answered Dec 16 '25 21:12

indivisible



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!