Rizin
unix-like reverse engineering framework and cli tools
windows_debug.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2015 Álvaro Felipe Melchor <alvaro.felipe91@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #ifndef WINDOWS_DEBUG_H
5 #define WINDOWS_DEBUG_H
6 /*_______
7  | | |
8  |___|___|
9  | | |
10  |___|___|
11 */
12 
13 #include <rz_types.h>
14 #include <rz_debug.h>
15 #include <rz_windows.h>
16 #include <tlhelp32.h> // CreateToolhelp32Snapshot
17 #include <psapi.h> // GetModuleFileNameEx, GetProcessImageFileName
18 #include <winternl.h>
19 #include <tchar.h>
20 #include <w32dbg_wrap.h>
21 
22 #ifndef XSTATE_GSSE
23 #define XSTATE_GSSE 2
24 #endif
25 
26 #ifndef XSTATE_LEGACY_SSE
27 #define XSTATE_LEGACY_SSE 1
28 #endif
29 
30 #if !defined(XSTATE_MASK_GSSE)
31 #define XSTATE_MASK_GSSE (1LLU << (XSTATE_GSSE))
32 #endif
33 
34 #undef CONTEXT_XSTATE
35 #if defined(_M_X64)
36 #define CONTEXT_XSTATE (0x00100040)
37 #else
38 #define CONTEXT_XSTATE (0x00010040)
39 #endif
40 #define XSTATE_AVX (XSTATE_GSSE)
41 #define XSTATE_MASK_AVX (XSTATE_MASK_GSSE)
42 #ifndef CONTEXT_ALL
43 #define CONTEXT_ALL 1048607
44 #endif
45 
46 typedef struct _SYSTEM_HANDLE {
50  USHORT Handle;
54 
59 
60 typedef enum _POOL_TYPE {
70 
71 typedef struct _OBJECT_TYPE_INFORMATION {
86  GENERIC_MAPPING GenericMapping;
95 
96 // thread list
97 typedef struct {
98  int pid;
99  int tid;
100  bool bFinished;
108 
109 typedef struct {
110  int pid;
112  void *BaseOfDll;
113  char *Path;
114  char *Name;
116 
117 // Vista
118 BOOL(WINAPI *w32_ProcessIdToSessionId)
120 BOOL(WINAPI *w32_QueryFullProcessImageNameW)
122 // Internal NT functions (winternl.h)
123 NTSTATUS(WINAPI *w32_NtQuerySystemInformation)
125 NTSTATUS(WINAPI *w32_NtQueryInformationThread)
127 NTSTATUS(WINAPI *w32_NtDuplicateObject)
129 NTSTATUS(WINAPI *w32_NtQueryObject)
131 // fpu access API (Windows 7)
132 ut64(WINAPI *w32_GetEnabledXStateFeatures)();
133 BOOL(WINAPI *w32_InitializeContext)
134 (PVOID, DWORD, PCONTEXT *, PDWORD);
135 BOOL(WINAPI *w32_GetXStateFeaturesMask)
136 (PCONTEXT Context, PDWORD64);
137 PVOID(WINAPI *w32_LocateXStateFeature)
138 (PCONTEXT Context, DWORD, PDWORD);
139 BOOL(WINAPI *w32_SetXStateFeaturesMask)
140 (PCONTEXT Context, DWORD64);
141 
142 // APIs
143 int w32_init(RzDebug *dbg);
144 
145 int w32_reg_read(RzDebug *dbg, int type, ut8 *buf, int size);
146 int w32_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size);
147 
148 int w32_attach(RzDebug *dbg, int pid);
149 int w32_detach(RzDebug *dbg, int pid);
151 int w32_select(RzDebug *dbg, int pid, int tid);
152 int w32_kill(RzDebug *dbg, int pid, int tid, int sig);
153 void w32_break_process(void *user);
154 int w32_dbg_wait(RzDebug *dbg, int pid);
155 
156 int w32_step(RzDebug *dbg);
157 int w32_continue(RzDebug *dbg, int pid, int tid, int sig);
160 int w32_map_protect(RzDebug *dbg, ut64 addr, int size, int perms);
161 
163 RzDebugInfo *w32_info(RzDebug *dbg, const char *arg);
164 
166 
167 RzList *w32_desc_list(int pid);
168 
169 #if __arm64__
172 #endif
173 
174 #endif
RzDebug * dbg
Definition: desil.c:30
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
static void list(RzEgg *egg)
Definition: rz-gg.c:52
static static fork const void static count static fd const char const char static newpath char char char static envp time_t static t const char static mode static whence const char static dir time_t static t unsigned static seconds const char struct utimbuf static buf static inc pid
Definition: sflib.h:64
unsigned char BYTE
Definition: lz4.c:286
int type
Definition: mipsasm.c:17
#define b(i)
Definition: sha256.c:42
void * BaseOfDll
char * Path
char * Name
HANDLE hFile
PVOID lpThreadEntryPoint
DWORD dwExitCode
LPVOID lpThreadLocalBase
HANDLE hThread
LPVOID lpStartAddress
GENERIC_MAPPING GenericMapping
Definition: windows_debug.h:86
SYSTEM_HANDLE Handles[1]
Definition: windows_debug.h:57
ACCESS_MASK GrantedAccess
Definition: windows_debug.h:52
Definition: rz_bp.h:78
LONG NTSTATUS
Definition: win.h:198
int w32_hwbp_arm_del(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b)
int w32_hwbp_arm_add(RzDebug *dbg, RzBreakpoint *bp, RzBreakpointItem *b)
DWORD LPWSTR
ACCESS_MASK
DWORD PDWORD
RzDebugInfo * w32_info(RzDebug *dbg, const char *arg)
int w32_attach_new_process(RzDebug *dbg, int pid)
int w32_attach(RzDebug *dbg, int pid)
_POOL_TYPE
Definition: windows_debug.h:60
@ PagedPoolCacheAligned
Definition: windows_debug.h:66
@ NonPagedPoolCacheAligned
Definition: windows_debug.h:65
@ NonPagedPoolCacheAlignedMustS
Definition: windows_debug.h:67
@ NonPagedPool
Definition: windows_debug.h:61
@ DontUseThisType
Definition: windows_debug.h:64
@ NonPagedPoolMustSucceed
Definition: windows_debug.h:63
@ PagedPool
Definition: windows_debug.h:62
struct LIB_ITEM * PLIB_ITEM
PCONTEXT Context
struct _SYSTEM_HANDLE_INFORMATION * PSYSTEM_HANDLE_INFORMATION
DWORD * HANDLE
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
struct THREAD_ITEM * PTHREAD_ITEM
enum _POOL_TYPE POOL_TYPE
struct _SYSTEM_HANDLE_INFORMATION SYSTEM_HANDLE_INFORMATION
int w32_step(RzDebug *dbg)
PHANDLE
enum _POOL_TYPE * PPOOL_TYPE
PCONTEXT PDWORD64
ULONG
int w32_map_protect(RzDebug *dbg, ut64 addr, int size, int perms)
RzList * w32_thread_list(RzDebug *dbg, int pid, RzList *list)
void w32_break_process(void *user)
int w32_map_dealloc(RzDebug *dbg, ut64 addr, int size)
struct _OBJECT_TYPE_INFORMATION * POBJECT_TYPE_INFORMATION
int w32_init(RzDebug *dbg)
Definition: windows_debug.c:37
int w32_dbg_wait(RzDebug *dbg, int pid)
RzList * w32_pid_list(RzDebug *dbg, int pid, RzList *list)
PVOID
int w32_kill(RzDebug *dbg, int pid, int tid, int sig)
PCONTEXT DWORD64
int w32_reg_read(RzDebug *dbg, int type, ut8 *buf, int size)
int w32_continue(RzDebug *dbg, int pid, int tid, int sig)
struct _SYSTEM_HANDLE * PSYSTEM_HANDLE
struct _OBJECT_TYPE_INFORMATION OBJECT_TYPE_INFORMATION
DWORD
struct _SYSTEM_HANDLE SYSTEM_HANDLE
int w32_detach(RzDebug *dbg, int pid)
int w32_select(RzDebug *dbg, int pid, int tid)
int w32_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size)
PULONG
RzList * w32_desc_list(int pid)
RzDebugMap * w32_map_alloc(RzDebug *dbg, ut64 addr, int size)
static int addr
Definition: z80asm.c:58