Rizin
unix-like reverse engineering framework and cli tools
rz-run.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2011-2020 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_util.h>
5 #include <rz_main.h>
6 #include <rz_socket.h>
7 
8 #if __UNIX__
9 static void fwd(int sig) {
10  /* do nothing? send kill signal to remote process */
11 }
12 
13 static void rz_run_tty(void) {
14  /* TODO: Implement in native code */
15  rz_sys_xsystem("tty");
16  close(1);
17  dup2(2, 1);
18  rz_sys_signal(SIGINT, fwd);
19  for (;;) {
20  sleep(1);
21  }
22 }
23 #endif
24 
25 RZ_API int rz_main_rz_run(int argc, const char **argv) {
26  RzRunProfile *p;
27  int i, ret;
28  if (argc == 1 || !strcmp(argv[1], "-h")) {
29  printf("Usage: rz-run -v|-t|script.rr2 [directive ..]\n");
30  printf("%s", rz_run_help());
31  return 1;
32  }
33  if (!strcmp(argv[1], "-v")) {
34  return rz_main_version_print("rz-run");
35  }
36  const char *file = argv[1];
37  if (!strcmp(file, "-t")) {
38 #if __UNIX__
39  rz_run_tty();
40  return 0;
41 #else
42  eprintf("Not supported\n");
43  return 1;
44 #endif
45  }
46  if (*file && !strchr(file, '=')) {
47  p = rz_run_new(file);
48  } else {
49  bool noMoreDirectives = false;
50  int directiveIndex = 0;
51  p = rz_run_new(NULL);
52  for (i = *file ? 1 : 2; i < argc; i++) {
53  if (!strcmp(argv[i], "--")) {
54  noMoreDirectives = true;
55  continue;
56  }
57  if (noMoreDirectives) {
58  const char *word = argv[i];
59  char *line = directiveIndex
60  ? rz_str_newf("arg%d=%s", directiveIndex, word)
61  : rz_str_newf("program=%s", word);
63  directiveIndex++;
64  free(line);
65  } else {
67  }
68  }
69  }
70  if (!p) {
71  return 1;
72  }
73  ret = rz_run_config_env(p);
74  if (ret) {
75  printf("error while configuring the environment.\n");
76  rz_run_free(p);
77  return 1;
78  }
79  ret = rz_run_start(p);
80  rz_run_free(p);
81  return ret;
82 }
lzma_index ** i
Definition: index.h:629
#define RZ_API
#define NULL
Definition: cris-opc.c:27
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
static static fork const void static count close
Definition: sflib.h:33
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
void * p
Definition: libc.cpp:67
RZ_API int rz_main_rz_run(int argc, const char **argv)
Definition: rz-run.c:25
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
static static fork const void static count static fd const char static mode const char static pathname const char static path const char static dev const char static group static getpid static getuid void void static data static pause const char static mode static sync const char const char static newpath const char static pathname unsigned long static filedes void static end_data_segment static handler static getegid char static len static pgid const char static path dup2
Definition: sflib.h:94
line
Definition: setup.py:34
#define eprintf(x, y...)
Definition: rlcc.c:7
RZ_API int rz_main_version_print(const char *program)
Definition: main.c:49
RZ_API void rz_run_free(RzRunProfile *r)
Definition: run.c:122
RZ_API RzRunProfile * rz_run_new(const char *str)
Definition: run.c:86
RZ_API const char * rz_run_help(void)
Definition: run.c:630
RZ_API bool rz_run_parseline(RzRunProfile *p, const char *b)
Definition: run.c:479
RZ_API int rz_run_start(RzRunProfile *p)
Definition: run.c:1081
RZ_API int rz_run_config_env(RzRunProfile *p)
Definition: run.c:809
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
#define rz_sys_xsystem(cmd)
Definition: rz_sys.h:83
RZ_API int rz_sys_signal(int sig, void(*handler)(int))
Definition: sys.c:178
Definition: gzappend.c:170