title: Is finding code's address in visual studio 2010 c++ using in-line assembly possible?
body: <p>Lets say I want to write an inline assembly function in a c++ code that returns its return address.</p>
  
  <p>So if I'm calling the function returnAddress() from some address and it needs to return to the address X after the function is done, I want returnAddress() to return the value X.</p>
  
  <p>example of code for returnAddress():</p>
  
  <pre><code>void* getAddress()
  {
      __asm {
          pop ebx;     // moving return offset to ebx?
          push ebx;    // restoring stack state
          xor eax, eax;
          mov ax, cs;  // ax &lt;- code segment
          mov ecx, 16;
          mul ecx;     // multiplying the code segment by 16
          add eax, ebx;// adding offset
      }
  }
  </code></pre>
  
  <p>The previous code doesn't work correctly, since when I press alt+8 I can clearly see my code's address is completely different from the return value of this function.</p>
  
  <p>The reason I want to find my code's address in the memory is because I want to try and change it while the code itself is running. If there is any other way to find the address of my code without using inline assembly (maybe using windows API?) let me know please.</p>
  
  <p>Also I'm pretty sure I can't even use CS's (code segment) value using visual studio 2010, so maybe that's what causing me problems... CS always equals to 35.
  Does the assembly view (alt+8) show incorrect addresses because VS2010 runs a virtual machine?</p>
  
  <p>This is my first post here so maybe I didn't make my point very clear. Please let me know if I can explain myself to make it any clearer.</p>