MarkdownPad Document

*:first-child {
margin-top: 0 !important;
}

body>*:last-child {
margin-bottom: 0 !important;
}

/* BLOCKS
=============================================================================*/

p, blockquote, ul, ol, dl, table, pre {
margin: 15px 0;
}

/* HEADERS
=============================================================================*/

h1, h2, h3, h4, h5, h6 {
margin: 20px 0 10px;
padding: 0;
font-weight: bold;
-webkit-font-smoothing: antialiased;
}

h1 tt, h1 code, h2 tt, h2 code, h3 tt, h3 code, h4 tt, h4 code, h5 tt, h5 code, h6 tt, h6 code {
font-size: inherit;
}

h1 {
font-size: 28px;
color: #000;
}

h2 {
font-size: 24px;
border-bottom: 1px solid #ccc;
color: #000;
}

h3 {
font-size: 18px;
}

h4 {
font-size: 16px;
}

h5 {
font-size: 14px;
}

h6 {
color: #777;
font-size: 14px;
}

body>h2:first-child, body>h1:first-child, body>h1:first-child+h2, body>h3:first-child, body>h4:first-child, body>h5:first-child, body>h6:first-child {
margin-top: 0;
padding-top: 0;
}

a:first-child h1, a:first-child h2, a:first-child h3, a:first-child h4, a:first-child h5, a:first-child h6 {
margin-top: 0;
padding-top: 0;
}

h1+p, h2+p, h3+p, h4+p, h5+p, h6+p {
margin-top: 10px;
}

/* LINKS
=============================================================================*/

a {
color: #4183C4;
text-decoration: none;
}

a:hover {
text-decoration: underline;
}

/* LISTS
=============================================================================*/

ul, ol {
padding-left: 30px;
}

ul li > :first-child,
ol li > :first-child,
ul li ul:first-of-type,
ol li ol:first-of-type,
ul li ol:first-of-type,
ol li ul:first-of-type {
margin-top: 0px;
}

ul ul, ul ol, ol ol, ol ul {
margin-bottom: 0;
}

dl {
padding: 0;
}

dl dt {
font-size: 14px;
font-weight: bold;
font-style: italic;
padding: 0;
margin: 15px 0 5px;
}

dl dt:first-child {
padding: 0;
}

dl dt>:first-child {
margin-top: 0px;
}

dl dt>:last-child {
margin-bottom: 0px;
}

dl dd {
margin: 0 0 15px;
padding: 0 15px;
}

dl dd>:first-child {
margin-top: 0px;
}

dl dd>:last-child {
margin-bottom: 0px;
}

/* CODE
=============================================================================*/

pre, code, tt {
font-size: 12px;
font-family: Consolas, "Liberation Mono", Courier, monospace;
}

code, tt {
margin: 0 0px;
padding: 0px 0px;
white-space: nowrap;
border: 1px solid #eaeaea;
background-color: #f8f8f8;
border-radius: 3px;
}

pre>code {
margin: 0;
padding: 0;
white-space: pre;
border: none;
background: transparent;
}

pre {
background-color: #f8f8f8;
border: 1px solid #ccc;
font-size: 13px;
line-height: 19px;
overflow: auto;
padding: 6px 10px;
border-radius: 3px;
}

pre code, pre tt {
background-color: transparent;
border: none;
}

kbd {
-moz-border-bottom-colors: none;
-moz-border-left-colors: none;
-moz-border-right-colors: none;
-moz-border-top-colors: none;
background-color: #DDDDDD;
background-image: linear-gradient(#F1F1F1, #DDDDDD);
background-repeat: repeat-x;
border-color: #DDDDDD #CCCCCC #CCCCCC #DDDDDD;
border-image: none;
border-radius: 2px 2px 2px 2px;
border-style: solid;
border-width: 1px;
font-family: "Helvetica Neue",Helvetica,Arial,sans-serif;
line-height: 10px;
padding: 1px 4px;
}

/* QUOTES
=============================================================================*/

blockquote {
border-left: 4px solid #DDD;
padding: 0 15px;
color: #777;
}

blockquote>:first-child {
margin-top: 0px;
}

blockquote>:last-child {
margin-bottom: 0px;
}

/* HORIZONTAL RULES
=============================================================================*/

hr {
clear: both;
margin: 15px 0;
height: 0px;
overflow: hidden;
border: none;
background: transparent;
border-bottom: 4px solid #ddd;
padding: 0;
}

/* TABLES
=============================================================================*/

table th {
font-weight: bold;
}

table th, table td {
border: 1px solid #ccc;
padding: 6px 13px;
}

table tr {
border-top: 1px solid #ccc;
background-color: #fff;
}

table tr:nth-child(2n) {
background-color: #f8f8f8;
}

/* IMAGES
=============================================================================*/

img {
max-width: 100%
}
-->

pwnable.kr-balckjack-Writeup

该题的代码奇长无比(788行)但题挺容易,并且比较有意思

  • 首先从提供的网址https://cboard.cprogramming.com/c-programming/114023-simple-blackjack-program.html查看该题用到的代码如下:

     // Programmer: Vladislav Shulman
    // Final Project
    // Blackjack // Feel free to use any and all parts of this program and claim it as your own work //FINAL DRAFT #include <stdlib.h>
    #include <stdio.h>
    #include <math.h>
    #include <time.h> //Used for srand((unsigned) time(NULL)) command
    #include <process.h> //Used for system("cls") command #define spade 06 //Used to print spade symbol
    #define club 05 //Used to print club symbol
    #define diamond 04 //Used to print diamond symbol
    #define heart 03 //Used to print heart symbol
    #define RESULTS "Blackjack.txt" //File name is Blackjack //Global Variables
    int k;
    int l;
    int d;
    int won;
    int loss;
    int cash = ;
    int bet;
    int random_card;
    int player_total=;
    int dealer_total; //Function Prototypes
    int clubcard(); //Displays Club Card Image
    int diamondcard(); //Displays Diamond Card Image
    int heartcard(); //Displays Heart Card Image
    int spadecard(); //Displays Spade Card Image
    int randcard(); //Generates random card
    int betting(); //Asks user amount to bet
    void asktitle(); //Asks user to continue
    void rules(); //Prints "Rules of Vlad's Blackjack" menu
    void play(); //Plays game
    void dealer(); //Function to play for dealer AI
    void stay(); //Function for when user selects 'Stay'
    void cash_test(); //Test for if user has cash remaining in purse
    void askover(); //Asks if user wants to continue playing
    void fileresults(); //Prints results into Blackjack.txt file in program directory //Main Function
    int main(void)
    {
    int choice1;
    printf("\n");
    printf("\n");
    printf("\n");
    printf("\n 222 111 ");
    printf("\n 222 222 11111 ");
    printf("\n 222 222 11 111 ");
    printf("\n 222 111 ");
    printf("\n 222 111 ");
    printf("\n");
    printf("\n%c%c%c%c%c %c%c %c%c %c%c%c%c%c %c %c ", club, club, club, club, club, spade, spade, diamond, diamond, heart, heart, heart, heart, heart, club, club);
    printf("\n%c %c %c%c %c %c %c %c %c %c ", club, club, spade, spade, diamond, diamond, heart, heart, club, club);
    printf("\n%c %c %c%c %c %c %c %c %c ", club, club, spade, spade, diamond, diamond, heart, club, club);
    printf("\n%c%c%c%c%c %c%c %c %c%c %c %c %c %c ", club, club, club, club, club, spade, spade, diamond, diamond, diamond, diamond, heart, club, club);
    printf("\n%c %c %c%c %c %c%c%c%c %c %c %c%c %c ", club, club, spade, spade, diamond, diamond, diamond, diamond, diamond, diamond, heart, club, club, club);
    printf("\n%c %c %c%c %c %c %c %c %c ", club, club, spade, spade, diamond, diamond, heart, club, club);
    printf("\n%c %c %c%c %c %c %c %c %c %c ", club, club, spade, spade, diamond, diamond, heart, heart, club, club);
    printf("\n%c%c%c%c%c%c %c%c%c%c%c%c%c %c %c %c%c%c%c%c %c %c ", club, club, club, club, club, club, spade, spade, spade, spade, spade, spade, spade, diamond, diamond, heart, heart, heart, heart, heart, club, club);
    printf("\n");
    printf("\n 21 "); printf("\n %c%c%c%c%c%c%c%c %c%c %c%c%c%c%c %c %c ", diamond, diamond, diamond, diamond, diamond, diamond, diamond, diamond, heart, heart, club, club, club, club, club, spade, spade);
    printf("\n %c%c %c %c %c %c %c %c ", diamond, diamond, heart, heart, club, club, spade, spade);
    printf("\n %c%c %c %c %c %c %c ", diamond, diamond, heart, heart, club, spade, spade);
    printf("\n %c%c %c %c%c %c %c %c %c ", diamond, diamond, heart, heart, heart, heart, club, spade, spade);
    printf("\n %c%c %c %c%c%c%c %c %c %c%c %c ", diamond, diamond, heart, heart, heart, heart, heart, heart, club, spade, spade, spade);
    printf("\n %c%c %c %c %c %c %c ", diamond, diamond, heart, heart, club, spade, spade);
    printf("\n %c %c%c %c %c %c %c %c %c ", diamond, diamond, diamond, heart, heart, club, spade, spade);
    printf("\n %c%c%c %c %c %c%c%c%c%c %c %c ", diamond, diamond, diamond, heart, heart, club, club, club, club, club, spade, spade);
    printf("\n");
    printf("\n 222 111 ");
    printf("\n 222 111 ");
    printf("\n 222 111 ");
    printf("\n 222222222222222 111111111111111 ");
    printf("\n 2222222222222222 11111111111111111 ");
    printf("\n");
    printf("\n"); asktitle(); printf("\n");
    printf("\n");
    system("pause");
    return();
    } //end program void asktitle() // Function for asking player if they want to continue
    {
    char choice1;
    int choice2; printf("\n Are You Ready?");
    printf("\n ----------------");
    printf("\n (Y/N)\n ");
    scanf("\n%c",&choice1); while((choice1!='Y') && (choice1!='y') && (choice1!='N') && (choice1!='n')) // If invalid choice entered
    {
    printf("\n");
    printf("Incorrect Choice. Please Enter Y for Yes or N for No.\n");
    scanf("%c",&choice1);
    } if((choice1 == 'Y') || (choice1 == 'y')) // If yes, continue. Prints menu.
    {
    system("cls");
    printf("\nEnter 1 to Begin the Greatest Game Ever Played.");
    printf("\nEnter 2 to See a Complete Listing of Rules.");
    printf("\nEnter 3 to Exit Game. (Not Recommended)");
    printf("\nChoice: ");
    scanf("%d", &choice2); // Prompts user for choice
    if((choice2<) || (choice2>)) // If invalid choice entered
    {
    printf("\nIncorrect Choice. Please enter 1, 2 or 3\n");
    scanf("%d", &choice2);
    }
    switch(choice2) // Switch case for different choices
    {
    case : // Case to begin game
    system("cls"); play(); break; case : // Case to see rules
    system("cls");
    rules();
    break; case : // Case to exit game
    printf("\nYour day could have been perfect.");
    printf("\nHave an almost perfect day!\n\n");
    system("pause");
    exit();
    break; default:
    printf("\nInvalid Input");
    } // End switch case
    } // End if loop else if((choice1 == 'N') || (choice1 == 'n')) // If no, exit program
    {
    printf("\nYour day could have been perfect.");
    printf("\nHave an almost perfect day!\n\n");
    system("pause");
    exit();
    } return;
    } // End function void rules() //Prints "Rules of Vlad's Blackjack" list
    {
    char choice1;
    int choice2; printf("\n RULES of VLAD's BLACKJACK");
    printf("\n ---------------------------");
    printf("\nI.");
    printf("\n Thou shalt not question the odds of this game.");
    printf("\n %c This program generates cards at random.", spade);
    printf("\n %c If you keep losing, you are very unlucky!\n", diamond); printf("\nII.");
    printf("\n Each card has a value.");
    printf("\n %c Number cards 1 to 10 hold a value of their number.", spade);
    printf("\n %c J, Q, and K cards hold a value of 10.", diamond);
    printf("\n %c Ace cards hold a value of 11", club);
    printf("\n The goal of this game is to reach a card value total of 21.\n"); printf("\nIII.");
    printf("\n After the dealing of the first two cards, YOU must decide whether to HIT or STAY.");
    printf("\n %c Staying will keep you safe, hitting will add a card.", spade);
    printf("\n Because you are competing against the dealer, you must beat his hand.");
    printf("\n BUT BEWARE!.");
    printf("\n %c If your total goes over 21, you will LOSE!.", diamond);
    printf("\n But the world is not over, because you can always play again.\n");
    printf("\n%c%c%c YOUR RESULTS ARE RECORDED AND FOUND IN SAME FOLDER AS PROGRAM %c%c%c\n", spade, heart, club, club, heart, spade);
    printf("\nWould you like to go the previous screen? (I will not take NO for an answer)");
    printf("\n (Y/N)\n ");
    scanf("\n%c",&choice1); while((choice1!='Y') && (choice1!='y') && (choice1!='N') && (choice1!='n')) // If invalid choice entered
    {
    printf("\n");
    printf("Incorrect Choice. Please Enter Y for Yes or N for No.\n");
    scanf("%c",&choice1);
    } if((choice1 == 'Y') || (choice1 == 'y')) // If yes, continue. Prints menu.
    {
    system("cls");
    asktitle();
    } // End if loop else if((choice1 == 'N') || (choice1 == 'n')) // If no, convinces user to enter yes
    {
    system("cls");
    printf("\n I told you so.\n");
    asktitle();
    } return;
    } // End function int clubcard() //Displays Club Card Image
    { srand((unsigned) time(NULL)); //Generates random seed for rand() function
    k=rand()%+; if(k<=) //If random number is 9 or less, print card with that number
    {
    //Club Card
    printf("-------\n");
    printf("|%c |\n", club);
    printf("| %d |\n", k);
    printf("| %c|\n", club);
    printf("-------\n");
    } if(k==) //If random number is 10, print card with J (Jack) on face
    {
    //Club Card
    printf("-------\n");
    printf("|%c |\n", club);
    printf("| J |\n");
    printf("| %c|\n", club);
    printf("-------\n");
    } if(k==) //If random number is 11, print card with A (Ace) on face
    {
    //Club Card
    printf("-------\n");
    printf("|%c |\n", club);
    printf("| A |\n");
    printf("| %c|\n", club);
    printf("-------\n");
    if(player_total<=) //If random number is Ace, change value to 11 or 1 depending on dealer total
    {
    k=;
    } else
    { k=;
    }
    } if(k==) //If random number is 12, print card with Q (Queen) on face
    {
    //Club Card
    printf("-------\n");
    printf("|%c |\n", club);
    printf("| Q |\n");
    printf("| %c|\n", club);
    printf("-------\n");
    k=; //Set card value to 10
    } if(k==) //If random number is 13, print card with K (King) on face
    {
    //Club Card
    printf("-------\n");
    printf("|%c |\n", club);
    printf("| K |\n");
    printf("| %c|\n", club);
    printf("-------\n");
    k=; //Set card value to 10
    }
    return k;
    }// End function int diamondcard() //Displays Diamond Card Image
    { srand((unsigned) time(NULL)); //Generates random seed for rand() function
    k=rand()%+; if(k<=) //If random number is 9 or less, print card with that number
    {
    //Diamond Card
    printf("-------\n");
    printf("|%c |\n", diamond);
    printf("| %d |\n", k);
    printf("| %c|\n", diamond);
    printf("-------\n");
    } if(k==) //If random number is 10, print card with J (Jack) on face
    {
    //Diamond Card
    printf("-------\n");
    printf("|%c |\n", diamond);
    printf("| J |\n");
    printf("| %c|\n", diamond);
    printf("-------\n");
    } if(k==) //If random number is 11, print card with A (Ace) on face
    {
    //Diamond Card
    printf("-------\n");
    printf("|%c |\n", diamond);
    printf("| A |\n");
    printf("| %c|\n", diamond);
    printf("-------\n");
    if(player_total<=) //If random number is Ace, change value to 11 or 1 depending on dealer total
    {
    k=;
    } else
    {
    k=;
    }
    } if(k==) //If random number is 12, print card with Q (Queen) on face
    {
    //Diamond Card
    printf("-------\n");
    printf("|%c |\n", diamond);
    printf("| Q |\n");
    printf("| %c|\n", diamond);
    printf("-------\n");
    k=; //Set card value to 10
    } if(k==) //If random number is 13, print card with K (King) on face
    {
    //Diamond Card
    printf("-------\n");
    printf("|%c |\n", diamond);
    printf("| K |\n");
    printf("| %c|\n", diamond);
    printf("-------\n");
    k=; //Set card value to 10
    }
    return k;
    }// End function int heartcard() //Displays Heart Card Image
    { srand((unsigned) time(NULL)); //Generates random seed for rand() function
    k=rand()%+; if(k<=) //If random number is 9 or less, print card with that number
    {
    //Heart Card
    printf("-------\n");
    printf("|%c |\n", heart);
    printf("| %d |\n", k);
    printf("| %c|\n", heart);
    printf("-------\n");
    } if(k==) //If random number is 10, print card with J (Jack) on face
    {
    //Heart Card
    printf("-------\n");
    printf("|%c |\n", heart);
    printf("| J |\n");
    printf("| %c|\n", heart);
    printf("-------\n");
    } if(k==) //If random number is 11, print card with A (Ace) on face
    {
    //Heart Card
    printf("-------\n");
    printf("|%c |\n", heart);
    printf("| A |\n");
    printf("| %c|\n", heart);
    printf("-------\n");
    if(player_total<=) //If random number is Ace, change value to 11 or 1 depending on dealer total
    {
    k=;
    } else
    {
    k=;
    }
    } if(k==) //If random number is 12, print card with Q (Queen) on face
    {
    //Heart Card
    printf("-------\n");
    printf("|%c |\n", heart);
    printf("| Q |\n");
    printf("| %c|\n", heart);
    printf("-------\n");
    k=; //Set card value to 10
    } if(k==) //If random number is 13, print card with K (King) on face
    {
    //Heart Card
    printf("-------\n");
    printf("|%c |\n", heart);
    printf("| K |\n");
    printf("| %c|\n", heart);
    printf("-------\n");
    k=; //Set card value to 10
    }
    return k;
    } // End Function int spadecard() //Displays Spade Card Image
    { srand((unsigned) time(NULL)); //Generates random seed for rand() function
    k=rand()%+; if(k<=) //If random number is 9 or less, print card with that number
    {
    //Spade Card
    printf("-------\n");
    printf("|%c |\n", spade);
    printf("| %d |\n", k);
    printf("| %c|\n", spade);
    printf("-------\n");
    } if(k==) //If random number is 10, print card with J (Jack) on face
    {
    //Spade Card
    printf("-------\n");
    printf("|%c |\n", spade);
    printf("| J |\n");
    printf("| %c|\n", spade);
    printf("-------\n");
    } if(k==) //If random number is 11, print card with A (Ace) on face
    {
    //Spade Card
    printf("-------\n");
    printf("|%c |\n", spade);
    printf("| A |\n");
    printf("| %c|\n", spade);
    printf("-------\n");
    if(player_total<=) //If random number is Ace, change value to 11 or 1 depending on dealer total
    {
    k=;
    } else
    {
    k=;
    }
    } if(k==) //If random number is 12, print card with Q (Queen) on face
    {
    //Spade Card
    printf("-------\n");
    printf("|%c |\n", spade);
    printf("| Q |\n");
    printf("| %c|\n", spade);
    printf("-------\n");
    k=; //Set card value to 10
    } if(k==) //If random number is 13, print card with K (King) on face
    {
    //Spade Card
    printf("-------\n");
    printf("|%c |\n", spade);
    printf("| K |\n");
    printf("| %c|\n", spade);
    printf("-------\n");
    k=; //Set card value to 10
    }
    return k;
    } // End Function int randcard() //Generates random card
    { srand((unsigned) time(NULL)); //Generates random seed for rand() function
    random_card = rand()%+; if(random_card==)
    {
    clubcard();
    l=k;
    } if(random_card==)
    {
    diamondcard();
    l=k;
    } if(random_card==)
    {
    heartcard();
    l=k;
    } if(random_card==)
    {
    spadecard();
    l=k;
    }
    return l;
    } // End Function void play() //Plays game
    { int p=; // holds value of player_total
    int i=; // counter for asking user to hold or stay (aka game turns)
    char choice3; cash = cash;
    cash_test();
    printf("\nCash: $%d\n",cash); //Prints amount of cash user has
    randcard(); //Generates random card
    player_total = p + l; //Computes player total
    p = player_total;
    printf("\nYour Total is %d\n", p); //Prints player total
    dealer(); //Computes and prints dealer total
    betting(); //Prompts user to enter bet amount while(i<=) //While loop used to keep asking user to hit or stay at most twenty-one times
    // because there is a chance user can generate twenty-one consecutive 1's
    {
    if(p==) //If user total is 21, win
    {
    printf("\nUnbelievable! You Win!\n");
    won = won+;
    cash = cash+bet;
    printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss);
    dealer_total=;
    askover();
    } if(p>) //If player total is over 21, loss
    {
    printf("\nWoah Buddy, You Went WAY over.\n");
    loss = loss+;
    cash = cash - bet;
    printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss);
    dealer_total=;
    askover();
    } if(p<=) //If player total is less than 21, ask to hit or stay
    {
    printf("\n\nWould You Like to Hit or Stay?"); scanf("%c", &choice3);
    while((choice3!='H') && (choice3!='h') && (choice3!='S') && (choice3!='s')) // If invalid choice entered
    {
    printf("\n");
    printf("Please Enter H to Hit or S to Stay.\n");
    scanf("%c",&choice3);
    } if((choice3=='H') || (choice3=='h')) // If Hit, continues
    {
    randcard();
    player_total = p + l;
    p = player_total;
    printf("\nYour Total is %d\n", p);
    dealer();
    if(dealer_total==) //Is dealer total is 21, loss
    {
    printf("\nDealer Has the Better Hand. You Lose.\n");
    loss = loss+;
    cash = cash - bet;
    printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss);
    dealer_total=;
    askover();
    } if(dealer_total>) //If dealer total is over 21, win
    {
    printf("\nDealer Has Went Over!. You Win!\n");
    won = won+;
    cash = cash+bet;
    printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss);
    dealer_total=;
    askover();
    }
    }
    if((choice3=='S') || (choice3=='s')) // If Stay, does not continue
    {
    printf("\nYou Have Chosen to Stay at %d. Wise Decision!\n", player_total);
    stay();
    }
    }
    i++; //While player total and dealer total are less than 21, re-do while loop
    } // End While Loop
    } // End Function void dealer() //Function to play for dealer AI
    {
    int z; if(dealer_total<)
    {
    srand((unsigned) time(NULL) + ); //Generates random seed for rand() function
    z=rand()%+;
    if(z<=) //If random number generated is 10 or less, keep that value
    {
    d=z; } if(z>) //If random number generated is more than 11, change value to 10
    {
    d=;
    } if(z==) //If random number is 11(Ace), change value to 11 or 1 depending on dealer total
    {
    if(dealer_total<=)
    {
    d=;
    } else
    {
    d=;
    }
    }
    dealer_total = dealer_total + d;
    } printf("\nThe Dealer Has a Total of %d", dealer_total); //Prints dealer total } // End Function void stay() //Function for when user selects 'Stay'
    {
    dealer(); //If stay selected, dealer continues going
    if(dealer_total>=)
    {
    if(player_total>=dealer_total) //If player's total is more than dealer's total, win
    {
    printf("\nUnbelievable! You Win!\n");
    won = won+;
    cash = cash+bet;
    printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss);
    dealer_total=;
    askover();
    }
    if(player_total<dealer_total) //If player's total is less than dealer's total, loss
    {
    printf("\nDealer Has the Better Hand. You Lose.\n");
    loss = loss+;
    cash = cash - bet;
    printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss);
    dealer_total=;
    askover();
    }
    if(dealer_total>) //If dealer's total is more than 21, win
    {
    printf("\nUnbelievable! You Win!\n");
    won = won+;
    cash = cash+bet;
    printf("\nYou have %d Wins and %d Losses. Awesome!\n", won, loss);
    dealer_total=;
    askover();
    }
    }
    else
    {
    stay();
    } } // End Function void cash_test() //Test for if user has cash remaining in purse
    {
    if (cash <= ) //Once user has zero remaining cash, game ends and prompts user to play again
    {
    printf("You Are Bankrupt. Game Over");
    cash = ;
    askover();
    }
    } // End Function int betting() //Asks user amount to bet
    {
    printf("\n\nEnter Bet: $");
    scanf("%d", &bet); if (bet > cash) //If player tries to bet more money than player has
    {
    printf("\nYou cannot bet more money than you have.");
    printf("\nEnter Bet: ");
    scanf("%d", &bet);
    return bet;
    }
    else return bet;
    } // End Function void askover() // Function for asking player if they want to play again
    {
    char choice1; printf("\nWould You Like To Play Again?");
    printf("\nPlease Enter Y for Yes or N for No\n");
    scanf("\n%c",&choice1); while((choice1!='Y') && (choice1!='y') && (choice1!='N') && (choice1!='n')) // If invalid choice entered
    {
    printf("\n");
    printf("Incorrect Choice. Please Enter Y for Yes or N for No.\n");
    scanf("%c",&choice1);
    } if((choice1 == 'Y') || (choice1 == 'y')) // If yes, continue.
    {
    system("cls");
    play();
    } else if((choice1 == 'N') || (choice1 == 'n')) // If no, exit program
    {
    fileresults();
    printf("\nBYE!!!!\n\n");
    system("pause");
    exit();
    }
    return;
    } // End function void fileresults() //Prints results into Blackjack.txt file in program directory
    {
    FILE *fpresults; //File pointer is fpresults
    fpresults = fopen(RESULTS, "w"); //Creates file and writes into it
    if(fpresults == NULL) // what to do if file missing from directory
    {
    printf("\nError: File Missing\n");
    system("pause");
    exit();
    }
    else
    {
    fprintf(fpresults,"\n\t RESULTS");
    fprintf(fpresults,"\n\t---------\n");
    fprintf(fpresults,"\nYou Have Won %d Times\n", won);
    fprintf(fpresults,"\nYou Have Lost %d Times\n", loss);
    fprintf(fpresults,"\nKeep Playing and Set an All-Time Record!");
    }
    fclose(fpresults);
    return;
    } // End Function

    虽然代码足足有近800行,但根据代码的流程逐渐分析,还是能分析出以下信息:

  1. 游戏规则

    • 玩家在每轮游戏开始之前设置赌资;
    • 玩家的任务是通过hit(继续加扑克牌)或者stay(等待)使自己的点数之和等于21;
    • 卡片1~10的点数即为相对应的数字,卡片J,Q,K的点数为10,卡片A的点数为11;
    • 当自己的点数大于了21,或者自己的点数小于了庄家的点数,玩家输;则要从赌本中减去赌资;
    • 当玩家的点数之和等于21时,玩家胜;玩家就从庄家处赚取同赌资金额的金钱;
  2. 当玩家的赌本大于1000000时,胜利,即可拿到flag;


