16.01.2015 Views

Hacking

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

if((choice < 1) || (choice > 7))<br />

printf("\n[!!] The number %d is an invalid selection.\n\n", choice);<br />

else if (choice < 4) { // Otherwise, choice was a game of some sort.<br />

if(choice != last_game) { // If the function ptr isn't set,<br />

if(choice == 1) // then point it at the selected game<br />

player.current_game = pick_a_number;<br />

else if(choice == 2)<br />

player.current_game = dealer_no_match;<br />

else<br />

player.current_game = find_the_ace;<br />

last_game = choice; // and set last_game.<br />

}<br />

play_the_game(); // Play the game.<br />

}<br />

If last_game isn’t the same as the current choice, the function pointer of<br />

current_game is changed to the appropriate game. This means that in order to<br />

get the program to call the function pointer without overwriting it, a game<br />

must be played first to set the last_game variable.<br />

reader@hacking:~/booksrc $ ./game_of_chance<br />

-=[ Game of Chance Menu ]=-<br />

1 - Play the Pick a Number game<br />

2 - Play the No Match Dealer game<br />

3 - Play the Find the Ace game<br />

4 - View current high score<br />

5 - Change your user name<br />

6 - Reset your account at 100 credits<br />

7 - Quit<br />

[Name: Jon Erickson]<br />

[You have 70 credits] -> 1<br />

[DEBUG] current_game pointer @ 0x08048fde<br />

####### Pick a Number ######<br />

This game costs 10 credits to play. Simply pick a number<br />

between 1 and 20, and if you pick the winning number, you<br />

will win the jackpot of 100 credits!<br />

10 credits have been deducted from your account.<br />

Pick a number between 1 and 20: 5<br />

The winning number is 17<br />

Sorry, you didn't win.<br />

You now have 60 credits<br />

Would you like to play again (y/n) n<br />

-=[ Game of Chance Menu ]=-<br />

1 - Play the Pick a Number game<br />

2 - Play the No Match Dealer game<br />

3 - Play the Find the Ace game<br />

4 - View current high score<br />

5 - Change your user name<br />

6 - Reset your account at 100 credits<br />

Exploitation 157

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!