/** Save the document. */ static int file_save(char const *fname) { spt_t sp, ep; int rc; status_display("Saving..."); pt_get_sof(&sp); pt_get_eof(&ep); rc = file_save_range(fname, &sp, &ep); switch (rc) { case EINVAL: status_display("Error opening file!"); break; case EIO: status_display("Error writing data!"); break; default: status_display("File saved."); break; } return rc; }
static void main_monitor_status_refresh (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) { const user_options_t *user_options = hashcat_ctx->user_options; const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { if (user_options->quiet == false) { //clear_prompt (); event_log_info (hashcat_ctx, ""); event_log_info (hashcat_ctx, ""); } } status_display (hashcat_ctx); if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { if (user_options->quiet == false) { event_log_info (hashcat_ctx, ""); send_prompt (); } } }
static void selection_copy(void) { spt_t pa, pb; char *str; selection_get_points(&pa, &pb); str = range_get_str(&pa, &pb); if (str == NULL || clipboard_put_str(str) != EOK) { status_display("Copying to clipboard failed!"); } free(str); }
static void main_cracker_finished (MAYBE_UNUSED hashcat_ctx_t *hashcat_ctx, MAYBE_UNUSED const void *buf, MAYBE_UNUSED const size_t len) { const hashes_t *hashes = hashcat_ctx->hashes; const user_options_t *user_options = hashcat_ctx->user_options; const user_options_extra_t *user_options_extra = hashcat_ctx->user_options_extra; if (user_options->keyspace == true) return; if (user_options->opencl_info == true) return; if (user_options->stdout_flag == true) return; // if we had a prompt, clear it if ((user_options_extra->wordlist_mode == WL_MODE_FILE) || (user_options_extra->wordlist_mode == WL_MODE_MASK)) { if ((user_options->benchmark == false) && (user_options->speed_only == false)) { clear_prompt (); } } // print final status if ((user_options->benchmark == true) || (user_options->speed_only == true)) { status_benchmark (hashcat_ctx); if (user_options->machine_readable == false) { event_log_info (hashcat_ctx, ""); } } else { if (user_options->quiet == false) { if (hashes->digests_saved != hashes->digests_done) event_log_info (hashcat_ctx, ""); status_display (hashcat_ctx); event_log_info (hashcat_ctx, ""); } } }
/** Change document name and save. */ static void file_save_as(void) { const char *old_fname = (doc.file_name != NULL) ? doc.file_name : ""; char *fname; fname = filename_prompt("Save As", old_fname); if (fname == NULL) { status_display("Save cancelled."); return; } int rc = file_save(fname); if (rc != EOK) return; if (doc.file_name != NULL) free(doc.file_name); doc.file_name = fname; }
void run() { int ch = 0, ich, i, current_columns, current_rows, success = 1; // some variables for the timer (inclusive the interval) struct timespec last_time = {}; struct timespec current_time = {}; long long default_interval = 40000000; long long interval = default_interval; long long res; char playername[HIGHSCORE_NAME_LENGTH] = {}; int range_counter = 0; // create the game struct GAME game = {}; // set the eat range to 1 game.snake.eat_range = 1; // helper variable to keep track of how long we've paused time_t pause_start; // get the dimensions of the terminal and store them in the GAME struct getmaxyx(stdscr, game.rows, game.columns); // clear the whole screen clear(); // draw the walls draw_border(&game); // show the newly created walls refresh(); // place the snake in the middle of the game field grow_snake(&game.snake, game.rows / 2, game.columns / 2); game.snake.dir = DIR_LEFT; // create some fruits on the screen // NOM, NOM, NOM for(i = 0; i < 50; i++) { grow_fruit(&game); } // get the time when the game started time(&game.started); // get the current time current_utc_time(&last_time); // start the event loop while((ich = getch()) && success) { // key typed? if(ich == ERR) { } else if(ich == '0') { // reset the speed interval = default_interval; } else if(ich == '8') { // speed up interval *= 1.1; } else if(ich == '9') { // slow down interval *= 0.9; } else { // use this key as a direction ch = ich; } // check if we have an overrun current_utc_time(¤t_time); // calculate the dirrence between the last snake move and the current time res = timeval_diff(&last_time, ¤t_time); // is the interval over? if(res > interval) { // has an effect on the eat_range ? if(game.snake.eat_range > 1) { // every 200th field, decrease the range range_counter = (range_counter + 1) % 150; // it turns to 0 after the 200th field if(range_counter == 0) { game.snake.eat_range--; // so, decrease it! } } // new direction? if((ch == KEY_UP || ch == 'w') && game.snake.dir != DIR_DOWN) { game.snake.dir = DIR_UP; } else if((ch == KEY_LEFT || ch == 'a') && game.snake.dir != DIR_RIGHT) { game.snake.dir = DIR_LEFT; } else if((ch == KEY_RIGHT || ch == 'd') && game.snake.dir != DIR_LEFT) { game.snake.dir = DIR_RIGHT; } else if((ch == KEY_DOWN || ch == 's') && game.snake.dir != DIR_UP) { game.snake.dir = DIR_DOWN; } // move the snake success = move_snake(&game); // refresh the screen refresh(); // display the status bar (top-right) status_display(&game); // update the time when we last moved the snake last_time = current_time; } getmaxyx(stdscr, current_rows, current_columns); // 'p' pressed || size of the terminal changed if(ich == 'p' || (current_rows != game.rows || current_columns != game.columns)) { // use the terminal new size game.rows = current_rows; game.columns = current_columns; // get the time time(&pause_start); // show the pause dialog switch(pause_dialog()) { case 2: // leave the game if '2' is pressed success = 0; default: // redraw the screen on resume game.paused += time(NULL) - pause_start; redraw_game(&game); break; } } } // get the time when the game has ended time(&game.ended); // display the highscore dialog & let the player enter his name display_highscore(&game, playername, HIGHSCORE_NAME_LENGTH); // has a name been entered? if not don't create a highscore entry if(playername[0]) { add_highscore(playername, game.highscore, game.ended - game.started - game.paused); } // free all the resources reserved in the game struct kill_game(&game); }
/** Ask for a file name. */ static char *filename_prompt(char const *prompt, char const *init_value) { kbd_event_t ev; char *str; wchar_t buffer[INFNAME_MAX_LEN + 1]; int max_len; int nc; bool done; asprintf(&str, "%s: %s", prompt, init_value); status_display(str); console_set_pos(con, 1 + str_length(str), scr_rows - 1); free(str); console_set_style(con, STYLE_INVERTED); max_len = min(INFNAME_MAX_LEN, scr_columns - 4 - str_length(prompt)); str_to_wstr(buffer, max_len + 1, init_value); nc = wstr_length(buffer); done = false; while (!done) { console_get_kbd_event(con, &ev); if (ev.type == KEY_PRESS) { /* Handle key press. */ if (((ev.mods & KM_ALT) == 0) && (ev.mods & KM_CTRL) != 0) { ; } else if ((ev.mods & (KM_CTRL | KM_ALT)) == 0) { switch (ev.key) { case KC_ESCAPE: return NULL; case KC_BACKSPACE: if (nc > 0) { putchar('\b'); console_flush(con); --nc; } break; case KC_ENTER: done = true; break; default: if (ev.c >= 32 && nc < max_len) { putchar(ev.c); console_flush(con); buffer[nc++] = ev.c; } break; } } } } buffer[nc] = '\0'; str = wstr_to_astr(buffer); console_set_style(con, STYLE_NORMAL); return str; }
int main(int argc, char *argv[]) { kbd_event_t ev; coord_t coord; bool new_file; spt_t pt; con = console_init(stdin, stdout); console_clear(con); console_get_size(con, &scr_columns, &scr_rows); pane.rows = scr_rows - 1; pane.columns = scr_columns; pane.sh_row = 1; pane.sh_column = 1; /* Start with an empty sheet. */ sheet_init(&doc.sh); /* Place caret at the beginning of file. */ coord.row = coord.column = 1; sheet_get_cell_pt(&doc.sh, &coord, dir_before, &pt); sheet_place_tag(&doc.sh, &pt, &pane.caret_pos); pane.ideal_column = coord.column; if (argc == 2) { doc.file_name = str_dup(argv[1]); } else if (argc > 1) { printf("Invalid arguments.\n"); return -2; } else { doc.file_name = NULL; } new_file = false; if (doc.file_name == NULL || file_insert(doc.file_name) != EOK) new_file = true; /* Move to beginning of file. */ caret_move(-ED_INFTY, -ED_INFTY, dir_before); /* Place selection start tag. */ tag_get_pt(&pane.caret_pos, &pt); sheet_place_tag(&doc.sh, &pt, &pane.sel_start); /* Initial display */ cursor_visible = true; cursor_hide(); console_clear(con); pane_text_display(); pane_status_display(); if (new_file && doc.file_name != NULL) status_display("File not found. Starting empty file."); pane_caret_display(); cursor_show(); done = false; while (!done) { console_get_kbd_event(con, &ev); pane.rflags = 0; if (ev.type == KEY_PRESS) { /* Handle key press. */ if (((ev.mods & KM_ALT) == 0) && ((ev.mods & KM_SHIFT) == 0) && (ev.mods & KM_CTRL) != 0) { key_handle_ctrl(&ev); } else if (((ev.mods & KM_ALT) == 0) && ((ev.mods & KM_CTRL) == 0) && (ev.mods & KM_SHIFT) != 0) { key_handle_shift(&ev); } else if ((ev.mods & (KM_CTRL | KM_ALT | KM_SHIFT)) == 0) { key_handle_unmod(&ev); } } /* Redraw as necessary. */ cursor_hide(); if (pane.rflags & REDRAW_TEXT) pane_text_display(); if (pane.rflags & REDRAW_ROW) pane_row_display(); if (pane.rflags & REDRAW_STATUS) pane_status_display(); if (pane.rflags & REDRAW_CARET) pane_caret_display(); cursor_show(); } console_clear(con); return 0; }
static void keypress (hashcat_ctx_t *hashcat_ctx) { status_ctx_t *status_ctx = hashcat_ctx->status_ctx; user_options_t *user_options = hashcat_ctx->user_options; // this is required, because some of the variables down there are not initialized at that point while (status_ctx->devices_status == STATUS_INIT) usleep (100000); const bool quiet = user_options->quiet; tty_break (); while (status_ctx->shutdown_outer == false) { int ch = tty_getchar (); if (ch == -1) break; if (ch == 0) continue; //https://github.com/hashcat/hashcat/issues/302 //#if defined (_POSIX) //if (ch != '\n') //#endif hc_thread_mutex_lock (status_ctx->mux_display); event_log_info (hashcat_ctx, NULL); switch (ch) { case 's': case '\r': case '\n': event_log_info (hashcat_ctx, NULL); status_display (hashcat_ctx); event_log_info (hashcat_ctx, NULL); if (quiet == false) send_prompt (hashcat_ctx); break; case 'b': event_log_info (hashcat_ctx, NULL); bypass (hashcat_ctx); event_log_info (hashcat_ctx, "Next dictionary / mask in queue selected. Bypassing current one."); event_log_info (hashcat_ctx, NULL); if (quiet == false) send_prompt (hashcat_ctx); break; case 'p': if (status_ctx->devices_status != STATUS_PAUSED) { event_log_info (hashcat_ctx, NULL); SuspendThreads (hashcat_ctx); if (status_ctx->devices_status == STATUS_PAUSED) { event_log_info (hashcat_ctx, "Paused"); } event_log_info (hashcat_ctx, NULL); } if (quiet == false) send_prompt (hashcat_ctx); break; case 'r': if (status_ctx->devices_status == STATUS_PAUSED) { event_log_info (hashcat_ctx, NULL); ResumeThreads (hashcat_ctx); if (status_ctx->devices_status != STATUS_PAUSED) { event_log_info (hashcat_ctx, "Resumed"); } event_log_info (hashcat_ctx, NULL); } if (quiet == false) send_prompt (hashcat_ctx); break; case 'c': event_log_info (hashcat_ctx, NULL); stop_at_checkpoint (hashcat_ctx); if (status_ctx->checkpoint_shutdown == true) { event_log_info (hashcat_ctx, "Checkpoint enabled. Will quit at next restore-point update."); } else { event_log_info (hashcat_ctx, "Checkpoint disabled. Restore-point updates will no longer be monitored."); } event_log_info (hashcat_ctx, NULL); if (quiet == false) send_prompt (hashcat_ctx); break; case 'q': event_log_info (hashcat_ctx, NULL); myquit (hashcat_ctx); break; default: if (quiet == false) send_prompt (hashcat_ctx); break; } //https://github.com/hashcat/hashcat/issues/302 //#if defined (_POSIX) //if (ch != '\n') //#endif hc_thread_mutex_unlock (status_ctx->mux_display); } tty_fix (); }
int main(int argc, char *argv[]) { /* * AmigaOS ReadArgs-style argument parsing is an inconsistent shit. * Pile of shit. Period. */ UBYTE returnCode = 0; UBYTE returnCode_EXIT = 0; struct RDArgs *result; CONST_STRPTR argTemplate = "M68K/T,PCMCIA/T,MAPROM/T,SHADOWROM/T,LOADROM/K,MOREMEM/S,INSTCACHE/T,REBOOT/S,DEBUG/S,HELP/S"; #define ARGNUM 11 #define MODE68K_ARG 0 /*#define MODE68KMEMORY_ARG 1 */ #define PCMCIA_ARG 1 #define MAPROM_ARG 2 #define SHADOWROM_ARG 3 #define LOADROM_ARG 4 #define MOREMEM_ARG 5 #define INSTCACHE_ARG 6 #define REBOOT_ARG 7 #define DEBUG_ARG 8 #define HELP_ARG 9 argArray = AllocVec(ARGNUM*sizeof(LONG), MEMF_ANY|MEMF_CLEAR); argArray[MODE68K_ARG] = TOGGLE_EMPTY; /* argArray[MODE68KMEMORY_ARG] = TOGGLE_EMPTY; */ argArray[PCMCIA_ARG] = TOGGLE_EMPTY; argArray[MAPROM_ARG] = TOGGLE_EMPTY; argArray[SHADOWROM_ARG] = TOGGLE_EMPTY; argArray[INSTCACHE_ARG] = TOGGLE_EMPTY; result = ReadArgs(argTemplate, argArray, NULL); if (!arg_switch_isempty(DEBUG_ARG)) { debug = TRUE; } if (!arg_switch_isempty(HELP_ARG)) { help(); return 0; } /* * Some RURUs for correct usage of this program... */ if ((!arg_toggle_isempty(MAPROM_ARG)) && (!arg_toggle_isempty(SHADOWROM_ARG))) { printf("MAPROM and SHADOWROM can't be used together!\n"); return EXIT_SYNTAX_ERROR; } hwrev = ninetails_detect(); if (hwrev == -1) { printf("Ninetails board not detected! :(\n"); return EXIT_HARDWARE_ERROR; } cfgreg_unlock(); /* Some options are forbidden in 68000 mode. */ if (cpu_68k_get()) { if (!arg_switch_isempty(MOREMEM_ARG)) { printf("MOREMEM cannot be used in 68000 mode!\n"); cfgreg_lock(); return EXIT_SYNTAX_ERROR; } if (!arg_toggle_isempty(PCMCIA_ARG)) { printf("PCMCIA is always available in 68000 mode!\n"); cfgreg_lock(); return EXIT_SYNTAX_ERROR; } if (!arg_toggle_isempty(MAPROM_ARG)) { printf("MAPROM cannot be used in 68000 mode!\n"); cfgreg_lock(); return EXIT_SYNTAX_ERROR; } if (!arg_toggle_isempty(SHADOWROM_ARG)) { printf("SHADOWROM cannot be used in 68000 mode!\n"); cfgreg_lock(); return EXIT_SYNTAX_ERROR; } } if (!arg_switch_isempty(MOREMEM_ARG)) { /* printf("DEBUG: MOREMEM arugment passed\n"); */ /* only if not running in 68000 mode */ memory_add_misc(); } /* MAPROM ON only if LOADROM passed. */ if (!arg_toggle_isempty(MAPROM_ARG)) { if (arg_toggle_val(MAPROM_ARG)) if (arg_key_isempty(LOADROM_ARG)){ printf("MAPROM ON must be used with LOADROM!\n"); return EXIT_SYNTAX_ERROR; } else { returnCode = maprom_enable((STRPTR) argArray[LOADROM_ARG]); if ( returnCode > 5 ){ cfgreg_lock(); return returnCode; } else{ if(returnCode > returnCode_EXIT) returnCode_EXIT = returnCode; } } else maprom_disable(); } if (!arg_toggle_isempty(SHADOWROM_ARG)) { if (arg_toggle_val(SHADOWROM_ARG)) { returnCode = shadowrom_enable(); if( returnCode > 5 ){ cfgreg_lock(); return returnCode; } else{ if(returnCode > returnCode_EXIT) returnCode_EXIT = returnCode; } } else shadowrom_disable(); } if (!arg_toggle_isempty(MODE68K_ARG)) { if (arg_toggle_val(MODE68K_ARG)) cpu_68k_enable(); else cpu_68k_disable(); } /* if (!arg_toggle_isempty(MODE68KMEMORY_ARG)) { if (arg_toggle_val(MODE68KMEMORY_ARG)) cpu_68kfast_enable(); else cpu_68kfast_disable(); } */ if (!arg_toggle_isempty(PCMCIA_ARG)) { if (arg_toggle_val(PCMCIA_ARG)) pcmcia_enable(); else pcmcia_disable(); } if (!arg_toggle_isempty(INSTCACHE_ARG)) { if (arg_toggle_val(INSTCACHE_ARG)) instcache_enable(); else instcache_disable(); } if (!arg_switch_isempty(REBOOT_ARG) & (returnCode_EXIT == 0)) { reboot(); } /* Display status only if no arguments were given. */ if (argc == 1) { status_display(); } cfgreg_lock(); /* Free everything and return to OS. */ FreeArgs(result); FreeVec(argArray); return returnCode_EXIT; }