Advertisement
Guest User

Untitled

a guest
Feb 24th, 2017
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. #include <windows.h>
  2. #include <stdio.h>
  3.  
  4. #define CTL_READ 0x10
  5. #define CTL_WRITE 0x11
  6.  
  7. typedef struct _KRNL_REQUEST
  8. {
  9. ULONG pId;
  10. ULONG Address;
  11. ULONG ReadSize;
  12. ULONG Value;
  13. }KRNL_REQUEST, *PKRNL_REQUEST;
  14.  
  15. boolean Read(DWORD pId, DWORD ReadAddress, DWORD* ReturnValue, DWORD ReadSize)
  16. {
  17. HANDLE hFile = CreateFile("\\\\.\\Example", GENERIC_READ | GENERIC_WRITE, 0, NULL, OPEN_EXISTING, 0, NULL);
  18. if (hFile == INVALID_HANDLE_VALUE)
  19. {
  20. printf("Could not open handle! Error Code: %X\n", GetLastError());
  21. system("pause");
  22. return 0;
  23. }
  24. if (hFile)
  25. {
  26.  
  27. KRNL_REQUEST ReadRequest;
  28. ReadRequest.Address = ReadAddress;
  29. ReadRequest.pId = GetCurrentProcessId();
  30. ReadRequest.ReadSize = ReadSize;
  31. ReadRequest.Value = 0;
  32.  
  33. if (!DeviceIoControl(hFile, CTL_READ, &ReadRequest, sizeof(ReadRequest), &ReadRequest, sizeof(ReadRequest), NULL, NULL))
  34. {
  35. printf("Device Could not be contacted! Error Code: %X\n", GetLastError());
  36. CloseHandle(hFile);
  37. system("pause");
  38. return 0;
  39. }
  40. *ReturnValue = ReadRequest.Value;
  41. CloseHandle(hFile);
  42. }
  43. return 1;
  44. }
  45.  
  46. int _cdecl main(void)
  47. {
  48. float i = 10.5f;
  49. float ReturnVal = 0;
  50. Read(GetCurrentProcessId(), &i, &ReturnVal, sizeof(ReturnVal));
  51. printf("Return Value: %f", ReturnVal);
  52. system("pause");
  53. return 0;
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement