service list
tracing output:
./strace -e ioctl service list
ioctl(3, BINDER_VERSION, 0x7fec428910) = 0
ioctl(3, BINDER_SET_MAX_THREADS, 0x7fec428928) = 0
ioctl(3, _IOC(_IOC_WRITE, 0x62, 0x10, 0x4), 0x7fec428a48) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428bf0) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428a58) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428b78) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428b78) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428af0) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428bc8) = 0
Found 298 services:
ioctl(3, BINDER_WRITE_READ, 0x7fec428b20) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428a78) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428a78) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428bf8) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428b90) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428c68) = 0
0 DockObserver: []
ioctl(3, BINDER_WRITE_READ, 0x7fec428dd8) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428db8) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428b20) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428a78) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428a78) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428bf8) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428b90) = 0
ioctl(3, BINDER_WRITE_READ, 0x7fec428c68) = 0
1 SurfaceFlinger: [android.ui.ISurfaceComposer]
help me complete the following code to list binder services
#include <unistd.h>
#include <fcntl.h>
#include <stdio.h>
#include <sys/ioctl.h>
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
struct binder_write_read {
uint64_t write_size;
uint64_t write_buffer;
uint64_t read_size;
uint64_t read_buffer;
uint64_t position;
uint64_t flags;
};
typedef struct {
uint32_t service_name_length;
char service_name[256];
} binder_service_info;
int main() {
int binder_fd;
struct binder_write_read bwr;
ssize_t bytes_read;
binder_fd = open("/dev/binder", O_RDWR);
if (binder_fd < 0) {
perror("Failed to open /dev/binder");
return 1;
}
bwr.write_size = 0;
bwr.write_buffer = 0;
bwr.read_size = 4096;
bwr.read_buffer = (uint64_t)malloc(bwr.read_size);
if (bwr.read_buffer == 0) {
perror("Failed to allocate read buffer");
close(binder_fd);
return 1;
}
bwr.position = 0;
bwr.flags = 0;
if (ioctl(binder_fd, BINDER_GET_SERVICE_LIST, &bwr) < 0) {
perror("IOCTL failed");
free((void *)bwr.read_buffer);
close(binder_fd);
return 1;
}
// Process and print the service information
close(binder_fd);
return 0;
}