Rizin
unix-like reverse engineering framework and cli tools
asm_pyc.c File Reference
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_util.h>
#include <rz_asm.h>
#include "../arch/pyc/pyc_dis.h"

Go to the source code of this file.

Functions

static int disassemble (RzAsm *a, RzAsmOp *opstruct, const ut8 *buf, int len)
 
static bool finish (void *user)
 

Variables

static pyc_opcodesopcodes_cache = NULL
 
RzAsmPlugin rz_asm_plugin_pyc
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ disassemble()

static int disassemble ( RzAsm a,
RzAsmOp opstruct,
const ut8 buf,
int  len 
)
static

Definition at line 14 of file asm_pyc.c.

14  {
15  RzList *shared = NULL;
16 
17  RzBin *bin = a->binb.bin;
18  ut64 pc = a->pc;
19 
20  RzBinPlugin *plugin = bin && bin->cur && bin->cur->o ? bin->cur->o->plugin : NULL;
21 
22  if (plugin) {
23  if (!strcmp(plugin->name, "pyc")) {
24  shared = ((RzBinPycObj *)bin->cur->o->bin_obj)->shared;
25  }
26  }
27 
28  RzList *cobjs = NULL;
29  RzList *interned_table = NULL;
30 
31  if (shared) {
32  cobjs = rz_list_get_n(shared, 0);
33  interned_table = rz_list_get_n(shared, 1);
34  }
35 
38  if (opcodes_cache == NULL) {
39  RZ_LOG_ERROR("disassembler: pyc: unsupported pyc opcode cpu/version (asm.cpu=%s).\n", a->cpu);
40  return len;
41  }
42  opcodes_cache->bits = a->bits;
43  }
44  int r = rz_pyc_disasm(opstruct, buf, cobjs, interned_table, pc, opcodes_cache);
45  opstruct->size = r;
46  return r;
47 }
size_t len
Definition: 6502dis.c:15
static pyc_opcodes * opcodes_cache
Definition: asm_pyc.c:12
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
voidpf void * buf
Definition: ioapi.h:138
RZ_API RZ_BORROW void * rz_list_get_n(RZ_NONNULL const RzList *list, ut32 n)
Returns the N-th element of the list.
Definition: list.c:574
pyc_opcodes * get_opcode_by_version(char *version)
Definition: opcode.c:169
bool pyc_opcodes_equal(pyc_opcodes *op, const char *version)
Definition: opcode.c:151
int rz_pyc_disasm(RzAsmOp *opstruct, const ut8 *code, RzList *cobjs, RzList *interned_table, ut64 pc, pyc_opcodes *ops)
Definition: pyc_dis.c:11
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define a(i)
Definition: sha256.c:41
Definition: malloc.c:26
ut8 bits
Definition: opcode.h:48
int size
Definition: rz_asm.h:67
char * name
Definition: rz_bin.h:509
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References a, pyc_opcodes::bits, get_opcode_by_version(), len, rz_bin_plugin_t::name, NULL, opcodes_cache, pc, pyc_opcodes_equal(), r, rz_list_get_n(), RZ_LOG_ERROR, rz_pyc_disasm(), rz_asm_op_t::size, and ut64().

◆ finish()

static bool finish ( void *  user)
static

Definition at line 49 of file asm_pyc.c.

49  {
50  if (opcodes_cache) {
53  }
54  return true;
55 }
void free_opcode(pyc_opcodes *opcodes)
Definition: opcode.c:217

References free_opcode(), NULL, and opcodes_cache.

Variable Documentation

◆ opcodes_cache

pyc_opcodes* opcodes_cache = NULL
static

Definition at line 12 of file asm_pyc.c.

Referenced by disassemble(), and finish().

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_ASM,
}
RzAsmPlugin rz_asm_plugin_pyc
Definition: asm_pyc.c:57
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
#define RZ_VERSION
Definition: rz_version.h:8
const char * version
Definition: rz_asm.h:133

Definition at line 68 of file asm_pyc.c.

◆ rz_asm_plugin_pyc

RzAsmPlugin rz_asm_plugin_pyc
Initial value:
= {
.name = "pyc",
.arch = "pyc",
.license = "LGPL3",
.bits = 16 | 8,
.desc = "PYC disassemble plugin",
.disassemble = &disassemble,
.fini = &finish,
}
static int disassemble(RzAsm *a, RzAsmOp *opstruct, const ut8 *buf, int len)
Definition: asm_pyc.c:14
static bool finish(void *user)
Definition: asm_pyc.c:49

Definition at line 57 of file asm_pyc.c.