1

Problem: How to read /dev/diag port data directly from a device that have rooted shell. Code:

fd = open("/dev/diag", O_RDWR | O_LARGEFILE | O_NONBLOCK);
    if (fd < 0) {
        perror("open diag dev");
        return -8002;
    }

Working solution with rooted adb shell and c executable:

  1. Make an executable of c code.
  2. Create new user in android.
  3. Make executable owner is this new user id with 'su shell'.
  4. Make /dev/diag port owner is this new user id with 'su shell'.
  5. Run executable without su permissions but in new user shell. I am able to get the data from /dev/diag port everytime after just one time procedure written above. So I do not need the rooted shell again to run my executable and read data from /dev/diag port.

Non-working solution with rooted adb shell and android application:

  1. Install an apk in your device that has UI to call the required function on JNI side to start reading data from the port.
  2. Find the user id of the installed application. I found it in data/system/packages.list file.
  3. Make /dev/diag port owner is this new user id with 'su shell'.
  4. Call the required function in the application that further try to open /dev/diag port. The dev/diag port is not opened by code and retured -8002.

I don't have enough linux knowledge but have a little idea that if I have rooted shell then I can surely give my android application an access on /dev/diag port.

Please help me in this. I will be really thankful to you.

Vatish Sharma
  • 1,536
  • 3
  • 16
  • 35
  • 1
    You need to open the device node using effective root, while running everything else from regular user. See how UNIX daemons work. No need to touch ownership at all. – 0andriy May 21 '19 at 20:05
  • I understand that the only thing I need to achieve is to execute the code that open diag port is with root permissions. But I found no way to this. Another thread for this thing https://stackoverflow.com/questions/55232995/how-to-open-dev-diag-with-super-user-permissions?rq=1 – Vatish Sharma May 28 '19 at 12:39
  • 1
    You make your app run by root in the first plce, but app itself will immediately low the itself priviledges as soon as it gets necessary bits required as a root. Again, just read a good book about daemons in Unix – 0andriy May 28 '19 at 19:20

0 Answers0