/*! \brief Creates and initialises a model info object. * * \return A valid model info object or \c NULL if unable to acquire * the necessary memory resources. */ static _model_info_t * _model_info_ctor (const char *fw_name, SANE_Status *status) { SANE_Status s = SANE_STATUS_GOOD; _model_info_t *self = NULL; log_call ("(%s)", fw_name); require (fw_name); self = t_calloc (1, _model_info_t); if (!self) { if (status) *status = SANE_STATUS_NO_MEM; return NULL; } self->fw_name = strdup (fw_name); if (!self->fw_name) { _model_info_dtor (self); if (status) *status = SANE_STATUS_NO_MEM; return NULL; } /* Set defaults using data defined in the source code. The various * getters decide a decent default in case self->fw_name is not one * of the names for which we have data in our sources. */ self->overseas = get_scanner_data (self->fw_name, MODEL_OVERSEAS); self->japan = get_scanner_data (self->fw_name, MODEL_JAPAN); self->profile = get_epson_scan_hard (self->fw_name); self->command = get_scan_command (self->fw_name); self->from_file = false; s = _model_info_merge_file (self); self->name = _model_info_guess_name (self); if (self) /* make sure things are compliant */ { promise (self->fw_name && self->name); promise ( self->name == self->fw_name || self->name == self->overseas || self->name == self->japan); promise (self->profile); promise (self->command); } if (status) *status = s; return self; }
/** Redraws the window. Draws the custom interface. @param win The window to redraw. @return OK if successful and ERR otherwise. **/ int OVERLOAD(wrefresh)(WINDOW * const win) { if (options.roll_on) { return OK; } log_call("wrefresh(" PTRF ").", PTRS(win)); /* Stores the state of the window, draws the interface and restores the state. Pointers are used to suppress a warning about a bug in a library. <pre> the comparison will always evaluate as 'true' for the address of 'attrs' will never be NULL [-Waddress] </pre> */ int y, x; attr_t attrs; attr_t * const attrs_ptr = &attrs; short int pair; short int * const pair_ptr = &pair; wattr_get(win, attrs_ptr, pair_ptr, NULL); getyx(win, y, x); wattrset(win, A_NORMAL); const int result = orig_wrefresh(win); gui_draw(win); orig_wrefresh(win); wmove(win, y, x); wattr_set(win, attrs, pair, NULL); return result; }
/** Prints a formatted string. Intercepts printing anything and initializes this process. @param format The string format. @return The amount of characters printed. **/ int OVERLOAD(printf)(const char * const format, ...) { if (options.progress == MAIN) { options.progress = PRINTF; if (init(TRUE) == -1) { uninit(FALSE); exit(probno); } } va_list ap; va_start(ap, format); char * const buf = astresc(format); if (buf == NULL) { probno = log_error(MALLOC_PROBLEM); uninit(FALSE); exit(probno); } log_call("printf(\"%s\", ...).", buf); free(buf); const int result = vsnprintf(NULL, 0, format, ap); va_end(ap); return result; }
/** Returns the current system time. Replaces the system time with a fixed time. @param t The fixed time to return. @return The fixed time. **/ time_t OVERLOAD(time)(time_t * const t) { log_call("time(" PTRF ").", PTRS(t)); if (t != NULL) { *t = cfg_timestamp; } return cfg_timestamp;//reduces entropy }
int cgp_gen_popul(struct cgp_t *cgp) { for(size_t i = 0; i < CGP_POPUL; ++i) { chromo_gen(chromo_at(cgp->c, i)); #if log_enabled(LOG_CGP) log_call(LOG_CGP); chromo_print(stderr, chromo_at(cgp->c, i)); fprintf(stderr, "\n"); #endif } return priv_eval_popul(cgp->c, CGP_POPUL, cgp->f, &cgp->found_best); }
void unload_font (MyFont * font) #endif { #if defined(LOG_FONT_CALLS) && defined(DEBUG_ALLOCS) log_call (file, line, "unload_font", font->name); #endif if (font->as_font) { release_font (font->as_font); font->as_font = NULL; } if (font->name != NULL) free (font->name); font->name = NULL; }
/*! \brief Tears down model info cache support. * * Releases all resources associated with the model info cache. * The \a self argument should be an opaque pointer obtained via a * call to model_info_cache_init(). * * Note that for error recovery purposes, model_info_cache_init() may * call this function with an empty _cache or no cache at all. * * \returns \c NULL, always */ void * model_info_cache_exit (void *self) { log_call ("(%p)", self); require (_cache == self); const_delete (_datadir, char *); list_destroy (_cache, _model_info_dtor); _datadir = NULL; _cache = NULL; promise (!_cache); return _cache; }
/** Controls the terminal. Intercepts <code>TIOCGWINSZ</code> to always report a fixed size. Resizing the terminal causes spurious calls and prints garbage on the screen. @param fildes An open file descriptor. @param request A request conforming to <code>ioctl_list</code>. @param ... A single pointer. @return 0 if successful and -1 otherwise. **/ int OVERLOAD(ioctl)(const int fildes, const unsigned long request, ...) { va_list argp; va_start(argp, request); void * arg = va_arg(argp, void *); log_call("ioctl(" PTRF ", " PTRF ", " PTRF ").", PTRS(fildes), PTRS(request), PTRS(arg)); const int result = orig_ioctl(fildes, request, arg); if (request == TIOCGWINSZ) { struct winsize * size = (struct winsize * )arg; size->ws_row = (unsigned short int )cfg_rows; size->ws_col = (unsigned short int )cfg_cols; } va_end(argp); return result; }
/*! \brief Sets up model info cache support. * * Model specific information will be looked for in \a pkgdatadir. * * \returns An opaque pointer to the cache. An additional \a status * will be returned as well if the argument is not \c NULL. */ void * model_info_cache_init (const char *pkgdatadir, SANE_Status *status) { SANE_Status s = SANE_STATUS_GOOD; log_call ("(%s, %p)", pkgdatadir, status); require (pkgdatadir); if (_cache) { err_minor ("been here, done that"); if (0 != strcmp_c (_datadir, pkgdatadir)) { err_major ("already using %s", _datadir); } if (status) *status = s; return _cache; } _datadir = strdup (pkgdatadir); _cache = list_create (); if (!_datadir || !_cache) { _cache = model_info_cache_exit (_cache); s = SANE_STATUS_NO_MEM; } if (0 != atexit (xmlCleanupParser)) { err_minor ("could not register XML parser cleanup function"); } /* ?FIXME? * Check for existence/readability of _pkgdatadir and log its * absence/presence. It is _not_ fatal if the directory does * not exist or is not readable. We just want to note it via * an err_minor(). If not readable, we may want to return a * SANE_STATUS_ACCESS_DENIED. */ if (status) *status = s; return _cache; }
/** Removes a file. Intercepts removing the debug file if it exists. @param path The path of the file to remove. @return 0 if successful and -1 otherwise. **/ int OVERLOAD(unlink)(const char * const path) { char * const buf = astresc(path); if (buf == NULL) { probno = log_error(MALLOC_PROBLEM); uninit(FALSE); exit(probno); } log_call("unlink(\"%s\").", buf); free(buf); if (strstr(path, "ADOM.DBG") != NULL) { struct stat unlink_stat; if (stat(path, &unlink_stat) == 0) { sleep(1); return 0; } } return orig_unlink(path); }
/** Ends drawing to the screen. Intercepts exiting prematurely. @return OK if successful and ERR otherwise. **/ int OVERLOAD(endwin)(void) { log_call("endwin()."); curs_set(0); cbreak(); noecho(); wclear(stdscr); short int y, x; getmaxyx(stdscr, y, x); const char * howto = "This process has reached its end."; const char * more_howto = "Load another process or press the exit key to continue."; mvwaddstr(stdscr, y / 2 - 1, (x - strlen(howto)) / 2, howto); mvwaddstr(stdscr, y / 2, (x - strlen(more_howto)) / 2, more_howto); wrefresh(stdscr); while (options.progress != EXIT) { wgetch(stdscr); } uninit(FALSE); exit(NO_PROBLEM); return OK; }
int cgp_next_popul(struct cgp_t *cgp) { const size_t winner_i = choose_winner(cgp); const struct chromo_t *winner = chromo_at(cgp->c, winner_i); chromo_copy(cgp->c, winner); cgp->f[0] = cgp->f[winner_i]; for(size_t i = 1; i < CGP_POPUL - 1; ++i) { chromo_copy(chromo_at(cgp->c, i), cgp->c); chromo_mut(chromo_at(cgp->c, i)); #if log_enabled(LOG_CGP) log_call(LOG_CGP); chromo_print(stderr, chromo_at(cgp->c, i)); fprintf(stderr, "\n"); #endif } cgp->gener += 1; return 0; }
void * dip_exit (void *self) { log_call ("(%p)", self); require (dip == self); if (dip) { if (dip->plugin) { dip->plugin = ipc_kill (dip->plugin); } else { /* sanei_magic_exit, if there was one */ } delete (dip); } return dip; }
void * dip_init (const char *pkglibdir, SANE_Status *status) { SANE_Status s = SANE_STATUS_GOOD; log_call ("(%s, %p)", pkglibdir, status); if (dip) { err_minor ("been here, done that"); if (status) *status = s; return dip; } dip = t_calloc (1, dip_type); if (!dip) { if (status) *status = SANE_STATUS_NO_MEM; return dip; } dip->plugin = ipc_exec ("esdip", pkglibdir, status); if (dip->plugin) { dip->autocrop = esdip_crop; dip->deskew = esdip_turn; } else if (ENABLE_SANEI_MAGIC) /* use free alternative API */ { sanei_magic_init (); dip->autocrop = magic_crop; dip->deskew = magic_turn; } if (status) *status = s; return dip; }
/*! \brief Attempts to find model information for \a fw_name. * * Checks for existing information in the cache before it attempts to * add new model information. Takes care to preserve the cache's cur * member so as not to invalidate existing "iterators". * * \return A pointer to the model information. \c NULL if not found, * in case anything went wrong trying to add the info to the * cache or the caller passed in garbage. */ static _model_info_t * _model_info_cache_get_info (const char *fw_name, SANE_Status *status) { SANE_Status s = SANE_STATUS_GOOD; _model_info_t *info = NULL; list_entry *cur = NULL; bool found = false; log_call ("(%s)", fw_name); require (_cache && _datadir); if (!fw_name || 0 == strlen (fw_name)) { if (status) *status = SANE_STATUS_INVAL; return NULL; } cur = _cache->cur; /* check whether cached */ list_reset (_cache); while (!found && (info = list_next (_cache))) { found = (0 == strcmp_c (info->fw_name, fw_name)); } _cache->cur = cur; if (!found) /* try to add info to cache */ { info = _model_info_ctor (fw_name, &s); if (!info || !list_append (_cache, info)) { _model_info_dtor (info); info = NULL; } } if (status) *status = s; return info; }
/* * gofuzz * * Purpose: * * Fuzzing procedure, building parameters list and using syscall gate. * */ void gofuzz(ULONG ServiceIndex, ULONG ParametersInStack) { ULONG_PTR Arguments[MAX_PARAMETERS]; ULONG c, r, k; RtlSecureZeroMemory(Arguments, sizeof(Arguments)); ParametersInStack /= 4; for (c = 0; c < ParametersInStack + 4; c++) { k = ~GetTickCount(); r = RtlRandomEx(&k); Arguments[c] = fuzzdata[r % SIZEOF_FUZZDATA]; } #ifdef _DEBUG if (g_Log) { log_call(ServiceIndex, ParametersInStack, Arguments); } #endif ntSyscallGate(ServiceIndex, ParametersInStack + 4, Arguments); }
/*! \brief Returns a best-effort model name based on \a fw_name. * * The caller gets to manage the memory occupied by the string that * is returned. Note that \c NULL may be returned. */ char * model_info_cache_get_model (const char *fw_name) { SANE_Status s = SANE_STATUS_GOOD; _model_info_t *m = NULL; log_call ("(%s)", fw_name); require (_cache && _datadir); if (!fw_name || 0 == strlen (fw_name)) { err_minor ("%s", sane_strstatus (SANE_STATUS_INVAL)); return strdup ("(unknown model)"); } m = _model_info_cache_get_info (fw_name, &s); if (!m) { err_minor ("%s", sane_strstatus (s)); return strdup (fw_name); /* best we can do */ } return strdup (m->name); }
/** Prints a string to a window. Draws the custom interface. @param win The window to print to. @param str The string to print. @param n The length of the string. @return OK if successful and ERR otherwise. **/ int OVERLOAD(waddnstr)(WINDOW * const win, const char * const str, const int n) { if (options.progress == PRINTF) { options.progress = WADDNSTR; if (gui_init() == -1) { uninit(FALSE); exit(probno); } if (init_fork() == -1) { uninit(FALSE); exit(probno); } } char * const buf = astresc(str); if (buf == NULL) { probno = log_error(MALLOC_PROBLEM); uninit(FALSE); exit(probno); } log_call("waddnstr(" PTRF ", \"%s\", %d).", PTRS(win), buf, n); free(buf); return orig_waddnstr(win, str, n); }
/** Generates the next pseudorandom number. @return The number. **/ long int OVERLOAD(random)(void) { log_call("random()."); return orig_random(); }
Bool load_font (const char *name_in, MyFont * font) #endif { char *name; char *clean_name; int font_size = asxml_var_get ("font.size"); if (font == NULL) return False; if (font_size <= 0) font_size = 14; #if defined(LOG_FONT_CALLS) && defined(DEBUG_ALLOCS) log_call (file, line, "load_font", name); #endif if (ASDefaultScr->font_manager == NULL) { char *path = getenv ("FONT_PATH"); if (path == NULL) path = getenv ("PATH"); ASDefaultScr->font_manager = create_font_manager (dpy, path, NULL); } name = name_in ? (char *)name_in : font->name; clean_name = name; if (clean_name != NULL) { int i = 0; register char *ptr = clean_name; while (ptr[i]) ++i; while (--i >= 0) if (!isdigit (ptr[i])) break; if ((isspace (ptr[i]) || ptr[i] == '-') && ptr[i + 1]) { font_size = atoi (&(ptr[i + 1])); while (i > 0 && isspace (ptr[i - 1])) --i; clean_name = mystrndup (name, i); } } if (clean_name != NULL) { if ((font->as_font = get_asfont (ASDefaultScr->font_manager, clean_name, 0, font_size, ASF_Freetype)) != NULL) show_progress ("Successfully loaded freetype font \"%s\"", clean_name); } if (font->as_font == NULL && name != NULL) { if ((font->as_font = get_asfont (ASDefaultScr->font_manager, name, 0, font_size, ASF_GuessWho)) != NULL) show_progress ("Successfully loaded font \"%s\"", name); } if (font->as_font == NULL) { font->as_font = get_asfont (ASDefaultScr->font_manager, default_font, 0, font_size, ASF_GuessWho); show_warning ("failed to load font \"%s\" - using default instead", name); } if (clean_name && clean_name != name) free (clean_name); if (font->as_font != NULL && name != font->name) set_string (&(font->name), mystrdup (name)); return (font->as_font != NULL); }
/** Initializes a new color pair. @param pair The index of the pair. @param f The foreground color. @param b The background color. @return OK if successful and ERR otherwise. **/ int OVERLOAD(init_pair)(const short int pair, const short int f, const short int b) { log_call("init_pair(%d, %d, %d).", pair, f, b); pairs++; return orig_init_pair(pair, f, b); }
/** Seeds the pseudorandom number generator. @param seed The seed. **/ void OVERLOAD(srandom)(const unsigned int seed) { log_call("srandom(%u).", seed); orig_srandom(seed); }
/** Converts a <code>time_t</code> to a broken-down <code>struct tm</code>. Replaces <code>localtime</code> with <code>gmtime</code> to disregard timezones. @param timep The <code>time_t</code> to convert. @return The <code>struct tm</code>. **/ struct tm * OVERLOAD(localtime)(const time_t * const timep) { log_call("localtime(" PTRF ").", PTRS(timep)); return gmtime(timep);//reduces entropy }
/** Reads a key code from a window. @param win The window to read from. @return The key code. **/ int OVERLOAD(wgetch)(WINDOW * const win) { log_call("wgetch(" PTRF ").", PTRS(win)); if (options.play_on) { int key = play_key(win); if (key == KEY_EOF) { options.play_on = FALSE; } else { return key; } } if (options.roll_on) { int key = play_key(win); if (key == KEY_EOF) { options.roll_on = FALSE; } else { return key; } } /* Keeps track of the actual turn count. */ if (*exec_turns < previous_turns) { negative_turns++; } else if (*exec_turns > previous_turns) { options.k_on = TRUE; } else { options.k_on = FALSE; } previous_turns = *exec_turns; turns = *exec_turns + negative_turns; /* Waits for a key. */ const int key = orig_wgetch(win); /* Handles a key. */ if (key == cfg_save_key) { put_fwrite(cfg_output_paths[current_save]); save_state(current_save); } else if (key == cfg_load_key) { load_state(current_save); } else if (key == cfg_next_save_key) { INC(current_save, 1, cfg_saves); } else if (key == cfg_prev_save_key) { DEC(current_save, 1, cfg_saves); } else if (key == cfg_longer_duration_key) { if (current_duration < frame_rate * frame_rate) { current_duration *= 2; } } else if (key == cfg_shorter_duration_key) { if (current_duration > frame_rate / frame_rate) { current_duration /= 2; } } else if (key == cfg_more_time_key) { if (cfg_timestamp - record.timestamp < LONG_MAX) { cfg_timestamp++; } } else if (key == cfg_less_time_key) { if (cfg_timestamp - record.timestamp > 0) { cfg_timestamp--; } } else if (key == cfg_menu_key) { options.gui_menu = !options.gui_menu; options.gui_info = FALSE; } else if (key == cfg_info_key) { options.gui_menu = FALSE; options.gui_info = !options.gui_info; } else if (key == cfg_condense_key) { options.gui_condensed = !options.gui_condensed; } else if (key == cfg_hide_key) { options.gui_hidden = !options.gui_hidden; } else if (key == cfg_play_key) { if (options.play_on) { options.play_on = !options.play_on; } else if (record.frames == 0) { options.play_on = TRUE; put_fread(cfg_input_path); record.current = record.first; } } else if (key == cfg_stop_key) { options.play_on = FALSE; record.current = NULL; } else if (key == cfg_quit_key) { options.progress = EXIT; *shared.state = HAD_ENOUGH; shared.pids[0] = 0; uninit(FALSE); exit(NO_PROBLEM); } else { if (record.frames == 0 && key != ' ') { return KEY_NULL; } else { const size_t inputs = sizeof previous_inputs / sizeof *previous_inputs - 1; for (size_t input = 0; input < inputs; input++) {//shifts the array left previous_inputs[input] = previous_inputs[input + 1]; } previous_inputs[inputs] = key; rec_add_key_frame(current_duration, key); } } wrefresh(win); return key; }