26.07.2018 Views

hacking-the-art-of-exploitation

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

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

815015288<br />

1315541117<br />

2080969327<br />

450538726<br />

710528035<br />

907694519<br />

1525415338<br />

1843056422<br />

random values from 1 to 20<br />

2<br />

3<br />

8<br />

5<br />

9<br />

1<br />

4<br />

20<br />

reader@<strong>hacking</strong>:~/booksrc $ ./a.out<br />

RAND_MAX is 2147483647<br />

random values from 0 to RAND_MAX<br />

678789658<br />

577505284<br />

1472754734<br />

2134715072<br />

1227404380<br />

1746681907<br />

341911720<br />

93522744<br />

random values from 1 to 20<br />

6<br />

16<br />

12<br />

19<br />

8<br />

19<br />

2<br />

1<br />

reader@<strong>hacking</strong>:~/booksrc $<br />

The program’s output just displays random numbers. Pseudo-randomness<br />

can also be used for more complex programs, as you will see in this section’s<br />

final script.<br />

0x287<br />

A Game <strong>of</strong> Chance<br />

The final program in this section is a set <strong>of</strong> games <strong>of</strong> chance that use many<br />

<strong>of</strong> <strong>the</strong> concepts we’ve discussed. The program uses pseudo-random number<br />

generator functions to provide <strong>the</strong> element <strong>of</strong> chance. It has three different<br />

game functions, which are called using a single global function pointer, and<br />

it uses structs to hold data for <strong>the</strong> player, which is saved in a file. Multi-user file<br />

permissions and user IDs allow multiple users to play and maintain <strong>the</strong>ir own<br />

account data. The game_<strong>of</strong>_chance.c program code is heavily documented,<br />

and you should be able to understand it at this point.<br />

102 0x200

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

Saved successfully!

Ooh no, something went wrong!