Skip to content

Instantly share code, notes, and snippets.

@tewilove
Created August 17, 2020 13:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save tewilove/aa5d93ece528f7b2f5fdbb55272d5f07 to your computer and use it in GitHub Desktop.
Save tewilove/aa5d93ece528f7b2f5fdbb55272d5f07 to your computer and use it in GitHub Desktop.
Enables or disables N-02E diag interface without root.
#include <dlfcn.h>
#include <fcntl.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
typedef int (*nv_cmd_remote_t)(int, int, void *);
int main(int argc, char *argv[])
{
int rc;
void *h;
nv_cmd_remote_t nv_cmd_remote;
int disabled;
unsigned char data[128];
int fd;
int one;
if (argc != 2)
return 1;
disabled = !(!!atoi(argv[1]));
memset(data, 0, sizeof(data));
one = !disabled;
fd = open("/dev/diag", O_RDWR);
h = dlopen("libnv.so", RTLD_NOW);
nv_cmd_remote = dlsym(h, "nv_cmd_remote");
/* diag port */
data[0] = disabled;
rc = nv_cmd_remote(1, 61171, data);
/* diag traffic */
data[0] = !disabled;
rc |= nv_cmd_remote(1, 61168, data);
/* /system/bin/ncmdiagd */
rc | = nv_cmd_remote(1, 61167, data);
printf("Turn %s DIAG returned %d.\n", disabled ? "OFF" : "ON", rc);
ioctl(fd, 0x26b, &one);
close(fd);
if (rc)
return 1;
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment