Rizin
unix-like reverse engineering framework and cli tools
opcode_arg_fmt.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2020 FXTi <zjxiang1998@gmail.com>
2 // SPDX-License-Identifier: LGPL-3.0-only
3 
4 #include "opcode.h"
5 
6 const char *format_extended_arg(ut32 oparg) {
7  return rz_str_newf("%u", oparg * (1 << 16));
8 }
9 
11  ut32 pos_args = oparg & 0xFF;
12  ut32 name = (oparg >> 8) & 0xFF;
13  return rz_str_newf("%u positional, %u named", pos_args, name);
14 }
15 
16 const char *format_MAKE_FUNCTION_arg_3x(ut32 oparg) {
17  ut32 pos_args = oparg & 0xFF;
18  ut32 name_default = (oparg >> 8) & 0xFF;
19  ut32 annotate_args = (oparg >> 16) & 0x7FFF;
20  return rz_str_newf("%u positional, %u name and default, %u annotations", pos_args, name_default, annotate_args);
21 }
22 
23 const char *format_CALL_FUNCTION_KW_36(ut32 oparg) {
24  return rz_str_newf("%u total positional and keyword args", oparg);
25 }
26 
27 const char *format_CALL_FUNCTION_EX_36(ut32 oparg) {
28  return rz_str_new((oparg & 0x01) ? "keyword args" : "");
29 }
30 
31 static const char *MAKE_FUNCTION_FLAGS[] = { "default", "keyword-only", "annotation", "closure" };
32 
33 const char *format_MAKE_FUNCTION_arg_36(ut32 oparg) {
34  size_t i;
35  char *ret = rz_str_new(" ");
36  for (i = 0; i < sizeof(MAKE_FUNCTION_FLAGS) / sizeof(char *); ++i) {
37  if (oparg & 0x1) {
38  rz_str_appendf(ret, ", %s", MAKE_FUNCTION_FLAGS[i]);
39  } else {
40  free(ret);
42  }
43  oparg >>= 1;
44  }
45  return ret;
46 }
47 
48 const char *format_value_flags_36(ut32 oparg) {
49  const char *ret = "";
50  switch (oparg & 0x3) {
51  case 1:
52  ret = "!s";
53  break;
54  case 2:
55  ret = "!r";
56  break;
57  case 3:
58  ret = "!a";
59  break;
60  }
61  if ((oparg & 0x4) == 0x4) {
62  // pop fmt_spec from the stack and use it, else use an
63  // empty fmt_spec.
64  ret = "";
65  }
66  return rz_str_new(ret);
67 }
68 
69 const char *format_extended_arg_36(ut32 oparg) {
70  return rz_str_newf("%u", oparg * (1 << 8));
71 }
lzma_index ** i
Definition: index.h:629
uint32_t ut32
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
const char * format_extended_arg(ut32 oparg)
Definition: opcode_arg_fmt.c:6
const char * format_MAKE_FUNCTION_arg_3x(ut32 oparg)
const char * format_MAKE_FUNCTION_arg_36(ut32 oparg)
const char * format_CALL_FUNCTION_KW_36(ut32 oparg)
static const char * MAKE_FUNCTION_FLAGS[]
const char * format_extended_arg_36(ut32 oparg)
const char * format_CALL_FUNCTION_pos_name_encoded(ut32 oparg)
const char * format_CALL_FUNCTION_EX_36(ut32 oparg)
const char * format_value_flags_36(ut32 oparg)
RZ_API char * rz_str_appendf(char *ptr, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_new(const char *str)
Definition: str.c:865
Definition: z80asm.h:102