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

Go to the source code of this file.

Classes

struct  RzIOBochs
 

Functions

static bool isBochs (RzDebug *dbg)
 
static int rz_debug_bochs_breakpoint (RzBreakpoint *bp, RzBreakpointItem *b, bool set)
 
static int rz_debug_bochs_reg_read (RzDebug *dbg, int type, ut8 *buf, int size)
 
static int rz_debug_bochs_reg_write (RzDebug *dbg, int type, const ut8 *buf, int size)
 
void map_free (RzDebugMap *map)
 
static RzListrz_debug_bochs_map_get (RzDebug *dbg)
 
static int rz_debug_bochs_step (RzDebug *dbg)
 
static int rz_debug_bochs_continue (RzDebug *dbg, int pid, int tid, int sig)
 
static void bochs_debug_break (void *u)
 
static RzDebugReasonType rz_debug_bochs_wait (RzDebug *dbg, int pid)
 
static int rz_debug_bochs_stop (RzDebug *dbg)
 
static int rz_debug_bochs_attach (RzDebug *dbg, int pid)
 
static int rz_debug_bochs_detach (RzDebug *dbg, int pid)
 
static const char * rz_debug_bochs_reg_profile (RzDebug *dbg)
 

Variables

static bool bCapturaRegs = true
 
static bool bStep = false
 
static bool bBreak = false
 
static bool bAjusta = true
 
static char * saveRegs
 
static ut64 ripStop = 0LL
 
static libbochs_tdesc = NULL
 
RzDebugPlugin rz_debug_plugin_bochs
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ bochs_debug_break()

static void bochs_debug_break ( void *  u)
static

Definition at line 265 of file debug_bochs.c.

265  {
266  eprintf("bochs_debug_break: Sending break...\n");
268  bBreak = true;
269 }
static libbochs_t * desc
Definition: debug_bochs.c:18
static bool bBreak
Definition: debug_bochs.c:9
bool bochs_cmd_stop(libbochs_t *b)
Definition: libbochs.c:45
#define eprintf(x, y...)
Definition: rlcc.c:7

References bBreak, bochs_cmd_stop(), desc, and eprintf.

Referenced by rz_debug_bochs_wait().

◆ isBochs()

static bool isBochs ( RzDebug dbg)
static

Definition at line 20 of file debug_bochs.c.

20  {
21  RzIODesc *d = dbg->iob.io->desc;
22  if (d && d->plugin && d->plugin->name) {
23  if (!strcmp("bochs", d->plugin->name)) {
24  return true;
25  }
26  }
27  eprintf("error: the iodesc data is not bochs friendly\n");
28  return false;
29 }
RzDebug * dbg
Definition: desil.c:30
#define d(i)
Definition: sha256.c:44
RzIOBind iob
Definition: rz_debug.h:293
RzIO * io
Definition: rz_io.h:232
struct rz_io_desc_t * desc
Definition: rz_io.h:60

References d, dbg, rz_io_t::desc, eprintf, rz_io_bind_t::io, and rz_debug_t::iob.

Referenced by rz_debug_bochs_map_get(), rz_debug_bochs_reg_read(), rz_debug_bochs_step(), and rz_debug_bochs_wait().

◆ map_free()

void map_free ( RzDebugMap map)

Definition at line 216 of file debug_bochs.c.

216  {
217  free(map->name);
218  free(map);
219 }
size_t map(int syms, int left, int len)
Definition: enough.c:237
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130

References free(), and map().

Referenced by rz_debug_bochs_map_get().

◆ rz_debug_bochs_attach()

static int rz_debug_bochs_attach ( RzDebug dbg,
int  pid 
)
static

Definition at line 336 of file debug_bochs.c.

336  {
337  RzIODesc *d = dbg->iob.io->desc;
338  // eprintf ("bochs_attach:\n");
339  dbg->swstep = false;
340  if (d && d->plugin && d->plugin->name && d->data) {
341  if (!strcmp("bochs", d->plugin->name)) {
342  RzIOBochs *g = d->data;
343  // int arch = rz_sys_arch_id (dbg->arch);
344  // int bits = dbg->analysis->bits;
345  if ((desc = &g->desc)) {
346  eprintf("bochs attach: ok\n");
347  saveRegs = malloc(1024);
348  bCapturaRegs = true;
349  bStep = false;
350  bBreak = false;
351  }
352  }
353  }
354  return true;
355 }
static bool bCapturaRegs
Definition: debug_bochs.c:7
static char * saveRegs
Definition: debug_bochs.c:11
static bool bStep
Definition: debug_bochs.c:8
struct @667 g
void * malloc(size_t size)
Definition: malloc.c:123
int swstep
Definition: rz_debug.h:261

