Rizin
unix-like reverse engineering framework and cli tools
io_bochs.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2016-2017 SkUaTeR <skuater@hotmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_io.h>
5 #include <rz_lib.h>
6 #include <rz_util.h>
7 #include <libbochs.h>
8 
9 typedef struct {
11 } RzIOBochs;
12 
13 static libbochs_t *desc = NULL;
15 extern RzIOPlugin rz_io_plugin_bochs; // forward declaration
16 
17 static bool __plugin_open(RzIO *io, const char *file, bool many) {
18  return !strncmp(file, "bochs://", strlen("bochs://"));
19 }
20 
21 static RzIODesc *__open(RzIO *io, const char *file, int rw, int mode) {
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 }
62 
63 static int __write(RzIO *io, RzIODesc *fd, const ut8 *buf, int count) {
64  lprintf("io_write\n");
65  return -1;
66 }
67 
68 static ut64 __lseek(RzIO *io, RzIODesc *fd, ut64 offset, int whence) {
69  lprintf("io_seek %016" PFMT64x " \n", offset);
70  return offset;
71 }
72 
73 static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count) {
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 }
83 
84 static int __close(RzIODesc *fd) {
85  lprintf("io_close\n");
87  return true;
88 }
89 
90 static char *__system(RzIO *io, RzIODesc *fd, const char *cmd) {
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 }
105 
107  .name = "bochs",
108  .desc = "Attach to a BOCHS debugger instance",
109  .license = "LGPL3",
110  .uris = "bochs://",
111  .open = __open,
112  .close = __close,
113  .read = __read,
114  .write = __write,
115  .check = __plugin_open,
116  .lseek = __lseek,
117  .system = __system,
118  .isdbg = true
119 };
120 
121 #ifndef RZ_PLUGIN_INCORE
123  .type = RZ_LIB_TYPE_IO,
124  .data = &rz_io_plugin_bochs,
126 };
127 #endif
lzma_index ** i
Definition: index.h:629
#define RZ_API
#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 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
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
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
static RzIODesc * riobochs
Definition: io_bochs.c:14
static int __read(RzIO *io, RzIODesc *fd, ut8 *buf, int count)
Definition: io_bochs.c:73
RzIOPlugin rz_io_plugin_bochs
Definition: io_bochs.c:106
static libbochs_t * desc
Definition: io_bochs.c:13
static bool __plugin_open(RzIO *io, const char *file, bool many)
Definition: io_bochs.c:17
RZ_API RzLibStruct rizin_plugin
Definition: io_bochs.c:122
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
voidpf uLong offset
Definition: ioapi.h:144
const char int mode
Definition: ioapi.h:137
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
int bochs_read(libbochs_t *b, ut64 addr, int count, ut8 *buf)
Definition: libbochs.c:136
#define lprintf(x, y...)
Definition: libbochs.h:64
void bochs_send_cmd(libbochs_t *b, const char *comando, bool bWait)
Definition: libbochs.c:117
bool bochs_open(libbochs_t *b, const char *rutaBochs, const char *rutaConfig)
Definition: libbochs.c:188
void bochs_close(libbochs_t *b)
Definition: libbochs.c:168
bool bochs_cmd_stop(libbochs_t *b)
Definition: libbochs.c:45
return memset(p, 0, total)
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_LIB_TYPE_IO
Definition: rz_lib.h:69
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
#define PFMT64x
Definition: rz_types.h:393
#define RZ_VERSION
Definition: rz_version.h:8
libbochs_t desc
Definition: debug_bochs.c:15
Definition: gzappend.c:170
char * data
Definition: libbochs.h:15
const char * name
Definition: rz_io.h:115
const char * version
Definition: rz_io.h:117
Definition: rz_io.h:59
ut64 off
Definition: rz_io.h:61
PrintfCallback cb_printf
Definition: rz_io.h:91
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static const z80_opcode fd[]
Definition: z80_tab.h:997
static int addr
Definition: z80asm.c:58