由以上分析,首先先到了三种方法作弊(或者相信自己的人品无穷大,可以通过自己的努力能成为百万富翁):

  1. 直接修改赌本为 ≥ 1000000;
  2. 通过修改, 使自己每局都能获胜,那么需要
  3. 在每局结束时动手脚,增加赌本

分析代码,前两种想法没有找到相应的漏洞,
第三种方法,分析betting函数:

 int betting() //Asks user amount to bet
{
printf("\n\nEnter Bet: $");
scanf("%d", &bet); if (bet > cash) //If player tries to bet more money than player has
{
printf("\nYou cannot bet more money than you have.");
printf("\nEnter Bet: ");
scanf("%d", &bet);
return bet;
}
else return bet;
} // End Function
  • 可以看出函数对输入的赌资只做了是否小于赌本的判断,那么我们就可以输入一个负的大小合适的赌本(大小合适指不会数据溢出),如-1000000
  • 那么,如果我们输掉了那一局,我们的赌本就要减负的1000000,就是加正的1000000,就可以拿到flag;

经过几次探索,拿到flag如下:

则flag即为YaY_I_AM_A_MILLIONARE_LOL
2017-2-16 8:16;47

pwnable.kr-balckjack-Writeup的更多相关文章

  1. pwnable.kr simple login writeup

    这道题是pwnable.kr Rookiss部分的simple login,需要我们去覆盖程序的ebp,eip,esp去改变程序的执行流程   主要逻辑是输入一个字符串,base64解码后看是否与题目 ...

  2. pwnable.kr的passcode

    前段时间找到一个练习pwn的网站,pwnable.kr 这里记录其中的passcode的做题过程,给自己加深印象. 废话不多说了,看一下题目, 看到题目,就ssh连接进去,就看到三个文件如下 看了一下 ...

  3. pwnable.kr bof之write up

    这一题与前两题不同,用到了静态调试工具ida 首先题中给出了源码: #include <stdio.h> #include <string.h> #include <st ...

  4. pwnable.kr col之write up

    Daddy told me about cool MD5 hash collision today. I wanna do something like that too! ssh col@pwnab ...

  5. pwnable.kr brainfuck之write up

    I made a simple brain-fuck language emulation program written in C. The [ ] commands are not impleme ...

  6. pwnable.kr login之write up

    main函数如下: auth函数如下: 程序的流程如下: 输入Authenticate值,并base64解码,将解码的值代入md5_auth函数中 mad5_auth()生成其MD5值并与f87cd6 ...

  7. pwnable.kr详细通关秘籍(二)

    i春秋作家:W1ngs 原文来自:pwnable.kr详细通关秘籍(二) 0x00 input 首先看一下代码: 可以看到程序总共有五步,全部都满足了才可以得到flag,那我们就一步一步来看 这道题考 ...

  8. pwnable.kr第二天

    3.bof 这题就是简单的数组越界覆盖,直接用gdb 调试出偏移就ok from pwn import * context.log_level='debug' payload='A'*52+p32(0 ...

  9. [pwnable.kr]Dragon

    0x00: dragon 是一个UAF漏洞的利用. UseAfterFree 是堆的漏洞利用的一种 简单介绍 https://www.owasp.org/index.php/Using_freed_m ...

  10. [pwnable.kr] - wtf

    Q: I don't understand why my exploit is not working. I need your help. download : http://pwnable.kr/ ...

随机推荐

  1. jQuery里ready方法用原生js实现原理

    function ready(fn){ if(document.addEventListener){ //标准浏览器 document.addEventListener('DOMContentLoad ...

  2. 【NOIP2011提高组】计算系数

    计算系数 算法:真·滚动数组模拟!!! 马上CSP/S了,这是远在今年暑假前的一天的校内考试题中的一道.当时做的时候不会组合数,不会二项式定理,不会DP,不会……只知道应该n*n的空间存一个杨辉三角形 ...

  3. [USACO19OPEN]I Would Walk 500 Miles 贪心

    题目 洛谷P5425(点击可跳转) 题目描述 Farmer John想要将他的编号为 \(1 \ldots N\)的 N N 头奶牛( \(N \leq 7500\) )分为非空的 \(K\) 组( ...

  4. Android 开发替换Launcher

    做android产品的时候,根据需求会制定各种各样的Launcher,因此,在此记录替换系统Launcher的流程. 1.修改frameworks/base/core/java/android/con ...

  5. word文档巧替换(空行替换、空格替换、软回车替换成硬回车)

    一.空行替换 在日常工作中,我们经常从网上下载一些文字材料,往往因空行多使得页数居高不下.一般方法是:在“编辑”菜单中打开“查找和替换”对话框(或按ctrl+H),在“查找内容”中输入“^p^p”“替 ...

  6. MySql -- unique唯一约束

    3.UNIQUE 约束 约束唯一标识数据库表中的每条记录. 创建一张测试表 CREATE TABLE `test`.`info`( `id` ) UNSIGNED NOT NULL AUTO_INCR ...

  7. [IOI2002] 任务安排

    题目链接 题意 一些不能改变顺序的任务被分成若干批,每批包含相邻的若干任务.第 $i$ 个任务单独完成所需的时间是 $T_i$.在每批任务开始前,机器需要启动时间 $S$,而完成这批任务所需的时间是各 ...

  8. C++-POJ3274-Gold Balanced Lineup[hash]

    不是很懂? 胡乱hash #include <set> #include <map> #include <cmath> #include <queue> ...

  9. 2.7.2 元素定位:frame 内定位 driver.switch_to.frame()

    来源: http://blog.csdn.net/anniejunyan/article/details/23257327  Selenium + Webdriver 学习(五) frame下元素定位 ...

  10. myeclipse2017配置tomcat7.0

    具体配置参考这篇博客:https://www.cnblogs.com/alibaba-inc/p/9249135.html 期间可能会碰到这样一个问题,"The server does no ...