References bBreak, bCapturaRegs, bStep, d, dbg, desc, rz_io_t::desc, eprintf, g, rz_io_bind_t::io, rz_debug_t::iob, malloc(), saveRegs, and rz_debug_t::swstep.

◆ rz_debug_bochs_breakpoint()

static int rz_debug_bochs_breakpoint ( RzBreakpoint bp,
RzBreakpointItem b,
bool  set 
)
static

Definition at line 31 of file debug_bochs.c.

31  {
32  char cmd[64];
33  char num[4];
34  char addr[19];
35  char bufcmd[100];
36  ut64 a;
37  int n, i, lenRec;
38  // eprintf ("bochs_breakpoint\n");
39  if (!b) {
40  return false;
41  }
42  if (set) {
43  // eprintf("[set] bochs_breakpoint %016"PFMT64x"\n",bp->addr);
44  sprintf(cmd, "lb 0x%x", (ut32)b->addr);
45  bochs_send_cmd(desc, cmd, true);
46  bCapturaRegs = true;
47  } else {
48  // eprintf("[unset] bochs_breakpoint %016"PFMT64x"\n",bp->addr);
49  /*
50  Num Type Disp Enb Address
51  1 lbreakpoint keep y 0x0000000000007c00
52  2 lbreakpoint keep y 0x0000000000007c00
53  <bochs:39>
54  */
55  bochs_send_cmd(desc, "blist", true);
56  lenRec = strlen(desc->data);
57  a = -1;
58  n = 0;
59  if (!strncmp(desc->data, "Num Type", 8)) {
60  i = 37;
61  do {
62  if (desc->data[i + 24] == 'y') {
63  strncpy(num, &desc->data[i], 3);
64  num[3] = 0;
65  strncpy(addr, &desc->data[i + 28], 18);
66  addr[18] = 0;
67  n = rz_num_get(NULL, num);
68  a = rz_num_get(NULL, addr);
69  // eprintf("parseado %x %016"PFMT64x"\n",n,a);
70  if (a == b->addr) {
71  break;
72  }
73  }
74  i += 48;
75  } while (desc->data[i] != '<' && i < lenRec - 4);
76  }
77  if (a == b->addr) {
78  snprintf(bufcmd, sizeof(bufcmd), "d %i", n);
79  // eprintf("[unset] Break point localizado indice = %x (%x) %s \n",n,(DWORD)a,bufcmd);
80  bochs_send_cmd(desc, bufcmd, true);
81  }
82  }
83  return true;
84 }
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
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
uint32_t ut32
snprintf
Definition: kernel.h:364
sprintf
Definition: kernel.h:365
void bochs_send_cmd(libbochs_t *b, const char *comando, bool bWait)
Definition: libbochs.c:117
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 static sig const char static mode static oldfd struct tms static buf static getgid static geteuid const char static filename static arg static mask struct ustat static ubuf static getppid static setsid static egid sigset_t static set struct timeval struct timezone static tz fd_set fd_set fd_set struct timeval static timeout const char char static bufsiz const char static swapflags void static offset const char static length static mode static who const char struct statfs static buf unsigned unsigned num
Definition: sflib.h:126
int n
Definition: mipsasm.c:19
RZ_API ut64 rz_num_get(RzNum *num, const char *str)
Definition: unum.c:172
#define b(i)
Definition: sha256.c:42
#define a(i)
Definition: sha256.c:41
char * data
Definition: libbochs.h:15
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58

References a, addr, b, bCapturaRegs, bochs_send_cmd(), cmd, libbochs_t::data, desc, i, n, NULL, num, rz_num_get(), snprintf, sprintf, and ut64().

◆ rz_debug_bochs_continue()

static int rz_debug_bochs_continue ( RzDebug dbg,
int  pid,
int  tid,
int  sig 
)
static

Definition at line 257 of file debug_bochs.c.

