Rizin
unix-like reverse engineering framework and cli tools
io_windbg.c File Reference
#include <rz_core.h>
#include <DbgEng.h>

Go to the source code of this file.

Classes

struct  DbgEngContext
 

Macros

#define INITGUID
 
#define WINDBGURI   "windbg://"
 
#define THISCALL(dbginterface, function, ...)   dbginterface->lpVtbl->function(dbginterface, __VA_ARGS__)
 
#define ITHISCALL(dbginterface, function, ...)   THISCALL(idbg->dbginterface, function, __VA_ARGS__)
 
#define DECLARE_CALLBACKS_IMPL(Type, IFace)
 
#define INIT_IUNKNOWN_CALLBACKS(IFace, lpVtbl)
 
#define DECLARE_NEW(IFace, IVtbl)
 
#define DECLARE_QUERYINTERFACE(IFace, IFaceIID)
 
#define DECLARE_ADDREF(IFace)
 
#define DECLARE_RELEASE(IFace)
 
#define RELEASE(I)
 
#define RELEASE(I)
 

Typedefs

typedef HRESULT(__stdcall * DebugCreate_t) (_In_ REFIID InterfaceId, _Out_ PVOID *Interface)
 
typedef HRESULT(__stdcall * DebugConnectWide_t) (_In_ PCWSTR RemoteOptions, _In_ REFIID InterfaceId, _Out_ PVOID *Interface)
 

Enumerations

enum  DbgEngTarget {
  TARGET_LOCAL_SPAWN , TARGET_LOCAL_ATTACH , TARGET_LOCAL_KERNEL , TARGET_DUMP_FILE ,
  TARGET_KERNEL
}
 

Functions

static STDMETHODIMP __interest_mask (PDEBUG_EVENT_CALLBACKS This, PULONG Mask)
 
static STDMETHODIMP __createprocess_cb (PDEBUG_EVENT_CALLBACKS This, ULONG64 ImageFileHandle, ULONG64 Handle, ULONG64 BaseOffset, ULONG ModuleSize, PCSTR ModuleName, PCSTR ImageName, ULONG CheckSum, ULONG TimeDateStamp, ULONG64 InitialThreadHandle, ULONG64 ThreadDataOffset, ULONG64 StartOffset)
 
static STDMETHODIMP __breakpoint_cb (PDEBUG_EVENT_CALLBACKS This, PDEBUG_BREAKPOINT Bp)
 
static STDMETHODIMP __exception_cb (PDEBUG_EVENT_CALLBACKS This, PEXCEPTION_RECORD64 Exception, ULONG FirstChance)
 
static STDMETHODIMP __exit_process_cb (PDEBUG_EVENT_CALLBACKS This, ULONG ExitCode)
 
static STDMETHODIMP __system_error_cb (PDEBUG_EVENT_CALLBACKS This, ULONG Error, ULONG Level)
 
static STDMETHODIMP __input_cb (PDEBUG_INPUT_CALLBACKS This, ULONG BufferSize)
 
static STDMETHODIMP __input_end_cb (PDEBUG_INPUT_CALLBACKS This)
 
static STDMETHODIMP __output_cb (PDEBUG_OUTPUT_CALLBACKS This, ULONG Mask, PCSTR Text)
 
static void DEBUG_EVENT_CALLBACKS_vtbl_init (PDEBUG_EVENT_CALLBACKS callbacks)
 
static void DEBUG_INPUT_CALLBACKS_vtbl_init (PDEBUG_INPUT_CALLBACKS callbacks)
 
static void DEBUG_OUTPUT_CALLBACKS_vtbl_init (PDEBUG_OUTPUT_CALLBACKS callbacks)
 
static void __free_context (DbgEngContext *idbg)
 
static bool init_callbacks (DbgEngContext *idbg)
 
static DbgEngContextcreate_remote_context (const char *opts)
 
static DbgEngContextcreate_context (void)
 
static int windbg_init (void)
 
static bool windbg_check (RzIO *io, const char *uri, bool many)
 
static bool cur_dbg_plugin_is_windbg (RzDebug *dbg)
 
static RzIODescwindbg_open (RzIO *io, const char *uri, int perm, int mode)
 
static int windbg_close (RzIODesc *fd)
 
static ut64 windbg_lseek (RzIO *io, RzIODesc *fd, ut64 offset, int whence)
 
static int windbg_read (RzIO *io, RzIODesc *fd, ut8 *buf, int count)
 
static int windbg_write (RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
 
static int windbg_getpid (RzIODesc *fd)
 
static int windbg_gettid (RzIODesc *fd)
 
static bool windbg_getbase (RzIODesc *fd, ut64 *base)
 
static char * windbg_system (RzIO *io, RzIODesc *fd, const char *cmd)
 

Variables

static DebugCreate_t w32_DebugCreate = NULL
 
static DebugConnectWide_t w32_DebugConnectWide = NULL
 
RzIOPlugin rz_io_plugin_windbg
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ DECLARE_ADDREF

#define DECLARE_ADDREF (   IFace)
Value:
static STDMETHODIMP_(ULONG) IFace##_AddRef_impl( \
P##IFace This) { \
P##IFace##_IMPL impl = (P##IFace##_IMPL)This; \
return InterlockedIncrement(&impl->m_ref); \
}
#define P
InterlockedIncrement
Definition: kernel.h:56
ULONG

Definition at line 88 of file io_windbg.c.

◆ DECLARE_CALLBACKS_IMPL

#define DECLARE_CALLBACKS_IMPL (   Type,
  IFace 
)
Value:
typedef struct IFace##_impl { \
IFace *lpVtbl; \
DbgEngContext *m_idbg; \
LONG m_ref; \
} Type##_IMPL, *P##Type##_IMPL;
Definition: swift.c:7

Definition at line 39 of file io_windbg.c.

◆ DECLARE_NEW

