void output_invocation(long syscall_id, syscall_arg *args) { char str[MAX_LINE_SIZE]; const syscall_info *info; int written; unsigned i; info = get_syscall_info(syscall_id); if (info) { written = snprintf(str, MAX_LINE_SIZE, "%s(", info->name); if (info->arg_count) { write_arg(args[0], info->args_type[0], str, &written); for (i = 1; i < info->arg_count; ++i) { str_printf(str, &written, ", "); write_arg(args[i], info->args_type[i], str, &written); } } written = written > MAX_LINE_SIZE ? MAX_LINE_SIZE : written; snprintf(str + written, MAX_LINE_SIZE - written, ")"); } else snprintf(str, MAX_LINE_SIZE, PLACEHOLDER_TEXT" (%ld)", syscall_id); fprintf(stderr, "%-*s", MIN_PADDING - 1, str); }
void output_return_value(long value, long syscall_id, void *arg) { char str[MAX_LINE_SIZE]; const syscall_info *info; int written; char *err; if (value < 0) { err = strerror(-value); if (-value < ERANGE) written = snprintf( str, MAX_LINE_SIZE, " = -1 %s (%s)", ERRNO_NAMES[-value], err ); else if (-value == RESTART_BLOCKED_ERRNO) /* Special case */ written = snprintf(str, MAX_LINE_SIZE, RESTART_BLOCKED_STR); else /* Unknown ERRNO */ written = snprintf(str, MAX_LINE_SIZE, " = -1 (%s)", err); } else { info = get_syscall_info(syscall_id); if (info) { written = snprintf(str, MAX_LINE_SIZE, " = "); write_arg(arg, info->return_type, str, &written); } else written = snprintf(str, MAX_LINE_SIZE, " = %ld", value); } snprintf(str + written, MAX_LINE_SIZE - written, "\n"); fprintf(stderr, str); }
int read_string(t_env *e, va_list ap) { while (e->str[e->current] != '\0') { if (e->str[e->current] == '%') { e->current++; e->ret = handle_conversion(e, ap); if (e->ret == 1) write_arg(e, ap); } else { ft_putchar(e->str[e->current]); e->current++; e->written++; } } return (0); }
void IntelDisassembler::handle_stmt(IntelSyntaxDisStmt &stmt) { if(stmt.ident == symbol_write) { write(unquotify(stmt.args[0]).c_str()); } else if(stmt.ident == symbol_space) { space(); } else if(stmt.ident == symbol_maybe_write_space_args_imm32) { if(icode->imm != get_num(stmt.args[0])) { space(); write_args(); } } else if(stmt.ident == symbol_write_args) { write_args(); } else if(stmt.ident == symbol_write_arg) { if(stmt.args.size() == 1) write_arg(get_num(stmt.args[0])); else if(stmt.args.size() == 2) write_arg(get_num(stmt.args[0]), get_num(stmt.args[1])); else if(stmt.args.size() == 3) write_arg(get_num(stmt.args[0]), get_num(stmt.args[1]), get_num(stmt.args[2])); else if(stmt.args.size() == 4) write_arg(get_num(stmt.args[0]), get_num(stmt.args[1]), get_num(stmt.args[2]), get_num(stmt.args[3])); } else if(stmt.ident == symbol_write_rep) { if(icode->lockrep == 2 || icode->lockrep == 3) write("rep "); } else if(stmt.ident == symbol_write_repcc) { if(icode->lockrep == 2) write("repnz "); else if(icode->lockrep == 3) write("repz "); } else if(stmt.ident == symbol_write_size_suffix_argsize) { write_size_suffix(icode->argsize[get_num(stmt.args[0])]); } else if(stmt.ident == symbol_write_size_suffix_osz) { write_size_suffix(2 << icode->osz); } else if(stmt.ident == symbol_write_seg_reg) { if(icode->ea.sreg <= 5) { do_write_seg_reg(icode->ea.sreg); write(" "); } } else if(stmt.ident == symbol_comma) { comma(); } else if(stmt.ident == symbol_write_osz64) { write(unquotify(stmt.args[(icode->osz == 2) ? 0 : 1]).c_str()); } else if(stmt.ident == symbol_write_stack_o16_o32_o64) { if(dsz == 2) { // 64bit mode. if(icode->osz == 0) write("o16 "); } else if(dsz != icode->osz) { write_o16_o32_o64(); } } else if(stmt.ident == symbol_do_nop_xchg) { // do_nop_xchg("nop", "xchg", 1) means: argvalue(1) is 0, nop else do xchg int a = get_num(stmt.args[2]); if(icode->argvalue[a] == 0 && state->opcode0 == 0x90 && icode->argtype[0] == IntelArgTypes::Treg_gr) write(unquotify(stmt.args[0]).c_str()); else { write(unquotify(stmt.args[1]).c_str()); space(); write_args(); } } else if(stmt.ident == symbol_write_xlat_o16_o32_o64) { if(dsz == 2) { // 64bit mode. if(icode->osz != 1) write_o16_o32_o64(); } else if(dsz != icode->osz) { write_o16_o32_o64(); } } else if(stmt.ident == symbol_write_osz) { // if osz == 0, write 1st argument. // if osz == 1, write 2nd argument. // if osz == 2, write 3rd argument. write(unquotify(stmt.args[icode->osz]).c_str()); } else if(stmt.ident == symbol_write_asz) { // if asz == 0, write 1st argument. // if asz == 1, write 2nd argument. // if asz == 2, write 3rd argument. write(unquotify(stmt.args[icode->asz]).c_str()); } else if(stmt.ident == symbol_write_far_imm) { write_far_imm(); } else if(stmt.ident == symbol_write_jrcxz_o16_o32_o64) { if(dsz != 2) { if(icode->osz != dsz) write_o16_o32_o64(); } } else { write("<unimpl-stmt>"); } }
char *parse_emit_string (const char *ptr, ES_TYPE type, void *echo_target) { static int level = 0; char *word = NULL; int session; bool fWasParsed; char *name_end; level++; arg_context_t context = ARG_CONTEXT_INITIALIZER; while ((word = extract_arg_string(&ptr, &context)) != NULL) { // handle strings if (word[0] == '"') { char *next = next_expr (word, EXPR_DELIMS); if (*next != '\0') goto echo_error; reduce_string (word); if (type == ES_ECHO) { if (echo_target != NULL) { fprintf ((FILE *) echo_target, "%s", word); } } else if (type == ES_FCREATE) { eb_append((expand_buf_t *) echo_target, word, strlen(word)); } else { int i; for (i = 0; word[i]; i++) { if ((mode & MODE_NORMAL) || (mode & MODE_LIST)) write_out (word[i]); stats_datasize++; program_counter++; } } } else { int value; session = StartSPASMErrorSession(); fWasParsed = parse_num(word, &value); if (fWasParsed == true) { switch (type) { case ES_ECHO: { if (echo_target != NULL) { fprintf ((FILE *) echo_target, "%d", value); } break; } #ifdef USE_BUILTIN_FCREATE case ES_FCREATE: { char buffer[256]; sprintf_s(buffer, "%d", value); eb_append((expand_buf_t *) echo_target, buffer, -1); break; } #endif case ES_BYTE: { write_arg(value, ARG_NUM_8, 0, 0); stats_datasize++; program_counter++; break; } case ES_WORD: { write_arg(value, ARG_NUM_16, 0, 0); stats_datasize+=2; program_counter+=2; break; } case ES_LONG: { write_arg(value, ARG_NUM_24, 0, 0); stats_datasize+=3; program_counter+=3; break; } } ReplaySPASMErrorSession(session); } else if (IsSPASMErrorSessionFatal(session) == false && type != ES_FCREATE) { switch (type) { case ES_ECHO: break; case ES_BYTE: { add_pass_two_expr(word, ARG_NUM_8, 0, 0); stats_datasize++; program_counter++; break; } case ES_WORD: { add_pass_two_expr(word, ARG_NUM_16, 0, 0); stats_datasize+=2; program_counter+=2; break; } case ES_LONG: { add_pass_two_expr(word, ARG_NUM_24, 0, 0); stats_datasize += 3; program_counter += 3; break; } } ReplayFatalSPASMErrorSession(session); } else { char name[256]; char *next; define_t *define; name_end = word; //printf("error occured: %d, forward: %d, value: %d\n", error_occurred, parser_forward_ref_err, value); read_expr (&name_end, name, "("); //printf("Looking up %s\n", name); next = name_end; read_expr (&next, NULL, ")"); if (*next != '\0') goto echo_error; if ((define = search_defines (name))) { char *expr; list_t *args = NULL; //handle defines if (define->contents == NULL) { SetLastSPASMError(SPASM_ERR_ARG_USED_WITHOUT_VALUE, name); } if (*(name_end - 1) == '(') name_end--; name_end = parse_args (name_end, define, &args); if (!name_end) return (char *) ptr; expr = parse_define (define); if (expr != NULL) { arg_context_t nested_context = ARG_CONTEXT_INITIALIZER; // Is it some kind of argument list? const char *nested_expr = expr; extract_arg_string(&nested_expr, &nested_context); if (extract_arg_string(&nested_expr, &nested_context) != NULL) { // if it is, plug it in to the emit string parse_emit_string(expr, type, echo_target); } else { if (IsErrorInSPASMErrorSession(session, SPASM_ERR_EXCEEDED_RECURSION_LIMIT) == false) { int inner_session = StartSPASMErrorSession(); parse_emit_string(expr, type, echo_target); if (IsSPASMErrorSessionFatal(inner_session)) { EndSPASMErrorSession(inner_session); AddSPASMErrorSessionAnnotation(session, _T("Error during evaluation of macro '%s'"), define->name); ReplaySPASMErrorSession(session); } else { EndSPASMErrorSession(inner_session); } //ReplaySPASMErrorSession(session); } else { ReplaySPASMErrorSession(session); } } free (expr); } remove_arg_set (args); } else { echo_error: switch (type) { case ES_ECHO: { if (echo_target != NULL) { fprintf((FILE *) echo_target, "(error)"); } break; } case ES_FCREATE: { SetLastSPASMError(SPASM_ERR_LABEL_NOT_FOUND, word); eb_append((expand_buf_t *) echo_target, "(error)", -1); break; } } ReplaySPASMErrorSession(session); } } EndSPASMErrorSession(session); } } if (type == ES_ECHO && level == 1) { if (echo_target == stdout) putchar ('\n'); else { if (echo_target != NULL) { fclose ((FILE *) echo_target); } } } level--; return (char *) ptr; }
/* This routine tries to write out an equivalent --read-batch command * given the user's --write-batch args. However, it doesn't really * understand most of the options, so it uses some overly simple * heuristics to munge the command line into something that will * (hopefully) work. */ void write_batch_shell_file(int argc, char *argv[], int file_arg_cnt) { int fd, i, len, err = 0; char *p, filename[MAXPATHLEN]; stringjoin(filename, sizeof filename, batch_name, ".sh", NULL); fd = do_open(filename, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IXUSR); if (fd < 0) { rsyserr(FERROR, errno, "Batch file %s open error", filename); exit_cleanup(RERR_FILESELECT); } /* Write argvs info to BATCH.sh file */ if (write_arg(fd, argv[0]) < 0) err = 1; if (filter_list.head) { if (protocol_version >= 29) write_sbuf(fd, " --filter=._-"); else write_sbuf(fd, " --exclude-from=-"); } for (i = 1; i < argc - file_arg_cnt; i++) { p = argv[i]; if (strncmp(p, "--files-from", 12) == 0 || strncmp(p, "--filter", 8) == 0 || strncmp(p, "--include", 9) == 0 || strncmp(p, "--exclude", 9) == 0) { if (strchr(p, '=') == NULL) i++; continue; } if (strcmp(p, "-f") == 0) { i++; continue; } if (write(fd, " ", 1) != 1) err = 1; if (strncmp(p, "--write-batch", len = 13) == 0 || strncmp(p, "--only-write-batch", len = 18) == 0) { if (write(fd, "--read-batch", 12) != 12) err = 1; if (p[len] == '=') { if (write(fd, "=", 1) != 1 || write_arg(fd, p + len + 1) < 0) err = 1; } } else { if (write_arg(fd, p) < 0) err = 1; } } if (!(p = check_for_hostspec(argv[argc - 1], &p, &i))) p = argv[argc - 1]; if (write(fd, " ${1:-", 6) != 6 || write_arg(fd, p) < 0) err = 1; write_byte(fd, '}'); if (filter_list.head) write_filter_rules(fd); if (write(fd, "\n", 1) != 1 || close(fd) < 0 || err) { rsyserr(FERROR, errno, "Batch file %s write error", filename); exit_cleanup(RERR_FILEIO); } }