Rizin
unix-like reverse engineering framework and cli tools
c55plus.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <rz_types.h>
#include <rz_lib.h>
#include <rz_asm.h>
#include "decode.h"
#include "../tms320_dasm.h"

Go to the source code of this file.

Macros

#define USE_DECODE
 

Functions

char * c55plus_decode (ut32 ins_pos, ut32 *next_ins_pos)
 
int c55x_plus_disassemble (tms320_dasm_t *dasm, const ut8 *buf, int len)
 

Variables

ut8ins_buff
 
ut32 ins_buff_len
 

Macro Definition Documentation

◆ USE_DECODE

#define USE_DECODE

Definition at line 12 of file c55plus.c.

Function Documentation

◆ c55plus_decode()

char* c55plus_decode ( ut32  ins_pos,
ut32 next_ins_pos 
)

Definition at line 448 of file c55plus_decode.c.

448  {
449  ut8 opcode, two_ins = 0;
450  ut32 next_ins1_pos, next_ins2_pos;
451  st32 hash_code;
452  char *ins1, *ins2, *aux, *ins_res;
453  int err_code;
454 
455  if (ins_pos >= ins_buff_len) {
456  return NULL;
457  }
458  ins_res = NULL;
459  err_code = 0;
460 
461  opcode = get_ins_part(ins_pos, 1);
462  if ((opcode & 0xF0) == 0x30) {
463  two_ins = opcode & 0x0F;
464  if (two_ins < 4) {
465  two_ins += 0xF;
466  }
467  } else {
468  two_ins = 0;
469  }
470 
471  // two instruction execution?
472  if (two_ins) {
473  ins1 = do_decode(1, ins_pos, two_ins, &next_ins1_pos, &hash_code, &err_code);
474  if (err_code < 0) {
475  free(ins1);
476  return NULL;
477  }
478  ins2 = do_decode(next_ins1_pos + 1, ins_pos, two_ins, &next_ins2_pos, NULL, &err_code);
479  if (err_code < 0) {
480  free(ins1);
481  free(ins2);
482  return NULL;
483  }
484  *next_ins_pos = next_ins2_pos;
485 
486  if (hash_code == 0xF0 || hash_code == 0xF1) {
487  aux = strcat_dup(ins2, " || ", 1);
488  ins_res = strcat_dup(aux, ins1, 1);
489  free(ins1);
490  } else {
491  aux = strcat_dup(ins1, " || ", 1);
492  ins_res = strcat_dup(aux, ins2, 1);
493  free(ins2);
494  }
495  *next_ins_pos = next_ins1_pos + next_ins2_pos + 1;
496  if (*next_ins_pos != two_ins) {
497  // ins_res = strcat_dup(ins_res, " P-tag problem", 1);
498  err_code = -1;
499  free(ins_res);
500  return NULL;
501  }
502  } else {
503  ins_res = do_decode(0, ins_pos, two_ins, &next_ins1_pos, &hash_code, &err_code);
504  if (err_code < 0) {
505  free(ins_res);
506  return NULL;
507  }
508  *next_ins_pos = next_ins1_pos;
509  }
510 
511  return ins_res;
512 }
static char * do_decode(ut32 ins_off, ut32 ins_pos, ut32 two_ins, ut32 *next_ins_pos, st32 *ins_hash_code, int *err_code)
ut32 ins_buff_len
Definition: ins.c:7
#define NULL
Definition: cris-opc.c:27
uint32_t ut32
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
ut32 get_ins_part(ut32 pos, ut32 len)
Definition: ins.c:51
uint8_t ut8
Definition: lh5801.h:11
char * strcat_dup(char *s1, char *s2, st32 n_free)
Definition: utils.c:12
#define st32
Definition: rz_types_base.h:12

References do_decode(), free(), get_ins_part(), ins_buff_len, NULL, st32, and strcat_dup().

Referenced by c55x_plus_disassemble().

◆ c55x_plus_disassemble()

int c55x_plus_disassemble ( tms320_dasm_t dasm,
const ut8 buf,
int  len 
)

Definition at line 21 of file c55plus.c.

21  {
22  unsigned int next_ins_pos;
23  char *ins_decoded;
24  size_t i, ins_decoded_len;
25 
26  ins_buff = (ut8 *)buf;
28 
29  next_ins_pos = 0;
30 
31  // decode instruction
32  ins_decoded = c55plus_decode(0, &next_ins_pos);
33  dasm->length = next_ins_pos;
34  if (!ins_decoded) {
35  return 0;
36  }
37 
38  // opcode length
39  dasm->length = next_ins_pos;
40  ins_decoded_len = strlen(ins_decoded);
41  for (i = 0; i < ins_decoded_len; i++) {
42  {
43  ins_decoded[i] = tolower((unsigned char)ins_decoded[i]);
44  }
45  }
46  snprintf(dasm->syntax, sizeof(dasm->syntax), "%s", ins_decoded);
47  free(ins_decoded);
48 
49  return next_ins_pos;
50 }
size_t len
Definition: 6502dis.c:15
lzma_index ** i
Definition: index.h:629
ut8 * ins_buff
Definition: ins.c:6
ut32 ins_buff_len
Definition: ins.c:7
char * c55plus_decode(ut32 ins_pos, ut32 *next_ins_pos)
voidpf void * buf
Definition: ioapi.h:138
snprintf
Definition: kernel.h:364
#define tolower(c)
Definition: safe-ctype.h:149
char syntax[1024]
Definition: tms320_dasm.h:127

References c55plus_decode(), free(), i, ins_buff, ins_buff_len, len, tms320_dasm_t::length, snprintf, tms320_dasm_t::syntax, and tolower.

Referenced by tms320_dasm().

Variable Documentation

◆ ins_buff

ut8* ins_buff
extern

Definition at line 6 of file ins.c.

Referenced by c55x_plus_disassemble().

◆ ins_buff_len

ut32 ins_buff_len
extern

Definition at line 7 of file ins.c.

Referenced by c55x_plus_disassemble().