Rizin
unix-like reverse engineering framework and cli tools
winkd.h
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2014-2017 LemonBoy <thatlemon@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #ifndef _winkd_H_
5 #define _winkd_H_
6 
7 #include <rz_util.h>
8 #include <stdint.h>
9 #include "kd.h"
10 
11 typedef struct WindProc {
17  char name[17];
19 
20 typedef struct WindThread {
22  bool runnable;
23  char status;
27 
28 typedef struct WindModule {
29  char *name;
34 
35 typedef struct WindMap {
36  char *file;
41 
42 enum {
43  K_PaeEnabled = 0x036,
47 };
48 
49 enum {
50  E_ActiveProcessLinks, // EPROCESS
51  E_UniqueProcessId, // EPROCESS
52  E_Peb, // EPROCESS
53  E_ImageFileName, // EPROCESS
54  E_VadRoot, // EPROCESS
55  E_ThreadListHead, // EPROCESS
56  K_DirectoryTableBase, // KPROCESS
59  RZ_ImagePathName, // RTL_USER_PROCESS_PARAMETERS
60  ET_ApcProcess, // ETHREAD
61  ET_ThreadListEntry, // ETHREAD
63  ET_Cid, // ETHREAD
64  C_UniqueThread, // CLIENT_ID
66 };
67 
68 typedef struct {
69  int build;
70  int sp;
71  int bits;
72  int flags;
73  int f[O_Max];
74 } Profile;
75 
76 typedef int WindReadAt(RZ_NONNULL void *user, ut64 address, RZ_BORROW RZ_NONNULL RZ_OUT ut8 *buf, int count);
77 typedef int WindWriteAt(RZ_NONNULL void *user, ut64 address, RZ_BORROW RZ_NONNULL RZ_IN const ut8 *buf, int count);
78 
79 typedef struct _WindCtx {
84  void *user;
88  bool is_64bit;
89  bool is_pae;
90  bool is_arm;
94 
95 typedef struct _KdCtx {
100  int syncd;
102  int cpu;
110  bool breaked;
112 
113 #define TARGET_BACKEND 0
114 #define TARGET_PHYSICAL 1
115 #define TARGET_KERNEL 2
116 #define TARGET_VIRTUAL 3
117 
118 typedef struct _DmpCtx {
121  ut64 target; // TARGET_BACKEND, TARGET_PHYSICAL, or DirectoryTable
125  ut32 kprcb_context_offset; // nt!_KPRCB ProcessorState.ContextFrame
126  ut32 kthread_switch_frame_offset; // nt!_KTHREAD SwitchFrame.Fp
127  ut32 kthread_process_offset; // nt!_KTHREAD Process
129  size_t context_sz;
130  void *bf; // RzBinFile * of DMP File
132 
134  ut8 ptr_buf[8];
135  if (!read_at_func(ctx->user, at, ptr_buf, ctx->is_64bit ? 8 : 4)) {
136  return 0;
137  }
138  return ctx->is_64bit ? rz_read_le64(ptr_buf) : rz_read_le32(ptr_buf);
139 }
140 
142  free(ctx->user);
143  free(ctx->profile);
144 }
145 
146 // grep -e "^winkd_" subprojects/rzwinkd/winkd.c | sed -e 's/ {$/;/' -e 's/^/int /'
149 Profile *winkd_get_profile(int bits, int build, int sp);
159 void winkd_windmodule_free(void *ptr);
164 
173 int winkd_continue(RZ_BORROW RZ_NONNULL KdCtx *ctx, bool handled);
176 int winkd_query_mem(RZ_BORROW RZ_NONNULL KdCtx *ctx, const ut64 addr, int *address_space, int *flags);
177 int winkd_bkpt(RZ_BORROW RZ_NONNULL KdCtx *ctx, const ut64 addr, const int set, const int hw, RZ_BORROW RZ_NONNULL int *handle);
182 void winkd_break(void *ctx);
185 #endif
static ut32 cpu[32]
Definition: analysis_or1k.c:21
static mcore_handle handle
Definition: asm_mcore.c:8
const char * desc
Definition: bin_vsf.c:19
int bits(struct state *s, int need)
Definition: blast.c:72
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void count
Definition: sflib.h:98
uint32_t ut32
static RzBuffer * build(RzEgg *egg)
Definition: egg_bind.c:144
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
voidpf uLong offset
Definition: ioapi.h:144
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * p
Definition: libc.cpp:67
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
int type
Definition: mipsasm.c:17
static ut32 rz_read_le32(const void *src)
Definition: rz_endian.h:239
static ut64 rz_read_le64(const void *src)
Definition: rz_endian.h:266
#define RZ_IN
Definition: rz_types.h:50
#define RZ_NULLABLE
Definition: rz_types.h:65
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_OUT
Definition: rz_types.h:51
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_BORROW
Definition: rz_types.h:63
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
#define f(i)
Definition: sha256.c:46
Definition: winkd.h:68
int flags
Definition: winkd.h:72
int sp
Definition: winkd.h:70
int build
Definition: winkd.h:69
int bits
Definition: winkd.h:71
Definition: winkd.h:35
ut32 perm
Definition: winkd.h:39
ut64 start
Definition: winkd.h:37
ut64 end
Definition: winkd.h:38
char * file
Definition: winkd.h:36
ut32 size
Definition: winkd.h:31
ut32 timestamp
Definition: winkd.h:32
char * name
Definition: winkd.h:29
ut64 addr
Definition: winkd.h:30
Definition: winkd.h:11
ut64 peb
Definition: winkd.h:16
ut64 eprocess
Definition: winkd.h:12
ut64 vadroot
Definition: winkd.h:14
ut32 uniqueid
Definition: winkd.h:13
ut64 dir_base_table
Definition: winkd.h:15
ut64 entrypoint
Definition: winkd.h:25
ut64 ethread
Definition: winkd.h:24
bool runnable
Definition: winkd.h:22
char status
Definition: winkd.h:23
ut32 uniqueid
Definition: winkd.h:21
Definition: winkd.h:118
RzVector KiProcessorBlock
Definition: winkd.h:124
size_t context_sz
Definition: winkd.h:129
void * bf
Definition: winkd.h:130
RzIODesc * backend
Definition: winkd.h:123
ut64 kernelDirectoryTable
Definition: winkd.h:122
ut32 kthread_process_offset
Definition: winkd.h:127
ut32 kprcb_context_offset
Definition: winkd.h:125
ut32 type
Definition: winkd.h:120
ut64 target
Definition: winkd.h:121
ut32 kthread_switch_frame_offset
Definition: winkd.h:126
WindCtx windctx
Definition: winkd.h:119
ut8 * context
Definition: winkd.h:128
Definition: winkd.h:95
int cpu_count
Definition: winkd.h:101
ut32 seq_id
Definition: winkd.h:98
WindCtx windctx
Definition: winkd.h:96
RzList * tlist_cache
Definition: winkd.h:104
RzList * plist_cache
Definition: winkd.h:103
int syncd
Definition: winkd.h:100
int cpu
Definition: winkd.h:102
ut8 * context_cache
Definition: winkd.h:107
bool context_cache_valid
Definition: winkd.h:109
int context_cache_size
Definition: winkd.h:108
RzThreadLock * dontmix
Definition: winkd.h:105
WindModule kernel_module
Definition: winkd.h:106
io_desc_t * desc
Definition: winkd.h:97
ut32 last_received_id
Definition: winkd.h:99
bool breaked
Definition: winkd.h:110
Definition: winkd.h:79
ut64 PsActiveProcessHead
Definition: winkd.h:87
WindThread target_thread
Definition: winkd.h:92
bool is_pae
Definition: winkd.h:89
ut64 PsLoadedModuleList
Definition: winkd.h:86
WindProc target
Definition: winkd.h:91
Profile * profile
Definition: winkd.h:80
void * user
Definition: winkd.h:84
WindReadAt * read_at_physical
Definition: winkd.h:81
WindReadAt * read_at_kernel_virtual
Definition: winkd.h:82
bool is_arm
Definition: winkd.h:90
ut64 KdDebuggerDataBlock
Definition: winkd.h:85
bool is_64bit
Definition: winkd.h:88
WindWriteAt * write_at_physical
Definition: winkd.h:83
Definition: z80asm.h:102
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
int WindReadAt(RZ_NONNULL void *user, ut64 address, RZ_BORROW RZ_NONNULL RZ_OUT ut8 *buf, int count)
Definition: winkd.h:76
@ K_OffsetKThreadApcProcess
Definition: winkd.h:46
@ K_CmNtCSDVersion
Definition: winkd.h:45
@ K_PsActiveProcessHead
Definition: winkd.h:44
@ K_PaeEnabled
Definition: winkd.h:43
struct WindModule WindModule
int winkd_read_at_uva(RZ_BORROW RZ_NONNULL WindCtx *ctx, ut64 offset, RZ_BORROW RZ_NONNULL RZ_OUT ut8 *buf, int count)
Definition: winkd.c:596
bool winkd_va_to_pa(RZ_BORROW RZ_NONNULL WindCtx *ctx, ut64 directory_table, ut64 va, RZ_BORROW RZ_NONNULL RZ_OUT ut64 *pa)
Definition: winkd.c:860
@ P_ProcessParameters
Definition: winkd.h:58
@ C_UniqueThread
Definition: winkd.h:64
@ E_Peb
Definition: winkd.h:52
@ E_UniqueProcessId
Definition: winkd.h:51
@ ET_Win32StartAddress
Definition: winkd.h:62
@ ET_ApcProcess
Definition: winkd.h:60
@ E_ActiveProcessLinks
Definition: winkd.h:50
@ K_DirectoryTableBase
Definition: winkd.h:56
@ ET_Cid
Definition: winkd.h:63
@ E_VadRoot
Definition: winkd.h:54
@ O_Max
Definition: winkd.h:65
@ RZ_ImagePathName
Definition: winkd.h:59
@ E_ImageFileName
Definition: winkd.h:53
@ ET_ThreadListEntry
Definition: winkd.h:61
@ E_ThreadListHead
Definition: winkd.h:55
@ P_ImageBaseAddress
Definition: winkd.h:57
ut64 winkd_get_target_base(RZ_BORROW RZ_NONNULL WindCtx *ctx)
Definition: winkd.c:166
void winkd_break(void *ctx)
Definition: winkd.c:1442
int winkd_write_at(RZ_BORROW RZ_NONNULL KdCtx *ctx, const ut64 offset, RZ_BORROW RZ_NONNULL RZ_IN const ut8 *buf, const int count)
Definition: winkd.c:1384
bool winkd_read_ver(RZ_BORROW RZ_NONNULL KdCtx *ctx)
Definition: winkd.c:997
ut32 winkd_get_target(RZ_BORROW RZ_NONNULL WindCtx *ctx)
Definition: winkd.c:158
WindThread * winkd_get_thread_at(RZ_BORROW RZ_NONNULL WindCtx *ctx, ut64 address)
Definition: winkd.c:739
bool winkd_lock_leave(RZ_BORROW RZ_NONNULL KdCtx *ctx)
Definition: winkd.c:34
int winkd_write_at_phys(RZ_BORROW RZ_NONNULL KdCtx *ctx, const ut64 offset, RZ_BORROW RZ_NONNULL RZ_IN const ut8 *buf, const int count)
Definition: winkd.c:1408
int WindWriteAt(RZ_NONNULL void *user, ut64 address, RZ_BORROW RZ_NONNULL RZ_IN const ut8 *buf, int count)
Definition: winkd.h:77
struct WindProc WindProc
int winkd_read_at(RZ_BORROW RZ_NONNULL KdCtx *ctx, const ut64 offset, RZ_BORROW RZ_NONNULL RZ_OUT ut8 *buf, const int count)
Definition: winkd.c:1377
struct _KdCtx KdCtx
Profile * winkd_get_profile(int bits, int build, int sp)
Definition: winkd.c:58
static void winkd_ctx_fini(RZ_BORROW RZ_NONNULL WindCtx *ctx)
Definition: winkd.h:141
RzList * winkd_list_threads(RZ_BORROW RZ_NONNULL WindCtx *ctx)
Definition: winkd.c:782
int winkd_wait_packet(RZ_BORROW RZ_NONNULL KdCtx *ctx, const ut32 type, RZ_NULLABLE RZ_OUT kd_packet_t **p)
Definition: winkd.c:258
int winkd_get_cpus(RZ_BORROW RZ_NONNULL KdCtx *ctx)
Definition: winkd.c:84
void winkd_kdctx_free(RZ_OWN KdCtx **ctx)
Definition: winkd.c:187
int winkd_get_cpu(RZ_BORROW RZ_NONNULL KdCtx *ctx)
Definition: winkd.c:99
int winkd_read_reg(RZ_BORROW RZ_NONNULL KdCtx *ctx, RZ_BORROW RZ_NONNULL RZ_OUT ut8 *buf, int size)
Definition: winkd.c:1231
RzList * winkd_list_maps(RZ_BORROW RZ_NONNULL WindCtx *ctx)
Definition: winkd.c:476
int winkd_get_sp(RZ_BORROW RZ_NONNULL WindCtx *ctx)
Definition: winkd.c:40
int winkd_write_at_uva(RZ_BORROW RZ_NONNULL WindCtx *ctx, ut64 offset, RZ_BORROW RZ_NONNULL RZ_IN const ut8 *buf, int count)
Definition: winkd.c:600
bool winkd_write_reg(RZ_BORROW RZ_NONNULL KdCtx *ctx, ut32 flags, RZ_BORROW RZ_NONNULL RZ_IN const ut8 *buf, int size)
Definition: winkd.c:1179
void winkd_windmodule_free(void *ptr)
Definition: winkd.c:611
ut32 winkd_get_target_thread(RZ_BORROW RZ_NONNULL WindCtx *ctx)
Definition: winkd.c:162
RzList * winkd_list_modules(RZ_BORROW RZ_NONNULL WindCtx *ctx)
Definition: winkd.c:625
struct _DmpCtx DmpCtx
bool winkd_set_cpu(RZ_BORROW RZ_NONNULL KdCtx *ctx, int cpu)
Definition: winkd.c:91
int winkd_read_at_phys(RZ_BORROW RZ_NONNULL KdCtx *ctx, const ut64 offset, RZ_BORROW RZ_NONNULL RZ_OUT ut8 *buf, const int count)
Definition: winkd.c:1370
int winkd_continue(RZ_BORROW RZ_NONNULL KdCtx *ctx, bool handled)
Definition: winkd.c:1141
bool winkd_set_target(RZ_BORROW RZ_NONNULL WindCtx *ctx, ut32 pid, ut32 tid)
Definition: winkd.c:106
struct WindMap WindMap
struct _WindCtx WindCtx
KdCtx * winkd_kdctx_new(RZ_BORROW RZ_NONNULL io_desc_t *desc)
Definition: winkd.c:177
bool winkd_lock_enter(RZ_BORROW RZ_NONNULL KdCtx *ctx)
Definition: winkd.c:23
int winkd_sync(RZ_BORROW RZ_NONNULL KdCtx *ctx)
Definition: winkd.c:1065
int winkd_query_mem(RZ_BORROW RZ_NONNULL KdCtx *ctx, const ut64 addr, int *address_space, int *flags)
Definition: winkd.c:1276
struct WindThread WindThread
WindProc * winkd_get_process_at(RZ_BORROW RZ_NONNULL WindCtx *ctx, ut64 address)
Definition: winkd.c:488
int winkd_bkpt(RZ_BORROW RZ_NONNULL KdCtx *ctx, const ut64 addr, const int set, const int hw, RZ_BORROW RZ_NONNULL int *handle)
Definition: winkd.c:1312
static ut64 winkd_read_ptr_at(RZ_BORROW RZ_NONNULL WindCtx *ctx, RZ_BORROW RZ_NONNULL WindReadAt *read_at_func, ut64 at)
Definition: winkd.h:133
RzList * winkd_list_process(RZ_BORROW RZ_NONNULL WindCtx *ctx)
Definition: winkd.c:513
int winkd_get_bits(RZ_BORROW RZ_NONNULL WindCtx *ctx)
Definition: winkd.c:80
static int sp
Definition: z80asm.c:91
static int addr
Definition: z80asm.c:58