From dcce50b71ee198bd335f7f9692c8c539108d8d54 Mon Sep 17 00:00:00 2001 From: Sam Sneed <163201376+sam-sneed@users.noreply.github.com> Date: Thu, 23 May 2024 23:50:50 +0000 Subject: [PATCH] Update mei-disable.c Add said changes ;) --- mei-disable.c | 57 ++++++++++++++++++++++++++------------------------- 1 file changed, 29 insertions(+), 28 deletions(-) diff --git a/mei-disable.c b/mei-disable.c index c3638a2..614f62f 100644 --- a/mei-disable.c +++ b/mei-disable.c @@ -7,15 +7,9 @@ #include #include -// Disable Intel ME engine. -// This was tested on Z87 board. -// Payload data taken from reverse-engineered fpt.exe v9.5. - - #define _countof(a) (sizeof(a)/sizeof(*(a))) - -static const char *DEV_NAME[] = { "/dev/mei", "/dev/mei0", "/dev/mei1", "/dev/mei2" }; - +#define NUM_DEV_NAMES 5 +char *DEF_DEV_NAMES[NUM_DEV_NAMES] = {"/dev/mei0", "/dev/mei", "/dev/mei1", "/dev/mei2", "/dev/mei3"}; struct guid { uint32_t data1; @@ -33,34 +27,41 @@ static const struct guid mkhi_guid = { uint8_t disable_cmd[] = {0xff,0x10,0x00,0x00}; -int main(int argc, char *argv[]) -{ - int fd; - int rc; - int i; - struct mei_connect_client_data meidata; - for(int i=0;i<_countof(DEV_NAME);i++) - { - printf("Opening %s ... ",DEV_NAME[i]); - fd = open(DEV_NAME[i], O_RDWR); - break; - if (fd < 0) { - printf("%s\n", strerror(errno)); - } +char *find_dev_name() { + char *dev_name = NULL; + struct stat st; + + for (int i = 0; i < NUM_DEV_NAMES; i++) { + char path[20]; + snprintf(path, sizeof(path), "/dev/%s", DEF_DEV_NAMES[i]); + + if (stat(path, &st) == 0) { + dev_name = DEF_DEV_NAMES[i]; + break; + } } - if (fd<0) - { - printf("ME device not found\n"); - return 1; + + if (dev_name == NULL) { + perror("device not found"); + exit(1); } + return dev_name; +} + +int main() { + char *dev_name = find_dev_name(); + printf("Device found: %s\n", dev_name); + int fd = open(dev_name, O_RDWR); + struct mei_connect_client_data meidata; + printf("opened\n"); memcpy(&meidata.in_client_uuid,&mkhi_guid,sizeof(mkhi_guid)); - + printf("Sending IOCTL_MEI_CONNECT_CLIENT .. "); - rc = ioctl(fd, IOCTL_MEI_CONNECT_CLIENT, &meidata); + int rc = ioctl(fd, IOCTL_MEI_CONNECT_CLIENT, &meidata); if (rc < 0) { printf("error\n"); fflush(stdout); perror("ioctl");