Rizin
unix-like reverse engineering framework and cli tools
bin_menuet.c File Reference
#include <rz_types.h>
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_bin.h>

Go to the source code of this file.

Macros

#define MENUET_VERSION(x)   x[7]
 
#define B(x, y)   rz_buf_append_bytes(buf, (const ut8 *)(x), y)
 
#define D(x)   rz_buf_append_ut32(buf, x)
 

Functions

static bool check_buffer (RzBuffer *b)
 
static bool load_buffer (RzBinFile *bf, RzBinObject *obj, RzBuffer *b, Sdb *sdb)
 
static ut64 baddr (RzBinFile *bf)
 
static ut64 menuetEntry (const ut8 *buf, int buf_size)
 
static RzListentries (RzBinFile *bf)
 
static RzListsections (RzBinFile *bf)
 
static RzBinInfoinfo (RzBinFile *bf)
 
static ut64 size (RzBinFile *bf)
 
static RzBuffercreate (RzBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RzBinArchOptions *opt)
 

Variables

RzBinPlugin rz_bin_plugin_menuet
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ B

#define B (   x,
 
)    rz_buf_append_bytes(buf, (const ut8 *)(x), y)

◆ D

#define D (   x)    rz_buf_append_ut32(buf, x)

◆ MENUET_VERSION

#define MENUET_VERSION (   x)    x[7]

Definition at line 9 of file bin_menuet.c.

Function Documentation

◆ baddr()

static ut64 baddr ( RzBinFile bf)
static

Definition at line 74 of file bin_menuet.c.

74  {
75  return 0; // 0x800000;
76 }

Referenced by entries(), and sections().

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 53 of file bin_menuet.c.

53  {
54  ut8 buf[8];
55  if (rz_buf_read_at(b, 0, buf, sizeof(buf)) != sizeof(buf)) {
56  return false;
57  }
58  if (rz_buf_size(b) >= 32 && !memcmp(buf, "MENUET0", 7)) {
59  switch (buf[7]) {
60  case '0':
61  case '1':
62  case '2':
63  return true;
64  }
65  RZ_LOG_ERROR("Unsupported MENUET version header\n");
66  }
67  return false;
68 }
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
RZ_API st64 rz_buf_read_at(RZ_NONNULL RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *buf, ut64 len)
Read len bytes of the buffer at the specified address.
Definition: buf.c:1136
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define b(i)
Definition: sha256.c:42

References b, rz_buf_read_at(), rz_buf_size(), and RZ_LOG_ERROR.

Referenced by load_buffer().

◆ create()

static RzBuffer* create ( RzBin bin,
const ut8 code,
int  codelen,
const ut8 data,
int  datalen,
RzBinArchOptions opt 
)
static

Definition at line 190 of file bin_menuet.c.

190  {
192 #define B(x, y) rz_buf_append_bytes(buf, (const ut8 *)(x), y)
193 #define D(x) rz_buf_append_ut32(buf, x)
194  B("MENUET01", 8);
195  D(1); // header version
196  D(32); // program start
197  D(0x1000); // program image size
198  D(0x1000); // ESP
199  D(0); // no parameters
200  D(0); // no path
201  B(code, codelen);
202  return buf;
203 }
#define B(x, y)
#define D(x)
#define NULL
Definition: cris-opc.c:27
RZ_API RZ_OWN RzBuffer * rz_buf_new_with_bytes(RZ_NULLABLE RZ_BORROW const ut8 *bytes, ut64 len)
Creates a new buffer with a bytes array.
Definition: buf.c:465
Definition: inftree9.h:24

References B, D, NULL, and rz_buf_new_with_bytes().

◆ entries()

static RzList* entries ( RzBinFile bf)
static

Definition at line 87 of file bin_menuet.c.

