Rizin
unix-like reverse engineering framework and cli tools
cmd_hash.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 deroad <wargio@libero.it>
2 // SPDX-FileCopyrightText: 2009-2020 pancake <pancake@nopcode.org>
3 // SPDX-FileCopyrightText: 2009-2020 nibble <nibble.ds@gmail.com>
4 // SPDX-License-Identifier: LGPL-3.0-only
5 #include <stddef.h>
6 #include <rz_core.h>
7 
8 typedef void (*DigestHandler)(const char *name, const ut8 *block, int len);
9 
10 typedef struct {
11  const char *name;
15 
16 RZ_IPI RzCmdDescDetail *rz_hash_bang_details_cb(RzCore *core, int argc, const char **argv) {
18  RzLangPlugin *lp;
20  if (!details) {
21  return NULL;
22  }
23  details[0].name = (const char *)strdup("Available interpreters");
24  if (!details->name) {
25  goto err;
26  }
28  details[0].entries = (const RzCmdDescDetailEntry *)entries;
29  if (!entries) {
30  goto err;
31  }
32  int i = 0;
33  rz_list_foreach (core->lang->langs, iter, lp) {
34  entries[i].text = (char *)strdup("#!");
35  entries[i].arg_str = (char *)strdup(lp->name);
36  entries[i].comment = (char *)rz_str_newf("%s (%s)", lp->desc, lp->license);
37  if (!entries[i].text || !entries[i].arg_str || !entries[i].comment) {
38  goto err;
39  }
40  i++;
41  }
42  details->entries = (const RzCmdDescDetailEntry *)entries;
43  return details;
44 err:
45  rz_cmd_desc_details_free(details);
46  return NULL;
47 }
48 
49 RZ_IPI RzCmdStatus rz_hash_bang_handler(RzCore *core, int argc, const char **argv) {
51  if (!p) {
52  RZ_LOG_ERROR("No interpreter with name '%s'\n", argv[1]);
53  return RZ_CMD_STATUS_ERROR;
54  }
55  core->lang->cur = p;
56  if (argc > 2) {
57  if (rz_lang_set_argv(core->lang, argc - 2, (char **)&argv[2])) {
58  rz_lang_run_file(core->lang, argv[2]);
59  } else {
60  char *run_str = rz_str_array_join(argv + 2, argc - 2, " ");
61  rz_lang_run_file(core->lang, run_str);
62  free(run_str);
63  }
64  } else {
65  if (rz_cons_is_interactive()) {
66  rz_lang_prompt(core->lang);
67  } else {
68  RZ_LOG_ERROR("scr.interactive required to run the rlang prompt\n");
69  return RZ_CMD_STATUS_ERROR;
70  }
71  }
72  return RZ_CMD_STATUS_OK;
73 }
size_t len
Definition: 6502dis.c:15
#define RZ_IPI
Definition: analysis_wasm.c:11
lzma_index ** i
Definition: index.h:629
static bool err
Definition: armass.c:435
RzList * entries(RzBinFile *bf)
Definition: bin_ne.c:98
RZ_API void rz_cmd_desc_details_free(RzCmdDescDetail *details)
Free an array of RzCmdDescDetail sections.
Definition: cmd_api.c:2698
void(* DigestHandler)(const char *name, const ut8 *block, int len)
Definition: cmd_hash.c:8
RZ_IPI RzCmdStatus rz_hash_bang_handler(RzCore *core, int argc, const char **argv)
Definition: cmd_hash.c:49
RZ_IPI RzCmdDescDetail * rz_hash_bang_details_cb(RzCore *core, int argc, const char **argv)
Definition: cmd_hash.c:16
RZ_API bool rz_cons_is_interactive(void)
Definition: cons.c:365
#define NULL
Definition: cris-opc.c:27
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API int rz_lang_prompt(RzLang *lang)
Definition: lang.c:205
RZ_API RzLangPlugin * rz_lang_get_by_name(RzLang *lang, const char *name)
Definition: lang.c:141
RZ_API int rz_lang_run_file(RzLang *lang, const char *file)
Definition: lang.c:183
RZ_API bool rz_lang_set_argv(RzLang *lang, int argc, char **argv)
Definition: lang.c:165
uint8_t ut8
Definition: lh5801.h:11
void * p
Definition: libc.cpp:67
RZ_API ut32 rz_list_length(RZ_NONNULL const RzList *list)
Returns the length of the list.
Definition: list.c:109
static static fork const void static count static fd const char const char static newpath char char argv
Definition: sflib.h:40
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
const char * name
Definition: op.c:541
enum rz_cmd_status_t RzCmdStatus
@ RZ_CMD_STATUS_OK
command handler exited in the right way
Definition: rz_cmd.h:24
@ RZ_CMD_STATUS_ERROR
command handler had issues while running (e.g. allocation error, etc.)
Definition: rz_cmd.h:26
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_array_join(const char **a, size_t n, const char *sep)
Definition: str.c:3861
#define RZ_NEWS0(x, y)
Definition: rz_types.h:282
const char * name
Definition: cmd_hash.c:11
DigestHandler handler
Definition: cmd_hash.c:12
RzHashPlugin * plugin
Definition: cmd_hash.c:13
A detailed entry that can be used to show additional info about a command entry.
Definition: rz_cmd.h:172
const char * name
Definition: rz_cmd.h:197
const RzCmdDescDetailEntry * entries
Definition: rz_cmd.h:201
RzLang * lang
Definition: rz_core.h:328
const char * desc
Definition: rz_lang.h:30
const char * license
Definition: rz_lang.h:31
const char * name
Definition: rz_lang.h:28
struct rz_lang_plugin_t * cur
Definition: rz_lang.h:18
RzList * langs
Definition: rz_lang.h:21