#define DECLARE_NEW (   IFace,
  IVtbl 
)
Value:
static P##IFace IFace##_impl_new( \
DbgEngContext *idbg) { \
if (!idbg) { \
return NULL; \
} \
P##IFace##_IMPL callbacks = RZ_NEW(IFace##_IMPL); \
if (!callbacks) { \
return NULL; \
} \
callbacks->lpVtbl = RZ_NEW(IVtbl); \
if (!callbacks->lpVtbl) { \
free(callbacks); \
return NULL; \
} \
IFace##_vtbl_init((P##IFace)callbacks); \
callbacks->m_idbg = idbg; \
callbacks->m_ref = 1; \
return (P##IFace)callbacks; \
}
#define NULL
Definition: cris-opc.c:27
#define RZ_NEW(x)
Definition: rz_types.h:285

Definition at line 51 of file io_windbg.c.

◆ DECLARE_QUERYINTERFACE

#define DECLARE_QUERYINTERFACE (   IFace,
  IFaceIID 
)
Value:
static STDMETHODIMP IFace##_QueryInterface_impl( \
P##IFace This, \
_In_ REFIID InterfaceId, \
_Out_ PVOID *Interface) { \
if (IsEqualIID(InterfaceId, &IID_IUnknown) || \
IsEqualIID(InterfaceId, &IFaceIID)) { \
*Interface = This; \
THISCALL(This, AddRef); \
return S_OK; \
} else { \
return E_NOINTERFACE; \
} \
}
PVOID

Definition at line 72 of file io_windbg.c.

◆ DECLARE_RELEASE

#define DECLARE_RELEASE (   IFace)
Value:
static STDMETHODIMP_(ULONG) IFace##_Release_impl( \
P##IFace This) { \
P##IFace##_IMPL impl = (P##IFace##_IMPL)This; \
LONG ret = InterlockedDecrement(&impl->m_ref); \
if (!ret) { \
free(This->lpVtbl); \
free(This); \
} \
return ret; \
}
InterlockedDecrement
Definition: kernel.h:55

Definition at line 95 of file io_windbg.c.

◆ INIT_IUNKNOWN_CALLBACKS

#define INIT_IUNKNOWN_CALLBACKS (   IFace,
  lpVtbl 
)
Value:
lpVtbl->QueryInterface = IFace##_QueryInterface_impl; \
lpVtbl->AddRef = IFace##_AddRef_impl; \
lpVtbl->Release = IFace##_Release_impl

Definition at line 46 of file io_windbg.c.

◆ INITGUID

#define INITGUID

Definition at line 4 of file io_windbg.c.

◆ ITHISCALL

#define ITHISCALL (   dbginterface,
  function,
  ... 
)    THISCALL(idbg->dbginterface, function, __VA_ARGS__)

Definition at line 37 of file io_windbg.c.

◆ RELEASE [1/2]

#define RELEASE (   I)
Value:
if (idbg->I) { \
ITHISCALL(I, Release); \
idbg->I = NULL; \
}
#define I(x)
Definition: arc.h:164

◆ RELEASE [2/2]

#define RELEASE (   I)
Value:
if (I) \
THISCALL(I, Release);

◆ THISCALL

#define THISCALL (   dbginterface,
  function,
  ... 
)    dbginterface->lpVtbl->function(dbginterface, __VA_ARGS__)

Definition at line 36 of file io_windbg.c.

◆ WINDBGURI

#define WINDBGURI   "windbg://"

Definition at line 20 of file io_windbg.c.

Typedef Documentation

◆ DebugConnectWide_t

typedef HRESULT(__stdcall * DebugConnectWide_t) (_In_ PCWSTR RemoteOptions, _In_ REFIID InterfaceId, _Out_ PVOID *Interface)

Definition at line 12 of file io_windbg.c.

◆ DebugCreate_t

typedef HRESULT(__stdcall * DebugCreate_t) (_In_ REFIID InterfaceId, _Out_ PVOID *Interface)

Definition at line 8 of file io_windbg.c.

Enumeration Type Documentation

◆ DbgEngTarget

Enumerator
TARGET_LOCAL_SPAWN 
TARGET_LOCAL_ATTACH 
TARGET_LOCAL_KERNEL 
TARGET_DUMP_FILE 
TARGET_KERNEL 

Definition at line 392 of file io_windbg.c.

392  {
398 } DbgEngTarget;
DbgEngTarget
Definition: io_windbg.c:392
@ TARGET_KERNEL
Definition: io_windbg.c:397
@ TARGET_DUMP_FILE
Definition: io_windbg.c:396
@ TARGET_LOCAL_KERNEL
Definition: io_windbg.c:395
@ TARGET_LOCAL_SPAWN
Definition: io_windbg.c:393
@ TARGET_LOCAL_ATTACH
Definition: io_windbg.c:394

Function Documentation

◆ __breakpoint_cb()

static STDMETHODIMP __breakpoint_cb ( PDEBUG_EVENT_CALLBACKS  This,
PDEBUG_BREAKPOINT  Bp 
)
static

Definition at line 136 of file io_windbg.c.

136  {
137  return DEBUG_STATUS_BREAK;
138 }

Referenced by DEBUG_EVENT_CALLBACKS_vtbl_init().

◆ __createprocess_cb()

static STDMETHODIMP __createprocess_cb ( PDEBUG_EVENT_CALLBACKS  This,
ULONG64  ImageFileHandle,
ULONG64  Handle,
ULONG64  BaseOffset,
ULONG  ModuleSize,
PCSTR  ModuleName,
PCSTR  ImageName,
ULONG  CheckSum,
ULONG  TimeDateStamp,
ULONG64  InitialThreadHandle,
ULONG64  ThreadDataOffset,
ULONG64  StartOffset 
)
static

Definition at line 118 of file io_windbg.c.

130  {
131  PDEBUG_EVENT_CALLBACKS_IMPL impl = (PDEBUG_EVENT_CALLBACKS_IMPL)This;
132  impl->m_idbg->processBase = BaseOffset;
133  return DEBUG_STATUS_BREAK;
134 }

Referenced by DEBUG_EVENT_CALLBACKS_vtbl_init().

◆ __exception_cb()

static STDMETHODIMP __exception_cb ( PDEBUG_EVENT_CALLBACKS  This,
PEXCEPTION_RECORD64  Exception,
ULONG  FirstChance 
)
static

Definition at line 140 of file io_windbg.c.

140  {
141  return DEBUG_STATUS_BREAK;
142 }

Referenced by DEBUG_EVENT_CALLBACKS_vtbl_init().

◆ __exit_process_cb()

static STDMETHODIMP __exit_process_cb ( PDEBUG_EVENT_CALLBACKS  This,
ULONG  ExitCode 
)
static

Definition at line 144 of file io_windbg.c.

144  {
145  return DEBUG_STATUS_BREAK;
146 }

Referenced by DEBUG_EVENT_CALLBACKS_vtbl_init().

◆ __free_context()

static void __free_context ( DbgEngContext idbg)
static

Definition at line 210 of file io_windbg.c.

