static void fstat_kvm(int what, int arg) { struct kinfo_proc *p, *plast; char buf[_POSIX2_LINE_MAX]; int cnt; ALLOC_OFILES(256); /* reserve space for file pointers */ /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. */ if (nlistf != NULL || memf != NULL) setgid(getgid()); if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL) errx(1, "%s", buf); setgid(getgid()); #ifdef notdef if (kvm_nlist(kd, nl) != 0) errx(1, "no namelist: %s", kvm_geterr(kd)); #endif if ((p = kvm_getprocs(kd, what, arg, &cnt)) == NULL) errx(1, "%s", kvm_geterr(kd)); print_header(); for (plast = &p[cnt]; p < plast; ++p) { if (p->ki_stat == SZOMB) continue; dofiles(p); if (mflg) dommap(p); } }
int main(int argc, char *argv[]) { PICTURE *pic,*pic2; int opdim = 4; float lowthresh = 0.05f, highthresh = 0.9f; switch (argc) { case 6: highthresh = (float)atof(argv[5]); argc--; case 5: lowthresh = (float)atof(argv[4]); argc--; case 4: opdim = atoi(argv[3]); argc--; case 3: case 2: case 1: dofiles(argc,argv); fprintf(stderr,"%s: operator side = %d\n", PROGNAME,opdim); break; default: fprintf(stderr, "usage: %s [infile] [outfile] [side] [lowthresh] [highthresh]\n", PROGNAME); exit(1); } if ((pic = readpic(FILEIN)) == NULL) { fprintf(stderr,"%s: failed to read input file\n",PROGNAME); exit(1); } if ((pic->fileid) != IMAGE_ID) { fprintf(stderr,"%s: wrong type of input file\n",PROGNAME); exit(1); } timex(); pic = grad(pic,opdim); timex(); // pic = morphgrads(pic); /* optional thinning */ pic = gradmag(pic); pic2 = ftoim(pic,lowthresh,highthresh,1); freepic(pic); /* ftoim does not free pic */ writepmpic(pic2,FILEOUT); exit(0); }
int main(int argc, char *argv[]) { PICTURE *pic; int bperc = 5, wperc = 5, sz; vmessage(); switch (argc) { case 5: wperc = atoi(argv[4]); case 4: bperc = atoi(argv[3]); case 3: case 2: dofiles(argc,argv); /* fprintf(stderr,"%s %d %d %s %s\n",PROGNAME,bperc,wperc,FILEIN,FILEOUT); */ break; default: (void)fprintf(stderr, "usage: contrast infile outfile [blackpercent][whitepercent]\n"); exit(1); } if ((pic = readpic(FILEIN)) == NULL) exit(1); if ((pic->fileid) != IMAGE_ID) { (void)fprintf(stderr,"%s: wrong type of input file\n",PROGNAME); exit(1); } sz = (pic->items)*(pic->samples); contrast(pic,bperc*sz/100,wperc*sz/100); writepmpic(pic,FILEOUT); exit(0); }
int main(int argc,char *argv[]) { if (argc != 3) { fprintf(stderr,"usage: %s filein fileout\n",argv[0]); exit(1); } dofiles(argc,argv); if ((fp = fopen(FILEIN,"rb")) == NULL ) { fprintf(stderr,"%s: wrong input file %s\n",PROGNAME,FILEIN); exit(1); } pic = newpic(); while (1) { printf("k keeps the existing header\n"); printf("d deletes the header (translates into raw data format)\n"); printf("p prepends new header (translates from raw data format)\n"); printf("c changes to new header (d+p)\t>"); answer = getchar(); getchar(); printf("%c it is!\n\n",answer); if ((answer == 'd') || (answer == 'k') || (answer == 'c')) { if (readhead(pic,fp) == -1) exit(1); break; } if (answer == 'p') { /* request new header - no header to be read anymore */ printf("Fileid int, as defined in vis.h (0 for unsigned char image): "); scanf("%d",&(pic->fileid)); printf("New image width (x pixels): "); scanf("%d",&(pic->x)); printf("New image height (y pixels): "); scanf("%d",&(pic->y)); printf("Window x origin (float): "); scanf("%f",&(pic->xorigin)); printf("Window y origin (float): "); scanf("%f",&(pic->yorigin)); printf("Number of items (0 for x*y): "); scanf("%d",&(pic->items)); if (pic->items == 0) pic->items = (pic->x)*(pic->y); printf("Number of samples for each item: "); scanf("%d",&(pic->samples)); printf("New image history: "); scanf("%[^\n]",pic->history); getchar(); pic->magic = VIS_MAGIC; break; } printf("Unexpected response, please try again\n"); } while (1) { printf("d for diagonal reflection (rows into columns)\n"); printf("r rotate 90 deg anti-clockwise (diagonal & horizontal reflections)\n"); printf("n for no reflection or endian byte swapping: "); reverse = getchar(); getchar(); printf("%c it is!\n\n",reverse); if ((reverse=='d') || (reverse=='r') || (reverse=='n')) break; printf("Unexpected response - please try again or control-C\n"); } while (1) { printf("v for Libor Spacek's LVL format output\n"); printf("p for Jef Poskanzer's PGM or PPM output \t>"); wout = getchar(); getchar(); printf("%c it is!\n",wout); if (wout == 'v') break; if (wout == 'p') break; (void) printf("Unexpected response - please try again or control-C\n"); } /* no more user input the desired header must be known by now and be in *pic */ if ((reverse == 'd')||(reverse == 'r')) /* swap rows and columns */ { newdata(pic); chbufin = (unsigned char *)pic->data; swapping = pic->y; pic->y = pic->x; pic->x = swapping; sz = (pic->samples)*sizeofidtype(pic->fileid); for (count=0;count<pic->x;count++) if (reverse == 'r') for (county=(pic->y)-1;county>=0;county--) fread(&(chbufin[sz*(county*(pic->x)+count)]),sz,1,fp); else for (county=0;county<pic->y;county++) fread(&(chbufin[sz*(county*pic->x+count)]),sz,1,fp); } else readdata(pic,fp); fclose(fp); if (answer != 'd') switch (wout) { case 'v': writepic(pic,FILEOUT); break; case 'p': writepmpic(pic,FILEOUT); break; default: exit(1); } else { if ((fp = fopen(FILEOUT,"wb")) == NULL ) { fprintf(stderr,"%s: wrong output file %s\n",PROGNAME,FILEOUT); exit(1); } if (fwrite(pic->data,sizeofdata(pic),1,fp) == 0) { fprintf(stderr,"%s: failed to write data\n",PROGNAME); exit(1); } } exit(0); }
int main(int argc, char **argv) { struct passwd *passwd; struct kinfo_proc *p, *plast; struct proc proc; int arg, ch, what; char *memf, *nlistf; char buf[_POSIX2_LINE_MAX]; int cnt; arg = 0; what = KERN_PROC_ALL; nlistf = memf = NULL; while ((ch = getopt(argc, argv, "fmnp:u:vwN:M:")) != -1) switch((char)ch) { case 'f': fsflg = 1; break; case 'M': memf = optarg; break; case 'N': nlistf = optarg; break; case 'm': mflg = 1; break; case 'n': nflg = 1; break; case 'p': if (pflg++) usage(); if (!isdigit(*optarg)) { warnx("-p requires a process id"); usage(); } what = KERN_PROC_PID; arg = atoi(optarg); break; case 'u': if (uflg++) usage(); if (!(passwd = getpwnam(optarg))) errx(1, "%s: unknown uid", optarg); what = KERN_PROC_UID; arg = passwd->pw_uid; break; case 'v': vflg = 1; break; case 'w': wflg_mnt = 40; wflg_cmd = 16; break; case '?': default: usage(); } if (*(argv += optind)) { for (; *argv; ++argv) { if (getfname(*argv)) checkfile = 1; } if (!checkfile) /* file(s) specified, but none accessable */ exit(1); } ALLOC_OFILES(256); /* reserve space for file pointers */ if (fsflg && !checkfile) { /* -f with no files means use wd */ if (getfname(".") == 0) exit(1); checkfile = 1; } /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. */ if (nlistf != NULL || memf != NULL) setgid(getgid()); if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL) errx(1, "%s", buf); #ifdef notdef if (kvm_nlist(kd, nl) != 0) errx(1, "no namelist: %s", kvm_geterr(kd)); #endif if ((p = kvm_getprocs(kd, what, arg, &cnt)) == NULL) errx(1, "%s", kvm_geterr(kd)); if (nflg) printf("USER %-*.*s %*.*s FD DEV %*.*s MODE SZ|DV R/W", wflg_cmd, wflg_cmd, "CMD", pid_width, pid_width, "PID", ino_width, ino_width, "INUM"); else printf("USER %-*.*s %*.*s FD %-*.*s %*.*s MODE SZ|DV R/W", wflg_cmd, wflg_cmd, "CMD", pid_width, pid_width, "PID", wflg_mnt, wflg_mnt, "PATH", ino_width, ino_width, "INUM"); if (checkfile && fsflg == 0) printf(" NAME\n"); else putchar('\n'); for (plast = &p[cnt]; p < plast; ++p) { if (p->kp_stat == SZOMB) continue; if (!kread((void *)p->kp_paddr, &proc, sizeof(proc))) { dprintf(stderr, "can't read proc at %p for pid %d\n", (void *)p->kp_paddr, Pid); continue; } dofiles(p, &proc); if (mflg) dommap(&proc); } exit(0); }
int main(int argc, char *argv[]) { extern char *optarg; extern int optind; struct passwd *passwd; struct kinfo_proc2 *p, *plast; int arg, ch, what; char *memf, *nlistf; char buf[_POSIX2_LINE_MAX]; int cnt; arg = 0; what = KERN_PROC_ALL; nlistf = memf = NULL; oflg = 0; while ((ch = getopt(argc, argv, "fnop:u:vN:M:")) != -1) switch((char)ch) { case 'f': fsflg = 1; break; case 'M': memf = optarg; break; case 'N': nlistf = optarg; break; case 'n': nflg = 1; break; case 'o': oflg = 1; break; case 'p': if (pflg++) usage(); if (!isdigit(*optarg)) { warnx( "-p requires a process id"); usage(); } what = KERN_PROC_PID; arg = atoi(optarg); break; case 'u': if (uflg++) usage(); if (!(passwd = getpwnam(optarg))) errx(1, "%s: unknown uid", optarg); what = KERN_PROC_UID; arg = passwd->pw_uid; break; case 'v': vflg = 1; break; default: usage(); } /* * Discard setgid privileges if not the running kernel so that bad * guys can't print interesting stuff from kernel memory. */ if (nlistf != NULL || memf != NULL) { setegid(getgid()); setgid(getgid()); } if ((kd = kvm_openfiles(nlistf, memf, NULL, O_RDONLY, buf)) == NULL) errx(1, "%s", buf); setegid(getgid()); setgid(getgid()); if (*(argv += optind)) { for (; *argv; ++argv) { if (getfname(*argv)) checkfile = 1; } if (!checkfile) /* file(s) specified, but none accessible */ exit(1); } ALLOC_OFILES(256); /* reserve space for file pointers */ if (fsflg && !checkfile) { /* -f with no files means use wd */ if (getfname(".") == 0) exit(1); checkfile = 1; } if ((p = kvm_getproc2(kd, what, arg, sizeof(*p), &cnt)) == NULL) errx(1, "%s", kvm_geterr(kd)); if (nflg) printf("%s", "USER CMD PID FD DEV INUM MODE R/W DV|SZ"); else printf("%s", "USER CMD PID FD MOUNT INUM MODE R/W DV|SZ"); if (oflg) printf("%s", ":OFFSET "); if (checkfile && fsflg == 0) printf(" NAME\n"); else putchar('\n'); for (plast = &p[cnt]; p < plast; ++p) { if (p->p_stat == SZOMB) continue; dofiles(p); } exit(0); }