static void reshape(int w, int h) { if (cmdopts.verbose) { jas_eprintf("reshape(%d, %d)\n", w, h); dumpstate(); } if (pixmap_resize(&gs.vp, w, h)) { cleanupandexit(EXIT_FAILURE); } pixmap_clear(&gs.vp); glViewport(0, 0, w, h); glMatrixMode(GL_PROJECTION); glLoadIdentity(); glOrtho( 0, w, 0, h, 0.f, 1.f ); glMatrixMode(GL_MODELVIEW); glLoadIdentity(); glTranslatef(0, 0, 0); glRasterPos2i(0, 0); if (gs.vp.width > jas_image_width(gs.image) / gs.sx) { gs.vcx = (jas_image_tlx(gs.image) + jas_image_brx(gs.image)) / 2.0; } if (gs.vp.height > jas_image_height(gs.image) / gs.sy) { gs.vcy = (jas_image_tly(gs.image) + jas_image_bry(gs.image)) / 2.0; } gs.dirty = 1; }
static void dumpnfa(labellist *ll, nfa *nf) { int i; printf("NFA '%s' has %d states; start %d, finish %d\n", nf->nf_name, nf->nf_nstates, nf->nf_start, nf->nf_finish); for (i = 0; i < nf->nf_nstates; i++) dumpstate(ll, nf, i); }
static void display() { float vtlx; float vtly; if (cmdopts.verbose) { jas_eprintf("display()\n"); dumpstate(); } if (!gs.dirty) { glClear(GL_COLOR_BUFFER_BIT); glDrawPixels(gs.vp.width, gs.vp.height, GL_RGBA, GL_UNSIGNED_SHORT, gs.vp.data); glFlush(); return; } glClear(GL_COLOR_BUFFER_BIT); pixmap_clear(&gs.vp); glDrawPixels(gs.vp.width, gs.vp.height, GL_RGBA, GL_UNSIGNED_SHORT, gs.vp.data); glFlush(); vtlx = gs.vcx - 0.5 * gs.sx * gs.vp.width; vtly = gs.vcy - 0.5 * gs.sy * gs.vp.height; if (cmdopts.verbose) { jas_eprintf("vtlx=%f, vtly=%f, vsx=%f, vsy=%f\n", vtlx, vtly, gs.sx, gs.sy); } if (gs.monomode) { if (cmdopts.verbose) { jas_eprintf("component %d\n", gs.cmptno); } jas_image_render2(gs.image, gs.cmptno, vtlx, vtly, gs.sx, gs.sy, gs.vp.width, gs.vp.height, gs.vp.data); } else { if (cmdopts.verbose) { jas_eprintf("color\n"); } jas_image_render(gs.altimage, vtlx, vtly, gs.sx, gs.sy, gs.vp.width, gs.vp.height, gs.vp.data); } glClear(GL_COLOR_BUFFER_BIT); glDrawPixels(gs.vp.width, gs.vp.height, GL_RGBA, GL_UNSIGNED_SHORT, gs.vp.data); glFlush(); gs.dirty = 0; }
int main(int argc, char *argv[]) { struct sigaction sigact; int do_add_date = 0; int do_compress = 0; int do_vibrate = 1; char* use_outfile = 0; char* begin_sound = 0; char* end_sound = 0; int use_socket = 0; int do_fb = 0; if (getuid() != 0) { // Old versions of the adb client would call the // dumpstate command directly. Newer clients // call /system/bin/bugreport instead. If we detect // we're being called incorrectly, then exec the // correct program. return execl("/system/bin/bugreport", "/system/bin/bugreport", NULL); } ALOGI("begin\n"); memset(&sigact, 0, sizeof(sigact)); sigact.sa_handler = sigpipe_handler; sigaction(SIGPIPE, &sigact, NULL); /* set as high priority, and protect from OOM killer */ setpriority(PRIO_PROCESS, 0, -20); FILE *oom_adj = fopen("/proc/self/oom_adj", "w"); if (oom_adj) { fputs("-17", oom_adj); fclose(oom_adj); } /* very first thing, collect stack traces from Dalvik and native processes (needs root) */ dump_traces_path = dump_traces(); int c; while ((c = getopt(argc, argv, "b:de:ho:svqzp")) != -1) { switch (c) { case 'b': begin_sound = optarg; break; case 'd': do_add_date = 1; break; case 'e': end_sound = optarg; break; case 'o': use_outfile = optarg; break; case 's': use_socket = 1; break; case 'v': break; // compatibility no-op case 'q': do_vibrate = 0; break; case 'z': do_compress = 6; break; case 'p': do_fb = 1; break; case '?': printf("\n"); case 'h': usage(); exit(1); } } FILE *vibrator = 0; if (do_vibrate) { /* open the vibrator before dropping root */ vibrator = fopen("/sys/class/timed_output/vibrator/enable", "w"); if (vibrator) fcntl(fileno(vibrator), F_SETFD, FD_CLOEXEC); } /* read /proc/cmdline before dropping root */ FILE *cmdline = fopen("/proc/cmdline", "r"); if (cmdline != NULL) { fgets(cmdline_buf, sizeof(cmdline_buf), cmdline); fclose(cmdline); } if (prctl(PR_SET_KEEPCAPS, 1) < 0) { ALOGE("prctl(PR_SET_KEEPCAPS) failed: %s\n", strerror(errno)); return -1; } /* switch to non-root user and group */ gid_t groups[] = { AID_LOG, AID_SDCARD_R, AID_SDCARD_RW, AID_MOUNT, AID_INET, AID_NET_BW_STATS }; if (setgroups(sizeof(groups)/sizeof(groups[0]), groups) != 0) { ALOGE("Unable to setgroups, aborting: %s\n", strerror(errno)); return -1; } if (setgid(AID_SHELL) != 0) { ALOGE("Unable to setgid, aborting: %s\n", strerror(errno)); return -1; } if (setuid(AID_SHELL) != 0) { ALOGE("Unable to setuid, aborting: %s\n", strerror(errno)); return -1; } struct __user_cap_header_struct capheader; struct __user_cap_data_struct capdata[2]; memset(&capheader, 0, sizeof(capheader)); memset(&capdata, 0, sizeof(capdata)); capheader.version = _LINUX_CAPABILITY_VERSION_3; capheader.pid = 0; capdata[CAP_TO_INDEX(CAP_SYSLOG)].permitted = CAP_TO_MASK(CAP_SYSLOG); capdata[CAP_TO_INDEX(CAP_SYSLOG)].effective = CAP_TO_MASK(CAP_SYSLOG); capdata[0].inheritable = 0; capdata[1].inheritable = 0; if (capset(&capheader, &capdata[0]) < 0) { ALOGE("capset failed: %s\n", strerror(errno)); return -1; } char path[PATH_MAX], tmp_path[PATH_MAX]; pid_t gzip_pid = -1; if (use_socket) { redirect_to_socket(stdout, "dumpstate"); } else if (use_outfile) { strlcpy(path, use_outfile, sizeof(path)); if (do_add_date) { char date[80]; time_t now = time(NULL); strftime(date, sizeof(date), "-%Y-%m-%d-%H-%M-%S", localtime(&now)); strlcat(path, date, sizeof(path)); } if (do_fb) { strlcpy(screenshot_path, path, sizeof(screenshot_path)); strlcat(screenshot_path, ".png", sizeof(screenshot_path)); } strlcat(path, ".txt", sizeof(path)); if (do_compress) strlcat(path, ".gz", sizeof(path)); strlcpy(tmp_path, path, sizeof(tmp_path)); strlcat(tmp_path, ".tmp", sizeof(tmp_path)); gzip_pid = redirect_to_file(stdout, tmp_path, do_compress); } if (begin_sound) { play_sound(begin_sound); } else if (vibrator) { fputs("150", vibrator); fflush(vibrator); } dumpstate(); if (end_sound) { play_sound(end_sound); } else if (vibrator) { int i; for (i = 0; i < 3; i++) { fputs("75\n", vibrator); fflush(vibrator); usleep((75 + 50) * 1000); } fclose(vibrator); } /* wait for gzip to finish, otherwise it might get killed when we exit */ if (gzip_pid > 0) { fclose(stdout); waitpid(gzip_pid, NULL, 0); } /* rename the (now complete) .tmp file to its final location */ if (use_outfile && rename(tmp_path, path)) { fprintf(stderr, "rename(%s, %s): %s\n", tmp_path, path, strerror(errno)); } ALOGI("done\n"); return 0; }
bool f18a_debug(f18a *f18a) { static char buf[BUFSIZ]; f18a_msg("entering emulator debugger: enter 'h' for help.\n"); dumpheader(); dumpstate(f18a); for (;;) { f18a_msg(" * "); if (!f18a_getstr(buf, BUFSIZ)) return false; char *delim = " \t\n"; char *tok = strtok(buf, delim); if (!tok) continue; if (matches(tok, "h", "help") || matches(tok, "?", "?")) { f18a_msg( " help, ?: show this message\n" " continue: resume running\n" " step [n]: execute a single instruction (or n instructions)\n" " dump: display the state of the cpu\n" " print addr [len]: display memory contents in hex\n" " (addr is hex, len decimal)\n" " exit, quit: exit emulator\n" "unambiguous abbreviations are recognized " "(e.g., s for step or con for continue).\n" ); } else if (matches(tok, "con", "continue")) { return true; } else if (matches(tok, "s", "step")) { uint32_t steps = 1; tok = strtok(NULL, delim); if (tok) { char *endptr; steps = strtoul(tok, &endptr, 10); if (*endptr) { f18a_msg("argument to 'step' must be a decimal number\n"); continue; } } for (uint32_t i = 0; i < steps; i++) { f18a_runterm(); f18a_step(f18a); f18a_dbgterm(); dumpstate(f18a); } } else if (matches(tok, "d", "dump")) { dumpheader(); dumpstate(f18a); } else if (matches(tok, "p", "print")) { tok = strtok(NULL, delim); if (!tok) { f18a_msg("print requires an argument\n"); continue; } char *endptr; u32 addr = strtoul(tok, &endptr, 16); if (*endptr) { f18a_msg("addr argument to 'print' must be a hex number: %s\n", endptr); continue; } u16 length = 1; tok = strtok(NULL, delim); if (tok) { length = strtoul(tok, &endptr, 10); if (*endptr) { f18a_msg("len argument to 'print' must be a decimal number\n"); continue; } } dumpram(f18a, addr, length); } else if (matches(tok, "e", "exit") || matches(tok, "q", "quit")) { return false; } else { f18a_msg("unrecognized or ambiguous command: %s\n", tok); } } }
int main( int argc, char *argv[] ) /* ------------------------------------------------------------------------ ** * Program main line. * * Input: argc - You know what this is. * argv - You know what to do. * * Output: EXIT_SUCCESS. * * ------------------------------------------------------------------------ ** */ { char s[1024]; if( argc != 3 ) Usage( argv[0] ); /* Initialize the cache header. */ (void)ubi_cacheInit( CachePtr, compfunc, freefunc, atoi( argv[1] ), atoi( argv[2] ) ); (void)fprintf( stderr, "Cache opened with MaxEntries: %ld MaxMemory: %ld\n", ubi_cacheGetMaxEntries( CachePtr ), ubi_cacheGetMaxMemory( CachePtr ) ); /* Load the cache. */ while( gets( s ) && strlen(s) ) { int i; char *p; RecPtr rp; rp = (RecPtr)malloc( sizeof( Rec ) ); /* parse the input. */ p = strrchr( s, '/' ); if( !p ) rp->key = strdup( "" ); else { rp->key = strdup( ++p ); *p = '\0'; } rp->content = strdup( s ); /* Add up size of the record plus string lengths plus nul bytes. */ i = sizeof( Rec ) + strlen( rp->key ) + strlen( rp->content ) + 2; (void)ubi_cachePut( CachePtr, i, (ubi_cacheEntryPtr)rp, rp->key ); } /* Report on stuff. */ (void)fputs( "Full cache:\n", stderr ); dumpstate( NULL ); /* Pseudo-randomly prune the cache. */ (void)fputs( "\nRemoving semi-random entries:\n", stderr ); prunecache(); dumpstate( NULL ); /* Trim the cache to a maximum of 500 entries. */ (void)fputs( "\nRestricting cache size to 500 entries:\n", stderr ); (void)ubi_cacheSetMaxEntries( CachePtr, 500 ); dumpstate( NULL ); /* Trim the cache to a maximum of 32K bytes. */ (void)fputs( "\nRestricting cache size to 32K bytes:\n", stderr ); (void)ubi_cacheSetMaxMemory( CachePtr, 32768 ); dumpstate( NULL ); /* Dump the cache. */ (void)puts( "\nCacheDump:" ); dumpcache(); /* Clear the cache and exit. */ ubi_cacheClear( CachePtr ); return( EXIT_SUCCESS ); } /* main */
int main(int argc, char **argv) { int ch, mode, disp, accessmode; struct kvmvars kvmvars; const char *systemname; char *kmemf; if (seteuid(getuid()) != 0) { err(1, "seteuid failed\n"); } kmemf = NULL; systemname = NULL; while ((ch = getopt(argc, argv, "M:N:Bbhpr")) != -1) { switch((char)ch) { case 'M': kmemf = optarg; kflag = 1; break; case 'N': systemname = optarg; break; case 'B': Bflag = 1; break; case 'b': bflag = 1; break; case 'h': hflag = 1; break; case 'p': pflag = 1; break; case 'r': rflag = 1; break; default: usage(); } } argc -= optind; argv += optind; #define BACKWARD_COMPATIBILITY #ifdef BACKWARD_COMPATIBILITY if (*argv) { systemname = *argv; if (*++argv) { kmemf = *argv; ++kflag; } } #endif if (systemname == NULL) systemname = getbootfile(); accessmode = openfiles(systemname, kmemf, &kvmvars); mode = getprof(&kvmvars); if (hflag) disp = GMON_PROF_OFF; else if (Bflag) disp = GMON_PROF_HIRES; else if (bflag) disp = GMON_PROF_ON; else disp = mode; if (pflag) dumpstate(&kvmvars); if (rflag) reset(&kvmvars); if (accessmode == O_RDWR) setprof(&kvmvars, disp); (void)fprintf(stdout, "kgmon: kernel profiling is %s.\n", disp == GMON_PROF_OFF ? "off" : disp == GMON_PROF_HIRES ? "running (high resolution)" : disp == GMON_PROF_ON ? "running" : disp == GMON_PROF_BUSY ? "busy" : disp == GMON_PROF_ERROR ? "off (error)" : "in an unknown state"); return (0); }
int main(int argc, char *argv[]) { int dumpcrash = check_command_name(argv[0], "dumpcrash"); int bugreport = check_command_name(argv[0], "bugreport"); int add_date = 0; char* outfile = 0; int vibrate = 0; int compress = 0; int c, fd, vibrate_fd, fds[2]; char path[PATH_MAX]; pid_t pid; /* set as high priority, and protect from OOM killer */ setpriority(PRIO_PROCESS, 0, -20); protect_from_oom_killer(); get_time(&now); if (bugreport) { do { c = getopt(argc, argv, "do:vz"); if (c == EOF) break; switch (c) { case 'd': add_date = 1; break; case 'o': outfile = optarg; break; case 'v': vibrate = 1; break; case 'z': compress = 1; break; case '?': fprintf(stderr, "%s: invalid option -%c\n", argv[0], optopt); exit(1); } } while (1); } /* open vibrator before switching user */ if (vibrate) { vibrate_fd = open("/sys/class/timed_output/vibrator/enable", O_WRONLY); if (vibrate_fd > 0) fcntl(vibrate_fd, F_SETFD, FD_CLOEXEC); } else vibrate_fd = -1; /* switch to non-root user and group */ setgid(AID_LOG); setuid(AID_SHELL); /* make it safe to use both printf and STDOUT_FILENO */ setvbuf(stdout, 0, _IONBF, 0); if (outfile) { if (strlen(outfile) > sizeof(path) - 100) exit(1); strcpy(path, outfile); if (add_date) { char date[260]; strftime(date, sizeof(date), "-%Y-%m-%d-%H-%M-%S", &now); strcat(path, date); } if (compress) strcat(path, ".gz"); else strcat(path, ".txt"); /* ensure that all directories in the path exist */ create_directories(path); fd = open(path, O_WRONLY | O_CREAT | O_TRUNC, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH); if (fd < 0) return fd; if (compress) { pipe(fds); /* redirect our stdout to the pipe */ dup2(fds[1], STDOUT_FILENO); close(fds[1]); if ((pid = fork()) < 0) { fprintf(stderr, "fork error\n"); exit(1); } if (pid) { /* parent case */ /* close our copy of the input to gzip */ close(fds[0]); /* close our copy of the output file */ close(fd); } else { /* child case */ /* redirect our input pipe to stdin */ dup2(fds[0], STDIN_FILENO); close(fds[0]); /* redirect stdout to the output file */ dup2(fd, STDOUT_FILENO); close(fd); /* run gzip to postprocess our output */ execv("/system/bin/gzip", gzip_args); fprintf(stderr, "execv returned\n"); } } else { /* redirect stdout to the output file */ dup2(fd, STDOUT_FILENO); close(fd); } } /* else everything will print to stdout */ if (vibrate) { vibrate_pattern(vibrate_fd, start_pattern); } dumpstate(!dumpcrash); if (vibrate) { vibrate_pattern(vibrate_fd, end_pattern); close(vibrate_fd); } /* so gzip will terminate */ close(STDOUT_FILENO); return 0; }
//main function for web services int main(void) { long n; char strPage[1023]; char strFooters[1023]; char strHeaders[1023]; char strPopup[1023]; char str[1024]; char command[1024] = "echo Welcome to EurekaRom"; char decodedCommand[1024]; char *data; char *token; char *headers; char *page = NULL; const char *key, *value; char *postBuffer = NULL; int postRead; unsigned int postLen; char postData[4096]; char * queryString; char query_action[1024]; char query_section[1024]; char query_field[1024]; char query_value[1024]; data = malloc(QS_LEN); token = malloc(QS_LEN); key = malloc(QS_LEN); value = malloc(QS_LEN); //Operations if POST detected if(compStr(getenv("REQUEST_METHOD"), "POST", sizearray(getenv("REQUEST_METHOD")))) { if (getenv("QUERY_STRING")) { token = strtok (getenv("QUERY_STRING"),"&"); while (token != NULL) { sscanf(token, "%[^=]=%65536s", key, value); if ( compStr(key, "page", sizearray(key) )) { strcpy(strPage, value); } token = strtok (NULL, "&"); } } postRead = getline(&postBuffer, &postLen, stdin); if (-1 != postRead) { strcpy(postData, postBuffer); } if (compStr(strPage, "debug", sizearray(strPage) )) { sscanf(postData, "page=debug&command=%[^,]", command); urldecode2(decodedCommand, command); web_module_headers(strPage); web_module_debug(decodedCommand); web_module_footer(); } if (compStr(strPage, "settings", sizearray(strPage) )) { processPostData(postData); web_module_headers(strPage); web_module_settings(); web_module_footer(); } free(postBuffer); } else { if (!getenv("QUERY_STRING")) { //no query string web_module_headers("home"); web_module_home(); } if (getenv("QUERY_STRING")) { //parse Query_STRING for page //query string present token = strtok (getenv("QUERY_STRING"),"&"); while (token != NULL) { sscanf(token, "%[^=]=%65536s", key, value); if ( compStr(key, "page", sizearray(key) )) { strcpy(strPage, value); } if ( compStr(key, "headers", sizearray(key) )) { strcpy(strHeaders, value); } if ( compStr(key, "footers", sizearray(key) )) { strcpy(strFooters, value); } if ( compStr(key, "popup", sizearray(key) )) { strcpy(strPopup, value); } token = strtok (NULL, "&"); } // Call this before headers if ( compStr(strPage, "dumpstate", sizearray(strPage) )) { dumpstate(); exit(0); } //check for which page to load if ( compStr(strHeaders, "0", sizearray(strHeaders) )) { } else { web_module_headers(strPage); } if ( compStr(strPopup, "1", sizearray(strHeaders) )) { web_module_popup_headers(strPage); } if ( compStr(strPage, "home", sizearray(strPage) )) { web_module_home(); } if ( compStr(strPage, "logcat", sizearray(strPage) )) { web_module_logcat(); } if ( compStr(strPage, "forceeurekaupdate", sizearray(strPage) )) { forceeurekaupdate(); } if ( compStr(strPage, "debug", sizearray(strPage) )) { web_module_debug(command); } if ( compStr(strPage, "settings", sizearray(strPage) )) { web_module_settings(); } if ( compStr(strPage, "status", sizearray(strPage) )) { web_module_status(); } if ( compStr(strPage, "companion", sizearray(strPage) )) { web_module_companion(); } if ( compStr(strPage, "aboutus", sizearray(strPage) )) { web_module_aboutus(); } if ( compStr(strPage, "Reboot", sizearray(strPage) )) { reboot(); } if ( compStr(strPage, "sysupdate", sizearray(strPage) )) { sysupdate(); } if ( compStr(strPage, "factorydatareset", sizearray(strPage) )) { factorydatareset(); } if ( compStr(strFooters, "0", sizearray(strFooters) )) { } else { web_module_footer(); } } } }