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

Go to the source code of this file.

Functions

static Sdbget_sdb (RzBinFile *bf)
 
static bool load_buffer (RzBinFile *bf, RzBinObject *obj, RzBuffer *b, Sdb *sdb)
 
static void destroy (RzBinFile *bf)
 
static ut64 baddr (RzBinFile *bf)
 
static RzBinAddrbinsym (RzBinFile *bf, RzBinSpecialSymbol type)
 
static RzListentries (RzBinFile *bf)
 
static RzListsections (RzBinFile *bf)
 
static RzBinInfoinfo (RzBinFile *bf)
 
static bool check_buffer (RzBuffer *b)
 

Variables

RzBinPlugin rz_bin_plugin_te
 
RZ_API RzLibStruct rizin_plugin
 

Function Documentation

◆ baddr()

static ut64 baddr ( RzBinFile bf)
static

Definition at line 38 of file bin_te.c.

38  {
39  return rz_bin_te_get_image_base(bf->o->bin_obj);
40 }
RzBinObject * o
Definition: rz_bin.h:305
void * bin_obj
Definition: rz_bin.h:293
ut64 rz_bin_te_get_image_base(struct rz_bin_te_obj_t *bin)
Definition: te.c:222

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

◆ binsym()

static RzBinAddr* binsym ( RzBinFile bf,
RzBinSpecialSymbol  type 
)
static

Definition at line 42 of file bin_te.c.

42  {
43  RzBinAddr *ret = NULL;
44  switch (type) {
46  if (!(ret = RZ_NEW(RzBinAddr))) {
47  return NULL;
48  }
49  ret->paddr = ret->vaddr = rz_bin_te_get_main_paddr(bf->o->bin_obj);
50  break;
51  default:
52  break;
53  }
54  return ret;
55 }
#define NULL
Definition: cris-opc.c:27
int type
Definition: mipsasm.c:17
@ RZ_BIN_SPECIAL_SYMBOL_MAIN
Definition: rz_bin.h:139
#define RZ_NEW(x)
Definition: rz_types.h:285
ut64 vaddr
Definition: rz_bin.h:186
ut64 paddr
Definition: rz_bin.h:187
ut64 rz_bin_te_get_main_paddr(struct rz_bin_te_obj_t *bin)
Definition: te.c:95

References rz_bin_object_t::bin_obj, NULL, rz_bin_file_t::o, rz_bin_addr_t::paddr, RZ_BIN_SPECIAL_SYMBOL_MAIN, rz_bin_te_get_main_paddr(), RZ_NEW, type, and rz_bin_addr_t::vaddr.

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 144 of file bin_te.c.

144  {
145  ut8 buf[2];
146  if (rz_buf_read_at(b, 0, buf, 2) == 2) {
147  return !memcmp(buf, "\x56\x5a", 2);
148  }
149  return false;
150 }
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
#define b(i)
Definition: sha256.c:42

References b, and rz_buf_read_at().

◆ destroy()

static void destroy ( RzBinFile bf)
static

Definition at line 34 of file bin_te.c.

34  {
35  rz_bin_te_free((struct rz_bin_te_obj_t *)bf->o->bin_obj);
36 }
void * rz_bin_te_free(struct rz_bin_te_obj_t *bin)
Definition: te.c:431

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

◆ entries()

static RzList* entries ( RzBinFile bf)
static

Definition at line 57 of file bin_te.c.

57  {
58  RzList *ret = rz_list_newf(free);
59  if (ret) {
61  if (entry) {
62  RzBinAddr *ptr = RZ_NEW0(RzBinAddr);
63  if (ptr) {
64  ptr->paddr = entry->paddr;
65  ptr->vaddr = entry->vaddr;
66  rz_list_append(ret, ptr);
67  }
68  free(entry);
69  }
70  }
71  return ret;
72 }
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
#define RZ_NEW0(x)
Definition: rz_types.h:284
Definition: zipcmp.c:77
RzBinAddr * rz_bin_te_get_entrypoint(struct rz_bin_te_obj_t *bin)
Definition: te.c:204

References rz_bin_object_t::bin_obj, free(), rz_bin_file_t::o, rz_bin_addr_t::paddr, rz_bin_te_get_entrypoint(), rz_list_append(), rz_list_newf(), RZ_NEW0, and rz_bin_addr_t::vaddr.

