Rizin
unix-like reverse engineering framework and cli tools
bin_bios.c File Reference
#include <rz_types.h>
#include <rz_util.h>
#include <rz_lib.h>
#include <rz_bin.h>
#include "../i/private.h"

Go to the source code of this file.

Functions

static bool check_buffer (RzBuffer *buf)
 
static bool load_buffer (RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
 
static void destroy (RzBinFile *bf)
 
static ut64 baddr (RzBinFile *bf)
 
static RzListstrings (RzBinFile *bf)
 
static RzBinInfoinfo (RzBinFile *bf)
 
static RzListsections (RzBinFile *bf)
 
static RzListentries (RzBinFile *bf)
 

Variables

RzBinPlugin rz_bin_plugin_bios
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ baddr()

static ut64 baddr ( RzBinFile bf)
static

Definition at line 57 of file bin_bios.c.

57  {
58  return 0;
59 }

◆ check_buffer()

static bool check_buffer ( RzBuffer buf)
static

Definition at line 10 of file bin_bios.c.

10  {
11  rz_return_val_if_fail(buf, false);
12 
13  ut64 sz = rz_buf_size(buf);
14  if (sz <= 0xffff) {
15  return false;
16  }
17 
18  ut8 b0;
19  if (!rz_buf_read8_at(buf, 0, &b0)) {
20  return false;
21  }
22 
23  if (b0 == 0xcf || b0 == 0x7f) {
24  return false;
25  }
26 
27  const ut32 ep = sz - 0x10000 + 0xfff0; /* F000:FFF0 address */
28  /* hacky check to avoid detecting multidex or MZ bins as bios */
29  /* need better fix for this */
30  ut8 tmp[3];
31  int r = rz_buf_read_at(buf, 0, tmp, sizeof(tmp));
32  if (r <= 0 || !memcmp(tmp, "dex", 3) || !memcmp(tmp, "MZ", 2)) {
33  return false;
34  }
35 
36  /* Check if this a 'jmp' opcode */
37  ut8 bep;
38  if (!rz_buf_read8_at(buf, ep, &bep)) {
39  return false;
40  }
41 
42  return bep == 0xea || bep == 0xe9;
43 }
#define r
Definition: crypto_rc6.c:12
uint32_t ut32
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API bool rz_buf_read8_at(RzBuffer *b, ut64 addr, RZ_NONNULL RZ_OUT ut8 *result)
Read a byte at the specified address in the buffer.
Definition: buf.c:876
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
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References r, rz_buf_read8_at(), rz_buf_read_at(), rz_buf_size(), rz_return_val_if_fail, autogen_x86imm::tmp, and ut64().

Referenced by load_buffer().

◆ destroy()

static void destroy ( RzBinFile bf)
static

Definition at line 53 of file bin_bios.c.

53  {
54  rz_buf_free(bf->o->bin_obj);
55 }
RZ_API void rz_buf_free(RzBuffer *b)
Free all internal data hold by the buffer and the buffer.
Definition: buf.c:1253
RzBinObject * o
Definition: rz_bin.h:305
void * bin_obj
Definition: rz_bin.h:293

References rz_bin_object_t::bin_obj, rz_bin_file_t::o, and rz_buf_free().

◆ entries()

static RzList* entries ( RzBinFile bf)
static

Definition at line 120 of file bin_bios.c.

120  {
121  RzList *ret;
122  RzBinAddr *ptr = NULL;
123  if (!(ret = rz_list_new())) {
124  return NULL;
125  }
126  ret->free = free;
127  if (!(ptr = RZ_NEW0(RzBinAddr))) {
128  return ret;
129  }
130  ptr->paddr = 0; // 0x70000;
131  ptr->vaddr = 0xffff0;
132  rz_list_append(ret, ptr);
133  return ret;
134 }
#define NULL
Definition: cris-opc.c:27
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
#define RZ_NEW0(x)
Definition: rz_types.h:284
ut64 vaddr
Definition: rz_bin.h:186
ut64 paddr
Definition: rz_bin.h:187
RzListFree free
Definition: rz_list.h:21

References rz_list_t::free, free(), NULL, rz_bin_addr_t::paddr, rz_list_append(), rz_list_new(), RZ_NEW0, and rz_bin_addr_t::vaddr.

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 66 of file bin_bios.c.

66  {
67  RzBinInfo *ret = NULL;
68  if (!(ret = RZ_NEW0(RzBinInfo))) {
69  return NULL;
70  }
71  ret->lang = NULL;
72  ret->file = bf->file ? strdup(bf->file) : NULL;
73  ret->type = strdup("bios");
74  ret->bclass = strdup("1.0");
75  ret->rclass = strdup("bios");
76  ret->os = strdup("any");
77  ret->subsystem = strdup("unknown");
78  ret->machine = strdup("pc");
79  ret->arch = strdup("x86");
80  ret->has_va = 1;
81  ret->bits = 16;
82  ret->big_endian = 0;
83  ret->dbg_info = 0;
84  return ret;
85 }
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
const char * lang
Definition: rz_bin.h:224
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::lang, rz_bin_info_t::machine, NULL, rz_bin_info_t::os, rz_bin_info_t::rclass, RZ_NEW0, strdup(), rz_bin_info_t::subsystem, and rz_bin_info_t::type.

◆ load_buffer()

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

Definition at line 45 of file bin_bios.c.

45  {
46  if (!check_buffer(buf)) {
47  return false;
48  }
49  obj->bin_obj = rz_buf_ref(buf);
50  return true;
51 }
static bool check_buffer(RzBuffer *buf)
Definition: bin_bios.c:10
RZ_API RzBuffer * rz_buf_ref(RzBuffer *b)
Increment the reference count of the buffer.
Definition: buf.c:668

References rz_bin_object_t::bin_obj, check_buffer(), and rz_buf_ref().

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 87 of file bin_bios.c.

87  {
88  RzList *ret = NULL;
89  RzBinSection *ptr = NULL;
90  RzBuffer *obj = bf->o->bin_obj;
91 
93  return NULL;
94  }
95  // program headers is another section
96  if (!(ptr = RZ_NEW0(RzBinSection))) {
97  return ret;
98  }
99  ptr->name = strdup("bootblk"); // Maps to 0xF000:0000 segment
100  ptr->vsize = ptr->size = 0x10000;
101  ptr->paddr = rz_buf_size(bf->buf) - ptr->size;
102  ptr->vaddr = 0xf0000;
103  ptr->perm = RZ_PERM_RWX;
104  rz_list_append(ret, ptr);
105  // If image bigger than 128K - add one more section
106  if (bf->size >= 0x20000) {
107  if (!(ptr = RZ_NEW0(RzBinSection))) {
108  return ret;
109  }
110  ptr->name = strdup("_e000"); // Maps to 0xE000:0000 segment
111  ptr->vsize = ptr->size = 0x10000;
112  ptr->paddr = rz_buf_size(obj) - 2 * ptr->size;
113  ptr->vaddr = 0xe0000;
114  ptr->perm = RZ_PERM_RWX;
115  rz_list_append(ret, ptr);
116  }
117  return ret;
118 }
RZ_API void rz_bin_section_free(RzBinSection *bs)
Definition: bin.c:1116
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
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_PERM_RWX
Definition: rz_types.h:98
RzBuffer * buf
Definition: rz_bin.h:303
char * name
Definition: rz_bin.h:619

