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

Go to the source code of this file.

Functions

static bool load_buffer (RzBinFile *bf, RzBinObject *obj, RzBuffer *b, Sdb *sdb)
 
static void destroy (RzBinFile *bf)
 
static bool check_buffer (RzBuffer *b)
 
static ut64 baddr (RzBinFile *bf)
 
static RzListentries (RzBinFile *bf)
 
static RzListsections (RzBinFile *bf)
 
static RzListsymbols (RzBinFile *bf)
 
static RzBinInfoinfo (RzBinFile *bf)
 
static ut64 get_vaddr (RzBinFile *bf, ut64 baddr, ut64 paddr, ut64 vaddr)
 

Variables

RzBinPlugin rz_bin_plugin_omf
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ baddr()

static ut64 baddr ( RzBinFile bf)
static

Definition at line 66 of file bin_omf.c.

66  {
67  return OMF_BASE_ADDR;
68 }
#define OMF_BASE_ADDR
Definition: omf.h:61

References OMF_BASE_ADDR.

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 24 of file bin_omf.c.

24  {
25  int i;
26  ut8 ch;
27  if (rz_buf_read_at(b, 0, &ch, 1) != 1) {
28  return false;
29  }
30  if (ch != 0x80 && ch != 0x82) {
31  return false;
32  }
33 
34  ut16 rec_size;
35  if (!rz_buf_read_le16_at(b, 1, &rec_size)) {
36  return false;
37  }
38 
39  ut8 str_size;
40  (void)rz_buf_read_at(b, 3, &str_size, 1);
42  if (str_size + 2 != rec_size || length < rec_size + 3) {
43  return false;
44  }
45  // check that the string is ASCII
46  for (i = 4; i < str_size + 4; i++) {
47  if (rz_buf_read_at(b, i, &ch, 1) != 1) {
48  break;
49  }
50  if (ch > 0x7f) {
51  return false;
52  }
53  }
54  ut64 size;
55  const ut8 *buf = rz_buf_data(b, &size);
56  if (buf == NULL) {
57  // hackaround until we make this plugin not use RBuf.data
58  ut8 buf[1024] = { 0 };
59  rz_buf_read_at(b, 0, buf, sizeof(buf));
60  return rz_bin_checksum_omf_ok(buf, sizeof(buf));
61  }
62  rz_return_val_if_fail(buf, false);
64 }
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
uint16_t ut16
voidpf void uLong size
Definition: ioapi.h:138
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
bool rz_bin_checksum_omf_ok(const ut8 *buf, ut64 buf_size)
Definition: omf.c:30
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
#define rz_buf_read_le16_at(b, addr, result)
Definition: rz_buf.h:270
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_DEPRECATE RZ_API RZ_BORROW ut8 * rz_buf_data(RZ_NONNULL RzBuffer *b, RZ_NONNULL RZ_OUT ut64 *size)
Return a borrowed array of bytes representing the buffer data.
Definition: buf.c:1287
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
#define b(i)
Definition: sha256.c:42
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References b, i, length, NULL, rz_bin_checksum_omf_ok(), rz_buf_data(), rz_buf_read_at(), rz_buf_read_le16_at, rz_buf_size(), rz_return_val_if_fail, and ut64().

◆ destroy()

static void destroy ( RzBinFile bf)
static

Definition at line 19 of file bin_omf.c.

19  {
21  bf->o->bin_obj = NULL;
22 }
void rz_bin_free_all_omf_obj(rz_bin_omf_obj *obj)
Definition: omf.c:665
RzBinObject * o
Definition: rz_bin.h:305
void * bin_obj
Definition: rz_bin.h:293

References rz_bin_object_t::bin_obj, NULL, rz_bin_file_t::o, and rz_bin_free_all_omf_obj().

◆ entries()

static RzList* entries ( RzBinFile bf)
static

Definition at line 70 of file bin_omf.c.

