Rizin
unix-like reverse engineering framework and cli tools
pyc_dis.h File Reference
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "opcode.h"
#include "../../../bin/format/pyc/marshal.h"

Go to the source code of this file.

Functions

int rz_pyc_disasm (RzAsmOp *op, const ut8 *buf, RzList *cobjs, RzList *interned_table, ut64 pc, pyc_opcodes *opcodes)
 

Function Documentation

◆ rz_pyc_disasm()

int rz_pyc_disasm ( RzAsmOp op,
const ut8 buf,
RzList cobjs,
RzList interned_table,
ut64  pc,
pyc_opcodes opcodes 
)

Definition at line 11 of file pyc_dis.c.

11  {
12  pyc_code_object *cobj = NULL, *t = NULL;
13  ut32 i = 0, oparg;
14  st64 start_offset, end_offset;
15  RzListIter *iter = NULL;
16 
17  rz_list_foreach (cobjs, iter, t) {
18  start_offset = t->start_offset;
19  end_offset = t->end_offset;
20  if (start_offset <= pc && pc < end_offset) { // pc in [start_offset, end_offset)
21  cobj = t;
22  break;
23  }
24  }
25 
26  if (cobj) {
27  /* TODO: adding line number and offset */
28  RzList *varnames = cobj->varnames->data;
29  RzList *consts = cobj->consts->data;
30  RzList *names = cobj->names->data;
31  RzList *freevars = cobj->freevars->data;
32  RzList *cellvars = cobj->cellvars->data;
33 
34  ut8 op = code[i];
35  i++;
36  char *name = ops->opcodes[op].op_name;
37  rz_strbuf_set(&opstruct->buf_asm, name);
38  if (!name) {
39  return 0;
40  }
41  if (op >= ops->have_argument) {
42  if (ops->bits == 16) {
43  oparg = code[i] + code[i + 1] * 256;
44  i += 2;
45  } else {
46  oparg = code[i];
47  i += 1;
48  }
49  const char *arg = parse_arg(&ops->opcodes[op], oparg, names, consts, varnames, interned_table, freevars, cellvars, ops->opcode_arg_fmt);
50  if (arg != NULL) {
51  rz_strbuf_appendf(&opstruct->buf_asm, "%20s", arg);
52  free((char *)arg);
53  }
54  } else if (ops->bits == 8) {
55  i += 1;
56  }
57 
58  return i;
59  }
60  return 0;
61 }
static struct @29 ops[]
ut8 op
Definition: 6502dis.c:13
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
uint32_t ut32
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
uint8_t ut8
Definition: lh5801.h:11
static const char * parse_arg(pyc_opcode_object *op, ut32 oparg, RzList *names, RzList *consts, RzList *varnames, RzList *interned_table, RzList *freevars, RzList *cellvars, RzList *opcode_arg_fmt)
Definition: pyc_dis.c:65
RZ_API const char * rz_strbuf_set(RzStrBuf *sb, const char *s)
Definition: strbuf.c:153
RZ_API bool rz_strbuf_appendf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2
#define st64
Definition: rz_types_base.h:10
Definition: inftree9.h:24
Definition: z80asm.h:102
Definition: names.h:123
pyc_object * names
Definition: marshal.h:64
pyc_object * varnames
Definition: marshal.h:65
pyc_object * freevars
Definition: marshal.h:66
pyc_object * cellvars
Definition: marshal.h:67
pyc_object * consts
Definition: marshal.h:63
void * data
Definition: marshal.h:52
Definition: dis.c:32

References rz_asm_op_t::buf_asm, pyc_code_object::cellvars, pyc_code_object::consts, pyc_object::data, free(), pyc_code_object::freevars, i, pyc_code_object::names, NULL, op, ops, parse_arg(), pc, rz_strbuf_appendf(), rz_strbuf_set(), st64, and pyc_code_object::varnames.

Referenced by disassemble().