257  {
258  // eprintf ("bochs_continue:\n");
259  bochs_send_cmd(desc, "c", false);
260  bCapturaRegs = true;
261  bBreak = false;
262  return true;
263 }

References bBreak, bCapturaRegs, bochs_send_cmd(), and desc.

◆ rz_debug_bochs_detach()

static int rz_debug_bochs_detach ( RzDebug dbg,
int  pid 
)
static

Definition at line 357 of file debug_bochs.c.

357  {
358  // eprintf ("bochs_detach:\n");
359  free(saveRegs);
360  return true;
361 }

References free(), and saveRegs.

◆ rz_debug_bochs_map_get()

static RzList* rz_debug_bochs_map_get ( RzDebug dbg)
static

Definition at line 221 of file debug_bochs.c.

221  { // TODO
222  if (!isBochs(dbg)) {
223  return NULL;
224  }
225  // eprintf("bochs_map_getdebug:\n");
226  RzDebugMap *mr;
228  if (!list) {
229  return NULL;
230  }
231  mr = RZ_NEW0(RzDebugMap);
232  if (!mr) {
234  return NULL;
235  }
236  mr->name = strdup("fake");
237  mr->addr = 0;
238  mr->addr_end = UT32_MAX;
239  mr->size = UT32_MAX;
240  mr->perm = 0;
241  mr->user = 0;
243  return list;
244 }
static int mr(RzAnalysisEsil *esil, ut64 addr, ut8 *buf, int len)
Definition: cmd_analysis.c:471
static bool isBochs(RzDebug *dbg)
Definition: debug_bochs.c:20
void map_free(RzDebugMap *map)
Definition: debug_bochs.c:216
static void list(RzEgg *egg)
Definition: rz-gg.c:52
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
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")
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define UT32_MAX
Definition: rz_types_base.h:99

References dbg, isBochs(), list(), map_free(), mr(), NULL, rz_list_append(), rz_list_free(), rz_list_newf(), RZ_NEW0, strdup(), and UT32_MAX.

◆ rz_debug_bochs_reg_profile()

static const char* rz_debug_bochs_reg_profile ( RzDebug dbg)
static

Definition at line 363 of file debug_bochs.c.

