Rizin
unix-like reverse engineering framework and cli tools
analysis_msp430.c File Reference
#include <string.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include <rz_analysis.h>
#include <rz_util.h>
#include <msp430_disas.h>

Go to the source code of this file.

Functions

static int msp430_op (RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)
 

Variables

RzAnalysisPlugin rz_analysis_plugin_msp430
 

Function Documentation

◆ msp430_op()

static int msp430_op ( RzAnalysis analysis,
RzAnalysisOp op,
ut64  addr,
const ut8 buf,
int  len,
RzAnalysisOpMask  mask 
)
static

Definition at line 13 of file analysis_msp430.c.

13  {
14  int ret;
15  struct msp430_cmd cmd;
16 
17  memset(&cmd, 0, sizeof(cmd));
18  // op->id = ???;
19  op->size = -1;
20  op->nopcode = 1;
22  op->family = RZ_ANALYSIS_OP_FAMILY_CPU;
23 
24  ret = op->size = msp430_decode_command(buf, len, &cmd);
25 
26  if (ret < 0) {
27  return ret;
28  }
29 
30  op->addr = addr;
31 
32  switch (cmd.type) {
33  case MSP430_ONEOP:
34  switch (cmd.opcode) {
35  case MSP430_RRA:
36  case MSP430_RRC:
38  break;
39  case MSP430_PUSH:
41  break;
42  case MSP430_CALL:
44  op->fail = addr + op->size;
45  op->jump = rz_read_at_le16(buf, 2);
46  break;
47  case MSP430_RETI:
49  break;
50  }
51  break;
52  case MSP430_TWOOP:
53  switch (cmd.opcode) {
54  case MSP430_BIT:
55  case MSP430_BIC:
56  case MSP430_BIS:
57  case MSP430_MOV:
59  if ((cmd.instr)[0] == 'b' && (cmd.instr)[1] == 'r') {
60  // Emulated branch instruction, moves source operand to PC register.
62  }
63  break;
64  case MSP430_DADD:
65  case MSP430_ADDC:
66  case MSP430_ADD: op->type = RZ_ANALYSIS_OP_TYPE_ADD; break;
67  case MSP430_SUBC:
68  case MSP430_SUB: op->type = RZ_ANALYSIS_OP_TYPE_SUB; break;
69  case MSP430_CMP: op->type = RZ_ANALYSIS_OP_TYPE_CMP; break;
70  case MSP430_XOR: op->type = RZ_ANALYSIS_OP_TYPE_XOR; break;
71  case MSP430_AND: op->type = RZ_ANALYSIS_OP_TYPE_AND; break;
72  }
73  break;
74  case MSP430_JUMP:
75  if (cmd.jmp_cond == MSP430_JMP) {
77  } else {
79  }
80  op->jump = addr + cmd.jmp_addr;
81  op->fail = addr + 2;
82  break;
83  case MSP430_INV:
85  break;
86  default:
88  }
89 
90  return ret;
91 }
size_t len
Definition: 6502dis.c:15
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
voidpf void * buf
Definition: ioapi.h:138
return memset(p, 0, total)
int msp430_decode_command(const ut8 *in, int len, struct msp430_cmd *cmd)
Definition: msp430_disas.c:441
@ MSP430_JUMP
Definition: msp430_disas.h:58
@ MSP430_INV
Definition: msp430_disas.h:59
@ MSP430_TWOOP
Definition: msp430_disas.h:57
@ MSP430_ONEOP
Definition: msp430_disas.h:56
@ MSP430_SUBC
Definition: msp430_disas.h:37
@ MSP430_MOV
Definition: msp430_disas.h:34
@ MSP430_CMP
Definition: msp430_disas.h:39
@ MSP430_BIC
Definition: msp430_disas.h:42
@ MSP430_XOR
Definition: msp430_disas.h:44
@ MSP430_SUB
Definition: msp430_disas.h:38
@ MSP430_DADD
Definition: msp430_disas.h:40
@ MSP430_BIS
Definition: msp430_disas.h:43
@ MSP430_ADD
Definition: msp430_disas.h:35
@ MSP430_BIT
Definition: msp430_disas.h:41
@ MSP430_AND
Definition: msp430_disas.h:45
@ MSP430_ADDC
Definition: msp430_disas.h:36
@ MSP430_RRA
Definition: msp430_disas.h:13
@ MSP430_RRC
Definition: msp430_disas.h:11
@ MSP430_PUSH
Definition: msp430_disas.h:15
@ MSP430_CALL
Definition: msp430_disas.h:16
@ MSP430_RETI
Definition: msp430_disas.h:17
@ MSP430_JMP
Definition: msp430_disas.h:29
@ RZ_ANALYSIS_OP_FAMILY_CPU
Definition: rz_analysis.h:312
@ 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_JMP
Definition: rz_analysis.h:368
@ 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_CALL
Definition: rz_analysis.h:378
@ RZ_ANALYSIS_OP_TYPE_ADD
Definition: rz_analysis.h:401
@ RZ_ANALYSIS_OP_TYPE_PUSH
Definition: rz_analysis.h:397
@ RZ_ANALYSIS_OP_TYPE_CJMP
Definition: rz_analysis.h:373
@ RZ_ANALYSIS_OP_TYPE_MOV
Definition: rz_analysis.h:390
@ RZ_ANALYSIS_OP_TYPE_ILL
Definition: rz_analysis.h:387
@ RZ_ANALYSIS_OP_TYPE_RET
Definition: rz_analysis.h:385
@ RZ_ANALYSIS_OP_TYPE_XOR
Definition: rz_analysis.h:412
static ut16 rz_read_at_le16(const void *src, size_t offset)
Definition: rz_endian.h:214
Definition: dis.c:32
static int addr
Definition: z80asm.c:58

