Rizin
unix-like reverse engineering framework and cli tools
io_bochs.c File Reference
#include <rz_io.h>
#include <rz_lib.h>
#include <rz_util.h>
#include <libbochs.h>

Go to the source code of this file.

Classes

struct  RzIOBochs
 

Functions

static bool __plugin_open (RzIO *io, const char *file, bool many)
 
static RzIODesc__open (RzIO *io, const char *file, int rw, int mode)
 
static int __write (RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
 
static ut64 __lseek (RzIO *io, RzIODesc *fd, ut64 offset, int whence)
 
static int __read (RzIO *io, RzIODesc *fd, ut8 *buf, int count)
 
static int __close (RzIODesc *fd)
 
static char * __system (RzIO *io, RzIODesc *fd, const char *cmd)
 

Variables

static libbochs_tdesc = NULL
 
static RzIODescriobochs = NULL
 
RzIOPlugin rz_io_plugin_bochs
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ __close()

static int __close ( RzIODesc fd)
static

Definition at line 84 of file io_bochs.c.

84  {
85  lprintf("io_close\n");
87  return true;
88 }
static libbochs_t * desc
Definition: io_bochs.c:13
#define lprintf(x, y...)
Definition: libbochs.h:64
void bochs_close(libbochs_t *b)
Definition: libbochs.c:168

References bochs_close(), desc, and lprintf.

◆ __lseek()

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

Definition at line 68 of file io_bochs.c.

68  {
69  lprintf("io_seek %016" PFMT64x " \n", offset);
70  return offset;
71 }
voidpf uLong offset
Definition: ioapi.h:144
#define PFMT64x
Definition: rz_types.h:393

References lprintf, and PFMT64x.

◆ __open()

static RzIODesc* __open ( RzIO io,
const char *  file,
int  rw,
int  mode 
)
static

Definition at line 21 of file io_bochs.c.

21  {
22  RzIOBochs *riob;
23  lprintf("io_open\n");
24  const char *i;
25  char *fileBochs = NULL;
26  char *fileCfg = NULL;
27  int l;
28  if (!__plugin_open(io, file, 0)) {
29  return NULL;
30  }
31  if (riobochs) {
32  return riobochs;
33  }
34 
35  i = strchr(file + 8, '#');
36  if (i) {
37  l = i - file - 8;
38  fileBochs = rz_str_ndup(file + 8, l);
39  fileCfg = strdup(i + 1);
40  } else {
41  free(fileCfg);
42  eprintf("Error can't find :\n");
43  return NULL;
44  }
45  riob = RZ_NEW0(RzIOBochs);
46 
47  // Inicializamos
48  if (bochs_open(&riob->desc, fileBochs, fileCfg) == true) {
49  desc = &riob->desc;
51  // riogdb = rz_io_desc_new (&rz_io_plugin_gdb, riog->desc.sock->fd, file, rw, mode, riog);
52  free(fileBochs);
53  free(fileCfg);
54  return riobochs;
55  }
56  lprintf("bochsio.open: Cannot connect to bochs.\n");
57  free(riob);
58  free(fileBochs);
59  free(fileCfg);
60  return NULL;
61 }
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static RzIODesc * riobochs
Definition: io_bochs.c:14
RzIOPlugin rz_io_plugin_bochs
Definition: io_bochs.c:106
static bool __plugin_open(RzIO *io, const char *file, bool many)
Definition: io_bochs.c:17
const char int mode
Definition: ioapi.h:137
bool bochs_open(libbochs_t *b, const char *rutaBochs, const char *rutaConfig)
Definition: libbochs.c:188
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")
#define eprintf(x, y...)
Definition: rlcc.c:7
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_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006
#define RZ_NEW0(x)
Definition: rz_types.h:284
libbochs_t desc
Definition: debug_bochs.c:15
Definition: gzappend.c:170

References __plugin_open(), bochs_open(), RzIOBochs::desc, desc, eprintf, free(), i, lprintf, NULL, riobochs, rz_io_desc_new(), rz_io_plugin_bochs, RZ_NEW0, rz_str_ndup(), and strdup().

◆ __plugin_open()

static bool __plugin_open ( RzIO io,
const char *  file,
bool  many 
)
static

Definition at line 17 of file io_bochs.c.

17  {
18  return !strncmp(file, "bochs://", strlen("bochs://"));
19 }

Referenced by __open().

◆ __read()

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

Definition at line 73 of file io_bochs.c.

73  {
74  memset(buf, 0xff, count);
75  ut64 addr = io->off;
76  if (!desc || !desc->data) {
77  return -1;
78  }
79  lprintf("io_read ofs= %016" PFMT64x " count= %x\n", io->off, count);
81  return count;
82 }
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 bochs_read(libbochs_t *b, ut64 addr, int count, ut8 *buf)
Definition: libbochs.c:136
return memset(p, 0, total)
char * data
Definition: libbochs.h:15
ut64 off
Definition: rz_io.h:61
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58

References addr, bochs_read(), count, libbochs_t::data, desc, lprintf, memset(), rz_io_t::off, PFMT64x, and ut64().

◆ __system()

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

Definition at line 90 of file io_bochs.c.

90  {
91  lprintf("system command (%s)\n", cmd);
92  if (!strcmp(cmd, "help")) {
93  lprintf("Usage: R!cmd args\n"
94  " R!:<bochscmd> - Send a bochs command.\n"
95  " R!dobreak - pause bochs.\n");
96  lprintf("io_system: Enviando commando bochs\n");
97  bochs_send_cmd(desc, &cmd[1], true);
98  io->cb_printf("%s\n", desc->data);
99  } else if (!strncmp(cmd, "dobreak", 7)) {
101  io->cb_printf("%s\n", desc->data);
102  }
103  return NULL;
104 }
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
void bochs_send_cmd(libbochs_t *b, const char *comando, bool bWait)
Definition: libbochs.c:117
bool bochs_cmd_stop(libbochs_t *b)
Definition: libbochs.c:45
PrintfCallback cb_printf
Definition: rz_io.h:91

References bochs_cmd_stop(), bochs_send_cmd(), rz_io_t::cb_printf, cmd, libbochs_t::data, desc, lprintf, and NULL.

◆ __write()

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

Definition at line 63 of file io_bochs.c.

63  {
64  lprintf("io_write\n");
65  return -1;
66 }

References lprintf.

Variable Documentation

◆ desc

libbochs_t* desc = NULL
static

Definition at line 13 of file io_bochs.c.

Referenced by __close(), __open(), __read(), and __system().

◆ riobochs

RzIODesc* riobochs = NULL
static

Definition at line 14 of file io_bochs.c.

Referenced by __open().

◆ 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 122 of file io_bochs.c.

◆ rz_io_plugin_bochs

RzIOPlugin rz_io_plugin_bochs
Initial value:
= {
.name = "bochs",
.desc = "Attach to a BOCHS debugger instance",
.license = "LGPL3",
.uris = "bochs://",
.open = __open,
.close = __close,
.read = __read,
.write = __write,
.check = __plugin_open,
.lseek = __lseek,
.system = __system,
.isdbg = true
}
static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count)
Definition: io_bochs.c:73
static RzIODesc * __open(RzIO *io, const char *file, int rw, int mode)
Definition: io_bochs.c:21
static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count)
Definition: io_bochs.c:63
static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence)
Definition: io_bochs.c:68
static int __close(RzIODesc *fd)
Definition: io_bochs.c:84
static char * __system(RzIO *io, RzIODesc *fd, const char *cmd)
Definition: io_bochs.c:90

Definition at line 106 of file io_bochs.c.

Referenced by __open().