210  {
211 #define RELEASE(I) \
212  if (idbg->I) { \
213  ITHISCALL(I, Release); \
214  idbg->I = NULL; \
215  }
216  RELEASE(dbgAdvanced);
217  RELEASE(dbgClient);
218  RELEASE(dbgCtrl);
219  RELEASE(dbgData);
220  RELEASE(dbgReg);
221  RELEASE(dbgSymbols);
222  RELEASE(dbgSysObj);
223  free(idbg);
224 #undef RELEASE
225 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define RELEASE(I)

References free(), and RELEASE.

Referenced by create_context(), create_remote_context(), windbg_close(), and windbg_open().

◆ __input_cb()

static STDMETHODIMP __input_cb ( PDEBUG_INPUT_CALLBACKS  This,
ULONG  BufferSize 
)
static

Definition at line 152 of file io_windbg.c.

152  {
153  char prompt[512];
154  PDEBUG_INPUT_CALLBACKS_IMPL impl = (PDEBUG_INPUT_CALLBACKS_IMPL)This;
155  DbgEngContext *idbg = impl->m_idbg;
156  ITHISCALL(dbgCtrl, GetPromptText, prompt, sizeof(prompt), NULL);
158  const char *str = rz_line_readline();
159  char *ret = rz_str_ndup(str, RZ_MIN(strlen(str), BufferSize));
160  ITHISCALL(dbgCtrl, ReturnInput, ret);
161  return S_OK;
162 }
RZ_API const char * rz_line_readline(void)
Definition: dietline.c:913
#define ITHISCALL(dbginterface, function,...)
Definition: io_windbg.c:37
RZ_API void rz_line_set_prompt(const char *prompt)
Definition: line.c:56
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006
#define RZ_MIN(x, y)
static char * prompt(const char *str, const char *txt)
Definition: vmenus.c:30

References ITHISCALL, NULL, prompt(), rz_line_readline(), rz_line_set_prompt(), RZ_MIN, rz_str_ndup(), and cmd_descs_generate::str.

Referenced by DEBUG_INPUT_CALLBACKS_vtbl_init().

◆ __input_end_cb()

static STDMETHODIMP __input_end_cb ( PDEBUG_INPUT_CALLBACKS  This)
static

Definition at line 164 of file io_windbg.c.

164  {
165  return S_OK;
166 }

Referenced by DEBUG_INPUT_CALLBACKS_vtbl_init().

◆ __interest_mask()

static STDMETHODIMP __interest_mask ( PDEBUG_EVENT_CALLBACKS  This,
PULONG  Mask 
)
static

Definition at line 111 of file io_windbg.c.

111  {
112  *Mask = DEBUG_EVENT_BREAKPOINT | DEBUG_EVENT_CREATE_PROCESS;
113  *Mask |= DEBUG_EVENT_EXCEPTION | DEBUG_EVENT_SYSTEM_ERROR;
114  *Mask |= DEBUG_EVENT_EXIT_PROCESS;
115  return S_OK;
116 }

Referenced by DEBUG_EVENT_CALLBACKS_vtbl_init().

◆ __output_cb()

static STDMETHODIMP __output_cb ( PDEBUG_OUTPUT_CALLBACKS  This,
ULONG  Mask,
PCSTR  Text 
)
static

Definition at line 168 of file io_windbg.c.

168  {
169  eprintf("%s", Text);
170  return S_OK;
171 }
#define eprintf(x, y...)
Definition: rlcc.c:7

References eprintf.

Referenced by DEBUG_OUTPUT_CALLBACKS_vtbl_init().

◆ __system_error_cb()

static STDMETHODIMP __system_error_cb ( PDEBUG_EVENT_CALLBACKS  This,
ULONG  Error,
ULONG  Level 
)
static

Definition at line 148 of file io_windbg.c.

148  {
149  return DEBUG_STATUS_BREAK;
150 }

Referenced by DEBUG_EVENT_CALLBACKS_vtbl_init().

◆ create_context()

static DbgEngContext* create_context ( void  )
static

Definition at line 305 of file io_windbg.c.

305  {
307 
308  if (!idbg) {
309  return false;
310  }
311 
312  // Initialize interfaces
313  if (w32_DebugCreate(&IID_IDebugClient5, (PVOID *)&idbg->dbgClient) != S_OK) {
314  goto fail;
315  }
316  if (w32_DebugCreate(&IID_IDebugControl4, (PVOID *)&idbg->dbgCtrl) != S_OK) {
317  goto fail;
318  }
319  if (w32_DebugCreate(&IID_IDebugDataSpaces4, (PVOID *)&idbg->dbgData) != S_OK) {
320  goto fail;
321  }
322  if (w32_DebugCreate(&IID_IDebugRegisters2, (PVOID *)&idbg->dbgReg) != S_OK) {
323  goto fail;
324  }
325  if (w32_DebugCreate(&IID_IDebugSystemObjects4, (PVOID *)&idbg->dbgSysObj) != S_OK) {
326  goto fail;
327  }
328  if (w32_DebugCreate(&IID_IDebugAdvanced3, (PVOID *)&idbg->dbgAdvanced) != S_OK) {
329  goto fail;
330  }
331  if (w32_DebugCreate(&IID_IDebugSymbols3, (PVOID *)&idbg->dbgSymbols) != S_OK) {
332  goto fail;
333  }
334  if (!init_callbacks(idbg)) {
335  goto fail;
336  }
337  idbg->initialized = true;
338  return idbg;
339 fail:
340  __free_context(idbg);
341  return NULL;
342 }
static DebugCreate_t w32_DebugCreate
Definition: io_windbg.c:17
static bool init_callbacks(DbgEngContext *idbg)
Definition: io_windbg.c:227
static void __free_context(DbgEngContext *idbg)
Definition: io_windbg.c:210
#define RZ_NEW0(x)
Definition: rz_types.h:284
PDEBUG_SYSTEM_OBJECTS4 dbgSysObj
Definition: debug_windbg.c:42
PDEBUG_REGISTERS2 dbgReg
Definition: debug_windbg.c:41
PDEBUG_CONTROL4 dbgCtrl
Definition: debug_windbg.c:39
PDEBUG_CLIENT5 dbgClient
Definition: debug_windbg.c:38
PDEBUG_SYMBOLS3 dbgSymbols
Definition: debug_windbg.c:43
PDEBUG_DATA_SPACES4 dbgData
Definition: debug_windbg.c:40
PDEBUG_ADVANCED3 dbgAdvanced
Definition: debug_windbg.c:44
#define fail(test)
Definition: tests.h:29

References __free_context(), DbgEngContext::dbgAdvanced, DbgEngContext::dbgClient, DbgEngContext::dbgCtrl, DbgEngContext::dbgData, DbgEngContext::dbgReg, DbgEngContext::dbgSymbols, DbgEngContext::dbgSysObj, fail, init_callbacks(), DbgEngContext::initialized, NULL, PVOID, RZ_NEW0, and w32_DebugCreate.

Referenced by windbg_open().

◆ create_remote_context()

static DbgEngContext* create_remote_context ( const char *  opts)
static

Definition at line 264 of file io_windbg.c.

264  {
266 
267  if (!idbg) {
268  return false;
269  }
270 
271  LPWSTR wopts = (LPWSTR)rz_utf8_to_utf16(opts);
272 
273  // Initialize interfaces
274  if (w32_DebugConnectWide(wopts, &IID_IDebugClient5, (PVOID *)&idbg->dbgClient) != S_OK) {
275  goto fail;
276  }
277  if (w32_DebugConnectWide(wopts, &IID_IDebugControl4, (PVOID *)&idbg->dbgCtrl) != S_OK) {
278  goto fail;
279  }
280  if (w32_DebugConnectWide(wopts, &IID_IDebugDataSpaces4, (PVOID *)&idbg->dbgData) != S_OK) {
281  goto fail;
282  }
283  if (w32_DebugConnectWide(wopts, &IID_IDebugRegisters2, (PVOID *)&idbg->dbgReg) != S_OK) {
284  goto fail;
285  }
286  if (w32_DebugConnectWide(wopts, &IID_IDebugSystemObjects4, (PVOID *)&idbg->dbgSysObj) != S_OK) {
287  goto fail;
288  }
289  if (w32_DebugConnectWide(wopts, &IID_IDebugAdvanced3, (PVOID *)&idbg->dbgAdvanced) != S_OK) {
290  goto fail;
291  }
292  if (w32_DebugConnectWide(wopts, &IID_IDebugSymbols3, (PVOID *)&idbg->dbgSymbols) != S_OK) {
293  goto fail;
294  }
295  if (!init_callbacks(idbg)) {
296  goto fail;
297  }
298  idbg->initialized = true;
299  return idbg;
300 fail:
301  __free_context(idbg);
302  return NULL;
303 }
static DebugConnectWide_t w32_DebugConnectWide
Definition: io_windbg.c:18
DWORD LPWSTR

References __free_context(), DbgEngContext::dbgAdvanced, DbgEngContext::dbgClient, DbgEngContext::dbgCtrl, DbgEngContext::dbgData, DbgEngContext::dbgReg, DbgEngContext::dbgSymbols, DbgEngContext::dbgSysObj, fail, init_callbacks(), DbgEngContext::initialized, LPWSTR, NULL, PVOID, RZ_NEW0, and w32_DebugConnectWide.

Referenced by windbg_open().

◆ cur_dbg_plugin_is_windbg()

static bool cur_dbg_plugin_is_windbg ( RzDebug dbg)
inlinestatic

Definition at line 388 of file io_windbg.c.

388  {
389  return dbg && dbg->cur && !strcmp(dbg->cur->name, "windbg");
390 }
RzDebug * dbg
Definition: desil.c:30
const char * name
Definition: rz_debug.h:359
struct rz_debug_plugin_t * cur
Definition: rz_debug.h:295

References rz_debug_t::cur, dbg, and rz_debug_plugin_t::name.

Referenced by windbg_close(), and windbg_open().

◆ DEBUG_EVENT_CALLBACKS_vtbl_init()

static void DEBUG_EVENT_CALLBACKS_vtbl_init ( PDEBUG_EVENT_CALLBACKS  callbacks)
static

Definition at line 185 of file io_windbg.c.

185  {
186  INIT_IUNKNOWN_CALLBACKS(DEBUG_EVENT_CALLBACKS, callbacks->lpVtbl);
187  callbacks->lpVtbl->GetInterestMask = __interest_mask;
188  callbacks->lpVtbl->Breakpoint = __breakpoint_cb;
189  callbacks->lpVtbl->Exception = __exception_cb;
190  callbacks->lpVtbl->CreateProcess = __createprocess_cb;
191  callbacks->lpVtbl->ExitProcess = __exit_process_cb;
192  callbacks->lpVtbl->SystemError = __system_error_cb;
193 }
#define INIT_IUNKNOWN_CALLBACKS(IFace, lpVtbl)
Definition: io_windbg.c:46
static STDMETHODIMP __breakpoint_cb(PDEBUG_EVENT_CALLBACKS This, PDEBUG_BREAKPOINT Bp)
Definition: io_windbg.c:136
static STDMETHODIMP __exception_cb(PDEBUG_EVENT_CALLBACKS This, PEXCEPTION_RECORD64 Exception, ULONG FirstChance)
Definition: io_windbg.c:140
static STDMETHODIMP __interest_mask(PDEBUG_EVENT_CALLBACKS This, PULONG Mask)
Definition: io_windbg.c:111
static STDMETHODIMP __system_error_cb(PDEBUG_EVENT_CALLBACKS This, ULONG Error, ULONG Level)
Definition: io_windbg.c:148
static STDMETHODIMP __createprocess_cb(PDEBUG_EVENT_CALLBACKS This, ULONG64 ImageFileHandle, ULONG64 Handle, ULONG64 BaseOffset, ULONG ModuleSize, PCSTR ModuleName, PCSTR ImageName, ULONG CheckSum, ULONG TimeDateStamp, ULONG64 InitialThreadHandle, ULONG64 ThreadDataOffset, ULONG64 StartOffset)
Definition: io_windbg.c:118
static STDMETHODIMP __exit_process_cb(PDEBUG_EVENT_CALLBACKS This, ULONG ExitCode)
Definition: io_windbg.c:144

References __breakpoint_cb(), __createprocess_cb(), __exception_cb(), __exit_process_cb(), __interest_mask(), __system_error_cb(), and INIT_IUNKNOWN_CALLBACKS.

◆ DEBUG_INPUT_CALLBACKS_vtbl_init()

static void DEBUG_INPUT_CALLBACKS_vtbl_init ( PDEBUG_INPUT_CALLBACKS  callbacks)
static

Definition at line 195 of file io_windbg.c.

195  {
196  INIT_IUNKNOWN_CALLBACKS(DEBUG_INPUT_CALLBACKS, callbacks->lpVtbl);
197  callbacks->lpVtbl->StartInput = __input_cb;
198  callbacks->lpVtbl->EndInput = __input_end_cb;
199 }
static STDMETHODIMP __input_cb(PDEBUG_INPUT_CALLBACKS This, ULONG BufferSize)
Definition: io_windbg.c:152
static STDMETHODIMP __input_end_cb(PDEBUG_INPUT_CALLBACKS This)
Definition: io_windbg.c:164

References __input_cb(), __input_end_cb(), and INIT_IUNKNOWN_CALLBACKS.

◆ DEBUG_OUTPUT_CALLBACKS_vtbl_init()

static void DEBUG_OUTPUT_CALLBACKS_vtbl_init ( PDEBUG_OUTPUT_CALLBACKS  callbacks)
static

Definition at line 201 of file io_windbg.c.

201  {
202  INIT_IUNKNOWN_CALLBACKS(DEBUG_OUTPUT_CALLBACKS, callbacks->lpVtbl);
203  callbacks->lpVtbl->Output = __output_cb;
204 }
static STDMETHODIMP __output_cb(PDEBUG_OUTPUT_CALLBACKS This, ULONG Mask, PCSTR Text)
Definition: io_windbg.c:168

References __output_cb(), and INIT_IUNKNOWN_CALLBACKS.

◆ init_callbacks()

static bool init_callbacks ( DbgEngContext idbg)
static

Definition at line 227 of file io_windbg.c.

227  {
228 #define RELEASE(I) \
229  if (I) \
230  THISCALL(I, Release);
231  if (!idbg->dbgClient) {
232  return false;
233  }
234 
235  PDEBUG_EVENT_CALLBACKS event_callbacks = DEBUG_EVENT_CALLBACKS_impl_new(idbg);
236  PDEBUG_INPUT_CALLBACKS input_callbacks = DEBUG_INPUT_CALLBACKS_impl_new(idbg);
237  PDEBUG_OUTPUT_CALLBACKS output_callbacks = DEBUG_OUTPUT_CALLBACKS_impl_new(idbg);
238 
239  if (!event_callbacks || !output_callbacks || !event_callbacks) {
240  RELEASE(event_callbacks);
241  RELEASE(input_callbacks);
242  RELEASE(output_callbacks);
243  return false;
244  }
245 
246  if (FAILED(ITHISCALL(dbgClient, SetEventCallbacks, event_callbacks)) ||
247  FAILED(ITHISCALL(dbgClient, SetInputCallbacks, input_callbacks)) ||
248  FAILED(ITHISCALL(dbgClient, SetOutputCallbacks, output_callbacks))) {
249  goto fail;
250  }
251 
252  RELEASE(event_callbacks);
253  RELEASE(input_callbacks);
254  RELEASE(output_callbacks);
255  return true;
256 fail:
257  ITHISCALL(dbgClient, SetEventCallbacks, NULL);
258  ITHISCALL(dbgClient, SetInputCallbacks, NULL);
259  ITHISCALL(dbgClient, SetOutputCallbacks, NULL);
260  return false;
261 #undef RELEASE
262 }

References DbgEngContext::dbgClient, fail, ITHISCALL, NULL, and RELEASE.

Referenced by create_context(), and create_remote_context().

◆ windbg_check()

static bool windbg_check ( RzIO io,
const char *  uri,
bool  many 
)
static

Definition at line 384 of file io_windbg.c.

384  {
385  return !strncmp(uri, WINDBGURI, strlen(WINDBGURI));
386 }
#define WINDBGURI
Definition: io_windbg.c:20

References WINDBGURI.

Referenced by windbg_open().

◆ windbg_close()

static int windbg_close ( RzIODesc fd)
static

Definition at line 582 of file io_windbg.c.

582  {
583  DbgEngContext *idbg = fd->data;
584  if (!idbg) {
585  return 0;
586  }
587  fd->data = NULL;
588  RzCore *core = fd->io->corebind.core;
589  if (idbg->server) {
590  ITHISCALL(dbgClient, EndSession, DEBUG_END_DISCONNECT);
591  ITHISCALL(dbgClient, DisconnectProcessServer, idbg->server);
592  idbg->server = 0ULL;
593  } else {
594  ITHISCALL(dbgClient, EndSession, DEBUG_END_ACTIVE_DETACH);
595  }
596  if (cur_dbg_plugin_is_windbg(core->dbg)) {
597  core->dbg->plugin_data = NULL;
598  }
599  __free_context(idbg);
600  return 0;
601 }
static bool cur_dbg_plugin_is_windbg(RzDebug *dbg)
Definition: io_windbg.c:388
ULONG64 server
Definition: debug_windbg.c:35
RzDebug * dbg
Definition: rz_core.h:329
void * plugin_data
Definition: rz_debug.h:296
static const z80_opcode fd[]
Definition: z80_tab.h:997

References __free_context(), cur_dbg_plugin_is_windbg(), rz_core_t::dbg, fd, ITHISCALL, NULL, rz_debug_t::plugin_data, and DbgEngContext::server.

◆ windbg_getbase()

static bool windbg_getbase ( RzIODesc fd,
ut64 base 
)
static

Definition at line 669 of file io_windbg.c.

669  {
670  DbgEngContext *idbg = fd->data;
671  *base = idbg->processBase;
672  return true;
673 }
ULONG64 processBase
Definition: debug_windbg.c:36

References fd, and DbgEngContext::processBase.

◆ windbg_getpid()

static int windbg_getpid ( RzIODesc fd)
static

Definition at line 643 of file io_windbg.c.

643  {
644  DbgEngContext *idbg = fd->data;
645  ULONG Id = 0, Class, Qualifier;
646  if (SUCCEEDED(ITHISCALL(dbgCtrl, GetDebuggeeType, &Class, &Qualifier))) {
647  if (Class == DEBUG_CLASS_KERNEL) {
648  ITHISCALL(dbgSysObj, GetCurrentProcessId, &Id);
649  } else {
650  ITHISCALL(dbgSysObj, GetCurrentProcessSystemId, &Id);
651  }
652  }
653  return Id;
654 }

References fd, ITHISCALL, and ULONG.

◆ windbg_gettid()

static int windbg_gettid ( RzIODesc fd)
static

Definition at line 656 of file io_windbg.c.

656  {
657  DbgEngContext *idbg = fd->data;
658  ULONG Id = 0, Class, Qualifier;
659  if (SUCCEEDED(ITHISCALL(dbgCtrl, GetDebuggeeType, &Class, &Qualifier))) {
660  if (Class == DEBUG_CLASS_KERNEL) {
661  ITHISCALL(dbgSysObj, GetCurrentThreadId, &Id);
662  } else {
663  ITHISCALL(dbgSysObj, GetCurrentThreadSystemId, &Id);
664  }
665  }
666  return Id;
667 }

References fd, ITHISCALL, and ULONG.

◆ windbg_init()

static int windbg_init ( void  )
static

Definition at line 344 of file io_windbg.c.

344  {
346  return 1;
347  }
348  char *ext_path = rz_sys_getenv("_NT_DEBUGGER_EXTENSION_PATH");
349  HANDLE h = NULL;
350  if (RZ_STR_ISNOTEMPTY(ext_path)) {
351  char *s = strtok(ext_path, ";");
352  do {
353  PWCHAR dir = rz_utf8_to_utf16(s);
354  SetDllDirectoryW(dir);
355  free(dir);
356  h = LoadLibrary(TEXT("dbgeng.dll"));
357  } while (!h && (s = strtok(NULL, ";")));
358  SetDllDirectoryW(NULL);
359  }
360  free(ext_path);
361  if (!h) {
362  h = LoadLibrary(TEXT("dbgeng.dll"));
363  }
364  if (!h) {
365  rz_sys_perror("LoadLibrary (\"dbgeng.dll\")");
366  return 0;
367  }
368 
369  w32_DebugCreate = (DebugCreate_t)GetProcAddress(h, "DebugCreate");
370  if (!w32_DebugCreate) {
371  rz_sys_perror("GetProcAddress (\"DebugCreate\")");
372  return 0;
373  }
374 
375  w32_DebugConnectWide = (DebugConnectWide_t)GetProcAddress(h, "DebugConnectWide");
376  if (!w32_DebugConnectWide) {
377  rz_sys_perror("GetProcAddress (\"DebugConnectWide\")");
378  return 0;
379  }
380 
381  return 1;
382 }
HRESULT(__stdcall * DebugConnectWide_t)(_In_ PCWSTR RemoteOptions, _In_ REFIID InterfaceId, _Out_ PVOID *Interface)
Definition: io_windbg.c:12
HRESULT(__stdcall * DebugCreate_t)(_In_ REFIID InterfaceId, _Out_ PVOID *Interface)
Definition: io_windbg.c:8
static RzSocket * s
Definition: rtr.c:28
#define RZ_STR_ISNOTEMPTY(x)
Definition: rz_str.h:68
RZ_API char * rz_sys_getenv(const char *key)
Get the value of an environment variable named key or NULL if none exists.
Definition: sys.c:483
#define rz_sys_perror(x)
Definition: rz_types.h:336
#define h(i)
Definition: sha256.c:48
DWORD * HANDLE

