int AmmCaptcha_loadDictionary(char * dictFilename) { captchaStrings = hashMap_Create(32889,1000,0); if (captchaStrings==0) { fprintf(stderr,"Could not loadDictionary %s \n",dictFilename); return 0; } FILE *fd=0; fd = fopen(dictFilename,"r"); if (fd!=0) { char str[256]={0}; while (!feof(fd)) { fscanf (fd, "%s", str); hashMap_Add(captchaStrings,str,0,0); } fclose(fd); return 1; } return 0; }
int runLdd(char * filename,int depth) { if (maxDepth!=0) { if (depth>maxDepth) { return 0; } } char output[SIZEOFOUTPUT]={0}; char * command=(char * ) malloc(sizeof(char) * (strlen(filename)+10) ); if (command==0) { fprintf(stderr,"Could not allocate enough memory\n"); return 0; } FILE *fp=0; strcpy(command,"ldd "); strcat(command,filename); // Open the command for reading. fp = popen(command, "r"); if (fp == 0 ) { fprintf(stderr,"Failed to run `%s`\n",filename); free(command); return 0; } // Read the output a line at a time - output it. unsigned int i=0; while (fgets(output, SIZEOFOUTPUT , fp) != 0) { ++i; if ( strstr(output,"not found")!=0 ) { //- Line %u , i if (printNotFoundLibs) { printf(RED "Not Found (%s) %s\n" NORMAL,filename,output); } } else { //fprintf(stderr,GREEN "Found - Line %u , %s \n" NORMAL,i,output); char * link = strstr(output,"=>"); if (link!=0) { link+=3; int z=0; while (z<strlen(link)) { if (link[z]==' ') { link[z]=0; } ++z; } if (!hashMap_ContainsKey(hm,link)) { //We have ourselves a new dynamic library ! //If we print them , lets print it! if (printFoundLibs) { fprintf(stderr,"%s\n",link); } //If we make symlinks to them lets do it ! if (linkToLibraries) { if (!linkToFileInCurrentDir(link)) { fprintf(stderr,"Error linking to %s\n",link); } } //Add it to our hash map hashMap_Add(hm,link,0,0); //Run LDD for the new library ..! runLdd(link,depth+1); } } } } // close pclose(fp); free(command); return 1; }