70  {
71  RzList *ret;
72  RzBinAddr *addr;
73 
74  if (!(ret = rz_list_newf(free))) {
75  return NULL;
76  }
77  if (!(addr = RZ_NEW0(RzBinAddr))) {
78  rz_list_free(ret);
79  return NULL;
80  }
81  if (!rz_bin_omf_get_entry(bf->o->bin_obj, addr)) {
82  RZ_FREE(addr);
83  } else {
84  rz_list_append(ret, addr);
85  }
86  return ret;
87 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
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
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
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
bool rz_bin_omf_get_entry(rz_bin_omf_obj *obj, RzBinAddr *addr)
Definition: omf.c:701
#define RZ_NEW0(x)
Definition: rz_types.h:284
#define RZ_FREE(x)
Definition: rz_types.h:369
static int addr
Definition: z80asm.c:58

References addr, rz_bin_object_t::bin_obj, free(), NULL, rz_bin_file_t::o, rz_bin_omf_get_entry(), RZ_FREE, rz_list_append(), rz_list_free(), rz_list_newf(), and RZ_NEW0.

◆ get_vaddr()

static ut64 get_vaddr ( RzBinFile bf,
ut64  baddr,
ut64  paddr,
ut64  vaddr 
)
static

Definition at line 161 of file bin_omf.c.

161  {
162  return vaddr;
163 }

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 139 of file bin_omf.c.

139  {
140  RzBinInfo *ret;
141 
142  if (!(ret = RZ_NEW0(RzBinInfo))) {
143  return NULL;
144  }
145  ret->file = strdup(bf->file);
146  ret->bclass = strdup("OMF");
147  ret->rclass = strdup("omf");
148  // the "E" is here to made rva return the same value for 16 bit en 32 bits files
149  ret->type = strdup("E OMF (Relocatable Object Module Format)");
150  ret->os = strdup("any");
151  ret->machine = strdup("i386");
152  ret->arch = strdup("x86");
153  ret->big_endian = false;
154  ret->has_va = true;
155  ret->bits = rz_bin_omf_get_bits(bf->o->bin_obj);
156  ret->dbg_info = 0;
157  ret->has_nx = false;
158  return ret;
159 }
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")
int rz_bin_omf_get_bits(rz_bin_omf_obj *obj)
Definition: omf.c:731
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
int has_nx
Definition: rz_bin.h:234
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_object_t::bin_obj, 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_nx, rz_bin_info_t::has_va, rz_bin_info_t::machine, NULL, rz_bin_file_t::o, rz_bin_info_t::os, rz_bin_info_t::rclass, rz_bin_omf_get_bits(), RZ_NEW0, strdup(), and rz_bin_info_t::type.

◆ load_buffer()

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

Definition at line 11 of file bin_omf.c.

11  {
12  ut64 size;
13  const ut8 *buf = rz_buf_data(b, &size);
14  rz_return_val_if_fail(buf, false);
16  return obj->bin_obj;
17 }
rz_bin_omf_obj * rz_bin_internal_omf_load(const ut8 *buf, ut64 size)
Definition: omf.c:683

References b, rz_bin_object_t::bin_obj, rz_bin_internal_omf_load(), rz_buf_data(), rz_return_val_if_fail, and ut64().

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 89 of file bin_omf.c.

89  {
90  RzList *ret;
91  ut32 ct_omf_sect = 0;
92 
93  if (!bf || !bf->o || !bf->o->bin_obj) {
94  return NULL;
95  }
96  rz_bin_omf_obj *obj = bf->o->bin_obj;
97 
98  if (!(ret = rz_list_new())) {
99  return NULL;
100  }
101 
102  while (ct_omf_sect < obj->nb_section) {
103  if (!rz_bin_omf_send_sections(ret,
104  obj->sections[ct_omf_sect++], bf->o->bin_obj)) {
105  return ret;
106  }
107  }
108  return ret;
109 }
uint32_t ut32
RZ_API RZ_OWN RzList * rz_list_new(void)
Returns a new initialized RzList pointer (free method is not initialized)
Definition: list.c:235
int rz_bin_omf_send_sections(RzList *list, OMF_segment *section, rz_bin_omf_obj *obj)
Definition: omf.c:746
OMF_segment ** sections
Definition: omf.h:52

References rz_bin_object_t::bin_obj, NULL, rz_bin_file_t::o, rz_bin_omf_send_sections(), rz_list_new(), and rz_bin_omf_obj::sections.

◆ symbols()

static RzList* symbols ( RzBinFile bf)
static

Definition at line 111 of file bin_omf.c.

111  {
112  RzList *ret;
113  RzBinSymbol *sym;
114  OMF_symbol *sym_omf;
115  int ct_sym = 0;
116  if (!bf || !bf->o || !bf->o->bin_obj) {
117  return NULL;
118  }
119  if (!(ret = rz_list_newf((RzListFree)rz_bin_symbol_free))) {
120  return NULL;
121  }
122 
123  while (ct_sym < ((rz_bin_omf_obj *)bf->o->bin_obj)->nb_symbol) {
124  if (!(sym = RZ_NEW0(RzBinSymbol))) {
125  return ret;
126  }
127  sym_omf = ((rz_bin_omf_obj *)bf->o->bin_obj)->symbols[ct_sym++];
128  sym->name = strdup(sym_omf->name);
129  sym->forwarder = "NONE";
130  sym->paddr = rz_bin_omf_get_paddr_sym(bf->o->bin_obj, sym_omf);
131  sym->vaddr = rz_bin_omf_get_vaddr_sym(bf->o->bin_obj, sym_omf);
132  sym->ordinal = ct_sym;
133  sym->size = 0;
134  rz_list_append(ret, sym);
135  }
136  return ret;
137 }
RZ_API void rz_bin_symbol_free(RzBinSymbol *sym)
Definition: bin.c:175
ut64 rz_bin_omf_get_vaddr_sym(rz_bin_omf_obj *obj, OMF_symbol *sym)
Definition: omf.c:797
ut64 rz_bin_omf_get_paddr_sym(rz_bin_omf_obj *obj, OMF_symbol *sym)
Definition: omf.c:774
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
Definition: omf.h:42
char * name
Definition: omf.h:43
char * name
Definition: rz_bin.h:675
ut32 ordinal
Definition: rz_bin.h:692
const char * forwarder
Definition: rz_bin.h:680

References rz_bin_object_t::bin_obj, rz_bin_symbol_t::forwarder, OMF_symbol::name, rz_bin_symbol_t::name, NULL, rz_bin_file_t::o, rz_bin_symbol_t::ordinal, rz_bin_symbol_t::paddr, rz_bin_omf_get_paddr_sym(), rz_bin_omf_get_vaddr_sym(), rz_bin_symbol_free(), rz_list_append(), rz_list_newf(), RZ_NEW0, rz_bin_symbol_t::size, strdup(), and rz_bin_symbol_t::vaddr.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_omf
Definition: bin_omf.c:165
@ 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 182 of file bin_omf.c.

◆ rz_bin_plugin_omf

RzBinPlugin rz_bin_plugin_omf
Initial value:
= {
.name = "omf",
.desc = "omf bin plugin",
.license = "LGPL3",
.load_buffer = &load_buffer,
.destroy = &destroy,
.check_buffer = &check_buffer,
.baddr = &baddr,
.entries = &entries,
.sections = &sections,
.symbols = &symbols,
.info = &info,
.get_vaddr = &get_vaddr,
}
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_omf.c:11
static RzList * symbols(RzBinFile *bf)
Definition: bin_omf.c:111
static void destroy(RzBinFile *bf)
Definition: bin_omf.c:19
static bool check_buffer(RzBuffer *b)
Definition: bin_omf.c:24
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_omf.c:139
static ut64 baddr(RzBinFile *bf)
Definition: bin_omf.c:66
static RzList * entries(RzBinFile *bf)
Definition: bin_omf.c:70
static RzList * sections(RzBinFile *bf)
Definition: bin_omf.c:89
static ut64 get_vaddr(RzBinFile *bf, ut64 baddr, ut64 paddr, ut64 vaddr)
Definition: bin_omf.c:161

Definition at line 165 of file bin_omf.c.