References rz_bin_object_t::bin_obj, rz_bin_file_t::buf, rz_bin_section_t::name, NULL, rz_bin_file_t::o, rz_bin_section_t::paddr, rz_bin_section_t::perm, rz_bin_section_free(), rz_buf_size(), rz_list_append(), rz_list_newf(), RZ_NEW0, RZ_PERM_RWX, rz_bin_file_t::size, rz_bin_section_t::size, strdup(), rz_bin_section_t::vaddr, and rz_bin_section_t::vsize.

◆ strings()

static RzList* strings ( RzBinFile bf)
static

Definition at line 62 of file bin_bios.c.

62  {
63  return NULL;
64 }

References NULL.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_bios
Definition: bin_bios.c:136
@ 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 152 of file bin_bios.c.

◆ rz_bin_plugin_bios

RzBinPlugin rz_bin_plugin_bios
Initial value:
= {
.name = "bios",
.desc = "BIOS bin plugin",
.license = "LGPL",
.load_buffer = &load_buffer,
.destroy = &destroy,
.check_buffer = &check_buffer,
.baddr = &baddr,
.entries = entries,
.sections = sections,
.strings = &strings,
.info = &info,
}
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 *buf, Sdb *sdb)
Definition: bin_bios.c:45
static RzList * strings(RzBinFile *bf)
Definition: bin_bios.c:62
static void destroy(RzBinFile *bf)
Definition: bin_bios.c:53
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_bios.c:66
static ut64 baddr(RzBinFile *bf)
Definition: bin_bios.c:57
static RzList * entries(RzBinFile *bf)
Definition: bin_bios.c:120
static RzList * sections(RzBinFile *bf)
Definition: bin_bios.c:87

Definition at line 136 of file bin_bios.c.