363  {
364  int bits = dbg->analysis->bits;
365 
366  if (bits == 16 || bits == 32 || bits == 64) {
367  return strdup(
368  "=PC csip\n"
369  "=SP rsp\n"
370  "=BP rbp\n"
371  "=A0 rax\n"
372  "=A1 rbx\n"
373  "=A2 rcx\n"
374  "=A3 rdi\n"
375 
376  "seg es 2 0x038 0 \n"
377  "seg cs 2 0x03A 0 \n"
378  "seg ss 2 0x03C 0 \n"
379  "seg ds 2 0x03E 0 \n"
380  "seg fs 2 0x040 0 \n"
381  "seg gs 2 0x042 0 \n"
382 
383  "gpr rax 8 0x078 0 \n"
384  "gpr eax 4 0x078 0 \n"
385  "gpr ax 2 0x078 0 \n"
386  "gpr al 1 0x078 0 \n"
387  "gpr rcx 8 0x080 0 \n"
388  "gpr ecx 4 0x080 0 \n"
389  "gpr cx 2 0x080 0 \n"
390  "gpr cl 1 0x078 0 \n"
391  "gpr rdx 8 0x088 0 \n"
392  "gpr edx 4 0x088 0 \n"
393  "gpr dx 2 0x088 0 \n"
394  "gpr dl 1 0x088 0 \n"
395  "gpr rbx 8 0x090 0 \n"
396  "gpr ebx 4 0x090 0 \n"
397  "gpr bx 2 0x090 0 \n"
398  "gpr bl 1 0x090 0 \n"
399  "gpr rsp 8 0x098 0 \n"
400  "gpr esp 4 0x098 0 \n"
401  "gpr sp 2 0x098 0 \n"
402  "gpr spl 1 0x098 0 \n"
403  "gpr rbp 8 0x0A0 0 \n"
404  "gpr ebp 4 0x0A0 0 \n"
405  "gpr bp 2 0x0A0 0 \n"
406  "gpr bpl 1 0x0A0 0 \n"
407  "gpr rsi 8 0x0A8 0 \n"
408  "gpr esi 4 0x0A8 0 \n"
409  "gpr si 2 0x0A8 0 \n"
410  "gpr sil 1 0x0A8 0 \n"
411  "gpr rdi 8 0x0B0 0 \n"
412  "gpr edi 4 0x0B0 0 \n"
413  "gpr di 2 0x0B0 0 \n"
414  "gpr dil 1 0x0B0 0 \n"
415  "gpr r8 8 0x0B8 0 \n"
416  "gpr r8d 4 0x0B8 0 \n"
417  "gpr r8w 2 0x0B8 0 \n"
418  "gpr r8b 1 0x0B8 0 \n"
419  "gpr r9 8 0x0C0 0 \n"
420  "gpr r9d 4 0x0C0 0 \n"
421  "gpr r9w 2 0x0C0 0 \n"
422  "gpr r9b 1 0x0C0 0 \n"
423  "gpr r10 8 0x0C8 0 \n"
424  "gpr r10d 4 0x0C8 0 \n"
425  "gpr r10w 2 0x0C8 0 \n"
426  "gpr r10b 1 0x0C8 0 \n"
427  "gpr r11 8 0x0D0 0 \n"
428  "gpr r11d 4 0x0D0 0 \n"
429  "gpr r11w 2 0x0D0 0 \n"
430  "gpr r11b 1 0x0D0 0 \n"
431  "gpr r12 8 0x0D8 0 \n"
432  "gpr r12d 4 0x0D8 0 \n"
433  "gpr r12w 2 0x0D8 0 \n"
434  "gpr r12b 1 0x0D8 0 \n"
435  "gpr r13 8 0x0E0 0 \n"
436  "gpr r13d 4 0x0E0 0 \n"
437  "gpr r13w 2 0x0E0 0 \n"
438  "gpr r13b 1 0x0E0 0 \n"
439  "gpr r14 8 0x0E8 0 \n"
440  "gpr r14d 4 0x0E8 0 \n"
441  "gpr r14w 2 0x0E8 0 \n"
442  "gpr r14b 1 0x0E8 0 \n"
443  "gpr r15 8 0x0F0 0 \n"
444  "gpr r15d 4 0x0F0 0 \n"
445  "gpr r15w 2 0x0F0 0 \n"
446  "gpr r15b 1 0x0F0 0 \n"
447  "gpr rip 8 0x0F8 0 \n"
448  "gpr eip 4 0x0F8 0 \n"
449  "gpr csip 8 0x000 0 \n"
450  /*
451  "gpr mxcsr 4 0x034 0 \n"
452  "seg cs 2 0x038 0 \n"
453  "seg ds 2 0x03A 0 \n"
454  "seg es 2 0x03C 0 \n"
455  "seg fs 2 0x03E 0 \n"
456  "seg gs 2 0x040 0 \n"
457  "seg ss 2 0x042 0 \n"
458  "gpr eflags 4 0x044 0 \n"
459  "drx dr0 8 0x048 0 \n"
460  "drx dr1 8 0x050 0 \n"
461  "drx dr2 8 0x058 0 \n"
462  "drx dr3 8 0x060 0 \n"
463  "drx dr6 8 0x068 0 \n"
464  "drx dr7 8 0x070 0 \n"
465  "gpr rax 8 0x078 0 \n"
466  "gpr eax 4 0x078 0 \n"
467  "gpr ax 2 0x078 0 \n"
468  "gpr al 1 0x078 0 \n"
469  "gpr rcx 8 0x080 0 \n"
470  "gpr ecx 4 0x080 0 \n"
471  "gpr cx 2 0x080 0 \n"
472  "gpr cl 1 0x078 0 \n"
473  "gpr rdx 8 0x088 0 \n"
474  "gpr edx 4 0x088 0 \n"
475  "gpr dx 2 0x088 0 \n"
476  "gpr dl 1 0x088 0 \n"
477  "gpr rbx 8 0x090 0 \n"
478  "gpr ebx 4 0x090 0 \n"
479  "gpr bx 2 0x090 0 \n"
480  "gpr bl 1 0x090 0 \n"
481  "gpr rsp 8 0x098 0 \n"
482  "gpr esp 4 0x098 0 \n"
483  "gpr sp 2 0x098 0 \n"
484  "gpr spl 1 0x098 0 \n"
485  "gpr rbp 8 0x0A0 0 \n"
486  "gpr ebp 4 0x0A0 0 \n"
487  "gpr bp 2 0x0A0 0 \n"
488  "gpr bpl 1 0x0A0 0 \n"
489  "gpr rsi 8 0x0A8 0 \n"
490  "gpr esi 4 0x0A8 0 \n"
491  "gpr si 2 0x0A8 0 \n"
492  "gpr sil 1 0x0A8 0 \n"
493  "gpr rdi 8 0x0B0 0 \n"
494  "gpr edi 4 0x0B0 0 \n"
495  "gpr di 2 0x0B0 0 \n"
496  "gpr dil 1 0x0B0 0 \n"
497  "gpr r8 8 0x0B8 0 \n"
498  "gpr r8d 4 0x0B8 0 \n"
499  "gpr r8w 2 0x0B8 0 \n"
500  "gpr r8b 1 0x0B8 0 \n"
501  "gpr r9 8 0x0C0 0 \n"
502  "gpr r9d 4 0x0C0 0 \n"
503  "gpr r9w 2 0x0C0 0 \n"
504  "gpr r9b 1 0x0C0 0 \n"
505  "gpr r10 8 0x0C8 0 \n"
506  "gpr r10d 4 0x0C8 0 \n"
507  "gpr r10w 2 0x0C8 0 \n"
508  "gpr r10b 1 0x0C8 0 \n"
509  "gpr r11 8 0x0D0 0 \n"
510  "gpr r11d 4 0x0D0 0 \n"
511  "gpr r11w 2 0x0D0 0 \n"
512  "gpr r11b 1 0x0D0 0 \n"
513  "gpr r12 8 0x0D8 0 \n"
514  "gpr r12d 4 0x0D8 0 \n"
515  "gpr r12w 2 0x0D8 0 \n"
516  "gpr r12b 1 0x0D8 0 \n"
517  "gpr r13 8 0x0E0 0 \n"
518  "gpr r13d 4 0x0E0 0 \n"
519  "gpr r13w 2 0x0E0 0 \n"
520  "gpr r13b 1 0x0E0 0 \n"
521  "gpr r14 8 0x0E8 0 \n"
522  "gpr r14d 4 0x0E8 0 \n"
523  "gpr r14w 2 0x0E8 0 \n"
524  "gpr r14b 1 0x0E8 0 \n"
525  "gpr r15 8 0x0F0 0 \n"
526  "gpr r15d 4 0x0F0 0 \n"
527  "gpr r15w 2 0x0F0 0 \n"
528  "gpr r15b 1 0x0F0 0 \n"
529  "gpr rip 8 0x0F8 0 \n"
530  "gpr cf .1 .544 0 carry\n"
531  "gpr pf .1 .546 0 parity\n"
532  "gpr af .1 .548 0 adjust\n"
533  "gpr zf .1 .550 0 zero\n"
534  "gpr sf .1 .551 0 sign\n"
535  "gpr tf .1 .552 0 trap\n"
536  "gpr if .1 .553 0 interrupt\n"
537  "gpr df .1 .554 0 direction\n"
538  "gpr of .1 .555 0 overflow\n"
539  */
540  );
541  }
542  return NULL;
543 }
int bits(struct state *s, int need)
Definition: blast.c:72
RzAnalysis * analysis
Definition: rz_debug.h:305