References free(), h, HANDLE, NULL, RZ_STR_ISNOTEMPTY, rz_sys_getenv(), rz_sys_perror, s, w32_DebugConnectWide, and w32_DebugCreate.

Referenced by windbg_open().

◆ windbg_lseek()

static ut64 windbg_lseek ( RzIO io,
RzIODesc fd,
ut64  offset,
int  whence 
)
static

Definition at line 603 of file io_windbg.c.

603  {
604  switch (whence) {
605  case RZ_IO_SEEK_SET:
606  io->off = offset;
607  break;
608  case RZ_IO_SEEK_CUR:
609  io->off += (st64)offset;
610  break;
611  case RZ_IO_SEEK_END:
612  io->off = UT64_MAX;
613  break;
614  }
615  return io->off;
616 }
voidpf uLong offset
Definition: ioapi.h:144
#define RZ_IO_SEEK_CUR
Definition: rz_io.h:16
#define RZ_IO_SEEK_SET
Definition: rz_io.h:15
#define RZ_IO_SEEK_END
Definition: rz_io.h:17
#define st64
Definition: rz_types_base.h:10
#define UT64_MAX
Definition: rz_types_base.h:86
ut64 off
Definition: rz_io.h:61

References rz_io_t::off, RZ_IO_SEEK_CUR, RZ_IO_SEEK_END, RZ_IO_SEEK_SET, st64, and UT64_MAX.

