Rizin
unix-like reverse engineering framework and cli tools
le.h File Reference
#include <rz_bin.h>
#include "le_specs.h"

Go to the source code of this file.

Classes

struct  rz_bin_le_obj_s
 

Typedefs

typedef struct rz_bin_le_obj_s rz_bin_le_obj_t
 

Functions

rz_bin_le_obj_trz_bin_le_new_buf (RzBuffer *buf)
 
void rz_bin_le_free (rz_bin_le_obj_t *bin)
 
RzListrz_bin_le_get_entrypoints (rz_bin_le_obj_t *bin)
 
RzListrz_bin_le_get_sections (rz_bin_le_obj_t *bin)
 
RzListrz_bin_le_get_symbols (rz_bin_le_obj_t *bin)
 
RzListrz_bin_le_get_imports (rz_bin_le_obj_t *bin)
 
RzListrz_bin_le_get_libs (rz_bin_le_obj_t *bin)
 
RzListrz_bin_le_get_relocs (rz_bin_le_obj_t *bin)
 

Typedef Documentation

◆ rz_bin_le_obj_t

Function Documentation

◆ rz_bin_le_free()

void rz_bin_le_free ( rz_bin_le_obj_t bin)

Definition at line 795 of file le.c.

795  {
797  free(bin->header);
798  free(bin->objtbl);
799  free(bin->filename);
800  free(bin);
801 }
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
Definition: malloc.c:26

References free(), and rz_return_if_fail.

Referenced by destroy(), and rz_bin_le_new_buf().

◆ rz_bin_le_get_entrypoints()

RzList* rz_bin_le_get_entrypoints ( rz_bin_le_obj_t bin)

Definition at line 229 of file le.c.

229  {
231  if (!l) {
232  return NULL;
233  }
235  if (entry) {
236  if ((bin->header->startobj - 1) < bin->header->objcnt) {
237  entry->vaddr = (ut64)bin->objtbl[bin->header->startobj - 1].reloc_base_addr + bin->header->eip;
238  }
239  }
240  rz_list_append(l, entry);
241 
242  return l;
243 }
#define NULL
Definition: cris-opc.c:27
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
void(* RzListFree)(void *ptr)
Definition: rz_list.h:11
#define RZ_NEW0(x)
Definition: rz_types.h:284
Definition: zipcmp.c:77
ut64(WINAPI *w32_GetEnabledXStateFeatures)()

References free(), NULL, rz_list_append(), rz_list_newf(), RZ_NEW0, and ut64().

Referenced by entries().

◆ rz_bin_le_get_imports()

RzList* rz_bin_le_get_imports ( rz_bin_le_obj_t bin)

Definition at line 205 of file le.c.

205  {
207  if (!l) {
208  return NULL;
209  }
210  LE_image_header *h = bin->header;
211  ut64 offset = (ut64)h->impproc + bin->headerOff + 1; // First entry is a null string
212  ut64 end = (ut64)h->fixupsize + h->fpagetab + bin->headerOff;
213  while (offset < end) {
215  if (!imp) {
216  break;
217  }
219  if (!imp->name) {
220  rz_bin_import_free(imp);
221  break;
222  }
223  imp->type = RZ_BIN_TYPE_FUNC_STR;
224  rz_list_append(l, imp);
225  }
226  return l;
227 }
RZ_API void rz_bin_import_free(RzBinImport *imp)
Definition: bin.c:137
voidpf uLong offset
Definition: ioapi.h:144
static char * le_read_nonnull_str_at(RzBuffer *buf, ut64 *offset)
Definition: le.c:60
#define RZ_BIN_TYPE_FUNC_STR
Definition: rz_bin.h:119
#define h(i)
Definition: sha256.c:48
unsigned char * buf
Definition: gzjoin.c:83
const char * type
Definition: rz_bin.h:704
char * name
Definition: rz_bin.h:701

References bin::buf, test_evm::end, h, le_read_nonnull_str_at(), rz_bin_import_t::name, NULL, rz_bin_import_free(), RZ_BIN_TYPE_FUNC_STR, rz_list_append(), rz_list_newf(), RZ_NEW0, rz_bin_import_t::type, and ut64().

Referenced by imports().

◆ rz_bin_le_get_libs()

RzList* rz_bin_le_get_libs ( rz_bin_le_obj_t bin)

Definition at line 245 of file le.c.

245  {
247  if (!l) {
248  return NULL;
249  }
250  LE_image_header *h = bin->header;
251  ut64 offset = (ut64)h->impmod + bin->headerOff;
252  ut64 end = offset + h->impproc - h->impmod;
253  while (offset < end) {
255  if (!name) {
256  break;
257  }
258  rz_list_append(l, name);
259  }
260  return l;
261 }
while(len< limit &&buf1[len]==buf2[len])++len
Definition: z80asm.h:102

References bin::buf, test_evm::end, free(), h, le_read_nonnull_str_at(), NULL, rz_list_append(), rz_list_newf(), ut64(), and while().

Referenced by libs().

◆ rz_bin_le_get_relocs()

RzList* rz_bin_le_get_relocs ( rz_bin_le_obj_t bin)

Definition at line 453 of file le.c.

453  {
455  if (!l) {
456  return NULL;
457  }
460  LE_image_header *h = bin->header;
461  ut64 cur_page = 0;
462  const ut64 fix_rec_tbl_off = (ut64)h->frectab + bin->headerOff;
463  ut32 tmp_offset;
464  if (!rz_buf_read_ble32_at(bin->buf, (ut64)h->fpagetab + bin->headerOff + cur_page * sizeof(ut32), &tmp_offset, h->worder)) {
465  rz_list_free(l);
468  return NULL;
469  }
470 
471  ut64 offset = tmp_offset + fix_rec_tbl_off;
472 
473  ut32 tmp_end;
474  if (!rz_buf_read_ble32_at(bin->buf, (ut64)h->fpagetab + bin->headerOff + (cur_page + 1) * sizeof(ut32), &tmp_end, h->worder)) {
475  rz_list_free(l);
478  return NULL;
479  }
480  ut64 end = tmp_end + fix_rec_tbl_off;
481 
482  const RzBinSection *cur_section = (RzBinSection *)rz_list_get_n(sections, cur_page);
483  ut64 cur_page_offset = cur_section ? cur_section->vaddr : 0;
484  while (cur_page < h->mpages) {
485  RzBinReloc *rel = RZ_NEW0(RzBinReloc);
486  bool rel_appended = false; // whether rel has been appended to l and must not be freed
487  if (!rel) {
488  break;
489  }
491  int ret = rz_buf_read_at(bin->buf, offset, (ut8 *)&header, sizeof(header));
492  if (ret != sizeof(header)) {
493  RZ_LOG_WARN("Cannot read out of bounds relocation.\n");
494  free(rel);
495  break;
496  }
497  offset += sizeof(header);
498  switch (header.source & F_SOURCE_TYPE_MASK) {
499  case BYTEFIXUP:
500  rel->type = RZ_BIN_RELOC_8;
501  break;
502  case SELECTOR16:
503  case OFFSET16:
504  rel->type = RZ_BIN_RELOC_16;
505  break;
506  case OFFSET32:
507  case POINTER32:
508  case SELFOFFSET32:
509  rel->type = RZ_BIN_RELOC_32;
510  break;
511  case POINTER48:
512  rel->type = 48;
513  break;
514  }
515  ut8 repeat = 0;
516  ut16 source = 0;
517  if (header.source & F_SOURCE_LIST) {
518  if (!rz_buf_read8_at(bin->buf, offset, &repeat)) {
519  rz_bin_reloc_free(rel);
520  break;
521  }
522  offset += sizeof(ut8);
523  } else {
524  if (!rz_buf_read_ble16_at(bin->buf, offset, &source, h->worder)) {
525  rz_bin_reloc_free(rel);
526  break;
527  }
528  offset += sizeof(ut16);
529  }
530  ut32 ordinal;
531  if (header.target & F_TARGET_ORD16) {
532  ut16 tmp;
533  if (!rz_buf_read_ble16_at(bin->buf, offset, &tmp, h->worder)) {
534  rz_bin_reloc_free(rel);
535  break;
536  }
537  ordinal = tmp;
538  offset += sizeof(ut16);
539  } else {
540  ut8 tmp;
541  if (!rz_buf_read8_at(bin->buf, offset, &tmp)) {
542  rz_bin_reloc_free(rel);
543  break;
544  }
545  ordinal = tmp;
546  offset += sizeof(ut8);
547  }
548  switch (header.target & F_TARGET_TYPE_MASK) {
549  case INTERNAL:
550  if ((ordinal - 1) < bin->header->objcnt) {
551  rel->addend = bin->objtbl[ordinal - 1].reloc_base_addr;
552  if ((header.source & F_SOURCE_TYPE_MASK) != SELECTOR16) {
553  if (header.target & F_TARGET_OFF32) {
554  ut32 tmp;
555  if (!rz_buf_read_ble32_offset(bin->buf, &offset, &tmp, h->worder)) {
556  rz_bin_reloc_free(rel);
557  continue;
558  }
559  rel->addend += tmp;
560  } else {
561  ut16 tmp;
562  if (!rz_buf_read_ble16_offset(bin->buf, &offset, &tmp, h->worder)) {
563  rz_bin_reloc_free(rel);
564  continue;
565  }
566  rel->addend += tmp;
567  }
568  }
569  }
570  break;
571  case IMPORTORD: {
573  if (!imp) {
574  break;
575  }
576  char *mod_name = le_get_modname_by_ord(bin, ordinal);
577  if (!mod_name) {
578  rz_bin_import_free(imp);
579  break;
580  }
581 
582  if (header.target & F_TARGET_ORD8) {
583  ut8 tmp;
584  if (!rz_buf_read8_at(bin->buf, offset, &tmp)) {
585  rz_bin_import_free(imp);
586  break;
587  }
588  ordinal = tmp;
589  offset += sizeof(ut8);
590  } else if (header.target & F_TARGET_OFF32) {
591  if (!rz_buf_read_ble32_offset(bin->buf, &offset, &ordinal, h->worder)) {
592  rz_bin_import_free(imp);
593  break;
594  }
595  } else {
596  ut16 tmp;
597  if (!rz_buf_read_ble16_offset(bin->buf, &offset, &tmp, h->worder)) {
598  rz_bin_import_free(imp);
599  break;
600  }
601  ordinal = tmp;
602  }
603  imp->name = rz_str_newf("%s.%u", mod_name, ordinal);
604  imp->ordinal = ordinal;
605  rel->import = imp;
606  free(mod_name);
607  break;
608  }
609  case IMPORTNAME: {
611  if (!imp) {
612  break;
613  }
614  ut32 nameoff;
615  if (header.target & F_TARGET_OFF32) {
616  if (!rz_buf_read_ble32_offset(bin->buf, &offset, &nameoff, h->worder)) {
617  rz_bin_import_free(imp);
618  break;
619  }
620  } else {
621  ut16 tmp;
622  if (!rz_buf_read_ble16_offset(bin->buf, &offset, &tmp, h->worder)) {
623  rz_bin_import_free(imp);
624  break;
625  }
626  nameoff = tmp;
627  }
628  ut64 off = (ut64)h->impproc + nameoff + bin->headerOff;
629  char *proc_name = le_read_nonnull_str_at(bin->buf, &off);
630  char *mod_name = le_get_modname_by_ord(bin, ordinal);
631  imp->name = rz_str_newf("%s.%s", mod_name ? mod_name : "", proc_name ? proc_name : "");
632  rel->import = imp;
633  break;
634  }
635  case INTERNALENTRY:
636  rel->addend = (ut64)(size_t)rz_list_get_n(entries, ordinal - 1);
637  break;
638  }
639  if (header.target & F_TARGET_ADDITIVE) {
640  ut32 additive = 0;
641  if (header.target & F_TARGET_ADD32) {
642  if (!rz_buf_read_ble32_offset(bin->buf, &offset, &additive, h->worder)) {
643  rz_bin_reloc_free(rel);
644  break;
645  }
646  } else {
647  ut16 tmp;
648  if (!rz_buf_read_ble16_offset(bin->buf, &offset, &tmp, h->worder)) {
649  rz_bin_reloc_free(rel);
650  break;
651  }
652  additive = tmp;
653  }
654  rel->addend += additive;
655  }
656  if (!repeat) {
657  rel->vaddr = cur_page_offset + source;
658  rel->paddr = cur_section ? cur_section->paddr + source : 0;
659  rz_list_append(l, rel);
660  rel_appended = true;
661  }
662 
663  if (header.target & F_TARGET_CHAIN) {
664  ut32 fixupinfo;
665  if (!rz_buf_read_ble32_at(bin->buf, cur_page_offset + source, &fixupinfo, h->worder)) {
666  break;
667  }
668 
669  ut64 base_target_address = rel->addend - (fixupinfo & 0xFFFFF);
670  do {
671  if (!rz_buf_read_ble32_at(bin->buf, cur_page_offset + source, &fixupinfo, h->worder)) {
672  break;
673  }
674  RzBinReloc *new = RZ_NEW0(RzBinReloc);
675  *new = *rel;
676  new->addend = base_target_address + (fixupinfo & 0xFFFFF);
677  rz_list_append(l, new);
678  source = (fixupinfo >> 20) & 0xFFF;
679  } while (source != 0xFFF);
680  }
681 
682  while (repeat) {
683  ut16 off;
684  if (!rz_buf_read_ble16_offset(bin->buf, &offset, &off, h->worder)) {
685  break;
686  }
687  rel->vaddr = cur_page_offset + off;
688  rel->paddr = cur_section ? cur_section->paddr + off : 0;
689  RzBinReloc *new = RZ_NEW0(RzBinReloc);
690  *new = *rel;
691  rz_list_append(l, new);
692  repeat--;
693  }
694  while (offset >= end) {
695  cur_page++;
696  if (cur_page >= h->mpages) {
697  break;
698  }
699  ut64 at = h->fpagetab + bin->headerOff;
700  ut32 w0;
701  if (!rz_buf_read_ble32_at(bin->buf, at + cur_page * sizeof(ut32), &w0, h->worder)) {
702  break;
703  }
704  ut32 w1;
705  if (!rz_buf_read_ble32_at(bin->buf, at + (cur_page + 1) * sizeof(ut32), &w1, h->worder)) {
706  break;
707  }
708  offset = fix_rec_tbl_off + w0;
709  end = fix_rec_tbl_off + w1;
710  if (offset < end) {
711  cur_section = (RzBinSection *)rz_list_get_n(sections, cur_page);
712  cur_page_offset = cur_section ? cur_section->vaddr : 0;
713  }
714  }
715  if (!rel_appended) {
716  rz_bin_reloc_free(rel);
717  }
718  }
721  return l;
722 }
RZ_API void rz_bin_reloc_free(RzBinReloc *reloc)
Definition: bin.c:188
RzList * entries(RzBinFile *bf)
Definition: bin_ne.c:98
RzList * sections(RzBinFile *bf)
Definition: bin_ne.c:110
#define ut8
Definition: dcpu16.h:8
uint16_t ut16
uint32_t ut32
RzList * le_get_entries(rz_bin_le_obj_t *bin)
Definition: le.c:97
char * le_get_modname_by_ord(rz_bin_le_obj_t *bin, ut32 ordinal)
Definition: le.c:442
RzList * rz_bin_le_get_sections(rz_bin_le_obj_t *bin)
Definition: le.c:338
#define F_SOURCE_LIST
Definition: le_specs.h:81
#define F_TARGET_ORD16
Definition: le_specs.h:100
@ POINTER32
Definition: le_specs.h:87
@ BYTEFIXUP
Definition: le_specs.h:84
@ SELFOFFSET32
Definition: le_specs.h:92
@ SELECTOR16
Definition: le_specs.h:86
@ POINTER48
Definition: le_specs.h:90
@ OFFSET32
Definition: le_specs.h:91
@ OFFSET16
Definition: le_specs.h:89
#define F_TARGET_TYPE_MASK
Definition: le_specs.h:95
@ IMPORTORD
Definition: le_specs.h:105
@ INTERNALENTRY
Definition: le_specs.h:107
@ IMPORTNAME
Definition: le_specs.h:106
@ INTERNAL
Definition: le_specs.h:104
#define F_SOURCE_TYPE_MASK
Definition: le_specs.h:79
#define F_TARGET_ADD32
Definition: le_specs.h:99
#define F_TARGET_OFF32
Definition: le_specs.h:98
#define F_TARGET_ADDITIVE
Definition: le_specs.h:96
#define F_TARGET_CHAIN
Definition: le_specs.h:97
#define F_TARGET_ORD8
Definition: le_specs.h:101
uint8_t ut8
Definition: lh5801.h:11
RZ_API RZ_BORROW void * rz_list_get_n(RZ_NONNULL const RzList *list, ut32 n)
Returns the N-th element of the list.
Definition: list.c:574
RZ_API void rz_list_free(RZ_NONNULL RzList *list)
Empties the list and frees the list pointer.
Definition: list.c:137
const char * source
Definition: lz4.h:699
#define header(is_bt, len_min, ret_op)
int off
Definition: pal.c:13
static void repeat(struct parse *, sopno, int, int)
Definition: regcomp.c:1155
@ RZ_BIN_RELOC_32
Definition: rz_bin.h:176
@ RZ_BIN_RELOC_16
Definition: rz_bin.h:174
@ RZ_BIN_RELOC_8
Definition: rz_bin.h:173
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
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
ut32 ordinal
Definition: rz_bin.h:707
ut64 paddr
the paddr where the value should be patched into
Definition: rz_bin.h:717
RzBinRelocType type
Definition: rz_bin.h:712
ut64 vaddr
the vaddr where the value should be patched into
Definition: rz_bin.h:716
RzBinImport * import
Definition: rz_bin.h:714
st64 addend
Definition: rz_bin.h:715
if(dbg->bits==RZ_SYS_BITS_64)
Definition: windows-arm64.h:4

