Open jiridanek opened 2 years ago
@jiridanek
//5 byte(jmp rel32)
#define REPLACE_NEAR(t, fn, fn_stub)\
*fn = 0xE9;\
int an = (int)(fn_stub - fn - CODESIZE_MIN);\
*(fn + 1) = ((char*)&an)[0];\
*(fn + 2) = ((char*)&an)[1];\
*(fn + 3) = ((char*)&an)[2];\
*(fn + 4) = ((char*)&an)[3];\
//CACHEFLUSH((char *)fn, CODESIZE);
I am using amd64 architecture. I enabled AddressSanitizer and UndefinedBehavior sanitizer in GCC. My tests produce the following undefined behavior error:
The
stub.cpp
code isThe macro is
Looking into code, there is more statements suffering from this, e.g.
*(long long *)(fn + 2) = (long long)fn_stub;\
in the same file.For a solution, I am thinking that std::copy or memcpy should solve this, but it feels more clumsy than the current code and it may need helper variable.