References rz_debug_t::analysis, rz_analysis_t::bits, bits(), dbg, NULL, and strdup().

◆ rz_debug_bochs_reg_read()

static int rz_debug_bochs_reg_read ( RzDebug dbg,
int  type,
ut8 buf,
int  size 
)
static

Definition at line 86 of file debug_bochs.c.

86  {
87  char strReg[19];
88  char regname[4];
89  char strBase[19];
90  char strLimit[19];
91  int i = 0, pos = 0, lenRec = 0;
92  ut64 val = 0, valRIP = 0; //, posRIP = 0;
93  if (!isBochs(dbg)) {
94  return 0;
95  }
96 
97  // eprintf ("bochs_reg_read\n");
98  if (bCapturaRegs == true) {
99  bochs_send_cmd(desc, "regs", true);
100  // r14: 00000000_00000000 r15: 00000000_00000000
101  // rip: 00000000_0000e07b
102  // eflags 0x00000046: id vip vif ac vm rf nt IOPL=0 of df if tf sf ZF af PF cf
103  //<bochs:109>return -1;
104  pos = 0x78;
105  lenRec = strlen(desc->data);
106  while (desc->data[i] != 0 && i < lenRec - 4) {
107  if ((desc->data[i] == (ut8)'r' && desc->data[i + 3] == (ut8)':')) {
108  strncpy(regname, &desc->data[i], 3);
109  regname[3] = 0;
110  strncpy(&strReg[2], &desc->data[i + 5], 8);
111  strncpy(&strReg[10], &desc->data[i + 14], 8);
112  strReg[0] = '0';
113  strReg[1] = 'x';
114  strReg[18] = 0;
115  i += 22;
116  val = rz_num_get(NULL, strReg);
117  // eprintf("parseado %s = %s valx64 = %016"PFMT64x"\n", regname, strReg,val);
118  memcpy(&buf[pos], &val, 8);
119  // guardamos la posicion del rip y su valor para ajustarlo al obtener el CS
120  if (!strncmp(regname, "rip", 3)) {
121  // UNUSED posRIP = pos;
122  valRIP = val;
123  }
124  pos += 8;
125 
126  } else {
127  i++;
128  }
129  }
130 
131  bochs_send_cmd(desc, "info cpu", true);
132  if (strstr(desc->data, "PC_32")) {
133  bAjusta = true;
134  // eprintf("[modo PC_32]\n");
135  } else if (strstr(desc->data, "PC_80")) {
136  bAjusta = false;
137  // eprintf("[modo PC_80]\n");
138  } else if (strstr(desc->data, "PC_64")) {
139  bAjusta = false;
140  // eprintf("[modo PC_64]\n");
141  } else {
142  eprintf("[unknown mode]\n%s\n", desc->data);
143  }
144  /*
145  es:0x0000, dh=0x00009300, dl=0x0000ffff, valid=7
146  Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
147  cs:0xf000, dh=0xff0093ff, dl=0x0000ffff, valid=7
148  Data segment, base=0xffff0000, limit=0x0000ffff, Read/Write, Accessed
149  ss:0x0000, dh=0x00009300, dl=0x0000ffff, valid=7
150  Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
151  ds:0x0000, dh=0x00009300, dl=0x0000ffff, valid=7
152  Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
153  fs:0x0000, dh=0x00009300, dl=0x0000ffff, valid=7
154  Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
155  gs:0x0000, dh=0x00009300, dl=0x0000ffff, valid=7
156  Data segment, base=0x00000000, limit=0x0000ffff, Read/Write, Accessed
157  ldtr:0x0000, dh=0x00008200, dl=0x0000ffff, valid=1
158  tr:0x0000, dh=0x00008b00, dl=0x0000ffff, valid=1
159  gdtr:base=0x0000000000000000, limit=0xffff
160  idtr:base=0x0000000000000000, limit=0xffff
161  */
162  bochs_send_cmd(desc, "sreg", true);
163 
164  pos = 0x38;
165  char *s[] = { "es:0x", "cs:0x", "ss:0x", "ds:0x", "fs:0x", "gs:0x", 0 };
166  const char *x;
167  int n;
168  for (n = 0; s[n] != 0; n++) {
169  if ((x = strstr(desc->data, s[n]))) {
170  strncpy(&strReg[0], x + 3, 7);
171  strReg[6] = 0;
172  val = rz_num_get(NULL, strReg);
173  strncpy(regname, s[n], 2);
174  regname[2] = 0;
175  if ((x = strstr(x, "base="))) {
176  strncpy(strBase, x + 5, 10);
177  strBase[10] = 0;
178  if ((x = strstr(x, "limit="))) {
179  strncpy(strLimit, x + 6, 10);
180  strLimit[10] = 0;
181  }
182  }
183  // eprintf("%s localizado %s %04x base = %s limit = %s\n",regname,strReg,(WORD)val,strBase,strLimit);
184  memcpy(&buf[pos], &val, 2);
185  pos += 2;
186  if (bAjusta) {
187  if (!strncmp(regname, "cs", 2)) {
188  valRIP += (val * 0x10); // desplazamos CS y lo aƱadimos a RIP
189  // eprintf("%016"PFMT64x"\n",valRIP);
190  }
191  }
192  }
193  }
194  // Cheat para evitar traducciones de direcciones
195  if (ripStop != 0) {
196  memcpy(&buf[0], &ripStop, 8);
197  } else {
198  memcpy(&buf[0], &valRIP, 8); // guardamos el valor cs:ip en el registro virtual "vip"
199  }
200  // eprintf("guardando regs procesados%x\n",size);
201  memcpy(saveRegs, buf, size);
202  bCapturaRegs = false;
203  // eprintf("bochs_reg_read\n");
204  } else {
205  memcpy(buf, saveRegs, size);
206  // eprintf("[cache] bochs_reg_read\n");
207  }
208  return size;
209 }
ut16 val
Definition: armass64_const.h:6
static bool bAjusta
Definition: debug_bochs.c:10
static ut64 ripStop
Definition: debug_bochs.c:12
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
memcpy(mem, inblock.get(), min(CONTAINING_RECORD(inblock.get(), MEMBLOCK, data) ->size, size))
int x
Definition: mipsasm.c:20
static RzSocket * s
Definition: rtr.c:28
int pos
Definition: main.c:11
static char * regname(int reg)
Definition: dis.c:71

