mirror of
https://github.com/h3xduck/TripleCross.git
synced 2025-12-27 03:43:09 +08:00
FIltering the found filepaths now fully working. We can now detect opened file descriptors of all processes
This commit is contained in:
43
src/user/include/utils/strings/regex.c
Normal file
43
src/user/include/utils/strings/regex.c
Normal file
@@ -0,0 +1,43 @@
|
||||
#include <regex.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#include "regex.h"
|
||||
|
||||
/**
|
||||
* @brief Compares string against regular expression for file descriptor detection
|
||||
*
|
||||
* @param str
|
||||
* @return 0 if matches, 1 if not matching, -1 if error
|
||||
*/
|
||||
int regex_match_fd(const char* str){
|
||||
regex_t regex;
|
||||
int reti;
|
||||
|
||||
// Compile regular expression (/proc/*/fd/*)
|
||||
reti = regcomp(®ex, "^\\/proc\\/[[:alnum:]]\\+\\/fd\\/[^\n ]\\+$", 0);
|
||||
if (reti) {
|
||||
fprintf(stderr, "Could not compile regex\n");
|
||||
return -1;
|
||||
}
|
||||
|
||||
// Execute regular expression
|
||||
int result = 0;
|
||||
reti = regexec(®ex, str, 0, NULL, 0);
|
||||
if (!reti) {
|
||||
puts("Match");
|
||||
result = 0;
|
||||
}else if (reti == REG_NOMATCH) {
|
||||
result = 1;
|
||||
}else {
|
||||
char msgbuf[100];
|
||||
regerror(reti, ®ex, msgbuf, sizeof(msgbuf));
|
||||
fprintf(stderr, "Regex match failed: %s\n", msgbuf);
|
||||
return -1;
|
||||
}
|
||||
|
||||
//Free memory allocated to the pattern buffer by regcomp()
|
||||
regfree(®ex);
|
||||
|
||||
return result;
|
||||
}
|
||||
Reference in New Issue
Block a user