Advertisement
Guest User

15343685@stackoverflow

a guest
Mar 11th, 2013
111
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.82 KB | None | 0 0
  1. You were close.
  2.  
  3. The following is on linux on x86-64.
  4.  
  5. main.c:
  6.  
  7. #include <stdio.h>
  8.  
  9. void change()
  10. {
  11. char x;
  12.  
  13. /* skip local variable and rbp */
  14. *(long*)(&x + sizeof(char) + sizeof(long*)) += 0x40055e - 0x400554;
  15. }
  16.  
  17. int main()
  18. {
  19. printf("Hello\n");
  20. change();
  21. printf("Hai\n");
  22. printf("How are you?\n");
  23. return 0;
  24. }
  25.  
  26. output:
  27.  
  28. $ cc -o main main.c
  29. $ ./main
  30. Hello
  31. How are you?
  32.  
  33. from objdump we get:
  34.  
  35. 40054f: e8 c8 ff ff ff callq 40051c <change>
  36. -> 400554: bf 1a 06 40 00 mov $0x40061a,%edi
  37. 400559: e8 92 fe ff ff callq 4003f0 <puts@plt>
  38. -> 40055e: bf 1e 06 40 00 mov $0x40061e,%edi
  39. 400563: e8 88 fe ff ff callq 4003f0 <puts@plt>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement