static void _Json_print(Json_val_t *root, int level) { size_t i = 0; print_prefix(level); switch (root->val_type) { case JT_NULL: printf("NULL"); break; case JT_TRUE: printf("TRUE"); break; case JT_FALSE: printf("FALSE"); break; case JT_STRING: printf("\"%.*s\"", root->v.string.len, root->v.string.str); break; case JT_INT: printf("%lld", (long long)root->v.integer); break; case JT_REAL: printf("%lg", root->v.real); break; case JT_NUM_RAW: i = root->v.numraw.nlen + root->v.numraw.elen + !!root->v.numraw.elen + root->v.numraw.flen + !!root->v.numraw.flen; printf("%.*s", (int)i, root->v.numraw.number); break; case JT_ARRAY: printf("[\n"); for (i = 0; i < root->v.array.len; i++) { _Json_print(root->v.array.arr + i, level + 1); printf(",\n"); } print_prefix(level); printf("]"); break; case JT_OBJECT: printf("{\n"); for (i = 0; i < root->v.object.len; i++) { Json_pair_t *pair = root->v.object.objects + i; print_prefix(level + 1); printf("\"%.*s\" : ", pair->name.v.string.len, pair->name.v.string.str); if (pair->value.val_type != JT_ARRAY && pair->value.val_type != JT_OBJECT) { _Json_print(&pair->value, 0); } else { printf("\n"); _Json_print(&pair->value, level + 1); } printf(",\n"); } print_prefix(level); printf("}"); break; } }
void print_prefix(struct node *root) { if (root == NULL) return; printf("%s ", root->token); print_prefix(root->left); print_prefix(root->right); }
static void dump_match (FILE* f, seq* seq1, unspos pos1, seq* seq2, unspos pos2, unspos length) { print_prefix (f, (char*) seq1->v + pos1, length); fprintf (f, "\n"); print_prefix (f, (char*) seq2->v + pos2, length); fprintf (f, "\n"); }
static void print_rusage(struct kinfo_proc *kipp) { long *lp; unsigned int i; char *field, *threadid; print_prefix(kipp); xo_emit("{d:resource/%-14s} {d:usage/%29s}{P: }\n", "user time", format_time(&kipp->ki_rusage.ru_utime)); print_prefix(kipp); xo_emit("{d:resource/%-14s} {d:usage/%29s}{P: }\n", "system time", format_time(&kipp->ki_rusage.ru_stime)); if (Hflag) { asprintf(&threadid, "%d", kipp->ki_tid); if (threadid == NULL) xo_errc(1, ENOMEM, "Failed to allocate memory in print_rusage()"); xo_open_container(threadid); xo_emit("{e:thread_id/%d}", kipp->ki_tid); } else { xo_emit("{e:process_id/%d}", kipp->ki_pid); xo_emit("{e:command/%s}", kipp->ki_comm); } xo_emit("{e:user time/%s}", format_time(&kipp->ki_rusage.ru_utime)); xo_emit("{e:system time/%s}", format_time(&kipp->ki_rusage.ru_stime)); lp = &kipp->ki_rusage.ru_maxrss; for (i = 0; i < nitems(rusage_info); i++) { print_prefix(kipp); asprintf(&field, "{e:%s/%%D}", rusage_info[i].ri_name); if (field == NULL) xo_errc(1, ENOMEM, "Failed to allocate memory in print_rusage()"); xo_emit(field, *lp); free(field); xo_emit("{d:resource/%-32s} {d:usage/%14s}\n", rusage_info[i].ri_name, format_value(*lp, rusage_info[i].ri_humanize, rusage_info[i].ri_scale)); lp++; } if (Hflag) { xo_close_container(threadid); free(threadid); } }
static void _hda_log(int level, const char *fmt, va_list ap) { va_list ap2; int i; if (level > log_level) return; if (logfp == stdout) set_color(level); print_prefix(level); va_copy(ap2, ap); vfprintf(logfp, fmt, ap); if (!(log_flags & HDA_LOG_FLAG_NO_ECHO) && logfp != stdout) vprintf(fmt, ap2); va_end(ap2); if (logfp == stdout) reset_color(); if (((i = strlen(fmt)) > 0) && (fmt[i-1] == '\n')) log_previous_prefix = -1; if ((level == HDA_LOG_ERR || level == HDA_LOG_WARN) && hda_log_trap_on_error) raise(SIGTRAP); }
int main(int argc, char **argv) { int c; int new_line = 1; process_args(argc, argv); while (1) { c = getchar(); if (c == EOF) { break; } if (new_line) { print_prefix(stdout); new_line = 0; } write(out_fd, &c, 1); if (c == '\n') { new_line = 1; } if (trim) { trim_output(); } } return 0; }
int accept_msg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; if (timestamp) print_timestamp(fp); if (n->nlmsg_type == RTM_NEWROUTE || n->nlmsg_type == RTM_DELROUTE) { print_route(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWLINK || n->nlmsg_type == RTM_DELLINK) { ll_remember_index(who, n, NULL); print_linkinfo(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWADDR || n->nlmsg_type == RTM_DELADDR) { print_addrinfo(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWNEIGH || n->nlmsg_type == RTM_DELNEIGH) { print_neigh(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWPREFIX) { print_prefix(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWRULE || n->nlmsg_type == RTM_DELRULE) { print_rule(who, n, arg); return 0; } if (n->nlmsg_type == 15) { char *tstr; time_t secs = ((__u32*)NLMSG_DATA(n))[0]; long usecs = ((__u32*)NLMSG_DATA(n))[1]; tstr = asctime(localtime(&secs)); tstr[strlen(tstr)-1] = 0; fprintf(fp, "Timestamp: %s %lu us\n", tstr, usecs); return 0; } if (n->nlmsg_type == RTM_NEWQDISC || n->nlmsg_type == RTM_DELQDISC || n->nlmsg_type == RTM_NEWTCLASS || n->nlmsg_type == RTM_DELTCLASS || n->nlmsg_type == RTM_NEWTFILTER || n->nlmsg_type == RTM_DELTFILTER) return 0; if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP && n->nlmsg_type != NLMSG_DONE) { fprintf(fp, "Unknown message: %08x %08x %08x\n", n->nlmsg_len, n->nlmsg_type, n->nlmsg_flags); } return 0; }
void st_help(char *msg, ...) { va_list args; va_start(args,msg); st_vsnprintf(msgbuf,BUF_SIZE,msg,args); print_lines("error: ",msgbuf); va_end(args); print_prefix(); fprintf(stderr,"\n"); print_prefix(); fprintf(stderr,"type '%s -h' for help\n",st_priv.fullprogname); exit(ST_EXIT_ERROR); }
static void print_rusage(struct kinfo_proc *kipp) { long *lp; unsigned int i; print_prefix(kipp); printf("%-14s %32s\n", "user time", format_time(&kipp->ki_rusage.ru_utime)); print_prefix(kipp); printf("%-14s %32s\n", "system time", format_time(&kipp->ki_rusage.ru_stime)); lp = &kipp->ki_rusage.ru_maxrss; for (i = 0; i < nitems(rusage_info); i++) { print_prefix(kipp); printf("%-32s %14s\n", rusage_info[i].ri_name, format_value(*lp, rusage_info[i].ri_humanize, rusage_info[i].ri_scale)); lp++; } }
void begin_log_entry( std::ostream& output, log_entry_types let ) { switch( let ) { case BOOST_UTL_ET_INFO: print_prefix( output ); output << "info: "; break; case BOOST_UTL_ET_MESSAGE: break; case BOOST_UTL_ET_WARNING: print_prefix( output ); output << "warning in \"" << unit_test_result::instance().test_case_name() << "\": "; break; case BOOST_UTL_ET_ERROR: print_prefix( output ); output << "error in \"" << unit_test_result::instance().test_case_name() << "\": "; break; case BOOST_UTL_ET_FATAL_ERROR: print_prefix( output ); output << "fatal error in \"" << unit_test_result::instance().test_case_name() << "\": "; break; } }
static void print_lines(char *msgtype,char *msg) { int line = 0; char *head, *tail; head = tail = msgbuf; while (*head) { if ('\n' == *head) { *head = 0; print_prefix(); print_msgtype(msgtype,line); fprintf(stderr,"%s\n",tail); tail = head + 1; line++; } head++; } print_prefix(); print_msgtype(msgtype,line); fprintf(stderr,"%s\n",tail); }
void print_with_width(char *str, t_value *v, t_printer *p) { int marge; char c; int len; len = SPEC == 'c' ? 1 : ft_strlen(str); marge = 0; while (marge + len < v->width) marge++; p->lenght += marge + len; c = ZERO ? '0' : ' '; if (RIGHT) print_str(str, v, p->fd); str = print_prefix(str, c, p, v); marge++; while (--marge) ft_putchar_fd(c, p->fd); if (!RIGHT) print_str(str, v, p->fd); }
int print_space_left(t_opt opt) { int size; int ret; ret = 0; size = opt.width - nbrlen(opt); if (check_signe_moins(opt) == -1 || (ft_check_charset(opt.type, "diDuU") && opt.attri.plus)) size--; size -= print_prefix(opt, 0); if ((!opt.attri.moins && opt.presi) || (!opt.attri.moins && !opt.attri.zero && !opt.presi)) deal_pres(opt, &ret, &size); else if (opt.attri.space && ft_check_charset(opt.type, "diD")) { ft_putchar(' '); ret++; } deal_opt(opt, &ret); return (ret); }
static int accept_msg(const struct sockaddr_nl *who, struct nlmsghdr *n, void *arg) { FILE *fp = (FILE*)arg; if (n->nlmsg_type == RTM_NEWROUTE || n->nlmsg_type == RTM_DELROUTE) { struct rtmsg *r = NLMSG_DATA(n); int len = n->nlmsg_len - NLMSG_LENGTH(sizeof(*r)); if (len < 0) { fprintf(stderr, "BUG: wrong nlmsg len %d\n", len); return -1; } if (r->rtm_flags & RTM_F_CLONED) return 0; if (timestamp) print_timestamp(fp); if (r->rtm_family == RTNL_FAMILY_IPMR || r->rtm_family == RTNL_FAMILY_IP6MR) { if (prefix_banner) fprintf(fp, "[MROUTE]"); print_mroute(who, n, arg); return 0; } else { if (prefix_banner) fprintf(fp, "[ROUTE]"); print_route(who, n, arg); return 0; } } if (timestamp) print_timestamp(fp); if (n->nlmsg_type == RTM_NEWLINK || n->nlmsg_type == RTM_DELLINK) { ll_remember_index(who, n, NULL); if (prefix_banner) fprintf(fp, "[LINK]"); print_linkinfo(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWADDR || n->nlmsg_type == RTM_DELADDR) { if (prefix_banner) fprintf(fp, "[ADDR]"); print_addrinfo(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWADDRLABEL || n->nlmsg_type == RTM_DELADDRLABEL) { if (prefix_banner) fprintf(fp, "[ADDRLABEL]"); print_addrlabel(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWNEIGH || n->nlmsg_type == RTM_DELNEIGH || n->nlmsg_type == RTM_GETNEIGH) { if (preferred_family) { struct ndmsg *r = NLMSG_DATA(n); if (r->ndm_family != preferred_family) return 0; } if (prefix_banner) fprintf(fp, "[NEIGH]"); print_neigh(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWPREFIX) { if (prefix_banner) fprintf(fp, "[PREFIX]"); print_prefix(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWRULE || n->nlmsg_type == RTM_DELRULE) { if (prefix_banner) fprintf(fp, "[RULE]"); print_rule(who, n, arg); return 0; } if (n->nlmsg_type == RTM_NEWNETCONF) { if (prefix_banner) fprintf(fp, "[NETCONF]"); print_netconf(who, n, arg); return 0; } if (n->nlmsg_type == NLMSG_TSTAMP) { print_nlmsg_timestamp(fp, n); return 0; } if (n->nlmsg_type != NLMSG_ERROR && n->nlmsg_type != NLMSG_NOOP && n->nlmsg_type != NLMSG_DONE) { fprintf(fp, "Unknown message: type=0x%08x(%d) flags=0x%08x(%d)" "len=0x%08x(%d)\n", n->nlmsg_type, n->nlmsg_type, n->nlmsg_flags, n->nlmsg_flags, n->nlmsg_len, n->nlmsg_len); } return 0; }
extern void articulate(void) { node *stn, *stnStart; int i; long cFixed; component_list = NULL; articulation_list = NULL; artlist = NULL; fixedlist = NULL; /* find articulation points and components */ colour = 0; stnStart = NULL; cMaxVisits = 0; FOR_EACH_STN(stn, stnlist) { if (fixed(stn)) { remove_stn_from_list(&stnlist, stn); add_stn_to_list(&fixedlist, stn); colour++; stn->colour = -colour; #ifdef DEBUG_ARTIC printf("Putting stn "); print_prefix(stn->name); printf(" on fixedlist\n"); #endif } else { cMaxVisits++; stn->colour = 0; } } dirn_stack = osmalloc(cMaxVisits); min_stack = osmalloc(cMaxVisits * sizeof(long)); /* fixedlist can be NULL here if we've had a *solve followed by survey * which is all hanging. */ cFixed = colour; while (fixedlist) { int c; stnStart = fixedlist; stn = stnStart; /* see if this is a fresh component - it may not be, we may be * processing the other way from a fixed point cut-line */ if (stn->colour < 0) { #ifdef DEBUG_ARTIC printf("new component\n"); #endif stn->colour = -stn->colour; /* fixed points are negative until we colour from them */ cComponents++; /* FIXME: logic to count components isn't the same as the logic * to start a new one - we should start a new one for a fixed point * cut-line (see below) */ if (artlist) { component *comp; articulation *art; art = osnew(articulation); art->stnlist = artlist; art->next = articulation_list; articulation_list = art; artlist = NULL; comp = osnew(component); comp->next = component_list; comp->artic = articulation_list; component_list = comp; articulation_list = NULL; } #ifdef DEBUG_ARTIC print_prefix(stn->name); printf(" [%p] is root of component %ld\n", stn, cComponents); printf(" and colour = %d/%d\n", stn->colour, cFixed); #endif } c = 0; for (i = 0; i <= 2 && stn->leg[i]; i++) { node *stn2 = stn->leg[i]->l.to; if (stn2->colour < 0) { stn2->colour = -stn2->colour; } else if (stn2->colour == 0) { /* Special case to check if start station is an articulation point * which it is iff we have to colour from it in more than one dirn * * We're looking for articulation legs - these are those where * colouring from here doesn't reach a fixed point (including * stn - the fixed point we've started from) * * FIXME: this is a "fixed point cut-line" case where we could * start a new component. */ long col = visit(stn2, reverse_leg_dirn(stn->leg[i])); #ifdef DEBUG_ARTIC print_prefix(stn->name); printf(" -> "); print_prefix(stn2->name); printf(" col %d cFixed %d\n", col, cFixed); #endif if (col > cFixed) { /* start new articulation - FIXME - overeager */ articulation *art = osnew(articulation); art->stnlist = artlist; art->next = articulation_list; articulation_list = art; artlist = NULL; c |= 1 << i; } } } switch (c) { /* had to colour in 2 or 3 directions from start point */ case 3: case 5: case 6: case 7: #ifdef DEBUG_ARTIC print_prefix(stn->name); printf(" is a special case start articulation point [%d]\n", c); #endif for (i = 0; i <= 2 && stn->leg[i]; i++) { if (TSTBIT(c, i)) { /* flag leg as an articulation for loop error reporting */ stn->leg[i]->l.reverse |= FLAG_ARTICULATION; #ifdef DEBUG_ARTIC print_prefix(stn->leg[i]->l.to->name); putnl(); #endif reverse_leg(stn->leg[i])->l.reverse |= FLAG_ARTICULATION; } } } #ifdef DEBUG_ARTIC printf("Putting FIXED stn "); print_prefix(stn->name); printf(" on artlist\n"); #endif remove_stn_from_list(&fixedlist, stn); add_stn_to_list(&artlist, stn); if (stnStart->colour == 1) { #ifdef DEBUG_ARTIC printf("%ld components\n",cComponents); #endif break; } } osfree(dirn_stack); dirn_stack = NULL; osfree(min_stack); min_stack = NULL; if (artlist) { articulation *art = osnew(articulation); art->stnlist = artlist; art->next = articulation_list; articulation_list = art; artlist = NULL; } if (articulation_list) { component *comp = osnew(component); comp->next = component_list; comp->artic = articulation_list; component_list = comp; articulation_list = NULL; } if (stnlist) { /* Any stations still in stnlist are unfixed, which is means we have * one or more hanging surveys. * * The cause of the problem is pretty likely to be a typo, so run the * checks which report errors and warnings about issues which such a * typo is likely to result in. */ check_node_stats(); /* Actually this error is fatal, but we want to list the survey * stations which aren't connected, so we report it as an error * and die after listing them... */ bool fNotAttached = fFalse; error(/*Survey not all connected to fixed stations*/45); FOR_EACH_STN(stn, stnlist) { /* Anonymous stations must be at the end of a trailing traverse (since * the same anonymous station can't be referred to more than once), * and trailing traverses have been removed at this point. */ SVX_ASSERT(!TSTBIT(stn->name->sflags, SFLAGS_ANON)); if (stn->name->ident) { if (!fNotAttached) { fNotAttached = fTrue; puts(msg(/*The following survey stations are not attached to a fixed point:*/71)); } puts(sprint_prefix(stn->name)); } } exit(EXIT_FAILURE); }
static unsigned long visit(node *stn, int back) { long min_colour; int i; unsigned long tos = 0; SVX_ASSERT(dirn_stack && min_stack); #ifdef DEBUG_ARTIC printf("visit(%p, %d) called\n", stn, back); #endif iter: min_colour = stn->colour = ++colour; #ifdef DEBUG_ARTIC printf("visit: stn [%p] ", stn); print_prefix(stn->name); printf(" set to colour %ld -> min\n", colour); #endif for (i = 0; i <= 2 && stn->leg[i]; i++) { if (i != back) { node *to = stn->leg[i]->l.to; long col = to->colour; if (col == 0) { SVX_ASSERT(tos < cMaxVisits); dirn_stack[tos] = back; min_stack[tos] = min_colour; tos++; back = reverse_leg_dirn(stn->leg[i]); stn = to; goto iter; uniter: SVX_ASSERT(tos > 0); --tos; i = reverse_leg_dirn(stn->leg[back]); to = stn; stn = to->leg[back]->l.to; back = dirn_stack[tos]; if (min_stack[tos] < min_colour) min_colour = min_stack[tos]; #ifdef DEBUG_ARTIC printf("unwind: stn [%p] ", stn); print_prefix(stn->name); printf(" colour %d, min %d, station after %d\n", stn->colour, min_colour, to->colour); printf("Putting stn "); print_prefix(to->name); printf(" on artlist\n"); #endif remove_stn_from_list(&stnlist, to); add_stn_to_list(&artlist, to); if (to->colour <= min_colour) { articulation *art; min_colour = to->colour; /* FIXME: note down leg (<-), remove and replace: * /\ / /\ * [fixed point(s)] *-* -> [..] ) * \/ \ \/ * stn to */ /* flag leg as an articulation for loop error reporting */ to->leg[dirn_stack[tos]]->l.reverse |= FLAG_ARTICULATION; stn->leg[i]->l.reverse |= FLAG_ARTICULATION; /* start new articulation */ art = osnew(articulation); art->stnlist = artlist; art->next = articulation_list; articulation_list = art; artlist = NULL; #ifdef DEBUG_ARTIC printf("Articulate *-"); print_prefix(stn->name); printf("-"); print_prefix(to->name); printf("-...\n"); #endif } } else { /* back edge case */ if (col < 0) { /* we've found a fixed point */ col = -col; to->colour = col; #if 0 /* Removing this solves Graham Mullan's problem and makes more * sense since it means we'll recheck this point for further * legs. */ #ifdef DEBUG_ARTIC printf("Putting FOUND FIXED stn "); print_prefix(to->name); printf(" on artlist\n"); #endif remove_stn_from_list(&fixedlist, to); add_stn_to_list(&artlist, to); #endif } if (col < min_colour) min_colour = col; } } } SVX_ASSERT(!stn->leg[0] || stn->leg[0]->l.to->colour > 0); SVX_ASSERT(!stn->leg[1] || stn->leg[1]->l.to->colour > 0); SVX_ASSERT(!stn->leg[2] || stn->leg[2]->l.to->colour > 0); if (tos > 0) goto uniter; #ifdef DEBUG_ARTIC printf("Putting stn "); print_prefix(stn->name); printf(" on artlist\n"); #endif remove_stn_from_list(&stnlist, stn); add_stn_to_list(&artlist, stn); return min_colour; }
/* Parse user command */ int parse_cmd(uint8_t *buf, size_t *len) { char cmd_buf[MAX_SIZE] = ""; /* For storing command */ char split[8] = " "; /* Split characters for parsing command */ char *para; /* Point to parameters in command */ /* Initialize variables */ print_prefix(); fgets(cmd_buf, MAX_SIZE, stdin); /* Repeat? */ if ('\n' == cmd_buf[0]) /* Repeat last command */ strcpy(cmd_buf, last_cmd); else /* Just store the command */ strcpy(last_cmd, cmd_buf); /* Move the point to the command */ para = strtok(cmd_buf, split); if (!para) return CMD_ERR; /* Help */ if (!compare_cmd(para, "help")) return CMD_HELP; /* Continue */ else if (!compare_cmd(para, "c") || !compare_cmd(para, "continue")) return CMD_CONTINUE; /* Single step */ else if (!compare_cmd(para, "s") || !compare_cmd(para, "step")) return CMD_SINGLE_STEP; /* Quit */ else if (!compare_cmd(para, "q") || !compare_cmd(para, "quit")) return CMD_QUIT; /* Detach */ else if (!compare_cmd(para, "detach")) return CMD_DETACH; /* Set breakpoint */ else if (!compare_cmd(para, "b") || !compare_cmd(para, "bp") || !compare_cmd(para, "breakpoint")) { GET_ADDR(); return CMD_BREAKPOINT; /* Disassembly */ } else if (!compare_cmd(para, "disas") || !compare_cmd(para, "disass") || !compare_cmd(para, "disassembly")) { GET_ADDR(); return CMD_DISAS; /* Disassembly single instruction */ } else if (!compare_cmd(para, "ds") || !compare_cmd(para, "disas_s") || !compare_cmd(para, "disas_single") || !compare_cmd(para, "disassembly_single")) { GET_ADDR(); return CMD_DISAS_SINGLE; /* Peek memory or register */ } else if (!compare_cmd(para, "x") || !compare_cmd(para, "peek")) { char *tmp; peek_t *peek; if (*len < sizeof(peek_t)) { printf("Memory is not enough\n"); return CMD_ERR; } /* Initialize viables */ peek = (peek_t *)buf; memset(peek, 0, sizeof(peek_t)); /* Make tmp point to the first character after command */ if ('x' == *para) tmp = para + 1; else tmp = para + strlen("peek"); /* para -> "peekABCD..." * ^ * tmp ---------| */ /* para -> parameters */ para = strtok(NULL, split); if (NULL == para) { printf("Lack parameters.\n"); return CMD_ERR; } if ('/' == *tmp) { tmp++; if (isdigit(*tmp)) peek->len = strtoul(tmp, NULL, 0); tmp = para - 1; while ((*tmp != '/') && !isalpha(*tmp)) tmp--; if (*tmp != '/') peek->format = *tmp; else { printf("Incorrect format. See help.\n"); return CMD_ERR; } } else peek->format = 'x'; if ('$' == *para) { /* Rigster */ strncpy(peek->reg, para, min(sizeof(peek->reg) - 1, strlen(para))); return CMD_PEEK_REG; } else { /* Memory */ if (0 == (peek->addr = strtoul(para, NULL, 16))) { printf("Invalid address.\n"); return CMD_ERR; } return CMD_PEEK_MEM; } return CMD_ERR; /* Poke, Change the value of memory or rigester */ } else if (!compare_cmd(para, "poke") || !compare_cmd(para, "set")) { int user_cmd; poke_t *poke; if (*len < sizeof(peek_t)) { printf("Memory is not enough.\n"); return CMD_ERR; } poke = (poke_t *)buf; memset(poke, 0, sizeof(poke_t)); strcpy(split, " ="); para = strtok(NULL, split); if (!para) return CMD_ERR; if (isdigit(*para)) { /* Memory */ if (0 == (poke->addr = strtoul(para, NULL, 0))) { printf("Invalid address.\n"); return CMD_ERR; } user_cmd = CMD_POKE_MEM; } else if ('$' == *para) { /* Rigester */ strncpy(poke->reg, para, sizeof(poke->reg)-1); user_cmd = CMD_POKE_REG; } else { printf("Invalid parameters. See help.\n"); return CMD_ERR; } /* Get value */ para = strtok(NULL, split); if (!para) { printf("Lack value.\n"); return CMD_ERR; } if (0 == (poke->value = strtoul(para, NULL, 0))) { printf("Invalid value.\n"); return CMD_ERR; } return user_cmd; /* Set Shellcode */ } else if (0 == compare_cmd(para, "shellcode")) { return CMD_SET_SHELLCODE; /* Inject shellcode */ } else if (0 == compare_cmd(para, "inject")) { GET_ADDR(); return CMD_INJECT_SHELLCODE; } return CMD_UNSUPPORTED; }
int recursive_listdir( const char *path) { struct dirent *entry; DIR *dp; int files_count=0; int deep_level=path_deep_level(path); if ( strlen(path) > 1 ) ++deep_level; print_prefix(deep_level); printf("--%s Folder\n", path); dp = opendir(path); if (dp == NULL) { perror("opendir: Path does not exist or could not be read."); return -1; } while ( (entry = readdir(dp)) ){ if ( !strcmp(".", entry->d_name) ) continue; if ( !strcmp("..", entry->d_name) ) continue; int compound_path_len = strlen(path) + strlen(entry->d_name) + 2; char* compound_path = (char*)malloc( compound_path_len ); int len = strlen(path); /*construct full filename for current processing file returned by readdir*/ if ( len > 0 && path[len-1] == '/' ){ /*path already contains trailing slash*/ snprintf( compound_path, compound_path_len, "%s%s", path, entry->d_name ); } else{ /*add slash because subdirs has no that*/ snprintf( compound_path, compound_path_len, "%s/%s", path, entry->d_name ); } if ( entry->d_type != DT_DIR ){ /*do notoutput directory because it's name will output by next recursive call*/ ++files_count; print_prefix(path_deep_level(compound_path)); /*retrieve stat for to get file size, assert on error stat should not get fail for now*/ int err = lstat( compound_path, &s_temp_stat ); assert( err == 0 ); printf( "%s, size=%u, ", compound_path, (uint32_t)s_temp_stat.st_size ); switch( entry->d_type ){ case DT_REG: printf("regular file"); break; case DT_CHR: printf("character device"); break; case DT_FIFO: printf("pipe"); break; case DT_BLK: printf("block device"); break; case DT_LNK: printf("link"); break; case DT_SOCK: printf("socket"); break; default: printf( "%s, (octal)%o", "unknown", s_temp_stat.st_mode&S_IFMT ); break; } printf( "\n" ); } else if ( strcmp(path, compound_path) != 0 ){ /*for non current directory do listdir*/ files_count+=recursive_listdir(compound_path); } free(compound_path); fflush(0); } closedir(dp); return files_count; }