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);
62
rz_run_parseline
(
p
,
line
);
63
directiveIndex++;
64
free
(
line
);
65
}
else
{
66
rz_run_parseline
(
p
,
argv
[
i
]);
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
}
i
lzma_index ** i
Definition:
index.h:629
RZ_API
#define RZ_API
Definition:
core_plugin_example.c:36
NULL
#define NULL
Definition:
cris-opc.c:27
printf
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition:
cs_driver.c:93
close
static static fork const void static count close
Definition:
sflib.h:33
free
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition:
ht_inc.c:130
p
void * p
Definition:
libc.cpp:67
rz_main_rz_run
RZ_API int rz_main_rz_run(int argc, const char **argv)
Definition:
rz-run.c:25
argv
static static fork const void static count static fd const char const char static newpath char char argv
Definition:
sflib.h:40
dup2
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
setup.line
line
Definition:
setup.py:34
eprintf
#define eprintf(x, y...)
Definition:
rlcc.c:7
rz_main.h
rz_main_version_print
RZ_API int rz_main_version_print(const char *program)
Definition:
main.c:49
rz_socket.h
rz_run_free
RZ_API void rz_run_free(RzRunProfile *r)
Definition:
run.c:122
rz_run_new
RZ_API RzRunProfile * rz_run_new(const char *str)
Definition:
run.c:86
rz_run_help
RZ_API const char * rz_run_help(void)
Definition:
run.c:630
rz_run_parseline
RZ_API bool rz_run_parseline(RzRunProfile *p, const char *b)
Definition:
run.c:479
rz_run_start
RZ_API int rz_run_start(RzRunProfile *p)
Definition:
run.c:1081
rz_run_config_env
RZ_API int rz_run_config_env(RzRunProfile *p)
Definition:
run.c:809
rz_str_newf
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
rz_sys_xsystem
#define rz_sys_xsystem(cmd)
Definition:
rz_sys.h:83
rz_sys_signal
RZ_API int rz_sys_signal(int sig, void(*handler)(int))
Definition:
sys.c:178
rz_util.h
file
Definition:
gzappend.c:170
rz_run_profile_t
Definition:
rz_socket.h:212
librz
main
rz-run.c
Generated by
1.9.1