References bAjusta, bCapturaRegs, bochs_send_cmd(), libbochs_t::data, dbg, desc, eprintf, i, isBochs(), memcpy(), n, NULL, pos, regname(), ripStop, rz_num_get(), s, saveRegs, ut64(), val, and x.

◆ rz_debug_bochs_reg_write()

static int rz_debug_bochs_reg_write ( RzDebug dbg,
int  type,
const ut8 buf,
int  size 
)
static

Definition at line 211 of file debug_bochs.c.

211  {
212  // eprintf("bochs_reg_write\n");
213  return -1;
214 }

◆ rz_debug_bochs_step()

static int rz_debug_bochs_step ( RzDebug dbg)
static

Definition at line 246 of file debug_bochs.c.

246  {
247  if (!isBochs(dbg)) {
248  return false;
249  }
250  // eprintf ("bochs_step\n");
251  bochs_send_cmd(desc, "s", true);
252  bCapturaRegs = true;
253  bStep = true;
254  return true;
255 }

References bCapturaRegs, bochs_send_cmd(), bStep, dbg, desc, and isBochs().

◆ rz_debug_bochs_stop()

static int rz_debug_bochs_stop ( RzDebug dbg)
static

Definition at line 328 of file debug_bochs.c.

328  {
329  // eprintf("bochs_stop:\n");
330  // RzIOBdescbg *o = dbg->iob.io->desc->data;
331  // BfvmCPU *c = o->bfvm;
332  // c->breaked = true;
333  return true;
334 }