87  {
88  RzList *ret;
89  ut8 buf[64] = { 0 };
90  RzBinAddr *ptr = NULL;
91  const int buf_size = RZ_MIN(sizeof(buf), rz_buf_size(bf->buf));
92 
93  rz_buf_read_at(bf->buf, 0, buf, buf_size);
95  if (entry == UT64_MAX) {
96  return NULL;
97  }
98  if (!(ret = rz_list_new())) {
99  return NULL;
100  }
101  ret->free = free;
102  if ((ptr = RZ_NEW0(RzBinAddr))) {
103  ptr->paddr = rz_read_ble32(buf + 12, false);
104  ptr->vaddr = ptr->paddr + baddr(bf);
105  rz_list_append(ret, ptr);
106  }
107  return ret;
108 }
static ut64 baddr(RzBinFile *bf)
Definition: bin_menuet.c:74
static ut64 menuetEntry(const ut8 *buf, int buf_size)
Definition: bin_menuet.c:78
static int buf_size
Definition: debug_qnx.c:35
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
RZ_API RZ_BORROW RzListIter * rz_list_append(RZ_NONNULL RzList *list, void *data)
Appends at the end of the list a new element.
Definition: list.c:288
static ut32 rz_read_ble32(const void *src, bool big_endian)
Definition: rz_endian.h:497
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_MIN(x, y)
#define UT64_MAX
Definition: rz_types_base.h:86
Definition: zipcmp.c:77
ut64 vaddr
Definition: rz_bin.h:186
ut64 paddr
Definition: rz_bin.h:187
RzBuffer * buf
Definition: rz_bin.h:303
RzListFree free
Definition: rz_list.h:21
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References baddr(), rz_bin_file_t::buf, buf_size, rz_list_t::free, free(), menuetEntry(), NULL, rz_bin_addr_t::paddr, rz_buf_read_at(), rz_buf_size(), rz_list_append(), rz_list_new(), RZ_MIN, RZ_NEW0, rz_read_ble32(), ut64(), UT64_MAX, and rz_bin_addr_t::vaddr.

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 155 of file bin_menuet.c.

155  {
156  RzBinInfo *ret = RZ_NEW0(RzBinInfo);
157  if (ret) {
158  ret->file = strdup(bf->file);
159  ret->bclass = strdup("program");
160  ret->rclass = strdup("menuet");
161  ret->os = strdup("MenuetOS");
162  ret->arch = strdup("x86");
163  ret->machine = strdup(ret->arch);
164  ret->subsystem = strdup("kolibri");
165  ret->type = strdup("EXEC");
166  ret->bits = 32;
167  ret->has_va = true;
168  ret->big_endian = 0;
169  ret->dbg_info = 0;
170  ret->dbg_info = 0;
171  }
172  return ret;
173 }
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")
char * file
Definition: rz_bin.h:299
int has_va
Definition: rz_bin.h:228
char * type
Definition: rz_bin.h:211
char * os
Definition: rz_bin.h:219
char * subsystem
Definition: rz_bin.h:220
char * machine
Definition: rz_bin.h:216
char * bclass
Definition: rz_bin.h:212
char * file
Definition: rz_bin.h:210
ut64 dbg_info
Definition: rz_bin.h:240
char * rclass
Definition: rz_bin.h:213
char * arch
Definition: rz_bin.h:214
int big_endian
Definition: rz_bin.h:235

References rz_bin_info_t::arch, rz_bin_info_t::bclass, rz_bin_info_t::big_endian, rz_bin_info_t::bits, rz_bin_info_t::dbg_info, rz_bin_info_t::file, rz_bin_file_t::file, rz_bin_info_t::has_va, rz_bin_info_t::machine, rz_bin_info_t::os, rz_bin_info_t::rclass, RZ_NEW0, strdup(), rz_bin_info_t::subsystem, and rz_bin_info_t::type.

Referenced by size().

◆ load_buffer()

static bool load_buffer ( RzBinFile bf,
RzBinObject obj,
RzBuffer b,
Sdb sdb 
)
static

Definition at line 70 of file bin_menuet.c.

70  {
71  return check_buffer(b);
72 }
static bool check_buffer(RzBuffer *b)
Definition: bin_menuet.c:53

References b, and check_buffer().

◆ menuetEntry()

static ut64 menuetEntry ( const ut8 buf,
int  buf_size 
)
static

Definition at line 78 of file bin_menuet.c.

78  {
79  switch (MENUET_VERSION(buf)) {
80  case '0': return rz_read_ble32(buf + 12, false);
81  case '1': return rz_read_ble32(buf + 12, false);
82  case '2': return rz_read_ble32(buf + 44, false);
83  }
84  return UT64_MAX;
85 }
#define MENUET_VERSION(x)
Definition: bin_menuet.c:9

References MENUET_VERSION, rz_read_ble32(), and UT64_MAX.

Referenced by entries().

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 110 of file bin_menuet.c.

