Rizin
unix-like reverse engineering framework and cli tools
main.c File Reference
#include "../spp.h"
#include "../rz_api.h"

Go to the source code of this file.

Functions

static void spp_help (char *argv0)
 
int main (int argc, char **argv)
 

Variables

struct Procprocs []
 
struct Procproc
 
struct Argargs
 

Function Documentation

◆ main()

int main ( int  argc,
char **  argv 
)

Definition at line 35 of file main.c.

35  {
36  int dostdin = 1;
37  int i, j;
38  Output out;
39  out.fout = stdout;
40  char *arg;
41 
42  spp_proc_set (proc, argv[0], 0);
43 
44  if (argc < 2)
45  spp_io (stdin, &out);
46  else {
47  for(i = 1; i < argc; i++) {
48  /* check preprocessor args */
49  if (args)
50  for(j = 0; args[j].flag; j++) {
51  if (!memcmp (argv[i], args[j].flag, 2)) {
52  if (args[j].has_arg) {
53  GET_ARG (arg, argv, i);
54  args[j].callback (arg);
55  } else {
56  args[j].callback (NULL);
57  }
58  continue;
59  }
60  }
61 
62  /* TODO: Add these flags in Arg[] */
63  if (!memcmp (argv[i], "-o", 2)) {
64  GET_ARG (arg, argv, i);
65  if (arg != NULL) {
66  if (!strcmp (arg, "buff")) {
67  out.fout = NULL;
68  out.cout = rz_strbuf_new ("");
69  rz_strbuf_init (out.cout);
70  } else {
71  out.cout = NULL;
72  out.fout = fopen (arg, "w");
73  }
74  }
75  if (!out.cout && (arg == NULL || out.fout == NULL)) {
76  fprintf (stderr, "Cannot open output file\n");
77  exit (1);
78  }
79  } else
80  if (!memcmp (argv[i],"-t", 2)) {
81  GET_ARG (arg, argv, i);
82  spp_proc_set (proc, arg, 1);
83  } else
84  if (!strcmp (argv[i],"-v")) {
85  printf ("%s\n", VERSION);
86  exit (1);
87  } else
88  if (!strcmp (argv[i],"-h")) {
89  /* show help */
90  spp_help (argv[0]);
91  } else
92  if (!strcmp (argv[i],"-n")) {
93  dostdin = 0;
94  } else
95  if (!strcmp (argv[i],"-l")) {
96  spp_proc_list ();
97  exit (0);
98  } else
99  if (!strcmp (argv[i],"-L")) {
100  spp_proc_list_kw ();
101  exit (0);
102  } else
103  if (!strcmp (argv[i],"-s")) {
104  GET_ARG (arg, argv, i);
105  if (arg == NULL) arg = "";
106  fprintf (out.fout, "%s\n", arg);
107  } else
108  if (!strcmp (argv[i],"-e")) {
109  GET_ARG (arg, argv, i);
110  if (arg == NULL) {
111  arg = "";
112  }
113  spp_eval (arg, &out);
114  } else {
115  if (i == argc) {
116  fprintf (stderr, "No file specified.\n");
117  } else {
118  spp_file (argv[i], &out);
119  dostdin = 0;
120 
121  if (!out.fout) {
122  D printf ("%s\n", rz_strbuf_get (out.cout));
123  rz_strbuf_free (out.cout);
124  }
125  }
126  }
127  }
128  if (dostdin) {
129  spp_io (stdin, &out);
130  }
131  }
132 
133  if (proc->eof) {
134  proc->eof (&proc->state, &out, "");
135  }
136  if (out.fout) {
137  fclose (out.fout);
138  }
139 
140  return 0;
141 }
lzma_index ** i
Definition: index.h:629
static const char * arg(RzAnalysis *a, csh *handle, cs_insn *insn, char *buf, int n)
Definition: arm_esil32.c:136
#define D
Definition: block.c:38
const lzma_allocator const uint8_t size_t uint8_t * out
Definition: block.h:528
#define VERSION
Definition: config.h:54
#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 static fd const char const char static newpath char char argv
Definition: sflib.h:40
RZ_API char * rz_strbuf_get(RzStrBuf *sb)
Definition: strbuf.c:321
RZ_API RzStrBuf * rz_strbuf_new(const char *s)
Definition: strbuf.c:8
RZ_API void rz_strbuf_free(RzStrBuf *sb)
Definition: strbuf.c:358
RZ_API void rz_strbuf_init(RzStrBuf *sb)
Definition: strbuf.c:33
S_API void spp_eval(char *buf, Output *out)
Definition: spp.c:109
S_API void spp_proc_list()
Definition: spp.c:291
S_API void spp_proc_list_kw()
Definition: spp.c:284
S_API void spp_proc_set(SppProc *p, const char *arg, int fail)
Definition: spp.c:298
S_API int spp_file(const char *file, Output *out)
Definition: spp.c:272
S_API void spp_io(FILE *in, Output *out)
Definition: spp.c:224
#define GET_ARG(x, y, i)
Definition: spp.h:73
const char * flag
Definition: spp.h:122
Definition: spp.h:92
SppState state
Definition: spp.h:141
struct Proc * proc
static void spp_help(char *argv0)
Definition: main.c:10
struct Arg * args
Definition: mipsasm.c:18

