1d29b2c44Sab196087 /* 2d29b2c44Sab196087 * CDDL HEADER START 3d29b2c44Sab196087 * 4d29b2c44Sab196087 * The contents of this file are subject to the terms of the 5d29b2c44Sab196087 * Common Development and Distribution License (the "License"). 6d29b2c44Sab196087 * You may not use this file except in compliance with the License. 7d29b2c44Sab196087 * 8d29b2c44Sab196087 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE 9d29b2c44Sab196087 * or http://www.opensolaris.org/os/licensing. 10d29b2c44Sab196087 * See the License for the specific language governing permissions 11d29b2c44Sab196087 * and limitations under the License. 12d29b2c44Sab196087 * 13d29b2c44Sab196087 * When distributing Covered Code, include this CDDL HEADER in each 14d29b2c44Sab196087 * file and include the License file at usr/src/OPENSOLARIS.LICENSE. 15d29b2c44Sab196087 * If applicable, add the following below this CDDL HEADER, with the 16d29b2c44Sab196087 * fields enclosed by brackets "[]" replaced with your own identifying 17d29b2c44Sab196087 * information: Portions Copyright [yyyy] [name of copyright owner] 18d29b2c44Sab196087 * 19d29b2c44Sab196087 * CDDL HEADER END 20d29b2c44Sab196087 */ 21d29b2c44Sab196087 22d29b2c44Sab196087 /* 23*cce0e03bSab196087 * Copyright 2008 Sun Microsystems, Inc. All rights reserved. 24d29b2c44Sab196087 * Use is subject to license terms. 25d29b2c44Sab196087 */ 26d29b2c44Sab196087 27d29b2c44Sab196087 #ifndef _ELFEDIT_H 28d29b2c44Sab196087 #define _ELFEDIT_H 29d29b2c44Sab196087 30d29b2c44Sab196087 #pragma ident "%Z%%M% %I% %E% SMI" 31d29b2c44Sab196087 32d29b2c44Sab196087 #include <stdio.h> 33d29b2c44Sab196087 #include <stdlib.h> 34d29b2c44Sab196087 #include <sys/types.h> 35d29b2c44Sab196087 #include <libelf.h> 36d29b2c44Sab196087 #include <stdarg.h> 37d29b2c44Sab196087 38d29b2c44Sab196087 /* The following are here to support use of elfedit_msg() */ 39d29b2c44Sab196087 #include <sys/machelf.h> /* EC_ macros */ 40d29b2c44Sab196087 #include <libintl.h> 41d29b2c44Sab196087 42d29b2c44Sab196087 #ifdef __cplusplus 43d29b2c44Sab196087 extern "C" { 44d29b2c44Sab196087 #endif 45d29b2c44Sab196087 46d29b2c44Sab196087 47d29b2c44Sab196087 /* 48d29b2c44Sab196087 * elfedit uses elfedit_printf() to produce generic output to stdout. 49d29b2c44Sab196087 * elfedit_msg() is used to produce error message, or specific types 50d29b2c44Sab196087 * of terse informational messages: 51d29b2c44Sab196087 * 52d29b2c44Sab196087 * ELFEDIT_MSG_ERR: 53d29b2c44Sab196087 * Issues an error to stderr. elfedit_msg() does not return 54d29b2c44Sab196087 * to the caller. Control returns to the outer loop in 55d29b2c44Sab196087 * interactive use. elfedit exits in non-interactive use. 56d29b2c44Sab196087 * 57d29b2c44Sab196087 * ELFEDIT_MSG_FATAL: 58d29b2c44Sab196087 * Issues an error to stderr. elfedit_msg() exits the process, 59d29b2c44Sab196087 * and does not return to the caller. 60d29b2c44Sab196087 * 61d29b2c44Sab196087 * ELFEDIT_MSG_USAGE: 62d29b2c44Sab196087 * Issues an elfedit usage message to stderr, and 63d29b2c44Sab196087 * returns to the caller. 64d29b2c44Sab196087 * 65d29b2c44Sab196087 * ELFEDIT_MSG_CMDUSAGE 66d29b2c44Sab196087 * Issues an elfedit usage message to stderr, and 67d29b2c44Sab196087 * does not return to the caller. 68d29b2c44Sab196087 * 69d29b2c44Sab196087 * ELFEDIT_MSG_DEBUG 70d29b2c44Sab196087 * If the ELFEDIT_F_DEBUG flag is set, the message 71d29b2c44Sab196087 * is printed to stdout, otherwise no output is produced. 72d29b2c44Sab196087 * elfedit_msg() returns to the caller. 73d29b2c44Sab196087 * 74d29b2c44Sab196087 * ELFEDIT_MSG_QUIET 75d29b2c44Sab196087 * This is a very special case, intended to handle the 76d29b2c44Sab196087 * case where the pager subprocess exits before we are 77d29b2c44Sab196087 * done producing output (the user presses 'q'). It acts 78d29b2c44Sab196087 * just like ELFEDIT_MSG_ERR, except that no message is 79d29b2c44Sab196087 * actually printed. 80d29b2c44Sab196087 * 81d29b2c44Sab196087 * In the cases where elfedit_msg() does not return to the caller, the 82d29b2c44Sab196087 * behavior depends on the mode of execution. If running in interactive 83d29b2c44Sab196087 * mode (reading from a tty), control is returned directly to the outer 84d29b2c44Sab196087 * elfedit control loop to read another command. If not running in interactive 85d29b2c44Sab196087 * mode, elfedit exits with a non-zero status. 86d29b2c44Sab196087 */ 87d29b2c44Sab196087 typedef enum { 88d29b2c44Sab196087 ELFEDIT_MSG_ERR = 0, 89d29b2c44Sab196087 ELFEDIT_MSG_FATAL = 1, 90d29b2c44Sab196087 ELFEDIT_MSG_USAGE = 2, 91d29b2c44Sab196087 ELFEDIT_MSG_CMDUSAGE = 3, 92d29b2c44Sab196087 ELFEDIT_MSG_DEBUG = 4, 93d29b2c44Sab196087 ELFEDIT_MSG_QUIET = 5 94d29b2c44Sab196087 } elfedit_msg_t; 95d29b2c44Sab196087 96d29b2c44Sab196087 97d29b2c44Sab196087 /* 98d29b2c44Sab196087 * Information for a single ELF section. 99d29b2c44Sab196087 * 100d29b2c44Sab196087 * NOTE: sec_xshndx 101d29b2c44Sab196087 * A symbol table can have an associated SHT_SYMTAB_SHNDX section. This 102d29b2c44Sab196087 * happens when the number of sections is too large to fit in the 103d29b2c44Sab196087 * ELF symbol st_shndx field, which is a 16-bit value. The sec_xshndx 104d29b2c44Sab196087 * field will be SHN_UNDEF if there is no such section, and will be 105d29b2c44Sab196087 * the section index of the extended section index section assocated 106d29b2c44Sab196087 * with the symbol table otherwise. 107d29b2c44Sab196087 * 108d29b2c44Sab196087 * NOTE: sec_versym 109d29b2c44Sab196087 * Symbol table sections can have an SHT_SUNW_VERSYM section that 110d29b2c44Sab196087 * contains its version indices. Other types of section will have 111d29b2c44Sab196087 * this field set to SHN_UNDEF. 112d29b2c44Sab196087 */ 113d29b2c44Sab196087 typedef struct { 114d29b2c44Sab196087 Elf32_Word sec_shndx; /* Section index */ 115d29b2c44Sab196087 Elf_Scn *sec_scn; /* Section descriptor */ 116d29b2c44Sab196087 Elf32_Shdr *sec_shdr; /* Section header */ 117d29b2c44Sab196087 Elf_Data *sec_data; /* Data region of section */ 118d29b2c44Sab196087 const char *sec_name; /* Name of section */ 119d29b2c44Sab196087 } elfedit32_section_t; 120d29b2c44Sab196087 121d29b2c44Sab196087 typedef struct { 122d29b2c44Sab196087 Elf64_Word sec_shndx; 123d29b2c44Sab196087 Elf_Scn *sec_scn; 124d29b2c44Sab196087 Elf64_Shdr *sec_shdr; 125d29b2c44Sab196087 Elf_Data *sec_data; 126d29b2c44Sab196087 const char *sec_name; 127d29b2c44Sab196087 } elfedit64_section_t; 128d29b2c44Sab196087 129d29b2c44Sab196087 #ifdef _ELF64 130d29b2c44Sab196087 #define elfedit_section_t elfedit64_section_t 131d29b2c44Sab196087 #else 132d29b2c44Sab196087 #define elfedit_section_t elfedit32_section_t 133d29b2c44Sab196087 #endif 134d29b2c44Sab196087 135d29b2c44Sab196087 136d29b2c44Sab196087 /* 137d29b2c44Sab196087 * We maintain extra information for symbol tables. We look them 138d29b2c44Sab196087 * up frequently, so we want to eliminate expensive linear searches 139d29b2c44Sab196087 * of the entire section header array. Also, symbol tables usually 140d29b2c44Sab196087 * have associated parallal sections (syminfo, versym, extended indexes, etc) 141d29b2c44Sab196087 * and we want to eliminate repeated linear lookups for them, as well as 142d29b2c44Sab196087 * the basic error checking that is necessary to ensure they match the 143d29b2c44Sab196087 * symbol table they're given. 144d29b2c44Sab196087 * 145d29b2c44Sab196087 * This extra information is kept in elfedit_symtab_t structs. Each field 146d29b2c44Sab196087 * is a section index, with SHN_UNDEF used for those that do not apply. 147d29b2c44Sab196087 */ 148d29b2c44Sab196087 typedef struct { 149d29b2c44Sab196087 Elf32_Word symt_shndx; /* Symbol table section index */ 150d29b2c44Sab196087 Elf32_Word symt_xshndx; /* Index of extended index section */ 151d29b2c44Sab196087 Elf32_Word symt_syminfo; /* Index of versym section */ 152d29b2c44Sab196087 Elf32_Word symt_versym; /* Index of versym section */ 153d29b2c44Sab196087 } elfedit32_symtab_t; 154d29b2c44Sab196087 155d29b2c44Sab196087 typedef struct { 156d29b2c44Sab196087 Elf64_Word symt_shndx; 157d29b2c44Sab196087 Elf64_Word symt_xshndx; 158d29b2c44Sab196087 Elf64_Word symt_versym; 159d29b2c44Sab196087 Elf64_Word symt_syminfo; 160d29b2c44Sab196087 } elfedit64_symtab_t; 161d29b2c44Sab196087 162d29b2c44Sab196087 #ifdef _ELF64 163d29b2c44Sab196087 #define elfedit_symtab_t elfedit64_symtab_t 164d29b2c44Sab196087 #else 165d29b2c44Sab196087 #define elfedit_symtab_t elfedit32_symtab_t 166d29b2c44Sab196087 #endif 167d29b2c44Sab196087 168d29b2c44Sab196087 169d29b2c44Sab196087 /* 170d29b2c44Sab196087 * Information for a single ELF object. 171d29b2c44Sab196087 * 172d29b2c44Sab196087 * note: 173d29b2c44Sab196087 * elfedit is intended to be an expert's tool, capable of modifying 174d29b2c44Sab196087 * nearly everything in the file, whether or not such modifications 175d29b2c44Sab196087 * are a good idea. At the same time, elfedit, via libelf, relies 176d29b2c44Sab196087 * on the contents of the object to properly locate information in 177d29b2c44Sab196087 * the file. As this is the same information that elfedit allows the 178d29b2c44Sab196087 * user to modify, it should be obvious that the potential exists 179d29b2c44Sab196087 * for users to corrupt the file to the degree that elfedit itself 180d29b2c44Sab196087 * may fail, or produce spurious results. We allow such changes for 181d29b2c44Sab196087 * several reasons: 182d29b2c44Sab196087 * 183d29b2c44Sab196087 * 1) Such corruption does not happen in the most obvious and 184d29b2c44Sab196087 * useful operations elfedit supports, but comes as a result 185d29b2c44Sab196087 * of modifying fields that contain size and offset information 186d29b2c44Sab196087 * used to navigate the file. Non-ELF developers have 187d29b2c44Sab196087 * little practical reason to change such things. 188d29b2c44Sab196087 * 189d29b2c44Sab196087 * 2) Producing a corrupt ELF file can be very useful 190d29b2c44Sab196087 * for R&D and/or testing purposes. 191d29b2c44Sab196087 * 192d29b2c44Sab196087 * 3) ELF is sufficiently complex that no absolute guarantees can 193d29b2c44Sab196087 * be made about "safe" operations, beyond the basic 194d29b2c44Sab196087 * and obvious things that are of practical use. 195d29b2c44Sab196087 * 196d29b2c44Sab196087 * One way we protect ourselves is via the information cached in 197d29b2c44Sab196087 * the elfedit_obj_state_t structure at startup. By using this 198d29b2c44Sab196087 * information, rather than constantly fetching it via libelf, 199d29b2c44Sab196087 * we protect ourselves against many user changes, such as changing the 200d29b2c44Sab196087 * program or section header offsets, or similar size/position fields. 201d29b2c44Sab196087 * 202d29b2c44Sab196087 * Of course, we make no assurances that that we will be able to 203d29b2c44Sab196087 * read the resulting file in a subsequent session. 204d29b2c44Sab196087 */ 205d29b2c44Sab196087 typedef struct { 206d29b2c44Sab196087 const char *os_file; /* Path to ELF file */ 207d29b2c44Sab196087 int os_fd; /* Open file descriptor */ 208d29b2c44Sab196087 Elf *os_elf; /* ELF descriptor */ 209d29b2c44Sab196087 Elf32_Ehdr *os_ehdr; /* ELF header */ 210d29b2c44Sab196087 Elf32_Word os_dynndx; /* Index of dynamic section */ 211d29b2c44Sab196087 size_t os_shstrndx; /* Index of section header */ 212d29b2c44Sab196087 /* string table section */ 213d29b2c44Sab196087 size_t os_shnum; /* # of sections in file */ 214d29b2c44Sab196087 elfedit32_section_t *os_secarr; /* Section data */ 215d29b2c44Sab196087 size_t os_phnum; /* # of program headers */ 216d29b2c44Sab196087 Elf32_Phdr *os_phdr; /* Program header array */ 217d29b2c44Sab196087 size_t os_symtabnum; /* # items in os_symtab[] */ 218d29b2c44Sab196087 elfedit32_symtab_t *os_symtab; /* Array of symbol tbl info */ 219d29b2c44Sab196087 } elfedit32_obj_state_t; 220d29b2c44Sab196087 221d29b2c44Sab196087 typedef struct { 222d29b2c44Sab196087 const char *os_file; 223d29b2c44Sab196087 int os_fd; 224d29b2c44Sab196087 Elf *os_elf; 225d29b2c44Sab196087 Elf64_Ehdr *os_ehdr; 226d29b2c44Sab196087 Elf64_Word os_dynndx; 227d29b2c44Sab196087 size_t os_shstrndx; 228d29b2c44Sab196087 size_t os_shnum; 229d29b2c44Sab196087 elfedit64_section_t *os_secarr; 230d29b2c44Sab196087 size_t os_phnum; 231d29b2c44Sab196087 Elf64_Phdr *os_phdr; 232d29b2c44Sab196087 size_t os_symtabnum; 233d29b2c44Sab196087 elfedit64_symtab_t *os_symtab; 234d29b2c44Sab196087 } elfedit64_obj_state_t; 235d29b2c44Sab196087 236d29b2c44Sab196087 #ifdef _ELF64 237d29b2c44Sab196087 #define elfedit_obj_state_t elfedit64_obj_state_t 238d29b2c44Sab196087 #else 239d29b2c44Sab196087 #define elfedit_obj_state_t elfedit32_obj_state_t 240d29b2c44Sab196087 #endif 241d29b2c44Sab196087 242d29b2c44Sab196087 243d29b2c44Sab196087 /* 244d29b2c44Sab196087 * Bit values for editor state. 245d29b2c44Sab196087 */ 246d29b2c44Sab196087 typedef enum { 247d29b2c44Sab196087 ELFEDIT_F_AUTOPRINT = 1, /* Print informational text about edits */ 248d29b2c44Sab196087 ELFEDIT_F_DEBUG = 2, /* Print informational text about operations */ 249d29b2c44Sab196087 ELFEDIT_F_READONLY = 4, /* File is processed readonly */ 250d29b2c44Sab196087 } elfedit_flag_t; 251d29b2c44Sab196087 252d29b2c44Sab196087 /* 253d29b2c44Sab196087 * Type used to represent the output style for printing ELF values. 254d29b2c44Sab196087 * 255d29b2c44Sab196087 * DEFAULT - Output is in 'elfdump' style, designed for human eyes. 256d29b2c44Sab196087 * Headers, and additional information are shown. 257d29b2c44Sab196087 * SIMPLE - Output is simple, consisting only of the target item. 258d29b2c44Sab196087 * Integer values are shown as symbolic constants when possible, 259d29b2c44Sab196087 * and integers otherwise. 260d29b2c44Sab196087 * NUM - Like SIMPLE, except integer values are always shown as 261d29b2c44Sab196087 * integer constants, and strings are shown as the integer 262d29b2c44Sab196087 * offset into the string table. 263d29b2c44Sab196087 */ 264d29b2c44Sab196087 typedef enum { 265d29b2c44Sab196087 ELFEDIT_OUTSTYLE_DEFAULT = 0, 266d29b2c44Sab196087 ELFEDIT_OUTSTYLE_SIMPLE = 1, 267d29b2c44Sab196087 ELFEDIT_OUTSTYLE_NUM = 2 268d29b2c44Sab196087 } elfedit_outstyle_t; 269d29b2c44Sab196087 270d29b2c44Sab196087 271d29b2c44Sab196087 /* 272d29b2c44Sab196087 * The elfedit_module_t, and the types it references, are defined 273d29b2c44Sab196087 * by loadable elfedit modules, and used by elfedit. These structures 274d29b2c44Sab196087 * need to communicate internationalized strings for elfedit to print. 275d29b2c44Sab196087 * 276d29b2c44Sab196087 * We want to leave the choice of internationalization APIs, as well as 277d29b2c44Sab196087 * the decision about whether or not to even to it to the individual 278d29b2c44Sab196087 * modules. Hence, we do not use a simple (const char *) pointer to 279d29b2c44Sab196087 * communicate potentially internationalized strings. Instead, we define 280d29b2c44Sab196087 * elfedit_i18nhdl_t, an opaque type guaranteed to be large enough 281d29b2c44Sab196087 * to hold a pointer. Each module casts the handle needed to access the 282d29b2c44Sab196087 * string to this type. Each module also supplies a function 283d29b2c44Sab196087 * (mod_i18nhdl_to_str field of elfedit_module_t) that given one 284d29b2c44Sab196087 * of these opaque keys, will return a (const char *) pointer to the 285d29b2c44Sab196087 * actual string, for elfedit to print. 286d29b2c44Sab196087 * 287d29b2c44Sab196087 * If the underlying module doesn't want to implement i18n support, 288d29b2c44Sab196087 * all it has to do is cast the strings to elfedit_i18nhdl_t and 289d29b2c44Sab196087 * back. 290d29b2c44Sab196087 */ 291d29b2c44Sab196087 typedef uintptr_t elfedit_i18nhdl_t; 292d29b2c44Sab196087 293d29b2c44Sab196087 294d29b2c44Sab196087 295d29b2c44Sab196087 /* 296d29b2c44Sab196087 * Macro to handle casting international string "handles" to the 297d29b2c44Sab196087 * elfedit_i18nhdl_t opaque type. 298d29b2c44Sab196087 */ 299d29b2c44Sab196087 #define ELFEDIT_I18NHDL(_i18n_str_ref) ((elfedit_i18nhdl_t)_i18n_str_ref) 300d29b2c44Sab196087 301d29b2c44Sab196087 302d29b2c44Sab196087 /* 303d29b2c44Sab196087 * Return values from command functions 304d29b2c44Sab196087 */ 305d29b2c44Sab196087 typedef enum { 306d29b2c44Sab196087 ELFEDIT_CMDRET_NONE = 0, /* Nothing to report */ 307d29b2c44Sab196087 ELFEDIT_CMDRET_MOD = 1, /* Command modified output ELF file */ 308d29b2c44Sab196087 ELFEDIT_CMDRET_FLUSH = 2 /* Output file flushed: elf_update() */ 309d29b2c44Sab196087 } elfedit_cmdret_t; 310d29b2c44Sab196087 311d29b2c44Sab196087 /* 312d29b2c44Sab196087 * Prototype of an implementation function for an edit command. Note that 313d29b2c44Sab196087 * commands do not return a status: 314d29b2c44Sab196087 * - Success is indicated by a normal return. 315d29b2c44Sab196087 * - The command indicates a fatal error by calling elfedit_msg() with the 316d29b2c44Sab196087 * ELFEDIT_MSG_ERR type, in which case execution does not return 317d29b2c44Sab196087 * to the command, and the elfedit command loop knows that an 318d29b2c44Sab196087 * error occurred. 319d29b2c44Sab196087 * - The command is responsible for using the standard libelf 320d29b2c44Sab196087 * mechanisms to indicate when changes have been made to 321d29b2c44Sab196087 * the ELF file. 322d29b2c44Sab196087 */ 323d29b2c44Sab196087 typedef elfedit_cmdret_t elfedit32_cmd_func_t(elfedit32_obj_state_t *state, 324d29b2c44Sab196087 int argc, const char *argv[]); 325d29b2c44Sab196087 typedef elfedit_cmdret_t elfedit64_cmd_func_t(elfedit64_obj_state_t *state, 326d29b2c44Sab196087 int argc, const char *argv[]); 327d29b2c44Sab196087 #ifdef _ELF64 328d29b2c44Sab196087 #define elfedit_cmd_func_t elfedit64_cmd_func_t 329d29b2c44Sab196087 #else 330d29b2c44Sab196087 #define elfedit_cmd_func_t elfedit32_cmd_func_t 331d29b2c44Sab196087 #endif 332d29b2c44Sab196087 333d29b2c44Sab196087 334d29b2c44Sab196087 /* 335d29b2c44Sab196087 * An elfedit command (elfedit_cmd_t) has a cmd_cpl field that 336d29b2c44Sab196087 * can be set to a command completion function. If such a function 337d29b2c44Sab196087 * is present (non-NULL), and the user presses the tab key at the 338d29b2c44Sab196087 * command line while the cursor is at a plain (non option) argument, 339d29b2c44Sab196087 * elfedit calls the function, passing it all the tokens up through 340d29b2c44Sab196087 * the one needing completion. The function can use elfedit_cpl_match() 341d29b2c44Sab196087 * to enter possible alternatives. Additionally, there are helper 342d29b2c44Sab196087 * functions built on top of elfedit_cpl_match() that simplify common cases. 343d29b2c44Sab196087 * 344d29b2c44Sab196087 * elfedit_cpl_ato[iu]() - enter matches from elfedit_ato[iu]_sym_t 345d29b2c44Sab196087 * mappings. 346d29b2c44Sab196087 * elfedit_cpl_atoconst() - Enter matches for well known constants 347d29b2c44Sab196087 * elfedit_cpl_command() - enter matches for all known commands 348d29b2c44Sab196087 * elfedit_cpl_mod() - enter matches for all known modules. 349d29b2c44Sab196087 * 350d29b2c44Sab196087 * The completion function is passed the following arguments: 351d29b2c44Sab196087 * 352d29b2c44Sab196087 * obj_state - Object state. Will be NULL if elfedit session does not 353d29b2c44Sab196087 * have an active object. The completion function must test 354d29b2c44Sab196087 * the pointer before using it. 355d29b2c44Sab196087 * cpldata - Completion data, to be passed to elfedit_cpl_match() 356d29b2c44Sab196087 * or the helper functions built on it to register alternative 357d29b2c44Sab196087 * strings. 358d29b2c44Sab196087 * argc, argv - The tokens from the start of the line throught 359d29b2c44Sab196087 * the one needing completion, which will always 360d29b2c44Sab196087 * be cmdcpl_argv[cmdcpl_argc - 1]. 361d29b2c44Sab196087 * num_opt - A count of the optional arguments (those starting with 362d29b2c44Sab196087 * '-' at the beginning of argv. This means that argv[num_opt] 363d29b2c44Sab196087 * is the first plain argument, and the 1-based positional 364d29b2c44Sab196087 * number of the plain argument for which command completion 365d29b2c44Sab196087 * is needed is (argc - num_opt). 366d29b2c44Sab196087 */ 367d29b2c44Sab196087 typedef void elfedit32_cmdcpl_func_t(elfedit32_obj_state_t *state, 368d29b2c44Sab196087 void *cpldata, int argc, const char *argv[], int num_opt); 369d29b2c44Sab196087 typedef void elfedit64_cmdcpl_func_t(elfedit64_obj_state_t *state, 370d29b2c44Sab196087 void *cpldata, int argc, const char *argv[], int num_opt); 371d29b2c44Sab196087 #ifdef _ELF64 372d29b2c44Sab196087 #define elfedit_cmdcpl_func_t elfedit64_cmdcpl_func_t 373d29b2c44Sab196087 #else 374d29b2c44Sab196087 #define elfedit_cmdcpl_func_t elfedit32_cmdcpl_func_t 375d29b2c44Sab196087 #endif 376d29b2c44Sab196087 377d29b2c44Sab196087 378d29b2c44Sab196087 379d29b2c44Sab196087 380d29b2c44Sab196087 /* 381d29b2c44Sab196087 * Command option/argument descriptor. These structures 382d29b2c44Sab196087 * are used to represent each option and plain argument accepted 383d29b2c44Sab196087 * by a command, via the cmd_opt and cmd_args fields in the 384d29b2c44Sab196087 * command definition (elfedit_cmd_t). Each descriptor consists 385d29b2c44Sab196087 * of a name, a help string (formatted for display via sys:help), 386d29b2c44Sab196087 * and a flags field that conveys extra information about the 387d29b2c44Sab196087 * item: 388d29b2c44Sab196087 * 389d29b2c44Sab196087 * ELFEDIT_CMDOA_F_OPT 390d29b2c44Sab196087 * The item is optional. This flag is implicit for options 391d29b2c44Sab196087 * and need only be set for plain arguments. 392d29b2c44Sab196087 * 393d29b2c44Sab196087 * ELFEDIT_CMDOA_F_VALUE 394d29b2c44Sab196087 * The item has a value, which is found in the following 395d29b2c44Sab196087 * item. This flag only has meaning for options, and should 396d29b2c44Sab196087 * not be set for plain arguments. The descriptor for the 397d29b2c44Sab196087 * value is found in the next array element, and only the 398d29b2c44Sab196087 * oa_name field is used (the other should be set t 0). 399d29b2c44Sab196087 * 400d29b2c44Sab196087 * ELFEDIT_CMDOA_F_MULT 401d29b2c44Sab196087 * More than one of the specified items may be specified 402d29b2c44Sab196087 * 403d29b2c44Sab196087 * ELFEDIT_CMDOA_F_INHERIT 404d29b2c44Sab196087 * This is an item for which a common definition exists. 405d29b2c44Sab196087 * Elfedit will substitute the standard values for the 406d29b2c44Sab196087 * name, help text, and flags. This enforces consistency 407d29b2c44Sab196087 * in documentation, plus it is easier for the module author. 408d29b2c44Sab196087 * When ELFEDIT_CMDOA_F_INHERIT is set: 409d29b2c44Sab196087 * - oa_name should be set to one of the ELFEDIT_STDOA_ 410d29b2c44Sab196087 * values to specifiy which standard item is being 411d29b2c44Sab196087 * inherited. 412d29b2c44Sab196087 * - oa_help must be set to NULL. 413d29b2c44Sab196087 * - It is an error to set any other flags with 414d29b2c44Sab196087 * ELFEDIT_CMDOA_F_INHERIT. 415d29b2c44Sab196087 * - oa_idmask and oa_excmask are used in the normal way. 416d29b2c44Sab196087 * 417d29b2c44Sab196087 * The oa_idmask and oa_excmask fields are used to identify options, 418d29b2c44Sab196087 * and to support mutual exclusion (when two or more options cannot be 419d29b2c44Sab196087 * used together). They are ignored for arguments, and should be set to 0. 420d29b2c44Sab196087 * oa_idmask is used to uniquely identify each item. When elfedit_getopt() 421d29b2c44Sab196087 * matches an option, it returns the value of oa_idmask to the caller to 422d29b2c44Sab196087 * indicate which option was matched. elfedit enforces the following rules 423d29b2c44Sab196087 * for oa_idmask, and will refuse to load a module that does not follow them: 424d29b2c44Sab196087 * - The value of oa_idmask must be 0, or have a value that 425d29b2c44Sab196087 * is a power of 2 (i.e. only has one bit set). 426d29b2c44Sab196087 * - Each item that sets a non-0 value for oa_idmask must have 427d29b2c44Sab196087 * a unique value. 428d29b2c44Sab196087 * - If oa_idmask is 0, oa_excmask must be 0 also. 429d29b2c44Sab196087 * - oa_excmask is set to 0 if an item is not mutually exclusive 430d29b2c44Sab196087 * to any other item. Otherwise, it should set the bit 431d29b2c44Sab196087 * values representing the items it is mutually exclusive to. 432d29b2c44Sab196087 * - An oa_idmask value of 0 can be used for any item that 433d29b2c44Sab196087 * the module does not need to identify, and which 434d29b2c44Sab196087 * is not mutually exclusive to any other item. 435d29b2c44Sab196087 * As elfedit_getopt() processes items, it maintains a bitmask combining the 436d29b2c44Sab196087 * oa_idmask fields of all the options already seen. For each option, it uses 437d29b2c44Sab196087 * oa_excmask to check for conflicts. 438d29b2c44Sab196087 * 439d29b2c44Sab196087 * note: elfedit enforces the rule that options consist of a '-' 440d29b2c44Sab196087 * character followed by at least one character when a module 441d29b2c44Sab196087 * is loaded. 442d29b2c44Sab196087 */ 443d29b2c44Sab196087 typedef enum { 444d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT = 1, /* Item is optional */ 445d29b2c44Sab196087 ELFEDIT_CMDOA_F_VALUE = 2, /* Item has a value arg following */ 446d29b2c44Sab196087 ELFEDIT_CMDOA_F_MULT = 4, /* More than one are allowed */ 447d29b2c44Sab196087 ELFEDIT_CMDOA_F_INHERIT = 8, /* Inherit definition: See above */ 448d29b2c44Sab196087 } elfedit_cmd_oa_flag_t; 449d29b2c44Sab196087 450d29b2c44Sab196087 typedef u_longlong_t elfedit_cmd_oa_mask_t; 451d29b2c44Sab196087 452d29b2c44Sab196087 typedef struct { 453d29b2c44Sab196087 const char *oa_name; /* Name of option */ 454d29b2c44Sab196087 elfedit_i18nhdl_t oa_help; /* Help text for option */ 455d29b2c44Sab196087 elfedit_cmd_oa_flag_t oa_flags; /* Additional attributes */ 456d29b2c44Sab196087 elfedit_cmd_oa_mask_t oa_idmask; /* Unique id, returned by */ 457d29b2c44Sab196087 /* elfedit_getopt */ 458d29b2c44Sab196087 /* for use by caller */ 459d29b2c44Sab196087 elfedit_cmd_oa_mask_t oa_excmask; /* Mutual exclusion mask */ 460d29b2c44Sab196087 } elfedit_cmd_optarg_t; 461d29b2c44Sab196087 462d29b2c44Sab196087 463d29b2c44Sab196087 464d29b2c44Sab196087 /* 465d29b2c44Sab196087 * These values define the standard options and arguments that a module 466d29b2c44Sab196087 * can inherit using the ELFEDIT_CMDOA_F_INHERIT flag (described above). 467d29b2c44Sab196087 * New items must be added at the end --- reordering the list will 468d29b2c44Sab196087 * require all modules to be rebuilt. 469d29b2c44Sab196087 * 470d29b2c44Sab196087 * Note: 0 cannot be used as a ELFEDIT_STDOA_ value, because a NULL 471d29b2c44Sab196087 * value of oa_name is used to terminate argument and options lists. 472d29b2c44Sab196087 * Therefore, these values start at 1. 473d29b2c44Sab196087 */ 474d29b2c44Sab196087 #define ELFEDIT_STDOA_OPT_O ((const char *) 1) /* -o ostyle */ 475d29b2c44Sab196087 #define ELFEDIT_STDOA_OPT_AND ((const char *) 2) /* -and */ 476d29b2c44Sab196087 #define ELFEDIT_STDOA_OPT_CMP ((const char *) 3) /* -cmp */ 477d29b2c44Sab196087 #define ELFEDIT_STDOA_OPT_OR ((const char *) 4) /* -or */ 478d29b2c44Sab196087 479d29b2c44Sab196087 #define ELFEDIT_NUM_STDOA 4 /* # of ELFEDIT_STDOA_ definitions */ 480d29b2c44Sab196087 481d29b2c44Sab196087 482d29b2c44Sab196087 483d29b2c44Sab196087 /* 484d29b2c44Sab196087 * Definition of a command 485d29b2c44Sab196087 * 486d29b2c44Sab196087 * This structure includes an elfedit_cmd_func_t pointer, which has 487d29b2c44Sab196087 * different definitions for different ELFCLASS. Rather than needlessly 488d29b2c44Sab196087 * complicate the code with three versions of this type, and any 489d29b2c44Sab196087 * type that uses it, we simply use the GenericClass type. elfedit 490d29b2c44Sab196087 * will always cast this to the correct type before calling a module. 491d29b2c44Sab196087 * 492d29b2c44Sab196087 * cmd_name is an array of pointers to the names for the command. 493d29b2c44Sab196087 * The "primary" name should always be first, followed by any alias 494d29b2c44Sab196087 * names. The final element of the array must be a NULL pointer, 495d29b2c44Sab196087 * which terminates the list. Every command is required to have at 496d29b2c44Sab196087 * least one name, so code is allowed to assume that the first element 497d29b2c44Sab196087 * of cmd_name is non-NULL, and contains the primary name. 498d29b2c44Sab196087 * 499d29b2c44Sab196087 * Many modules provide a "default" command, which is a command 500d29b2c44Sab196087 * that is run if only the module name is specified, followed 501d29b2c44Sab196087 * by a colon (i.e. "sym:"). The way this is implemented is to 502d29b2c44Sab196087 * give the desired default command an empty string as an alias. 503d29b2c44Sab196087 * Note that the primary name cannot be an empty string, only the 504d29b2c44Sab196087 * alias name. 505d29b2c44Sab196087 * 506d29b2c44Sab196087 * cmd_opts and cmd_args are each an array of elfedit_cmd_argdesc_t 507d29b2c44Sab196087 * structures, that describe the options and plain arguments accepted 508d29b2c44Sab196087 * by the command. These arrays are used to general help text for 509d29b2c44Sab196087 * the commands. The cmd_opts array is also used to provide command 510d29b2c44Sab196087 * completion for options. Both of these arrays are terminated by 511d29b2c44Sab196087 * a final NULL element (all fields zero). 512d29b2c44Sab196087 */ 513d29b2c44Sab196087 typedef struct { 514d29b2c44Sab196087 elfedit32_cmd_func_t *cmd_func; /* Implementation */ 515d29b2c44Sab196087 elfedit32_cmdcpl_func_t *cmd_cplfunc; /* Completion function */ 516d29b2c44Sab196087 const char **cmd_name; /* Cmd names (null term.) */ 517d29b2c44Sab196087 elfedit_i18nhdl_t cmd_desc; /* Short desc. of cmd purpose */ 518d29b2c44Sab196087 elfedit_i18nhdl_t cmd_help; /* Help text for the command */ 519d29b2c44Sab196087 elfedit_cmd_optarg_t *cmd_opt; /* Options */ 520d29b2c44Sab196087 elfedit_cmd_optarg_t *cmd_args; /* Plain arguments */ 521d29b2c44Sab196087 } elfedit32_cmd_t; 522d29b2c44Sab196087 523d29b2c44Sab196087 typedef struct { 524d29b2c44Sab196087 elfedit64_cmd_func_t *cmd_func; 525d29b2c44Sab196087 elfedit64_cmdcpl_func_t *cmd_cplfunc; 526d29b2c44Sab196087 const char **cmd_name; 527d29b2c44Sab196087 elfedit_i18nhdl_t cmd_desc; 528d29b2c44Sab196087 elfedit_i18nhdl_t cmd_help; 529d29b2c44Sab196087 elfedit_cmd_optarg_t *cmd_opt; 530d29b2c44Sab196087 elfedit_cmd_optarg_t *cmd_args; 531d29b2c44Sab196087 } elfedit64_cmd_t; 532d29b2c44Sab196087 533d29b2c44Sab196087 #ifdef _ELF64 534d29b2c44Sab196087 #define elfedit_cmd_t elfedit64_cmd_t 535d29b2c44Sab196087 #else 536d29b2c44Sab196087 #define elfedit_cmd_t elfedit32_cmd_t 537d29b2c44Sab196087 #endif 538d29b2c44Sab196087 539d29b2c44Sab196087 540d29b2c44Sab196087 541d29b2c44Sab196087 /* 542d29b2c44Sab196087 * elfedit modules version themselves so that we can alter the definition 543d29b2c44Sab196087 * of elfedit_module_t in a backward compatible way. 544d29b2c44Sab196087 */ 545d29b2c44Sab196087 typedef enum { 546d29b2c44Sab196087 ELFEDIT_VER_NONE = 0, 547d29b2c44Sab196087 ELFEDIT_VER_CURRENT = 1, 548d29b2c44Sab196087 ELFEDIT_VER_NUM = 2 549d29b2c44Sab196087 } elfedit_module_version_t; 550d29b2c44Sab196087 551d29b2c44Sab196087 552d29b2c44Sab196087 /* 553d29b2c44Sab196087 * Each module returns a pointer to an elfedit_module_t, describing 554d29b2c44Sab196087 * what commands the module provides. 555d29b2c44Sab196087 * 556d29b2c44Sab196087 * Note: mod_cmds is a NULL terminated array of command defs. This 557d29b2c44Sab196087 * means that the final element in the array should have all of its 558d29b2c44Sab196087 * fields set to NULL. 559d29b2c44Sab196087 * 560d29b2c44Sab196087 * The mod_i18nhdl_to_str function pointer is explained above 561d29b2c44Sab196087 * with the definition of elfedit_i18nhdl_t. 562d29b2c44Sab196087 */ 563d29b2c44Sab196087 typedef const char *(* elfedit_mod_i18nhdl_to_str_func_t)(elfedit_i18nhdl_t); 564d29b2c44Sab196087 565d29b2c44Sab196087 typedef struct { 566d29b2c44Sab196087 elfedit_module_version_t mod_version; /* version */ 567d29b2c44Sab196087 const char *mod_name; /* Name of module */ 568d29b2c44Sab196087 elfedit_i18nhdl_t mod_desc; /* Short desc. of mod purpose */ 569d29b2c44Sab196087 elfedit32_cmd_t *mod_cmds; /* Array of command defs */ 570d29b2c44Sab196087 /* i18n -> (char *) fcn */ 571d29b2c44Sab196087 elfedit_mod_i18nhdl_to_str_func_t mod_i18nhdl_to_str; 572d29b2c44Sab196087 } elfedit32_module_t; 573d29b2c44Sab196087 574d29b2c44Sab196087 typedef struct { 575d29b2c44Sab196087 elfedit_module_version_t mod_version; 576d29b2c44Sab196087 const char *mod_name; 577d29b2c44Sab196087 elfedit_i18nhdl_t mod_desc; 578d29b2c44Sab196087 elfedit64_cmd_t *mod_cmds; 579d29b2c44Sab196087 elfedit_mod_i18nhdl_to_str_func_t mod_i18nhdl_to_str; 580d29b2c44Sab196087 } elfedit64_module_t; 581d29b2c44Sab196087 582d29b2c44Sab196087 #ifdef _ELF64 583d29b2c44Sab196087 #define elfedit_module_t elfedit64_module_t 584d29b2c44Sab196087 #else 585d29b2c44Sab196087 #define elfedit_module_t elfedit32_module_t 586d29b2c44Sab196087 #endif 587d29b2c44Sab196087 588d29b2c44Sab196087 589d29b2c44Sab196087 /* 590d29b2c44Sab196087 * Each module is a sharable library, expected to provide a single global 591d29b2c44Sab196087 * function, named elfedit_init(), with the following prototype. 592d29b2c44Sab196087 */ 593d29b2c44Sab196087 typedef elfedit_module_t *elfedit_init_func_t(elfedit_module_version_t version); 594d29b2c44Sab196087 595d29b2c44Sab196087 596*cce0e03bSab196087 /* 597*cce0e03bSab196087 * Prototype for elfedit_write(), and for outfunc argument 598*cce0e03bSab196087 * to elfedit_str_to_c_literal(). 599*cce0e03bSab196087 */ 600*cce0e03bSab196087 typedef void elfedit_write_func_t(const void *ptr, size_t size); 601d29b2c44Sab196087 602d29b2c44Sab196087 603d29b2c44Sab196087 /* 604d29b2c44Sab196087 * Core elfedit functions exported for use by modules 605d29b2c44Sab196087 */ 606d29b2c44Sab196087 extern void elfedit_command_usage(void); 607d29b2c44Sab196087 extern void elfedit_cpl_command(void *cpldata); 608d29b2c44Sab196087 extern void elfedit_cpl_match(void *cpldata, const char *str, int casefold); 609d29b2c44Sab196087 extern void elfedit_elferr(const char *file, const char *libelf_rtn_name); 610d29b2c44Sab196087 extern elfedit_flag_t elfedit_flags(void); 611d29b2c44Sab196087 extern void *elfedit_malloc(const char *item_name, size_t size); 612d29b2c44Sab196087 extern void elfedit_msg(elfedit_msg_t type, const char *format, ...); 613d29b2c44Sab196087 extern elfedit_outstyle_t elfedit_outstyle(void); 614d29b2c44Sab196087 extern void elfedit_pager_init(void); 615d29b2c44Sab196087 extern void elfedit_printf(const char *format, ...); 616d29b2c44Sab196087 extern void *elfedit_realloc(const char *item_name, void *ptr, size_t size); 617*cce0e03bSab196087 extern void elfedit_str_to_c_literal(const char *str, 618*cce0e03bSab196087 elfedit_write_func_t *outfunc); 619*cce0e03bSab196087 extern elfedit_write_func_t elfedit_write; 620d29b2c44Sab196087 621d29b2c44Sab196087 /* 622d29b2c44Sab196087 * Core elfedit functions exported for use by sys: module only 623d29b2c44Sab196087 */ 624d29b2c44Sab196087 extern void elfedit_cpl_module(void *cpldata, int load_all_modules); 625d29b2c44Sab196087 626d29b2c44Sab196087 627d29b2c44Sab196087 /* 628d29b2c44Sab196087 * elfedit modules are expected to define two functions, one for 629d29b2c44Sab196087 * each ELFCLASS. Define a generic name for this function, based on 630d29b2c44Sab196087 * the class being supported by the including module. 631d29b2c44Sab196087 */ 632d29b2c44Sab196087 #ifdef _ELF64 633d29b2c44Sab196087 #define elfedit_init elfedit64_init 634d29b2c44Sab196087 #else 635d29b2c44Sab196087 #define elfedit_init elfedit32_init 636d29b2c44Sab196087 #endif 637d29b2c44Sab196087 638d29b2c44Sab196087 639d29b2c44Sab196087 640d29b2c44Sab196087 /* 641d29b2c44Sab196087 * It is common to search the dynamic section for specific elements. 642d29b2c44Sab196087 * Structures of this type are used to represent the contents of such 643d29b2c44Sab196087 * elements in a systematic way. The elfedit_dyn_elt_init() function 644d29b2c44Sab196087 * is used to prepare these strucutres for use. 645d29b2c44Sab196087 */ 646d29b2c44Sab196087 typedef struct { 647d29b2c44Sab196087 int dn_seen; /* True if this item has been seen */ 648d29b2c44Sab196087 Elf32_Word dn_ndx; /* Index of item in dynamic array */ 649d29b2c44Sab196087 Elf32_Dyn dn_dyn; /* Contents of dynamic item */ 650d29b2c44Sab196087 } elfedit32_dyn_elt_t; 651d29b2c44Sab196087 652d29b2c44Sab196087 typedef struct { 653d29b2c44Sab196087 int dn_seen; 654d29b2c44Sab196087 Elf64_Word dn_ndx; 655d29b2c44Sab196087 Elf64_Dyn dn_dyn; 656d29b2c44Sab196087 } elfedit64_dyn_elt_t; 657d29b2c44Sab196087 658d29b2c44Sab196087 #ifdef _ELF64 659d29b2c44Sab196087 #define elfedit_dyn_elt_t elfedit64_dyn_elt_t 660d29b2c44Sab196087 #else 661d29b2c44Sab196087 #define elfedit_dyn_elt_t elfedit32_dyn_elt_t 662d29b2c44Sab196087 #endif 663d29b2c44Sab196087 664d29b2c44Sab196087 /* 665d29b2c44Sab196087 * The elfedit_atoi() and elfedit_atoui() functions can optionally 666d29b2c44Sab196087 * accept an array of these structures, giving symbolic names that 667d29b2c44Sab196087 * will be accepted instead of numeric codes. If such an array is 668d29b2c44Sab196087 * present, the supplied string has it's leading and trailing whitespace 669d29b2c44Sab196087 * removed and is then compared to the list, and if there is a match, 670d29b2c44Sab196087 * the corresponding integer value is returned. 671d29b2c44Sab196087 * 672d29b2c44Sab196087 * The final array element must have its name field set to NULL. 673d29b2c44Sab196087 */ 674d29b2c44Sab196087 typedef u_longlong_t elfedit_atoui_t; 675d29b2c44Sab196087 typedef struct { 676d29b2c44Sab196087 const char *sym_name; 677d29b2c44Sab196087 elfedit_atoui_t sym_value; 678d29b2c44Sab196087 } elfedit_atoui_sym_t; 679d29b2c44Sab196087 typedef longlong_t elfedit_atoi_t; 680d29b2c44Sab196087 typedef struct { 681d29b2c44Sab196087 const char *sym_name; 682d29b2c44Sab196087 elfedit_atoi_t sym_value; 683d29b2c44Sab196087 } elfedit_atoi_sym_t; 684d29b2c44Sab196087 685d29b2c44Sab196087 686d29b2c44Sab196087 /* 687d29b2c44Sab196087 * The elfedit_atoconst*() functions are built on top of the atoui routines. 688d29b2c44Sab196087 * These routines accept an elfedit_const_t code instead of a 689d29b2c44Sab196087 * pointer to an elfedit_atoui_sym_t array, and use internally 690d29b2c44Sab196087 * predefined tables of elfedit_atoui_sym_t in order to do the desired 691d29b2c44Sab196087 * mappings. elfedit modules are encouraged to use these standard 692d29b2c44Sab196087 * tables instead of defining their own elfedit_atoui_sym_t arrays. 693d29b2c44Sab196087 * 694d29b2c44Sab196087 * note: 695d29b2c44Sab196087 * - The values assigned here must be in agreement with the 696d29b2c44Sab196087 * sym_table[] array defined in elfconst.c. 697d29b2c44Sab196087 * - Once defined, these values must not change. Reordering the 698d29b2c44Sab196087 * list will require all modules to be rebuilt, and will 699d29b2c44Sab196087 * break backward compatability. New items should be 700d29b2c44Sab196087 * added to the end. 701d29b2c44Sab196087 */ 702d29b2c44Sab196087 typedef enum { 703d29b2c44Sab196087 ELFEDIT_CONST_OUTSTYLE = 0, /* elfedit output styles */ 704d29b2c44Sab196087 ELFEDIT_CONST_OUTSTYLE_MO = 1, /* ostyles with -o prefix */ 705d29b2c44Sab196087 ELFEDIT_CONST_BOOL = 2, /* boolean names */ 706d29b2c44Sab196087 ELFEDIT_CONST_SHN = 3, /* ELF SHN_ section indexes */ 707d29b2c44Sab196087 ELFEDIT_CONST_SHT = 4, /* ELF SHT_ section types */ 708d29b2c44Sab196087 ELFEDIT_CONST_SHT_STRTAB = 5, /* ELF SHT_STRTAB */ 709d29b2c44Sab196087 ELFEDIT_CONST_SHT_ALLSYMTAB = 6, /* ELF SHT_ symbol table */ 710d29b2c44Sab196087 /* section types */ 711d29b2c44Sab196087 ELFEDIT_CONST_SHT_SYMTAB = 7, /* ELF SHT_SYMTAB */ 712d29b2c44Sab196087 ELFEDIT_CONST_SHT_DYNSYM = 8, /* ELF SHT_DYNSYM */ 713d29b2c44Sab196087 ELFEDIT_CONST_SHT_LDYNSYM = 9, /* ELF SHT_SUNW_LDYNSYM */ 714d29b2c44Sab196087 ELFEDIT_CONST_DT = 10, /* Dynamic tags: DT_ */ 715d29b2c44Sab196087 ELFEDIT_CONST_DF = 11, /* DT_FLAGS bits */ 716d29b2c44Sab196087 ELFEDIT_CONST_DF_P1 = 12, /* DF_POSFLAG_1 bits */ 717d29b2c44Sab196087 ELFEDIT_CONST_DF_1 = 13, /* DT_FLAGS_1 bits */ 718d29b2c44Sab196087 ELFEDIT_CONST_DTF_1 = 14, /* DT_FEATURE_1 bits */ 719d29b2c44Sab196087 ELFEDIT_CONST_EI = 15, /* ELF header e_ident indexes */ 720d29b2c44Sab196087 ELFEDIT_CONST_ET = 16, /* Ehdr obj type */ 721d29b2c44Sab196087 ELFEDIT_CONST_ELFCLASS = 17, /* Ehdr wordsize (32,64) */ 722d29b2c44Sab196087 ELFEDIT_CONST_ELFDATA = 18, /* Ehdr endian */ 723d29b2c44Sab196087 ELFEDIT_CONST_EF = 19, /* Ehdr flags */ 724d29b2c44Sab196087 ELFEDIT_CONST_EV = 20, /* Ehdr version */ 725d29b2c44Sab196087 ELFEDIT_CONST_EM = 21, /* Ehdr machine */ 726d29b2c44Sab196087 ELFEDIT_CONST_ELFOSABI = 22, /* Ehdr ABI */ 727d29b2c44Sab196087 ELFEDIT_CONST_PT = 23, /* Phdr type */ 728d29b2c44Sab196087 ELFEDIT_CONST_PF = 24, /* Phdr flags */ 729d29b2c44Sab196087 ELFEDIT_CONST_SHF = 25, /* Shdr flags */ 730d29b2c44Sab196087 ELFEDIT_CONST_STB = 26, /* Sym binding */ 731d29b2c44Sab196087 ELFEDIT_CONST_STT = 27, /* Sym type */ 732d29b2c44Sab196087 ELFEDIT_CONST_STV = 28, /* Sym visibility */ 733d29b2c44Sab196087 ELFEDIT_CONST_SYMINFO_BT = 29, /* Syminfo boundto */ 734d29b2c44Sab196087 ELFEDIT_CONST_SYMINFO_FLG = 30, /* Syminfo flags */ 735d29b2c44Sab196087 ELFEDIT_CONST_CA = 31, /* Capabilities tags: CA_ */ 736d29b2c44Sab196087 ELFEDIT_CONST_AV_386 = 32, /* X86 hardware caps */ 737d29b2c44Sab196087 ELFEDIT_CONST_AV_SPARC = 33, /* sparc hardware caps */ 738d29b2c44Sab196087 ELFEDIT_CONST_SF1_SUNW = 34, /* software capabilities */ 739d29b2c44Sab196087 } elfedit_const_t; 740d29b2c44Sab196087 741d29b2c44Sab196087 /* 742d29b2c44Sab196087 * Given an elfedit_const_t, return the array of elfedit_atoui_sym_t 743d29b2c44Sab196087 * entries that it represents. 744d29b2c44Sab196087 */ 745d29b2c44Sab196087 extern elfedit_atoui_sym_t *elfedit_const_to_atoui(elfedit_const_t const_type); 746d29b2c44Sab196087 747d29b2c44Sab196087 /* 748d29b2c44Sab196087 * Return the elfedit_atoui_t array that corresponds to the 749d29b2c44Sab196087 * CA_SUNW_HW_1 hardware capabiliies field for a given 750d29b2c44Sab196087 * machine type. 751d29b2c44Sab196087 */ 752d29b2c44Sab196087 extern elfedit_atoui_sym_t *elfedit_mach_sunw_hw1_to_atoui(int mach); 753d29b2c44Sab196087 754d29b2c44Sab196087 /* 755d29b2c44Sab196087 * ato[u]i and const routines, used to turn strings into numeric values, 756d29b2c44Sab196087 * with support for mapping symbol names to numbers, and range checking. 757d29b2c44Sab196087 */ 758d29b2c44Sab196087 extern elfedit_atoi_t elfedit_atoi(const char *str, 759d29b2c44Sab196087 const elfedit_atoi_sym_t *sym); 760d29b2c44Sab196087 extern elfedit_atoui_t elfedit_atoui(const char *str, 761d29b2c44Sab196087 const elfedit_atoui_sym_t *sym); 762d29b2c44Sab196087 extern elfedit_atoui_t elfedit_atoconst(const char *str, 763d29b2c44Sab196087 elfedit_const_t const_type); 764d29b2c44Sab196087 765d29b2c44Sab196087 extern int elfedit_atoi2(const char *str, const elfedit_atoi_sym_t *sym, 766d29b2c44Sab196087 elfedit_atoi_t *v); 767d29b2c44Sab196087 extern int elfedit_atoui2(const char *str, const elfedit_atoui_sym_t *sym, 768d29b2c44Sab196087 elfedit_atoui_t *); 769d29b2c44Sab196087 extern int elfedit_atoconst2(const char *str, elfedit_const_t const_type, 770d29b2c44Sab196087 elfedit_atoui_t *); 771d29b2c44Sab196087 772d29b2c44Sab196087 extern elfedit_atoi_t elfedit_atoi_range(const char *str, 773d29b2c44Sab196087 const char *item_name, elfedit_atoi_t min, elfedit_atoi_t max, 774d29b2c44Sab196087 const elfedit_atoi_sym_t *sym); 775d29b2c44Sab196087 extern elfedit_atoui_t elfedit_atoui_range(const char *str, 776d29b2c44Sab196087 const char *item_name, elfedit_atoui_t min, elfedit_atoui_t max, 777d29b2c44Sab196087 const elfedit_atoui_sym_t *sym); 778d29b2c44Sab196087 extern elfedit_atoui_t elfedit_atoconst_range(const char *str, 779d29b2c44Sab196087 const char *item_name, elfedit_atoui_t min, elfedit_atoui_t max, 780d29b2c44Sab196087 elfedit_const_t const_type); 781d29b2c44Sab196087 782d29b2c44Sab196087 extern int elfedit_atoi_range2(const char *str, elfedit_atoi_t min, 783d29b2c44Sab196087 elfedit_atoi_t max, const elfedit_atoi_sym_t *sym, elfedit_atoi_t *v); 784d29b2c44Sab196087 extern int elfedit_atoui_range2(const char *str, elfedit_atoui_t min, 785d29b2c44Sab196087 elfedit_atoui_t max, const elfedit_atoui_sym_t *sym, elfedit_atoui_t *v); 786d29b2c44Sab196087 extern int elfedit_atoconst_range2(const char *str, elfedit_atoui_t min, 787d29b2c44Sab196087 elfedit_atoui_t max, elfedit_const_t const_type, elfedit_atoui_t *v); 788d29b2c44Sab196087 789d29b2c44Sab196087 extern const char *elfedit_atoi_value_to_str(const elfedit_atoi_sym_t *sym, 790d29b2c44Sab196087 elfedit_atoi_t value, int required); 791d29b2c44Sab196087 extern const char *elfedit_atoui_value_to_str(const elfedit_atoui_sym_t *sym, 792d29b2c44Sab196087 elfedit_atoui_t value, int required); 793d29b2c44Sab196087 extern const char *elfedit_atoconst_value_to_str(elfedit_const_t const_type, 794d29b2c44Sab196087 elfedit_atoui_t value, int required); 795d29b2c44Sab196087 796d29b2c44Sab196087 extern void elfedit_cpl_atoi(void *cpldata, const elfedit_atoi_sym_t *sym); 797d29b2c44Sab196087 extern void elfedit_cpl_atoui(void *cpldata, const elfedit_atoui_sym_t *sym); 798d29b2c44Sab196087 extern void elfedit_cpl_atoconst(void *cpldata, elfedit_const_t const_type); 799d29b2c44Sab196087 800d29b2c44Sab196087 801d29b2c44Sab196087 /* 802d29b2c44Sab196087 * Convenience functions built on top of the ato[u]i routines. 803d29b2c44Sab196087 */ 804d29b2c44Sab196087 extern int elfedit_atobool(const char *str, const char *item_name); 805d29b2c44Sab196087 extern elfedit_atoui_t elfedit_atoshndx(const char *str, size_t shnum); 806d29b2c44Sab196087 807d29b2c44Sab196087 808d29b2c44Sab196087 /* 809d29b2c44Sab196087 * elfedit provides a getopt utility for use by the module commands. 810d29b2c44Sab196087 * elfedit_getopt_state_t is the state block used by elfedit_getopt(). 811d29b2c44Sab196087 * elfedit_getopt_ret_t is the definition of the values returned to 812d29b2c44Sab196087 * the user by elfedit_getopt() when an option is matched. Elfedit 813d29b2c44Sab196087 * getopt processing is done as follows: 814d29b2c44Sab196087 * 815d29b2c44Sab196087 * 1) The caller initializes an elfedit_getopt_state_t struct via 816d29b2c44Sab196087 * a call to elfedit_getopt_init(). The contents of this structure 817d29b2c44Sab196087 * must not be accessed by the caller, as they are all private and 818d29b2c44Sab196087 * subject to change. 819d29b2c44Sab196087 * 2) Repeated calls are made to elfedit_getopt(), as long as it returns 820d29b2c44Sab196087 * a non-NULL pointer to an elfedit_getopt_ret_t structure. If the 821d29b2c44Sab196087 * matched option has a value (ELFEDIT_CMDOA_F_VALUE), then the gor_value 822d29b2c44Sab196087 * field contains the pointer to the string. Otherwise, gor_value is NULL. 823d29b2c44Sab196087 * 3) As elfedit_getopt() consumes optional arguments from the argc/argv 824d29b2c44Sab196087 * passed to elfedit_getopt_init(), it adjusts argc/argc to skip over 825d29b2c44Sab196087 * them. Once elfedit_getopt() returns NULL to indicate that there are no 826d29b2c44Sab196087 * more options to match, argc/argv have been adjusted so that they 827d29b2c44Sab196087 * reference the plain arguments. 828d29b2c44Sab196087 */ 829d29b2c44Sab196087 typedef struct { 830d29b2c44Sab196087 elfedit_cmd_oa_mask_t gor_idmask; /* oa_idmask from matching */ 831d29b2c44Sab196087 /* elfedit_cmd_optarg_t. Can be */ 832d29b2c44Sab196087 /* used to quickly identify opt */ 833d29b2c44Sab196087 const char *gor_value; /* Opt value if ELFEDIT_CMDOA_F_VALUE */ 834d29b2c44Sab196087 /* Otherwise, NULL */ 835d29b2c44Sab196087 } elfedit_getopt_ret_t; 836d29b2c44Sab196087 typedef struct { 837d29b2c44Sab196087 int *go_argc; /* Pointer to # of options */ 838d29b2c44Sab196087 const char ***go_argv; /* Ptr to array of opt strs */ 839d29b2c44Sab196087 elfedit_cmd_optarg_t *go_optarg; /* Array of allowed options */ 840d29b2c44Sab196087 elfedit_cmd_oa_mask_t go_idmask; /* Combined id masks of all */ 841d29b2c44Sab196087 /* seen options */ 842d29b2c44Sab196087 int go_done; /* True if last option seen */ 843d29b2c44Sab196087 const char *go_sglgrp; /* Group of 1-letter opts */ 844d29b2c44Sab196087 elfedit_getopt_ret_t go_ret; /* Data returned to user */ 845d29b2c44Sab196087 } elfedit_getopt_state_t; 846d29b2c44Sab196087 847d29b2c44Sab196087 848d29b2c44Sab196087 849d29b2c44Sab196087 /* 850d29b2c44Sab196087 * getopt related routines 851d29b2c44Sab196087 */ 852d29b2c44Sab196087 extern void elfedit_getopt_init(elfedit_getopt_state_t *, 853d29b2c44Sab196087 int *, const char ***); 854d29b2c44Sab196087 extern elfedit_getopt_ret_t *elfedit_getopt(elfedit_getopt_state_t *); 855d29b2c44Sab196087 856d29b2c44Sab196087 857d29b2c44Sab196087 858d29b2c44Sab196087 /* 859d29b2c44Sab196087 * Additional utility functions exported for use by modules 860d29b2c44Sab196087 */ 861d29b2c44Sab196087 extern void elfedit_array_elts_delete(const char *name_str, void *data_start, 862d29b2c44Sab196087 size_t entsize, size_t num_ent, size_t start_ndx, size_t cnt); 863d29b2c44Sab196087 864d29b2c44Sab196087 extern void elfedit_array_elts_move(const char *name_str, void *data_start, 865d29b2c44Sab196087 size_t entsize, size_t num_ent, size_t srcndx, 866d29b2c44Sab196087 size_t dstndx, size_t cnt, void *scr_item); 867d29b2c44Sab196087 868d29b2c44Sab196087 extern int elfedit_bits_set(u_longlong_t v, int sizeof_orig_v); 869d29b2c44Sab196087 870d29b2c44Sab196087 extern void elfedit32_dyn_elt_init(elfedit32_dyn_elt_t *dyn_elt); 871d29b2c44Sab196087 extern void elfedit64_dyn_elt_init(elfedit64_dyn_elt_t *dyn_elt); 872d29b2c44Sab196087 873d29b2c44Sab196087 extern void elfedit32_dyn_elt_save(elfedit32_dyn_elt_t *elt, Elf32_Word ndx, 874d29b2c44Sab196087 Elf32_Dyn *dyn); 875d29b2c44Sab196087 extern void elfedit64_dyn_elt_save(elfedit64_dyn_elt_t *elt, Elf64_Word ndx, 876d29b2c44Sab196087 Elf64_Dyn *dyn); 877d29b2c44Sab196087 878d29b2c44Sab196087 const char *elfedit32_dyn_offset_to_str(elfedit32_section_t *strsec, 879d29b2c44Sab196087 elfedit32_dyn_elt_t *dynelt); 880d29b2c44Sab196087 const char *elfedit64_dyn_offset_to_str(elfedit64_section_t *strsec, 881d29b2c44Sab196087 elfedit64_dyn_elt_t *dynelt); 882d29b2c44Sab196087 883d29b2c44Sab196087 extern int elfedit32_dynstr_getpad(elfedit32_section_t *dynsec, 884d29b2c44Sab196087 elfedit32_dyn_elt_t *dyn_strpad); 885d29b2c44Sab196087 extern int elfedit64_dynstr_getpad(elfedit64_section_t *dynsec, 886d29b2c44Sab196087 elfedit64_dyn_elt_t *dyn_strpad); 887d29b2c44Sab196087 888d29b2c44Sab196087 extern Elf32_Word elfedit32_dynstr_insert(elfedit32_section_t *dynsec, 889d29b2c44Sab196087 elfedit32_section_t *strsec, elfedit32_dyn_elt_t *dyn_strpad, 890d29b2c44Sab196087 const char *str); 891d29b2c44Sab196087 extern Elf64_Word elfedit64_dynstr_insert(elfedit64_section_t *dynsec, 892d29b2c44Sab196087 elfedit64_section_t *strsec, elfedit64_dyn_elt_t *dyn_strpad, 893d29b2c44Sab196087 const char *str); 894d29b2c44Sab196087 895d29b2c44Sab196087 extern void elfedit32_modified_data(elfedit32_section_t *s); 896d29b2c44Sab196087 extern void elfedit64_modified_data(elfedit64_section_t *s); 897d29b2c44Sab196087 898d29b2c44Sab196087 extern void elfedit32_modified_ehdr(elfedit32_obj_state_t *obj_state); 899d29b2c44Sab196087 extern void elfedit64_modified_ehdr(elfedit64_obj_state_t *obj_state); 900d29b2c44Sab196087 901d29b2c44Sab196087 extern void elfedit32_modified_phdr(elfedit32_obj_state_t *obj_state); 902d29b2c44Sab196087 extern void elfedit64_modified_phdr(elfedit64_obj_state_t *obj_state); 903d29b2c44Sab196087 904d29b2c44Sab196087 extern void elfedit32_modified_shdr(elfedit32_section_t *s); 905d29b2c44Sab196087 extern void elfedit64_modified_shdr(elfedit64_section_t *s); 906d29b2c44Sab196087 907d29b2c44Sab196087 extern Elf32_Word elfedit32_name_to_shndx(elfedit32_obj_state_t *obj_state, 908d29b2c44Sab196087 const char *shnam); 909d29b2c44Sab196087 extern Elf64_Word elfedit64_name_to_shndx(elfedit64_obj_state_t *obj_state, 910d29b2c44Sab196087 const char *shnam); 911d29b2c44Sab196087 912d29b2c44Sab196087 extern Elf32_Word elfedit32_type_to_shndx(elfedit32_obj_state_t *obj_state, 913d29b2c44Sab196087 Elf32_Word shtype); 914d29b2c44Sab196087 extern Elf64_Word elfedit64_type_to_shndx(elfedit64_obj_state_t *obj_state, 915d29b2c44Sab196087 Elf64_Word shtype); 916d29b2c44Sab196087 917d29b2c44Sab196087 extern int elfedit32_name_to_symndx(elfedit32_section_t *symsec, 918d29b2c44Sab196087 elfedit32_section_t *strsec, const char *name, elfedit_msg_t msg_type, 919d29b2c44Sab196087 Elf32_Word *ret_symndx); 920d29b2c44Sab196087 extern int elfedit64_name_to_symndx(elfedit64_section_t *symsec, 921d29b2c44Sab196087 elfedit64_section_t *strsec, const char *name, elfedit_msg_t msg_type, 922d29b2c44Sab196087 Elf64_Word *ret_symndx); 923d29b2c44Sab196087 924d29b2c44Sab196087 extern const char *elfedit32_offset_to_str(elfedit32_section_t *strsec, 925d29b2c44Sab196087 Elf32_Word offset, elfedit_msg_t msg_type, int debug_msg); 926d29b2c44Sab196087 extern const char *elfedit64_offset_to_str(elfedit64_section_t *strsec, 927d29b2c44Sab196087 Elf64_Word offset, elfedit_msg_t msg_type, int debug_msg); 928d29b2c44Sab196087 929d29b2c44Sab196087 extern int elfedit32_sec_findstr(elfedit32_section_t *sec, Elf32_Word tail_ign, 930d29b2c44Sab196087 const char *str, Elf32_Word *ret_offset); 931d29b2c44Sab196087 extern int elfedit64_sec_findstr(elfedit64_section_t *sec, Elf64_Word tail_ign, 932d29b2c44Sab196087 const char *str, Elf64_Word *ret_offset); 933d29b2c44Sab196087 934*cce0e03bSab196087 extern elfedit32_section_t *elfedit32_sec_get( 935*cce0e03bSab196087 elfedit32_obj_state_t *obj_state, Elf32_Word shndx); 936*cce0e03bSab196087 extern elfedit64_section_t *elfedit64_sec_get( 937*cce0e03bSab196087 elfedit64_obj_state_t *obj_state, Elf64_Word shndx); 938*cce0e03bSab196087 939d29b2c44Sab196087 extern elfedit32_section_t *elfedit32_sec_getcap( 940d29b2c44Sab196087 elfedit32_obj_state_t *obj_state, Elf32_Cap **cap, Elf32_Word *num); 941d29b2c44Sab196087 extern elfedit64_section_t *elfedit64_sec_getcap( 942d29b2c44Sab196087 elfedit64_obj_state_t *obj_state, Elf64_Cap **cap, Elf64_Word *num); 943d29b2c44Sab196087 944d29b2c44Sab196087 extern elfedit32_section_t *elfedit32_sec_getdyn( 945d29b2c44Sab196087 elfedit32_obj_state_t *obj_state, Elf32_Dyn **dyn, Elf32_Word *num); 946d29b2c44Sab196087 extern elfedit64_section_t *elfedit64_sec_getdyn( 947d29b2c44Sab196087 elfedit64_obj_state_t *obj_state, Elf64_Dyn **dyn, Elf64_Word *num); 948d29b2c44Sab196087 949d29b2c44Sab196087 extern elfedit32_section_t *elfedit32_sec_getstr( 950d29b2c44Sab196087 elfedit32_obj_state_t *obj_state, Elf32_Word shndx); 951d29b2c44Sab196087 extern elfedit64_section_t *elfedit64_sec_getstr( 952d29b2c44Sab196087 elfedit64_obj_state_t *obj_state, Elf64_Word shndx); 953d29b2c44Sab196087 954d29b2c44Sab196087 extern elfedit32_section_t *elfedit32_sec_getsyminfo( 955d29b2c44Sab196087 elfedit32_obj_state_t *obj_state, Elf32_Syminfo **syminfo, Elf32_Word *num); 956d29b2c44Sab196087 extern elfedit64_section_t *elfedit64_sec_getsyminfo( 957d29b2c44Sab196087 elfedit64_obj_state_t *obj_state, Elf64_Syminfo **syminfo, Elf64_Word *num); 958d29b2c44Sab196087 959d29b2c44Sab196087 extern elfedit32_section_t *elfedit32_sec_getsymtab( 960d29b2c44Sab196087 elfedit32_obj_state_t *obj_state, int by_index, Elf32_Word index, 961d29b2c44Sab196087 const char *name, Elf32_Sym **sym, Elf32_Word *num, 962d29b2c44Sab196087 elfedit32_symtab_t **aux_info); 963d29b2c44Sab196087 extern elfedit64_section_t *elfedit64_sec_getsymtab( 964d29b2c44Sab196087 elfedit64_obj_state_t *obj_state, int by_index, Elf64_Word index, 965d29b2c44Sab196087 const char *name, Elf64_Sym **sym, Elf64_Word *num, 966d29b2c44Sab196087 elfedit64_symtab_t **aux_info); 967d29b2c44Sab196087 968d29b2c44Sab196087 extern elfedit32_section_t *elfedit32_sec_getversym( 969d29b2c44Sab196087 elfedit32_obj_state_t *obj_state, elfedit32_section_t *symsec, 970d29b2c44Sab196087 Elf32_Versym **versym, Elf32_Word *num); 971d29b2c44Sab196087 extern elfedit64_section_t *elfedit64_sec_getversym( 972d29b2c44Sab196087 elfedit64_obj_state_t *obj_state, elfedit64_section_t *symsec, 973d29b2c44Sab196087 Elf64_Versym **versym, Elf64_Word *num); 974d29b2c44Sab196087 975d29b2c44Sab196087 extern elfedit32_section_t *elfedit32_sec_getxshndx( 976d29b2c44Sab196087 elfedit32_obj_state_t *obj_state, elfedit32_section_t *symsec, 977d29b2c44Sab196087 Elf32_Word **xshndx, Elf32_Word *num); 978d29b2c44Sab196087 extern elfedit64_section_t *elfedit64_sec_getxshndx( 979d29b2c44Sab196087 elfedit64_obj_state_t *obj_state, elfedit64_section_t *symsec, 980d29b2c44Sab196087 Elf64_Word **xshndx, Elf64_Word *num); 981d29b2c44Sab196087 982d29b2c44Sab196087 extern int elfedit32_sec_issymtab(elfedit32_section_t *sec, int issue_err, 983d29b2c44Sab196087 elfedit_atoui_sym_t **atoui_list); 984d29b2c44Sab196087 extern int elfedit64_sec_issymtab(elfedit64_section_t *sec, int issue_err, 985d29b2c44Sab196087 elfedit_atoui_sym_t **atoui_list); 986d29b2c44Sab196087 987d29b2c44Sab196087 extern const char *elfedit32_sec_msgprefix(elfedit32_section_t *sec); 988d29b2c44Sab196087 extern const char *elfedit64_sec_msgprefix(elfedit64_section_t *sec); 989d29b2c44Sab196087 990d29b2c44Sab196087 extern const char *elfedit32_shndx_to_name(elfedit32_obj_state_t *obj_state, 991d29b2c44Sab196087 Elf32_Word shndx); 992d29b2c44Sab196087 extern const char *elfedit64_shndx_to_name(elfedit64_obj_state_t *obj_state, 993d29b2c44Sab196087 Elf64_Word shndx); 994d29b2c44Sab196087 995d29b2c44Sab196087 extern Elf32_Word elfedit32_strtab_insert(elfedit32_obj_state_t *obj_state, 996d29b2c44Sab196087 elfedit32_section_t *strsec, elfedit32_section_t *dynsec, const char *str); 997d29b2c44Sab196087 extern Elf64_Word elfedit64_strtab_insert(elfedit64_obj_state_t *obj_state, 998d29b2c44Sab196087 elfedit64_section_t *strsec, elfedit64_section_t *dynsec, const char *str); 999d29b2c44Sab196087 1000d29b2c44Sab196087 extern void elfedit32_strtab_insert_test(elfedit32_obj_state_t *obj_state, 1001d29b2c44Sab196087 elfedit32_section_t *strsec, elfedit32_section_t *dynsec, const char *str); 1002d29b2c44Sab196087 extern void elfedit64_strtab_insert_test(elfedit64_obj_state_t *obj_state, 1003d29b2c44Sab196087 elfedit64_section_t *strsec, elfedit64_section_t *dynsec, const char *str); 1004d29b2c44Sab196087 1005d29b2c44Sab196087 extern Elf32_Word elfedit32_type_to_shndx(elfedit32_obj_state_t *obj_state, 1006d29b2c44Sab196087 Elf32_Word shtype); 1007d29b2c44Sab196087 extern Elf64_Word elfedit64_type_to_shndx(elfedit64_obj_state_t *obj_state, 1008d29b2c44Sab196087 Elf64_Word shtype); 1009d29b2c44Sab196087 1010d29b2c44Sab196087 1011d29b2c44Sab196087 1012d29b2c44Sab196087 /* 1013d29b2c44Sab196087 * Map the generic names for each of the ELFCLASS specific routines 1014d29b2c44Sab196087 * above to reference the proper routine for the current compilation. 1015d29b2c44Sab196087 */ 1016d29b2c44Sab196087 #ifdef _ELF64 1017d29b2c44Sab196087 #define elfedit_dyn_elt_init elfedit64_dyn_elt_init 1018d29b2c44Sab196087 #define elfedit_dyn_elt_save elfedit64_dyn_elt_save 1019d29b2c44Sab196087 #define elfedit_dyn_offset_to_str elfedit64_dyn_offset_to_str 1020d29b2c44Sab196087 #define elfedit_dynstr_getpad elfedit64_dynstr_getpad 1021d29b2c44Sab196087 #define elfedit_dynstr_insert elfedit64_dynstr_insert 1022d29b2c44Sab196087 #define elfedit_modified_data elfedit64_modified_data 1023d29b2c44Sab196087 #define elfedit_modified_ehdr elfedit64_modified_ehdr 1024d29b2c44Sab196087 #define elfedit_modified_phdr elfedit64_modified_phdr 1025d29b2c44Sab196087 #define elfedit_modified_shdr elfedit64_modified_shdr 1026d29b2c44Sab196087 #define elfedit_name_to_shndx elfedit64_name_to_shndx 1027d29b2c44Sab196087 #define elfedit_name_to_symndx elfedit64_name_to_symndx 1028d29b2c44Sab196087 #define elfedit_offset_to_str elfedit64_offset_to_str 1029d29b2c44Sab196087 #define elfedit_sec_findstr elfedit64_sec_findstr 1030*cce0e03bSab196087 #define elfedit_sec_get elfedit64_sec_get 1031d29b2c44Sab196087 #define elfedit_sec_getcap elfedit64_sec_getcap 1032d29b2c44Sab196087 #define elfedit_sec_getdyn elfedit64_sec_getdyn 1033d29b2c44Sab196087 #define elfedit_sec_getstr elfedit64_sec_getstr 1034d29b2c44Sab196087 #define elfedit_sec_getsyminfo elfedit64_sec_getsyminfo 1035d29b2c44Sab196087 #define elfedit_sec_getsymtab elfedit64_sec_getsymtab 1036d29b2c44Sab196087 #define elfedit_sec_getversym elfedit64_sec_getversym 1037d29b2c44Sab196087 #define elfedit_sec_getxshndx elfedit64_sec_getxshndx 1038d29b2c44Sab196087 #define elfedit_sec_issymtab elfedit64_sec_issymtab 1039d29b2c44Sab196087 #define elfedit_shndx_to_name elfedit64_shndx_to_name 1040d29b2c44Sab196087 #define elfedit_sec_msgprefix elfedit64_sec_msgprefix 1041d29b2c44Sab196087 #define elfedit_strtab_insert elfedit64_strtab_insert 1042d29b2c44Sab196087 #define elfedit_strtab_insert_test elfedit64_strtab_insert_test 1043d29b2c44Sab196087 #define elfedit_type_to_shndx elfedit64_type_to_shndx 1044d29b2c44Sab196087 #else 1045d29b2c44Sab196087 #define elfedit_dyn_elt_init elfedit32_dyn_elt_init 1046d29b2c44Sab196087 #define elfedit_dyn_elt_save elfedit32_dyn_elt_save 1047d29b2c44Sab196087 #define elfedit_dyn_offset_to_str elfedit32_dyn_offset_to_str 1048d29b2c44Sab196087 #define elfedit_dynstr_getpad elfedit32_dynstr_getpad 1049d29b2c44Sab196087 #define elfedit_dynstr_insert elfedit32_dynstr_insert 1050d29b2c44Sab196087 #define elfedit_modified_data elfedit32_modified_data 1051d29b2c44Sab196087 #define elfedit_modified_ehdr elfedit32_modified_ehdr 1052d29b2c44Sab196087 #define elfedit_modified_phdr elfedit32_modified_phdr 1053d29b2c44Sab196087 #define elfedit_modified_shdr elfedit32_modified_shdr 1054d29b2c44Sab196087 #define elfedit_name_to_shndx elfedit32_name_to_shndx 1055d29b2c44Sab196087 #define elfedit_name_to_symndx elfedit32_name_to_symndx 1056d29b2c44Sab196087 #define elfedit_offset_to_str elfedit32_offset_to_str 1057d29b2c44Sab196087 #define elfedit_sec_findstr elfedit32_sec_findstr 1058*cce0e03bSab196087 #define elfedit_sec_get elfedit32_sec_get 1059d29b2c44Sab196087 #define elfedit_sec_getcap elfedit32_sec_getcap 1060d29b2c44Sab196087 #define elfedit_sec_getdyn elfedit32_sec_getdyn 1061d29b2c44Sab196087 #define elfedit_sec_getstr elfedit32_sec_getstr 1062d29b2c44Sab196087 #define elfedit_sec_getsyminfo elfedit32_sec_getsyminfo 1063d29b2c44Sab196087 #define elfedit_sec_getsymtab elfedit32_sec_getsymtab 1064d29b2c44Sab196087 #define elfedit_sec_getversym elfedit32_sec_getversym 1065d29b2c44Sab196087 #define elfedit_sec_getxshndx elfedit32_sec_getxshndx 1066d29b2c44Sab196087 #define elfedit_sec_issymtab elfedit32_sec_issymtab 1067d29b2c44Sab196087 #define elfedit_shndx_to_name elfedit32_shndx_to_name 1068d29b2c44Sab196087 #define elfedit_sec_msgprefix elfedit32_sec_msgprefix 1069d29b2c44Sab196087 #define elfedit_strtab_insert elfedit32_strtab_insert 1070d29b2c44Sab196087 #define elfedit_strtab_insert_test elfedit32_strtab_insert_test 1071d29b2c44Sab196087 #define elfedit_type_to_shndx elfedit32_type_to_shndx 1072d29b2c44Sab196087 #endif 1073d29b2c44Sab196087 1074d29b2c44Sab196087 1075d29b2c44Sab196087 #ifdef __cplusplus 1076d29b2c44Sab196087 } 1077d29b2c44Sab196087 #endif 1078d29b2c44Sab196087 1079d29b2c44Sab196087 #endif /* _ELFEDIT_H */ 1080