title: Access violation error with memcpy
body: <pre><code>    unsigned char hexData[14] = {
      0x31, 0xC0, 0xBB, 0x42, 0x24, 0x80, 0x7C, 0x66,
      0xB8, 0x88, 0x13, 0x50, 0xFF, 0xD3
  };
  
  void dummy(){}
  
  int main()
  {
      void *code_ptr = &amp;dummy;
      PDWORD OP;
      __asm
      {
          call code_ptr
          add code_ptr,10h
      }
      VirtualProtect(code_ptr, 14, PAGE_EXECUTE_WRITECOPY, OP);
      memcpy(code_ptr, hexData, 14);
  .
  .
  .
  </code></pre>
  
  <p>and in disassembly</p>
  
  <pre><code>_LoadLibraryA@4:
  003C11E0  jmp         _LoadLibraryA@4 (03C1430h)  
  dummy:
  003C11E5  jmp         dummy (03C1A80h)  
  _printf:
  003C11EA  jmp         _printf (03C1436h)  
  _VirtualProtect@16:
  003C11EF  jmp         _VirtualProtect@16 (03C143Ch)  
  003C11F4  int         3  
  003C11F5  int         3  
  003C11F6  int         3  
  003C11F7  int         3 
  </code></pre>
  
  <p>so it seems i can copy something 15 blocks after 003C11E5<br>
  but when i do that i get access Access violation error</p>
  
  <p>I tried using VirtualAlloc like</p>
  
  <pre><code>void *code_ptr = &amp;dummy;
  code_ptr = VirtualAlloc(NULL, 14, MEM_COMMIT | MEM_RESERVE, PAGE_EXECUTE_READWRITE);
  memcpy(code_ptr, hexData, 14);
  __asm
  {
      call code_ptr
  }
  </code></pre>
  
  <p>and i got that error again </p>
  
  <pre><code>int (*func)();
  func = (int (*)()) code;
  (int)(*func)();
  </code></pre>
  
  <p>that not working either</p>
  
  <p>my IDE is VS2013 and my OS is win8.1</p>
  
  <p>I would appreciate any ideas</p>