References arg(), args, argv, D, test-lz4-list::exit, Arg::flag, GET_ARG, Arg::has_arg, i, NULL, out, printf(), proc, rz_strbuf_free(), rz_strbuf_get(), rz_strbuf_init(), rz_strbuf_new(), spp_eval(), spp_file(), spp_help(), spp_io(), spp_proc_list(), spp_proc_list_kw(), spp_proc_set(), Proc::state, and VERSION.

◆ spp_help()

static void spp_help ( char *  argv0)
static

Definition at line 10 of file main.c.

10  {
11  size_t i;
12  char supported[128] = "";
13  for (i = 0; procs[i]; ++i ) {
14  if (i) strcat (supported, ",");
15  strcat (supported, procs[i]->name);
16  }
17  printf("Usage: %s [-othesv] [file] [...]\n", argv0);
18  printf( " -o [file] set output file (stdout)\n"
19  " -t [type] define processor type (%s)\n"
20  " -e [str] evaluate this string with the selected proc\n"
21  " -s [str] show this string before anything\n"
22  " -l list all built-in preprocessors\n"
23  " -L list keywords registered by the processor\n"
24  " -n do not read from stdin\n"
25  " -v show version information\n", supported);
26  if (proc) {
27  printf ("%s specific flags:\n", proc->name);
28  for(i = 0; args[i].flag; i++) {
29  printf (" %s %s\n", args[i].flag, args[i].desc);
30  }
31  }
32  exit(0);
33 }
const char * desc
Definition: bin_vsf.c:19
const char * name
Definition: spp.h:129
Definition: z80asm.h:102
struct Proc * procs[]
Definition: config.h:24

References args, desc, test-lz4-list::exit, Arg::flag, i, Proc::name, printf(), proc, and procs.

Referenced by main().

Variable Documentation

◆ args

struct Arg* args
extern

Definition at line 18 of file mipsasm.c.

Referenced by add_filter(), analysis_pic_midrange_extract_args(), analysis_pic_midrange_op(), aprintf(), arg_n(), args_parse(), args_preprocessing(), argv_call_cb(), autocompleteFilename(), call_cd(), cmd_agraph_edge(), cmd_agraph_node(), cmd_print_format(), cmd_print_gadget(), concat(), cplus_demangle_fill_extended_operator(), cplus_demangle_type(), cpp_macro_add(), crc_read(), createdb(), d_expression_1(), d_index_template_argument(), d_make_extended_operator(), DEFINE_HANDLE_TS_FCN_AND_SYMBOL(), encode_instruction(), free_filters(), function_list_print_to_table(), get_args_offset(), get_help(), get_insn_args(), handle_substitution_args(), insertkeys(), INST_HANDLER(), invoke_cgi_script(), is_arg(), is_group_of_args(), is_handled_args(), iter_offsets_common(), libdemangle_handler_objc(), load_spanning_cabinets(), macro_call(), main(), make_program_args(), match_prefix_f(), mips_assemble(), parse_args(), parse_environment(), parse_function(), parse_function_args_and_vars(), parse_real(), parseOpcode(), print_message(), print_mips16_insn_arg(), print_runner(), printf(), process_cabinet(), processNode(), qnxr_run(), read_file(), read_name(), replace(), riscv_op(), run_rz_test(), rz_analysis_cc_set(), rz_analysis_function_args(), rz_analysis_function_derive_args(), rz_assert_log(), rz_cmd_call_parsed_args(), rz_cmd_get_help(), rz_cmd_get_help_json(), rz_cmd_macro_add(), rz_cmd_macro_cmd_args(), rz_cmd_parsed_args_new(), rz_cmd_parsed_args_newargs(), rz_cmd_parsed_args_setargs(), rz_cmd_search(), rz_core_file_reopen(), rz_core_file_reopen_debug(), rz_core_notify_begin(), rz_core_notify_done(), rz_core_notify_error(), rz_core_rtr_gdb_run(), rz_core_syscall(), rz_core_visual_define(), rz_debug_native_frames(), rz_il_handler_let(), rz_il_op_new_seqn(), rz_log(), rz_remote_add_handler(), rz_remote_del_handler(), rz_remote_handler(), rz_remote_open_handler(), rz_remote_rap_bg_handler(), rz_remote_rap_handler(), rz_remote_send_handler(), rz_reopen_debug_handler(), rz_str_argv(), rz_subprocess_start(), rz_test_check_jq_available(), rz_test_check_json_test(), rz_test_run_asm_test(), rz_type_format_data_internal(), rz_type_format_struct_size(), rz_vlog(), setup_workers(), show_syscall(), spp_help(), subprocess_runner(), substitute(), substitute_args(), system_exec(), thumb_selector(), uv__format_fallback_error(), uv__random_sysctl(), uv__recvmmsg(), uv__sendmmsg(), uv_exepath(), VALIDATOR_EFFECT(), VALIDATOR_PURE(), vreplace(), windbg_open(), window_read(), zip_source_seek(), zip_source_seek_compute_offset(), and zip_source_seek_write().

◆ proc

◆ procs

struct Proc* procs[]
extern

Definition at line 24 of file config.h.

Referenced by rz_debug_dmp_pids(), spp_help(), spp_proc_list(), and spp_proc_set().