size_t event_log_advice_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...) { event_ctx_t *event_ctx = hashcat_ctx->event_ctx; if (fmt == NULL) { event_ctx->msg_buf[0] = 0; event_ctx->msg_len = 0; } else { va_list ap; va_start (ap, fmt); event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1); va_end (ap); } event_ctx->msg_newline = false; event_call (EVENT_LOG_ADVICE, hashcat_ctx, NULL, 0); return event_ctx->msg_len; }
void extern_exit(int info) { if(info == SIGINT) log_write("*** Recieved CTRL-C..."); irc_quit("Program Terminated"); free_xion_memory(); event_call(EVENT_EXIT, 0); log_write("*** Program ended successfully. Allocation Calls: %d Free Calls: %d", stats.alloc_calls, stats.free_calls); exit(EXIT_SUCCESS); return ; }
static int event_thirdEvent(event_t * self, queue_t * queuePtr) { if (queue_thirdEvent(queuePtr) == DATA) { return DATA; } else if (queue_thirdEvent(queuePtr) == NOT_OK) { return NOT_OK; } else { puts("IT IS THIRD EVENT NOW!!!"); event_call(self); } }
/* Use this instead of exit() to prevent memory leaks */ void clean_exit(unsigned int error) { irc_disconnect(); free_xion_memory(); event_call(EVENT_EXIT, 0); if(error) { log_write("*** Program was halted due to an error. Allocation Calls: %d Free Calls: %d", stats.alloc_calls, stats.free_calls); exit(EXIT_FAILURE); } else { log_write("*** Program was halted. Allocation Calls: %d Free Calls: %d", stats.alloc_calls, stats.free_calls); exit(EXIT_SUCCESS); } return ; }
size_t event_log_warning_nn (hashcat_ctx_t *hashcat_ctx, const char *fmt, ...) { va_list ap; va_start (ap, fmt); event_ctx_t *event_ctx = hashcat_ctx->event_ctx; event_ctx->msg_len = event_log (fmt, ap, event_ctx->msg_buf, HCBUFSIZ_TINY - 1); event_ctx->msg_buf[event_ctx->msg_len] = 0; va_end (ap); event_ctx->msg_newline = false; event_call (EVENT_LOG_WARNING, hashcat_ctx, NULL, 0); return event_ctx->msg_len; }
int main(int argc, char *argv[]) { char console[MAX_LEN]; unsigned int err = 0; extern unsigned long alloc_calls; extern unsigned long free_calls; handle_first = (struct handle_list*)mallocm(sizeof(struct handle_list)); if(handle_first == NULL) { make_error("Failed to allocate memory for internal handle list!"); getchar(); return 1; } handle_first->next = NULL; handle_first->handle = (void*)&handle_first; handle_last = handle_first; dispsplash(); printf("Initializing... "); stats.start_time = (long)time(NULL); if(!init()) { make_error("Initialization failed (init() is 0)."); free_xion_memory(); getchar(); return 1; } bot_cmd_init(); printf("Done.\n"); if(!log_clean()) make_warning("Failed to clear log file."); log_write("*** Program started. Executed as: %s", argv[0]); printf("Connecting to %s:%d... ", bot.servaddr, bot.servport); if((err = irc_connect(bot.servaddr, bot.servport)) != 0) { printf("Failed to connect. ERROR %d\n\n", err); log_write("Connecting failed with code: %d", err); printf("Press Enter key to continue."); getchar(); return 0; } printf("Connected.\n"); signal(SIGINT, extern_exit); while(1) { fgets(console, 512, stdin); if(console[0] == '\n') break; strrtok(console, "\r\n"); if(istrcmp(console, "exit")) break; else if(istrcmp(console, "rehash")) { printf("\nRehashing configuration...\n"); if(!rehashconfig()) printf("Failed."); else printf("Done."); } else irc_send(console, 1); } irc_quit(NULL); free_xion_memory(); event_call(EVENT_EXIT, 0); log_write("*** Program ended successfully. Allocation Calls: %d Free Calls: %d", stats.alloc_calls, stats.free_calls); return 0; }
unsigned int rehashconfig(void) { char **xlines; char *conftok = (char*)callocm(CONF_MAX_ITEMLEN, sizeof(char)); unsigned int i = 0, xcount = 0, acount = 0; /* Don't get this confused with the word "account" */ extern q_maxbytes; /*X:Line*/ xcount = get_confitem(&xlines, 'X'); if(!xcount) { make_error("No X:lines in configuration file."); freem(conftok); return 0; } /*nickname*/ xstrcpy(bot.nick, get_itemtok(conftok, xlines[0], 2), 32); if(!istrcmp(bot.current_nick, bot.nick)) irc_nick(bot.nick); /*altnick*/ xstrcpy(bot.altnick, get_itemtok(conftok, xlines[0], 3), 32); /*S:Lines*/ /*maxretry*/ irc_subconftok(conftok, 'S', "maxretry", 3); bot.maxretry = atoi(conftok); /*pingtimeout*/ irc_subconftok(conftok, 'S', "pingtimeout", 3); bot.ping_timeout = atoi(conftok); /*antiflood*/ irc_subconftok(conftok, 'S', "antiflood", 5); bot.floodcheck = (atoi(conftok) ? 1 : 0); irc_subconftok(conftok, 'S', "antiflood", 3); q_maxbytes = (unsigned int)atoi(conftok); /*ctrigger*/ irc_subconftok(conftok, 'S', "ctrigger", 3); conf_replace_alias(conftok); bot.ctrigger = conftok[0]; /*ptrigger*/ irc_subconftok(conftok, 'S', "ptrigger", 3); conf_replace_alias(conftok); bot.ptrigger = conftok[0]; /*A:Lines*/ if(bot.admin_array != NULL) free_2d_array(bot.admin_array, bot.admin_lines); acount = get_confitem(&bot.admin_array, 'A'); bot.admin_lines = acount; if(acount) { for(i = 0;i < bot.admin_lines;i++) { get_itemtok(conftok, bot.admin_array[i], 3); if((istrcmp(conftok, ";")) || (istrcmp(conftok, "*"))) adm_loginuser(get_itemtok(conftok, bot.admin_array[i], 2), get_itemtok(conftok, bot.admin_array[i], 4), atoi(get_itemtok(conftok, bot.admin_array[i], 5))); } } freem(conftok); free_2d_array(xlines, xcount); event_call(EVENT_REHASH, 0); return 1; }
/* This function should not be called more than once */ unsigned int init(void) { char **xlines, **clines; char *conftok = (char*)callocm(CONF_MAX_ITEMLEN, sizeof(char)); unsigned int i = 0, xcount = 0, ccount = 0, acount = 0; /* Don't get this confused with the word "account" */ extern q_maxbytes, q_maxqueue; /* For making sure when these variables are tested, they are set to NULL first. */ init_handle(&q_first); init_handle(&q_last); init_handle(&event_first); init_handle(&event_last); init_handle(&chan_first); init_handle(&chan_last); init_handle(&user_first); init_handle(&user_last); init_handle(&me); init_handle(&bc_first); init_handle(&bc_last); init_handle(&dcc_first); init_handle(&dcc_last); eventloop_running = 0; bot.cid = 0; bot.connected = 0; xstrcpy(bot.config, XION_CONFIG, 260); bot.admin_current_count = 0; bot.current_try = 1; q_first = NULL; /*X:Line*/ xcount = get_confitem(&xlines, 'X'); if(!xcount) { make_error("No X:lines in configuration file."); freem(conftok); return 0; } /*nickname*/ xstrcpy(bot.nick, get_itemtok(conftok, xlines[0], 2), 32); /*altnick*/ xstrcpy(bot.altnick, get_itemtok(conftok, xlines[0], 3), 32); /*username*/ xstrcpy(bot.username, get_itemtok(conftok, xlines[0], 4), 12); /*fullname*/ xstrcpy(bot.info, get_itemtok(conftok, xlines[0], 5), 256); xstrcpy(bot.info, conf_replace_alias(conftok), 256); /*C:Line*/ ccount = get_confitem(&clines, 'C'); if(!ccount) { make_error("No C:lines in configuration file."); freem(conftok); free_2d_array(xlines, xcount); return 0; } /*servaddr*/ xstrcpy(bot.servaddr, get_itemtok(conftok, clines[0], 2), 256); /*servport*/ bot.servport = atoi(get_itemtok(conftok, clines[0], 3)); /*servpass*/ xstrcpy(bot.servpass, get_itemtok(conftok, clines[0], 4), 256); /*S:Lines*/ /*maxretry*/ irc_subconftok(conftok, 'S', "maxretry", 3); bot.maxretry = atoi(conftok); /*pingtimeout*/ irc_subconftok(conftok, 'S', "pingtimeout", 3); bot.ping_timeout = atoi(conftok); /*freshlog*/ irc_subconftok(conftok, 'S', "freshlog", 3); bot.fresh_log = (atoi(conftok) ? 1 : 0); /*antiflood*/ irc_subconftok(conftok, 'S', "antiflood", 5); bot.floodcheck = (atoi(conftok) ? 1 : 0); irc_subconftok(conftok, 'S', "antiflood", 3); q_maxbytes = (unsigned int)atoi(conftok); irc_subconftok(conftok, 'S', "antiflood", 4); q_maxqueue = (unsigned int)atoi(conftok); /*ctrigger*/ irc_subconftok(conftok, 'S', "ctrigger", 3); conf_replace_alias(conftok); bot.ctrigger = conftok[0]; /*ptrigger*/ irc_subconftok(conftok, 'S', "ptrigger", 3); conf_replace_alias(conftok); bot.ptrigger = conftok[0]; /*A:Lines*/ if(bot.admin_array != NULL) free_2d_array(bot.admin_array, bot.admin_lines); acount = get_confitem(&bot.admin_array, 'A'); bot.admin_lines = acount; if(acount) { for(i = 0;i < bot.admin_lines;i++) { get_itemtok(conftok, bot.admin_array[i], 3); if((istrcmp(conftok, ";")) || (istrcmp(conftok, "*"))) adm_loginuser(get_itemtok(conftok, bot.admin_array[i], 2), get_itemtok(conftok, bot.admin_array[i], 4), atoi(get_itemtok(conftok, bot.admin_array[i], 5))); } } /* URL Module: mod-weburlcache.c */ urlmod_init(); freem(conftok); free_2d_array(xlines, xcount); free_2d_array(clines, ccount); event_call(EVENT_INIT, 0); return 1; }
/** * rr simulation */ void s_rr(priority_queue q, v_memory vm, int num, int cs_t, float *a_wait_t, int *total_cs, int *total_t, int *total_d, int t_memmove, int t_slice) { int cur_t = 0; // current time int cur_cs_t = cs_t + 1; // current context switch time (-1 when not switching) int cur_s_t = 0; // current time-slice time int in_use = 0; // boolean for processor usage int procs_t[num]; // processor countdowns process *procs[num]; // processes in use process *tmp; // process to pop from waiting queue int active; // active processor in use int pri = 0; // rr priority (fcfs) char *algo; // fitting algorithm priority_queue pq; // processes queue // zero arrays int i; for(i = 0; i < num; ++i) { procs_t[i] = 0; procs[i] = 0; } // initialize stuff pq = pq_new(0); // print vm algorithm switch(vm.algo) { case 'f': algo = "First-Fit"; break; case 'n': algo = "Next-Fit"; break; case 'b': algo = "Best-Fit"; break; default: break; } printf("time 0ms: Simulator started for RR (t_slice %d) and %s\n", t_slice, algo); while(1) { // check process arrival times tmp = NULL; while(tmp == NULL) { tmp = pq_peek(q, NULL); if(tmp && tmp->a_t == cur_t) { int rc; // add process to system tmp = pq_pop(q, NULL); pq_push(pq, tmp, ++pri); rc = vm_add(&vm, *tmp); if(rc != 1) { // (defrag) event_call("", cur_t, tmp->num, 'a', NULL); event_call("", cur_t, 0, 'b', NULL); event_call("", cur_t, 0, '9', NULL); vm_print(vm); *total_d += vm_defrag(&vm, 10); event_call("", cur_t, 0, 'c', NULL); event_call("", cur_t, 0, '9', NULL); vm_print(vm); vm_add(&vm, *tmp); } // print event_call("", cur_t, tmp->num, '8', pq); event_call("", cur_t, 0, '9', NULL); vm_print(vm); tmp = NULL; } else { tmp = NULL; break; } } // switching context if(cur_cs_t > 0) --cur_cs_t; // switched context if(cur_cs_t == 0) { --cur_cs_t; // check if open process available and run it if possible if((pq_size(pq) != 0) && !in_use) { int procs_u = 0; while(procs[procs_u] != 0) ++procs_u; // get next open index in_use = 1; procs[procs_u] = pq_pop(pq, NULL); // pop the next open process change_status(procs[procs_u], 1); // set status to using cpu procs_t[procs_u] = procs[procs_u]->b_t + 1; // start process timer cur_s_t = t_slice + 1; // start t_slice timer if(procs[procs_u]->cur_t > 0) procs_t[procs_u] = procs[procs_u]->cur_t; active = procs_u; --procs[procs_u]->b_n; event_call("", cur_t, procs[procs_u]->num, '1', pq); } } // process timers for(i = 0; i < num; ++i) { if(procs[i] != 0) { // check timers if(procs_t[i] > 0) { --procs_t[i]; if(cur_s_t > 0) --cur_s_t; // handle timers if(procs_t[i] == 0) { // completed cpu burst if(procs[i]->status == 1) { change_status(procs[i], 2); procs_t[i] = procs[i]->io_t; if(procs[i]->cur_t > 0) procs[i]->cur_t = 0; // reset cur_t in_use = 0; cur_cs_t = cs_t; ++*total_cs; // if process does not require i/o if(procs_t[i] == 0) { if(procs[i]->b_n <= 0) { vm_del(&vm, procs[i]->num); event_call("", cur_t, procs[i]->num, '5', pq); event_call("", cur_t, procs[i]->num, 'd', NULL); event_call("", cur_t, procs[i]->num, '9', NULL); vm_print(vm); change_status(procs[i], 3); // terminate } else { change_status(procs[i], 0); pq_push(pq, procs[i], ++pri); event_call("", cur_t, procs[i]->num, '2', pq); procs[i] = 0; } } else { if(procs[i]->b_n != 0) { event_call("", cur_t, procs[i]->num, '2', pq); event_call("", cur_t, procs[i]->num, '3', pq); } // terminate process else { procs_t[i] = 0; change_status(procs[i], 3); vm_del(&vm, procs[i]->num); event_call("", cur_t, procs[i]->num, '5', pq); event_call("", cur_t, procs[i]->num, 'd', NULL); event_call("", cur_t, procs[i]->num, '9', NULL); vm_print(vm); } } } // completed i/o else if(procs[i]->status == 2) { change_status(procs[i], 0); if(!in_use) cur_cs_t = cs_t; // finished burst if(procs[i]->b_n <= 0) { // terminate on last burst if(pq_size(pq) != 0) { vm_del(&vm, procs[i]->num); event_call("", cur_t, procs[i]->num, '5', pq); event_call("", cur_t, procs[i]->num, 'd', NULL); event_call("", cur_t, procs[i]->num, '9', NULL); vm_print(vm); } change_status(procs[i], 3); } else { pq_push(pq, procs[i], ++pri); event_call("", cur_t, procs[i]->num, '4', pq); procs[i] = 0; } } } // check time slice expiration else if(cur_s_t == 0 && procs[i]->status == 1) { if(pq_size(pq) != 0) { procs[active]->cur_t = procs_t[active]; // store the current processing time ++procs[active]->b_n; // restore burst number since it hasnt finished change_status(procs[active], 0); // reset status pq_push(pq, procs[active], ++pri); // push back into queue preempt_call(cur_t, procs[active]->num, '0', pq); // print cur_cs_t = cs_t; // switch contexts ++*total_cs; // void existing processors procs_t[active] = 0; procs[active] = 0; in_use = 0; cur_s_t = -1; } } } } } // get statistics from all processes for(i = 1; i <= pq_size(pq); ++i) { if(((process*)(pq->buf[i].data))->status == 0) { ++*a_wait_t; } } if(pq_size(pq) == 0 && !in_use && done(procs_t, sizeof(procs_t) / sizeof(int))) { *total_t = cur_t; event_call("RR", cur_t, 0, '7', pq); return; } ++cur_t; } }
int main(int argc, char **argv) { /* SIMULATION VARIABLES */ int n = 0; // processes int cs_t = 13; // context switch time (in ms) int cur_t; // current time (in ms) FILE* inf; // input file (processes.txt) if(argc != 1) { printf("There are no arguments associated with this simulation. Input is read from processes.txt.\n"); return 1; } // processes array, beginning with 10 // realloc when necessary int capacity = 10; struct process *processes = malloc(capacity * sizeof(struct process)); /* read file */ if((inf = fopen("processes.txt", "r")) != NULL) { // get current line char *line = NULL; size_t nbytes = 0; while(getline(&line, &nbytes, inf) != -1) { // preemptive check for capacity if(n == capacity) { capacity += 10; processes = realloc(processes, capacity * sizeof(struct process)); } // trim the string first char *newline; newline = trim(line); if(*newline != 0) { // get values int pn, bt, bn, it; sscanf(newline, "%i|%i|%i|%i", &pn, &bt, &bn, &it); // store values processes[n].num = pn; processes[n].b_t = bt; processes[n].b_n = bn; processes[n].io_t = it; processes[n].enq = n; ++n; } } // free memory free(line); /* ===begin simulation=== */ /** * status is a numerical indicator of the state * the current process is in: * 0 - not running / terminated * 1 - using cpu * 2 - performing i/o */ // initialize timekeeping cur_t = 0; int cur_cs_t = cs_t; // current context switch time int proc_t[sizeof(processes)] = { -1 }; // individual prcess times int proc_s[sizeof(processes)] = { 0 }; // individual process status int i; // for loop iterator int in_use = 0; // defines whether a processor is in use or not // copy processes to queue struct process queue[sizeof(processes)]; memcpy(queue, processes, sizeof(struct process) * sizeof(processes)); event_call(cur_t, 0, '0', queue); // start timer! while(cur_t != -1) { ++cur_t; // switching context if(cur_cs_t > 0) --cur_cs_t; // switched context if(cur_cs_t == 0) { --cur_cs_t; // check if open process available and run it if possible int idx = nextp(queue); if(idx != -1 && !in_use) { in_use = 1; int process = queue[idx].num; proc_s[idx] = 1; // set status to using cpu proc_t[idx] = queue[idx].b_t + 1; // start timer --queue[idx].b_n; // decrement burst number pop(queue); // pop the highest process event_call(cur_t, process, '1', queue); } } // process timers for(i = 0; i < sizeof(processes); ++i) { // check if theres a timer associated with that process if(proc_t[i] > 0) { --proc_t[i]; // handle events if(proc_t[i] == 0) { // completed cpu burst if(proc_s[i] == 1) { proc_s[i] = 2; proc_t[i] = queue[i].io_t; in_use = 0; cur_cs_t = cs_t; // switch contexts if possible // if process does not require i/o if(proc_t[i] == 0) { if(queue[i].b_n <= 0) { event_call(cur_t, queue[i].num, '5', queue); if(done(queue)) { event_call(cur_t, 0, '6', queue); cur_t = -1; } } else { push(queue, i); event_call(cur_t, queue[i].num, '2', queue); } proc_s[i] = 0; } else { if(queue[i].b_n != 0) { event_call(cur_t, queue[i].num, '2', queue); event_call(cur_t, queue[i].num, '3', queue); } // terminate process else { proc_t[i] = 0; proc_s[i] = 0; event_call(cur_t, queue[i].num, '5', queue); if(done(queue)) { event_call(cur_t, 0, '6', queue); cur_t = -1; } } } } // completed i/o else if(proc_s[i] == 2) { proc_s[i] = 0; if(!in_use) cur_cs_t = cs_t; // finished burst if(queue[i].b_n <= 0) { if(done(queue)) { event_call(cur_t, 0, '6', queue); cur_t = -1; } else event_call(cur_t, queue[i].num, '5', queue); } else { push(queue, i); event_call(cur_t, queue[i].num, '4', queue); } } } } } } } else { printf("Error: Couldn't open processes.txt for reading.\n"); } // free memory and exit gracefully free(processes); return 0; }