110  {
111  RzList *ret = NULL;
112  RzBinSection *ptr = NULL;
113  ut8 buf[64] = { 0 };
114  const int buf_size = RZ_MIN(sizeof(buf), rz_buf_size(bf->buf));
115 
116  rz_buf_read_at(bf->buf, 0, buf, buf_size);
117  if (!bf->o->info) {
118  return NULL;
119  }
120 
121  if (!(ret = rz_list_newf(free))) {
122  return NULL;
123  }
124  // add text segment
125  if (!(ptr = RZ_NEW0(RzBinSection))) {
126  return ret;
127  }
128  ptr->name = strdup("text");
129  ptr->size = rz_read_ble32(buf + 16, false);
130  ptr->vsize = ptr->size + (ptr->size % 4096);
131  ptr->paddr = rz_read_ble32(buf + 12, false);
132  ptr->vaddr = ptr->paddr + baddr(bf);
133  ptr->perm = RZ_PERM_RX; // r-x
134  rz_list_append(ret, ptr);
135 
136  if (MENUET_VERSION(buf)) {
137  /* add data section */
138  if (!(ptr = RZ_NEW0(RzBinSection))) {
139  return ret;
140  }
141  ptr->name = strdup("idata");
142  const ut32 idata_start = rz_read_ble32(buf + 40, false);
143  const ut32 idata_end = rz_read_ble32(buf + 44, false);
144  ptr->size = idata_end - idata_start;
145  ptr->vsize = ptr->size + (ptr->size % 4096);
146  ptr->paddr = rz_read_ble32(buf + 40, false);
147  ptr->vaddr = ptr->paddr + baddr(bf);
148  ptr->perm = RZ_PERM_R; // r--
149  rz_list_append(ret, ptr);
150  }
151 
152  return ret;
153 }
uint32_t ut32
RZ_API RZ_OWN RzList * rz_list_newf(RzListFree f)
Returns a new initialized RzList pointer and sets the free method.
Definition: list.c:248
#define RZ_PERM_R
Definition: rz_types.h:93
#define RZ_PERM_RX
Definition: rz_types.h:97
RzBinObject * o
Definition: rz_bin.h:305
RzBinInfo * info
Definition: rz_bin.h:287
char * name
Definition: rz_bin.h:619

References baddr(), rz_bin_file_t::buf, buf_size, free(), rz_bin_object_t::info, MENUET_VERSION, rz_bin_section_t::name, NULL, rz_bin_file_t::o, rz_bin_section_t::paddr, rz_bin_section_t::perm, rz_buf_read_at(), rz_buf_size(), rz_list_append(), rz_list_newf(), RZ_MIN, RZ_NEW0, RZ_PERM_R, RZ_PERM_RX, rz_read_ble32(), rz_bin_section_t::size, strdup(), rz_bin_section_t::vaddr, and rz_bin_section_t::vsize.

◆ size()

static ut64 size ( RzBinFile bf)
static

Definition at line 175 of file bin_menuet.c.

175  {
176  ut8 buf[4] = { 0 };
177  if (!bf->o->info) {
178  bf->o->info = info(bf);
179  }
180  if (!bf->o->info) {
181  return 0;
182  }
183  rz_buf_read_at(bf->buf, 16, buf, 4);
184  return (ut64)rz_read_ble32(buf, false);
185 }
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_menuet.c:155

References rz_bin_file_t::buf, info(), rz_bin_object_t::info, rz_bin_file_t::o, rz_buf_read_at(), rz_read_ble32(), and ut64().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_menuet
Definition: bin_menuet.c:205
@ RZ_LIB_TYPE_BIN
Definition: rz_lib.h:75
#define RZ_VERSION
Definition: rz_version.h:8
char * version
Definition: rz_bin.h:512

Definition at line 221 of file bin_menuet.c.

◆ rz_bin_plugin_menuet

RzBinPlugin rz_bin_plugin_menuet
Initial value:
= {
.name = "menuet",
.desc = "Menuet/KolibriOS bin plugin",
.license = "LGPL3",
.load_buffer = &load_buffer,
.size = &size,
.check_buffer = &check_buffer,
.baddr = &baddr,
.entries = &entries,
.sections = &sections,
.info = &info,
.create = &create,
}
RZ_API RZ_OWN RzList * rz_bin_maps_of_file_sections(RZ_NONNULL RzBinFile *binfile)
Create a list of RzBinMap from RzBinSections queried from the given file.
Definition: bin.c:1040
static bool load_buffer(RzBinFile *bf, RzBinObject *obj, RzBuffer *b, Sdb *sdb)
Definition: bin_menuet.c:70
static RzBuffer * create(RzBin *bin, const ut8 *code, int codelen, const ut8 *data, int datalen, RzBinArchOptions *opt)
Definition: bin_menuet.c:190
static ut64 size(RzBinFile *bf)
Definition: bin_menuet.c:175
static RzList * entries(RzBinFile *bf)
Definition: bin_menuet.c:87
static RzList * sections(RzBinFile *bf)
Definition: bin_menuet.c:110

Definition at line 205 of file bin_menuet.c.