Rizin
unix-like reverse engineering framework and cli tools
rz-bb.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2017 pancake <pancake@nopcode.org>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include <rz_util.h>
5 
6 typedef char *(*CommandCallback)(const char *args);
7 
8 typedef struct {
9  const char *cmd;
11 } BbCommands;
12 
13 static BbCommands bbcmds[] = {
14  { "cat", rz_syscmd_cat },
15  { "ls", rz_syscmd_ls },
16  NULL
17 };
18 
19 static int run(int i, const char *arg) {
20  char *res = bbcmds[i].cb(arg);
21  if (res) {
22  printf("%s", res);
23  free(res);
24  return 0;
25  }
26  return 1;
27 }
28 
29 int main(int argc, char **argv) {
30  int i;
31  for (i = 0; bbcmds[i].cmd; i++) {
32  if (!strcmp(bbcmds[i].cmd, argv[0])) {
33  const char *arg = argc > 1 ? argv[1] : NULL;
34  return run(i, arg);
35  }
36  }
37  if (argc > 1) {
38  for (i = 0; bbcmds[i].cmd; i++) {
39  if (!strcmp(bbcmds[i].cmd, argv[1])) {
40  const char *arg = argc > 2 ? argv[2] : NULL;
41  return run(i, arg);
42  }
43  }
44  }
45  for (i = 0; bbcmds[i].cmd; i++) {
46  printf("%s\n", bbcmds[i].cmd);
47  }
48  return 1;
49 }
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
_Use_decl_annotations_ int __cdecl printf(const char *const _Format,...)
Definition: cs_driver.c:93
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 static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
int args
Definition: mipsasm.c:18
char *(* CommandCallback)(const char *args)
Definition: rz-bb.c:6
int main(int argc, char **argv)
Definition: rz-bb.c:29
static BbCommands bbcmds[]
Definition: rz-bb.c:13
static int run(int i, const char *arg)
Definition: rz-bb.c:19
RZ_API RZ_OWN char * rz_syscmd_cat(RZ_NONNULL const char *file)
Definition: syscmd.c:442
RZ_API RZ_OWN char * rz_syscmd_ls(RZ_NONNULL const char *input)
Definition: syscmd.c:121
CommandCallback cb
Definition: rz-bb.c:10
const char * cmd
Definition: rz-bb.c:9