Rizin
unix-like reverse engineering framework and cli tools
w32dbg_wrap.c File Reference
#include <windows.h>
#include <w32dbg_wrap.h>

Go to the source code of this file.

Functions

static DWORD WINAPI __w32dbg_thread (LPVOID param)
 
W32DbgWInstw32dbg_wrap_new (void)
 
void w32dbg_wrap_free (W32DbgWInst *inst)
 
int w32dbg_wrap_wait_ret (W32DbgWInst *inst)
 

Function Documentation

◆ __w32dbg_thread()

static DWORD WINAPI __w32dbg_thread ( LPVOID  param)
static

Definition at line 7 of file w32dbg_wrap.c.

7  {
8  W32DbgWInst *inst = param;
9  W32DbgWParams *params = &inst->params;
10  PROCESS_INFORMATION *pi = &inst->pi;
11  while (1) {
12  WaitForSingleObject(inst->request_sem, INFINITE);
13  switch (params->type) {
14  case W32_CONTINUE:
15  params->ret = ContinueDebugEvent(pi->dwProcessId, pi->dwThreadId, params->continue_status);
16  break;
17  case W32_WAIT:
18  params->ret = WaitForDebugEvent(params->wait.de, params->wait.wait_time);
19  if (params->ret) {
20  pi->dwProcessId = params->wait.de->dwProcessId;
21  pi->dwThreadId = params->wait.de->dwThreadId;
22  }
23  break;
24  case W32_CALL_FUNC:
25  params->ret = params->func.func(params->func.user);
26  break;
27  case W32_ATTACH:
28  params->ret = DebugActiveProcess(pi->dwProcessId);
29  break;
30  case W32_DETACH:
31  case W32_STOP:
32  params->ret = DebugActiveProcessStop(pi->dwProcessId);
33  break;
34  default:
35  break;
36  }
37  if (!params->ret) {
38  params->err = GetLastError();
39  }
40  ReleaseSemaphore(inst->result_sem, 1, NULL);
41  if (params->type == W32_STOP) {
42  break;
43  }
44  }
45  return 0;
46 }
#define NULL
Definition: cris-opc.c:27
HANDLE result_sem
Definition: w32dbg_wrap.h:38
W32DbgWParams params
Definition: w32dbg_wrap.h:36
PROCESS_INFORMATION pi
Definition: w32dbg_wrap.h:40
HANDLE request_sem
Definition: w32dbg_wrap.h:37
int(* func)(void *)
Definition: w32dbg_wrap.h:26
DWORD continue_status
Definition: w32dbg_wrap.h:20
w32dbg_wrap_req type
Definition: w32dbg_wrap.h:18
struct W32DbgWParams::@606::@608 wait
@ W32_ATTACH
Definition: w32dbg_wrap.h:10
@ W32_STOP
Definition: w32dbg_wrap.h:13
@ W32_CONTINUE
Definition: w32dbg_wrap.h:9
@ W32_DETACH
Definition: w32dbg_wrap.h:11
@ W32_CALL_FUNC
Definition: w32dbg_wrap.h:14
@ W32_WAIT
Definition: w32dbg_wrap.h:12

References W32DbgWParams::continue_status, W32DbgWParams::err, W32DbgWParams::func, NULL, W32DbgWInst::params, W32DbgWInst::pi, W32DbgWInst::request_sem, W32DbgWInst::result_sem, W32DbgWParams::ret, W32DbgWParams::type, W32_ATTACH, W32_CALL_FUNC, W32_CONTINUE, W32_DETACH, W32_STOP, W32_WAIT, and W32DbgWParams::wait.

Referenced by w32dbg_wrap_new().

◆ w32dbg_wrap_free()

void w32dbg_wrap_free ( W32DbgWInst inst)

Definition at line 58 of file w32dbg_wrap.c.

58  {
59  if (!inst) {
60  return;
61  }
62  inst->params.type = W32_STOP;
64  WaitForSingleObject(inst->debugThread, INFINITE);
65  CloseHandle(inst->request_sem);
66  CloseHandle(inst->result_sem);
67  CloseHandle(inst->debugThread);
68  free(inst);
69 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
HANDLE debugThread
Definition: w32dbg_wrap.h:35
int w32dbg_wrap_wait_ret(W32DbgWInst *inst)
Definition: w32dbg_wrap.c:71

References W32DbgWInst::debugThread, free(), W32DbgWInst::params, W32DbgWInst::request_sem, W32DbgWInst::result_sem, W32DbgWParams::type, W32_STOP, and w32dbg_wrap_wait_ret().

Referenced by rz_io_fini().

◆ w32dbg_wrap_new()

W32DbgWInst* w32dbg_wrap_new ( void  )

Definition at line 48 of file w32dbg_wrap.c.

48  {
49  W32DbgWInst *inst = calloc(1, sizeof(W32DbgWInst));
50  if (inst) {
51  inst->request_sem = CreateSemaphore(NULL, 0, 1, NULL);
52  inst->result_sem = CreateSemaphore(NULL, 0, 1, NULL);
53  inst->debugThread = CreateThread(NULL, 0, __w32dbg_thread, inst, 0, NULL);
54  }
55  return inst;
56 }
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
static DWORD WINAPI __w32dbg_thread(LPVOID param)
Definition: w32dbg_wrap.c:7

References __w32dbg_thread(), calloc(), W32DbgWInst::debugThread, NULL, W32DbgWInst::request_sem, and W32DbgWInst::result_sem.

◆ w32dbg_wrap_wait_ret()

int w32dbg_wrap_wait_ret ( W32DbgWInst inst)

Definition at line 71 of file w32dbg_wrap.c.

71  {
72  ReleaseSemaphore(inst->request_sem, 1, NULL);
73  WaitForSingleObject(inst->result_sem, INFINITE);
74  return w32dbgw_ret(inst);
75 }
#define w32dbgw_ret(inst)
Definition: w32dbg_wrap.h:45

References NULL, W32DbgWInst::request_sem, W32DbgWInst::result_sem, and w32dbgw_ret.

Referenced by w32_attach(), w32_continue(), w32_dbg_wait(), w32_detach(), and w32dbg_wrap_free().