Rizin
unix-like reverse engineering framework and cli tools
analysis_propeller.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2012-2013 pancake <pancake@nopcode.org>
2 // SPDX-FileCopyrightText: 2014 Fedor Sakharov <fedor.sakharov@gmail.com>
3 // SPDX-License-Identifier: LGPL-3.0-only
4 
5 #include <string.h>
6 #include <rz_types.h>
7 #include <rz_lib.h>
8 #include <rz_asm.h>
9 #include <rz_analysis.h>
10 #include <rz_util.h>
11 
12 #include <propeller_disas.h>
13 
14 static int propeller_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask) {
15  rz_return_val_if_fail(analysis && op && buf, -1);
16  if (len < 4) {
17  RZ_LOG_WARN("Couldn't disassemble instruction at 0x%x. Less than 4 bytes were provided.\n", (ut32)addr);
18  return -1;
19  }
20  int ret;
21  struct propeller_cmd cmd;
22 
23  memset(&cmd, 0, sizeof(cmd));
24 
25  ret = op->size = propeller_decode_command(buf, &cmd);
26 
27  if (ret < 0) {
28  return ret;
29  }
30 
31  op->addr = addr;
32 
33  switch (cmd.opcode) {
34  case PROP_TEST:
35  case PROP_TESTN:
36  case PROP_TJNZ:
37  case PROP_TJZ:
38  case PROP_CMPS:
39  case PROP_CMPSUB:
41  break;
42  case PROP_ADD:
43  case PROP_ADDX:
44  case PROP_ADDABS:
46  break;
47  case PROP_OR:
48  op->type = RZ_ANALYSIS_OP_TYPE_OR;
49  break;
50  case PROP_RCL:
51  case PROP_ROL:
52  case PROP_SHL:
54  break;
55  case PROP_RCR:
56  case PROP_ROR:
57  case PROP_SHR:
59  break;
60  case PROP_NEG:
62  break;
63  case PROP_XOR:
65  break;
66  case PROP_ABS:
67  case PROP_MINS:
68  case PROP_MIN:
69  case PROP_MAX:
70  case PROP_MAXS:
71  case PROP_RDBYTE:
72  case PROP_RDLONG:
73  case PROP_RDWORD:
74  case PROP_MOV:
75  case PROP_MOVD:
76  case PROP_MOVI:
77  case PROP_MOVS:
78  case PROP_WAITVID:
79  case PROP_MUXC:
80  if (cmd.opcode == PROP_MOV && cmd.dst == 0x44 && cmd.src == 0x3c) {
82  } else {
84  }
85  break;
86  case PROP_SUB:
88  break;
89  case PROP_JMP:
90  case PROP_DJNZ:
91  if (cmd.immed == 0) {
93  op->jump = 0x20 + cmd.src;
94  op->fail = addr + 2;
95  } else {
97  op->fail = addr + 2;
98  }
99  break;
100  default:
101  op->type = RZ_ANALYSIS_OP_TYPE_UNK;
102  break;
103  }
104 
105  return ret;
106 }
107 
109  .name = "propeller",
110  .desc = "Parallax propeller code analysis plugin",
111  .license = "LGPL3",
112  .arch = "propeller",
113  .bits = 32,
114  .op = propeller_op,
115 };
size_t len
Definition: 6502dis.c:15
#define mask()
static int propeller_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
RzAnalysisPlugin rz_analysis_plugin_propeller
static static sync static getppid static getegid const char static filename char static len const char char static bufsiz static mask static vfork const void static prot static getpgrp const char static swapflags cmd
Definition: sflib.h:79
uint32_t ut32
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
return memset(p, 0, total)
int propeller_decode_command(const ut8 *instr, struct propeller_cmd *cmd)
@ PROP_MOVS
@ PROP_MOVD
@ PROP_MIN
@ PROP_RDWORD
@ PROP_CMPSUB
@ PROP_RCR
@ PROP_ADDX
@ PROP_XOR
@ PROP_NEG
@ PROP_MOVI
@ PROP_SHL
@ PROP_RDBYTE
@ PROP_TJZ
@ PROP_TJNZ
@ PROP_SHR
@ PROP_RCL
@ PROP_MUXC
@ PROP_ROR
@ PROP_TEST
@ PROP_MAXS
@ PROP_MINS
@ PROP_RDLONG
@ PROP_ADDABS
@ PROP_MOV
@ PROP_WAITVID
@ PROP_TESTN
@ PROP_ADD
@ PROP_ROL
@ PROP_OR
@ PROP_MAX
@ PROP_JMP
@ PROP_DJNZ
@ PROP_CMPS
@ PROP_SUB
@ PROP_ABS
RzAnalysisOpMask
Definition: rz_analysis.h:439
@ RZ_ANALYSIS_OP_TYPE_CMP
Definition: rz_analysis.h:399
@ RZ_ANALYSIS_OP_TYPE_SUB
Definition: rz_analysis.h:402
@ RZ_ANALYSIS_OP_TYPE_UNK
Definition: rz_analysis.h:388
@ RZ_ANALYSIS_OP_TYPE_ROL
Definition: rz_analysis.h:420
@ RZ_ANALYSIS_OP_TYPE_AND
Definition: rz_analysis.h:411
@ RZ_ANALYSIS_OP_TYPE_UJMP
Definition: rz_analysis.h:369
@ RZ_ANALYSIS_OP_TYPE_ROR
Definition: rz_analysis.h:419
@ RZ_ANALYSIS_OP_TYPE_ADD
Definition: rz_analysis.h:401
@ RZ_ANALYSIS_OP_TYPE_OR
Definition: rz_analysis.h:410
@ RZ_ANALYSIS_OP_TYPE_CJMP
Definition: rz_analysis.h:373
@ RZ_ANALYSIS_OP_TYPE_MOV
Definition: rz_analysis.h:390
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385
@ RZ_ANALYSIS_OP_TYPE_XOR
Definition: rz_analysis.h:412
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
Definition: dis.c:32
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58