Advertisement
Guest User

garbage in pointer

a guest
Sep 9th, 2018
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
GDB 2.18 KB | None | 0 0
  1. // this is the function I'm trying to jump to
  2. 0x40102e <lit>                  lods   %ds:(%rsi),%rax                                                                              
  3. 0x401030 <lit+2>                push   %rax                                                                                        
  4. 0x401031 <lit+3>                lods   %ds:(%rsi),%rax                                                                              
  5. 0x401033 <lit+5>                jmpq   *%rax
  6.  
  7. // this is where we're executing from                                          
  8. 0x401035 <hello_world>          push   %rsi
  9. // %rax is equal to 0x401035, I checked.
  10. // %rax now loads from 0x401043, I checked the math too.
  11. 0x401036 <hello_world+1>        mov    0xe(%rax),%rax                                                                              
  12. 0x40103a <hello_world+5>        lea    0xa(%rip),%rsi        # 0x40104b <hello_world+22>0x401041 <hello_world+12>    
  13.  
  14. // the rsi trick seems to load the correct address
  15.    (gdb) info reg rsi
  16.     rsi            0x40104b 4198475  
  17.  
  18. // segfault
  19.  
  20. jmpq   *%rax
  21. // this is the beginning of the data, which is an array of 64-bit pointers.
  22. // %rax is supposed to point at 0x40102e, i.e. <lit>, but instead it points at garbage.
  23.  
  24.    (gdb) p/x *(long*) 0x401043
  25.     $4 = 0x680040102e
  26.  
  27. // and I can confirm that %rax equals the same.
  28. // as we can see, 0x401043 is actually equal to
  29. // 0x000000680040102e instead of
  30. //         ^ why is this here?
  31. // 0x000000000040102e
  32.  
  33. // this data was generated with
  34.  
  35.     <code>
  36.     .long lit
  37.     .long 'h'
  38.     <...>
  39.  
  40. 0x401043 <hello_world+14>       adc    %al,%cs:0x0(%rax)                                                                            
  41. 0x401047 <hello_world+18>       pushq  $0x5000000                                                                                  
  42. 0x40104c <hello_world+23>       adc    %al,0x0(%rax)                                                                                
  43. 0x40104f <hello_world+26>       adc    %al,%cs:0x0(%rax)                                                                            
  44. 0x401053 <hello_world+30>       insb   (%dx),%es:(%rdi)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement