From a905826e1e960a235c59655911170fb573bf551f Mon Sep 17 00:00:00 2001 From: Yigit Colakoglu Date: Thu, 10 Jun 2021 02:39:33 +0300 Subject: [PATCH] Red-Black self balancing tree implemented. --- README.md | 11 +++- linkedlist.c | 6 +-- linkedlist.h | 2 +- massurl | Bin 25920 -> 31976 bytes massurl.c | 150 +++++++++++++++++++++++++++++++++++---------------- tree.c | 134 ++++++++++++++++++++++++++++++++++++--------- tree.h | 12 +++-- urlparse.c | 5 +- urlparse.h | 1 + 9 files changed, 239 insertions(+), 82 deletions(-) diff --git a/README.md b/README.md index eabc007..9237650 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,16 @@ massurl is a simple tool that aims to parse the outputs of tools like gau, and extract the parameters for each URL, remove duplicates and do it all very quickly. Because web scraping tools' outputs can get very large very quickly, it is nice to have a tool that parses them and and outputs something clean and easy to read. ## How to use? -Simply clone the git repository and run `make` which outputs the binary *massurl*. You can then simply pipe the output of any command that outputs urls into it or use pass the filename where you want it to read the urls from. It expects each line to have only one url. +Simply clone the git repository and run `make` which outputs the binary *massurl*. You can then simply pipe the output of any command that outputs urls into it or pass the filename where you want it to read the urls from. It expects each line to have only one url. It has several parameters: + +``` +usage: massurl [-v] [-o outfile] [-p payloads] [-n minparamnum] input_file +``` + +You can specify an output file, which it will write instead of stdout, you can also give it a list of payloads which massurl will automatically enter as the values for each parameter. And finally, you can specify the minimum amount of parameters a url must have to be outputted, this value is zero by default but I recommend you use 1. + +## How fast is it? +The tool uses a binary tree to store the urls and keeps it balanced using the red-black self balancing tree algorithm, which allows it to run at incredible speeds. ## Contributing This is a very simple project so you shouldn't have trouble reading the code and fixing the bugs you encounter. If you do so, feel free to send a PR. Or, if you can't seem to fix it yourself, don't be shy and open an issue! diff --git a/linkedlist.c b/linkedlist.c index ac11380..b6f2f2e 100644 --- a/linkedlist.c +++ b/linkedlist.c @@ -36,10 +36,10 @@ LinkedList *linkedlistadd(LinkedList *p, char *data){ return p; } -void linkedlistprint(LinkedList *p, FILE *out){ +void linkedlistprint(LinkedList *p, FILE *out, char* payload){ if(p != NULL){ - (p->data == NULL) ? fprintf(out, "NULL") : fprintf(out, "%s", p->data); + (p->data == NULL) ? fprintf(out, "NULL=NULL") : fprintf(out, "%s=%s", p->data, payload); (p->next == NULL) ? : fprintf(out, "%c",'&'); - linkedlistprint(p->next, out); + linkedlistprint(p->next, out, payload); } } diff --git a/linkedlist.h b/linkedlist.h index 2e5772f..a9b8c83 100644 --- a/linkedlist.h +++ b/linkedlist.h @@ -18,5 +18,5 @@ typedef struct { LinkedList *linkedlistalloc(void); int linkedlistfind(LinkedList *p, char *str); LinkedList*linkedlistadd(LinkedList *p, char *data); -void linkedlistprint(LinkedList *p, FILE *out); +void linkedlistprint(LinkedList *p, FILE *out, char *payload); #endif /* Symbol’s value as variable is void: \. */ diff --git a/massurl b/massurl index eb762f8c876bf9eb1cf3ba81d75bf6d14df233b6..1533ca12e3ea806f879d46c01be052ae17d19d09 100755 GIT binary patch literal 31976 zcmeHw4Rn>&mG*h>y(jnHB=;wOkbuAiL9j{)iUqo;w#xJK0v~ol#cgDz_F>)53 zFpjX$`jckxe~IyDA*@Fpk9u_$qEK#!kt>9&4ZnpfgU3y;XIuU&b(n z3kz*|H$aYl`BM+u%r~0y#%qUa<9`c{d&Po|_AQGSE$C>O-_hQg+cAH~lEw2EFRIOS z)n1}Zpj`|F#?-afZxp^=;s|M0-Vx3y+-GpGsDr$f_@~<`zvmY_?tkGI-J2fRf1>h( z-?^&e*jLxLlZW-7PV(>|jsNzbJoS)A`Nv6!T~6FbS{43zTsZBM=e2HZiZ6X@z;-8{ z;W?KgUGBkc@-Pw!i+JFtksgbG@i_FFapziAx$PeD)Mzwqb)VOAj#IERfgQ6mmE>P*|u-)HED3g|Z& z`jG;7E|ZdUsEIHZ7X6UG2#4Y46OoLS^%grc`TtXH!S} zhtgEiysaBlbirnp){{+bYhoEt(A6VIW=C8su3fig)zzs>Y8SbwOKL9@sWltcr%+hB ztv!=X_iR{yb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9GP)5>B)0eV8WS_yRJ)ng=YMhsnj<}0 zyWVnRucd9&CyeIsCK5Oa)Q%_~5jyU4o%s~<;>q&MrQo!W8J5r)rbwhQEH;C1o&nW9s!>>BoW@d0(Gh{8M zCG=F*5;hOTjXT<#P%G{Yc&SzuXl3Y0QH_YQ1Azj@Cby?sA=lX1ituC5_Rf|rn{V8{ zy(f8t#o*_p&BJ>(OEQK>&p6@pUrpk+2TMPfd6gLVnJl#5k!z~vwRytR@xv>Lj67f6 zF*ytq_w+(42V7B~DBX8l{QBjq%>$D}W&6BtH0TxCrqk;MISAvdzP42SoKWyr^ zu-3@oF|bPc_BVoxw?mos+wbQse2&gVVjG#Y@_hQt)Q%skwDsHX@hyCdOj*gO%TTUI zj^DaldHa34g=ZK}Yro~QkmpGA+j)!I@8>PF?a#O08Zd|qeQM?H_xl#w@Aqx}`R)I@ zkzZ*QS_T788am~%s~_XPzW|LsvHH2CQ^`Pk|6-`hR+}e0h+npR)W})*a5gjYdFsXe zdGdC@XW?CixeBbjr9PA=Z};mK7F$LG^T+S^jlA{0h#E!%ziLnmta~l~7&2_XmA^fz zODx>0(abf!e%@bZ%SUEwRtu}FVxu9y{$GHOyKXfH$YTG$#hw?R&u?)HUxiFKOWxjJ zpIk_7qvJ(mqqvnnfdY;lGwn0?pZ5I!V{9A}$3K&mv;D}&;AFA#M=vB7zArT!{skJ% zT&=u?zeh>7yoedrS`FI_YJrur(1mceyuI&gGxFBXeEAFxVd}E>?~dt`okrdO%Pyjs zoX!-R`t$j${M8 zESe4Trl{hNT&l%tP5b8nfR<;X5{z+SMf!SPp{-Y!@}6#d`Cnb7Ie0!{ JcFIG={{e@>>3aYG diff --git a/massurl.c b/massurl.c index 55533a4..622e5b1 100644 --- a/massurl.c +++ b/massurl.c @@ -5,64 +5,120 @@ * Copyright yigit@yigitcolakoglu.com. 2021. All rights reserved. */ -#include -#include "urlparse.h" -#include "tree.h" #include "strings.h" +#include "tree.h" +#include "urlparse.h" +#include +#include +#include +#include #define MAXURL 100000 +#define MAXPAYLOAD 10000 -static void usage(void){ - fputs("\n", stderr); +static void usage(void) { + fputs("usage: massurl [-v] [-o outfile] [-p payloads] [-n minparamnum] input_file\n", stderr); + exit(1); } -enum outformat{ PLAIN = 01 }; +enum outformat { PLAIN = 01 }; + +TreeNode *root = NULL; int main(int argc, char *argv[]) { - FILE *fin = stdin, *fout = stdout; - char *param, urlstr[MAXURL]; + FILE *fin = stdin, *fout = stdout, *payloads = NULL; + char *param, urlstr[MAXURL], payload[MAXPAYLOAD]; + int minparamn, verbose = 0, npayloads = 1; + time_t begin = time(NULL); + unsigned long lines, errors = 0; - while(--argc > 0){ - param= *++argv; - if(param[0] == '-'){ - param++; - argc--; - switch(*param){ - case 'o': - if ((fout = fopen(*++argv, "w")) == NULL) { - fprintf(stderr, "Can't open output file for writing.\n"); - return 1; - } - if(ferror(fout)){ - fprintf(stderr, "Can't open output file for writing.\n"); - return 1; - } - break; - default: - fprintf(stderr, "Parameter -%c does not exist!", *param); - } - }else{ - if((fin = fopen(param, "r")) == NULL){ - fprintf(stderr, "Can't open file %s\n", param); - return 1; - } + while (--argc > 0) { + param = *++argv; + if (param[0] == '-') { + param++; + argc--; + switch (*param) { + case 'o': + if ((fout = fopen(*++argv, "w")) == NULL) { + fprintf(stderr, "Can't open output file for writing.\n"); + return 1; } - } - - TreeNode *urltree = treealloc(); - URL *url; - while(fgets(urlstr, MAXURL, fin) != NULL){ - if((url = parseurl(urlstr)) == NULL){ - fprintf(stderr, "Malformed URL %s", urlstr); - continue; + if (ferror(fout)) { + fprintf(stderr, "Can't open output file for writing.\n"); + return 1; + } + break; + case 'n': + minparamn = atoi(*++argv); + break; + case 'v': + verbose = 1; + break; + case 'h': + usage(); + break; + case 'p': + if ((payloads = fopen(*++argv, "r")) == NULL) { + fprintf(stderr, "Can't open payload file for reading.\n"); + return 1; } - if(urltree->path == NULL){ - urltree->path = url->base; - urltree->params = url->params; - }else{ - urltree = addtree(urltree, url); + if (ferror(fout)) { + fprintf(stderr, "Can't open payload file for reading.\n"); + return 1; } + break; + default: + fprintf(stderr, "Parameter -%c does not exist!\n", *param); + usage(); + } + } else { + if ((fin = fopen(param, "r")) == NULL) { + fprintf(stderr, "Can't open file %s\n", param); + return 1; + } + } + } + + URL *url; + while (fgets(urlstr, MAXURL, fin) != NULL) { + lines++; + if ((url = parseurl(urlstr)) == NULL) { + errors++; + if (verbose) + fprintf(stderr, "Malformed URL %s", urlstr); + continue; + } + + if (url->nparams >= minparamn) { + TreeNode *newnode = treealloc(); + newnode->path = url->base; + newnode->params = url->params; + newnode->parent = NULL; + newnode->left = newnode->right = NULL; + newnode->nparams = url->nparams; + newnode->red = 1; /* Always color new nodes red */ + root = addtree(root, newnode); + balancetree(root, newnode); + } + } + + int printzeros = 0; + if (payloads == NULL) + printtree(root, fout, "%s", 0); + else { + while (fgets(payload, MAXPAYLOAD, payloads) != NULL) { + npayloads++; + for(int i=0; i #include +#include #include -TreeNode *addtree(TreeNode *p, URL *url) { - if (p == NULL) { - TreeNode *newnode = treealloc(); - newnode->path = url->base; - newnode->params = url->params; - newnode->left = newnode->right = NULL; - return newnode; - } - int strdiff = strcmp(url->base, p->path); +extern TreeNode *root; + +TreeNode *addtree(TreeNode *parent, TreeNode *p) { + if (parent == NULL) + return p; + int strdiff = strcmp(parent->path, p->path); if (!strdiff) { - while(url->params != NULL){ - if(p->params == NULL || linkedlistfind(p->params, url->params->data) == -1){ - p->params = linkedlistadd(p->params, url->params->data); + while (p->params != NULL) { + if (p->params == NULL || + linkedlistfind(parent->params, p->params->data) == -1) { + p->params = linkedlistadd(parent->params, p->params->data); } - url->params = url->params->next; + p->params = p->params->next; } } else if (strdiff < 0) { - p->left = addtree(p->left, url); + parent->left = addtree(parent->left, p); + parent->left->parent = parent; } else { - p->right = addtree(p->right, url); + parent->right = addtree(parent->right, p); + parent->right->parent = parent; } - return p; + return parent; +} + +void rotatetreeleft(TreeNode *p) { + TreeNode *r = p->right; + p->right = r->left; + if (p->right) + p->right->parent = p; + r->parent = p->parent; + if (p->parent == NULL) + root = r; + else if (p->parent->left == p) + p->parent->left = r; + else + p->parent->right = r; + r->left = p; + p->parent = r; +} + +void rotatetreeright(TreeNode *p) { + TreeNode *l = p->left; + p->left = l->right; + if (p->left) + p->left->parent = p; + l->parent = p->parent; + if (p->parent == NULL) + root = l; + else if (p->parent->left == p) + p->parent->left = l; + else + p->parent->right = l; + l->right = p; + p->parent = l; } -TreeNode *treealloc(void){ - return (TreeNode *) malloc(sizeof(TreeNode)); +void balancetree(TreeNode *root, TreeNode *node) { + TreeNode *p = NULL; + TreeNode *gP = NULL; + + while (node->parent != NULL && node->parent->parent != NULL && node->red && node->parent->red ) { + p = node->parent; + gP = node->parent->parent; + if (gP->left == p) { + if (gP->right != NULL && gP->right->red) { + gP->red = 1; + gP->left->red = 0; + gP->right->red = 0; + node = gP; + }else{ + if(p->right == node){ + rotatetreeleft(p); + node = p; + p = node->parent; + }else{ + rotatetreeright(gP); + int c = p->red; + p->red = gP->red; + gP->red = c; + node = p; + } + } + } else { + if(gP->left != NULL && gP->left->red){ + gP->red = 1; + gP->left->red = 0; + gP->right->red = 0; + node = gP; + }else{ + if(p->left == node){ + rotatetreeright(p); + node = p; + p = node->parent; + }else{ + rotatetreeleft(gP); + int c = p->red; + p->red = gP->red; + gP->red = c; + node = p; + } + } + } + } + root->red = 0; } -void printtree(TreeNode *root, FILE *out){ - if(root != NULL){ - printtree(root->left, out); - fprintf(out, "%s ", root->path); - linkedlistprint(root->params, out); - fprintf(out, "%c", '\n'); - printtree(root->right, out); +TreeNode *treealloc(void) { return (TreeNode *)malloc(sizeof(TreeNode)); } + +void printtree(TreeNode *root, FILE *out, char *payload, int minparams) { + if (root != NULL) { + printtree(root->left, out, payload, minparams); + if(root->nparams >= minparams){ + fprintf(out, "%s?", root->path); + linkedlistprint(root->params, out, payload); + fprintf(out, "%c", '\n'); } + printtree(root->right, out, payload, minparams); + } } diff --git a/tree.h b/tree.h index 6b38e70..6002c5c 100644 --- a/tree.h +++ b/tree.h @@ -11,15 +11,21 @@ #ifndef tree_h #define tree_h -typedef struct { +typedef struct tnode { char *path; + unsigned int red : 1; LinkedList *params; + int nparams; + struct tnode *parent; struct tnode *left; struct tnode *right; } TreeNode; -TreeNode *addtree(TreeNode *root, URL *url); +TreeNode *addtree(TreeNode *parent, TreeNode *node); +void rotatetreeright(TreeNode *node); +void rotatetreeleft(TreeNode *node); +void balancetree(TreeNode *root, TreeNode *node); TreeNode *treealloc(void); -void printtree(TreeNode *root, FILE *out); +void printtree(TreeNode *root, FILE *out, char *payload, int minparams); #endif /* Symbol’s value as variable is void: \. */ diff --git a/urlparse.c b/urlparse.c index b7632cc..2ca6ff1 100644 --- a/urlparse.c +++ b/urlparse.c @@ -14,19 +14,21 @@ URL *parseurl(char *url) { URL *urlp = urlalloc(); urlp->params = NULL; + urlp->nparams = 0; short stage = 0; /* var to keep track of where we are in url */ int counter = 0; while (*url != '\0' && *url != '\n') { switch (*url++) { case ':': + counter++; if (stage == 0) { urlp->https = *(url - 2) == 's'; if (*(url + 1) == '\0' || *url == '\0' || *url == '\n') /* weird stuff would happen with strings like "http:" */ return NULL; url += 2; /* Skip the // after the :*/ stage = 1; - counter+=4; + counter+=3; } break; @@ -53,6 +55,7 @@ URL *parseurl(char *url) { urlp->params->data = foo; }else urlp->params = linkedlistadd(urlp->params, foo); + urlp->nparams++; while(*url != '&' && *url != '\0' && *url != '\n') url++; url++; diff --git a/urlparse.h b/urlparse.h index 11e83b9..55a41cc 100644 --- a/urlparse.h +++ b/urlparse.h @@ -14,6 +14,7 @@ typedef struct{ unsigned int https : 1; char *base; LinkedList *params; + int nparams; } URL; URL *parseurl(char *urlstr);