Hacking - The Art of Exploitation, 2nd Edition
Programming 47 An additional unary operator called the dereference operator exists for use with pointers. This operator will ret ...
48 0x200 0x264 Format Strings............................................................................... The printf() functi ...
Programming 49 // Example of printing with different format string printf("[A] Dec: %d, Hex: %x, Unsigned: %u\n", A, A, A); prin ...
50 0x200 The final line just shows the address of the variable A, using the unary address operator to dereference the variable. ...
Programming 51 7 - Hello, world! 8 - Hello, world! 9 - Hello, world! 10 - Hello, world! 11 - Hello, world! reader@hacking:~/book ...
52 0x200 As discussed earlier, dividing the integer 13 by 5 will round down to the incorrect answer of 2, even if this value is ...
Programming 53 are actually printed with the %d and %c format parameters, notice that the corresponding printf() arguments must ...
54 0x200 printf("[char pointer] points to %p, which contains the integer %d\n", char_pointer, *char_pointer); char_pointer = cha ...
Programming 55 pointer_types3.c include <stdio.h> int main() { int i; char char_array[5] = {'a', 'b', 'c', 'd', 'e'}; int ...
56 0x200 Naturally, it is far easier just to use the correct data type for pointers in the first place; however, sometimes a gen ...
Programming 57 reader@hacking:~/booksrc $ gcc pointer_types4.c reader@hacking:~/booksrc $ ./a.out [char pointer] points to 0xbff ...
58 0x200 This is rather hacky, but since this integer value is typecast into the proper pointer types when it is assigned and de ...
Programming 59 reader@hacking:~/booksrc $ gcc -o commandline commandline.c reader@hacking:~/booksrc $ ./commandline There were 1 ...
60 0x200 reader@hacking:~/booksrc $ ./a.out 'Hello, world!' 3 Repeating 3 times.. 0 - Hello, world! 1 - Hello, world! 2 - Hello, ...
Programming 61 reader@hacking:~/booksrc $ gcc -g convert2.c reader@hacking:~/booksrc $ gdb -q ./a.out Using host libthread_db li ...
62 0x200 0x267 Variable Scoping Another interesting concept regarding memory in C is variable scoping or context—in particular, ...
Programming 63 In each function, the variable i is set to a different value and printed. Notice that within the main() function, ...
64 0x200 [in func1] i = 5, j = 42 [in func2] i = 7, j = 42 [in func2] setting j = 1337 [in func3] i = 11, j = 999 [back in func2 ...
Programming 65 int main() { int i = 3; printf("[in main] i @ 0x%08x = %d\n", &i, i); printf("[in main] j @ 0x%08x = %d\n", & ...
66 0x200 10 (gdb) break 7 Breakpoint 1 at 0x8048388: file scope3.c, line 7. (gdb) run Starting program: /home/reader/booksrc/a.o ...
«
1
2
3
4
5
6
7
8
9
10
»
Free download pdf