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

Go to the source code of this file.

Classes

struct  symbols_header_t
 
struct  symbols_metadata_t
 

Macros

#define D   if (0)
 
#define RZ_UUID_LENGTH   33
 

Typedefs

typedef struct symbols_header_t SymbolsHeader
 
typedef struct symbols_metadata_t SymbolsMetadata
 

Functions

static SymbolsHeader parseHeader (RzBuffer *buf)
 
static const char * typeString (ut32 n, int *bits)
 
static const char * subtypeString (int n)
 
static SymbolsMetadata parseMetadata (RzBuffer *buf, int off)
 
static RzBinSectionbin_section_from_section (RzCoreSymCacheElementSection *sect)
 
static RzBinSectionbin_section_from_segment (RzCoreSymCacheElementSegment *seg)
 
static RzBinSymbolbin_symbol_from_symbol (RzCoreSymCacheElement *element, RzCoreSymCacheElementSymbol *s)
 
static RzCoreSymCacheElementparseDragons (RzBinFile *bf, RzBuffer *buf, int off, int bits, RZ_OWN char *file_name)
 
static bool load_buffer (RzBinFile *bf, RzBinObject *obj, RzBuffer *buf, Sdb *sdb)
 
static RzListsections (RzBinFile *bf)
 
static ut64 baddr (RzBinFile *bf)
 
static RzBinInfoinfo (RzBinFile *bf)
 
static bool check_buffer (RzBuffer *b)
 
static RzListsymbols (RzBinFile *bf)
 
static ut64 size (RzBinFile *bf)
 
static void destroy (RzBinFile *bf)
 
static void header (RzBinFile *bf)
 
static RzBinSourceLineInfolines (RzBinFile *bf)
 

Variables

RzBinPlugin rz_bin_plugin_symbols
 
RZ_API RzLibStruct rizin_plugin
 

Macro Definition Documentation

◆ D

#define D   if (0)

Definition at line 13 of file bin_symbols.c.

◆ RZ_UUID_LENGTH

#define RZ_UUID_LENGTH   33

Definition at line 14 of file bin_symbols.c.

Typedef Documentation

◆ SymbolsHeader

◆ SymbolsMetadata

Function Documentation

◆ baddr()

static ut64 baddr ( RzBinFile bf)
static

Definition at line 316 of file bin_symbols.c.

316  {
317  return 0LL;
318 }

◆ bin_section_from_section()

static RzBinSection* bin_section_from_section ( RzCoreSymCacheElementSection sect)
static

Definition at line 122 of file bin_symbols.c.

122  {
123  if (!sect->name) {
124  return NULL;
125  }
127  if (!s) {
128  return NULL;
129  }
130  s->name = rz_str_ndup(sect->name, 256);
131  s->size = sect->size;
132  s->vsize = s->size;
133  s->paddr = sect->paddr;
134  s->vaddr = sect->vaddr;
135  s->perm = strstr(s->name, "TEXT") ? 5 : 4;
136  s->is_segment = false;
137  return s;
138 }
#define NULL
Definition: cris-opc.c:27
static RzSocket * s
Definition: rtr.c:28
RZ_API char * rz_str_ndup(RZ_NULLABLE const char *ptr, int len)
Create new copy of string ptr limited to size len.
Definition: str.c:1006
#define RZ_NEW0(x)
Definition: rz_types.h:284

References rz_coresym_cache_element_section_t::name, NULL, rz_coresym_cache_element_section_t::paddr, RZ_NEW0, rz_str_ndup(), s, rz_coresym_cache_element_section_t::size, and rz_coresym_cache_element_section_t::vaddr.

Referenced by sections().

◆ bin_section_from_segment()

static RzBinSection* bin_section_from_segment ( RzCoreSymCacheElementSegment seg)
static

Definition at line 140 of file bin_symbols.c.

140  {
141  if (!seg->name) {
142  return NULL;
143  }
145  if (!s) {
146  return NULL;
147  }
148  s->name = rz_str_ndup(seg->name, 16);
149  s->size = seg->size;
150  s->vsize = seg->vsize;
151  s->paddr = seg->paddr;
152  s->vaddr = seg->vaddr;
153  s->perm = strstr(s->name, "TEXT") ? 5 : 4;
154  s->is_segment = true;
155  return s;
156 }

References rz_coresym_cache_element_segment_t::name, NULL, rz_coresym_cache_element_segment_t::paddr, RZ_NEW0, rz_str_ndup(), s, rz_coresym_cache_element_segment_t::size, rz_coresym_cache_element_segment_t::vaddr, and rz_coresym_cache_element_segment_t::vsize.