◆ get_sdb()

static Sdb* get_sdb ( RzBinFile bf)
static

Definition at line 11 of file bin_te.c.

11  {
12  RzBinObject *o = bf->o;
13  if (!o) {
14  return NULL;
15  }
16  struct rz_bin_te_obj_t *bin = (struct rz_bin_te_obj_t *)o->bin_obj;
17  return bin ? bin->kv : NULL;
18 }
Definition: malloc.c:26

References rz_bin_object_t::bin_obj, NULL, and rz_bin_file_t::o.

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 121 of file bin_te.c.

121  {
122  RzBinInfo *ret = RZ_NEW0(RzBinInfo);
123  if (!ret) {
124  return NULL;
125  }
126  ret->file = strdup(bf->file);
127  ret->bclass = strdup("TE");
128  ret->rclass = strdup("te");
129  ret->os = rz_bin_te_get_os(bf->o->bin_obj);
130  ret->arch = rz_bin_te_get_arch(bf->o->bin_obj);
131  ret->machine = rz_bin_te_get_machine(bf->o->bin_obj);
133  ret->type = strdup("EXEC (Executable file)");
134  ret->bits = rz_bin_te_get_bits(bf->o->bin_obj);
135  ret->big_endian = 1;
136  ret->dbg_info = 0;
137  ret->has_va = true;
138 
139  sdb_num_set(bf->sdb, "te.bits", ret->bits, 0);
140 
141  return ret;
142 }
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")
RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas)
Definition: num.c:25
RZ_DEPRECATE Sdb * sdb
deprecated, put info in C structures instead of this
Definition: rz_bin.h:315
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
char * rz_bin_te_get_os(struct rz_bin_te_obj_t *bin)
Definition: te.c:325
char * rz_bin_te_get_arch(struct rz_bin_te_obj_t *bin)
Definition: te.c:167
char * rz_bin_te_get_subsystem(struct rz_bin_te_obj_t *bin)
Definition: te.c:388
char * rz_bin_te_get_machine(struct rz_bin_te_obj_t *bin)
Definition: te.c:229
int rz_bin_te_get_bits(struct rz_bin_te_obj_t *bin)
Definition: te.c:200

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_va, rz_bin_info_t::machine, NULL, rz_bin_file_t::o, rz_bin_info_t::os, rz_bin_info_t::rclass, rz_bin_te_get_arch(), rz_bin_te_get_bits(), rz_bin_te_get_machine(), rz_bin_te_get_os(), rz_bin_te_get_subsystem(), RZ_NEW0, rz_bin_file_t::sdb, sdb_num_set(), strdup(), rz_bin_info_t::subsystem, and rz_bin_info_t::type.

◆ load_buffer()

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

Definition at line 20 of file bin_te.c.

20  {
21  rz_return_val_if_fail(bf && obj && b, false);
22  ut64 sz = rz_buf_size(b);
23  if (sz == 0 || sz == UT64_MAX) {
24  return false;
25  }
26  struct rz_bin_te_obj_t *res = rz_bin_te_new_buf(b);
27  if (res) {
28  sdb_ns_set(sdb, "info", res->kv);
29  }
30  obj->bin_obj = res;
31  return true;
32 }
RZ_API int sdb_ns_set(Sdb *s, const char *name, Sdb *r)
Definition: ns.c:156
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
#define UT64_MAX
Definition: rz_types_base.h:86
Sdb * kv
Definition: te.h:44
struct rz_bin_te_obj_t * rz_bin_te_new_buf(RzBuffer *buf)
Definition: te.c:466
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References b, rz_bin_object_t::bin_obj, rz_bin_te_obj_t::kv, rz_bin_te_new_buf(), rz_buf_size(), rz_return_val_if_fail, sdb_ns_set(), ut64(), and UT64_MAX.

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 74 of file bin_te.c.

