title: C++ mid-function hook: get register values and jump back [x86 assembly on windows]
body: <p>There is an int value in register <code>EBP</code> and a string in <code>EBX</code>. I need to get the values from these registers in my own function, do some operations on them and finally jump back some code below.</p>
  
  <p><img src="https://i.stack.imgur.com/TAqXs.png" alt="ollydbg jmp start"></p>
  
  <p>I do a <code>JMP</code> at <code>0x46AA17</code> to my function called <code>JmpHook</code>.</p>
  
  <pre><code> void JmpHook()
   {
        char *mystring;
        _asm mov mystring, ebx
  
        printf("value: %s", mystring);
  
        _asm
        {
            jmp       [0x46AA87]
        }
    }
  </code></pre>
  
  <p>As you can see, I am trying to move the string at <code>EBX</code> into <code>mystring</code> and at the end jump back to <code>0x46AA87</code> which is located some lines below my <code>JMP JmpHook</code>.</p>
  
  <p><code>printf</code> is being called and mystring being output but all this seems very untidy in OllyDbg. I am also unable to get <code>EBP</code> as it's being overwritten at the beginning of <code>JmpHook</code>(Saw that in OllyDbg). The <code>JMP</code> at the end of <code>JmpHook</code> also does not work:
  <img src="https://i.stack.imgur.com/KJvWL.png" alt="ollydbg error"></p>
  
  <p>So my question is how to properly jump to my own function, save the two registers there in variables and then after some operations jump back to the original code.</p>
  
  <p>Thank you!</p>