◆ windbg_open()

static RzIODesc* windbg_open ( RzIO io,
const char *  uri,
int  perm,
int  mode 
)
static

Definition at line 400 of file io_windbg.c.

400  {
401  if (!windbg_check(io, uri, 0)) {
402  return NULL;
403  }
404  if (!windbg_init()) {
405  return NULL;
406  }
407  HRESULT hr = E_FAIL;
408  RzIODesc *fd = NULL;
409  RzCore *core = io->corebind.core;
410  DbgEngContext *idbg = NULL;
411  const char *args = uri + strlen(WINDBGURI);
412  if (rz_str_startswith(args, "-remote")) {
413  args += strlen("-remote") + 1;
414  idbg = create_remote_context(args);
415  if (idbg) {
416  goto remote_client;
417  }
418  } else {
419  idbg = create_context();
420  if (idbg && rz_str_startswith(args, "-premote")) {
421  args += strlen("-premote") + 1;
422  if (FAILED(ITHISCALL(dbgClient, ConnectProcessServer, args, &idbg->server))) {
423  __free_context(idbg);
424  return NULL;
425  }
426  goto remote_client;
427  }
428  }
429  if (!idbg) {
430  return NULL;
431  }
432  ITHISCALL(dbgCtrl, AddEngineOptions, DEBUG_ENGOPT_INITIAL_BREAK);
433  ITHISCALL(dbgCtrl, AddEngineOptions, DEBUG_ENGOPT_FINAL_BREAK);
434  ITHISCALL(dbgCtrl, AddEngineOptions, DEBUG_ENGOPT_ALLOW_READ_ONLY_BREAKPOINTS);
435  ITHISCALL(dbgCtrl, SetCodeLevel, DEBUG_LEVEL_ASSEMBLY);
436  int argc;
437  char **argv = rz_str_argv(args, &argc);
438  const size_t argv_sz = sizeof(char *) * ((size_t)argc + 2);
439  char **tmp = realloc(argv, argv_sz);
440  if (!tmp) {
441  __free_context(idbg);
443  return NULL;
444  }
445  argv = tmp;
446  memmove(argv + 1, argv, argv_sz - sizeof(char *));
447  argv[0] = strdup(WINDBGURI);
448  argc++;
449  const char *command = NULL;
450  bool image_path_set = false, symbol_path_set = false;
452  DWORD spawn_options = DEBUG_ONLY_THIS_PROCESS | CREATE_NEW_CONSOLE;
453  DWORD attach_options = DEBUG_ATTACH_DEFAULT;
454  DWORD pid = 0;
455  int c;
456  RzGetopt opt;
457  rz_getopt_init(&opt, argc, (const char **)argv, "c:dgGh:i:k:op:y:z:");
458  while ((c = rz_getopt_next(&opt)) != -1) {
459  switch (c) {
460  case 'c':
461  command = opt.arg;
462  break;
463  case 'd':
464  ITHISCALL(dbgCtrl, AddEngineOptions, DEBUG_ENGOPT_INITIAL_MODULE_BREAK);
465  break;
466  case 'g':
467  ITHISCALL(dbgCtrl, RemoveEngineOptions, DEBUG_ENGOPT_INITIAL_BREAK);
468  break;
469  case 'G':
470  ITHISCALL(dbgCtrl, RemoveEngineOptions, DEBUG_ENGOPT_FINAL_BREAK);
471  break;
472  case 'h':
473  if (strcmp(opt.arg, "d")) {
474  spawn_options |= DEBUG_CREATE_PROCESS_NO_DEBUG_HEAP;
475  }
476  break;
477  case 'i':
478  ITHISCALL(dbgSymbols, SetImagePath, opt.arg);
479  image_path_set = true;
480  break;
481  case 'k':
482  if (strcmp(opt.arg, "l")) {
483  target = TARGET_LOCAL_KERNEL;
484  } else if (strcmp(opt.arg, "qm")) {
485  ITHISCALL(dbgCtrl, AddEngineOptions, DEBUG_ENGOPT_KD_QUIET_MODE);
486  } else {
487  target = TARGET_KERNEL;
488  args = opt.arg;
489  }
490  break;
491  case 'o':
492  spawn_options &= ~DEBUG_ONLY_THIS_PROCESS;
493  spawn_options |= DEBUG_PROCESS;
494  break;
495  case 'p':
496  if (rz_str_isnumber(opt.arg)) {
497  target = TARGET_LOCAL_ATTACH;
498  pid = atoi(opt.arg);
499  } else {
500  if (strcmp(opt.arg, "b")) {
501  attach_options |= DEBUG_ATTACH_INVASIVE_NO_INITIAL_BREAK;
502  } else if (strcmp(opt.arg, "e")) {
503  attach_options |= DEBUG_ATTACH_EXISTING;
504  } else if (strcmp(opt.arg, "v")) {
505  attach_options |= DEBUG_ATTACH_NONINVASIVE;
506  }
507  }
508  break;
509  case 'y':
510  symbol_path_set = true;
511  ITHISCALL(dbgSymbols, SetSymbolPath, opt.arg);
512  break;
513  case 'z':
514  target = TARGET_DUMP_FILE;
515  args = opt.arg;
516  break;
517  default:
518  break;
519  }
520  }
521  if (!symbol_path_set) {
522  const char *store = io->corebind.cfgGet(core, "pdb.symstore");
523  const char *server = io->corebind.cfgGet(core, "pdb.server");
524  char *s = strdup(server);
525  rz_str_replace_ch(s, ';', '*', true);
526  char *sympath = rz_str_newf("cache*;srv*%s*%s", store, s);
527  ITHISCALL(dbgSymbols, SetSymbolPath, sympath);
528  free(s);
529  free(sympath);
530  }
531  if (!image_path_set) {
532  char *path = rz_sys_getenv("PATH");
533  ITHISCALL(dbgSymbols, AppendImagePath, path);
534  free(path);
535  }
536  switch (target) {
537  case TARGET_LOCAL_SPAWN:
538  if (argv[opt.ind]) {
539  char *cmd = rz_str_format_msvc_argv((size_t)opt.argc - opt.ind, (const char **)argv + opt.ind);
540  hr = ITHISCALL(dbgClient, CreateProcess, 0ULL, cmd, spawn_options);
541  free(cmd);
542  } else {
543  eprintf("Missing argument for local spawn\n");
544  }
545  break;
546  case TARGET_LOCAL_ATTACH: // -p (PID)
547  hr = ITHISCALL(dbgClient, AttachProcess, 0ULL, pid, attach_options);
548  break;
549  case TARGET_LOCAL_KERNEL: // -kl
550  if (ITHISCALL(dbgClient, IsKernelDebuggerEnabled) == S_FALSE) {
551  eprintf("Live Kernel debug not available. Set the /debug boot switch to enable it\n");
552  } else {
553  hr = ITHISCALL(dbgClient, AttachKernel, DEBUG_ATTACH_LOCAL_KERNEL, args);
554  }
555  break;
556  case TARGET_DUMP_FILE: // -z
557  hr = ITHISCALL(dbgClient, OpenDumpFile, args);
558  break;
559  case TARGET_KERNEL: // -k
560  hr = ITHISCALL(dbgClient, AttachKernel, DEBUG_ATTACH_KERNEL_CONNECTION, args);
561  break;
562  }
563  if (hr != S_OK) {
565  __free_context(idbg);
566  return NULL;
567  }
568  ITHISCALL(dbgCtrl, WaitForEvent, DEBUG_WAIT_DEFAULT, INFINITE);
569  if (command) {
570  ITHISCALL(dbgCtrl, Execute, DEBUG_OUTCTL_ALL_CLIENTS, command, DEBUG_EXECUTE_DEFAULT);
571  }
573 remote_client:
574  fd = rz_io_desc_new(io, &rz_io_plugin_windbg, uri, perm | RZ_PERM_X, mode, idbg);
575  fd->name = strdup(args);
576  if (cur_dbg_plugin_is_windbg(core->dbg)) {
577  core->dbg->plugin_data = idbg;
578  }
579  return fd;
580 }
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
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 cmd
Definition: sflib.h:79
static DbgEngContext * create_context(void)
Definition: io_windbg.c:305
RzIOPlugin rz_io_plugin_windbg
Definition: io_windbg.c:684
static int windbg_init(void)
Definition: io_windbg.c:344
static bool windbg_check(RzIO *io, const char *uri, bool many)
Definition: io_windbg.c:384
static DbgEngContext * create_remote_context(const char *opts)
Definition: io_windbg.c:264
const char int mode
Definition: ioapi.h:137
void * realloc(void *ptr, size_t size)
Definition: malloc.c:144
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
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
int args
Definition: mipsasm.c:18
RZ_API void rz_getopt_init(RzGetopt *go, int argc, const char **argv, const char *ostr)
Definition: getopt.c:17
RZ_API int rz_getopt_next(RzGetopt *opt)
Definition: getopt.c:29
RZ_API RzIODesc * rz_io_desc_new(RzIO *io, RzIOPlugin *plugin, const char *uri, int flags, int mode, void *data)
Definition: io_desc.c:11
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_format_msvc_argv(size_t argc, const char **argv)
Definition: str.c:1844
RZ_API bool rz_str_isnumber(const char *str)
Definition: str.c:3550
RZ_API int rz_str_replace_ch(char *s, char a, char b, bool g)
Definition: str.c:139
RZ_API char ** rz_str_argv(const char *str, int *_argc)
Definition: str.c:2509
RZ_API bool rz_str_startswith(RZ_NONNULL const char *str, RZ_NONNULL const char *needle)
Checks if a string starts with a specifc sequence of characters (case sensitive)
Definition: str.c:3286
RZ_API void rz_str_argv_free(char **argv)
Definition: str.c:2633
#define RZ_PERM_X
Definition: rz_types.h:95
#define c(i)
Definition: sha256.c:43
RzCoreConfigGet cfgGet
Definition: rz_bind.h:44
void * core
Definition: rz_bind.h:31
const char * arg
Definition: rz_getopt.h:15
RzCoreBind corebind
Definition: rz_io.h:92
char * name
Definition: z80_tab.h:24
const char * command
Definition: main.c:7
DWORD