Referenced by sections().

◆ bin_symbol_from_symbol()

static RzBinSymbol* bin_symbol_from_symbol ( RzCoreSymCacheElement element,
RzCoreSymCacheElementSymbol s 
)
static

Definition at line 158 of file bin_symbols.c.

158  {
159  if (!s->name && !s->mangled_name) {
160  return NULL;
161  }
163  if (sym) {
164  if (s->name && s->mangled_name) {
165  sym->dname = strdup(s->name);
166  sym->name = strdup(s->mangled_name);
167  } else if (s->name) {
168  sym->name = strdup(s->name);
169  } else if (s->mangled_name) {
170  sym->name = s->mangled_name;
171  }
172  sym->paddr = s->paddr;
173  sym->vaddr = rz_coresym_cache_element_pa2va(element, s->paddr);
174  sym->size = s->size;
175  sym->type = RZ_BIN_TYPE_FUNC_STR;
176  sym->bind = "NONE";
177  }
178  return sym;
179 }
RZ_API ut64 rz_coresym_cache_element_pa2va(RzCoreSymCacheElement *element, ut64 pa)
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")
#define RZ_BIN_TYPE_FUNC_STR
Definition: rz_bin.h:119
const char * bind
Definition: rz_bin.h:681
const char * type
Definition: rz_bin.h:682
char * name
Definition: rz_bin.h:675
char * dname
Definition: rz_bin.h:676

References rz_bin_symbol_t::bind, rz_bin_symbol_t::dname, rz_bin_symbol_t::name, NULL, rz_bin_symbol_t::paddr, RZ_BIN_TYPE_FUNC_STR, rz_coresym_cache_element_pa2va(), RZ_NEW0, s, rz_bin_symbol_t::size, strdup(), rz_bin_symbol_t::type, and rz_bin_symbol_t::vaddr.

Referenced by symbols().

◆ check_buffer()

static bool check_buffer ( RzBuffer b)
static

Definition at line 338 of file bin_symbols.c.

338  {
339  ut8 buf[4];
340  rz_buf_read_at(b, 0, buf, sizeof(buf));
341  return !memcmp(buf, "\x02\xff\x01\xff", 4);
342 }
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 385 of file bin_symbols.c.

385  {
387 }
RZ_API void rz_coresym_cache_element_free(RzCoreSymCacheElement *element)
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_coresym_cache_element_free().

◆ header()

static void header ( RzBinFile bf)
static

Definition at line 389 of file bin_symbols.c.