References rz_bin_reloc_t::addend, bin::buf, BYTEFIXUP, test_evm::end, entries(), F_SOURCE_LIST, F_SOURCE_TYPE_MASK, F_TARGET_ADD32, F_TARGET_ADDITIVE, F_TARGET_CHAIN, F_TARGET_OFF32, F_TARGET_ORD16, F_TARGET_ORD8, F_TARGET_TYPE_MASK, free(), h, header, if(), rz_bin_reloc_t::import, IMPORTNAME, IMPORTORD, INTERNAL, INTERNALENTRY, le_get_entries(), le_get_modname_by_ord(), le_read_nonnull_str_at(), rz_bin_import_t::name, NULL, off, OFFSET16, OFFSET32, rz_bin_import_t::ordinal, rz_bin_section_t::paddr, rz_bin_reloc_t::paddr, POINTER32, POINTER48, repeat(), rz_bin_import_free(), rz_bin_le_get_sections(), RZ_BIN_RELOC_16, RZ_BIN_RELOC_32, RZ_BIN_RELOC_8, rz_bin_reloc_free(), rz_buf_read8_at(), rz_buf_read_at(), rz_list_append(), rz_list_free(), rz_list_get_n(), rz_list_newf(), RZ_LOG_WARN, RZ_NEW0, rz_str_newf(), sections(), SELECTOR16, SELFOFFSET32, source, autogen_x86imm::tmp, rz_bin_reloc_t::type, ut64(), ut8, rz_bin_section_t::vaddr, rz_bin_reloc_t::vaddr, w0, and w1.