◆ rz_debug_bochs_wait()

static RzDebugReasonType rz_debug_bochs_wait ( RzDebug dbg,
int  pid 
)
static

Definition at line 271 of file debug_bochs.c.

271  {
272  if (!isBochs(dbg)) {
273  return RZ_DEBUG_REASON_ERROR;
274  }
275  char strIP[19];
276  int i = 0;
277  const char *x;
278  char *ini = 0, *fin = 0;
279 
280  // eprintf ("bochs_wait:\n");
281 
282  if (bStep) {
283  bStep = false;
284  } else {
286  i = 500;
287  do {
288  bochs_wait(desc);
289  if (bBreak) {
290  if (desc->data[0]) {
291  eprintf("ctrl+c %s\n", desc->data);
292  bBreak = false;
293  break;
294  }
295  i--;
296  if (!i) {
297  bBreak = false;
298  eprintf("empty ctrl+c.\n");
299  break;
300  }
301  } else if (desc->data[0]) {
302  // eprintf("stop on breakpoint%s\n",desc->data);
303  break;
304  }
305  } while (1);
307  }
308  // eprintf ("bochs_wait: loop done\n");
309  // Next at t=394241428
310  // (0) [0x000000337635] 0020:0000000000337635 (unk. ctxt): add eax, esi ; 03c6
311  ripStop = 0;
312  if ((x = strstr(desc->data, "Next at"))) {
313  if ((ini = strstr(x, "[0x"))) {
314  if ((fin = strchr(ini, ']'))) {
315  int len = fin - ini - 1;
316  strncpy(strIP, ini + 1, len);
317  strIP[len] = 0;
318  // eprintf(" parada EIP = %s\n",strIP);
319  ripStop = rz_num_get(NULL, strIP);
320  }
321  }
322  }
323  desc->data[0] = 0;
324 
325  return RZ_DEBUG_REASON_NONE;
326 }
size_t len
Definition: 6502dis.c:15
RZ_API void rz_cons_break_pop(void)
Definition: cons.c:361
RZ_API void rz_cons_break_push(RzConsBreak cb, void *user)
Definition: cons.c:357
static void bochs_debug_break(void *u)
Definition: debug_bochs.c:265
bool bochs_wait(libbochs_t *b)
Definition: libbochs.c:70
@ RZ_DEBUG_REASON_ERROR
Definition: rz_debug.h:104
@ RZ_DEBUG_REASON_NONE
Definition: rz_debug.h:91

