Rizin
unix-like reverse engineering framework and cli tools
asm_pyc.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2016-2020 c0riolis
2 // SPDX-FileCopyrightText: 2016-2020 x0urc3
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #include <rz_types.h>
6 #include <rz_lib.h>
7 #include <rz_util.h>
8 #include <rz_asm.h>
9 
10 #include "../arch/pyc/pyc_dis.h"
11 
13 
14 static int disassemble(RzAsm *a, RzAsmOp *opstruct, const ut8 *buf, int len) {
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 }
48 
49 static bool finish(void *user) {
50  if (opcodes_cache) {
53  }
54  return true;
55 }
56 
58  .name = "pyc",
59  .arch = "pyc",
60  .license = "LGPL3",
61  .bits = 16 | 8,
62  .desc = "PYC disassemble plugin",
63  .disassemble = &disassemble,
64  .fini = &finish,
65 };
66 
67 #ifndef RZ_PLUGIN_INCORE
70  .data = &rz_asm_plugin_pyc,
72 };
73 
74 #endif
size_t len
Definition: 6502dis.c:15
static int disassemble(RzAsm *a, RzAsmOp *opstruct, const ut8 *buf, int len)
Definition: asm_pyc.c:14
RzAsmPlugin rz_asm_plugin_pyc
Definition: asm_pyc.c:57
static pyc_opcodes * opcodes_cache
Definition: asm_pyc.c:12
RZ_API RzLibStruct rizin_plugin
Definition: asm_pyc.c:68
static bool finish(void *user)
Definition: asm_pyc.c:49
#define RZ_API
#define NULL
Definition: cris-opc.c:27
#define r
Definition: crypto_rc6.c:12
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
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
void free_opcode(pyc_opcodes *opcodes)
Definition: opcode.c:217
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
@ RZ_LIB_TYPE_ASM
Definition: rz_lib.h:72
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define RZ_VERSION
Definition: rz_version.h:8
#define a(i)
Definition: sha256.c:41
Definition: malloc.c:26
ut8 bits
Definition: opcode.h:48
int size
Definition: rz_asm.h:67
const char * name
Definition: rz_asm.h:130
const char * version
Definition: rz_asm.h:133
char * name
Definition: rz_bin.h:509
ut64(WINAPI *w32_GetEnabledXStateFeatures)()