elf/
to_str.rs

1//! Optional module for getting string representations of ELF constants
2use crate::abi;
3
4pub fn e_osabi_to_str(e_osabi: u8) -> Option<&'static str> {
5    match e_osabi {
6        abi::ELFOSABI_SYSV => Some("ELFOSABI_SYSV"),
7        abi::ELFOSABI_HPUX => Some("ELFOSABI_HPUX"),
8        abi::ELFOSABI_NETBSD => Some("ELFOSABI_NETBSD"),
9        abi::ELFOSABI_LINUX => Some("ELFOSABI_LINUX"),
10        abi::ELFOSABI_SOLARIS => Some("ELFOSABI_SOLARIS"),
11        abi::ELFOSABI_AIX => Some("ELFOSABI_AIX"),
12        abi::ELFOSABI_IRIX => Some("ELFOSABI_IRIX"),
13        abi::ELFOSABI_FREEBSD => Some("ELFOSABI_FREEBSD"),
14        abi::ELFOSABI_TRU64 => Some("ELFOSABI_TRU64"),
15        abi::ELFOSABI_MODESTO => Some("ELFOSABI_MODESTO"),
16        abi::ELFOSABI_OPENBSD => Some("ELFOSABI_OPENBSD"),
17        abi::ELFOSABI_OPENVMS => Some("ELFOSABI_OPENVMS"),
18        abi::ELFOSABI_NSK => Some("ELFOSABI_NSK"),
19        abi::ELFOSABI_AROS => Some("ELFOSABI_AROS"),
20        abi::ELFOSABI_FENIXOS => Some("ELFOSABI_FENIXOS"),
21        abi::ELFOSABI_CLOUDABI => Some("ELFOSABI_CLOUDABI"),
22        abi::ELFOSABI_OPENVOS => Some("ELFOSABI_OPENVOS"),
23        _ => None,
24    }
25}
26
27pub fn e_osabi_to_string(e_osabi: u8) -> String {
28    match e_osabi_to_str(e_osabi) {
29        Some(s) => s.to_string(),
30        None => format!("e_osabi({e_osabi:#x})"),
31    }
32}
33
34pub fn e_type_to_human_str(e_type: u16) -> Option<&'static str> {
35    match e_type {
36        abi::ET_NONE => Some("No file type"),
37        abi::ET_REL => Some("Relocatable file"),
38        abi::ET_EXEC => Some("Executable file"),
39        abi::ET_DYN => Some("Shared object file"),
40        abi::ET_CORE => Some("Core file"),
41        _ => None,
42    }
43}
44
45pub fn e_type_to_str(e_type: u16) -> Option<&'static str> {
46    match e_type {
47        abi::ET_NONE => Some("ET_NONE"),
48        abi::ET_REL => Some("ET_REL"),
49        abi::ET_EXEC => Some("ET_EXEC"),
50        abi::ET_DYN => Some("ET_DYN"),
51        abi::ET_CORE => Some("ET_CORE"),
52        _ => None,
53    }
54}
55
56pub fn e_type_to_string(e_type: u16) -> String {
57    match e_type_to_str(e_type) {
58        Some(s) => s.to_string(),
59        None => format!("e_type({e_type:#x})"),
60    }
61}
62
63pub fn e_machine_to_human_str(e_machine: u16) -> Option<&'static str> {
64    match e_machine {
65        abi::EM_NONE => Some("No machine"),
66        abi::EM_M32 => Some("AT&T WE 32100"),
67        abi::EM_SPARC => Some("SPARC"),
68        abi::EM_386 => Some("Intel 80386"),
69        abi::EM_68K => Some("Motorola 68000"),
70        abi::EM_88K => Some("Motorola 88000"),
71        abi::EM_IAMCU => Some("Intel MCU"),
72        abi::EM_860 => Some("Intel 80860"),
73        abi::EM_MIPS => Some("MIPS I Architecture"),
74        abi::EM_S370 => Some("IBM System/370 Processor"),
75        abi::EM_MIPS_RS3_LE => Some("MIPS RS3000 Little-endian"),
76        abi::EM_PARISC => Some("Hewlett-Packard PA-RISC"),
77        abi::EM_VPP500 => Some("Fujitsu VPP500"),
78        abi::EM_SPARC32PLUS => Some("Enhanced instruction set SPARC"),
79        abi::EM_960 => Some("Intel 80960"),
80        abi::EM_PPC => Some("PowerPC"),
81        abi::EM_PPC64 => Some("64-bit PowerPC"),
82        abi::EM_S390 => Some("IBM System/390 Processor"),
83        abi::EM_SPU => Some("IBM SPU/SPC"),
84        abi::EM_V800 => Some("NEC V800"),
85        abi::EM_FR20 => Some("Fujitsu FR20"),
86        abi::EM_RH32 => Some("TRW RH-32"),
87        abi::EM_RCE => Some("Motorola RCE"),
88        abi::EM_ARM => Some("ARM 32-bit architecture (AARCH32)"),
89        abi::EM_ALPHA => Some("Digital Alpha"),
90        abi::EM_SH => Some("Hitachi SH"),
91        abi::EM_SPARCV9 => Some("SPARC Version 9"),
92        abi::EM_TRICORE => Some("Siemens TriCore embedded processor"),
93        abi::EM_ARC => Some("Argonaut RISC Core, Argonaut Technologies Inc."),
94        abi::EM_H8_300 => Some("Hitachi H8/300"),
95        abi::EM_H8_300H => Some("Hitachi H8/300H"),
96        abi::EM_H8S => Some("Hitachi H8S"),
97        abi::EM_H8_500 => Some("Hitachi H8/500"),
98        abi::EM_IA_64 => Some("Intel IA-64 processor architecture"),
99        abi::EM_MIPS_X => Some("Stanford MIPS-X"),
100        abi::EM_COLDFIRE => Some("Motorola ColdFire"),
101        abi::EM_68HC12 => Some("Motorola M68HC12"),
102        abi::EM_MMA => Some("Fujitsu MMA Multimedia Accelerator"),
103        abi::EM_PCP => Some("Siemens PCP"),
104        abi::EM_NCPU => Some("Sony nCPU embedded RISC processor"),
105        abi::EM_NDR1 => Some("Denso NDR1 microprocessor"),
106        abi::EM_STARCORE => Some("Motorola Star*Core processor"),
107        abi::EM_ME16 => Some("Toyota ME16 processor"),
108        abi::EM_ST100 => Some("STMicroelectronics ST100 processor"),
109        abi::EM_TINYJ => Some("Advanced Logic Corp. TinyJ embedded processor family"),
110        abi::EM_X86_64 => Some("AMD x86-64 architecture"),
111        abi::EM_PDSP => Some("Sony DSP Processor"),
112        abi::EM_PDP10 => Some("Digital Equipment Corp. PDP-10"),
113        abi::EM_PDP11 => Some("Digital Equipment Corp. PDP-11"),
114        abi::EM_FX66 => Some("Siemens FX66 microcontroller"),
115        abi::EM_ST9PLUS => Some("STMicroelectronics ST9+ 8/16 bit microcontroller"),
116        abi::EM_ST7 => Some("STMicroelectronics ST7 8-bit microcontroller"),
117        abi::EM_68HC16 => Some("Motorola MC68HC16 Microcontroller"),
118        abi::EM_68HC11 => Some("Motorola MC68HC11 Microcontroller"),
119        abi::EM_68HC08 => Some("Motorola MC68HC08 Microcontroller"),
120        abi::EM_68HC05 => Some("Motorola MC68HC05 Microcontroller"),
121        abi::EM_SVX => Some("Silicon Graphics SVx"),
122        abi::EM_ST19 => Some("STMicroelectronics ST19 8-bit microcontroller"),
123        abi::EM_VAX => Some("Digital VAX"),
124        abi::EM_CRIS => Some("Axis Communications 32-bit embedded processor"),
125        abi::EM_JAVELIN => Some("Infineon Technologies 32-bit embedded processor"),
126        abi::EM_FIREPATH => Some("Element 14 64-bit DSP Processor"),
127        abi::EM_ZSP => Some("LSI Logic 16-bit DSP Processor"),
128        abi::EM_MMIX => Some("Donald Knuth's educational 64-bit processor"),
129        abi::EM_HUANY => Some("Harvard University machine-independent object files"),
130        abi::EM_PRISM => Some("SiTera Prism"),
131        abi::EM_AVR => Some("Atmel AVR 8-bit microcontroller"),
132        abi::EM_FR30 => Some("Fujitsu FR30"),
133        abi::EM_D10V => Some("Mitsubishi D10V"),
134        abi::EM_D30V => Some("Mitsubishi D30V"),
135        abi::EM_V850 => Some("NEC v850"),
136        abi::EM_M32R => Some("Mitsubishi M32R"),
137        abi::EM_MN10300 => Some("Matsushita MN10300"),
138        abi::EM_MN10200 => Some("Matsushita MN10200"),
139        abi::EM_PJ => Some("picoJava"),
140        abi::EM_OPENRISC => Some("OpenRISC 32-bit embedded processor"),
141        abi::EM_ARC_COMPACT => Some("ARC International ARCompact processor"),
142        abi::EM_XTENSA => Some("Tensilica Xtensa Architecture"),
143        abi::EM_VIDEOCORE => Some("Alphamosaic VideoCore processor"),
144        abi::EM_TMM_GPP => Some("Thompson Multimedia General Purpose Processor"),
145        abi::EM_NS32K => Some("National Semiconductor 32000 series"),
146        abi::EM_TPC => Some("Tenor Network TPC processor"),
147        abi::EM_SNP1K => Some("Trebia SNP 1000 processor"),
148        abi::EM_ST200 => Some("STMicroelectronics (www.st.com) ST200 microcontroller"),
149        abi::EM_IP2K => Some("Ubicom IP2xxx microcontroller family"),
150        abi::EM_MAX => Some("MAX Processor"),
151        abi::EM_CR => Some("National Semiconductor CompactRISC microprocessor"),
152        abi::EM_F2MC16 => Some("Fujitsu F2MC16"),
153        abi::EM_MSP430 => Some("Texas Instruments embedded microcontroller msp430"),
154        abi::EM_BLACKFIN => Some("Analog Devices Blackfin (DSP) processor"),
155        abi::EM_SE_C33 => Some("S1C33 Family of Seiko Epson processors"),
156        abi::EM_SEP => Some("Sharp embedded microprocessor"),
157        abi::EM_ARCA => Some("Arca RISC Microprocessor"),
158        abi::EM_UNICORE => {
159            Some("Microprocessor series from PKU-Unity Ltd. and MPRC of Peking University")
160        }
161        abi::EM_EXCESS => Some("eXcess: 16/32/64-bit configurable embedded CPU"),
162        abi::EM_DXP => Some("Icera Semiconductor Inc. Deep Execution Processor"),
163        abi::EM_ALTERA_NIOS2 => Some("Altera Nios II soft-core processor"),
164        abi::EM_CRX => Some("National Semiconductor CompactRISC CRX microprocessor"),
165        abi::EM_XGATE => Some("Motorola XGATE embedded processor"),
166        abi::EM_C166 => Some("Infineon C16x/XC16x processor"),
167        abi::EM_M16C => Some("Renesas M16C series microprocessors"),
168        abi::EM_DSPIC30F => Some("Microchip Technology dsPIC30F Digital Signal Controller"),
169        abi::EM_CE => Some("Freescale Communication Engine RISC core"),
170        abi::EM_M32C => Some("Renesas M32C series microprocessors"),
171        abi::EM_TSK3000 => Some("Altium TSK3000 core"),
172        abi::EM_RS08 => Some("Freescale RS08 embedded processor"),
173        abi::EM_SHARC => Some("Analog Devices SHARC family of 32-bit DSP processors"),
174        abi::EM_ECOG2 => Some("Cyan Technology eCOG2 microprocessor"),
175        abi::EM_SCORE7 => Some("Sunplus S+core7 RISC processor"),
176        abi::EM_DSP24 => Some("New Japan Radio (NJR) 24-bit DSP Processor"),
177        abi::EM_VIDEOCORE3 => Some("Broadcom VideoCore III processor"),
178        abi::EM_LATTICEMICO32 => Some("RISC processor for Lattice FPGA architecture"),
179        abi::EM_SE_C17 => Some("Seiko Epson C17 family"),
180        abi::EM_TI_C6000 => Some("The Texas Instruments TMS320C6000 DSP family"),
181        abi::EM_TI_C2000 => Some("The Texas Instruments TMS320C2000 DSP family"),
182        abi::EM_TI_C5500 => Some("The Texas Instruments TMS320C55x DSP family"),
183        abi::EM_TI_ARP32 => {
184            Some("Texas Instruments Application Specific RISC Processor, 32bit fetch")
185        }
186        abi::EM_TI_PRU => Some("Texas Instruments Programmable Realtime Unit"),
187        abi::EM_MMDSP_PLUS => Some("STMicroelectronics 64bit VLIW Data Signal Processor"),
188        abi::EM_CYPRESS_M8C => Some("Cypress M8C microprocessor"),
189        abi::EM_R32C => Some("Renesas R32C series microprocessors"),
190        abi::EM_TRIMEDIA => Some("NXP Semiconductors TriMedia architecture family"),
191        abi::EM_QDSP6 => Some("QUALCOMM DSP6 Processor"),
192        abi::EM_8051 => Some("Intel 8051 and variants"),
193        abi::EM_STXP7X => {
194            Some("STMicroelectronics STxP7x family of configurable and extensible RISC processors")
195        }
196        abi::EM_NDS32 => Some("Andes Technology compact code size embedded RISC processor family"),
197        abi::EM_ECOG1X => Some("Cyan Technology eCOG1X family"),
198        abi::EM_MAXQ30 => Some("Dallas Semiconductor MAXQ30 Core Micro-controllers"),
199        abi::EM_XIMO16 => Some("New Japan Radio (NJR) 16-bit DSP Processor"),
200        abi::EM_MANIK => Some("M2000 Reconfigurable RISC Microprocessor"),
201        abi::EM_CRAYNV2 => Some("Cray Inc. NV2 vector architecture"),
202        abi::EM_RX => Some("Renesas RX family"),
203        abi::EM_METAG => Some("Imagination Technologies META processor architecture"),
204        abi::EM_MCST_ELBRUS => Some("MCST Elbrus general purpose hardware architecture"),
205        abi::EM_ECOG16 => Some("Cyan Technology eCOG16 family"),
206        abi::EM_CR16 => Some("National Semiconductor CompactRISC CR16 16-bit microprocessor"),
207        abi::EM_ETPU => Some("Freescale Extended Time Processing Unit"),
208        abi::EM_SLE9X => Some("Infineon Technologies SLE9X core"),
209        abi::EM_L10M => Some("Intel L10M"),
210        abi::EM_K10M => Some("Intel K10M"),
211        abi::EM_AARCH64 => Some("ARM 64-bit architecture (AARCH64)"),
212        abi::EM_AVR32 => Some("Atmel Corporation 32-bit microprocessor family"),
213        abi::EM_STM8 => Some("STMicroeletronics STM8 8-bit microcontroller"),
214        abi::EM_TILE64 => Some("Tilera TILE64 multicore architecture family"),
215        abi::EM_TILEPRO => Some("Tilera TILEPro multicore architecture family"),
216        abi::EM_MICROBLAZE => Some("Xilinx MicroBlaze 32-bit RISC soft processor core"),
217        abi::EM_CUDA => Some("NVIDIA CUDA architecture"),
218        abi::EM_TILEGX => Some("Tilera TILE-Gx multicore architecture family"),
219        abi::EM_CLOUDSHIELD => Some("CloudShield architecture family"),
220        abi::EM_COREA_1ST => Some("KIPO-KAIST Core-A 1st generation processor family"),
221        abi::EM_COREA_2ND => Some("KIPO-KAIST Core-A 2nd generation processor family"),
222        abi::EM_ARC_COMPACT2 => Some("Synopsys ARCompact V2"),
223        abi::EM_OPEN8 => Some("Open8 8-bit RISC soft processor core"),
224        abi::EM_RL78 => Some("Renesas RL78 family"),
225        abi::EM_VIDEOCORE5 => Some("Broadcom VideoCore V processor"),
226        abi::EM_78KOR => Some("Renesas 78KOR family"),
227        abi::EM_56800EX => Some("Freescale 56800EX Digital Signal Controller (DSC)"),
228        abi::EM_BA1 => Some("Beyond BA1 CPU architecture"),
229        abi::EM_BA2 => Some("Beyond BA2 CPU architecture"),
230        abi::EM_XCORE => Some("XMOS xCORE processor family"),
231        abi::EM_MCHP_PIC => Some("Microchip 8-bit PIC(r) family"),
232        abi::EM_INTEL205 => Some("Reserved by Intel"),
233        abi::EM_INTEL206 => Some("Reserved by Intel"),
234        abi::EM_INTEL207 => Some("Reserved by Intel"),
235        abi::EM_INTEL208 => Some("Reserved by Intel"),
236        abi::EM_INTEL209 => Some("Reserved by Intel"),
237        abi::EM_KM32 => Some("KM211 KM32 32-bit processor"),
238        abi::EM_KMX32 => Some("KM211 KMX32 32-bit processor"),
239        abi::EM_KMX16 => Some("KM211 KMX16 16-bit processor"),
240        abi::EM_KMX8 => Some("KM211 KMX8 8-bit processor"),
241        abi::EM_KVARC => Some("KM211 KVARC processor"),
242        abi::EM_CDP => Some("Paneve CDP architecture family"),
243        abi::EM_COGE => Some("Cognitive Smart Memory Processor"),
244        abi::EM_COOL => Some("Bluechip Systems CoolEngine"),
245        abi::EM_NORC => Some("Nanoradio Optimized RISC"),
246        abi::EM_CSR_KALIMBA => Some("CSR Kalimba architecture family"),
247        abi::EM_Z80 => Some("Zilog Z80"),
248        abi::EM_VISIUM => Some("Controls and Data Services VISIUMcore processor"),
249        abi::EM_FT32 => Some("FTDI Chip FT32 high performance 32-bit RISC architecture"),
250        abi::EM_MOXIE => Some("Moxie processor family"),
251        abi::EM_AMDGPU => Some("AMD GPU architecture"),
252        abi::EM_RISCV => Some("RISC-V"),
253        abi::EM_BPF => Some("Linux BPF"),
254        _ => None,
255    }
256}
257
258pub fn e_machine_to_str(e_machine: u16) -> Option<&'static str> {
259    match e_machine {
260        abi::EM_NONE => Some("EM_NONE"),
261        abi::EM_M32 => Some("EM_M32"),
262        abi::EM_SPARC => Some("EM_SPARC"),
263        abi::EM_386 => Some("EM_386"),
264        abi::EM_68K => Some("EM_68K"),
265        abi::EM_88K => Some("EM_88K"),
266        abi::EM_IAMCU => Some("EM_IAMCU"),
267        abi::EM_860 => Some("EM_860"),
268        abi::EM_MIPS => Some("EM_MIPS"),
269        abi::EM_S370 => Some("EM_S370"),
270        abi::EM_MIPS_RS3_LE => Some("EM_MIPS_RS3_LE"),
271        abi::EM_PARISC => Some("EM_PARISC"),
272        abi::EM_VPP500 => Some("EM_VPP500"),
273        abi::EM_SPARC32PLUS => Some("EM_SPARC32PLUS"),
274        abi::EM_960 => Some("EM_960"),
275        abi::EM_PPC => Some("EM_PPC"),
276        abi::EM_PPC64 => Some("EM_PPC64"),
277        abi::EM_S390 => Some("EM_S390"),
278        abi::EM_SPU => Some("EM_SPU"),
279        abi::EM_V800 => Some("EM_V800"),
280        abi::EM_FR20 => Some("EM_FR20"),
281        abi::EM_RH32 => Some("EM_RH32"),
282        abi::EM_RCE => Some("EM_RCE"),
283        abi::EM_ARM => Some("EM_ARM"),
284        abi::EM_ALPHA => Some("EM_ALPHA"),
285        abi::EM_SH => Some("EM_SH"),
286        abi::EM_SPARCV9 => Some("EM_SPARCV9"),
287        abi::EM_TRICORE => Some("EM_TRICORE"),
288        abi::EM_ARC => Some("EM_ARC"),
289        abi::EM_H8_300 => Some("EM_H8_300"),
290        abi::EM_H8_300H => Some("EM_H8_300H"),
291        abi::EM_H8S => Some("EM_H8S"),
292        abi::EM_H8_500 => Some("EM_H8_500"),
293        abi::EM_IA_64 => Some("EM_IA_64"),
294        abi::EM_MIPS_X => Some("EM_MIPS_X"),
295        abi::EM_COLDFIRE => Some("EM_COLDFIRE"),
296        abi::EM_68HC12 => Some("EM_68HC12"),
297        abi::EM_MMA => Some("EM_MMA"),
298        abi::EM_PCP => Some("EM_PCP"),
299        abi::EM_NCPU => Some("EM_NCPU"),
300        abi::EM_NDR1 => Some("EM_NDR1"),
301        abi::EM_STARCORE => Some("EM_STARCORE"),
302        abi::EM_ME16 => Some("EM_ME16"),
303        abi::EM_ST100 => Some("EM_ST100"),
304        abi::EM_TINYJ => Some("EM_TINYJ"),
305        abi::EM_X86_64 => Some("EM_X86_64"),
306        abi::EM_PDSP => Some("EM_PDSP"),
307        abi::EM_PDP10 => Some("EM_PDP10"),
308        abi::EM_PDP11 => Some("EM_PDP11"),
309        abi::EM_FX66 => Some("EM_FX66"),
310        abi::EM_ST9PLUS => Some("EM_ST9PLUS"),
311        abi::EM_ST7 => Some("EM_ST7"),
312        abi::EM_68HC16 => Some("EM_68HC16"),
313        abi::EM_68HC11 => Some("EM_68HC11"),
314        abi::EM_68HC08 => Some("EM_68HC08"),
315        abi::EM_68HC05 => Some("EM_68HC05"),
316        abi::EM_SVX => Some("EM_SVX"),
317        abi::EM_ST19 => Some("EM_ST19"),
318        abi::EM_VAX => Some("EM_VAX"),
319        abi::EM_CRIS => Some("EM_CRIS"),
320        abi::EM_JAVELIN => Some("EM_JAVELIN"),
321        abi::EM_FIREPATH => Some("EM_FIREPATH"),
322        abi::EM_ZSP => Some("EM_ZSP"),
323        abi::EM_MMIX => Some("EM_MMIX"),
324        abi::EM_HUANY => Some("EM_HUANY"),
325        abi::EM_PRISM => Some("EM_PRISM"),
326        abi::EM_AVR => Some("EM_AVR"),
327        abi::EM_FR30 => Some("EM_FR30"),
328        abi::EM_D10V => Some("EM_D10V"),
329        abi::EM_D30V => Some("EM_D30V"),
330        abi::EM_V850 => Some("EM_V850"),
331        abi::EM_M32R => Some("EM_M32R"),
332        abi::EM_MN10300 => Some("EM_MN10300"),
333        abi::EM_MN10200 => Some("EM_MN10200"),
334        abi::EM_PJ => Some("EM_PJ"),
335        abi::EM_OPENRISC => Some("EM_OPENRISC"),
336        abi::EM_ARC_COMPACT => Some("EM_ARC_COMPACT"),
337        abi::EM_XTENSA => Some("EM_XTENSA"),
338        abi::EM_VIDEOCORE => Some("EM_VIDEOCORE"),
339        abi::EM_TMM_GPP => Some("EM_TMM_GPP"),
340        abi::EM_NS32K => Some("EM_NS32K"),
341        abi::EM_TPC => Some("EM_TPC"),
342        abi::EM_SNP1K => Some("EM_SNP1K"),
343        abi::EM_ST200 => Some("EM_ST200"),
344        abi::EM_IP2K => Some("EM_IP2K"),
345        abi::EM_MAX => Some("EM_MAX"),
346        abi::EM_CR => Some("EM_CR"),
347        abi::EM_F2MC16 => Some("EM_F2MC16"),
348        abi::EM_MSP430 => Some("EM_MSP430"),
349        abi::EM_BLACKFIN => Some("EM_BLACKFIN"),
350        abi::EM_SE_C33 => Some("EM_SE_C33"),
351        abi::EM_SEP => Some("EM_SEP"),
352        abi::EM_ARCA => Some("EM_ARCA"),
353        abi::EM_UNICORE => Some("EM_UNICORE"),
354        abi::EM_EXCESS => Some("EM_EXCESS"),
355        abi::EM_DXP => Some("EM_DXP"),
356        abi::EM_ALTERA_NIOS2 => Some("EM_ALTERA_NIOS2"),
357        abi::EM_CRX => Some("EM_CRX"),
358        abi::EM_XGATE => Some("EM_XGATE"),
359        abi::EM_C166 => Some("EM_C166"),
360        abi::EM_M16C => Some("EM_M16C"),
361        abi::EM_DSPIC30F => Some("EM_DSPIC30F"),
362        abi::EM_CE => Some("EM_CE"),
363        abi::EM_M32C => Some("EM_M32C"),
364        abi::EM_TSK3000 => Some("EM_TSK3000"),
365        abi::EM_RS08 => Some("EM_RS08"),
366        abi::EM_SHARC => Some("EM_SHARC"),
367        abi::EM_ECOG2 => Some("EM_ECOG2"),
368        abi::EM_SCORE7 => Some("EM_SCORE7"),
369        abi::EM_DSP24 => Some("EM_DSP24"),
370        abi::EM_VIDEOCORE3 => Some("EM_VIDEOCORE3"),
371        abi::EM_LATTICEMICO32 => Some("EM_LATTICEMICO32"),
372        abi::EM_SE_C17 => Some("EM_SE_C17"),
373        abi::EM_TI_C6000 => Some("EM_TI_C6000"),
374        abi::EM_TI_C2000 => Some("EM_TI_C2000"),
375        abi::EM_TI_C5500 => Some("EM_TI_C5500"),
376        abi::EM_TI_ARP32 => Some("EM_TI_ARP32"),
377        abi::EM_TI_PRU => Some("EM_TI_PRU"),
378        abi::EM_MMDSP_PLUS => Some("EM_MMDSP_PLUS"),
379        abi::EM_CYPRESS_M8C => Some("EM_CYPRESS_M8C"),
380        abi::EM_R32C => Some("EM_R32C"),
381        abi::EM_TRIMEDIA => Some("EM_TRIMEDIA"),
382        abi::EM_QDSP6 => Some("EM_QDSP6"),
383        abi::EM_8051 => Some("EM_8051"),
384        abi::EM_STXP7X => Some("EM_STXP7X"),
385        abi::EM_NDS32 => Some("EM_NDS32"),
386        abi::EM_ECOG1X => Some("EM_ECOG1X"),
387        abi::EM_MAXQ30 => Some("EM_MAXQ30"),
388        abi::EM_XIMO16 => Some("EM_XIMO16"),
389        abi::EM_MANIK => Some("EM_MANIK"),
390        abi::EM_CRAYNV2 => Some("EM_CRAYNV2"),
391        abi::EM_RX => Some("EM_RX"),
392        abi::EM_METAG => Some("EM_METAG"),
393        abi::EM_MCST_ELBRUS => Some("EM_MCST_ELBRUS"),
394        abi::EM_ECOG16 => Some("EM_ECOG16"),
395        abi::EM_CR16 => Some("EM_CR16"),
396        abi::EM_ETPU => Some("EM_ETPU"),
397        abi::EM_SLE9X => Some("EM_SLE9X"),
398        abi::EM_L10M => Some("EM_L10M"),
399        abi::EM_K10M => Some("EM_K10M"),
400        abi::EM_AARCH64 => Some("EM_AARCH64"),
401        abi::EM_AVR32 => Some("EM_AVR32"),
402        abi::EM_STM8 => Some("EM_STM8"),
403        abi::EM_TILE64 => Some("EM_TILE64"),
404        abi::EM_TILEPRO => Some("EM_TILEPRO"),
405        abi::EM_MICROBLAZE => Some("EM_MICROBLAZE"),
406        abi::EM_CUDA => Some("EM_CUDA"),
407        abi::EM_TILEGX => Some("EM_TILEGX"),
408        abi::EM_CLOUDSHIELD => Some("EM_CLOUDSHIELD"),
409        abi::EM_COREA_1ST => Some("EM_COREA_1ST"),
410        abi::EM_COREA_2ND => Some("EM_COREA_2ND"),
411        abi::EM_ARC_COMPACT2 => Some("EM_ARC_COMPACT2"),
412        abi::EM_OPEN8 => Some("EM_OPEN8"),
413        abi::EM_RL78 => Some("EM_RL78"),
414        abi::EM_VIDEOCORE5 => Some("EM_VIDEOCORE5"),
415        abi::EM_78KOR => Some("EM_78KOR"),
416        abi::EM_56800EX => Some("EM_56800EX"),
417        abi::EM_BA1 => Some("EM_BA1"),
418        abi::EM_BA2 => Some("EM_BA2"),
419        abi::EM_XCORE => Some("EM_XCORE"),
420        abi::EM_MCHP_PIC => Some("EM_MCHP_PIC"),
421        abi::EM_INTEL205 => Some("EM_INTEL205"),
422        abi::EM_INTEL206 => Some("EM_INTEL206"),
423        abi::EM_INTEL207 => Some("EM_INTEL207"),
424        abi::EM_INTEL208 => Some("EM_INTEL208"),
425        abi::EM_INTEL209 => Some("EM_INTEL209"),
426        abi::EM_KM32 => Some("EM_KM32"),
427        abi::EM_KMX32 => Some("EM_KMX32"),
428        abi::EM_KMX16 => Some("EM_KMX16"),
429        abi::EM_KMX8 => Some("EM_KMX8"),
430        abi::EM_KVARC => Some("EM_KVARC"),
431        abi::EM_CDP => Some("EM_CDP"),
432        abi::EM_COGE => Some("EM_COGE"),
433        abi::EM_COOL => Some("EM_COOL"),
434        abi::EM_NORC => Some("EM_NORC"),
435        abi::EM_CSR_KALIMBA => Some("EM_CSR_KALIMBA"),
436        abi::EM_Z80 => Some("EM_Z80"),
437        abi::EM_VISIUM => Some("EM_VISIUM"),
438        abi::EM_FT32 => Some("EM_FT32"),
439        abi::EM_MOXIE => Some("EM_MOXIE"),
440        abi::EM_AMDGPU => Some("EM_AMDGPU"),
441        abi::EM_RISCV => Some("RISC-V"),
442        abi::EM_BPF => Some("EM_BPF"),
443        _ => None,
444    }
445}
446
447pub fn e_machine_to_string(e_machine: u16) -> String {
448    match e_machine_to_str(e_machine) {
449        Some(s) => s.to_string(),
450        None => format!("e_machine({e_machine:#x})"),
451    }
452}
453
454pub fn sh_type_to_str(sh_type: u32) -> Option<&'static str> {
455    match sh_type {
456        abi::SHT_NULL => Some("SHT_NULL"),
457        abi::SHT_PROGBITS => Some("SHT_PROGBITS"),
458        abi::SHT_SYMTAB => Some("SHT_SYMTAB"),
459        abi::SHT_STRTAB => Some("SHT_STRTAB"),
460        abi::SHT_RELA => Some("SHT_RELA"),
461        abi::SHT_HASH => Some("SHT_HASH"),
462        abi::SHT_DYNAMIC => Some("SHT_DYNAMIC"),
463        abi::SHT_NOTE => Some("SHT_NOTE"),
464        abi::SHT_NOBITS => Some("SHT_NOBITS"),
465        abi::SHT_REL => Some("SHT_REL"),
466        abi::SHT_SHLIB => Some("SHT_SHLIB"),
467        abi::SHT_DYNSYM => Some("SHT_DYNSYM"),
468        abi::SHT_INIT_ARRAY => Some("SHT_INIT_ARRAY"),
469        abi::SHT_FINI_ARRAY => Some("SHT_FINI_ARRAY"),
470        abi::SHT_PREINIT_ARRAY => Some("SHT_PREINIT_ARRAY"),
471        abi::SHT_GROUP => Some("SHT_GROUP"),
472        abi::SHT_SYMTAB_SHNDX => Some("SHT_SYMTAB_SHNDX"),
473        abi::SHT_GNU_ATTRIBUTES => Some("SHT_GNU_ATTRIBUTES"),
474        abi::SHT_GNU_HASH => Some("SHT_GNU_HASH"),
475        abi::SHT_GNU_LIBLIST => Some("SHT_GNU_LIBLIST"),
476        abi::SHT_GNU_VERDEF => Some("SHT_GNU_VERDEF"),
477        abi::SHT_GNU_VERNEED => Some("SHT_GNU_VERNEED"),
478        abi::SHT_GNU_VERSYM => Some("SHT_GNU_VERSYM"),
479        _ => None,
480    }
481}
482
483pub fn sh_type_to_string(sh_type: u32) -> String {
484    match sh_type_to_str(sh_type) {
485        Some(s) => s.to_string(),
486        None => format!("sh_type({sh_type:#x})"),
487    }
488}
489
490pub fn p_flags_to_string(p_flags: u32) -> String {
491    match p_flags < 8 {
492        true => {
493            let r = if p_flags & abi::PF_R != 0 { "R" } else { " " };
494            let w = if p_flags & abi::PF_W != 0 { "W" } else { " " };
495            let x = if p_flags & abi::PF_X != 0 { "E" } else { " " };
496            format!("{r}{w}{x}")
497        }
498        false => format!("p_flags({p_flags:#x})"),
499    }
500}
501
502pub fn p_type_to_str(p_type: u32) -> Option<&'static str> {
503    match p_type {
504        abi::PT_NULL => Some("PT_NULL"),
505        abi::PT_LOAD => Some("PT_LOAD"),
506        abi::PT_DYNAMIC => Some("PT_DYNAMIC"),
507        abi::PT_INTERP => Some("PT_INTERP"),
508        abi::PT_NOTE => Some("PT_NOTE"),
509        abi::PT_SHLIB => Some("PT_SHLIB"),
510        abi::PT_PHDR => Some("PT_PHDR"),
511        abi::PT_TLS => Some("PT_TLS"),
512        abi::PT_GNU_EH_FRAME => Some("PT_GNU_EH_FRAME"),
513        abi::PT_GNU_STACK => Some("PT_GNU_STACK"),
514        abi::PT_GNU_RELRO => Some("PT_GNU_RELRO"),
515        abi::PT_GNU_PROPERTY => Some("PT_GNU_PROPERTY"),
516        _ => None,
517    }
518}
519
520pub fn p_type_to_string(p_type: u32) -> String {
521    match p_type_to_str(p_type) {
522        Some(s) => s.to_string(),
523        None => format!("p_type({p_type:#x})"),
524    }
525}
526
527pub fn st_symtype_to_str(st_symtype: u8) -> Option<&'static str> {
528    match st_symtype {
529        abi::STT_NOTYPE => Some("STT_NOTYPE"),
530        abi::STT_OBJECT => Some("STT_OBJECT"),
531        abi::STT_FUNC => Some("STT_FUNC"),
532        abi::STT_SECTION => Some("STT_SECTION"),
533        abi::STT_FILE => Some("STT_FILE"),
534        abi::STT_COMMON => Some("STT_COMMON"),
535        abi::STT_TLS => Some("STT_TLS"),
536        abi::STT_GNU_IFUNC => Some("STT_GNU_IFUNC"),
537        _ => None,
538    }
539}
540
541pub fn st_symtype_to_string(st_symtype: u8) -> String {
542    match st_symtype_to_str(st_symtype) {
543        Some(s) => s.to_string(),
544        None => format!("st_symtype({st_symtype:#x})"),
545    }
546}
547
548pub fn st_bind_to_str(st_bind: u8) -> Option<&'static str> {
549    match st_bind {
550        abi::STB_LOCAL => Some("STB_LOCAL"),
551        abi::STB_GLOBAL => Some("STB_GLOBAL"),
552        abi::STB_WEAK => Some("STB_WEAK"),
553        abi::STB_GNU_UNIQUE => Some("STB_GNU_UNIQUE"),
554        _ => None,
555    }
556}
557
558pub fn st_bind_to_string(st_bind: u8) -> String {
559    match st_bind_to_str(st_bind) {
560        Some(s) => s.to_string(),
561        None => format!("st_bind({st_bind:#x})"),
562    }
563}
564
565pub fn st_vis_to_str(st_vis: u8) -> Option<&'static str> {
566    match st_vis {
567        abi::STV_DEFAULT => Some("STV_DEFAULT"),
568        abi::STV_INTERNAL => Some("STV_INTERNAL"),
569        abi::STV_HIDDEN => Some("STV_HIDDEN"),
570        abi::STV_PROTECTED => Some("STV_PROTECTED"),
571        _ => None,
572    }
573}
574
575pub fn st_vis_to_string(st_vis: u8) -> String {
576    match st_vis_to_str(st_vis) {
577        Some(s) => s.to_string(),
578        None => format!("st_vis({st_vis:#x})"),
579    }
580}
581
582pub fn ch_type_to_str(ch_type: u32) -> Option<&'static str> {
583    match ch_type {
584        abi::ELFCOMPRESS_ZLIB => Some("ELFCOMPRESS_ZLIB"),
585        abi::ELFCOMPRESS_ZSTD => Some("ELFCOMPRESS_ZSTD "),
586        _ => None,
587    }
588}
589
590pub fn note_abi_tag_os_to_str(os: u32) -> Option<&'static str> {
591    match os {
592        abi::ELF_NOTE_GNU_ABI_TAG_OS_LINUX => Some("Linux"),
593        abi::ELF_NOTE_GNU_ABI_TAG_OS_GNU => Some("GNU"),
594        abi::ELF_NOTE_GNU_ABI_TAG_OS_SOLARIS2 => Some("Solaris"),
595        abi::ELF_NOTE_GNU_ABI_TAG_OS_FREEBSD => Some("FreeBSD"),
596        _ => None,
597    }
598}
599
600pub fn d_tag_to_str(d_tag: i64) -> Option<&'static str> {
601    match d_tag {
602        abi::DT_NULL => Some("DT_NULL"),
603        abi::DT_NEEDED => Some("DT_NEEDED"),
604        abi::DT_PLTRELSZ => Some("DT_PLTRELSZ"),
605        abi::DT_PLTGOT => Some("DT_PLTGOT"),
606        abi::DT_HASH => Some("DT_HASH"),
607        abi::DT_STRTAB => Some("DT_STRTAB"),
608        abi::DT_SYMTAB => Some("DT_SYMTAB"),
609        abi::DT_RELA => Some("DT_RELA"),
610        abi::DT_RELASZ => Some("DT_RELASZ"),
611        abi::DT_RELAENT => Some("DT_RELAENT"),
612        abi::DT_STRSZ => Some("DT_STRSZ"),
613        abi::DT_SYMENT => Some("DT_SYMENT"),
614        abi::DT_INIT => Some("DT_INIT"),
615        abi::DT_FINI => Some("DT_FINI"),
616        abi::DT_SONAME => Some("DT_SONAME"),
617        abi::DT_RPATH => Some("DT_RPATH"),
618        abi::DT_SYMBOLIC => Some("DT_SYMBOLIC"),
619        abi::DT_REL => Some("DT_REL"),
620        abi::DT_RELSZ => Some("DT_RELSZ"),
621        abi::DT_RELENT => Some("DT_RELENT"),
622        abi::DT_PLTREL => Some("DT_PLTREL"),
623        abi::DT_DEBUG => Some("DT_DEBUG"),
624        abi::DT_TEXTREL => Some("DT_TEXTREL"),
625        abi::DT_JMPREL => Some("DT_JMPREL"),
626        abi::DT_BIND_NOW => Some("DT_BIND_NOW"),
627        abi::DT_INIT_ARRAY => Some("DT_INIT_ARRAY"),
628        abi::DT_FINI_ARRAY => Some("DT_FINI_ARRAY"),
629        abi::DT_INIT_ARRAYSZ => Some("DT_INIT_ARRAYSZ"),
630        abi::DT_FINI_ARRAYSZ => Some("DT_FINI_ARRAYSZ"),
631        abi::DT_RUNPATH => Some("DT_RUNPATH"),
632        abi::DT_FLAGS => Some("DT_FLAGS"),
633        abi::DT_PREINIT_ARRAY => Some("DT_PREINIT_ARRAY"),
634        abi::DT_PREINIT_ARRAYSZ => Some("DT_PREINIT_ARRAYSZ"),
635        abi::DT_SYMTAB_SHNDX => Some("DT_SYMTAB_SHNDX"),
636        abi::DT_GUILE_GC_ROOT => Some("DT_GUILE_GC_ROOT"),
637        abi::DT_GUILE_GC_ROOT_SZ => Some("DT_GUILE_GC_ROOT_SZ"),
638        abi::DT_GUILE_ENTRY => Some("DT_GUILE_ENTRY"),
639        abi::DT_GUILE_VM_VERSION => Some("DT_GUILE_VM_VERSION"),
640        abi::DT_GUILE_FRAME_MAPS => Some("DT_GUILE_FRAME_MAPS"),
641        abi::DT_LOOS => Some("DT_LOOS"),
642        abi::DT_GNU_PRELINKED => Some("DT_GNU_PRELINKED"),
643        abi::DT_GNU_CONFLICTSZ => Some("DT_GNU_CONFLICTSZ"),
644        abi::DT_GNU_LIBLISTSZ => Some("DT_GNU_LIBLISTSZ"),
645        abi::DT_CHECKSUM => Some("DT_CHECKSUM"),
646        abi::DT_PLTPADSZ => Some("DT_PLTPADSZ"),
647        abi::DT_MOVEENT => Some("DT_MOVEENT"),
648        abi::DT_MOVESZ => Some("DT_MOVESZ"),
649        abi::DT_FEATURE_1 => Some("DT_FEATURE_1"),
650        abi::DT_POSFLAG_1 => Some("DT_POSFLAG_1"),
651        abi::DT_SYMINSZ => Some("DT_SYMINSZ"),
652        abi::DT_SYMINENT => Some("DT_SYMINENT"),
653        abi::DT_GNU_HASH => Some("DT_GNU_HASH"),
654        abi::DT_TLSDESC_PLT => Some("DT_TLSDESC_PLT"),
655        abi::DT_TLSDESC_GOT => Some("DT_TLSDESC_GOT"),
656        abi::DT_GNU_CONFLICT => Some("DT_GNU_CONFLICT"),
657        abi::DT_GNU_LIBLIST => Some("DT_GNU_LIBLIST"),
658        abi::DT_CONFIG => Some("DT_CONFIG"),
659        abi::DT_DEPAUDIT => Some("DT_DEPAUDIT"),
660        abi::DT_AUDIT => Some("DT_AUDIT"),
661        abi::DT_PLTPAD => Some("DT_PLTPAD"),
662        abi::DT_MOVETAB => Some("DT_MOVETAB"),
663        abi::DT_SYMINFO => Some("DT_SYMINFO"),
664        abi::DT_VERSYM => Some("DT_VERSYM"),
665        abi::DT_RELACOUNT => Some("DT_RELACOUNT"),
666        abi::DT_RELCOUNT => Some("DT_RELCOUNT"),
667        abi::DT_FLAGS_1 => Some("DT_FLAGS_1"),
668        abi::DT_VERDEF => Some("DT_VERDEF"),
669        abi::DT_VERDEFNUM => Some("DT_VERDEFNUM"),
670        abi::DT_VERNEED => Some("DT_VERNEED"),
671        abi::DT_VERNEEDNUM => Some("DT_VERNEEDNUM"),
672        abi::DT_HIOS => Some("DT_HIOS"),
673        abi::DT_LOPROC => Some("DT_LOPROC"),
674        abi::DT_HIPROC => Some("DT_HIPROC"),
675        _ => None,
676    }
677}