/inc/win_structs.h

https://code.google.com/p/dwarftherapist/ · C Header · 67 lines · 39 code · 6 blank · 22 comment · 0 complexity · 68a7ed3a662482679387fecf14e271d1 MD5 · raw file

  1. /*
  2. Dwarf Therapist
  3. Copyright (c) 2009 Trey Stout (chmod)
  4. Permission is hereby granted, free of charge, to any person obtaining a copy
  5. of this software and associated documentation files (the "Software"), to deal
  6. in the Software without restriction, including without limitation the rights
  7. to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
  8. copies of the Software, and to permit persons to whom the Software is
  9. furnished to do so, subject to the following conditions:
  10. The above copyright notice and this permission notice shall be included in
  11. all copies or substantial portions of the Software.
  12. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  13. IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  14. FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
  15. AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  16. LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
  17. OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
  18. THE SOFTWARE.
  19. */
  20. #ifndef WIN_STRUCTS_H
  21. #define WIN_STRUCTS_H
  22. #include <windows.h>
  23. #include <ntsecapi.h>
  24. #include <stdio.h>
  25. typedef struct _PEB {
  26. bool InheritedAddressSpace;
  27. bool ReadImageFileExecOptions;
  28. bool BeingDebugged;
  29. bool Spare;
  30. HANDLE Mutant;
  31. PVOID ImageBaseAddress;
  32. } PEB, *PPEB;
  33. typedef NTSTATUS (NTAPI *_NtQueryInformationProcess)(
  34. HANDLE ProcessHandle,
  35. DWORD ProcessInformationClass,
  36. PVOID ProcessInformation,
  37. DWORD ProcessInformationLength,
  38. PDWORD ReturnLength
  39. );
  40. typedef struct _PROCESS_BASIC_INFORMATION
  41. {
  42. DWORD ExitStatus;
  43. PVOID PebBaseAddress;
  44. DWORD AffinityMask;
  45. DWORD BasePriority;
  46. DWORD UniqueProcessId;
  47. DWORD ParentProcessId;
  48. } PROCESS_BASIC_INFORMATION, *PPROCESS_BASIC_INFORMATION;
  49. PVOID GetPebAddress(HANDLE ProcessHandle)
  50. {
  51. _NtQueryInformationProcess NtQueryInformationProcess =
  52. (_NtQueryInformationProcess)GetProcAddress(
  53. GetModuleHandleA("ntdll.dll"), "NtQueryInformationProcess");
  54. PROCESS_BASIC_INFORMATION pbi;
  55. NtQueryInformationProcess(ProcessHandle, 0, &pbi, sizeof(pbi), NULL);
  56. return pbi.PebBaseAddress;
  57. }
  58. #endif // WIN_STRUCTS_H