int main() { char choice[16]; int seed; allocate(0x1000, 1, (void **)&state); if(state == NULL) { put("Could not allocate space for gamestate. Terminating."); _terminate(-1); } state->hugcount = 1000; put("Welcome to the hug gambling server.\n"); put("What is your name?\n"); bzero(state->name, 256); recvUntil(0, state->name, 256, '\n'); put("Hi "); put(state->name); put(". "); memcpy((char *)&seed, state->name, 4); hugsrand(state, seed); while(state->hugcount > 0) { if(state->hugcount > 1000000) state->hugcount = 1000000; put("You have "); put(itoa(state->hugcount)); put(" hugs. Shall we play a game?\n1. Coin Flip\n2. Hangman\n3. Dice game\n4. War\nq. Quit\n"); bzero(choice, 16); recvUntil(0, choice, 15, '\n'); switch(choice[0]) { case '1': coinflip(); break; case '2': hangman(); break; case '3': dicegame(); break; case '4': war(); break; case 'q': put("Thanks for playing! Don't spend all your hugs in one place.\n"); _terminate(0); } } put("You're all out of hugs :(. Thanks for playing.\n"); }
void inputLoop() { char action[2]; while(1) { memset(action, 0, 2); recvUntil(action, 2, '\n'); switch(action[0]) { case YOLO_ADD: promptAdd(); break; case YOLO_DEL: promptDel(); break; case YOLO_EDIT: promptEdit(); break; case YOLO_EXIT: puts("Thank you for using the yolodex."); _terminate(0); case YOLO_LIST: printList(); break; case YOLO_SORT: sortYolodex(); break; case YOLO_SHOW: promptShow(); break; default: puts("Unrecognized Command."); } } }
void hangman() { char *toguess; int i; char correct[128]; char guess[4]; unsigned int len = 0; int right; int correctcount = 0; unsigned int wagered = 0; bzero(correct, 128); toguess = pickaword(state); len = cgc_strlen(toguess); state->hangmanguess = 0; wagered = getBet(state); if(wagered == -1) return; while(state->hangmanguess < 5) { right = 0; bzero(guess, 4); put(renderBoard(state)); for(i=0;i<len;i++) { if(correct[i] == 0) put("_"); else { put(&correct[i]); i+= cgc_strlen(&correct[i])-1; } } put("\n"); put("Please enter a guess: "); recvUntil(0, guess, 3, '\n'); for(i=0;i<len;i++) { if(guess[0] == toguess[i]) { correct[i] = guess[0]; right = 1; correctcount++; } } if(right == 0) state->hangmanguess++; if(cgc_strlen(correct) == cgc_strlen(toguess)) { handleOutcome(state, 1, wagered); return; } } handleOutcome(state, 0, wagered); }
int barcodez(int socket) { char tehfile[41]; char safe[] = IMG_ROOT; char cobracmdr[sizeof(tehfile)+sizeof(safe)+9]; char data[600]; char safepath[sizeof(safe)+sizeof(tehfile)]; int res = 0; memset(tehfile, 0x0, sizeof(tehfile)); memset(cobracmdr, 0x0, sizeof(cobracmdr)); memset(data, 0x0, sizeof(data)); memset(safepath, 0x0, sizeof(safepath)); sendString(socket, "Welcome to the data matrix bar code reader.\n"); sendString(socket, "Enter the name of file uploaded to decode data.\n> "); if ((res = recvUntil(socket, tehfile, sizeof(tehfile) - 1, '\n')) == 0) { fprintf(stderr, "No datas!\n"); close(socket); exit(1); } snprintf(safepath, sizeof(safepath), "%s%s", safe, tehfile); if ((res = validPath(safe, safepath)) == -1) { sendString(socket, "Hey! You can't look in there.\n"); fprintf(stderr, "%s is outside the safe path.\n", safepath); close(socket); exit(1); } snprintf(cobracmdr, sizeof(cobracmdr), "dmtxread %s", safepath); if ((fp = popen(cobracmdr, "r")) == NULL) { perror("popen"); close(socket); exit(1); } fread(data, SIZE, 1, fp); if (data[0] == 0x0) { sendString(socket, "Looks like you lost your file!\n"); fprintf(stderr, "Nothing read!\n"); close(socket); exit(1); } sendString(socket, data); fclose(fp); unlink(safepath); close(socket); return 0; }
contact *findContact() { char first[32]; char last[32]; contact *ptr; contact *ret = NULL; put("First: "); recvUntil(first, 32, '\n'); put("Last: "); recvUntil(last, 32, '\n'); ptr = head; while(ptr != NULL) { if(strcmp(first, ptr->first) == 0) { if(strcmp(last, ptr->last) == 0) { ret = ptr; break; } } ptr = ptr->next; } return ret; }
int HttpTcpConnection::readLine(char * buffer, size_t bufsiz) { int numread = recvUntil(buffer, bufsiz, '\n'); // Just remove the \r if (numread > 0) { numread --; if (buffer[numread] == '\r') { // make it into a zero string buffer[numread] = '\0'; return numread; } } return numread; }
int netcat(int socket) { int canary = CANARY, i; char string[SIZE] = "Welcome to NetCat.\nPlease enter 4 lines to concatenate delimeted by a newline:\n"; sendString(socket, string); for (i = 0; i < 4; i++) recvUntil(socket, string + (strlen(string) - 1), SIZE, '\n'); sendMsg(socket, string, SIZE); checkCanary(socket, &canary); /* Make sure we close the socket before we return that way they can't do a * simple dup2()/exec() bind shell. Have fun writing shellcode for this shit. */ close(socket); return 0; }
void promptAdd() { char first[32]; char last[32]; char phone[16]; char officetmp[8]; short officenum; char gender; char hacker; char tmp[2]; contact *ptr; memset(phone, 0, 16); memset(officetmp, 0, 8); ptr = NULL; while(ptr == NULL) { put("First: "); recvUntil(first, 32, '\n'); put("Last: "); recvUntil(last, 32, '\n'); put("Phone Number: "); recvUntil(phone, 14, '\n'); put("Office Number: "); memset(officetmp, 0, 8); recvUntil(officetmp, 6, '\n'); officenum = (unsigned short)atoi(officetmp); put("Gender: "); recvUntil(tmp, 2, '\n'); gender = tmp[0]; hacker = '?'; while(hacker == '?') { put("Hacker: "); recvUntil(tmp, 2, '\n'); if(tmp[0] == 'n' || tmp[0] == 'y') hacker = tmp[0]; else puts("Please enter y or n for hacker."); } ptr = createContact(first, last, phone, officenum, gender, hacker); } if(ptr->cookie != cookie) { puts("Contact corruption detected."); _terminate(-1); } insert(ptr); }
void promptShow() { contact *ptr; char office[8]; char useraction[2]; ptr = findContact(); if(ptr == NULL) { puts("No such contact."); return; } memset(useraction, 0, 2); useraction[0] = 's'; while(useraction[0] != 'q') { memset(office, 0, 6); puts("****************************************"); put("First name:\t"); puts(ptr->first); put("Last name:\t"); puts(ptr->last); put("Phone num:\t"); puts(ptr->phone); itoa(office, ptr->officenum, 6); put("Office Number:\t"); puts(office); put("Gender:\t\t"); printGender(ptr->gender); if(ptr->hacker == 'y') { puts("[\x1B[31m!\x1B[0m]This user known to be a hacker[\x1B[31m!\x1B[0m]"); } puts("****************************************"); recvUntil(useraction, 2, '\n'); switch(useraction[0]) { case 'q': break; case 'd': if(ptr->next == NULL && ptr->prev == NULL) { remove(ptr); puts("No more contacts. Leaving detail view."); useraction[0]='q'; } else if (ptr->next == NULL) { ptr = ptr->prev; remove(ptr->next); } else { ptr = ptr->next; remove(ptr->prev); } break; case 'e': editUser(ptr); break; case 'n': if(ptr->next != NULL) ptr = ptr->next; else puts("No next contact."); break; case 'p': if(ptr->prev != NULL) ptr = ptr->prev; else puts("No previous contact."); } } }
void editUser(contact *ptr) { char data[32]; char number[8]; if(ptr != NULL) { puts("Updating fields. Send just a newline to keep old data."); put("New first name: "); recvUntil(data, 32, '\n'); if(data[0] && validateName(data) == 0){ puts("Not a legal first name. Stopping edit."); return; } #ifdef PATCHED data[31] = 0; #endif if(data[0] != 0) { memset(ptr->first, 0, 32); memcpy(ptr->first, data, strlen(data)); } put("New last name: "); recvUntil(data, 32, '\n'); #ifdef PATCHED data[31] = 0; #endif if(data[0] && validateName(data) == 0) { puts("Not a legal last name. Stopping edit."); return; } if(data[0] != 0){ memset(ptr->last, 0, 32); memcpy(ptr->last, data, strlen(data)); } put("New phone number: "); recvUntil(data, 14, '\n'); #ifdef PATCHED data[13] = 0; #endif if(data[0] && validatePhone(data) == 0) { puts("Not a legal phone number. Stopping edit."); return; } if(data[0] != 0) { memset(ptr->phone, 0, 16); memcpy(ptr->phone, data, strlen(data)); } put("New office number: "); recvUntil(data, 6, '\n'); if(data[0]) { memcpy(number, data, 5); ptr->officenum = atoi(number); } put("New gender: "); recvUntil(data, 2, '\n'); if(data[0]) ptr->gender = data[0]; put("Is the user a hacker? "); recvUntil(data, 2, '\n'); if(data[0]) ptr->hacker = data[0]; } if(ptr->cookie != cookie) { puts("Contact corruption detected."); _terminate(-1); } }