References bBreak, bochs_debug_break(), bochs_wait(), bStep, libbochs_t::data, dbg, desc, eprintf, i, isBochs(), len, NULL, ripStop, rz_cons_break_pop(), rz_cons_break_push(), RZ_DEBUG_REASON_ERROR, RZ_DEBUG_REASON_NONE, rz_num_get(), and x.

Variable Documentation

◆ bAjusta

bool bAjusta = true
static

Definition at line 10 of file debug_bochs.c.

Referenced by rz_debug_bochs_reg_read().

◆ bBreak

◆ bCapturaRegs

◆ bStep

bool bStep = false
static

Definition at line 8 of file debug_bochs.c.

Referenced by rz_debug_bochs_attach(), rz_debug_bochs_step(), and rz_debug_bochs_wait().

◆ desc

◆ ripStop

ut64 ripStop = 0LL
static

Definition at line 12 of file debug_bochs.c.

Referenced by rz_debug_bochs_reg_read(), and rz_debug_bochs_wait().

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_DBG,
}
RzDebugPlugin rz_debug_plugin_bochs
Definition: debug_bochs.c:545
@ RZ_LIB_TYPE_DBG
Definition: rz_lib.h:70
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_debug.h:362

Definition at line 565 of file debug_bochs.c.

◆ rz_debug_plugin_bochs

RzDebugPlugin rz_debug_plugin_bochs
Initial value:
= {
.name = "bochs",
.license = "LGPL3",
.arch = "x86",
.canstep = 1,
.reg_write = &rz_debug_bochs_reg_write,
.reg_profile = (void *)rz_debug_bochs_reg_profile,
}
static int rz_debug_bochs_continue(RzDebug *dbg, int pid, int tid, int sig)
Definition: debug_bochs.c:257
static int rz_debug_bochs_breakpoint(RzBreakpoint *bp, RzBreakpointItem *b, bool set)
Definition: debug_bochs.c:31
static const char * rz_debug_bochs_reg_profile(RzDebug *dbg)
Definition: debug_bochs.c:363
static RzList * rz_debug_bochs_map_get(RzDebug *dbg)
Definition: debug_bochs.c:221
static int rz_debug_bochs_detach(RzDebug *dbg, int pid)
Definition: debug_bochs.c:357
static int rz_debug_bochs_attach(RzDebug *dbg, int pid)
Definition: debug_bochs.c:336
static int rz_debug_bochs_step(RzDebug *dbg)
Definition: debug_bochs.c:246
static int rz_debug_bochs_reg_read(RzDebug *dbg, int type, ut8 *buf, int size)
Definition: debug_bochs.c:86
static int rz_debug_bochs_reg_write(RzDebug *dbg, int type, const ut8 *buf, int size)
Definition: debug_bochs.c:211
static int rz_debug_bochs_stop(RzDebug *dbg)
Definition: debug_bochs.c:328
static RzDebugReasonType rz_debug_bochs_wait(RzDebug *dbg, int pid)
Definition: debug_bochs.c:271
@ RZ_SYS_BITS_32
Definition: rz_sys.h:20
@ RZ_SYS_BITS_64
Definition: rz_sys.h:21
@ RZ_SYS_BITS_16
Definition: rz_sys.h:19

Definition at line 545 of file debug_bochs.c.

◆ saveRegs

char* saveRegs
static