References __free_context(), rz_getopt_t::arg, rz_getopt_t::argc, args, argv, c, rz_core_bind_t::cfgGet, cmd, command, rz_core_bind_t::core, rz_io_t::corebind, create_context(), create_remote_context(), cur_dbg_plugin_is_windbg(), rz_core_t::dbg, DWORD, eprintf, fd, free(), rz_getopt_t::ind, ITHISCALL, z80_opcode::name, NULL, path, pid, rz_debug_t::plugin_data, realloc(), rz_getopt_init(), rz_getopt_next(), rz_io_desc_new(), rz_io_plugin_windbg, RZ_PERM_X, rz_str_argv(), rz_str_argv_free(), rz_str_format_msvc_argv(), rz_str_isnumber(), rz_str_newf(), rz_str_replace_ch(), rz_str_startswith(), rz_sys_getenv(), s, DbgEngContext::server, strdup(), TARGET_DUMP_FILE, TARGET_KERNEL, TARGET_LOCAL_ATTACH, TARGET_LOCAL_KERNEL, TARGET_LOCAL_SPAWN, autogen_x86imm::tmp, windbg_check(), windbg_init(), and WINDBGURI.

◆ windbg_read()

static int windbg_read ( RzIO io,
RzIODesc fd,
ut8 buf,
int  count 
)
static

