title: Assembler instructions to modify the return address within the called function
body: <p>I'm quite new to assembler, and I still do not know most of the instructions.</p>
  
  <p>I am trying to add some asm lines to a C program (just for fun, playing with it) to modify the return address of a function.</p>
  
  <p>The C code looks like</p>
  
  <pre><code>int my_function()
  {
      int my_number = 1;
  
      __asm__ ("nop"); 
      __asm__ ("nop"); 
  
      return my_number;
  }
  
  int main(int argc, char *argv[])
  {
      //declarations
  
      ...lots of stuff
  
      int my_number = my_function();
  
      do_something;
  
      ...lots of stuff
  
      do_other_thing;
  
      ... lots of stuff (46 bits in assembler)
  
      return 0;
  }
  </code></pre>
  
  <p>so, what I try to do, is to modify the return address in the stack once on <code>my_function</code> so, when returning, it goes to <code>do_other_thing</code> instead of going to <code>do_something</code></p>
  
  <p>To make it nice, and dynamically, I prefer to not hard-code the return address, so I will like to add those 46 bits. I know also the return address is in <code>EBP + 4</code>. I have tested it manually within <code>x32dgb</code>, and it works.</p>
  
  <p>I guess I will have to:</p>
  
  <ol>
  <li>get the content pointed by EBP + 4 (maybe in EAX)</li>
  <li>sum 46 to EAX</li>
  <li>write back this value into the EBP + 4</li>
  </ol>
  
  <p>so far I have understand it, but not sure how to code this into ASM sentences ...</p>
  
  <p>may you help me??</p>