74  {
75  RzList *ret = NULL;
76  RzBinSection *ptr = NULL;
78  int i;
79 
80  if (!(ret = rz_list_new())) {
81  return NULL;
82  }
83  ret->free = free;
84  if (!(sections = rz_bin_te_get_sections(bf->o->bin_obj))) {
85  free(ret);
86  return NULL;
87  }
88  for (i = 0; !sections[i].last; i++) {
89  if (!(ptr = RZ_NEW0(RzBinSection))) {
90  break;
91  }
92  ptr->name = strdup((char *)sections[i].name);
93  ptr->size = sections[i].size;
94  ptr->vsize = sections[i].vsize;
95  ptr->paddr = sections[i].paddr;
96  ptr->vaddr = sections[i].vaddr;
97  ptr->perm = 0;
99  ptr->perm |= RZ_PERM_X;
100  }
102  ptr->perm |= RZ_PERM_W;
103  }
105  ptr->perm |= RZ_PERM_R;
106  }
108  ptr->perm |= RZ_PERM_SHAR;
109  }
110  /* All TE files have _TEXT_RE section, which is 16-bit, because of
111  * CPU start in this mode */
112  if (!strncmp(ptr->name, "_TEXT_RE", 8)) {
113  ptr->bits = RZ_SYS_BITS_16;
114  }
115  rz_list_append(ret, ptr);
116  }
117  free(sections);
118  return ret;
119 }
lzma_index ** i
Definition: index.h:629
static RzList * sections(RzBinFile *bf)
Definition: bin_te.c:74
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_SYS_BITS_16
Definition: rz_sys.h:19
#define RZ_PERM_R
Definition: rz_types.h:93
#define RZ_PERM_W
Definition: rz_types.h:94
#define RZ_PERM_X
Definition: rz_types.h:95
#define RZ_PERM_SHAR
Definition: rz_types.h:100
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
Definition: z80asm.h:102
char * name
Definition: rz_bin.h:619
RzListFree free
Definition: rz_list.h:21
struct rz_bin_te_section_t * rz_bin_te_get_sections(struct rz_bin_te_obj_t *bin)
Definition: te.c:359
#define RZ_BIN_TE_SCN_IS_WRITABLE(x)
Definition: te.h:16
#define RZ_BIN_TE_SCN_IS_READABLE(x)
Definition: te.h:15
#define RZ_BIN_TE_SCN_IS_SHAREABLE(x)
Definition: te.h:13
#define RZ_BIN_TE_SCN_IS_EXECUTABLE(x)
Definition: te.h:14

References rz_bin_object_t::bin_obj, rz_bin_section_t::bits, flags, rz_list_t::free, free(), i, rz_bin_section_t::name, NULL, rz_bin_file_t::o, rz_bin_section_t::paddr, rz_bin_section_t::perm, rz_bin_te_get_sections(), RZ_BIN_TE_SCN_IS_EXECUTABLE, RZ_BIN_TE_SCN_IS_READABLE, RZ_BIN_TE_SCN_IS_SHAREABLE, RZ_BIN_TE_SCN_IS_WRITABLE, rz_list_append(), rz_list_new(), RZ_NEW0, RZ_PERM_R, RZ_PERM_SHAR, RZ_PERM_W, RZ_PERM_X, RZ_SYS_BITS_16, rz_bin_section_t::size, strdup(), rz_bin_section_t::vaddr, and rz_bin_section_t::vsize.

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
.data = &rz_bin_plugin_te,
}
RzBinPlugin rz_bin_plugin_te
Definition: bin_te.c:152
@ 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 170 of file bin_te.c.

◆ rz_bin_plugin_te

RzBinPlugin rz_bin_plugin_te
Initial value:
= {
.name = "te",
.desc = "TE bin plugin",
.license = "LGPL3",
.get_sdb = &get_sdb,
.load_buffer = &load_buffer,
.destroy = &destroy,
.check_buffer = &check_buffer,
.baddr = &baddr,
.binsym = &binsym,
.entries = &entries,
.sections = &sections,
.info = &info,
.minstrlen = 4,
}
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_te.c:20
static Sdb * get_sdb(RzBinFile *bf)
Definition: bin_te.c:11
static RzBinAddr * binsym(RzBinFile *bf, RzBinSpecialSymbol type)
Definition: bin_te.c:42
static void destroy(RzBinFile *bf)
Definition: bin_te.c:34
static bool check_buffer(RzBuffer *b)
Definition: bin_te.c:144
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_te.c:121
static ut64 baddr(RzBinFile *bf)
Definition: bin_te.c:38
static RzList * entries(RzBinFile *bf)
Definition: bin_te.c:57

Definition at line 152 of file bin_te.c.