Definition at line 618 of file io_windbg.c.

618  {
619  DbgEngContext *idbg = fd->data;
620  ULONG bytesRead = 0ULL;
621  if (FAILED(ITHISCALL(dbgData, ReadVirtual, io->off, (PVOID)buf, count, &bytesRead))) {
622  ULONG64 ValidBase;
623  ULONG ValidSize;
624  if (SUCCEEDED(ITHISCALL(dbgData, GetValidRegionVirtual, io->off, count, &ValidBase, &ValidSize))) {
625  if (ValidSize && ValidBase < io->off + count) {
626  const ULONG64 skipped = ValidBase - io->off;
627  const ULONG toRead = count - skipped;
628  ITHISCALL(dbgData, ReadVirtual, ValidBase, (PVOID)(buf + skipped), toRead, &bytesRead);
629  bytesRead += skipped;
630  }
631  }
632  }
633  return bytesRead;
634 }
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
voidpf void * buf
Definition: ioapi.h:138
int off
Definition: pal.c:13

References count, fd, ITHISCALL, off, rz_io_t::off, PVOID, and ULONG.

◆ windbg_system()

static char* windbg_system ( RzIO io,
RzIODesc fd,
const char *  cmd 
)
static

Definition at line 675 of file io_windbg.c.

675  {
676  DbgEngContext *idbg = fd->data;
677  if (RZ_STR_ISEMPTY(cmd) || !strncmp("pid", cmd, 3)) {
678  return NULL;
679  }
680  ITHISCALL(dbgCtrl, Execute, DEBUG_OUTCTL_ALL_CLIENTS, cmd, DEBUG_EXECUTE_DEFAULT);
681  return NULL;
682 }
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67

