Example #1
0
void*
crack_password(void* arg){
  	params* p;
	buffer* buf;
	char pass[50];
	struct zip_archive * archive;
		p =(params*)arg;
		buf = p->buf;
		if ((archive = zip_load_archive(p->zipfile)) == NULL) {
			printf("Unable to open archive %s\n", p->zipfile);
			exit(-1);
		}
		do{	
		 	if (sem_wait(p->full)==-1){
			 	perror("error sem_wait on full w \n");
				exit(-1);
			}
			if(bounded_buffer_get(buf,pass) == 0){
				if(zip_test_password(archive, pass) == 0) {
					p->found = true;
					printf("###################################\n");
				  	printf("####[Password is: %s]\n", pass);
					printf("##################################\n");
				}
			}
			if(sem_post(p->empty)==-1){
			 	perror("error sem_post on full");
				exit(-1);
			}
		}while(!p->found);

		pthread_exit(NULL);
}
Example #2
0
void *downloader(void *arg) {
    struct input_args *in_args = (struct input_args *)arg;
    while (1) {
        char *url = (char *)bounded_buffer_get(in_args->url_queue);
        if (url == NULL)
            break;
        if (hashset_contains(in_args->url_set, url) == 0) {
            hashset_insert(in_args->url_set, url);
            char *content = in_args->fetch(url);
            assert(content != NULL);
            struct page *page = (struct page *)mem_malloc(sizeof(struct page));
            page->url = url;
            page->content = content;
            unbounded_buffer_put(in_args->page_queue, (void *)page);
        } else {
            mem_free(url);
        }
        bounded_buffer_done(in_args->url_queue);
        mutex_lock(in_args->done_mutex);
        cond_signal(in_args->done_cond);
        mutex_unlock(in_args->done_mutex);
    }
    return NULL;
}