Advertisement
Guest User

Untitled

a guest
Oct 17th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.73 KB | None | 0 0
  1. class KReader
  2. {
  3. public:
  4. KReader() : m_hDriver(0), m_PUID(0), m_PUBase(0)
  5. {
  6. m_isConnected = false;
  7.  
  8. m_hDriver = CreateFileA(DRIVERNAME, GENERIC_READ | GENERIC_WRITE, FILE_SHARE_READ | FILE_SHARE_WRITE, 0, OPEN_EXISTING, 0, 0);
  9.  
  10. if (!m_hDriver || m_hDriver == INVALID_HANDLE_VALUE)
  11. {
  12. m_isConnected = false;
  13. //ExitProcess(0);
  14. }
  15. else
  16. {
  17. m_isConnected = true;
  18. }
  19. }
  20. ~KReader()
  21. {
  22. CloseHandle(m_hDriver);
  23. }
  24.  
  25. /*
  26. * CLASS METHODS
  27. */
  28. bool SetPUID(ULONG PUID)
  29. {
  30.  
  31. DWORD at;
  32. // create a struct that requests the base address
  33. readStruct rStruct{ 0, 0, 0, 0, PROTO_SET_PID , PUID };
  34. // send the struct to IOCTL
  35. WriteFile(m_hDriver, (LPCVOID)&rStruct, sizeof(ReadStruct), &at, NULL);
  36.  
  37. return true;
  38. }
  39.  
  40.  
  41. HANDLE readPUID()
  42. {
  43. HANDLE PUID = 0;
  44. DWORD at;
  45.  
  46. void* read = nullptr;
  47.  
  48. // create a struct that requests the base address
  49. readStruct rStruct{ (uint64_t)&PUID, (uint64_t)read, sizeof(HANDLE), (uint32_t)GetCurrentProcessId(), PROTO_GET_PUID,0 };
  50. // send the struct to IOCTL
  51. WriteFile(m_hDriver, (LPCVOID)&rStruct, sizeof(ReadStruct), &at, NULL);
  52.  
  53. if (PUID)
  54. {
  55. m_PUID = PUID;
  56. }
  57.  
  58. return PUID;
  59.  
  60. }
  61.  
  62. int64_t readPUBase()
  63. {
  64. int64_t base = 0;
  65.  
  66. DWORD at;
  67. void* read = nullptr;
  68.  
  69. // create a struct that requests the base address
  70. readStruct rStruct{ (uint64_t)&base, (uint64_t)read, sizeof(int64_t), (uint32_t)GetCurrentProcessId(), PROTO_GET_BASEADDR,0 };
  71. // send the struct to IOCTL
  72. WriteFile(m_hDriver, (LPCVOID)&rStruct, sizeof(ReadStruct), &at, NULL);
  73.  
  74. if (base)
  75. {
  76. m_PUBase = base;
  77. }
  78.  
  79. return base;
  80. }
  81.  
  82. template<typename T>
  83. T RPM(const int64_t& w_read, const SIZE_T& Size) const
  84. {
  85. T writeMe;
  86.  
  87. DWORD at;
  88. readStruct rStruct{ (uint64_t)&writeMe, (uint64_t)w_read, Size, (uint32_t)GetCurrentProcessId(), PROTO_NORMAL_READ,0 };
  89. // send the struct to IOCTL
  90. WriteFile(m_hDriver, (LPCVOID)&rStruct, sizeof(ReadStruct), &at, NULL);
  91.  
  92. return writeMe;
  93. }
  94.  
  95. template<typename T>
  96. T RPM(const int64_t& w_read) const
  97. {
  98. T writeMe;
  99.  
  100. DWORD at;
  101. readStruct rStruct{ (uint64_t)&writeMe, (uint64_t)w_read, sizeof(T), (uint32_t)GetCurrentProcessId(), PROTO_NORMAL_READ,0 };
  102. // send the struct to IOCTL
  103.  
  104. WriteFile(m_hDriver, (LPCVOID)&rStruct, sizeof(ReadStruct), &at, NULL);
  105.  
  106. return writeMe;
  107. }
  108. template<typename T> void WPM(const int64_t& address_to_write, T value_to_write, ULONGLONG size)
  109. {
  110. readStruct write_struct{ (uint64_t)&value_to_write, (uint64_t)address_to_write, size, (uint32_t)GetCurrentProcessId(), PROTO_NORMAL_WRITE ,0 };
  111. // send the struct to IOCTL
  112. DWORD at;
  113. WriteFile(m_hDriver, (LPCVOID)&rStruct, sizeof(ReadStruct), &at, NULL);
  114. }
  115.  
  116. template<typename T> void WPM(const int64_t& address_to_write, T value_to_write)
  117. {
  118. readStruct write_struct{ (uint64_t)&value_to_write, (uint64_t)address_to_write, sizeof(T), (uint32_t)GetCurrentProcessId(), PROTO_NORMAL_WRITE };
  119. // send the struct to IOCTL
  120. DWORD at;
  121. WriteFile(m_hDriver, (LPCVOID)&write_struct, sizeof(ReadStruct), &at, NULL);
  122. }
  123.  
  124. BOOL writeSize(const int64_t& buffer, const BYTE* gOffset, ULONGLONG size) const
  125. {
  126. readStruct rStruct{ (uint64_t)gOffset, (uint64_t)buffer, size, (uint32_t)GetCurrentProcessId(), PROTO_NORMAL_WRITE,0 };
  127. // send the struct to IOCTL
  128. DWORD at;
  129. return WriteFile(m_hDriver, (LPCVOID)&rStruct, sizeof(ReadStruct), &at, NULL);
  130. }
  131.  
  132. void writeAll(const int64_t& w_read, const PVOID& w_write, ULONGLONG size) const
  133. {
  134. readStruct rStruct{ (uint64_t)w_write, (uint64_t)w_read, size, (uint32_t)GetCurrentProcessId(), PROTO_NORMAL_WRITE,0 };
  135. // send the struct to IOCTL
  136. DWORD at;
  137. WriteFile(m_hDriver, (LPCVOID)&rStruct, sizeof(ReadStruct), &at, NULL);
  138. }
  139.  
  140. bool iowrite(uint64_t address, PVOID data, ULONGLONG size) const
  141. {
  142. readStruct rStruct{ (uint64_t)data, (uint64_t)address, size, (uint32_t)GetCurrentProcessId(), PROTO_NORMAL_WRITE,0 };
  143.  
  144. DWORD at;
  145. /*rStruct.GameAddressOffset = address;
  146. rStruct.UserBufferAdress = (uintptr_t)data;
  147. rStruct.UserPID = (uint32_t)GetCurrentProcessId();
  148. rStruct.GAMEPID = this->m_PUID;
  149. rStruct.ProtocolMsg = PROTO_NORMAL_READ;
  150. rStruct.ReadSize = size;*/
  151.  
  152. // send the struct to IOCTL
  153. return WriteFile(m_hDriver, (LPCVOID)&rStruct, sizeof(ReadStruct), &at, NULL);
  154. }
  155.  
  156. bool ioread(uint64_t address, PVOID data, ULONGLONG size) const
  157. {
  158. readStruct rStruct{ (uint64_t)data, (uint64_t)address, size, (uint32_t)GetCurrentProcessId(), PROTO_NORMAL_READ,0 };
  159.  
  160. DWORD at;
  161. /*rStruct.GameAddressOffset = address;
  162. rStruct.UserBufferAdress = (uintptr_t)data;
  163. rStruct.UserPID = (uint32_t)GetCurrentProcessId();
  164. rStruct.GAMEPID = this->m_PUID;
  165. rStruct.ProtocolMsg = PROTO_NORMAL_READ;
  166. rStruct.ReadSize = size;*/
  167.  
  168. // send the struct to IOCTL
  169. return WriteFile(m_hDriver, (LPCVOID)&rStruct, sizeof(ReadStruct), &at, NULL);
  170. }
  171.  
  172.  
  173. BYTE* readSize(const int64_t& w_read, const uint32_t& w_readSize) const
  174. {
  175. BYTE* writeMe = new BYTE[w_readSize];
  176. // memset(paluu, 0, readSize);
  177.  
  178. DWORD at;
  179. if (PROTO_NORMAL_READ == PROTO_NORMAL_READ)
  180. {
  181. readStruct rStruct{ (uint64_t)writeMe, (uint64_t)w_read, w_readSize - 2, (uint32_t)GetCurrentProcessId(), PROTO_NORMAL_READ,0 };
  182. // send the struct to IOCTL
  183. WriteFile(m_hDriver, (LPCVOID)&rStruct, sizeof(ReadStruct), &at, NULL);
  184. }
  185.  
  186. if (*writeMe == 0)
  187. {
  188. delete writeMe;
  189. return NULL;
  190. }
  191.  
  192. return writeMe;
  193. }
  194.  
  195. void deletedriver()
  196. {
  197. DWORD at;
  198. // create a struct that requests the base address
  199. readStruct rStruct{ 0, 0, 0, (uint32_t)GetCurrentProcessId(), PROTO_DELETE_DRIVER ,0 };
  200.  
  201. // send the struct to IOCTL
  202. WriteFile(m_hDriver, (LPCVOID)&rStruct, sizeof(ReadStruct), &at, NULL);
  203. }
  204.  
  205. void deletedriver7()
  206. {
  207. DWORD at;
  208. // create a struct that requests the base address
  209. readStruct rStruct{ 0, 0, 0, (uint32_t)GetCurrentProcessId(), PROTO_DELETE_DRIVER7 ,0 };
  210.  
  211. // send the struct to IOCTL
  212. WriteFile(m_hDriver, (LPCVOID)&rStruct, sizeof(ReadStruct), &at, NULL);
  213. }
  214.  
  215. void cleandriver()
  216. {
  217. DWORD at;
  218. // create a struct that requests the base address
  219. readStruct rStruct{ 0, 0, 0, (uint32_t)GetCurrentProcessId(), PROTO_CLEAR_DRIVER,0 };
  220. // send the struct to IOCTL
  221. WriteFile(m_hDriver, (LPCVOID)&rStruct, sizeof(ReadStruct), &at, NULL);
  222. }
  223. /*
  224. * GETTERS AND SETTERS
  225. */
  226. HANDLE getKernHandle() const
  227. {
  228. return m_hDriver;
  229. }
  230.  
  231. HANDLE getPUID() const
  232. {
  233. return m_PUID;
  234. }
  235.  
  236. int64_t getPUBase() const
  237. {
  238. return m_PUBase;
  239. }
  240.  
  241. bool isReading() const
  242. {
  243. return m_readActive;
  244. }
  245. bool isConnected() const
  246. {
  247. return m_isConnected;
  248. }
  249.  
  250. private:
  251. HANDLE m_hDriver;
  252. HANDLE m_PUID;
  253. int64_t m_PUBase;
  254. bool m_readActive;
  255. bool m_isConnected;
  256. };
  257.  
  258. extern KReader* mem;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement