Você não pode selecionar mais de 25 tópicos Os tópicos devem começar com uma letra ou um número, podem incluir traços ('-') e podem ter até 35 caracteres.

43 linhas
2.1KB

  1. #ifndef SYSCALL64_H
  2. #define SYSCALL64_H
  3. #include <malloc.h> // eww include in headers
  4. extern "C" DWORD _cdecl syscall64(size_t cnt, DWORD id, ...);
  5. #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))
  6. #define Y_TUPLE_SIZE_II(__args) Y_TUPLE_SIZE_I __args
  7. #define Y_TUPLE_SIZE_PREFIX__Y_TUPLE_SIZE_POSTFIX ,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,0
  8. #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
  9. #define DO_SYSCALL(id, ...) syscall64(NARG(__VA_ARGS__), id, __VA_ARGS__)
  10. #define STR_VALUE(arg) #arg
  11. #define ALLOC_STRUCTURE(type, name) uint8_t* name = (unsigned char*)_aligned_malloc(is_WOW64() ? sizeof(type<DWORD64>) : sizeof(type<DWORD>), 16); \
  12. memset(name, 0, is_WOW64() ? sizeof(type<DWORD64>) : sizeof(type<DWORD>)); \
  13. printf("%s %s @ %p\n", STR_VALUE(type), STR_VALUE(name), name);
  14. #define FREE_STRUCTURE(type, name) _aligned_free(name); name = NULL;
  15. #define GET_MEMBER_OFFSET64(type, member) offsetof(type<DWORD64>, member)
  16. #define GET_MEMBER_OFFSET86(type, member) offsetof(type<DWORD>, member)
  17. #define GET_MEMBER_OFFSET(type, member) (is_WOW64() ? GET_MEMBER_OFFSET64(type, member) : GET_MEMBER_OFFSET86(type, member))
  18. #define GET_MEMBER(type, member, object) (object + GET_MEMBER_OFFSET(type, member))
  19. #define SET_MEMBER(type, member, object, val) { \
  20. decltype(val)* tmpDst = (decltype(val)*)GET_MEMBER(type, member, object); \
  21. decltype(val) tmpSrc = val; \
  22. printf("cpy %X(%s) from/value of %X to %X\n", sizeof(tmpDst), STR_VALUE(member), val, tmpDst); \
  23. memcpy((void*)tmpDst, (void*)&tmpSrc, sizeof(tmpDst)); \
  24. }
  25. #define SET_MEMBER_PTR(type, member, object, src) { \
  26. void* dstPtr = (void*)GET_MEMBER(type, member, object); \
  27. void* ptrToSrc = (void*)src; \
  28. printf("cpy ptr(%s) from %X to %X\n", STR_VALUE(member), src, dstPtr); \
  29. memcpy((void*)dstPtr, &ptrToSrc, 4); \
  30. }
  31. #endif