References cmd, fd, ITHISCALL, NULL, and RZ_STR_ISEMPTY.

◆ windbg_write()

static int windbg_write ( RzIO io,
RzIODesc fd,
const ut8 buf,
int  count 
)
static

Definition at line 636 of file io_windbg.c.

636  {
637  DbgEngContext *idbg = fd->data;
638  ULONG bytesWritten = 0ULL;
639  ITHISCALL(dbgData, WriteVirtual, io->off, (PVOID)buf, count, &bytesWritten);
640  return bytesWritten;
641 }

References count, fd, ITHISCALL, rz_io_t::off, PVOID, and ULONG.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_IO,
}
@ RZ_LIB_TYPE_IO
Definition: rz_lib.h:69
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_io.h:117

Definition at line 704 of file io_windbg.c.

◆ rz_io_plugin_windbg

RzIOPlugin rz_io_plugin_windbg
Initial value:
= {
.name = "windbg",
.desc = "WinDBG (DbgEng.dll) based io plugin for Windows",
.license = "LGPL3",
.uris = WINDBGURI,
.isdbg = true,
.init = windbg_init,
.open = windbg_open,
.lseek = windbg_lseek,
.read = windbg_read,
.write = windbg_write,
.system = windbg_system,
.close = windbg_close,
.getpid = windbg_getpid,
.gettid = windbg_gettid,
.getbase = windbg_getbase,
.check = windbg_check,
}
static int windbg_read(RzIO *io, RzIODesc *fd, ut8 *buf, int count)
Definition: io_windbg.c:618
static ut64 windbg_lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence)
Definition: io_windbg.c:603
static int windbg_gettid(RzIODesc *fd)
Definition: io_windbg.c:656
static int windbg_write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
Definition: io_windbg.c:636
static RzIODesc * windbg_open(RzIO *io, const char *uri, int perm, int mode)
Definition: io_windbg.c:400
static int windbg_close(RzIODesc *fd)
Definition: io_windbg.c:582
static bool windbg_getbase(RzIODesc *fd, ut64 *base)
Definition: io_windbg.c:669
static int windbg_getpid(RzIODesc *fd)
Definition: io_windbg.c:643
static char * windbg_system(RzIO *io, RzIODesc *fd, const char *cmd)
Definition: io_windbg.c:675

Definition at line 684 of file io_windbg.c.

Referenced by windbg_open().

◆ w32_DebugConnectWide

DebugConnectWide_t w32_DebugConnectWide = NULL
static

Definition at line 18 of file io_windbg.c.

Referenced by create_remote_context(), and windbg_init().

◆ w32_DebugCreate

DebugCreate_t w32_DebugCreate = NULL
static

Definition at line 17 of file io_windbg.c.

Referenced by create_context(), and windbg_init().