Rizin
unix-like reverse engineering framework and cli tools
windows_message.h File Reference
#include <rz_debug.h>

Go to the source code of this file.

Functions

RZ_API bool rz_w32_add_winmsg_breakpoint (RzDebug *dbg, const char *msg_name, const char *window_id)
 
RZ_API void rz_w32_identify_window (void)
 
RZ_API void rz_w32_print_windows (RzDebug *dbg)
 

Function Documentation

◆ rz_w32_add_winmsg_breakpoint()

RZ_API bool rz_w32_add_winmsg_breakpoint ( RzDebug dbg,
const char *  msg_name,
const char *  window_id 
)

Definition at line 462 of file windows_message.c.

462  {
463  rz_return_val_if_fail(dbg && msg_name, false);
464  char *name = strdup(msg_name);
465  rz_str_trim(name);
466 
468  if (!type) {
469  free(name);
470  return false;
471  }
472  ut64 offset = 0;
473  if (window_id) {
474  RzList *windows = get_windows(dbg);
475  if (windows && !windows->length) {
476  dbg->cb_printf("No windows for this process.\n");
477  }
478  ut64 win_h = rz_num_math(NULL, window_id);
479  RzListIter *it;
480  window *win;
481  rz_list_foreach (windows, it, win) {
482  if ((ut64)win->h == win_h || !strnicmp(win->name, window_id, strlen(window_id))) {
483  offset = win->proc;
484  break;
485  }
486  }
487  if (!offset) {
488  dbg->cb_printf("Window not found, try these:\n");
489  print_windows(dbg, windows);
490  }
491  rz_list_free(windows);
492  } else {
494  }
495  if (!offset) {
496  free(name);
497  return false;
498  }
499  RzBreakpointItem *b = rz_debug_bp_add(dbg, offset, 0, 0, 0, NULL, 0);
500  if (!b) {
501  free(name);
502  return false;
503  }
504  char *cond;
505  if (window_id) {
506  char *reg;
507  if (!strcmp(dbg->arch, "arm")) {
508  if (dbg->bits == RZ_SYS_BITS_64) {
509  reg = "x1";
510  } else {
511  reg = "r1";
512  }
513  } else {
514  reg = "edx";
515  }
516  b->cond = rz_str_newf("?q `ae %s,%d,-`", reg, type);
517  } else {
518  char *reg;
519  if (!strcmp(dbg->arch, "arm")) {
520  if (dbg->bits == RZ_SYS_BITS_64) {
521  reg = "x0";
522  } else {
523  reg = "r0";
524  }
525  } else {
526  if (dbg->bits == RZ_SYS_BITS_64) {
527  reg = "rcx";
528  } else {
529  reg = "ecx";
530  }
531  }
532  b->cond = rz_str_newf("?q `ae %lu,%s,%d,+,[4],-`", type, reg, dbg->bits);
533  }
534  free(name);
535  return true;
536 }
#define NULL
Definition: cris-opc.c:27
RzDebug * dbg
Definition: desil.c:30
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf uLong offset
Definition: ioapi.h:144
#define reg(n)
RZ_API RZ_BORROW RzBreakpointItem * rz_debug_bp_add(RZ_NONNULL RzDebug *dbg, ut64 addr, int hw, bool watch, int rw, RZ_NULLABLE const char *module, st64 m_delta)
Definition: debug.c:270
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
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 type
Definition: mipsasm.c:17
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API ut64 rz_num_math(RzNum *num, const char *str)
Definition: unum.c:456
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API void rz_str_trim(RZ_NONNULL RZ_INOUT char *str)
Removes whitespace characters (space, tab, newline etc.) from the beginning and end of a string.
Definition: str_trim.c:190
@ RZ_SYS_BITS_64
Definition: rz_sys.h:21
#define b(i)
Definition: sha256.c:42
#define cond(bop, top, mask, flags)
Definition: z80asm.h:102
PrintfCallback cb_printf
Definition: rz_debug.h:292
char * arch
Definition: rz_debug.h:242
int bits
Definition: rz_debug.h:243
ut32 length
Definition: rz_list.h:22
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
DWORD
static DWORD get_msg_type(char *name)
static RzList * get_windows(RzDebug *dbg)
static void print_windows(RzDebug *dbg, RzList *windows)
static ut64 get_dispatchmessage_offset(RzDebug *dbg)

References rz_debug_t::arch, b, rz_debug_t::bits, rz_debug_t::cb_printf, cond, dbg, DWORD, free(), get_dispatchmessage_offset(), get_msg_type(), get_windows(), rz_list_t::length, NULL, print_windows(), reg, rz_debug_bp_add(), rz_list_free(), rz_num_math(), rz_return_val_if_fail, rz_str_newf(), rz_str_trim(), RZ_SYS_BITS_64, strdup(), type, and ut64().

Referenced by rz_cmd_debug_set_cond_bp_win_handler().

◆ rz_w32_identify_window()

RZ_API void rz_w32_identify_window ( void  )

Definition at line 312 of file windows_message.c.

312  {
313  while (!rz_cons_yesno('y', "Move cursor to the window to be identified. Ready? (Y/n)"))
314  ;
315  POINT p;
316  if (!GetCursorPos(&p)) {
317  rz_sys_perror("GetCursorPos");
318  }
319  HWND hwnd = WindowFromPoint(p);
320  window *win = NULL;
321  if (hwnd) {
322  if (rz_cons_yesno('y', "Try to get the child? (Y/n)")) {
323  HWND child = ChildWindowFromPoint(hwnd, p);
324  hwnd = child ? child : hwnd;
325  }
326  win = window_from_handle(hwnd);
327  } else {
328  eprintf("No window found\n");
329  return;
330  }
331  if (!win) {
332  eprintf("Error trying to get information from 0x%08" PFMT64x "\n", (ut64)hwnd);
333  return;
334  }
335  RzTable *tbl = create_window_table();
336  if (!tbl) {
337  return;
338  }
339  add_window_to_table(tbl, win);
340  char *tbl_str = rz_table_tofancystring(tbl);
341  rz_cons_print(tbl_str);
342  free(tbl_str);
343  rz_table_free(tbl);
344 }
RZ_API bool rz_cons_yesno(int def, const char *fmt,...)
Definition: input.c:666
void * p
Definition: libc.cpp:67
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API void rz_table_free(RzTable *t)
Definition: table.c:114
RZ_API RZ_OWN char * rz_table_tofancystring(RZ_NONNULL RzTable *t)
Convert the content of RzTable to string.
Definition: table.c:404
#define rz_sys_perror(x)
Definition: rz_types.h:336
#define PFMT64x
Definition: rz_types.h:393
static window * window_from_handle(HANDLE hwnd)
static void add_window_to_table(RzTable *tbl, window *win)
static RzTable * create_window_table(void)

References add_window_to_table(), create_window_table(), eprintf, free(), NULL, p, PFMT64x, rz_cons_yesno(), rz_sys_perror, rz_table_free(), rz_table_tofancystring(), ut64(), and window_from_handle().

Referenced by rz_cmd_debug().

◆ rz_w32_print_windows()

RZ_API void rz_w32_print_windows ( RzDebug dbg)

Definition at line 450 of file windows_message.c.

450  {
451  RzList *windows = get_windows(dbg);
452  if (windows) {
453  if (!windows->length) {
454  dbg->cb_printf("No windows for this process.\n");
455  return;
456  }
457  print_windows(dbg, windows);
458  }
459  rz_list_free(windows);
460 }

References rz_debug_t::cb_printf, dbg, get_windows(), rz_list_t::length, print_windows(), and rz_list_free().

Referenced by rz_cmd_debug().