From d82685c027edef9f7ca73a98413d7ec562391dbd Mon Sep 17 00:00:00 2001 From: Andrea Possemato Date: Tue, 5 Apr 2016 11:18:59 +0200 Subject: Gdb env Add gdb detection via environment variables--- detect/env.c | 37 +++++++++++++++++++++++++++++++++++++ detect/env.h | 7 +++++++ detect/gdb.c | 1 + detect/main.c | 25 ++++++++++++++++++++++++- 4 files changed, 69 insertions(+), 1 deletion(-) create mode 100644 detect/env.c create mode 100644 detect/env.h diff --git a/detect/env.c b/detect/env.c new file mode 100644 index 0000000..6782f8d --- /dev/null +++ b/detect/env.c @@ -0,0 +1,37 @@ +/* + * Detect GDB using env + * + */ +#include +#include +#include +#include + +int gdb_columns() { + return (getenv("COLUMNS") != NULL); +} + +int gdb_lines() { + return (getenv("LINES") != NULL); +} + +int gdb_path() { + char *gdb_path = getenv("_"); + if (gdb_path == NULL) { + return 0; + } + char *block_path = strtok(gdb_path, "/"); + char *str = NULL; + while (block_path != NULL) { + str = block_path; + block_path = strtok(NULL, "/"); + } + if (str == NULL) { + return 0; + } + else { + return !strcmp(str,"gdb"); + } + +} + diff --git a/detect/env.h b/detect/env.h new file mode 100644 index 0000000..7cde9af --- /dev/null +++ b/detect/env.h @@ -0,0 +1,7 @@ +#ifndef _ENV_ +#define _ENV_ +int gdb_columns(); +int gdb_lines(); +int gdb_path(); +#endif + diff --git a/detect/gdb.c b/detect/gdb.c index fd0dacd..00336d6 100644 --- a/detect/gdb.c +++ b/detect/gdb.c @@ -6,6 +6,7 @@ #include #include +#include #include #include #include diff --git a/detect/main.c b/detect/main.c index 09e7515..47b9c19 100644 --- a/detect/main.c +++ b/detect/main.c @@ -6,7 +6,7 @@ #include "gdb.h" #include "various.h" - +#include "env.h" int main(int argc, char** argv){ unsigned int res = 0; @@ -68,5 +68,28 @@ int main(int argc, char** argv){ else printf("\n[ ] Everything seems fine\n"); + res = 0; + printf("\n\n"); + printf(".: GDB env detector :.\n\n"); + + if(res += gdb_columns()) + printf("[x] COLUMNS_ENV\n"); + else + printf("[ ] COLUMNS_ENV\n"); + + if(res += gdb_lines()) + printf("[x] LINES_ENV\n"); + else + printf("[ ] LINES_ENV\n"); + + if(res += gdb_path()) + printf("[x] GDB_ENV\n"); + else + printf("[ ] GDB_ENV\n"); + + if(res) + printf("\n[*] GDB detected\n"); + else + printf("\n[ ] No GDB detected\n"); return 0; } -- cgit v1.3