static struct arg_chain *arg_add(struct arg_chain *where, void *arg) { if (!where) where = arg_alloc(0, 32); if (where->args >= where->size) { while (where->next) where = where->next; where = where->next = arg_alloc(where, 32); } where->arg[where->args++] = arg; return where; }
ophcrack_t *create_crack_4test(table_t **tables, int ntables) { arg_t *arg = arg_alloc(); ophcrack_t *crack = ophcrack_alloc(1, arg); crack->find_freeram = find_freeram_4preload; // Add the tables for (int i=0; i<ntables; ++i) { table_t *tbl = tables[i]; table_set_size_4test(tbl); ophcrack_setup_table(tbl); ophcrack_add_table(crack, tbl); tbl->enabled = 1; list_add_tail(crack->enabled, tbl); } // Add some hashes char pwdump[] = "3e645334fd788c5f949a30c86b9f0fb1:535f34e7eb41001a5d5eea2714d20315"; list_t *hashes = list_alloc(); hash_extract_lmnt(pwdump, hashes, 0); assert(hashes->size == 3); for (list_nd_t *nd = hashes->head; nd != NULL; nd = nd->next) { hash_t *hash = nd->data; ophcrack_add_hash(crack, hash); for (list_nd_t *nd = crack->enabled->head; nd != NULL; nd = nd->next) { table_t *tbl = nd->data; ophcrack_associate(crack, hash, tbl); } } list_free(hashes); return crack; }
/* www_process(): * * The program's signal dispatcher function. Is called whenever a signal arrives. */ PROCESS_THREAD(www_process, ev, data) { static struct ctk_widget *w; #if WWW_CONF_WITH_WGET static char *argptr; #endif /* WWW_CONF_WITH_WGET */ w = (struct ctk_widget *)data; PROCESS_BEGIN(); /* Create the main window. */ memset(webpage, 0, sizeof(webpage)); ctk_window_new(&mainwindow, WWW_CONF_WEBPAGE_WIDTH, WWW_CONF_WEBPAGE_HEIGHT+5, "Web browser"); make_window(); #ifdef WWW_CONF_HOMEPAGE strncpy(editurl, WWW_CONF_HOMEPAGE, sizeof(editurl)); #endif /* WWW_CONF_HOMEPAGE */ CTK_WIDGET_FOCUS(&mainwindow, &urlentry); #if WWW_CONF_WITH_WGET || defined(WWW_CONF_WGET_EXEC) #if CTK_CONF_WINDOWS /* Create download dialog.*/ ctk_dialog_new(&wgetdialog, 38, 7); CTK_WIDGET_ADD(&wgetdialog, &wgetlabel1); CTK_WIDGET_ADD(&wgetdialog, &wgetlabel2); CTK_WIDGET_ADD(&wgetdialog, &wgetnobutton); CTK_WIDGET_ADD(&wgetdialog, &wgetyesbutton); #endif /* CTK_CONF_WINDOWS */ #endif /* WWW_CONF_WITH_WGET || WWW_CONF_WGET_EXEC */ ctk_window_open(&mainwindow); while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { webclient_appcall(data); } else if(ev == ctk_signal_widget_activate) { if(w == (struct ctk_widget *)&gobutton || w == (struct ctk_widget *)&urlentry) { start_loading(); firsty = 0; #if WWW_CONF_HISTORY_SIZE > 0 log_back(); #endif /* WWW_CONF_HISTORY_SIZE > 0 */ memcpy(url, editurl, WWW_CONF_MAX_URLLEN); petsciiconv_toascii(url, WWW_CONF_MAX_URLLEN); open_url(); CTK_WIDGET_FOCUS(&mainwindow, &gobutton); #if WWW_CONF_HISTORY_SIZE > 0 } else if(w == (struct ctk_widget *)&backbutton) { firsty = 0; start_loading(); --history_last; if(history_last > WWW_CONF_HISTORY_SIZE) { history_last = WWW_CONF_HISTORY_SIZE - 1; } memcpy(url, history[(int)history_last], WWW_CONF_MAX_URLLEN); open_url(); CTK_WIDGET_FOCUS(&mainwindow, &backbutton); #endif /* WWW_CONF_HISTORY_SIZE > 0 */ } else if(w == (struct ctk_widget *)&downbutton) { firsty = pagey + WWW_CONF_WEBPAGE_HEIGHT - 4; start_loading(); open_url(); CTK_WIDGET_FOCUS(&mainwindow, &downbutton); } else if(w == (struct ctk_widget *)&stopbutton) { loading = 0; webclient_close(); #if WWW_CONF_WITH_WGET || defined(WWW_CONF_WGET_EXEC) } else if(w == (struct ctk_widget *)&wgetnobutton) { #if CTK_CONF_WINDOWS ctk_dialog_close(); #else /* CTK_CONF_WINDOWS */ clear_page(); #endif /* CTK_CONF_WINDOWS */ } else if(w == (struct ctk_widget *)&wgetyesbutton) { #if CTK_CONF_WINDOWS ctk_dialog_close(); #else /* CTK_CONF_WINDOWS */ clear_page(); #endif /* CTK_CONF_WINDOWS */ #if WWW_CONF_WITH_WGET quit(); argptr = arg_alloc((char)WWW_CONF_MAX_URLLEN); if(argptr != NULL) { strncpy(argptr, url, WWW_CONF_MAX_URLLEN); } program_handler_load("wget.prg", argptr); #else /* WWW_CONF_WITH_WGET */ petsciiconv_topetscii(url, sizeof(url)); /* Clear screen */ ctk_restore(); WWW_CONF_WGET_EXEC(url); redraw_window(); show_statustext("Cannot exec wget"); #endif /* WWW_CONF_WITH_WGET */ #endif /* WWW_CONF_WITH_WGET || WWW_CONF_WGET_EXEC */ #if WWW_CONF_FORMS } else { /* Assume form widget. */ struct inputattrib *input = (struct inputattrib *) (((char *)w) - offsetof(struct inputattrib, widget)); formsubmit(input->formptr); #endif /* WWW_CONF_FORMS */ } } else if(ev == ctk_signal_hyperlink_activate) { firsty = 0; #if WWW_CONF_HISTORY_SIZE > 0 log_back(); #endif /* WWW_CONF_HISTORY_SIZE > 0 */ set_link(w->widget.hyperlink.url); show_url(); open_url(); start_loading(); CTK_WIDGET_FOCUS(&mainwindow, &stopbutton); } else if(ev == ctk_signal_hyperlink_hover) { if(CTK_WIDGET_TYPE((struct ctk_widget *)data) == CTK_WIDGET_HYPERLINK) { strncpy(statustexturl, w->widget.hyperlink.url, sizeof(statustexturl)); petsciiconv_topetscii(statustexturl, sizeof(statustexturl)); show_statustext(statustexturl); } #if UIP_UDP } else if(ev == resolv_event_found) { /* Either found a hostname, or not. */ if((char *)data != NULL && resolv_lookup((char *)data, NULL) == RESOLV_STATUS_CACHED) { open_url(); } else { show_statustext("Host not found"); } #endif /* UIP_UDP */ } else if(ev == ctk_signal_window_close || ev == PROCESS_EVENT_EXIT) { quit(); } }
/* www_process(): * * The program's signal dispatcher function. Is called whenever a signal arrives. */ PROCESS_THREAD(www_process, ev, data) { static struct ctk_widget *w; static unsigned char i; #if WWW_CONF_WITH_WGET static char *argptr; #endif /* WWW_CONF_WITH_WGET */ w = (struct ctk_widget *)data; PROCESS_BEGIN(); /* Create the main window. */ memset(webpage, 0, sizeof(webpage)); ctk_window_new(&mainwindow, WWW_CONF_WEBPAGE_WIDTH, WWW_CONF_WEBPAGE_HEIGHT+5, "Web browser"); make_window(); #ifdef WWW_CONF_HOMEPAGE strncpy(editurl, WWW_CONF_HOMEPAGE, sizeof(editurl)); #endif /* WWW_CONF_HOMEPAGE */ CTK_WIDGET_FOCUS(&mainwindow, &urlentry); #if WWW_CONF_WITH_WGET /* Create download dialog.*/ ctk_dialog_new(&wgetdialog, 38, 7); CTK_WIDGET_ADD(&wgetdialog, &wgetlabel1); CTK_WIDGET_ADD(&wgetdialog, &wgetlabel2); CTK_WIDGET_ADD(&wgetdialog, &wgetnobutton); CTK_WIDGET_ADD(&wgetdialog, &wgetyesbutton); #endif /* WWW_CONF_WITH_WGET */ ctk_window_open(&mainwindow); while(1) { PROCESS_WAIT_EVENT(); if(ev == tcpip_event) { webclient_appcall(data); } else if(ev == ctk_signal_widget_activate) { if(w == (struct ctk_widget *)&backbutton) { firsty = 0; start_loading(); --history_last; if(history_last > WWW_CONF_HISTORY_SIZE) { history_last = WWW_CONF_HISTORY_SIZE - 1; } memcpy(url, history[(int)history_last], WWW_CONF_MAX_URLLEN); open_url(); CTK_WIDGET_FOCUS(&mainwindow, &backbutton); } else if(w == (struct ctk_widget *)&downbutton) { firsty = pagey + WWW_CONF_WEBPAGE_HEIGHT - 4; start_loading(); open_url(); CTK_WIDGET_FOCUS(&mainwindow, &downbutton); } else if(w == (struct ctk_widget *)&gobutton || w == (struct ctk_widget *)&urlentry) { start_loading(); firsty = 0; log_back(); memcpy(url, editurl, WWW_CONF_MAX_URLLEN); petsciiconv_toascii(url, WWW_CONF_MAX_URLLEN); open_url(); CTK_WIDGET_FOCUS(&mainwindow, &gobutton); } else if(w == (struct ctk_widget *)&stopbutton) { loading = 0; webclient_close(); #if WWW_CONF_WITH_WGET } else if(w == (struct ctk_widget *)&wgetnobutton) { ctk_dialog_close(); } else if(w == (struct ctk_widget *)&wgetyesbutton) { ctk_dialog_close(); quit(); argptr = arg_alloc((char)WWW_CONF_MAX_URLLEN); if(argptr != NULL) { strncpy(argptr, url, WWW_CONF_MAX_URLLEN); } program_handler_load("wget.prg", argptr); #endif /* WWW_CONF_WITH_WGET */ #if WWW_CONF_FORMS } else { /* Check form buttons */ for(i = 0; i < pagewidgetptr; ++i) { if(&pagewidgets[i] == w) { formsubmit(&pagewidgetattribs[i].form); /* show_statustext(pagewidgetattribs[i].form.formaction);*/ /* PRINTF(("Formaction %s formname %s inputname %s\n", pagewidgetattribs[i].form.formaction, pagewidgetattribs[i].form.formname, pagewidgetattribs[i].form.inputname));*/ break; } } #endif /* WWW_CONF_FORMS */ } } else if(ev == ctk_signal_hyperlink_activate) { firsty = 0; log_back(); open_link(w->widget.hyperlink.url); CTK_WIDGET_FOCUS(&mainwindow, &stopbutton); /* ctk_window_open(&mainwindow);*/ } else if(ev == ctk_signal_hyperlink_hover) { if(CTK_WIDGET_TYPE((struct ctk_widget *)data) == CTK_WIDGET_HYPERLINK) { strncpy(statustexturl, w->widget.hyperlink.url, sizeof(statustexturl)); petsciiconv_topetscii(statustexturl, sizeof(statustexturl)); show_statustext(statustexturl); } } else if(ev == resolv_event_found) { /* Either found a hostname, or not. */ if((char *)data != NULL && resolv_lookup((char *)data) != NULL) { open_url(); } else { show_statustext("Host not found."); } } else if(ev == ctk_signal_window_close || ev == PROCESS_EVENT_EXIT) { quit(); } } PROCESS_END(); }
/* .External */ SEXP ocl_call(SEXP args) { struct arg_chain *float_args = 0; ocl_call_context_t *occ; int on, an = 0, ftype = FT_DOUBLE, ftsize, ftres, async; SEXP ker = CADR(args), olen, arg, res, octx, dimVec; cl_kernel kernel = getKernel(ker); cl_context context; cl_command_queue commands; cl_device_id device_id = getDeviceID(getAttrib(ker, Rf_install("device"))); cl_mem output; cl_int err; size_t wdims[3] = {0, 0, 0}; int wdim = 1; if (clGetKernelInfo(kernel, CL_KERNEL_CONTEXT, sizeof(context), &context, NULL) != CL_SUCCESS || !context) Rf_error("cannot obtain kernel context via clGetKernelInfo"); args = CDDR(args); res = Rf_getAttrib(ker, install("precision")); if (TYPEOF(res) == STRSXP && LENGTH(res) == 1 && CHAR(STRING_ELT(res, 0))[0] != 'd') ftype = FT_SINGLE; ftsize = (ftype == FT_DOUBLE) ? sizeof(double) : sizeof(float); olen = CAR(args); /* size */ args = CDR(args); on = Rf_asInteger(olen); if (on < 0) Rf_error("invalid output length"); ftres = (Rf_asInteger(CAR(args)) == 1) ? 1 : 0; /* native.result */ if (ftype != FT_SINGLE) ftres = 0; args = CDR(args); async = (Rf_asInteger(CAR(args)) == 1) ? 0 : 1; /* wait */ args = CDR(args); dimVec = coerceVector(CAR(args), INTSXP); /* dim */ wdim = LENGTH(dimVec); if (wdim > 3) Rf_error("OpenCL standard only supports up to three work item dimensions - use index vectors for higher dimensions"); if (wdim) { int i; /* we don't use memcpy in case int and size_t are different */ for (i = 0; i < wdim; i++) wdims[i] = INTEGER(dimVec)[i]; } if (wdim < 1 || wdims[0] < 1 || (wdim > 1 && wdims[1] < 1) || (wdim > 2 && wdims[2] < 1)) Rf_error("invalid dimensions - muse be a numeric vector with positive values"); args = CDR(args); occ = (ocl_call_context_t*) calloc(1, sizeof(ocl_call_context_t)); if (!occ) Rf_error("unable to allocate ocl_call context"); octx = PROTECT(R_MakeExternalPtr(occ, R_NilValue, R_NilValue)); R_RegisterCFinalizerEx(octx, ocl_call_context_fin, TRUE); occ->output = output = clCreateBuffer(context, CL_MEM_WRITE_ONLY, ftsize * on, NULL, &err); if (!output) Rf_error("failed to create output buffer of %d elements via clCreateBuffer (%d)", on, err); if (clSetKernelArg(kernel, an++, sizeof(cl_mem), &output) != CL_SUCCESS) Rf_error("failed to set first kernel argument as output in clSetKernelArg"); if (clSetKernelArg(kernel, an++, sizeof(on), &on) != CL_SUCCESS) Rf_error("failed to set second kernel argument as output length in clSetKernelArg"); occ->commands = commands = clCreateCommandQueue(context, device_id, 0, &err); if (!commands) ocl_err("clCreateCommandQueue"); if (ftype == FT_SINGLE) /* need conversions, create floats buffer */ occ->float_args = float_args = arg_alloc(0, 32); while ((arg = CAR(args)) != R_NilValue) { int n, ndiv = 1; void *ptr; size_t al; switch (TYPEOF(arg)) { case REALSXP: if (ftype == FT_SINGLE) { int i; float *f; double *d = REAL(arg); n = LENGTH(arg); f = (float*) malloc(sizeof(float) * n); if (!f) Rf_error("unable to allocate temporary single-precision memory for conversion from a double-precision argument vector of length %d", n); for (i = 0; i < n; i++) f[i] = d[i]; ptr = f; al = sizeof(float); arg_add(float_args, ptr); } else { ptr = REAL(arg); al = sizeof(double); } break; case INTSXP: ptr = INTEGER(arg); al = sizeof(int); break; case LGLSXP: ptr = LOGICAL(arg); al = sizeof(int); break; case RAWSXP: if (inherits(arg, "clFloat")) { ptr = RAW(arg); ndiv = al = sizeof(float); break; } default: Rf_error("only numeric or logical kernel arguments are supported"); /* no-ops but needed to make the compiler happy */ ptr = 0; al = 0; } n = LENGTH(arg); if (ndiv != 1) n /= ndiv; if (n == 1) {/* scalar */ if (clSetKernelArg(kernel, an++, al, ptr) != CL_SUCCESS) Rf_error("Failed to set scalar kernel argument %d (size=%d)", an, al); } else { cl_mem input = clCreateBuffer(context, CL_MEM_READ_ONLY | CL_MEM_USE_HOST_PTR, al * n, ptr, &err); if (!input) Rf_error("Unable to create buffer (%d elements, %d bytes each) for vector argument %d (oclError %d)", n, al, an, err); if (!occ->mem_objects) occ->mem_objects = arg_alloc(0, 32); arg_add(occ->mem_objects, input); #if 0 /* we used this before CL_MEM_USE_HOST_PTR */ if (clEnqueueWriteBuffer(commands, input, CL_TRUE, 0, al * n, ptr, 0, NULL, NULL) != CL_SUCCESS) Rf_error("Failed to transfer data (%d elements) for vector argument %d", n, an); #endif if (clSetKernelArg(kernel, an++, sizeof(cl_mem), &input) != CL_SUCCESS) Rf_error("Failed to set vector kernel argument %d (size=%d, length=%d)", an, al, n); /* clReleaseMemObject(input); */ } args = CDR(args); } if (clEnqueueNDRangeKernel(commands, kernel, wdim, NULL, wdims, NULL, 0, NULL, async ? &occ->event : NULL) != CL_SUCCESS) Rf_error("Error during kernel execution"); if (async) { /* asynchronous call -> get out and return the context */ #if USE_OCL_COMPLETE_CALLBACK clSetEventCallback(occ->event, CL_COMPLETE, ocl_complete_callback, occ); #endif clFlush(commands); /* the specs don't guarantee execution unless clFlush is called */ occ->ftres = ftres; occ->ftype = ftype; occ->on = on; Rf_setAttrib(octx, R_ClassSymbol, mkString("clCallContext")); UNPROTECT(1); return octx; } clFinish(commands); occ->finished = 1; /* we can release input memory objects now */ if (occ->mem_objects) { arg_free(occ->mem_objects, (afin_t) clReleaseMemObject); occ->mem_objects = 0; } if (float_args) { arg_free(float_args, 0); float_args = occ->float_args = 0; } res = ftres ? Rf_allocVector(RAWSXP, on * sizeof(float)) : Rf_allocVector(REALSXP, on); if (ftype == FT_SINGLE) { if (ftres) { if ((err = clEnqueueReadBuffer( commands, output, CL_TRUE, 0, sizeof(float) * on, RAW(res), 0, NULL, NULL )) != CL_SUCCESS) Rf_error("Unable to transfer result vector (%d float elements, oclError %d)", on, err); PROTECT(res); Rf_setAttrib(res, R_ClassSymbol, mkString("clFloat")); UNPROTECT(1); } else { /* float - need a temporary buffer */ float *fr = (float*) malloc(sizeof(float) * on); double *r = REAL(res); int i; if (!fr) Rf_error("unable to allocate memory for temporary single-precision output buffer"); occ->float_out = fr; if ((err = clEnqueueReadBuffer( commands, output, CL_TRUE, 0, sizeof(float) * on, fr, 0, NULL, NULL )) != CL_SUCCESS) Rf_error("Unable to transfer result vector (%d float elements, oclError %d)", on, err); for (i = 0; i < on; i++) r[i] = fr[i]; } } else if ((err = clEnqueueReadBuffer( commands, output, CL_TRUE, 0, sizeof(double) * on, REAL(res), 0, NULL, NULL )) != CL_SUCCESS) Rf_error("Unable to transfer result vector (%d double elements, oclError %d)", on, err); ocl_call_context_fin(octx); UNPROTECT(1); return res; }