std::string ArgParse::usage() const { std::stringstream ss; ss << m_description << std::endl << std::endl; bool oprionals = thereAreOptionalArgs(); bool required = thereAreRequiredArgs(); ss << "usage: " << m_programName << (required ? " <ARGS>" : "") << (oprionals ? " [OPTIONS]" : "") << std::endl; if ( required ) { ss << std::endl << "Required arguments:" << std::endl; ss << printArgs(REQUIRED); } if ( oprionals ) { ss << std::endl << "Options:" << std::endl; ss << printArgs(OPTIONAL); } ss << std::endl; ss << m_epilog; return ss.str();; }
void FZ_(syscall_open)(ThreadId tid, UWord *args, UInt nArgs, SysRes res) { if(fengSysFlag){VG_(printf)("feng:entered syscall_open\n");} printArgs(args,nArgs,"open"); Char fdpath[MAX_PATH]={0}; Int fd = sr_Res(res); // Nothing to do if no file tainting // But, if stdin tainting, always taint fd 0... if (!FZ_(clo_taint_file)/* && (fd != 0 || !FL_(clo_taint_stdin))*/) { return; } //populate_guest_args(tid); if (!sr_isError(res) && fd < MAXIMUM_FDS) { resolve_fd(fd, fdpath, MAX_PATH-1); tainted_fds[tid][sr_Res(res)] = (VG_(strncmp)(fdpath, FZ_(clo_file_filter), VG_(strlen)(FZ_(clo_file_filter))) == 0); VG_(printf)("[?] tid %d open(%d) fdpath=%s clo_file_filter=%s\n", tid, fd, fdpath, FZ_(clo_file_filter)); if (tainted_fds[tid][sr_Res(res)]) { VG_(printf)("[+] tid %d open(%d)\n", tid, fd); position_fds[tid][sr_Res(res)] = 0; } /*if (tainted_fds[tid][sr_Res(res)]) { VG_(printf)("tainting file %d\n", sr_Res(res)); } else { VG_(printf)("not tainting file %d\n", sr_Res(res)); }*/ } }
/* solve the problem */ int main (int argc, char *argv[]) { int p, q, l, r, loop, result; int **schedules; if (debug_on) printf("\nP7 - Chat Online:\n"); schedules = readArgs(&p, &q, &l, &r, argc, argv); if (debug_on) printArgs(p,q,l,r,schedules); if (p<1 || p>50 || q<1 || q>50 || l<0 || l>1000 || r<0 || r>1000) { printf("Invalid schedules. Aborting...\n"); printf("\n--------------------\n"); return 1; } if (debug_on) printf("\nProblem Solution:\n"); result = 0; for (loop=l; loop<=r; loop++) { if (momentSuits(loop,p,q,schedules) == true) result++; } printf("%d", result); if (debug_on) printf("\n--------------------\n"); return 0; }
bool test(char* argv[]) { // Forks our process and stores its ID into a variable "child id" printLine(20); struct stat fileStat; cout << "[DEBUG] Statting "; printArgs(argv); cout << "!" << endl; if (argv[1][0] == '-') { // If this is a flag cout << "[DEBUG] Flag detected!" << endl; if (stat(argv[2], &fileStat) == 0) { if (argv[1][1] == 'e') return true; else if (argv[1][1] == 'f') return S_ISREG(fileStat.st_mode); else if (argv[1][1] == 'd') return S_ISDIR(fileStat.st_mode); else { cout << "test failed: invalid flag passed in\n"; return false; } } else return false; } cout << "[DEBUG] No flag detected." << endl; printLine(20); return (stat(argv[1], &fileStat) == 0); }
void FZ_(syscall_write)(ThreadId tid, UWord *args, UInt nArgs, SysRes res) { if(fengSysFlag){VG_(printf)("feng:entered syscall_write\n");} printArgs(args,nArgs,"write"); UInt i, k; Int fd = -1; Char *data = NULL; //populate_guest_args(tid); fd = ((Int)args[0])/*guest_args[tid].args[3]*/; data = (Char *)(args[1]/*guest_args[tid].args[1]*/); if (fd < 0 || sr_isError(res)) { return; } k = position_fds[tid][fd]; for (i = 0; i < sr_Res(res); i++) { #ifdef FENG_AMD64 char * cons = depend_on_addr((Addr)(ULong)(data + i), 8); VG_(printf)("[+] tid %d write(%d) tainted byte %d (0x%08x) %s\n", tid, fd, k + i, (Addr)(ULong)(data + i), cons); #else char * cons = depend_on_addr((Addr)(UInt)(data + i), 8); VG_(printf)("[+] tid %d write(%d) tainted byte %d (0x%08x) %s\n", tid, fd, k + i, (Addr)(UInt)(data + i), cons); #endif // FENG_AMD64 } }
/* a tester */ int main(int argc, char **argv) { int n=0; char infile[9]="infile value"; char outfile[256]="outfile value"; float fl=-1.0; double dbl = -1.0; int flag = 0; //Add arguments addArg("infile", 'i', 1, 's', infile, sizeof(infile), "input file name"); addArg("outfile", 'o', 1, 's', outfile, sizeof(infile), "output file name"); addArg("nSPUs", 'n', 1, 'i', &n, 0, "number of SPUs"); addArg("floater", 0, 1, 'f', &fl, 0, "floating number"); addArg("doubler", 'k', 1, 'd', &dbl, 0, "double number"); addArg("justFlag",'F', 0, 0, &flag, 0, "just a flag"); // print the argument help printArgs(); // process (and free) arguments processArgs(argc,argv); // print the variables in the code printf("Got n = %d\n",n); printf("Got fl = %f\n",fl); printf("Got dbl = %lf\n",dbl); printf("Got flag = %d\n",flag); printf("Got infile = %s\n",infile); printf("Got outfile = %s\n",outfile); printf("\n\n"); return 0; }
int main(int argc, char* argv[]) { const char* arg = argc >= 2 ? argv[1] : NULL; if (argc >= 3) { gPPDFile = argv[2]; } if (enabled("scanner", arg)) { TestScanner(); } if (enabled("parser", arg)) { TestParser(); } if (enabled("ppd", arg)) { TestPPDParser(true); } if (enabled("header", arg)) { TestPPDParser(false); } if (enabled("ui", arg)) { TestExtractUI(); } if (enabled("ppd-timing", arg)) { TestPPDParser(true, false); } if (enabled("header-timing", arg)) { TestPPDParser(false, false); } if (arg == NULL) { printArgs(argv[0]); } }
/* solve the problem */ int main (int argc, char *argv[]) { int n; long wallsToPaint; char labyrinth[MAX_SIZE][MAX_SIZE]; int wasProcessed[MAX_SIZE][MAX_SIZE]; #ifdef debug_on printf("\nP12 - Labyrinth:\n"); #endif n = readArgs(labyrinth, argc, argv); #ifdef debug_on printArgs(n,labyrinth); printf("\nProblem Solution:\n"); #endif /* Solution */ wallsToPaint = process(0,0,n,labyrinth,wasProcessed); if (wasProcessed[n-1][n-1] == 0) wallsToPaint += process(n-1,n-1,n,labyrinth,wasProcessed); printf("%ld\n", 3*3*wallsToPaint); #ifdef debug_on printf("\n--------------------\n"); #endif return 0; }
void FZ_(syscall_munmap)(ThreadId tid, UWord *args, UInt nArgs, SysRes res) { if(fengSysFlag){VG_(printf)("feng:entered syscall_munmap\n");} printArgs(args,nArgs,"munmap"); UInt i, start, length; //populate_guest_args(tid); length = ((UInt)args[1])/*guest_args[tid].args[1]*/; start = ((UInt)args[0])/*guest_args[tid].args[2]*/; //VG_(printf)("[+] munmap(0x%08x, 0x%x)\n", start, length); if (sr_isError(res)) { return; } for (i = 0; i < depaddr8.count; i++) { paddr=getDep(&depaddr8,i); if (paddr->value.addr == start) { break; } } if (i == depaddr8.count) { return; } for (i = 0; i < length; i++) { del_dependency_addr(start + i, 8); } }
void FZ_(syscall_lseek)(ThreadId tid, UWord *args, UInt nArgs, SysRes res) { if(fengSysFlag){VG_(printf)("feng:entered syscall_lseek\n");} printArgs(args,nArgs,"lseek"); Int fd; //populate_guest_args(tid); fd = ((Int)args[0])/*guest_args[tid].args[3]*/; if (fd < 0 || sr_isError(res) || !tainted_fds[tid][fd]) { return; } position_fds[tid][fd] = sr_Res(res); //// Nothing to do if no file tainting //// But, if stdin tainting, always taint fd 0... /* //if (!FZ_(clo_taint_file)/* && (fd != 0 || !FL_(clo_taint_stdin))*/) { // return; //} //if (fd > -1 && fd < MAXIMUM_FDS) { // resolve_fd(fd, fdpath, MAX_PATH-1); // tainted_fds[tid][res.res] = (VG_(strncmp)(fdpath, FZ_(clo_file_filter), VG_(strlen)(FZ_(clo_file_filter))) == 0); // if (tainted_fds[tid][res.res]) { // position_fds[tid][res.res] = 0; // } // /*if (tainted_fds[tid][res.res]) { // VG_(printf)("tainting file %d\n", res.res); // } // else { // VG_(printf)("not tainting file %d\n", res.res); // }*/ //} }
int parseArgs(int argc, char **argv, ARGS *args){ int c; opterr = 0; while((c=getopt(argc,argv,"pTDf:h:"))!=-1){ switch(c){ case 'T': if(args->conversionModule == -1){ args->conversionModule = time; } else { printf("Redundant parameter %c\n",c); } break; case 'D': if(args->conversionModule == -1){ args->conversionModule = date; } else { printf("Redundant parameter %c\n",c); } break; case 'f': strcpy(args->filename,optarg); break; case 'h': args->hexValue = strtol(optarg,NULL,0); break; case 'p': printArgs(*args); break; } } return 1; }
void FZ_(syscall_mmap2)(ThreadId tid, UWord *args, UInt nArgs, SysRes res) { if (fengSysFlag){VG_(printf)("feng:entered syscall_mmap2\n");} printArgs(args,nArgs,"mmap2"); UInt i, j, length, offset; Int fd = -1; Char *data = NULL; //populate_guest_args(tid); fd = ((Int)args[4])/*guest_args[tid].args[5]*/; length = ((UInt)args[1])/*guest_args[tid].args[1]*/; data = ((Char *)args[0]); offset = ((UInt)args[5])/*guest_args[tid].args[6]*/; //VG_(printf)("[+] mmap2(0x%08x, 0x%x, 0x%x, 0x%x, 0x%x, 0x%x) = 0x%08x\n", guest_args[tid].args[3], length, guest_args[tid].args[2], guest_args[tid].args[4], fd, offset, data); if (fd < 0 || sr_isError(res) || !tainted_fds[tid][fd]) { return; } for (i = 0; i < length; i++) { #ifdef FENG_AMD64 if(fengSysFlag){VG_(printf)("feng:addr:%x\n",((ULong)data + i));} j = add_dependency_addr((Addr)((ULong)data + i), 8); VG_(printf)("[+] mmap2() tainting byte %d (0x%08x)\n", offset + i, (ULong)(data + i)); pj=getDep(&depaddr8,j); VG_(snprintf)(pj->cons, XXX_MAX_BUF, "input(%d)", offset + i); #else if(fengSysFlag){VG_(printf)("feng:addr:%x\n",((UInt)data + i));} j = add_dependency_addr((Addr)((UInt)data + i), 8); VG_(printf)("[+] mmap2() tainting byte %d (0x%08x)\n", offset + i, (UInt)(data + i)); pj=getDep(&depaddr8,j); VG_(snprintf)(pj->cons, XXX_MAX_BUF, "input(%d)", offset + i); #endif // FENG_AMD64 } }
inline void printArgs(std::ostream& out, Server::ArgStream args) { while (!args.atEnd()) { const char t = args.tag(); switch (t) { case 'i': out << "i:" << args.int32(); break; case 'f': out << "f:" << args.float32(); break; case 's': out << "s:" << args.string(); break; case 'b': out << "b:" << args.blob().size(); break; case '[': out << "[ "; printArgs(out, args.array()); out << " ]"; break; default: out << t << ":?"; args.drop(); break; } out << ' '; } }
void String::printf(const char * format, ...) { va_list args; va_start(args,format); printArgs(format,args); va_end( args ); }
EXPORT quintptr elGetProperty(quintptr id_element, int index) { PRINT_FUNC_INFO quintptr res = m_cgt->elGetProperty(id_element, index); printArgs({id(id_element), index}); PRINT_RESULT(id(res)) return res; }
EXPORT const char *resAddMenu(quintptr id_prop) { PRINT_FUNC_INFO const char *res = m_cgt->resAddMenu(id_prop); printArgs({id(id_prop)}); PRINT_RESULT(str(res)) return res; }
EXPORT int elGetPropCount(quintptr id_element) { PRINT_FUNC_INFO int res = m_cgt->elGetPropCount(id_element); printArgs({id(id_element)}); PRINT_RESULT(res) return res; }
EXPORT ElementFlags elGetFlag(quintptr id_element) { PRINT_FUNC_INFO ElementFlags res = m_cgt->elGetFlag(id_element); printArgs({id(id_element)}); PRINT_RESULT(ElementFlgs(res)) return res; }
EXPORT quintptr sdkGetElementName(quintptr id_sdk, char *name) { PRINT_FUNC_INFO quintptr res = m_cgt->sdkGetElementName(id_sdk, name); printArgs({id(id_sdk), str(name)}); PRINT_RESULT(id(res)) return res; }
EXPORT quintptr sdkGetElement(quintptr id_sdk, int index) { PRINT_FUNC_INFO quintptr res = m_cgt->sdkGetElement(id_sdk, index); printArgs({id(id_sdk), index}); PRINT_RESULT(id(res)) return res; }
EXPORT int sdkGetCount(quintptr id_sdk) { PRINT_FUNC_INFO int res = m_cgt->sdkGetCount(id_sdk); printArgs({id(id_sdk)}); PRINT_RESULT(res) return res; }
EXPORT int _Debug(const char *text, int color) { PRINT_FUNC_INFO int res = m_cgt->_Debug(text, color); printArgs({str(text), color}); PRINT_RESULT(res) return res; }
EXPORT int propToInteger(quintptr id_prop) { PRINT_FUNC_INFO int res = m_cgt->propToInteger(id_prop); printArgs({id(id_prop)}); PRINT_RESULT(res) return res; }
EXPORT bool elIsDefProp(quintptr id_element, int index) { PRINT_FUNC_INFO bool res = m_cgt->elIsDefProp(id_element, index); printArgs({id(id_element), index}); PRINT_RESULT(res) return res; }
void printQueue(list<char**> q) { for (int i = 0; !q.empty(); ++i) { cout << "[DEBUG] Argument #" << i << ": "; printArgs(q.front()); q.pop_front(); cout << endl; } return; }
EXPORT int resAddFile(const char *name) { PRINT_FUNC_INFO int res = m_cgt->resAddFile(name); printArgs({str(name)}); PRINT_RESULT(res) return res; }
EXPORT uchar propToByte(quintptr id_prop) { PRINT_FUNC_INFO uchar res = m_cgt->propToByte(id_prop); printArgs({id(id_prop)}); PRINT_RESULT(res) return res; }
EXPORT const char *resAddStr(const char *str) { PRINT_FUNC_INFO const char *res = m_cgt->resAddStr(str); printArgs({str}); PRINT_RESULT(str(res)) return res; }
EXPORT quintptr propGetValue(quintptr id_prop) { PRINT_FUNC_INFO quintptr res = m_cgt->propGetValue(id_prop); printArgs({id(id_prop)}); PRINT_RESULT(id(res)) return res; }
EXPORT qreal propToReal(quintptr id_prop) { PRINT_FUNC_INFO float res = m_cgt->propToReal(id_prop); printArgs({id(id_prop)}); PRINT_RESULT(res) return res; }