Rizin
unix-like reverse engineering framework and cli tools
parse_m68k_pseudo.c File Reference
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <rz_lib.h>
#include <rz_util.h>
#include <rz_flag.h>
#include <rz_analysis.h>
#include <rz_parse.h>
#include "parse_common.c"

Go to the source code of this file.

Functions

static RzListm68k_tokenize (const char *assembly, size_t length)
 
static bool parse (RzParse *parse, const char *assembly, RzStrBuf *sb)
 

Variables

static const RzPseudoGrammar m68k_lexicon []
 
static const RzPseudoReplace m68k_replace []
 
static const RzPseudoConfig m68k_config = RZ_PSEUDO_DEFINE_CONFIG_NO_DIRECT(m68k_lexicon, m68k_replace, 4, m68k_tokenize)
 
RzParsePlugin rz_parse_plugin_m68k_pseudo
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ m68k_tokenize()

RzList * m68k_tokenize ( const char *  assembly,
size_t  length 
)
static

Definition at line 62 of file parse_m68k_pseudo.c.

62  {
63  size_t i, p;
64  char *buf = NULL;
65  RzList *tokens = NULL;
66 
67  buf = rz_str_ndup(assembly, length);
68  if (!buf) {
69  return NULL;
70  }
71 
72  for (i = 0, p = 0; p < length; ++i, ++p) {
73  if (buf[p] == ',') {
74  p++;
75  }
76  if (p > i) {
77  buf[i] = buf[p];
78  }
79  }
80  buf[i] = 0;
81 
82  tokens = rz_str_split_duplist(buf, " ", true);
83  free(buf);
84  return tokens;
85 }
lzma_index ** i
Definition: index.h:629
#define NULL
Definition: cris-opc.c:27
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 static arg static fd static protocol static who struct sockaddr static addrlen static backlog struct timeval struct timezone static tz const struct iovec static count static mode const void const struct sockaddr static tolen const char static pathname void static offset struct stat static buf void long static basep static whence static length const void static len static semflg const void static shmflg const struct timespec struct timespec static rem const char static group const void length
Definition: sflib.h:133
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void * buf
Definition: ioapi.h:138
void * p
Definition: libc.cpp:67
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006
RZ_API RzList * rz_str_split_duplist(const char *str, const char *c, bool trim)
Split the string str according to the substring c and returns a RzList with the result.
Definition: str.c:3464

References free(), i, length, NULL, p, rz_str_ndup(), and rz_str_split_duplist().

◆ parse()

static bool parse ( RzParse parse,
const char *  assembly,
RzStrBuf sb 
)
static

Definition at line 87 of file parse_m68k_pseudo.c.

87  {
88  char *copy = strdup(assembly);
89  if (!copy) {
90  rz_strbuf_setf(sb, "asm(\"%s\")", assembly);
91  return true;
92  }
93  copy = rz_str_replace(copy, ".l", "", 0);
94  copy = rz_str_replace(copy, ".w", "", 0);
95  copy = rz_str_replace(copy, ".d", "", 0);
96  copy = rz_str_replace(copy, ".b", "", 0);
97  bool res = rz_pseudo_convert(&m68k_config, copy, sb);
98  free(copy);
99  return res;
100 }
static SblHeader sb
Definition: bin_mbn.c:26
return strdup("=SP r13\n" "=LR r14\n" "=PC r15\n" "=A0 r0\n" "=A1 r1\n" "=A2 r2\n" "=A3 r3\n" "=ZF zf\n" "=SF nf\n" "=OF vf\n" "=CF cf\n" "=SN or0\n" "gpr lr .32 56 0\n" "gpr pc .32 60 0\n" "gpr cpsr .32 64 0 ____tfiae_________________qvczn\n" "gpr or0 .32 68 0\n" "gpr tf .1 64.5 0 thumb\n" "gpr ef .1 64.9 0 endian\n" "gpr jf .1 64.24 0 java\n" "gpr qf .1 64.27 0 sticky_overflow\n" "gpr vf .1 64.28 0 overflow\n" "gpr cf .1 64.29 0 carry\n" "gpr zf .1 64.30 0 zero\n" "gpr nf .1 64.31 0 negative\n" "gpr itc .4 64.10 0 if_then_count\n" "gpr gef .4 64.16 0 great_or_equal\n" "gpr r0 .32 0 0\n" "gpr r1 .32 4 0\n" "gpr r2 .32 8 0\n" "gpr r3 .32 12 0\n" "gpr r4 .32 16 0\n" "gpr r5 .32 20 0\n" "gpr r6 .32 24 0\n" "gpr r7 .32 28 0\n" "gpr r8 .32 32 0\n" "gpr r9 .32 36 0\n" "gpr r10 .32 40 0\n" "gpr r11 .32 44 0\n" "gpr r12 .32 48 0\n" "gpr r13 .32 52 0\n" "gpr r14 .32 56 0\n" "gpr r15 .32 60 0\n" "gpr r16 .32 64 0\n" "gpr r17 .32 68 0\n")
static bool rz_pseudo_convert(const RzPseudoConfig *config, const char *assembly, RzStrBuf *sb)
Definition: parse_common.c:103
static const RzPseudoConfig m68k_config
RZ_API char * rz_str_replace(char *str, const char *key, const char *val, int g)
Definition: str.c:1110
RZ_API const char * rz_strbuf_setf(RzStrBuf *sb, const char *fmt,...) RZ_PRINTF_CHECK(2

References free(), m68k_config, rz_pseudo_convert(), rz_str_replace(), rz_strbuf_setf(), sb, and strdup().

Variable Documentation

◆ m68k_config

Definition at line 60 of file parse_m68k_pseudo.c.

Referenced by parse().

◆ m68k_lexicon

const RzPseudoGrammar m68k_lexicon[]
static

Definition at line 18 of file parse_m68k_pseudo.c.

◆ m68k_replace

const RzPseudoReplace m68k_replace[]
static
Initial value:
= {
RZ_PSEUDO_DEFINE_REPLACE("+ -", "- ", 1),
}
#define RZ_PSEUDO_DEFINE_REPLACE(x, y, f)
Definition: parse_common.c:64

Definition at line 56 of file parse_m68k_pseudo.c.

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.version = RZ_VERSION
}
RzParsePlugin rz_parse_plugin_m68k_pseudo
@ RZ_LIB_TYPE_PARSE
Definition: rz_lib.h:74
#define RZ_VERSION
Definition: rz_version.h:8

Definition at line 109 of file parse_m68k_pseudo.c.

◆ rz_parse_plugin_m68k_pseudo

RzParsePlugin rz_parse_plugin_m68k_pseudo
Initial value:
= {
.name = "m68k.pseudo",
.desc = "M68K pseudo syntax",
.parse = parse,
}
static bool parse(RzParse *parse, const char *assembly, RzStrBuf *sb)

Definition at line 102 of file parse_m68k_pseudo.c.