diff options
author | Gentoo <installgentoo@endianness.com> | 2020-09-27 11:08:16 +1000 |
---|---|---|
committer | Gentoo <installgentoo@endianness.com> | 2020-09-27 11:08:16 +1000 |
commit | 0f794020c7e7c59c77af58f9bdf5641d0f592966 (patch) | |
tree | 218897a6fce10bc3c95aad3be6e547c6c2d3bace | |
download | cloudflare-email-decode-0f794020c7e7c59c77af58f9bdf5641d0f592966.tar.gz cloudflare-email-decode-0f794020c7e7c59c77af58f9bdf5641d0f592966.tar.bz2 cloudflare-email-decode-0f794020c7e7c59c77af58f9bdf5641d0f592966.zip |
initial commit
-rw-r--r-- | Makefile | 14 | ||||
-rw-r--r-- | main.c | 55 |
2 files changed, 69 insertions, 0 deletions
diff --git a/Makefile b/Makefile new file mode 100644 index 0000000..5abdc0c --- /dev/null +++ b/Makefile @@ -0,0 +1,14 @@ +CC=gcc +CFLAGS=-O3 -march=native -pipe + +OBJ = main.o + +%.o: %.c $(DEPS) + $(CC) -c -o $@ $< $(CFLAGS) + +decode: $(OBJ) + $(CC) -o $@ $^ $(CFLAGS) + +clean: + rm $(OBJ) + rm decode @@ -0,0 +1,55 @@ +#include <stdio.h> +#include <stdlib.h> +#include <string.h> +#include <unistd.h> + +void decodeEmail(char encoded[]) + { + int len = strlen(encoded); + + char temp[3]; + char email[len/2];//the encoded string/2 gives the length of the result email+1 + + memcpy(temp, encoded, 2); + temp[2] = '\0'; + + char xorKey = strtol(temp, NULL, 16);//the value of the xorKey is the first two bytes in hex, encoded in UTF-8 + + int j = 0; + for (int i = 2; i < len; i += 2, ++j)//decode the rest of the two bytes + { + memcpy(temp, encoded+i,2); + temp[2] = '\0'; + + email[j] = strtol(temp, NULL, 16) ^ xorKey;//xor two bytes with the xorkey to get a UTF-8 character + } + email[j] = '\0';//terminate the string + + printf("Decoded email: %s\n", email); + } + + + +int main(int argc, char *argv[]) + { + if (!argv[1]) + { + char input[512+1];//as the maximun length of an email should be 255 chars, we allocate 255*2+2 chars for the longest valid input (+1 for the newline) + fprintf(stderr,"Input email to decode (string within data-cfemail=\"\"): "); + + ssize_t length = read(0, input, 512); + if (length < 5){fprintf(stderr,"Invalid input.\n"); exit(1);} + + input[length-1] = '\0';//overwrite newline with null char + + decodeEmail(input); + } + else + { + if (strlen(argv[1]) < 4 || strlen(argv[1]) > 512){fprintf(stderr,"Invalid input.\n"); exit(1);} + decodeEmail(argv[1]); + } + + //test string: e4908d9497a4908b9696818a90829681858fca878b89 + } + |