Rizin
unix-like reverse engineering framework and cli tools
rizin.c File Reference
#include <rz_main.h>
#include <rz_util.h>

Go to the source code of this file.

Functions

static void rz_cmd (int in, int out, const char *cmd)
 
static int rz_main_rzpipe (int argc, const char **argv)
 
int MAIN_NAME (int argc, const ARGV_TYPE **argv)
 

Function Documentation

◆ MAIN_NAME()

int MAIN_NAME ( int  argc,
const ARGV_TYPE **  argv 
)

Definition at line 51 of file rizin.c.

51  {
52  char **utf8_argv = ARGV_TYPE_TO_UTF8(argc, argv);
53  int ret;
54  if (argc > 0 && strstr(utf8_argv[0], "rzp")) {
55  ret = rz_main_rzpipe(argc, (const char **)utf8_argv);
56  } else {
57  ret = rz_main_rizin(argc, (const char **)utf8_argv);
58  }
59  FREE_UTF8_ARGV(argc, utf8_argv);
60  return ret;
61 }
static int rz_main_rzpipe(int argc, const char **argv)
Definition: rizin.c:31
RZ_API int rz_main_rizin(int argc, const char **argv)
Definition: rizin.c:370
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
#define ARGV_TYPE_TO_UTF8(argc, argv)
Definition: rz_main.h:30
#define FREE_UTF8_ARGV(argc, utf8_argv)
Definition: rz_main.h:31

References argv, ARGV_TYPE_TO_UTF8, FREE_UTF8_ARGV, rz_main_rizin(), and rz_main_rzpipe().

◆ rz_cmd()

static void rz_cmd ( int  in,
int  out,
const char *  cmd 
)
static

Definition at line 7 of file rizin.c.

7  {
8  rz_xwrite(out, cmd, strlen(cmd) + 1);
9  rz_xwrite(out, "\n", 1);
10  int bufsz = (1024 * 64);
11  unsigned char *buf = malloc(bufsz);
12  if (!buf) {
13  return;
14  }
15  while (1) {
16  rz_xread(in, buf, bufsz);
17  buf[bufsz - 1] = '\0';
18  int len = strlen((const char *)buf);
19  if (len < 1) {
20  break;
21  }
22  rz_xwrite(1, buf, len);
23  if (len != bufsz) {
24  break;
25  }
26  }
27  free(buf);
28  rz_xwrite(1, "\n", 1);
29 }
size_t len
Definition: 6502dis.c:15
const lzma_allocator const uint8_t * in
Definition: block.h:527
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
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
voidpf void * buf
Definition: ioapi.h:138
void * malloc(size_t size)
Definition: malloc.c:123
#define rz_xread(fd, buf, count)
Definition: rz_types.h:643
#define rz_xwrite(fd, buf, count)
Definition: rz_types.h:642

References cmd, free(), in, len, malloc(), out, rz_xread, and rz_xwrite.

Referenced by convert_dotcmd_to_image(), and rz_main_rzpipe().

◆ rz_main_rzpipe()

static int rz_main_rzpipe ( int  argc,
const char **  argv 
)
static

Definition at line 31 of file rizin.c.

31  {
32  int i, rc = 0;
33  char *_in = rz_sys_getenv("RZ_PIPE_IN");
34  char *_out = rz_sys_getenv("RZ_PIPE_OUT");
35  if (_in && _out) {
36  int in = atoi(_in);
37  int out = atoi(_out);
38  for (i = 1; i < argc; i++) {
39  rz_cmd(in, out, argv[i]);
40  }
41  } else {
42  eprintf("Error: RZ_PIPE_(IN|OUT) environment not set\n");
43  eprintf("Usage: rizin -c '!*rzp x' # run commands via rzpipe\n");
44  rc = 1;
45  }
46  free(_in);
47  free(_out);
48  return rc;
49 }
lzma_index ** i
Definition: index.h:629
static void rz_cmd(int in, int out, const char *cmd)
Definition: rizin.c:7
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API char * rz_sys_getenv(const char *key)
Get the value of an environment variable named key or NULL if none exists.
Definition: sys.c:483

References argv, eprintf, free(), i, in, out, rz_cmd(), and rz_sys_getenv().

Referenced by MAIN_NAME().