PageRenderTime 12ms CodeModel.GetById 2ms app.highlight 6ms RepoModel.GetById 1ms app.codeStats 0ms

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