Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Changing code at runtime

I have a pointer to a function (which i get from a vtable) and I want to edit the function by changing the assembler code (changing a few bytes) at runtime. I tried using memset and also tried assigning the new value directly (something like mPtr[0] = X, mPtr[1] = Y etc.) but I keep getting segmentation fault. How can I change the code?

(I'm using C++)

OS is windows.

like image 908
polo Avatar asked Mar 29 '10 09:03

polo


1 Answers

In generally: if memory is allocated with API call VirtualAlloc than you can change the memory attributes with API call VirtualProtect. Check first memory attributes with API call VirtualQuery

like image 134
GJ. Avatar answered Oct 19 '22 10:10

GJ.