Skip to content

Instantly share code, notes, and snippets.

@radwany2020
Forked from tewilove/N-02E_diag.c
Created August 12, 2022 01:24
Show Gist options
  • Save radwany2020/e55dc95aa1fb707bafc9947bb2200d74 to your computer and use it in GitHub Desktop.
Save radwany2020/e55dc95aa1fb707bafc9947bb2200d74 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