References addr, cmd, len, memset(), MSP430_ADD, MSP430_ADDC, MSP430_AND, MSP430_BIC, MSP430_BIS, MSP430_BIT, MSP430_CALL, MSP430_CMP, MSP430_DADD, msp430_decode_command(), MSP430_INV, MSP430_JMP, MSP430_JUMP, MSP430_MOV, MSP430_ONEOP, MSP430_PUSH, MSP430_RETI, MSP430_RRA, MSP430_RRC, MSP430_SUB, MSP430_SUBC, MSP430_TWOOP, MSP430_XOR, RZ_ANALYSIS_OP_FAMILY_CPU, RZ_ANALYSIS_OP_TYPE_ADD, RZ_ANALYSIS_OP_TYPE_AND, RZ_ANALYSIS_OP_TYPE_CALL, RZ_ANALYSIS_OP_TYPE_CJMP, RZ_ANALYSIS_OP_TYPE_CMP, RZ_ANALYSIS_OP_TYPE_ILL, RZ_ANALYSIS_OP_TYPE_JMP, RZ_ANALYSIS_OP_TYPE_MOV, RZ_ANALYSIS_OP_TYPE_PUSH, RZ_ANALYSIS_OP_TYPE_RET, RZ_ANALYSIS_OP_TYPE_ROR, RZ_ANALYSIS_OP_TYPE_SUB, RZ_ANALYSIS_OP_TYPE_UJMP, RZ_ANALYSIS_OP_TYPE_UNK, RZ_ANALYSIS_OP_TYPE_XOR, and rz_read_at_le16().

Variable Documentation

◆ rz_analysis_plugin_msp430

RzAnalysisPlugin rz_analysis_plugin_msp430
Initial value:
= {
.name = "msp430",
.desc = "TI MSP430 code analysis plugin",
.license = "LGPL3",
.arch = "msp430",
.bits = 16,
.op = msp430_op,
}
static int msp430_op(RzAnalysis *analysis, RzAnalysisOp *op, ut64 addr, const ut8 *buf, int len, RzAnalysisOpMask mask)

Definition at line 93 of file analysis_msp430.c.