389  {
390  rz_return_if_fail(bf && bf->o);
391 
392  RzCoreSymCacheElement *element = bf->o->bin_obj;
393  if (!element) {
394  return;
395  }
396 
397  RzBin *bin = bf->rbin;
398  PrintfCallback p = bin->cb_printf;
399  PJ *pj = pj_new();
400  if (!pj) {
401  return;
402  }
403 
404  pj_o(pj);
405  pj_kn(pj, "cs_version", element->hdr->version);
406  pj_kn(pj, "size", element->hdr->size);
407  if (element->file_name) {
408  pj_ks(pj, "name", element->file_name);
409  }
410  if (element->binary_version) {
411  pj_ks(pj, "version", element->binary_version);
412  }
413  char uuidstr[RZ_UUID_LENGTH];
414  rz_hex_bin2str(element->hdr->uuid, 16, uuidstr);
415  pj_ks(pj, "uuid", uuidstr);
416  pj_kn(pj, "segments", element->hdr->n_segments);
417  pj_kn(pj, "sections", element->hdr->n_sections);
418  pj_kn(pj, "symbols", element->hdr->n_symbols);
419  pj_kn(pj, "lined_symbols", element->hdr->n_lined_symbols);
420  pj_kn(pj, "line_info", element->hdr->n_line_info);
421  pj_end(pj);
422 
423  p("%s\n", pj_string(pj));
424  pj_free(pj);
425 }
#define RZ_UUID_LENGTH
Definition: bin_symbols.c:14
void * p
Definition: libc.cpp:67
#define rz_return_if_fail(expr)
Definition: rz_assert.h:100
RZ_API int rz_hex_bin2str(const ut8 *in, int len, char *out)
Definition: hex.c:382
RZ_API PJ * pj_new(void)
Definition: pj.c:25
RZ_API PJ * pj_end(PJ *j)
Definition: pj.c:87
RZ_API const char * pj_string(PJ *pj)
Definition: pj.c:57
RZ_API void pj_free(PJ *j)
Definition: pj.c:34
RZ_API PJ * pj_o(PJ *j)
Definition: pj.c:75
RZ_API PJ * pj_ks(PJ *j, const char *k, const char *v)
Definition: pj.c:170
RZ_API PJ * pj_kn(PJ *j, const char *k, ut64 n)
Definition: pj.c:121
int(* PrintfCallback)(const char *str,...) RZ_PRINTF_CHECK(1
Definition: rz_types.h:233
Definition: malloc.c:26
Definition: rz_pj.h:12
struct rz_bin_t * rbin
Definition: rz_bin.h:316
RzCoreSymCacheElementHdr * hdr

References rz_bin_object_t::bin_obj, rz_coresym_cache_element_t::binary_version, rz_coresym_cache_element_t::file_name, rz_coresym_cache_element_t::hdr, rz_coresym_cache_element_hdr_t::n_line_info, rz_coresym_cache_element_hdr_t::n_lined_symbols, rz_coresym_cache_element_hdr_t::n_sections, rz_coresym_cache_element_hdr_t::n_segments, rz_coresym_cache_element_hdr_t::n_symbols, rz_bin_file_t::o, p, pj_end(), pj_free(), pj_kn(), pj_ks(), pj_new(), pj_o(), pj_string(), rz_bin_file_t::rbin, rz_hex_bin2str(), rz_return_if_fail, RZ_UUID_LENGTH, rz_coresym_cache_element_hdr_t::size, rz_coresym_cache_element_hdr_t::uuid, and rz_coresym_cache_element_hdr_t::version.

◆ info()

static RzBinInfo* info ( RzBinFile bf)
static

Definition at line 320 of file bin_symbols.c.

320  {
321  SymbolsMetadata sm = parseMetadata(bf->buf, 0x40);
322  RzBinInfo *ret = RZ_NEW0(RzBinInfo);
323  if (!ret) {
324  return NULL;
325  }
326  ret->file = strdup(bf->file);
327  ret->bclass = strdup("symbols");
328  ret->os = strdup("unknown");
329  ret->arch = sm.arch ? strdup(sm.arch) : NULL;
330  ret->bits = sm.bits;
331  ret->type = strdup("Symbols file");
332  ret->subsystem = strdup("llvm");
333  ret->has_va = true;
334 
335  return ret;
336 }
static SymbolsMetadata parseMetadata(RzBuffer *buf, int off)
Definition: bin_symbols.c:87
char * file
Definition: rz_bin.h:299
RzBuffer * buf
Definition: rz_bin.h:303
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 * bclass
Definition: rz_bin.h:212
char * file
Definition: rz_bin.h:210
char * arch
Definition: rz_bin.h:214
const char * arch
Definition: bin_symbols.c:39

References symbols_metadata_t::arch, rz_bin_info_t::arch, rz_bin_info_t::bclass, symbols_metadata_t::bits, rz_bin_info_t::bits, rz_bin_file_t::buf, rz_bin_info_t::file, rz_bin_file_t::file, rz_bin_info_t::has_va, NULL, rz_bin_info_t::os, parseMetadata(), RZ_NEW0, strdup(), rz_bin_info_t::subsystem, and rz_bin_info_t::type.

Referenced by lines().

◆ lines()

static RzBinSourceLineInfo* lines ( RzBinFile bf)
static

Definition at line 427 of file bin_symbols.c.

427  {
428  rz_return_val_if_fail(bf && bf->o, NULL);
429  RzCoreSymCacheElement *element = bf->o->bin_obj;
430  if (!element || !element->hdr) {
431  return NULL;
432  }
435  if (element->lined_symbols) {
436  for (size_t i = 0; i < element->hdr->n_lined_symbols; i++) {
439  ut32 sz = lsym->sym.size;
440  rz_bin_source_line_info_builder_push_sample(&alice, addr, lsym->flc.line, lsym->flc.col, lsym->flc.file);
441  rz_bin_source_line_info_builder_push_sample(&alice, addr + (sz ? sz : 1), 0, 0, NULL);
442  }
443  }
444  if (element->line_info) {
445  for (size_t i = 0; i < element->hdr->n_line_info; i++) {
447  ut64 addr = rz_coresym_cache_element_pa2va(element, info->paddr);
448  ut32 sz = info->size;
449  rz_bin_source_line_info_builder_push_sample(&alice, addr, info->flc.line, info->flc.col, info->flc.file);
450  rz_bin_source_line_info_builder_push_sample(&alice, addr + (sz ? sz : 1), 0, 0, NULL);
451  }
452  }
454 }
lzma_index ** i
Definition: index.h:629
static RzBinInfo * info(RzBinFile *bf)
Definition: bin_symbols.c:320
RZ_API void rz_bin_source_line_info_builder_init(RzBinSourceLineInfoBuilder *builder)
Definition: dbginfo.c:9
RZ_API RzBinSourceLineInfo * rz_bin_source_line_info_builder_build_and_fini(RzBinSourceLineInfoBuilder *builder)
Definition: dbginfo.c:87
RZ_API void rz_bin_source_line_info_builder_push_sample(RzBinSourceLineInfoBuilder *builder, ut64 address, ut32 line, ut32 column, const char *file)
Push a new sample into the builder.
Definition: dbginfo.c:28
uint32_t ut32
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
RzCoreSymCacheElementLineInfo * line_info
RzCoreSymCacheElementLinedSymbol * lined_symbols
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58

References addr, rz_bin_object_t::bin_obj, rz_coresym_cache_element_flc_t::col, rz_coresym_cache_element_flc_t::file, rz_bin_info_t::file, rz_coresym_cache_element_lined_symbol_t::flc, rz_coresym_cache_element_t::hdr, i, info(), rz_coresym_cache_element_flc_t::line, rz_coresym_cache_element_t::line_info, rz_coresym_cache_element_t::lined_symbols, rz_coresym_cache_element_hdr_t::n_line_info, rz_coresym_cache_element_hdr_t::n_lined_symbols, NULL, rz_bin_file_t::o, rz_coresym_cache_element_symbol_t::paddr, rz_bin_source_line_info_builder_build_and_fini(), rz_bin_source_line_info_builder_init(), rz_bin_source_line_info_builder_push_sample(), rz_coresym_cache_element_pa2va(), rz_return_val_if_fail, rz_coresym_cache_element_symbol_t::size, rz_coresym_cache_element_lined_symbol_t::sym, and ut64().

Referenced by bin_dwarf(), handleHints(), main(), mcopy(), pager_all_matches(), pager_splitlines(), rz_cons_flush(), rz_cons_less_str(), rz_cons_visual_write(), rz_core_bin_apply_dwarf(), rz_core_bin_dwarf_print_line_units(), rz_core_cmd_lines(), rz_core_cmd_lines_rzshell(), rz_core_fortune_get_random(), rz_core_visual_define(), rz_file_slurp_line(), rz_file_slurp_lines(), rz_file_slurp_lines_from_bottom(), rz_file_slurp_random_line_count(), rz_str_scale(), spp_io(), and tokenize_lines().

◆ load_buffer()

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

Definition at line 252 of file bin_symbols.c.

252  {
253 #if 0
254  SYMBOLS HEADER
255 
256  0 MAGIC 02ff01ff
257  4 VERSION 1 (little endian)
258  8 ffffffff
259 16 002b0000 01000000 { 0x2b00, 0x0000 }
260 24 UUID 16 bytes
261 40 2621 d85b 2100 2000 0000 0000 0000 0000
262 56 ffff ffff ffff ff7f 0c00 0000 0900 0000
263 72 0400 0000 6800 0000 2f76 6172 2f66 6f6c .... 4, 104
264 184
265 0x000000b8 5f5f 5445 5854 0000 0000 0000 0000 0000 0000 0000 0000 0000 0080 0000 0000 0000 __TEXT..........................
266 0x000000d8 5f5f 4441 5441 0000 0000 0000 0000 0000 0080 0000 0000 0000 0040 0000 0000 0000 __DATA...................@......
267 0x000000f8 5f5f 4c4c 564d 0000 0000 0000 0000 0000 00c0 0000 0000 0000 0000 0100 0000 0000 __LLVM..........................
268 0x00000118 5f5f 4c49 4e4b 4544 4954 0000 0000 0000 00c0 0100 0000 0000 00c0 0000 0000 0000 __LINKEDIT......................
269 
270 #endif
271  // 0 - magic check, version ...
273  if (!sh.valid) {
274  eprintf("Invalid headers\n");
275  return false;
276  }
277  SymbolsMetadata sm = parseMetadata(buf, 0x40);
278  char *file_name = NULL;
279  if (sm.namelen) {
280  file_name = calloc(sm.namelen + 1, 1);
281  if (!file_name) {
282  return false;
283  }
284  if (rz_buf_read_at(buf, 0x50, (ut8 *)file_name, sm.namelen) != sm.namelen) {
285  return false;
286  }
287  }
288  RzCoreSymCacheElement *element = parseDragons(bf, buf, sm.addr + sm.size, sm.bits, file_name);
289  obj->bin_obj = element;
290  free(file_name);
291  return obj->bin_obj != NULL;
292 }
static ut8 bytes[32]
Definition: asm_arc.c:23
lsl lsr asr ror lsl lsr asr ror lsl lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror lsl lsr asr ror c0
static SymbolsHeader parseHeader(RzBuffer *buf)
Definition: bin_symbols.c:44
static RzCoreSymCacheElement * parseDragons(RzBinFile *bf, RzBuffer *buf, int off, int bits, RZ_OWN char *file_name)
Definition: bin_symbols.c:181
#define VERSION
Definition: config.h:54
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
void * calloc(size_t number, size_t size)
Definition: malloc.c:102
static const char file_name
Definition: sflib.h:131
#define eprintf(x, y...)
Definition: rlcc.c:7
@ HEADER
Definition: packet.c:10
#define d(i)
Definition: sha256.c:44

References symbols_metadata_t::addr, rz_bin_object_t::bin_obj, symbols_metadata_t::bits, bytes, c0, calloc(), d, eprintf, file_name, free(), HEADER, symbols_metadata_t::namelen, NULL, parseDragons(), parseHeader(), parseMetadata(), rz_buf_read_at(), symbols_metadata_t::size, symbols_header_t::valid, and VERSION.

◆ parseDragons()

static RzCoreSymCacheElement* parseDragons ( RzBinFile bf,
RzBuffer buf,
int  off,
int  bits,
RZ_OWN char *  file_name 
)
static

Definition at line 181 of file bin_symbols.c.

181  {
182  D eprintf("Dragons at 0x%x\n", off);
184  if (off >= size) {
185  return NULL;
186  }
187  size -= off;
188  if (!size) {
189  return NULL;
190  }
191  ut8 *b = malloc(size);
192  if (!b) {
193  return NULL;
194  }
195  int available = rz_buf_read_at(buf, off, b, size);
196  if (available != size) {
197  RZ_LOG_ERROR("bin: symbols: cannot read at 0x%08x\n", off);
198  return NULL;
199  }
200 #if 0
201  // after the list of sections, there's a bunch of unknown
202  // data, brobably dwords, and then the same section list again
203  // this function aims to parse it.
204  0x00000138 |1a2b b2a1 0300 0000 1a2b b2a1 e055 0000| .+.......+...U..
205  n_segments ----. .--- how many sections ?
206  0x00000148 |0100 0000 ca55 0000 0400 0000 1800 0000| .....U..........
207  .---- how many symbols? 0xc7
208  0x00000158 |c700 0000 0000 0000 0000 0000 0104 0000| ................
209  0x00000168 |250b e803 0000 0100 0000 0000 bd55 0000| %............U..
210  0x00000178 |91bb e903 e35a b42c 93a4 340a 8746 9489| .....Z.,..4..F..
211  0x00000188 |0cea 4c40 0c00 0000 0900 0000 0000 0000| ..L@............
212  0x00000198 |0000 0000 0000 0000 0000 0000 0000 0000| ................
213  0x000001a8 |0080 0000 0000 0000 5f5f 5445 5854 0000| ........__TEXT..
214  0x000001b8 |0000 0000 0000 0000 0080 0000 0000 0000| ................
215  0x000001c8 |0040 0000 0000 0000 5f5f 4441 5441 0000| .@......__DATA..
216  0x000001d8 |0000 0000 0000 0000 00c0 0000 0000 0000| ................
217  0x000001e8 |0000 0100 0000 0000 5f5f 4c4c 564d 0000| ........__LLVM..
218  0x000001f8 |0000 0000 0000 0000 00c0 0100 0000 0000| ................
219  0x00000208 |00c0 0000 0000 0000 5f5f 4c49 4e4b 4544| ........__LINKED
220  0x00000218 |4954 0000 0000 0000 0000 0000 d069 0000| IT...........i..
221 #endif
222  // eprintf ("Dragon's magic:\n");
223  int magicCombo = 0;
224  if (size > 3 && !memcmp("\x1a\x2b\xb2\xa1", b, 4)) { // 0x130 ?
225  magicCombo++;
226  }
227  if (size > 11 && !memcmp("\x1a\x2b\xb2\xa1", b + 8, 4)) {
228  magicCombo++;
229  }
230  if (magicCombo != 2) {
231  // hack for C22F7494
232  available = rz_buf_read_at(buf, off - 8, b, size);
233  if (available != size) {
234  RZ_LOG_WARN("bin: symbols: rz_buf_read_at failed\n");
235  return NULL;
236  }
237  if (size > 3 && !memcmp("\x1a\x2b\xb2\xa1", b, 4)) { // 0x130 ?
238  off -= 8;
239  } else {
240  RZ_LOG_ERROR("bin: symbols: 0x%08x parsing error: invalid magic retry\n", off);
241  }
242  }
243  D eprintf("0x%08x magic OK\n", off);
244  D {
245  const int e0ss = rz_read_le32(b + 12);
246  eprintf("0x%08x eoss 0x%x\n", off + 12, e0ss);
247  }
248  free(b);
249  return rz_coresym_cache_element_new(bf, buf, off + 16, bits, file_name);
250 }
static RzList * symbols(RzBinFile *bf)
Definition: bin_symbols.c:344
static RzList * sections(RzBinFile *bf)
Definition: bin_symbols.c:294
#define D
Definition: bin_symbols.c:13
int bits(struct state *s, int need)
Definition: blast.c:72
RZ_API RzCoreSymCacheElement * rz_coresym_cache_element_new(RzBinFile *bf, RzBuffer *buf, ut64 off, int bits, RZ_OWN char *file_name)
voidpf void uLong size
Definition: ioapi.h:138
void * malloc(size_t size)
Definition: malloc.c:123
int off
Definition: pal.c:13
RZ_API ut64 rz_buf_size(RZ_NONNULL RzBuffer *b)
Return the size of the buffer.
Definition: buf.c:1225
static ut32 rz_read_le32(const void *src)
Definition: rz_endian.h:239
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
#define RZ_LOG_ERROR(fmtstr,...)
Definition: rz_log.h:58
#define a(i)
Definition: sha256.c:41
#define L
Definition: zip_err_str.c:7

References a, b, bits(), c0, D, d, eprintf, file_name, free(), L, malloc(), NULL, off, rz_buf_read_at(), rz_buf_size(), rz_coresym_cache_element_new(), RZ_LOG_ERROR, RZ_LOG_WARN, rz_read_le32(), sections(), symbols(), and ut64().

Referenced by load_buffer().

◆ parseHeader()

static SymbolsHeader parseHeader ( RzBuffer buf)
static

Definition at line 44 of file bin_symbols.c.

44  {
45  ut8 b[64];
46  SymbolsHeader sh = { 0 };
47  (void)rz_buf_read_at(buf, 0, b, sizeof(b));
48  sh.magic = rz_read_le32(b);
49  sh.version = rz_read_le32(b + 4);
50  sh.valid = sh.magic == 0xff01ff02;
51  int i;
52  for (i = 0; i < 16; i++) {
53  sh.uuid[i] = b[24 + i];
54  }
55  sh.unk0 = rz_read_le16(b + 0x28);
56  sh.unk1 = rz_read_le16(b + 0x2c); // is slotsize + 1 :?
57  sh.slotsize = rz_read_le16(b + 0x2e);
58  sh.size = 0x40;
59  return sh;
60 }
static ut16 rz_read_le16(const void *src)
Definition: rz_endian.h:206

References b, i, symbols_header_t::magic, rz_buf_read_at(), rz_read_le16(), rz_read_le32(), symbols_header_t::size, symbols_header_t::slotsize, symbols_header_t::unk0, symbols_header_t::unk1, symbols_header_t::uuid, symbols_header_t::valid, and symbols_header_t::version.

Referenced by load_buffer().

◆ parseMetadata()

static SymbolsMetadata parseMetadata ( RzBuffer buf,
int  off 
)
static

Definition at line 87 of file bin_symbols.c.

87  {
88  SymbolsMetadata sm = { 0 };
89  ut8 b[0x100] = { 0 };
90  (void)rz_buf_read_at(buf, off, b, sizeof(b));
91  sm.addr = off;
92  sm.cputype = rz_read_le32(b);
93  sm.arch = typeString(sm.cputype, &sm.bits);
94  // eprintf ("0x%08x cputype 0x%x -> %s\n", 0x40, sm.cputype, typeString (sm.cputype));
95  // bits = (strstr (typeString (sm.cputype, &sm.bits), "64"))? 64: 32;
96  sm.subtype = rz_read_le32(b + 4);
97  sm.cpu = subtypeString(sm.subtype);
98  // eprintf ("0x%08x subtype 0x%x -> %s\n", 0x44, sm.subtype, subtypeString (sm.subtype));
99  sm.n_segments = rz_read_le32(b + 8);
100  // int count = rz_read_le32 (b + 0x48);
101  sm.namelen = rz_read_le32(b + 0xc);
102  // eprintf ("0x%08x count %d\n", 0x48, count);
103  // eprintf ("0x%08x strlen %d\n", 0x4c, sm.namelen);
104  // eprintf ("0x%08x filename %s\n", 0x50, b + 16);
105  int delta = 16;
106  // sm.segments = parseSegments (buf, off + sm.namelen + delta, sm.n_segments);
107  sm.size = (sm.n_segments * 32) + sm.namelen + delta;
108 
109  // hack to detect format
110  ut32 nm, nm2, nm3;
111  rz_buf_read_at(buf, off + sm.size, (ut8 *)&nm, sizeof(nm));
112  rz_buf_read_at(buf, off + sm.size + 4, (ut8 *)&nm2, sizeof(nm2));
113  rz_buf_read_at(buf, off + sm.size + 8, (ut8 *)&nm3, sizeof(nm3));
114  // eprintf ("0x%x next %x %x %x\n", off + sm.size, nm, nm2, nm3);
115  if (rz_read_le32(&nm3) != 0xa1b22b1a) {
116  sm.size -= 8;
117  // is64 = true;
118  }
119  return sm;
120 }
static const char * typeString(ut32 n, int *bits)
Definition: bin_symbols.c:62
static const char * subtypeString(int n)
Definition: bin_symbols.c:79
const char * cpu
Definition: bin_symbols.c:40
static st64 delta
Definition: vmenus.c:2425

References symbols_metadata_t::addr, symbols_metadata_t::arch, b, symbols_metadata_t::bits, symbols_metadata_t::cpu, symbols_metadata_t::cputype, delta, symbols_metadata_t::n_segments, symbols_metadata_t::namelen, off, rz_buf_read_at(), rz_read_le32(), symbols_metadata_t::size, symbols_metadata_t::subtype, subtypeString(), and typeString().

Referenced by info(), and load_buffer().

◆ sections()

static RzList* sections ( RzBinFile bf)
static

Definition at line 294 of file bin_symbols.c.

294  {
296  rz_return_val_if_fail(res && bf->o && bf->o->bin_obj, res);
297  RzCoreSymCacheElement *element = bf->o->bin_obj;
298  size_t i;
299  for (i = 0; i < element->hdr->n_segments; i++) {
300  RzCoreSymCacheElementSegment *seg = &element->segments[i];
302  if (s) {
303  rz_list_append(res, s);
304  }
305  }
306  for (i = 0; i < element->hdr->n_sections; i++) {
307  RzCoreSymCacheElementSection *sect = &element->sections[i];
309  if (s) {
310  rz_list_append(res, s);
311  }
312  }
313  return res;
314 }
RZ_API void rz_bin_section_free(RzBinSection *bs)
Definition: bin.c:1116
static RzBinSection * bin_section_from_segment(RzCoreSymCacheElementSegment *seg)
Definition: bin_symbols.c:140
static RzBinSection * bin_section_from_section(RzCoreSymCacheElementSection *sect)
Definition: bin_symbols.c:122
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
RzCoreSymCacheElementSegment * segments
RzCoreSymCacheElementSection * sections

References rz_bin_object_t::bin_obj, bin_section_from_section(), bin_section_from_segment(), rz_coresym_cache_element_t::hdr, i, rz_coresym_cache_element_hdr_t::n_sections, rz_coresym_cache_element_hdr_t::n_segments, rz_bin_file_t::o, rz_bin_section_free(), rz_list_append(), rz_list_newf(), rz_return_val_if_fail, s, rz_coresym_cache_element_t::sections, and rz_coresym_cache_element_t::segments.

Referenced by parseDragons().

◆ size()

static ut64 size ( RzBinFile bf)
static

Definition at line 381 of file bin_symbols.c.

381  {
382  return UT64_MAX;
383 }
#define UT64_MAX
Definition: rz_types_base.h:86

References UT64_MAX.

◆ subtypeString()

static const char* subtypeString ( int  n)
static

Definition at line 79 of file bin_symbols.c.

79  {
80  if (n == 9) { // CPU_SUBTYPE_ARM_V7) {
81  return "armv7";
82  }
83  return "?";
84 }
int n
Definition: mipsasm.c:19

References n.

Referenced by parseMetadata().

◆ symbols()

static RzList* symbols ( RzBinFile bf)
static

Definition at line 344 of file bin_symbols.c.

344  {
346  rz_return_val_if_fail(res && bf->o && bf->o->bin_obj, res);
347  RzCoreSymCacheElement *element = bf->o->bin_obj;
348  size_t i;
349  HtUU *hash = ht_uu_new0();
350  if (!hash) {
351  return res;
352  }
353  bool found = false;
354  for (i = 0; i < element->hdr->n_lined_symbols; i++) {
356  ht_uu_find(hash, sym->paddr, &found);
357  if (found) {
358  continue;
359  }
360  RzBinSymbol *s = bin_symbol_from_symbol(element, sym);
361  if (s) {
362  rz_list_append(res, s);
363  ht_uu_insert(hash, sym->paddr, 1);
364  }
365  }
366  for (i = 0; i < element->hdr->n_symbols; i++) {
367  RzCoreSymCacheElementSymbol *sym = &element->symbols[i];
368  ht_uu_find(hash, sym->paddr, &found);
369  if (found) {
370  continue;
371  }
372  RzBinSymbol *s = bin_symbol_from_symbol(element, sym);
373  if (s) {
374  rz_list_append(res, s);
375  }
376  }
377  ht_uu_free(hash);
378  return res;
379 }
RZ_API void rz_bin_symbol_free(RzBinSymbol *sym)
Definition: bin.c:175
static RzBinSymbol * bin_symbol_from_symbol(RzCoreSymCacheElement *element, RzCoreSymCacheElementSymbol *s)
Definition: bin_symbols.c:158
RZ_API const KEY_TYPE bool * found
Definition: ht_inc.h:130
RzCoreSymCacheElementSymbol * symbols

References rz_bin_object_t::bin_obj, bin_symbol_from_symbol(), found, rz_coresym_cache_element_t::hdr, i, rz_coresym_cache_element_t::lined_symbols, rz_coresym_cache_element_hdr_t::n_lined_symbols, rz_coresym_cache_element_hdr_t::n_symbols, rz_bin_file_t::o, rz_coresym_cache_element_symbol_t::paddr, rz_bin_symbol_free(), rz_list_append(), rz_list_newf(), rz_return_val_if_fail, s, and rz_coresym_cache_element_t::symbols.

Referenced by parseDragons().

◆ typeString()

static const char* typeString ( ut32  n,
int bits 
)
static

Definition at line 62 of file bin_symbols.c.

62  {
63  *bits = 32;
64  if (n == 12) { // CPU_SUBTYPE_ARM_V7) {
65  return "arm";
66  }
67  if (n == 0x0100000c) { // arm64
68  *bits = 64;
69  return "arm";
70  }
71  if (n == 0x0200000c) { // arm64-32
72  // TODO: must change bits
73  *bits = 64;
74  return "arm";
75  }
76  return "x86";
77 }

References bits(), and n.

Referenced by function_list_print_to_table(), parseMetadata(), print_stats(), rz_analysis_function_all_opcode_stat_handler(), rz_table_set_vcolumnsf(), rz_table_transpose(), and table_add_row_bool().

Variable Documentation

◆ rizin_plugin

RZ_API RzLibStruct rizin_plugin
Initial value:
= {
.type = RZ_LIB_TYPE_BIN,
}
RzBinPlugin rz_bin_plugin_symbols
Definition: bin_symbols.c:456
@ 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 474 of file bin_symbols.c.

◆ rz_bin_plugin_symbols

RzBinPlugin rz_bin_plugin_symbols
Initial value:
= {
.name = "symbols",
.desc = "Apple Symbols file",
.license = "MIT",
.load_buffer = &load_buffer,
.check_buffer = &check_buffer,
.symbols = &symbols,
.sections = &sections,
.size = &size,
.baddr = &baddr,
.info = &info,
.header = &header,
.destroy = &destroy,
.lines = lines
}
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_symbols.c:252
static ut64 size(RzBinFile *bf)
Definition: bin_symbols.c:381
static void header(RzBinFile *bf)
Definition: bin_symbols.c:389
static RzBinSourceLineInfo * lines(RzBinFile *bf)
Definition: bin_symbols.c:427
static void destroy(RzBinFile *bf)
Definition: bin_symbols.c:385
static bool check_buffer(RzBuffer *b)
Definition: bin_symbols.c:338
static ut64 baddr(RzBinFile *bf)
Definition: bin_symbols.c:316

Definition at line 456 of file bin_symbols.c.