Referenced by relocs().

◆ rz_bin_le_get_sections()

RzList* rz_bin_le_get_sections ( rz_bin_le_obj_t bin)

Definition at line 338 of file le.c.

338  {
340  if (!l) {
341  return NULL;
342  }
343  LE_image_header *h = bin->header;
344  ut32 pages_start_off = h->datapage;
345  int i;
346  for (i = 0; i < h->objcnt; i++) {
348  if (!sec) {
349  return l;
350  }
351  LE_object_entry *entry = &bin->objtbl[i];
352  sec->name = rz_str_newf("obj.%d", i + 1);
353  sec->vsize = entry->virtual_size;
354  sec->vaddr = entry->reloc_base_addr;
355  if (entry->flags & O_READABLE) {
356  sec->perm |= RZ_PERM_R;
357  }
358  if (entry->flags & O_WRITABLE) {
359  sec->perm |= RZ_PERM_W;
360  }
361  if (entry->flags & O_EXECUTABLE) {
362  sec->perm |= RZ_PERM_X;
363  }
364  if (entry->flags & O_BIG_BIT) {
365  sec->bits = RZ_SYS_BITS_32;
366  } else {
367  sec->bits = RZ_SYS_BITS_16;
368  }
369  sec->is_data = entry->flags & O_RESOURCE || !(sec->perm & RZ_PERM_X);
370  if (!entry->page_tbl_entries) {
371  rz_list_append(l, sec);
372  }
373  int j;
374  ut32 page_size_sum = 0;
375  ut32 next_idx = i < h->objcnt - 1 ? bin->objtbl[i + 1].page_tbl_idx - 1 : UT32_MAX;
376  ut32 objmaptbloff = h->objmap + bin->headerOff;
377  ut64 objpageentrysz = bin->is_le ? sizeof(ut32) : sizeof(LE_object_page_entry);
378  for (j = 0; j < entry->page_tbl_entries; j++) {
381  if (!s) {
382  rz_bin_section_free(sec);
383  return l;
384  }
385  s->name = rz_str_newf("%s.page.%d", sec->name, j);
386  s->is_data = sec->is_data;
387 
388  int cur_idx = entry->page_tbl_idx + j - 1;
389  ut64 page_entry_off = objpageentrysz * cur_idx + objmaptbloff;
390  ut64 offset = page_entry_off;
391  if (!(rz_buf_read_le32_offset(bin->buf, &offset, &page.offset) &&
394  RZ_LOG_WARN("Cannot read out of bounds page table entry.\n");
396  break;
397  }
398  if (cur_idx < next_idx) { // If not true rest of pages will be zeroes
399  if (bin->is_le) {
400  // Why is it big endian???
401  ut32 tmp_offset;
402  if (!rz_buf_read_be32_at(bin->buf, page_entry_off, &tmp_offset)) {
404  break;
405  }
406 
407  ut64 offset = tmp_offset >> 8;
408  s->paddr = (offset - 1) * h->pagesize + pages_start_off;
409  if (entry->page_tbl_idx + j == h->mpages) {
410  page.size = h->pageshift;
411  } else {
412  page.size = h->pagesize;
413  }
414  } else if (page.flags == P_ITERATED) {
415  ut64 vaddr = sec->vaddr + page_size_sum;
416  __create_iter_sections(l, bin, sec, &page, vaddr, j);
418  page_size_sum += h->pagesize;
419  continue;
420  } else if (page.flags == P_COMPRESSED) {
421  // TODO
422  RZ_LOG_WARN("Compressed page not handled: %s", s->name);
423  } else if (page.flags != P_ZEROED) {
424  s->paddr = ((ut64)page.offset << h->pageshift) + pages_start_off;
425  }
426  }
427  s->vsize = h->pagesize;
428  s->vaddr = sec->vaddr + page_size_sum;
429  s->perm = sec->perm;
430  s->size = page.size;
431  s->bits = sec->bits;
432  rz_list_append(l, s);
433  page_size_sum += s->vsize;
434  }
435  if (entry->page_tbl_entries) {
436  rz_bin_section_free(sec);
437  }
438  }
439  return l;
440 }
lzma_index ** i
Definition: index.h:629
RZ_API void rz_bin_section_free(RzBinSection *bs)
Definition: bin.c:1116
static ut32 next_idx(ut32 idx)
Definition: ht_inc.c:52
static void __create_iter_sections(RzList *l, rz_bin_le_obj_t *bin, RzBinSection *sec, LE_object_page_entry *page, ut64 vaddr, int cur_page)
Definition: le.c:268
#define O_BIG_BIT
Definition: le_specs.h:129
#define P_ITERATED
Definition: le_specs.h:143
#define O_EXECUTABLE
Definition: le_specs.h:117
#define O_READABLE
Definition: le_specs.h:115
#define O_RESOURCE
Definition: le_specs.h:118
#define O_WRITABLE
Definition: le_specs.h:116
#define P_COMPRESSED
Definition: le_specs.h:147
#define P_ZEROED
Definition: le_specs.h:145
static RzSocket * s
Definition: rtr.c:28
#define rz_buf_read_le16_offset(b, offset, result)
Definition: rz_buf.h:276
#define rz_buf_read_be32_at(b, addr, result)
Definition: rz_buf.h:285
#define rz_buf_read_le32_offset(b, offset, result)
Definition: rz_buf.h:277
@ RZ_SYS_BITS_32
Definition: rz_sys.h:20
@ 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 UT32_MAX
Definition: rz_types_base.h:99
Definition: le_specs.h:133
Definition: le_specs.h:149
ut16 flags
Definition: le_specs.h:152
ut16 size
Definition: le_specs.h:151
ut32 offset
Definition: le_specs.h:150
char * name
Definition: rz_bin.h:619

References __create_iter_sections(), rz_bin_section_t::bits, bin::buf, LE_object_page_entry_s::flags, h, i, if(), rz_bin_section_t::is_data, rz_bin_section_t::name, next_idx(), NULL, O_BIG_BIT, O_EXECUTABLE, O_READABLE, O_RESOURCE, O_WRITABLE, LE_object_page_entry_s::offset, P_COMPRESSED, P_ITERATED, P_ZEROED, rz_bin_section_t::perm, rz_bin_section_free(), rz_buf_read_be32_at, rz_buf_read_le16_offset, rz_buf_read_le32_offset, rz_list_append(), rz_list_newf(), RZ_LOG_WARN, RZ_NEW0, RZ_PERM_R, RZ_PERM_W, RZ_PERM_X, rz_str_newf(), RZ_SYS_BITS_16, RZ_SYS_BITS_32, s, LE_object_page_entry_s::size, UT32_MAX, ut64(), rz_bin_section_t::vaddr, and rz_bin_section_t::vsize.

Referenced by rz_bin_le_get_relocs(), and sections().

◆ rz_bin_le_get_symbols()

RzList* rz_bin_le_get_symbols ( rz_bin_le_obj_t bin)

Definition at line 191 of file le.c.

191  {
194  LE_image_header *h = bin->header;
195  ut64 offset = (ut64)h->restab + bin->headerOff;
196  ut32 end = h->enttab + bin->headerOff;
198  offset = h->nrestab;
199  end = h->nrestab + h->cbnrestab;
202  return l;
203 }
RZ_API void rz_bin_symbol_free(RzBinSymbol *sym)
Definition: bin.c:175
static void le_get_symbols_at(rz_bin_le_obj_t *bin, RzList *syml, RzList *entl, ut64 offset, ut64 end)
Definition: le.c:169

References test_evm::end, entries(), h, le_get_entries(), le_get_symbols_at(), rz_bin_symbol_free(), rz_list_free(), rz_list_newf(), and ut64().

Referenced by symbols().

◆ rz_bin_le_new_buf()

rz_bin_le_obj_t* rz_bin_le_new_buf ( RzBuffer buf)

Definition at line 803 of file le.c.

803  {
805  if (!bin) {
806  return NULL;
807  }
808 
810  LE_image_header *h = bin->header;
811  if (!memcmp("LE", h->magic, 2)) {
812  bin->is_le = true;
813  }
814  bin->type = le_get_module_type(bin);
815  bin->cpu = le_get_cpu_type(bin);
816  bin->os = le_get_os_type(bin);
817  bin->arch = le_get_arch(bin);
818  bin->objtbl = calloc(h->objcnt, sizeof(LE_object_entry));
819  if (!bin->objtbl) {
821  return NULL;
822  }
823  ut64 offset = (ut64)bin->headerOff + h->restab;
824  bin->filename = le_read_nonnull_str_at(buf, &offset);
825  offset = (ut64)bin->headerOff + h->objtab;
826  for (ut32 i = 0; i < h->objcnt; i++) {
827  LE_object_entry *le_obj_entry = bin->objtbl + i;
828  rz_buf_read_le32_offset(buf, &offset, &le_obj_entry->virtual_size);
830  rz_buf_read_le32_offset(buf, &offset, &le_obj_entry->flags);
831  rz_buf_read_le32_offset(buf, &offset, &le_obj_entry->page_tbl_idx);
833  rz_buf_read_le32_offset(buf, &offset, &le_obj_entry->reserved);
834  }
835  bin->buf = buf;
836  return bin;
837 }
voidpf void * buf
Definition: ioapi.h:138
void rz_bin_le_free(rz_bin_le_obj_t *bin)
Definition: le.c:795
const char * le_get_module_type(rz_bin_le_obj_t *bin)
Definition: le.c:7
const char * le_get_arch(rz_bin_le_obj_t *bin)
Definition: le.c:42
static bool le_init_header(rz_bin_le_obj_t *bin, RzBuffer *buf)
Definition: le.c:775
const char * le_get_cpu_type(rz_bin_le_obj_t *bin)
Definition: le.c:28
const char * le_get_os_type(rz_bin_le_obj_t *bin)
Definition: le.c:17
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
ut32 flags
Definition: le_specs.h:136
ut32 page_tbl_entries
Definition: le_specs.h:138
ut32 reloc_base_addr
Definition: le_specs.h:135
ut32 page_tbl_idx
Definition: le_specs.h:137
ut32 reserved
Definition: le_specs.h:139
ut32 virtual_size
Definition: le_specs.h:134

References bin::buf, calloc(), LE_object_entry_s::flags, h, i, le_get_arch(), le_get_cpu_type(), le_get_module_type(), le_get_os_type(), le_init_header(), le_read_nonnull_str_at(), NULL, LE_object_entry_s::page_tbl_entries, LE_object_entry_s::page_tbl_idx, LE_object_entry_s::reloc_base_addr, LE_object_entry_s::reserved, rz_bin_le_free(), rz_buf_read_le32_offset, RZ_NEW0, ut64(), and LE_object_entry_s::virtual_size.

Referenced by load_buffer().