Rizin
unix-like reverse engineering framework and cli tools
elf_info.c
Go to the documentation of this file.
1 // SPDX-FileCopyrightText: 2021 08A <08A@riseup.net>
2 // SPDX-FileCopyrightText: 2008-2020 nibble <nibble.ds@gmail.com>
3 // SPDX-FileCopyrightText: 2008-2020 pancake <pancake@nopcode.org>
4 // SPDX-FileCopyrightText: 2008-2020 alvaro_fe <alvaro.felipe91@gmail.com>
5 // SPDX-License-Identifier: LGPL-3.0-only
6 
7 #include "elf.h"
8 
9 #define EF_MIPS_ABI_O32 0x00001000 /* O32 ABI. */
10 #define EF_MIPS_ABI_O64 0x00002000 /* O32 extended for 64 bit. */
11 #define EF_MIPS_ABI 0x0000f000
12 
13 #define VERSYM_VERSION 0x7fff
14 
16  Elf_(Word) type;
17  int bits;
18 };
19 
21  const char *note_name;
22  const char *os_name;
23 };
24 
26  Elf_(Half) machine;
27  const char *name;
28 };
29 
31  unsigned char class;
32  const char *name;
33 };
34 
36  Elf_(Word) arch;
37  const char *name;
38 };
39 
41  Elf_(Half) arch;
42  const char *name;
43 };
44 
47  const char *name;
48 };
49 
50 static const struct mips_bits_translation mips_bits_translation_table[] = {
51  { EF_MIPS_ARCH_1, 32 },
52  { EF_MIPS_ARCH_2, 32 },
53  { EF_MIPS_ARCH_3, 32 },
54  { EF_MIPS_ARCH_4, 32 },
55  { EF_MIPS_ARCH_5, 32 },
56  { EF_MIPS_ARCH_32, 32 },
57  { EF_MIPS_ARCH_64, 64 },
58  { EF_MIPS_ARCH_32R2, 32 },
59  { EF_MIPS_ARCH_64R2, 64 }
60 };
61 
63  { ".note.openbsd.ident", "openbsd" },
64  { ".note.minix.ident", "minix" },
65  { ".note.netbsd.ident", "netbsd" },
66  { ".note.android.ident", "android" }
67 };
68 
70  { EM_NONE, "No machine" },
71  { EM_M32, "AT&T WE 32100" },
72  { EM_SPARC, "SUN SPARC" },
73  { EM_386, "Intel 80386" },
74  { EM_68K, "Motorola m68k family" },
75  { EM_88K, "Motorola m88k family" },
76  { EM_860, "Intel 80860" },
77  { EM_MIPS, "MIPS R3000" },
78  { EM_S370, "IBM System/370" },
79  { EM_MIPS_RS3_LE, "MIPS R3000 little-endian" },
80  { EM_PARISC, "HPPA" },
81  { EM_VPP500, "Fujitsu VPP500" },
82  { EM_SPARC32PLUS, "Sun's \"v8plus\"" },
83  { EM_960, "Intel 80960" },
84  { EM_PPC, "PowerPC" },
85  { EM_PPC64, "PowerPC 64-bit" },
86  { EM_S390, "IBM S390" },
87  { EM_V800, "NEC V800 series" },
88  { EM_FR20, "Fujitsu FR20" },
89  { EM_RH32, "TRW RH-32" },
90  { EM_RCE, "Motorola RCE" },
91  { EM_ARM, "ARM" },
92  { EM_BLACKFIN, "Analog Devices Blackfin" },
93  { EM_FAKE_ALPHA, "Digital Alpha" },
94  { EM_SH, "Hitachi SH" },
95  { EM_SPARCV9, "SPARC v9 64-bit" },
96  { EM_TRICORE, "Siemens Tricore" },
97  { EM_ARC, "Argonaut RISC Core" },
98  { EM_H8_300, "Hitachi H8/300" },
99  { EM_H8_300H, "Hitachi H8/300H" },
100  { EM_H8S, "Hitachi H8S" },
101  { EM_H8_500, "Hitachi H8/500" },
102  { EM_IA_64, "Intel Merced" },
103  { EM_MIPS_X, "Stanford MIPS-X" },
104  { EM_COLDFIRE, "Motorola Coldfire" },
105  { EM_68HC12, "Motorola M68HC12" },
106  { EM_MMA, "Fujitsu MMA Multimedia Accelerator" },
107  { EM_PCP, "Siemens PCP" },
108  { EM_NCPU, "Sony nCPU embeeded RISC" },
109  { EM_NDR1, "Denso NDR1 microprocessor" },
110  { EM_STARCORE, "Motorola Start*Core processor" },
111  { EM_ME16, "Toyota ME16 processor" },
112  { EM_ST100, "STMicroelectronic ST100 processor" },
113  { EM_TINYJ, "Advanced Logic Corp. Tinyj emb.fam" },
114  { EM_X86_64, "AMD x86-64 architecture" },
115  { EM_LANAI, "32bit LANAI architecture" },
116  { EM_PDSP, "Sony DSP Processor" },
117  { EM_PDP10, "Digital Equipment Corp. PDP-10" },
118  { EM_PDP11, "Digital Equipment Corp. PDP-11" },
119  { EM_FX66, "Siemens FX66 microcontroller" },
120  { EM_ST9PLUS, "STMicroelectronics ST9+ 8/16 mc" },
121  { EM_ST7, "STmicroelectronics ST7 8 bit mc" },
122  { EM_68HC16, "Motorola MC68HC16 microcontroller" },
123  { EM_68HC11, "Motorola MC68HC11 microcontroller" },
124  { EM_68HC08, "Motorola MC68HC08 microcontroller" },
125  { EM_68HC05, "Motorola MC68HC05 microcontroller" },
126  { EM_SVX, "Silicon Graphics SVx" },
127  { EM_ST19, "STMicroelectronics ST19 8 bit mc" },
128  { EM_VAX, "Digital VAX" },
129  { EM_CRIS, "Axis Communications 32-bit embedded processor" },
130  { EM_JAVELIN, "Infineon Technologies 32-bit embedded processor" },
131  { EM_FIREPATH, "Element 14 64-bit DSP Processor" },
132  { EM_ZSP, "LSI Logic 16-bit DSP Processor" },
133  { EM_MMIX, "Donald Knuth's educational 64-bit processor" },
134  { EM_HUANY, "Harvard University machine-independent object files" },
135  { EM_PRISM, "SiTera Prism" },
136  { EM_AVR, "Atmel AVR 8-bit microcontroller" },
137  { EM_FR30, "Fujitsu FR30" },
138  { EM_D10V, "Mitsubishi D10V" },
139  { EM_D30V, "Mitsubishi D30V" },
140  { EM_V850, "NEC v850" },
141  { EM_M32R, "Mitsubishi M32R" },
142  { EM_MN10300, "Matsushita MN10300" },
143  { EM_MN10200, "Matsushita MN10200" },
144  { EM_PJ, "picoJava" },
145  { EM_OPENRISC, "OpenRISC 32-bit embedded processor" },
146  { EM_ARC_A5, "ARC Cores Tangent-A5" },
147  { EM_XTENSA, "Tensilica Xtensa Architecture" },
148  { EM_AARCH64, "ARM aarch64" },
149  { EM_PROPELLER, "Parallax Propeller" },
150  { EM_MICROBLAZE, "Xilinx MicroBlaze" },
151  { EM_RISCV, "RISC V" },
152  { EM_VIDEOCORE3, "VideoCore III" },
153  { EM_VIDEOCORE4, "VideoCore IV" },
154  { EM_LATTICEMICO32, "RISC processor for Lattice FPGA architecture" },
155  { EM_SE_C17, "Seiko Epson C17 family" },
156  { EM_TI_C6000, "The Texas Instruments TMS320C6000 DSP family" },
157  { EM_TI_C2000, "The Texas Instruments TMS320C2000 DSP family" },
158  { EM_TI_C5500, "The Texas Instruments TMS320C55x DSP family" },
159  { EM_TI_ARP32, "Texas Instruments Application Specific RISC Processor, 32bit fetch" },
160  { EM_TI_PRU, "Texas Instruments Programmable Realtime Unit" },
161  { EM_MMDSP_PLUS, "STMicroelectronics 64bit VLIW Data Signal Processor" },
162  { EM_CYPRESS_M8C, "Cypress M8C microprocessor" },
163  { EM_R32C, "Renesas R32C series microprocessors" },
164  { EM_TRIMEDIA, "NXP Semiconductors TriMedia architecture family" },
165  { EM_QDSP6, "QUALCOMM DSP6 Processor" }, // Nonstandard
166  { EM_8051, "Intel 8051 and variants" },
167  { EM_STXP7X, "STMicroelectronics STxP7x family of configurable and extensible RISC processors" },
168  { EM_NDS32, "Andes Technology compact code size embedded RISC processor family" },
169  { EM_ECOG1, "Cyan Technology eCOG1X family" },
170  { EM_MAXQ30, "Dallas Semiconductor MAXQ30 Core Micro-controllers" },
171  { EM_XIMO16, "New Japan Radio (NJR) 16-bit DSP Processor" },
172  { EM_MANIK, "M2000 Reconfigurable RISC Microprocessor" },
173  { EM_CRAYNV2, "Cray Inc. NV2 vector architecture" },
174  { EM_RX, "Renesas RX family" },
175  { EM_METAG, "Imagination Technologies META processor architecture" },
176  { EM_MCST_ELBRUS, "MCST Elbrus general purpose hardware architecture" },
177  { EM_ECOG16, "Cyan Technology eCOG16 family" },
178  { EM_CR16, "National Semiconductor CompactRISC CR16 16-bit microprocessor" },
179  { EM_ETPU, "Freescale Extended Time Processing Unit" },
180  { EM_SLE9X, "Infineon Technologies SLE9X core" },
181  { EM_L10M, "Intel L10M" },
182  { EM_K10M, "Intel K10M" },
183  { EM_AVR32, "Atmel Corporation 32-bit microprocessor family" },
184  { EM_STM8, "STMicroeletronics STM8 8-bit microcontroller" },
185  { EM_TILE64, "Tilera TILE64 multicore architecture family" },
186  { EM_TILEPRO, "Tilera TILEPro multicore architecture family" },
187  { EM_CUDA, "NVIDIA CUDA architecture" },
188  { EM_TILEGX, "Tilera TILE-Gx multicore architecture family" },
189  { EM_CLOUDSHIELD, "CloudShield architecture family" },
190  { EM_COREA_1ST, "KIPO-KAIST Core-A 1st generation processor family" },
191  { EM_COREA_2ND, "KIPO-KAIST Core-A 2nd generation processor family" },
192  { EM_ARC_COMPACT2, "Synopsys ARCompact V2" },
193  { EM_OPEN8, "Open8 8-bit RISC soft processor core" },
194  { EM_RL78, "Renesas RL78 family" },
195  { EM_VIDEOCORE5, "Broadcom VideoCore V processor" },
196  { EM_78KOR, "Renesas 78KOR family" },
197  { EM_BA1, "Beyond BA1 CPU architecture" },
198  { EM_BA2_NON_STANDARD, "Beyond BA2 CPU architecture" },
199  { EM_BA2, "Beyond BA2 CPU architecture" },
200  { EM_XCORE, "XMOS xCORE processor family" },
201  { EM_MCHP_PIC, "Microchip 8-bit PIC(r) family" },
202  { EM_INTEL205, "Reserved by Intel" },
203  { EM_INTEL206, "Reserved by Intel" },
204  { EM_INTEL207, "Reserved by Intel" },
205  { EM_INTEL208, "Reserved by Intel" },
206  { EM_INTEL209, "Reserved by Intel" },
207  { EM_KM32, "KM211 KM32 32-bit processor" },
208  { EM_KMX32, "KM211 KMX32 32-bit processor" },
209  { EM_KMX16, "KM211 KMX16 16-bit processor" },
210  { EM_KMX8, "KM211 KMX8 8-bit processor" },
211  { EM_KVARC, "KM211 KVARC processor" },
212  { EM_CDP, "Paneve CDP architecture family" },
213  { EM_COGE, "Cognitive Smart Memory Processor" },
214  { EM_COOL, "Bluechip Systems CoolEngine" },
215  { EM_NORC, "Nanoradio Optimized RISC" },
216  { EM_CSR_KALIMBA, "CSR Kalimba architecture family" },
217  { EM_Z80, "Zilog Z80" },
218  { EM_VISIUM, "Controls and Data Services VISIUMcore processor" },
219  { EM_FT32, "FTDI Chip FT32 high performance 32-bit RISC architecture" },
220  { EM_MOXIE, "Moxie processor family" },
221  { EM_AMDGPU, "AMD GPU architecture" },
222  { EM_BPF, "Linux BPF" },
223  { EM_KVX, "Kalray VLIW core of the MPPA processor family" },
224 };
225 
226 static const struct class_translation class_translation_table[] = {
227  { ELFCLASSNONE, "none" },
228  { ELFCLASS32, "ELF32" },
229  { ELFCLASS64, "ELF64" }
230 };
231 
232 static const struct cpu_mips_translation cpu_mips_translation_table[] = {
233  { EF_MIPS_ARCH_1, "mips1" },
234  { EF_MIPS_ARCH_2, "mips2" },
235  { EF_MIPS_ARCH_3, "mips3" },
236  { EF_MIPS_ARCH_4, "mips4" },
237  { EF_MIPS_ARCH_5, "mips5" },
238  { EF_MIPS_ARCH_32, "mips32" },
239  { EF_MIPS_ARCH_64, "mips64" },
240  { EF_MIPS_ARCH_32R2, "mips32r2" },
241  { EF_MIPS_ARCH_64R2, "mips64r2" },
242 };
243 
244 static const struct arch_translation arch_translation_table[] = {
245  { EM_ARC, "arc" },
246  { EM_ARC_A5, "arc" },
247  { EM_AVR, "avr" },
248  { EM_BA2_NON_STANDARD, "ba2" },
249  { EM_BA2, "ba2" },
250  { EM_CRIS, "cris" },
251  { EM_68K, "m68k" },
252  { EM_MIPS, "mips" },
253  { EM_MIPS_RS3_LE, "mips" },
254  { EM_MIPS_X, "mips" },
255  { EM_MCST_ELBRUS, "elbrus" },
256  { EM_TRICORE, "tricore" },
257  { EM_RCE, "mcore" },
258  { EM_ARM, "arm" },
259  { EM_AARCH64, "arm" },
260  { EM_QDSP6, "hexagon" },
261  { EM_BLACKFIN, "blackfin" },
262  { EM_SPARC, "sparc" },
263  { EM_SPARC32PLUS, "sparc" },
264  { EM_SPARCV9, "sparc" },
265  { EM_PPC, "ppc" },
266  { EM_PPC64, "ppc" },
267  { EM_PARISC, "hppa" },
268  { EM_PROPELLER, "propeller" },
269  { EM_MICROBLAZE, "microblaze.gnu" },
270  { EM_RISCV, "riscv" },
271  { EM_VAX, "vax" },
272  { EM_XTENSA, "xtensa" },
273  { EM_LANAI, "lanai" },
274  { EM_VIDEOCORE3, "vc4" },
275  { EM_VIDEOCORE4, "vc4" },
276  { EM_MSP430, "msp430" },
277  { EM_SH, "sh" },
278  { EM_V800, "v850" },
279  { EM_V850, "v850" },
280  { EM_IA_64, "ia64" },
281  { EM_S390, "sysz" },
282  { EM_386, "x86" },
283  { EM_X86_64, "x86" },
284  { EM_NONE, "null" },
285  { EM_BPF, "bpf" },
286  { EM_KVX, "kvx" },
287 };
288 
289 static const struct ver_flags_translation ver_flags_translation_table[] = {
290  { VER_FLG_BASE, "BASE " },
291  { VER_FLG_BASE | VER_FLG_WEAK, "| " },
292  { VER_FLG_WEAK, "WEAK " },
293  { ~(VER_FLG_BASE | VER_FLG_WEAK), "| <unknown>" }
294 };
295 
297  RzBinElfSymbol *symbol;
299  if (symbol->name && !strcmp(symbol->name, "main")) {
300  if (symbol->paddr != UT64_MAX) {
301  return symbol->paddr;
302  }
303 
304  return symbol->vaddr;
305  }
306  }
307 
308  return UT64_MAX;
309 }
310 
312  /* linux64 pie main -- probably buggy in some cases */
313  int bo = 29; // Begin offset may vary depending on the entry prelude
314  // endbr64 - fedora bins have this
315  if (buf[0] == 0xf3 && buf[1] == 0x0f && buf[2] == 0x1e && buf[3] == 0xfa) {
316  // Change begin offset if binary starts with 'endbr64'
317  bo = 33;
318  // double xor for init and fini
319  if (!memcmp(buf + 19, "\x45\x31\xc0\x31\xc9", 5)) {
320  bo = 24;
321  }
322  }
323  if (buf[bo] == 0x48) {
324  ut8 ch = buf[bo + 1];
325  if (ch == 0x8d) { // lea rdi, qword [rip + MAINDELTA]
326  ut8 *p = buf + bo + 3;
327  st32 maindelta = (st32)rz_read_le32(p);
328  ut64 ventry = Elf_(rz_bin_elf_p2v)(bin, entry);
329  if (ventry == UT64_MAX) {
330  return UT64_MAX;
331  }
332  ut64 vmain = (ut64)(ventry + bo + maindelta) + 7;
333  return Elf_(rz_bin_elf_v2p)(bin, vmain);
334  } else if (ch == 0xc7) { // mov rdi, 0xADDR
335  ut8 *p = buf + bo + 3;
337  return Elf_(rz_bin_elf_v2p)(bin, addr);
338  }
339  }
340 
341  return UT64_MAX;
342 }
343 
345  // X86-NONPIE
346 #if RZ_BIN_ELF64
347  if (!memcmp(buf, "\x49\x89\xd9", 3) && buf[156] == 0xe8) { // openbsd
348  return rz_read_le32(buf + 157) + entry + 156 + 5;
349  }
350  if (!memcmp(buf + 29, "\x48\xc7\xc7", 3)) { // linux
351  ut64 addr = (ut64)rz_read_le32(buf + 29 + 3);
352  return Elf_(rz_bin_elf_v2p)(bin, addr);
353  }
354 #else
355  if (buf[23] == '\x68') {
356  ut64 addr = (ut64)rz_read_le32(buf + 23 + 1);
357  return Elf_(rz_bin_elf_v2p)(bin, addr);
358  }
359 #endif
360 
361  return UT64_MAX;
362 }
363 
365  // X86-PIE
366  if (buf[0x00] == 0x48 && buf[0x1e] == 0x8d && buf[0x11] == 0xe8) {
367  ut32 *pmain = (ut32 *)(buf + 0x30);
368  ut64 vmain = Elf_(rz_bin_elf_p2v)(bin, (ut64)*pmain);
369  ut64 ventry = Elf_(rz_bin_elf_p2v)(bin, entry);
370  if (vmain >> 16 == ventry >> 16) {
371  return vmain;
372  }
373  }
374  // X86-PIE
375  if (buf[0x1d] == 0x48 && buf[0x1e] == 0x8b) {
376  if (!memcmp(buf, "\x31\xed\x49\x89", 4)) { // linux
377  ut64 maddr, baddr;
378  ut8 n32s[sizeof(ut32)] = { 0 };
379  maddr = entry + 0x24 + rz_read_le32(buf + 0x20);
380  if (rz_buf_read_at(bin->b, maddr, n32s, sizeof(ut32)) == -1) {
381  return 0;
382  }
383  maddr = (ut64)rz_read_le32(&n32s[0]);
384  baddr = (bin->ehdr.e_entry >> 16) << 16;
387  }
388  maddr += baddr;
389  return maddr;
390  }
391  }
392 
393  return UT64_MAX;
394 }
395 
397  if (buf[0] != 0xe8 && memcmp(buf + 5, "\x50\xe8\x00\x00\x00\x00\xb8\x01\x00\x00\x00\x53", 12)) {
398  return UT64_MAX;
399  }
400 
401  size_t SIZEOF_CALL = 5;
402  ut64 rel_addr = (ut64)(buf[1] + (buf[2] << 8) + (buf[3] << 16) + (buf[4] << 24));
403  ut64 addr = Elf_(rz_bin_elf_p2v)(bin, entry + SIZEOF_CALL);
404  addr += rel_addr;
405  return Elf_(rz_bin_elf_v2p)(bin, addr);
406 }
407 
409  /* get .got, calculate offset of main symbol */
410  if (memcmp(buf, "\x21\x00\xe0\x03\x01\x00\x11\x04", 8)) {
411  return UT64_MAX;
412  }
413 
414  /*
415  assuming the startup code looks like
416  got = gp-0x7ff0
417  got[index__libc_start_main] ( got[index_main] );
418 
419  looking for the instruction generating the first argument to find main
420  lw a0, offset(gp)
421  */
422  ut64 got_addr;
423 
424  if (!Elf_(rz_bin_elf_get_dt_info)(bin, DT_PLTGOT, &got_addr)) {
425  return 0;
426  }
427 
428  ut64 got_offset = Elf_(rz_bin_elf_v2p)(bin, got_addr);
429  ut64 gp = got_offset + 0x7ff0;
430 
431  for (size_t i = 0; i < size; i += 4) {
432  const ut32 instr = rz_read_le32(buf + i);
433  if ((instr & 0xffff0000) == 0x8f840000) { // lw a0, offset(gp)
434  const short delta = instr & 0x0000ffff;
435  rz_buf_read_at(bin->b, /* got_entry_offset = */ gp + delta, buf, 4);
437  }
438  }
439 
440  return 0;
441 }
442 
444  size_t delta = 0;
445 
446  if (!memcmp(buf, "\xf0\x00\x0b\x4f\xf0\x00\x0e\x02\xbc\x6a\x46", 11)) {
447  /* newer versions of gcc use push/pop */
448  delta = 0x28;
449  } else if (!memcmp(buf, "\xf0\x00\x0b\x4f\xf0\x00\x0e\x5d\xf8\x04\x1b", 11)) {
450  /* older versions of gcc (4.5.x) use ldr/str */
451  delta = 0x30;
452  }
453 
454  if (delta) {
455  ut64 tmp = rz_read_le32(buf + delta - 1) & ~1;
456  ut64 pa = Elf_(rz_bin_elf_v2p)(bin, tmp);
457  if (pa < rz_buf_size(bin->b)) {
458  return pa;
459  }
460  }
461 
462  return UT64_MAX;
463 }
464 
466  if (!memcmp(buf, "\x00\xb0\xa0\xe3\x00\xe0\xa0\xe3", 8)) {
467  return Elf_(rz_bin_elf_v2p)(bin, rz_read_le32(buf + 0x34) & ~1);
468  }
469 
470  if (!memcmp(buf, "\x24\xc0\x9f\xe5\x00\xb0\xa0\xe3", 8)) {
471  return Elf_(rz_bin_elf_v2p)(bin, rz_read_le32(buf + 0x30) & ~1);
472  }
473 
474  return UT64_MAX;
475 }
476 
478  // ARM Glibc
481  } else {
483  }
484 
485  return UT64_MAX;
486 }
487 
489  if (buf[0x18 + 3] != 0x58 || buf[0x2f] != 0x00) {
490  return UT64_MAX;
491  }
492 
493  ut64 entry_vaddr = Elf_(rz_bin_elf_p2v)(bin, entry);
494  if (entry_vaddr == UT64_MAX) {
495  return UT64_MAX;
496  }
497 
498  ut64 main_addr = rz_read_le32(buf + 0x30);
499 
500  if (main_addr >> 16 == entry_vaddr >> 16) {
501  return Elf_(rz_bin_elf_v2p)(bin, main_addr);
502  }
503 
504  return UT64_MAX;
505 }
506 
509  if (section) {
510  return section->offset;
511  }
512 
514  if (section) {
515  return section->offset;
516  }
517 
519  if (section) {
520  return section->offset;
521  }
522 
523  return UT64_MAX;
524 }
525 
527  ut64 base = UT64_MAX;
528 
531  if (iter->data.p_type == PT_LOAD) {
532  base = RZ_MIN(base, iter->data.p_offset);
533  }
534  }
535 
536  return base == UT64_MAX ? 0 : base;
537 }
538 
540  ut64 base = UT64_MAX;
541 
544  if (iter->data.p_type == PT_LOAD) {
545  base = RZ_MIN(base, iter->data.p_vaddr);
546  }
547  }
548 
549  return base == UT64_MAX ? 0 : base;
550 }
551 
552 static bool elf_is_bind_now(ELFOBJ *bin) {
553  ut64 flags_1;
554 
556  return true;
557  }
558 
559  if (Elf_(rz_bin_elf_get_dt_info)(bin, DT_FLAGS_1, &flags_1)) {
560  return flags_1 & DF_1_NOW;
561  }
562 
563  return false;
564 }
565 
566 static bool elf_has_gnu_relro(ELFOBJ *bin) {
568  return false;
569  }
570 
572  return segment && segment->is_valid;
573 }
574 
575 static int get_bits_common(ELFOBJ *bin) {
576  switch (bin->ehdr.e_ident[EI_CLASS]) {
577  case ELFCLASS32:
578  return 32;
579  case ELFCLASS64:
580  return 64;
581  case ELFCLASSNONE:
582  default:
583  return 32;
584  }
585 }
586 
587 static bool has_thumb_symbol(ELFOBJ *bin) {
588  RzBinElfSymbol *symbol;
591  return true;
592  }
593  }
594 
595  return false;
596 }
597 
598 static int get_bits_mips_common(Elf_(Word) mips_type) {
599  for (size_t i = 0; i < RZ_ARRAY_SIZE(mips_bits_translation_table); i++) {
600  if (mips_type == mips_bits_translation_table[i].type) {
601  return mips_bits_translation_table[i].bits;
602  }
603  }
604 
605  return 32;
606 }
607 
608 static int is_playstation_hack(ELFOBJ *bin, Elf_(Word) mips_type) {
610 }
611 
612 static int get_bits_mips(ELFOBJ *bin) {
613  const Elf_(Word) mips_type = bin->ehdr.e_flags & EF_MIPS_ARCH;
614 
615  if (is_playstation_hack(bin, mips_type)) {
616  return 64;
617  }
618 
619  return get_bits_mips_common(mips_type);
620 }
621 
622 static bool arch_is_mips(ELFOBJ *bin) {
623  return Elf_(rz_bin_elf_has_segments)(bin) && bin->ehdr.e_machine == EM_MIPS;
624 }
625 
626 static bool arch_is_arcompact(ELFOBJ *bin) {
627  return bin->ehdr.e_machine == EM_ARC_A5;
628 }
629 
630 static char *read_elf_intrp(ELFOBJ *bin, ut64 addr, size_t size) {
631  char *str = malloc(size + 1);
632  if (!str) {
633  return NULL;
634  }
635 
636  if (rz_buf_read_at(bin->b, addr, (ut8 *)str, size) < 0) {
637  free(str);
638  return NULL;
639  }
640 
641  str[size] = 0;
642 
643  return str;
644 }
645 
646 static char *get_elf_intrp(ELFOBJ *bin, RzBinElfSegment *segment) {
647  ut64 addr = segment->data.p_offset;
648  size_t size = segment->data.p_filesz;
649 
650  if (!sdb_num_set(bin->kv, "elf_header.intrp_addr", addr, 0) ||
651  !sdb_num_set(bin->kv, "elf_header.intrp_size", size, 0)) {
652  return NULL;
653  }
654 
656  return NULL;
657  }
658 
659  char *str = read_elf_intrp(bin, addr, size);
660  if (!str) {
661  return NULL;
662  }
663 
664  if (!sdb_set(bin->kv, "elf_header.intrp", str, 0)) {
665  free(str);
666  return NULL;
667  }
668 
669  return str;
670 }
671 
672 static Elf_(Xword) get_dt_rpath(ELFOBJ *bin) {
673  ut64 path;
674 
676  return path;
677  }
678 
680  return path;
681  }
682 
683  return 0;
684 }
685 
686 static char *get_ver_flags(ut32 flags) {
687  char *result = NULL;
688 
689  if (!flags) {
690  return strdup("none");
691  }
692 
693  for (size_t i = 0; i < RZ_ARRAY_SIZE(ver_flags_translation_table); i++) {
695  result = rz_str_append(result, ver_flags_translation_table[i].name);
696  }
697  }
698 
699  return result;
700 }
701 
704 }
705 
707  if (section->type != SHT_NOTE) {
708  return NULL;
709  }
710 
711  for (size_t i = 0; i < RZ_ARRAY_SIZE(section_note_osabi_translation_table); i++) {
714  }
715  }
716 
717  return NULL;
718 }
719 
721  if (!bin->shstrtab) {
722  return NULL;
723  }
724 
727  if (!section->is_valid) {
728  continue;
729  }
730 
732  if (tmp) {
733  return tmp;
734  }
735  }
736 
737  return NULL;
738 }
739 
741  switch (bin->ehdr.e_ident[EI_OSABI]) {
742  case ELFOSABI_LINUX:
743  return strdup("linux");
744  case ELFOSABI_SOLARIS:
745  return strdup("solaris");
746  case ELFOSABI_FREEBSD:
747  return strdup("freebsd");
748  case ELFOSABI_HPUX:
749  return strdup("hpux");
750  }
751 
752  return NULL;
753 }
754 
755 static char *add_abi_info(ELFOBJ *bin, char *head_flag) {
756  char *str = Elf_(rz_bin_elf_get_abi)(bin);
757 
758  if (str) {
759  head_flag = rz_str_appendf(head_flag, " %s", str);
760  free(str);
761  }
762 
763  return head_flag;
764 }
765 
766 static char *add_cpu_info(ELFOBJ *bin, char *head_flag) {
767  char *str = Elf_(rz_bin_elf_get_cpu)(bin);
768 
769  if (str) {
770  head_flag = rz_str_append_owned(head_flag, str);
771  }
772 
773  return head_flag;
774 }
775 
776 static char *get_head_flag(ELFOBJ *bin) {
777  char *head_flag = NULL;
778 
779  head_flag = add_cpu_info(bin, head_flag);
780  head_flag = add_abi_info(bin, head_flag);
781 
782  return head_flag;
783 }
784 
786  return bin->ehdr.e_type >= ET_LOPROC && bin->ehdr.e_type <= ET_HIPROC;
787 }
788 
790  return bin->ehdr.e_type >= ET_LOOS && bin->ehdr.e_type <= ET_HIOS;
791 }
792 
794  switch (bin->ehdr.e_type) {
795  case ET_NONE:
796  return strdup("NONE (None)");
797  case ET_REL:
798  return strdup("REL (Relocatable file)");
799  case ET_EXEC:
800  return strdup("EXEC (Executable file)");
801  case ET_DYN:
802  return strdup("DYN (Shared object file)");
803  case ET_CORE:
804  return strdup("CORE (Core file)");
805  }
806 
807  return NULL;
808 }
809 
810 static char *get_cpu_mips(ELFOBJ *bin) {
811  Elf_(Word) mips_arch = bin->ehdr.e_flags & EF_MIPS_ARCH;
812 
813  for (size_t i = 0; i < RZ_ARRAY_SIZE(cpu_mips_translation_table); i++) {
814  if (mips_arch == cpu_mips_translation_table[i].arch) {
816  }
817  }
818 
819  return strdup(" Unknown mips ISA");
820 }
821 
822 static bool is_elf_class64(ELFOBJ *bin) {
823  return bin->ehdr.e_ident[EI_CLASS] == ELFCLASS64;
824 }
825 
826 static bool is_mips_o32(ELFOBJ *bin) {
827  if (bin->ehdr.e_ident[EI_CLASS] != ELFCLASS32) {
828  return false;
829  }
830 
831  if ((bin->ehdr.e_flags & EF_MIPS_ABI2) != 0) {
832  return false;
833  }
834 
835  if ((bin->ehdr.e_flags & EF_MIPS_ABI) != 0 && (bin->ehdr.e_flags & EF_MIPS_ABI) != EF_MIPS_ABI_O32) {
836  return false;
837  }
838 
839  return true;
840 }
841 
842 static bool is_mips_n32(ELFOBJ *bin) {
843  if (bin->ehdr.e_ident[EI_CLASS] != ELFCLASS32) {
844  return false;
845  }
846 
847  if ((bin->ehdr.e_flags & EF_MIPS_ABI2) == 0 || (bin->ehdr.e_flags & EF_MIPS_ABI) != 0) {
848  return false;
849  }
850 
851  return true;
852 }
853 
854 static char *get_abi_mips(ELFOBJ *bin) {
855  if (is_elf_class64(bin)) {
856  return strdup("n64");
857  }
858 
859  if (is_mips_n32(bin)) {
860  return strdup("n32");
861  }
862 
863  if (is_mips_o32(bin)) {
864  return strdup("o32");
865  }
866 
867  return NULL;
868 }
869 
879 
880  if (!Elf_(rz_bin_elf_has_dt_dynamic)(bin) || !bin->dynstr) {
881  return NULL;
882  }
883 
884  RzVector *dt_needed = Elf_(rz_bin_elf_get_dt_needed)(bin);
885  if (!dt_needed) {
886  return NULL;
887  }
888 
889  RzList *result = rz_list_newf(free);
890  if (!result) {
891  return NULL;
892  }
893 
894  ut64 *iter = NULL;
895  rz_vector_foreach(dt_needed, iter) {
896  char *tmp = Elf_(rz_bin_elf_strtab_get_dup)(bin->dynstr, *iter);
897  if (!tmp) {
898  rz_list_free(result);
899  return NULL;
900  }
901 
902  if (!rz_list_append(result, tmp)) {
903  rz_list_free(result);
904  return NULL;
905  }
906  }
907 
908  return result;
909 }
910 
911 static bool get_verdaux_entry_aux(ELFOBJ *bin, ut64 offset, Elf_(Verdaux) * entry) {
912  return Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vda_name) &&
913  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vda_next);
914 }
915 
916 static bool get_verdaux_entry(ELFOBJ *bin, ut64 offset, Elf_(Verdaux) * entry) {
918  RZ_LOG_WARN("Failed to read verdaux entry at 0x%" PFMT64x ".\n", offset);
919  return false;
920  }
921 
922  return true;
923 }
924 
925 static bool get_verdef_entry_aux(ELFOBJ *bin, ut64 offset, Elf_(Verdef) * entry) {
926  return Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vd_version) &&
927  Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vd_flags) &&
928  Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vd_ndx) &&
929  Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vd_cnt) &&
930  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vd_hash) &&
931  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vd_aux) &&
932  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vd_next);
933 }
934 
935 static bool get_verdef_entry(ELFOBJ *bin, ut64 offset, Elf_(Verdef) * entry) {
937  RZ_LOG_WARN("Failed to read verdef entry at 0x%" PFMT64x ".\n", offset);
938  return false;
939  }
940 
941  return true;
942 }
943 
944 static bool get_vernaux_entry_aux(ELFOBJ *bin, ut64 offset, Elf_(Vernaux) * entry) {
945  return Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vna_hash) &&
946  Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vna_flags) &&
947  Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vna_other) &&
948  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vna_name) &&
949  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vna_next);
950 }
951 
952 static bool get_vernaux_entry(ELFOBJ *bin, ut64 offset, Elf_(Vernaux) * entry) {
954  RZ_LOG_WARN("Failed to read vernaux entry at 0x%" PFMT64x ".\n", offset);
955  return false;
956  }
957 
958  return true;
959 }
960 static bool get_verneed_entry_aux(ELFOBJ *bin, ut64 offset, Elf_(Verneed) * entry) {
961  return Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vn_version) &&
962  Elf_(rz_bin_elf_read_half)(bin, &offset, &entry->vn_cnt) &&
963  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vn_file) &&
964  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vn_aux) &&
965  Elf_(rz_bin_elf_read_word)(bin, &offset, &entry->vn_next);
966 }
967 
968 static bool get_verneed_entry(ELFOBJ *bin, ut64 offset, Elf_(Verneed) * entry) {
970  RZ_LOG_WARN("Failed to read verneed entry at 0x%" PFMT64x ".\n", offset);
971  return false;
972  }
973 
974  return true;
975 }
976 
977 static bool get_versym_entry_sdb_from_verneed(ELFOBJ *bin, Sdb *sdb, const char *key, Elf_(Versym) versym) {
978  ut64 verneed_addr;
979  ut64 verneed_num;
980 
981  if (!Elf_(rz_bin_elf_get_dt_info)(bin, DT_VERNEED, &verneed_addr) || !Elf_(rz_bin_elf_get_dt_info)(bin, DT_VERNEEDNUM, &verneed_num)) {
982  return false;
983  }
984 
985  ut64 verneed_offset = Elf_(rz_bin_elf_v2p(bin, verneed_addr));
986 
987  if (verneed_offset == UT64_MAX) {
988  return false;
989  }
990 
991  ut64 verneed_entry_offset = verneed_offset;
992 
993  for (size_t i = 0; i < verneed_num; i++) {
994  Elf_(Verneed) verneed_entry;
995  if (!get_verneed_entry(bin, verneed_entry_offset, &verneed_entry)) {
996  return false;
997  }
998 
999  ut64 vernaux_entry_offset = verneed_entry_offset + verneed_entry.vn_aux;
1000 
1001  for (size_t j = 0; j < verneed_entry.vn_cnt; j++) {
1002  Elf_(Vernaux) vernaux_entry;
1003  if (!get_vernaux_entry(bin, vernaux_entry_offset, &vernaux_entry)) {
1004  return false;
1005  }
1006 
1007  if (vernaux_entry.vna_other != versym) {
1008  vernaux_entry_offset += vernaux_entry.vna_next;
1009  continue;
1010  }
1011 
1012  const char *tmp = Elf_(rz_bin_elf_strtab_get)(bin->dynstr, vernaux_entry.vna_name);
1013  if (!tmp) {
1014  return false;
1015  }
1016 
1017  char *value = rz_str_newf("%u (%s)", versym & VERSYM_VERSION, tmp);
1018  if (!value) {
1019  return false;
1020  }
1021 
1022  if (!sdb_set_owned(sdb, key, value, 0)) {
1023  return false;
1024  }
1025 
1026  return true;
1027  }
1028 
1029  verneed_entry_offset += verneed_entry.vn_next;
1030  }
1031 
1032  return false;
1033 }
1034 
1035 static bool get_versym_entry_sdb_from_verdef(ELFOBJ *bin, Sdb *sdb, const char *key, Elf_(Versym) versym) {
1036  ut64 verdef_addr;
1037  ut64 verdef_num;
1038 
1039  if (!Elf_(rz_bin_elf_get_dt_info)(bin, DT_VERDEF, &verdef_addr) || !Elf_(rz_bin_elf_get_dt_info)(bin, DT_VERDEFNUM, &verdef_num)) {
1040  return false;
1041  }
1042 
1043  ut64 verdef_offset = Elf_(rz_bin_elf_v2p(bin, verdef_addr));
1044 
1045  if (verdef_offset == UT64_MAX) {
1046  return false;
1047  }
1048 
1049  ut64 verdef_entry_offset = verdef_offset;
1050 
1051  for (size_t i = 0; i < verdef_num; i++) {
1052  Elf_(Verdef) verdef_entry;
1053  if (!get_verdef_entry(bin, verdef_entry_offset, &verdef_entry)) {
1054  return false;
1055  }
1056 
1057  if (!verdef_entry.vd_cnt || verdef_entry.vd_ndx != (versym & VERSYM_VERSION)) {
1058  verdef_entry_offset += verdef_entry.vd_next;
1059  continue;
1060  }
1061 
1062  ut64 verdaux_entry_offset = verdef_entry_offset + verdef_entry.vd_aux;
1063 
1064  Elf_(Verdaux) verdaux_entry;
1065  if (!get_verdaux_entry(bin, verdaux_entry_offset, &verdaux_entry)) {
1066  return false;
1067  }
1068 
1069  const char *tmp = Elf_(rz_bin_elf_strtab_get)(bin->dynstr, verdaux_entry.vda_name);
1070  if (!tmp) {
1071  return false;
1072  }
1073 
1074  char *value = rz_str_newf("%u (%s)", versym & VERSYM_VERSION, tmp);
1075  if (!value) {
1076  return false;
1077  }
1078 
1079  if (!sdb_set_owned(sdb, key, value, 0)) {
1080  return false;
1081  }
1082 
1083  return true;
1084  }
1085 
1086  return false;
1087 }
1088 
1090  ut64 versym_addr;
1091 
1092  if (!Elf_(rz_bin_elf_get_dt_info)(bin, DT_VERSYM, &versym_addr)) {
1093  return false;
1094  }
1095 
1096  ut64 versym_offset = Elf_(rz_bin_elf_v2p(bin, versym_addr));
1097 
1098  if (versym_offset == UT64_MAX) {
1099  return NULL;
1100  }
1101 
1102  ut64 number_of_symbols = Elf_(rz_bin_elf_get_number_of_dynamic_symbols)(bin);
1103  if (!number_of_symbols) {
1104  return NULL;
1105  }
1106 
1107  Sdb *sdb = sdb_new0();
1108  if (!sdb) {
1109  return NULL;
1110  }
1111 
1112  if (!sdb_num_set(sdb, "num_entries", number_of_symbols, 0) ||
1113  !sdb_num_set(sdb, "addr", versym_addr, 0) ||
1114  !sdb_num_set(sdb, "offset", versym_offset, 0)) {
1115  sdb_free(sdb);
1116  return NULL;
1117  }
1118 
1119  ut64 versym_entry_offset = versym_offset;
1120 
1121  for (size_t i = 0; i < number_of_symbols; i++) {
1122  char key[32];
1123  if (rz_strf(key, "entry%zu", i) == NULL) {
1124  sdb_free(sdb);
1125  return NULL;
1126  }
1127 
1128  Elf_(Versym) versym_entry;
1129  if (!Elf_(rz_bin_elf_read_versym)(bin, &versym_entry_offset, &versym_entry)) {
1130  sdb_free(sdb);
1131  return NULL;
1132  }
1133 
1134  switch (versym_entry) {
1135  case VER_NDX_LOCAL:
1136  if (!sdb_set(sdb, key, "0 (*local*)", 0)) {
1137  sdb_free(sdb);
1138  return NULL;
1139  }
1140  break;
1141  case VER_NDX_GLOBAL:
1142  if (!sdb_set(sdb, key, "1 (*global*)", 0)) {
1143  sdb_free(sdb);
1144  return NULL;
1145  }
1146  break;
1147  default:
1148  if (get_versym_entry_sdb_from_verneed(bin, sdb, key, versym_entry)) {
1149  break;
1150  }
1151 
1152  if (!get_versym_entry_sdb_from_verdef(bin, sdb, key, versym_entry)) {
1153  sdb_free(sdb);
1154  return NULL;
1155  }
1156  }
1157  }
1158 
1159  return sdb;
1160 }
1161 
1162 static Sdb *get_vernaux_entry_sdb(ELFOBJ *bin, Elf_(Vernaux) vernaux_entry, size_t index) {
1163  const char *tmp = Elf_(rz_bin_elf_strtab_get)(bin->dynstr, vernaux_entry.vna_name);
1164  if (!tmp) {
1165  return NULL;
1166  }
1167 
1168  Sdb *sdb_vernaux = sdb_new0();
1169  if (!sdb_vernaux) {
1170  return NULL;
1171  }
1172 
1173  char *flags = get_ver_flags(vernaux_entry.vna_flags);
1174  if (!sdb_set_owned(sdb_vernaux, "flags", flags, 0)) {
1175  sdb_free(sdb_vernaux);
1176  return NULL;
1177  }
1178 
1179  if (!sdb_num_set(sdb_vernaux, "idx", index, 0) ||
1180  !sdb_num_set(sdb_vernaux, "version", vernaux_entry.vna_other, 0) ||
1181  !sdb_set(sdb_vernaux, "name", tmp, 0)) {
1182  sdb_free(sdb_vernaux);
1183  return NULL;
1184  }
1185 
1186  return sdb_vernaux;
1187 }
1188 
1189 static Sdb *get_verneed_entry_sdb_aux(ELFOBJ *bin, Elf_(Verneed) verneed_entry, size_t index) {
1190  const char *tmp = Elf_(rz_bin_elf_strtab_get)(bin->dynstr, verneed_entry.vn_file);
1191  if (!tmp) {
1192  return NULL;
1193  }
1194 
1195  Sdb *sdb_version = sdb_new0();
1196  if (!sdb_version) {
1197  return NULL;
1198  }
1199 
1200  if (!sdb_num_set(sdb_version, "cnt", verneed_entry.vn_cnt, 0) ||
1201  !sdb_num_set(sdb_version, "idx", index, 0) ||
1202  !sdb_num_set(sdb_version, "vn_version", verneed_entry.vn_version, 0) ||
1203  !sdb_set(sdb_version, "file_name", tmp, 0)) {
1204  sdb_free(sdb_version);
1205  return NULL;
1206  }
1207 
1208  return sdb_version;
1209 }
1210 
1211 static Sdb *get_verneed_entry_sdb(ELFOBJ *bin, Elf_(Verneed) verneed_entry, size_t offset) {
1212  Sdb *sdb_version = get_verneed_entry_sdb_aux(bin, verneed_entry, offset);
1213  if (!sdb_version) {
1214  return NULL;
1215  }
1216 
1217  ut64 vernaux_entry_offset = offset + verneed_entry.vn_aux;
1218 
1219  for (size_t i = 0; i < verneed_entry.vn_cnt; i++) {
1220  Elf_(Vernaux) vernaux_entry;
1221  if (!get_vernaux_entry(bin, vernaux_entry_offset, &vernaux_entry)) {
1222  sdb_free(sdb_version);
1223  return NULL;
1224  }
1225 
1226  Sdb *sdb_vernaux = get_vernaux_entry_sdb(bin, vernaux_entry, vernaux_entry_offset);
1227  if (!sdb_vernaux) {
1228  sdb_free(sdb_version);
1229  return NULL;
1230  }
1231 
1232  char key[32];
1233  if (!sdb_ns_set(sdb_version, rz_strf(key, "vernaux%zu", i), sdb_vernaux)) {
1234  sdb_free(sdb_vernaux);
1235  sdb_free(sdb_version);
1236  return NULL;
1237  }
1238 
1239  sdb_free(sdb_vernaux);
1240 
1241  vernaux_entry_offset += vernaux_entry.vna_next;
1242  }
1243 
1244  return sdb_version;
1245 }
1246 
1248  ut64 verneed_addr;
1249  ut64 verneed_num;
1250 
1251  if (!Elf_(rz_bin_elf_get_dt_info)(bin, DT_VERNEED, &verneed_addr) || !Elf_(rz_bin_elf_get_dt_info)(bin, DT_VERNEEDNUM, &verneed_num)) {
1252  return NULL;
1253  }
1254 
1255  ut64 verneed_offset = Elf_(rz_bin_elf_v2p(bin, verneed_addr));
1256  if (verneed_offset == UT64_MAX) {
1257  RZ_LOG_WARN("Failed to convert verneed virtual address to physical address.\n");
1258  return NULL;
1259  }
1260 
1261  Sdb *sdb = sdb_new0();
1262  if (!sdb) {
1263  return NULL;
1264  }
1265 
1266  if (!sdb_num_set(sdb, "num_entries", verneed_num, 0) ||
1267  !sdb_num_set(sdb, "addr", verneed_addr, 0) ||
1268  !sdb_num_set(sdb, "offset", verneed_offset, 0)) {
1269  sdb_free(sdb);
1270  return NULL;
1271  }
1272 
1273  for (size_t i = 0; i < verneed_num; i++) {
1274  Elf_(Verneed) verneed_entry;
1275  if (!get_verneed_entry(bin, verneed_offset, &verneed_entry)) {
1276  sdb_free(sdb);
1277  return NULL;
1278  }
1279 
1280  Sdb *sdb_version = get_verneed_entry_sdb(bin, verneed_entry, verneed_offset);
1281  if (!sdb_version) {
1282  sdb_free(sdb);
1283  return NULL;
1284  }
1285 
1286  char key[32];
1287  if (!sdb_ns_set(sdb, rz_strf(key, "version%zu", i), sdb_version)) {
1288  sdb_free(sdb_version);
1289  sdb_free(sdb);
1290  return NULL;
1291  }
1292 
1293  sdb_free(sdb_version);
1294 
1295  verneed_offset += verneed_entry.vn_next;
1296  }
1297 
1298  return sdb;
1299 }
1300 
1302  rz_return_val_if_fail(bin, false);
1303 
1305  return NULL;
1306  }
1307 
1308  Sdb *res = sdb_new0();
1309  if (!res) {
1310  return NULL;
1311  }
1312 
1313  Sdb *sdb = get_gnu_verneed(bin);
1314  if (sdb && !sdb_ns_set(res, "verneed", sdb)) {
1315  sdb_free(res);
1316  sdb_free(sdb);
1317  return NULL;
1318  }
1319  sdb_free(sdb);
1320 
1321  sdb = get_gnu_versym(bin);
1322  if (sdb && !sdb_ns_set(res, "versym", sdb)) {
1323  sdb_free(res);
1324  sdb_free(sdb);
1325  return NULL;
1326  }
1327  sdb_free(sdb);
1328 
1329  return res;
1330 }
1331 
1341 
1343  if (!section) {
1344  return NULL;
1345  }
1346 
1348  ut64 size = RZ_MIN(section->size, 128);
1349  if (size < 1) {
1350  return NULL;
1351  }
1352 
1353  char *result = malloc(size + 1);
1354  if (!result) {
1355  return NULL;
1356  }
1357 
1358  if (rz_buf_read_at(bin->b, offset, (ut8 *)result, size) < 1) {
1359  free(result);
1360  return NULL;
1361  }
1362  result[size] = 0;
1363 
1364  size_t result_len = strlen(result);
1365  char *end = result + result_len;
1366 
1367  if (result_len != size && end[1]) {
1368  end[0] = ' ';
1369  }
1370 
1371  rz_str_trim(result);
1372  char *res = rz_str_escape(result);
1373 
1374  free(result);
1375  return res;
1376 }
1377 
1388 
1389  if (bin->ehdr.e_machine == EM_MIPS) {
1390  return get_abi_mips(bin);
1391  }
1392 
1393  return NULL;
1394 }
1395 
1405 
1406  for (size_t i = 0; i < RZ_ARRAY_SIZE(arch_translation_table); i++) {
1407  if (bin->ehdr.e_machine == arch_translation_table[i].arch) {
1409  }
1410  }
1411 
1412  return strdup("");
1413 }
1414 
1424 
1425  if (!Elf_(rz_bin_elf_has_segments)(bin)) {
1426  return NULL;
1427  }
1428 
1429  if (bin->ehdr.e_machine == EM_MIPS) {
1430  return get_cpu_mips(bin);
1431  }
1432 
1433  return NULL;
1434 }
1435 
1445 
1446  for (size_t i = 0; i < RZ_ARRAY_SIZE(class_translation_table); i++) {
1447  if (bin->ehdr.e_ident[EI_CLASS] == class_translation_table[i].class) {
1449  }
1450  }
1451 
1452  return rz_str_newf("<unknown: %x>", bin->ehdr.e_ident[EI_CLASS]);
1453 }
1454 
1464 
1465  char *result = get_file_type_basic(bin);
1466  if (result) {
1467  return result;
1468  }
1469 
1471  return rz_str_newf("Processor Specific: %x", bin->ehdr.e_type);
1472  }
1473 
1475  return rz_str_newf("OS Specific: %x", bin->ehdr.e_type);
1476  }
1477 
1478  return rz_str_newf("<unknown>: %x", bin->ehdr.e_type);
1479 }
1480 
1489 
1490  char *head_flag = get_head_flag(bin);
1491 
1492  if (RZ_STR_ISEMPTY(head_flag)) {
1493  free(head_flag);
1494  return strdup("unknown_flag");
1495  }
1496 
1497  return head_flag;
1498 }
1499 
1510 
1511  for (size_t i = 0; i < RZ_ARRAY_SIZE(machine_name_translation_table); i++) {
1512  if (bin->ehdr.e_machine == machine_name_translation_table[i].machine) {
1514  }
1515  }
1516 
1517  return rz_str_newf("<unknown>: 0x%x", bin->ehdr.e_machine);
1518 }
1519 
1529 
1531  if (name) {
1532  return name;
1533  }
1534 
1536  if (name) {
1537  return name;
1538  }
1539 
1540  return strdup("linux");
1541 }
1542 
1552 
1553  if (!Elf_(rz_bin_elf_has_segments)(bin) || !bin->dynstr || !has_dt_rpath_entry(bin)) {
1554  return NULL;
1555  }
1556 
1557  Elf_(Xword) val = get_dt_rpath(bin);
1558  return Elf_(rz_bin_elf_strtab_get_dup)(bin->dynstr, val);
1559 }
1560 
1570 
1571  if (!Elf_(rz_bin_elf_has_segments)(bin)) {
1572  return NULL;
1573  }
1574 
1576  if (!segment || !segment->is_valid) {
1577  return NULL;
1578  }
1579 
1580  return get_elf_intrp(bin, segment);
1581 }
1582 
1592  rz_return_val_if_fail(bin, false);
1593 
1594  if (!Elf_(rz_bin_elf_has_sections)(bin)) {
1595  return false;
1596  }
1597 
1600  if (section->type == SHT_SYMTAB) {
1601  return false;
1602  }
1603  }
1604 
1605  return true;
1606 }
1607 
1616  rz_return_val_if_fail(bin, false);
1617 
1618  if (!Elf_(rz_bin_elf_has_segments)(bin)) {
1619  return false;
1620  }
1621 
1623  if (!segment || !segment->is_valid) {
1624  return false;
1625  }
1626 
1627  return !(segment->data.p_flags & PF_X);
1628 }
1629 
1638  return true;
1639 }
1640 
1649  rz_return_val_if_fail(bin, false);
1650 
1651  const Elf_(Half) type = bin->ehdr.e_type;
1652  return type == ET_EXEC || type == ET_DYN;
1653 }
1654 
1663  rz_return_val_if_fail(bin, false);
1664  return bin->ehdr.e_type == ET_REL;
1665 }
1666 
1675  rz_return_val_if_fail(bin, false);
1676 
1678  if (segment && segment->is_valid) {
1679  return false;
1680  }
1681 
1683  if (segment && segment->is_valid) {
1684  return false;
1685  }
1686 
1687  return true;
1688 }
1689 
1699 
1700  /* Hack for ARCompact */
1701  if (arch_is_arcompact(bin)) {
1702  return 16;
1703  }
1704 
1705  /* Hack for Ps2 */
1706  if (arch_is_mips(bin)) {
1707  return get_bits_mips(bin);
1708  }
1709 
1710  /* Hack for Thumb */
1713  return 16;
1714  }
1715 
1718  return 16;
1719  }
1720  }
1721 
1722  return get_bits_common(bin);
1723 }
1724 
1735 
1736  bool is_bind_now = elf_is_bind_now(bin);
1737  bool has_gnu_relro = elf_has_gnu_relro(bin);
1738 
1739  if (has_gnu_relro) {
1740  if (is_bind_now) {
1741  return RZ_BIN_ELF_FULL_RELRO;
1742  }
1743 
1744  return RZ_BIN_ELF_PART_RELRO;
1745  }
1746 
1747  return RZ_BIN_ELF_NO_RELRO;
1748 }
1749 
1758  rz_return_val_if_fail(bin, false);
1759 
1760  return bin->ehdr.e_ident[EI_DATA] == ELFDATA2MSB;
1761 }
1762 
1774 
1776  return 0x08000000;
1777  }
1778 
1780  return compute_baddr_from_phdr(bin);
1781  }
1782 
1783  return 0;
1784 }
1785 
1797 
1800  }
1801 
1802  return 0;
1803 }
1804 
1815 
1817  return UT64_MAX;
1818  }
1819 
1820  ut64 entry = bin->ehdr.e_entry;
1821  if (entry) {
1823  if (tmp == UT64_MAX) {
1824  return entry;
1825  }
1826 
1827  return tmp;
1828  }
1829 
1831 }
1832 
1842 
1843  ut64 addr;
1844 
1846  return 0;
1847  }
1848 
1850  return 0;
1851  }
1852 
1853  return Elf_(rz_bin_elf_v2p)(bin, addr);
1854 }
1855 
1865 
1866  ut64 addr;
1867 
1869  return 0;
1870  }
1871 
1873  return 0;
1874  }
1875 
1876  return Elf_(rz_bin_elf_v2p)(bin, addr);
1877 }
1878 
1888 
1889  ut8 buf[256] = { 0 };
1891  ut64 main_addr;
1892 
1893  if (entry == UT64_MAX || entry > bin->size || (entry + sizeof(buf)) > bin->size) {
1894  return UT64_MAX;
1895  }
1896 
1897  if (rz_buf_read_at(bin->b, entry, buf, sizeof(buf)) < 0) {
1898  return UT64_MAX;
1899  }
1900 
1901  main_addr = get_main_offset_arm64(bin, entry, buf);
1902  if (main_addr != UT64_MAX) {
1903  return main_addr;
1904  }
1905 
1906  main_addr = get_main_offset_arm_glibc(bin, entry, buf);
1907  if (main_addr != UT64_MAX) {
1908  return main_addr;
1909  }
1910 
1912  if (main_addr != UT64_MAX) {
1913  return main_addr;
1914  }
1915 
1916  main_addr = get_main_offset_x86_gcc(bin, entry, buf);
1917  if (main_addr != UT64_MAX) {
1918  return main_addr;
1919  }
1920 
1921  main_addr = get_main_offset_x86_pie(bin, entry, buf);
1922  if (main_addr != UT64_MAX) {
1923  return main_addr;
1924  }
1925 
1926  main_addr = get_main_offset_x86_non_pie(bin, entry, buf);
1927  if (main_addr != UT64_MAX) {
1928  return main_addr;
1929  }
1930 
1931  main_addr = get_main_offset_linux_64_pie(bin, entry, buf);
1932  if (main_addr != UT64_MAX) {
1933  return main_addr;
1934  }
1935 
1937 }
#define RZ_IPI
Definition: analysis_wasm.c:11
lzma_index ** i
Definition: index.h:629
ut16 val
Definition: armass64_const.h:6
static ut64 baddr(RzBinFile *bf)
Definition: bin_any.c:58
int bits(struct state *s, int need)
Definition: blast.c:72
static int value
Definition: cmd_api.c:93
#define NULL
Definition: cris-opc.c:27
cs_arch arch
Definition: cstool.c:13
static static fork const void static count static fd const char const char static newpath const char static path const char path
Definition: sflib.h:35
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 key
Definition: sflib.h:118
uint32_t ut32
ut64 Elf_() rz_bin_elf_p2v(RZ_NONNULL ELFOBJ *bin, ut64 paddr)
Convert a physical address to the virtual address.
Definition: elf.c:400
ut64 Elf_() rz_bin_elf_v2p(RZ_NONNULL ELFOBJ *bin, ut64 vaddr)
Convert a virtual address to the physical address.
Definition: elf.c:429
#define rz_bin_elf_foreach_segments(bin, segment)
Definition: elf.h:26
#define RZ_BIN_ELF_NO_RELRO
Definition: elf.h:20
#define rz_bin_elf_foreach_sections(bin, section)
Definition: elf.h:30
RzBinElfSegment
Definition: elf.h:131
#define rz_bin_elf_foreach_symbols(bin, symbol)
Definition: elf.h:46
#define RZ_BIN_ELF_FULL_RELRO
Definition: elf.h:22
bool Elf_() rz_bin_elf_has_dt_dynamic(RZ_NONNULL ELFOBJ *bin)
Definition: elf_dynamic.c:130
#define ELFOBJ
Definition: elf.h:24
bool Elf_() rz_bin_elf_is_arm_binary_supporting_thumb(RZ_NONNULL ELFOBJ *bin)
Definition: elf_arm.c:19
bool Elf_() rz_bin_elf_is_thumb_addr(ut64 addr)
Definition: elf_arm.c:24
bool Elf_() rz_bin_elf_read_word(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Word) *result)
Definition: elf_misc.c:62
RZ_BORROW RzBinElfSection *Elf_() rz_bin_elf_get_section_with_name(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL const char *name)
Definition: elf_sections.c:278
bool Elf_() rz_bin_elf_read_half(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Half) *result)
Definition: elf_misc.c:57
bool Elf_() rz_bin_elf_get_dt_info(RZ_NONNULL ELFOBJ *bin, ut64 key, RZ_OUT ut64 *info)
Definition: elf_dynamic.c:120
bool Elf_() rz_bin_elf_read_versym(RZ_NONNULL ELFOBJ *bin, RZ_NONNULL RZ_INOUT ut64 *offset, RZ_NONNULL RZ_OUT Elf_(Versym) *result)
Definition: elf_misc.c:105
RZ_BORROW RzVector *Elf_() rz_bin_elf_get_dt_needed(RZ_NONNULL ELFOBJ *bin)
Definition: elf_dynamic.c:88
#define RZ_BIN_ELF_PART_RELRO
Definition: elf.h:21
bool Elf_() rz_bin_elf_has_segments(RZ_NONNULL ELFOBJ *bin)
Definition: elf_segments.c:149
bool Elf_() rz_bin_elf_has_sections(RZ_NONNULL ELFOBJ *bin)
Definition: elf_sections.c:440
RZ_OWN char *Elf_() rz_bin_elf_strtab_get_dup(RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
Definition: elf_strtab.c:52
RZ_BORROW const char *Elf_() rz_bin_elf_strtab_get(RZ_NONNULL RzBinElfStrtab *strtab, ut64 index)
Definition: elf_strtab.c:8
RZ_BORROW RzBinElfSegment *Elf_() rz_bin_elf_get_segment_with_type(RZ_NONNULL ELFOBJ *bin, Elf_(Word) type)
Definition: elf_segments.c:120
static ut64 get_main_offset_arm_glibc(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:477
#define VERSYM_VERSION
Definition: elf_info.c:13
static bool file_type_is_processor_specific(ELFOBJ *bin)
Definition: elf_info.c:785
RZ_IPI RZ_OWN Sdb *Elf_() rz_bin_elf_get_symbols_info(RZ_NONNULL ELFOBJ *bin)
Definition: elf_info.c:1301
bool Elf_() rz_bin_elf_is_big_endian(RZ_NONNULL ELFOBJ *bin)
Check the binary endianness.
Definition: elf_info.c:1757
static bool get_verneed_entry_aux(ELFOBJ *bin, ut64 offset, Elf_(Verneed) *entry)
Definition: elf_info.c:960
static const struct arch_translation arch_translation_table[]
Definition: elf_info.c:244
static bool get_verneed_entry(ELFOBJ *bin, ut64 offset, Elf_(Verneed) *entry)
Definition: elf_info.c:968
static bool arch_is_mips(ELFOBJ *bin)
Definition: elf_info.c:622
static int get_bits_common(ELFOBJ *bin)
Definition: elf_info.c:575
bool Elf_() rz_bin_elf_is_static(RZ_NONNULL ELFOBJ *bin)
Check if the binary is statically-linked library.
Definition: elf_info.c:1674
bool Elf_() rz_bin_elf_is_stripped(RZ_NONNULL ELFOBJ *bin)
Check if the binary is stripped.
Definition: elf_info.c:1591
static ut64 get_main_offset_arm_glibc_thumb(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:443
static const struct mips_bits_translation mips_bits_translation_table[]
Definition: elf_info.c:50
static bool arch_is_arcompact(ELFOBJ *bin)
Definition: elf_info.c:626
RZ_OWN char *Elf_() rz_bin_elf_get_file_type(RZ_NONNULL ELFOBJ *bin)
Return a string representing the file type.
Definition: elf_info.c:1462
static Sdb * get_gnu_verneed(ELFOBJ *bin)
Definition: elf_info.c:1247
bool Elf_() rz_bin_elf_is_executable(RZ_NONNULL ELFOBJ *bin)
Check if the elf binary is executable.
Definition: elf_info.c:1648
static bool get_verdaux_entry_aux(ELFOBJ *bin, ut64 offset, Elf_(Verdaux) *entry)
Definition: elf_info.c:911
ut64 Elf_() rz_bin_elf_get_main_offset(RZ_NONNULL ELFOBJ *bin)
Compute the main offset of the binary.
Definition: elf_info.c:1886
static ut64 get_main_offset_x86_gcc(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:396
#define EF_MIPS_ABI_O32
Definition: elf_info.c:9
static bool file_type_is_os_specific(ELFOBJ *bin)
Definition: elf_info.c:789
static int get_bits_mips_common(Elf_(Word) mips_type)
Definition: elf_info.c:598
bool Elf_() rz_bin_elf_has_va(ELFOBJ *bin)
Check if the elf use virtual address.
Definition: elf_info.c:1637
RZ_OWN char *Elf_() rz_bin_elf_get_elf_class(RZ_NONNULL ELFOBJ *bin)
Return a string representing the elf class.
Definition: elf_info.c:1443
static Sdb * get_verneed_entry_sdb(ELFOBJ *bin, Elf_(Verneed) verneed_entry, size_t offset)
Definition: elf_info.c:1211
static bool get_verdef_entry(ELFOBJ *bin, ut64 offset, Elf_(Verdef) *entry)
Definition: elf_info.c:935
static bool is_mips_o32(ELFOBJ *bin)
Definition: elf_info.c:826
static ut64 get_main_offset_arm_glibc_non_thumb(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:465
static bool is_mips_n32(ELFOBJ *bin)
Definition: elf_info.c:842
static ut64 get_main_offset_arm64(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:488
static ut64 compute_baddr_from_phdr(ELFOBJ *bin)
Definition: elf_info.c:539
bool Elf_() rz_bin_elf_has_nx(RZ_NONNULL ELFOBJ *bin)
Check if the stack is not executable.
Definition: elf_info.c:1615
RZ_OWN char *Elf_() rz_bin_elf_get_intrp(RZ_NONNULL ELFOBJ *bin)
Get the program interpreter.
Definition: elf_info.c:1568
static char * get_abi_mips(ELFOBJ *bin)
Definition: elf_info.c:854
static const struct ver_flags_translation ver_flags_translation_table[]
Definition: elf_info.c:289
static bool get_versym_entry_sdb_from_verneed(ELFOBJ *bin, Sdb *sdb, const char *key, Elf_(Versym) versym)
Definition: elf_info.c:977
RZ_OWN char *Elf_() rz_bin_elf_get_abi(RZ_NONNULL ELFOBJ *bin)
Return a string representing the application binary interface.
Definition: elf_info.c:1386
static char * get_cpu_mips(ELFOBJ *bin)
Definition: elf_info.c:810
static char * get_osabi_name_from_ehdr(ELFOBJ *bin)
Definition: elf_info.c:740
static Sdb * get_vernaux_entry_sdb(ELFOBJ *bin, Elf_(Vernaux) vernaux_entry, size_t index)
Definition: elf_info.c:1162
static Sdb * get_gnu_versym(ELFOBJ *bin)
Definition: elf_info.c:1089
ut64 Elf_() rz_bin_elf_get_baddr(RZ_NONNULL ELFOBJ *bin)
Compute the base address of the binary.
Definition: elf_info.c:1772
static int get_bits_mips(ELFOBJ *bin)
Definition: elf_info.c:612
RZ_OWN char *Elf_() rz_bin_elf_get_machine_name(RZ_NONNULL ELFOBJ *bin)
Return a string representing the machine name.
Definition: elf_info.c:1508
RZ_OWN RzList *Elf_() rz_bin_elf_get_libs(RZ_NONNULL ELFOBJ *bin)
List all imported lib.
Definition: elf_info.c:877
static ut64 get_entry_offset_from_shdr(ELFOBJ *bin)
Definition: elf_info.c:507
static const struct machine_name_translation machine_name_translation_table[]
Definition: elf_info.c:69
static bool get_verdef_entry_aux(ELFOBJ *bin, ut64 offset, Elf_(Verdef) *entry)
Definition: elf_info.c:925
static bool has_thumb_symbol(ELFOBJ *bin)
Definition: elf_info.c:587
static char * get_head_flag(ELFOBJ *bin)
Definition: elf_info.c:776
static char * get_osabi_name_from_shdr(ELFOBJ *bin)
Definition: elf_info.c:720
static char * read_elf_intrp(ELFOBJ *bin, ut64 addr, size_t size)
Definition: elf_info.c:630
static char * get_elf_intrp(ELFOBJ *bin, RzBinElfSegment *segment)
Definition: elf_info.c:646
static ut64 get_main_offset_mips(ELFOBJ *bin, ut64 entry, ut8 *buf, size_t size)
Definition: elf_info.c:408
static const struct class_translation class_translation_table[]
Definition: elf_info.c:226
RZ_OWN char *Elf_() rz_bin_elf_get_rpath(RZ_NONNULL ELFOBJ *bin)
Get the rpath.
Definition: elf_info.c:1550
RZ_OWN char *Elf_() rz_bin_elf_get_arch(RZ_NONNULL ELFOBJ *bin)
Get the elf binary architecture.
Definition: elf_info.c:1403
static ut64 get_main_offset_x86_non_pie(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:344
static bool has_dt_rpath_entry(ELFOBJ *bin)
Definition: elf_info.c:702
static ut64 get_main_offset_from_symbol(ELFOBJ *bin)
Definition: elf_info.c:296
static bool get_verdaux_entry(ELFOBJ *bin, ut64 offset, Elf_(Verdaux) *entry)
Definition: elf_info.c:916
static ut64 compute_boffset_from_phdr(ELFOBJ *bin)
Definition: elf_info.c:526
static bool get_vernaux_entry_aux(ELFOBJ *bin, ut64 offset, Elf_(Vernaux) *entry)
Definition: elf_info.c:944
int Elf_() rz_bin_elf_get_bits(RZ_NONNULL ELFOBJ *bin)
Return the elf bits.
Definition: elf_info.c:1697
static bool is_elf_class64(ELFOBJ *bin)
Definition: elf_info.c:822
static bool elf_is_bind_now(ELFOBJ *bin)
Definition: elf_info.c:552
RZ_OWN char *Elf_() rz_bin_elf_get_head_flag(RZ_NONNULL ELFOBJ *bin)
Return the head flag.
Definition: elf_info.c:1487
bool Elf_() rz_bin_elf_is_relocatable(RZ_NONNULL ELFOBJ *bin)
Check if the elf binary is relocatable.
Definition: elf_info.c:1662
static const struct cpu_mips_translation cpu_mips_translation_table[]
Definition: elf_info.c:232
static bool get_versym_entry_sdb_from_verdef(ELFOBJ *bin, Sdb *sdb, const char *key, Elf_(Versym) versym)
Definition: elf_info.c:1035
RZ_OWN char *Elf_() rz_bin_elf_get_osabi_name(RZ_NONNULL ELFOBJ *bin)
Return the os application binary interface name.
Definition: elf_info.c:1527
ut64 Elf_() rz_bin_elf_get_init_offset(RZ_NONNULL ELFOBJ *bin)
Compute the init offset of the binary.
Definition: elf_info.c:1863
static char * add_abi_info(ELFOBJ *bin, char *head_flag)
Definition: elf_info.c:755
static char * add_cpu_info(ELFOBJ *bin, char *head_flag)
Definition: elf_info.c:766
static Sdb * get_verneed_entry_sdb_aux(ELFOBJ *bin, Elf_(Verneed) verneed_entry, size_t index)
Definition: elf_info.c:1189
static bool elf_has_gnu_relro(ELFOBJ *bin)
Definition: elf_info.c:566
ut64 Elf_() rz_bin_elf_get_entry_offset(RZ_NONNULL ELFOBJ *bin)
Get the entry offset.
Definition: elf_info.c:1813
ut64 Elf_() rz_bin_elf_get_boffset(RZ_NONNULL ELFOBJ *bin)
Compute the base offset of the binary.
Definition: elf_info.c:1795
int Elf_() rz_bin_elf_has_relro(RZ_NONNULL ELFOBJ *bin)
Analyse if the elf binary has relro or partial relro.
Definition: elf_info.c:1733
RZ_OWN char *Elf_() rz_bin_elf_get_cpu(RZ_NONNULL ELFOBJ *bin)
Return a string representing the cpu.
Definition: elf_info.c:1422
#define EF_MIPS_ABI
Definition: elf_info.c:11
static int is_playstation_hack(ELFOBJ *bin, Elf_(Word) mips_type)
Definition: elf_info.c:608
static Elf_(Xword)
Definition: elf_info.c:672
static char * get_file_type_basic(RZ_NONNULL ELFOBJ *bin)
Definition: elf_info.c:793
static bool get_vernaux_entry(ELFOBJ *bin, ut64 offset, Elf_(Vernaux) *entry)
Definition: elf_info.c:952
static ut64 get_main_offset_x86_pie(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:364
RZ_OWN char *Elf_() rz_bin_elf_get_compiler(RZ_NONNULL ELFOBJ *bin)
Get the compiler info from the .comment section.
Definition: elf_info.c:1339
static char * get_ver_flags(ut32 flags)
Definition: elf_info.c:686
static char * get_osabi_name_from_section_note(ELFOBJ *bin, RzBinElfSection *section)
Definition: elf_info.c:706
static ut64 get_main_offset_linux_64_pie(ELFOBJ *bin, ut64 entry, ut8 *buf)
Definition: elf_info.c:311
static const struct section_note_osabi_translation section_note_osabi_translation_table[]
Definition: elf_info.c:62
ut64 Elf_() rz_bin_elf_get_fini_offset(RZ_NONNULL ELFOBJ *bin)
Compute the fini offset of the binary.
Definition: elf_info.c:1840
#define EM_INTEL205
Definition: elf_specs.h:183
#define EM_ECOG16
Definition: elf_specs.h:155
#define EM_TI_C6000
Definition: elf_specs.h:134
#define EM_COOL
Definition: elf_specs.h:195
#define EM_CDP
Definition: elf_specs.h:193
#define EM_KMX8
Definition: elf_specs.h:191
#define EM_KMX32
Definition: elf_specs.h:189
#define EM_MICROBLAZE
Definition: elf_specs.h:166
#define EM_TILE64
Definition: elf_specs.h:164
#define EM_RL78
Definition: elf_specs.h:174
#define EM_AMDGPU
Definition: elf_specs.h:202
#define EM_TI_C5500
Definition: elf_specs.h:136
#define EM_MCST_ELBRUS
Definition: elf_specs.h:154
#define EM_SE_C17
Definition: elf_specs.h:133
#define EM_CUDA
Definition: elf_specs.h:167
#define EM_VIDEOCORE3
Definition: elf_specs.h:131
#define EM_MANIK
Definition: elf_specs.h:150
#define EM_INTEL208
Definition: elf_specs.h:186
#define EM_NDS32
Definition: elf_specs.h:146
#define EM_ETPU
Definition: elf_specs.h:157
#define EM_MAXQ30
Definition: elf_specs.h:148
#define EM_STXP7X
Definition: elf_specs.h:145
#define EM_MMDSP_PLUS
Definition: elf_specs.h:139
#define EM_FT32
Definition: elf_specs.h:200
#define EM_XIMO16
Definition: elf_specs.h:149
#define EM_TILEGX
Definition: elf_specs.h:168
#define EM_VIDEOCORE4
Definition: elf_specs.h:92
#define EM_KVARC
Definition: elf_specs.h:192
#define EM_RX
Definition: elf_specs.h:152
#define EM_KVX
Definition: elf_specs.h:204
#define EM_INTEL207
Definition: elf_specs.h:185
#define EM_K10M
Definition: elf_specs.h:160
#define EM_BA2
Definition: elf_specs.h:179
#define EM_STM8
Definition: elf_specs.h:163
#define EM_ARC_COMPACT2
Definition: elf_specs.h:172
#define EM_ECOG1
Definition: elf_specs.h:147
#define EM_CYPRESS_M8C
Definition: elf_specs.h:140
#define EM_TI_C2000
Definition: elf_specs.h:135
#define EM_VISIUM
Definition: elf_specs.h:199
#define EM_COREA_2ND
Definition: elf_specs.h:171
#define EM_INTEL209
Definition: elf_specs.h:187
#define EM_L10M
Definition: elf_specs.h:159
#define EM_TI_ARP32
Definition: elf_specs.h:137
#define EM_Z80
Definition: elf_specs.h:198
#define EM_COREA_1ST
Definition: elf_specs.h:170
#define EM_KM32
Definition: elf_specs.h:188
#define EM_NORC
Definition: elf_specs.h:196
#define EM_LANAI
Definition: elf_specs.h:91
#define EM_MOXIE
Definition: elf_specs.h:201
#define EM_R32C
Definition: elf_specs.h:141
#define EM_TILEPRO
Definition: elf_specs.h:165
#define EM_OPEN8
Definition: elf_specs.h:173
#define EM_BA1
Definition: elf_specs.h:178
#define EM_CSR_KALIMBA
Definition: elf_specs.h:197
#define EM_LATTICEMICO32
Definition: elf_specs.h:132
#define EM_VIDEOCORE5
Definition: elf_specs.h:175
#define EM_AVR32
Definition: elf_specs.h:162
#define EM_XCORE
Definition: elf_specs.h:181
#define EM_CRAYNV2
Definition: elf_specs.h:151
#define EM_COGE
Definition: elf_specs.h:194
#define EM_8051
Definition: elf_specs.h:144
#define EM_AARCH64
Definition: elf_specs.h:161
#define EM_INTEL206
Definition: elf_specs.h:184
#define EM_KMX16
Definition: elf_specs.h:190
#define EM_TI_PRU
Definition: elf_specs.h:138
#define EM_78KOR
Definition: elf_specs.h:176
#define EM_MCHP_PIC
Definition: elf_specs.h:182
#define EM_TRIMEDIA
Definition: elf_specs.h:142
#define EM_SLE9X
Definition: elf_specs.h:158
#define EM_PROPELLER
Definition: elf_specs.h:90
#define EM_CLOUDSHIELD
Definition: elf_specs.h:169
#define EM_METAG
Definition: elf_specs.h:153
#define EF_MIPS_ARCH_2
Definition: glibc_elf.h:1594
#define EM_BPF
Definition: glibc_elf.h:363
#define EF_MIPS_ARCH_4
Definition: glibc_elf.h:1596
#define EF_MIPS_ARCH_32R2
Definition: glibc_elf.h:1600
#define EF_MIPS_ARCH_64
Definition: glibc_elf.h:1599
#define EM_PDSP
Definition: glibc_elf.h:225
#define EF_MIPS_ARCH_5
Definition: glibc_elf.h:1597
#define EF_MIPS_ARCH_32
Definition: glibc_elf.h:1598
#define EM_FAKE_ALPHA
Definition: glibc_elf.h:203
#define EF_MIPS_ARCH_1
Definition: glibc_elf.h:1593
#define EF_MIPS_ARCH_64R2
Definition: glibc_elf.h:1601
#define EM_VPP500
Definition: glibc_elf.h:190
#define EF_MIPS_ARCH_3
Definition: glibc_elf.h:1595
RZ_API void Ht_() free(HtName_(Ht) *ht)
Definition: ht_inc.c:130
voidpf void uLong size
Definition: ioapi.h:138
voidpf uLong offset
Definition: ioapi.h:144
voidpf void * buf
Definition: ioapi.h:138
uint8_t ut8
Definition: lh5801.h:11
void * p
Definition: libc.cpp:67
#define ELFDATA2MSB
Definition: common.h:59
#define EM_MIPS_X
Definition: common.h:140
#define DT_VERNEEDNUM
Definition: common.h:621
#define EM_PDP10
Definition: common.h:153
#define EM_ST7
Definition: common.h:157
#define EM_PDP11
Definition: common.h:154
#define PF_X
Definition: common.h:322
#define EM_M32
Definition: common.h:103
#define EM_RISCV
Definition: common.h:206
#define EM_RCE
Definition: common.h:128
#define DT_PLTGOT
Definition: common.h:540
#define PT_DYNAMIC
Definition: common.h:304
#define DT_VERNEED
Definition: common.h:620
#define EM_X86_64
Definition: common.h:151
#define EM_XTENSA
Definition: common.h:183
#define EM_D10V
Definition: common.h:174
#define EM_QDSP6
Definition: common.h:192
#define EM_68HC05
Definition: common.h:161
#define ET_REL
Definition: common.h:89
#define EM_NDR1
Definition: common.h:146
#define ET_CORE
Definition: common.h:92
#define DT_INIT
Definition: common.h:549
#define EM_MIPS
Definition: common.h:110
#define EM_MMIX
Definition: common.h:169
#define EM_H8_500
Definition: common.h:138
#define ET_NONE
Definition: common.h:88
#define DF_1_NOW
Definition: common.h:651
#define EM_68HC16
Definition: common.h:158
#define DT_RPATH
Definition: common.h:552
#define EM_SPARC
Definition: common.h:104
#define EM_CRIS
Definition: common.h:165
#define DT_VERSYM
Definition: common.h:624
#define EM_PPC64
Definition: common.h:120
#define EM_ARC
Definition: common.h:134
#define EM_PCP
Definition: common.h:144
#define ET_DYN
Definition: common.h:91
#define EM_MSP430
Definition: common.h:186
#define ET_LOOS
Definition: common.h:93
#define EM_S390
Definition: common.h:121
#define SHT_SYMTAB
Definition: common.h:333
#define VER_NDX_LOCAL
Definition: common.h:687
#define DT_BIND_NOW
Definition: common.h:561
#define EM_JAVELIN
Definition: common.h:166
#define EM_MMA
Definition: common.h:143
#define VER_FLG_WEAK
Definition: common.h:683
#define EM_NONE
Definition: common.h:102
#define EI_CLASS
Definition: common.h:51
#define EM_68HC12
Definition: common.h:142
#define ELFCLASS32
Definition: common.h:53
#define SHT_NOTE
Definition: common.h:338
#define EM_88K
Definition: common.h:107
#define EM_RH32
Definition: common.h:126
#define EM_NCPU
Definition: common.h:145
#define EM_386
Definition: common.h:105
#define ET_HIPROC
Definition: common.h:96
#define EI_DATA
Definition: common.h:56
#define EM_ST100
Definition: common.h:149
#define ELFOSABI_HPUX
Definition: common.h:65
#define EM_S370
Definition: common.h:111
#define EM_860
Definition: common.h:109
#define EM_H8_300
Definition: common.h:135
#define EM_PARISC
Definition: common.h:114
#define DT_FINI
Definition: common.h:550
#define EM_HUANY
Definition: common.h:170
#define PT_LOAD
Definition: common.h:303
#define EM_MIPS_RS3_LE
Definition: common.h:112
#define EI_OSABI
Definition: common.h:63
#define EM_ME16
Definition: common.h:148
#define EM_COLDFIRE
Definition: common.h:141
#define EM_D30V
Definition: common.h:175
#define ELFOSABI_SOLARIS
Definition: common.h:69
#define EM_FIREPATH
Definition: common.h:167
#define ET_LOPROC
Definition: common.h:95
#define ET_EXEC
Definition: common.h:90
#define EM_ST9PLUS
Definition: common.h:156
#define EM_BLACKFIN
Definition: common.h:187
#define EM_V850
Definition: common.h:176
#define ELFCLASS64
Definition: common.h:54
#define VER_NDX_GLOBAL
Definition: common.h:688
#define EM_STARCORE
Definition: common.h:147
#define EM_SH
Definition: common.h:131
#define EM_68HC11
Definition: common.h:159
#define ELFCLASSNONE
Definition: common.h:52
#define EM_OPENRISC
Definition: common.h:181
#define EM_H8S
Definition: common.h:137
#define PT_GNU_RELRO
Definition: common.h:318
#define DT_VERDEF
Definition: common.h:618
#define VER_FLG_BASE
Definition: common.h:682
#define EM_ARC_A5
Definition: common.h:182
#define EM_SVX
Definition: common.h:162
#define DT_FLAGS_1
Definition: common.h:617
#define DT_VERDEFNUM
Definition: common.h:619
#define PT_INTERP
Definition: common.h:305
#define EM_MN10300
Definition: common.h:178
#define EM_M32R
Definition: common.h:177
#define EM_TRICORE
Definition: common.h:133
#define EM_PRISM
Definition: common.h:171
#define ELFOSABI_FREEBSD
Definition: common.h:72
#define EM_68HC08
Definition: common.h:160
#define EM_ST19
Definition: common.h:163
#define EM_SPARC32PLUS
Definition: common.h:117
#define EM_68K
Definition: common.h:106
#define EM_H8_300H
Definition: common.h:136
#define EM_PPC
Definition: common.h:119
#define EM_FX66
Definition: common.h:155
#define ELFOSABI_LINUX
Definition: common.h:67
#define EM_CR16
Definition: common.h:190
#define EM_FR20
Definition: common.h:125
#define EM_SPARCV9
Definition: common.h:132
#define DT_RUNPATH
Definition: common.h:566
#define EM_IA_64
Definition: common.h:139
#define EM_MN10200
Definition: common.h:179
#define EM_ARM
Definition: common.h:129
#define EM_FR30
Definition: common.h:173
#define EM_V800
Definition: common.h:124
#define EM_VAX
Definition: common.h:164
#define EM_PJ
Definition: common.h:180
#define EM_TINYJ
Definition: common.h:150
#define EM_960
Definition: common.h:118
#define ET_HIOS
Definition: common.h:94
#define EM_ZSP
Definition: common.h:168
#define PT_GNU_STACK
Definition: common.h:317
#define EM_AVR
Definition: common.h:172
#define EM_BA2_NON_STANDARD
Definition: common.h:234
#define EF_MIPS_ABI2
#define EF_MIPS_ARCH
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
void * malloc(size_t size)
Definition: malloc.c:123
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 type
Definition: mipsasm.c:17
RZ_API int sdb_ns_set(Sdb *s, const char *name, Sdb *r)
Definition: ns.c:156
RZ_API int sdb_num_set(Sdb *s, const char *key, ut64 v, ut32 cas)
Definition: num.c:25
const char * name
Definition: op.c:541
#define rz_return_val_if_fail(expr, val)
Definition: rz_assert.h:108
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
static ut32 rz_read_le32(const void *src)
Definition: rz_endian.h:239
#define RZ_LOG_WARN(fmtstr,...)
Definition: rz_log.h:56
RZ_API char * rz_str_append_owned(char *ptr, char *string)
Definition: str.c:1050
RZ_API char * rz_str_appendf(char *ptr, const char *fmt,...) RZ_PRINTF_CHECK(2
RZ_API char * rz_str_newf(const char *fmt,...) RZ_PRINTF_CHECK(1
RZ_API char * rz_str_append(char *ptr, const char *string)
Definition: str.c:1063
RZ_API RZ_OWN char * rz_str_escape(RZ_NONNULL const char *buf)
Definition: str.c:1550
#define RZ_STR_ISEMPTY(x)
Definition: rz_str.h:67
RZ_API void rz_str_trim(RZ_NONNULL RZ_INOUT char *str)
Removes whitespace characters (space, tab, newline etc.) from the beginning and end of a string.
Definition: str_trim.c:190
#define rz_strf(buf,...)
Convenience macro for local temporary strings.
Definition: rz_str.h:59
#define RZ_OWN
Definition: rz_types.h:62
#define RZ_NONNULL
Definition: rz_types.h:64
#define RZ_ARRAY_SIZE(x)
Definition: rz_types.h:300
#define PFMT64x
Definition: rz_types.h:393
#define RZ_MIN(x, y)
#define UT64_MAX
Definition: rz_types_base.h:86
#define st32
Definition: rz_types_base.h:12
#define rz_vector_foreach(vec, it)
Definition: rz_vector.h:169
RZ_API int sdb_set_owned(Sdb *s, const char *key, char *val, ut32 cas)
Definition: sdb.c:607
RZ_API int sdb_set(Sdb *s, const char *key, const char *val, ut32 cas)
Definition: sdb.c:611
RZ_API Sdb * sdb_new0(void)
Definition: sdb.c:43
RZ_API bool sdb_free(Sdb *s)
Definition: sdb.c:206
static struct sockaddr static addrlen static backlog const void static flags void flags
Definition: sfsocketcall.h:123
Definition: malloc.c:26
const char * name
Definition: elf_info.c:32
unsigned char class
Definition: elf_info.c:31
Definition: zipcmp.c:77
Definition: z80asm.h:102
RZ_OWN char * name
Definition: elf.h:140
Definition: sdb.h:63
uint32_t offset
uint32_t size
const char * name
Definition: elf_info.c:47
static st64 delta
Definition: vmenus.c:2425
ut64(WINAPI *w32_GetEnabledXStateFeatures)()
static int addr
Definition: z80asm.c:58