|
12345678910111213141516171819202122232425262728293031323334353637383940414243 |
- #ifndef SYSCALL64_H
- #define SYSCALL64_H
- #include <malloc.h> // eww include in headers
-
- extern "C" DWORD _cdecl syscall64(size_t cnt, DWORD id, ...);
-
- #define NARG(...) Y_TUPLE_SIZE_II((Y_TUPLE_SIZE_PREFIX_ ## __VA_ARGS__ ## _Y_TUPLE_SIZE_POSTFIX,32,31,30,29,28,27,26,25,24,23,22,21,20,19,18,17,16,15,14,13,12,11,10,9,8,7,6,5,4,3,2,1,0))
- #define Y_TUPLE_SIZE_II(__args) Y_TUPLE_SIZE_I __args
-
- #define Y_TUPLE_SIZE_PREFIX__Y_TUPLE_SIZE_POSTFIX ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0
-
- #define Y_TUPLE_SIZE_I(__p0,__p1,__p2,__p3,__p4,__p5,__p6,__p7,__p8,__p9,__p10,__p11,__p12,__p13,__p14,__p15,__p16,__p17,__p18,__p19,__p20,__p21,__p22,__p23,__p24,__p25,__p26,__p27,__p28,__p29,__p30,__p31,__n,...) __n
-
-
- #define DO_SYSCALL(id, ...) syscall64(NARG(__VA_ARGS__), id, __VA_ARGS__)
-
- #define STR_VALUE(arg) #arg
-
- #define ALLOC_STRUCTURE(type, name) uint8_t* name = (unsigned char*)_aligned_malloc(is_WOW64() ? sizeof(type<DWORD64>) : sizeof(type<DWORD>), 16); \
- memset(name, 0, is_WOW64() ? sizeof(type<DWORD64>) : sizeof(type<DWORD>)); \
- printf("%s %s @ %p\n", STR_VALUE(type), STR_VALUE(name), name);
- #define FREE_STRUCTURE(type, name) _aligned_free(name); name = NULL;
-
-
- #define GET_MEMBER_OFFSET64(type, member) offsetof(type<DWORD64>, member)
- #define GET_MEMBER_OFFSET86(type, member) offsetof(type<DWORD>, member)
- #define GET_MEMBER_OFFSET(type, member) (is_WOW64() ? GET_MEMBER_OFFSET64(type, member) : GET_MEMBER_OFFSET86(type, member))
-
- #define GET_MEMBER(type, member, object) (object + GET_MEMBER_OFFSET(type, member))
- #define SET_MEMBER(type, member, object, val) { \
- decltype(val)* tmpDst = (decltype(val)*)GET_MEMBER(type, member, object); \
- decltype(val) tmpSrc = val; \
- printf("cpy %X(%s) from/value of %X to %X\n", sizeof(tmpDst), STR_VALUE(member), val, tmpDst); \
- memcpy((void*)tmpDst, (void*)&tmpSrc, sizeof(tmpDst)); \
- }
- #define SET_MEMBER_PTR(type, member, object, src) { \
- void* dstPtr = (void*)GET_MEMBER(type, member, object); \
- void* ptrToSrc = (void*)src; \
- printf("cpy ptr(%s) from %X to %X\n", STR_VALUE(member), src, dstPtr); \
- memcpy((void*)dstPtr, &ptrToSrc, 4); \
- }
-
- #endif
|