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 /* 23cce0e03bSab196087 * 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. 349*55ef6355Sab196087 * elfedit_cpl_ndx() - enter numeric index as a match 350d29b2c44Sab196087 * 351d29b2c44Sab196087 * The completion function is passed the following arguments: 352d29b2c44Sab196087 * 353d29b2c44Sab196087 * obj_state - Object state. Will be NULL if elfedit session does not 354d29b2c44Sab196087 * have an active object. The completion function must test 355d29b2c44Sab196087 * the pointer before using it. 356d29b2c44Sab196087 * cpldata - Completion data, to be passed to elfedit_cpl_match() 357d29b2c44Sab196087 * or the helper functions built on it to register alternative 358d29b2c44Sab196087 * strings. 359d29b2c44Sab196087 * argc, argv - The tokens from the start of the line throught 360d29b2c44Sab196087 * the one needing completion, which will always 361d29b2c44Sab196087 * be cmdcpl_argv[cmdcpl_argc - 1]. 362d29b2c44Sab196087 * num_opt - A count of the optional arguments (those starting with 363d29b2c44Sab196087 * '-' at the beginning of argv. This means that argv[num_opt] 364d29b2c44Sab196087 * is the first plain argument, and the 1-based positional 365d29b2c44Sab196087 * number of the plain argument for which command completion 366d29b2c44Sab196087 * is needed is (argc - num_opt). 367d29b2c44Sab196087 */ 368d29b2c44Sab196087 typedef void elfedit32_cmdcpl_func_t(elfedit32_obj_state_t *state, 369d29b2c44Sab196087 void *cpldata, int argc, const char *argv[], int num_opt); 370d29b2c44Sab196087 typedef void elfedit64_cmdcpl_func_t(elfedit64_obj_state_t *state, 371d29b2c44Sab196087 void *cpldata, int argc, const char *argv[], int num_opt); 372d29b2c44Sab196087 #ifdef _ELF64 373d29b2c44Sab196087 #define elfedit_cmdcpl_func_t elfedit64_cmdcpl_func_t 374d29b2c44Sab196087 #else 375d29b2c44Sab196087 #define elfedit_cmdcpl_func_t elfedit32_cmdcpl_func_t 376d29b2c44Sab196087 #endif 377d29b2c44Sab196087 378d29b2c44Sab196087 379d29b2c44Sab196087 380d29b2c44Sab196087 381d29b2c44Sab196087 /* 382d29b2c44Sab196087 * Command option/argument descriptor. These structures 383d29b2c44Sab196087 * are used to represent each option and plain argument accepted 384d29b2c44Sab196087 * by a command, via the cmd_opt and cmd_args fields in the 385d29b2c44Sab196087 * command definition (elfedit_cmd_t). Each descriptor consists 386d29b2c44Sab196087 * of a name, a help string (formatted for display via sys:help), 387d29b2c44Sab196087 * and a flags field that conveys extra information about the 388d29b2c44Sab196087 * item: 389d29b2c44Sab196087 * 390d29b2c44Sab196087 * ELFEDIT_CMDOA_F_OPT 391d29b2c44Sab196087 * The item is optional. This flag is implicit for options 392d29b2c44Sab196087 * and need only be set for plain arguments. 393d29b2c44Sab196087 * 394d29b2c44Sab196087 * ELFEDIT_CMDOA_F_VALUE 395d29b2c44Sab196087 * The item has a value, which is found in the following 396d29b2c44Sab196087 * item. This flag only has meaning for options, and should 397d29b2c44Sab196087 * not be set for plain arguments. The descriptor for the 398d29b2c44Sab196087 * value is found in the next array element, and only the 399d29b2c44Sab196087 * oa_name field is used (the other should be set t 0). 400d29b2c44Sab196087 * 401d29b2c44Sab196087 * ELFEDIT_CMDOA_F_MULT 402d29b2c44Sab196087 * More than one of the specified items may be specified 403d29b2c44Sab196087 * 404d29b2c44Sab196087 * ELFEDIT_CMDOA_F_INHERIT 405d29b2c44Sab196087 * This is an item for which a common definition exists. 406d29b2c44Sab196087 * Elfedit will substitute the standard values for the 407d29b2c44Sab196087 * name, help text, and flags. This enforces consistency 408d29b2c44Sab196087 * in documentation, plus it is easier for the module author. 409d29b2c44Sab196087 * When ELFEDIT_CMDOA_F_INHERIT is set: 410d29b2c44Sab196087 * - oa_name should be set to one of the ELFEDIT_STDOA_ 411d29b2c44Sab196087 * values to specifiy which standard item is being 412d29b2c44Sab196087 * inherited. 413d29b2c44Sab196087 * - oa_help must be set to NULL. 414d29b2c44Sab196087 * - It is an error to set any other flags with 415d29b2c44Sab196087 * ELFEDIT_CMDOA_F_INHERIT. 416d29b2c44Sab196087 * - oa_idmask and oa_excmask are used in the normal way. 417d29b2c44Sab196087 * 418d29b2c44Sab196087 * The oa_idmask and oa_excmask fields are used to identify options, 419d29b2c44Sab196087 * and to support mutual exclusion (when two or more options cannot be 420d29b2c44Sab196087 * used together). They are ignored for arguments, and should be set to 0. 421d29b2c44Sab196087 * oa_idmask is used to uniquely identify each item. When elfedit_getopt() 422d29b2c44Sab196087 * matches an option, it returns the value of oa_idmask to the caller to 423d29b2c44Sab196087 * indicate which option was matched. elfedit enforces the following rules 424d29b2c44Sab196087 * for oa_idmask, and will refuse to load a module that does not follow them: 425d29b2c44Sab196087 * - The value of oa_idmask must be 0, or have a value that 426d29b2c44Sab196087 * is a power of 2 (i.e. only has one bit set). 427d29b2c44Sab196087 * - Each item that sets a non-0 value for oa_idmask must have 428d29b2c44Sab196087 * a unique value. 429d29b2c44Sab196087 * - If oa_idmask is 0, oa_excmask must be 0 also. 430d29b2c44Sab196087 * - oa_excmask is set to 0 if an item is not mutually exclusive 431d29b2c44Sab196087 * to any other item. Otherwise, it should set the bit 432d29b2c44Sab196087 * values representing the items it is mutually exclusive to. 433d29b2c44Sab196087 * - An oa_idmask value of 0 can be used for any item that 434d29b2c44Sab196087 * the module does not need to identify, and which 435d29b2c44Sab196087 * is not mutually exclusive to any other item. 436d29b2c44Sab196087 * As elfedit_getopt() processes items, it maintains a bitmask combining the 437d29b2c44Sab196087 * oa_idmask fields of all the options already seen. For each option, it uses 438d29b2c44Sab196087 * oa_excmask to check for conflicts. 439d29b2c44Sab196087 * 440d29b2c44Sab196087 * note: elfedit enforces the rule that options consist of a '-' 441d29b2c44Sab196087 * character followed by at least one character when a module 442d29b2c44Sab196087 * is loaded. 443d29b2c44Sab196087 */ 444d29b2c44Sab196087 typedef enum { 445d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT = 1, /* Item is optional */ 446d29b2c44Sab196087 ELFEDIT_CMDOA_F_VALUE = 2, /* Item has a value arg following */ 447d29b2c44Sab196087 ELFEDIT_CMDOA_F_MULT = 4, /* More than one are allowed */ 448d29b2c44Sab196087 ELFEDIT_CMDOA_F_INHERIT = 8, /* Inherit definition: See above */ 449d29b2c44Sab196087 } elfedit_cmd_oa_flag_t; 450d29b2c44Sab196087 451d29b2c44Sab196087 typedef u_longlong_t elfedit_cmd_oa_mask_t; 452d29b2c44Sab196087 453d29b2c44Sab196087 typedef struct { 454d29b2c44Sab196087 const char *oa_name; /* Name of option */ 455d29b2c44Sab196087 elfedit_i18nhdl_t oa_help; /* Help text for option */ 456d29b2c44Sab196087 elfedit_cmd_oa_flag_t oa_flags; /* Additional attributes */ 457d29b2c44Sab196087 elfedit_cmd_oa_mask_t oa_idmask; /* Unique id, returned by */ 458d29b2c44Sab196087 /* elfedit_getopt */ 459d29b2c44Sab196087 /* for use by caller */ 460d29b2c44Sab196087 elfedit_cmd_oa_mask_t oa_excmask; /* Mutual exclusion mask */ 461d29b2c44Sab196087 } elfedit_cmd_optarg_t; 462d29b2c44Sab196087 463d29b2c44Sab196087 464d29b2c44Sab196087 465d29b2c44Sab196087 /* 466d29b2c44Sab196087 * These values define the standard options and arguments that a module 467d29b2c44Sab196087 * can inherit using the ELFEDIT_CMDOA_F_INHERIT flag (described above). 468d29b2c44Sab196087 * New items must be added at the end --- reordering the list will 469d29b2c44Sab196087 * require all modules to be rebuilt. 470d29b2c44Sab196087 * 471d29b2c44Sab196087 * Note: 0 cannot be used as a ELFEDIT_STDOA_ value, because a NULL 472d29b2c44Sab196087 * value of oa_name is used to terminate argument and options lists. 473d29b2c44Sab196087 * Therefore, these values start at 1. 474d29b2c44Sab196087 */ 475d29b2c44Sab196087 #define ELFEDIT_STDOA_OPT_O ((const char *) 1) /* -o ostyle */ 476d29b2c44Sab196087 #define ELFEDIT_STDOA_OPT_AND ((const char *) 2) /* -and */ 477d29b2c44Sab196087 #define ELFEDIT_STDOA_OPT_CMP ((const char *) 3) /* -cmp */ 478d29b2c44Sab196087 #define ELFEDIT_STDOA_OPT_OR ((const char *) 4) /* -or */ 479d29b2c44Sab196087 480d29b2c44Sab196087 #define ELFEDIT_NUM_STDOA 4 /* # of ELFEDIT_STDOA_ definitions */ 481d29b2c44Sab196087 482d29b2c44Sab196087 483d29b2c44Sab196087 484d29b2c44Sab196087 /* 485d29b2c44Sab196087 * Definition of a command 486d29b2c44Sab196087 * 487d29b2c44Sab196087 * This structure includes an elfedit_cmd_func_t pointer, which has 488d29b2c44Sab196087 * different definitions for different ELFCLASS. Rather than needlessly 489d29b2c44Sab196087 * complicate the code with three versions of this type, and any 490d29b2c44Sab196087 * type that uses it, we simply use the GenericClass type. elfedit 491d29b2c44Sab196087 * will always cast this to the correct type before calling a module. 492d29b2c44Sab196087 * 493d29b2c44Sab196087 * cmd_name is an array of pointers to the names for the command. 494d29b2c44Sab196087 * The "primary" name should always be first, followed by any alias 495d29b2c44Sab196087 * names. The final element of the array must be a NULL pointer, 496d29b2c44Sab196087 * which terminates the list. Every command is required to have at 497d29b2c44Sab196087 * least one name, so code is allowed to assume that the first element 498d29b2c44Sab196087 * of cmd_name is non-NULL, and contains the primary name. 499d29b2c44Sab196087 * 500d29b2c44Sab196087 * Many modules provide a "default" command, which is a command 501d29b2c44Sab196087 * that is run if only the module name is specified, followed 502d29b2c44Sab196087 * by a colon (i.e. "sym:"). The way this is implemented is to 503d29b2c44Sab196087 * give the desired default command an empty string as an alias. 504d29b2c44Sab196087 * Note that the primary name cannot be an empty string, only the 505d29b2c44Sab196087 * alias name. 506d29b2c44Sab196087 * 507d29b2c44Sab196087 * cmd_opts and cmd_args are each an array of elfedit_cmd_argdesc_t 508d29b2c44Sab196087 * structures, that describe the options and plain arguments accepted 509d29b2c44Sab196087 * by the command. These arrays are used to general help text for 510d29b2c44Sab196087 * the commands. The cmd_opts array is also used to provide command 511d29b2c44Sab196087 * completion for options. Both of these arrays are terminated by 512d29b2c44Sab196087 * a final NULL element (all fields zero). 513d29b2c44Sab196087 */ 514d29b2c44Sab196087 typedef struct { 515d29b2c44Sab196087 elfedit32_cmd_func_t *cmd_func; /* Implementation */ 516d29b2c44Sab196087 elfedit32_cmdcpl_func_t *cmd_cplfunc; /* Completion function */ 517d29b2c44Sab196087 const char **cmd_name; /* Cmd names (null term.) */ 518d29b2c44Sab196087 elfedit_i18nhdl_t cmd_desc; /* Short desc. of cmd purpose */ 519d29b2c44Sab196087 elfedit_i18nhdl_t cmd_help; /* Help text for the command */ 520d29b2c44Sab196087 elfedit_cmd_optarg_t *cmd_opt; /* Options */ 521d29b2c44Sab196087 elfedit_cmd_optarg_t *cmd_args; /* Plain arguments */ 522d29b2c44Sab196087 } elfedit32_cmd_t; 523d29b2c44Sab196087 524d29b2c44Sab196087 typedef struct { 525d29b2c44Sab196087 elfedit64_cmd_func_t *cmd_func; 526d29b2c44Sab196087 elfedit64_cmdcpl_func_t *cmd_cplfunc; 527d29b2c44Sab196087 const char **cmd_name; 528d29b2c44Sab196087 elfedit_i18nhdl_t cmd_desc; 529d29b2c44Sab196087 elfedit_i18nhdl_t cmd_help; 530d29b2c44Sab196087 elfedit_cmd_optarg_t *cmd_opt; 531d29b2c44Sab196087 elfedit_cmd_optarg_t *cmd_args; 532d29b2c44Sab196087 } elfedit64_cmd_t; 533d29b2c44Sab196087 534d29b2c44Sab196087 #ifdef _ELF64 535d29b2c44Sab196087 #define elfedit_cmd_t elfedit64_cmd_t 536d29b2c44Sab196087 #else 537d29b2c44Sab196087 #define elfedit_cmd_t elfedit32_cmd_t 538d29b2c44Sab196087 #endif 539d29b2c44Sab196087 540d29b2c44Sab196087 541d29b2c44Sab196087 542d29b2c44Sab196087 /* 543d29b2c44Sab196087 * elfedit modules version themselves so that we can alter the definition 544d29b2c44Sab196087 * of elfedit_module_t in a backward compatible way. 545d29b2c44Sab196087 */ 546d29b2c44Sab196087 typedef enum { 547d29b2c44Sab196087 ELFEDIT_VER_NONE = 0, 548d29b2c44Sab196087 ELFEDIT_VER_CURRENT = 1, 549d29b2c44Sab196087 ELFEDIT_VER_NUM = 2 550d29b2c44Sab196087 } elfedit_module_version_t; 551d29b2c44Sab196087 552d29b2c44Sab196087 553d29b2c44Sab196087 /* 554d29b2c44Sab196087 * Each module returns a pointer to an elfedit_module_t, describing 555d29b2c44Sab196087 * what commands the module provides. 556d29b2c44Sab196087 * 557d29b2c44Sab196087 * Note: mod_cmds is a NULL terminated array of command defs. This 558d29b2c44Sab196087 * means that the final element in the array should have all of its 559d29b2c44Sab196087 * fields set to NULL. 560d29b2c44Sab196087 * 561d29b2c44Sab196087 * The mod_i18nhdl_to_str function pointer is explained above 562d29b2c44Sab196087 * with the definition of elfedit_i18nhdl_t. 563d29b2c44Sab196087 */ 564d29b2c44Sab196087 typedef const char *(* elfedit_mod_i18nhdl_to_str_func_t)(elfedit_i18nhdl_t); 565d29b2c44Sab196087 566d29b2c44Sab196087 typedef struct { 567d29b2c44Sab196087 elfedit_module_version_t mod_version; /* version */ 568d29b2c44Sab196087 const char *mod_name; /* Name of module */ 569d29b2c44Sab196087 elfedit_i18nhdl_t mod_desc; /* Short desc. of mod purpose */ 570d29b2c44Sab196087 elfedit32_cmd_t *mod_cmds; /* Array of command defs */ 571d29b2c44Sab196087 /* i18n -> (char *) fcn */ 572d29b2c44Sab196087 elfedit_mod_i18nhdl_to_str_func_t mod_i18nhdl_to_str; 573d29b2c44Sab196087 } elfedit32_module_t; 574d29b2c44Sab196087 575d29b2c44Sab196087 typedef struct { 576d29b2c44Sab196087 elfedit_module_version_t mod_version; 577d29b2c44Sab196087 const char *mod_name; 578d29b2c44Sab196087 elfedit_i18nhdl_t mod_desc; 579d29b2c44Sab196087 elfedit64_cmd_t *mod_cmds; 580d29b2c44Sab196087 elfedit_mod_i18nhdl_to_str_func_t mod_i18nhdl_to_str; 581d29b2c44Sab196087 } elfedit64_module_t; 582d29b2c44Sab196087 583d29b2c44Sab196087 #ifdef _ELF64 584d29b2c44Sab196087 #define elfedit_module_t elfedit64_module_t 585d29b2c44Sab196087 #else 586d29b2c44Sab196087 #define elfedit_module_t elfedit32_module_t 587d29b2c44Sab196087 #endif 588d29b2c44Sab196087 589d29b2c44Sab196087 590d29b2c44Sab196087 /* 591d29b2c44Sab196087 * Each module is a sharable library, expected to provide a single global 592d29b2c44Sab196087 * function, named elfedit_init(), with the following prototype. 593d29b2c44Sab196087 */ 594d29b2c44Sab196087 typedef elfedit_module_t *elfedit_init_func_t(elfedit_module_version_t version); 595d29b2c44Sab196087 596d29b2c44Sab196087 597cce0e03bSab196087 /* 598cce0e03bSab196087 * Prototype for elfedit_write(), and for outfunc argument 599cce0e03bSab196087 * to elfedit_str_to_c_literal(). 600cce0e03bSab196087 */ 601cce0e03bSab196087 typedef void elfedit_write_func_t(const void *ptr, size_t size); 602d29b2c44Sab196087 603d29b2c44Sab196087 604d29b2c44Sab196087 /* 605d29b2c44Sab196087 * Core elfedit functions exported for use by modules 606d29b2c44Sab196087 */ 607d29b2c44Sab196087 extern void elfedit_command_usage(void); 608d29b2c44Sab196087 extern void elfedit_cpl_command(void *cpldata); 609d29b2c44Sab196087 extern void elfedit_cpl_match(void *cpldata, const char *str, int casefold); 610*55ef6355Sab196087 extern void elfedit_cpl_ndx(void *cpldata, uint_t ndx); 611d29b2c44Sab196087 extern void elfedit_elferr(const char *file, const char *libelf_rtn_name); 612d29b2c44Sab196087 extern elfedit_flag_t elfedit_flags(void); 613d29b2c44Sab196087 extern void *elfedit_malloc(const char *item_name, size_t size); 614d29b2c44Sab196087 extern void elfedit_msg(elfedit_msg_t type, const char *format, ...); 615d29b2c44Sab196087 extern elfedit_outstyle_t elfedit_outstyle(void); 616d29b2c44Sab196087 extern void elfedit_pager_init(void); 617d29b2c44Sab196087 extern void elfedit_printf(const char *format, ...); 618d29b2c44Sab196087 extern void *elfedit_realloc(const char *item_name, void *ptr, size_t size); 619cce0e03bSab196087 extern void elfedit_str_to_c_literal(const char *str, 620cce0e03bSab196087 elfedit_write_func_t *outfunc); 621cce0e03bSab196087 extern elfedit_write_func_t elfedit_write; 622d29b2c44Sab196087 623d29b2c44Sab196087 /* 624d29b2c44Sab196087 * Core elfedit functions exported for use by sys: module only 625d29b2c44Sab196087 */ 626d29b2c44Sab196087 extern void elfedit_cpl_module(void *cpldata, int load_all_modules); 627d29b2c44Sab196087 628d29b2c44Sab196087 629d29b2c44Sab196087 /* 630d29b2c44Sab196087 * elfedit modules are expected to define two functions, one for 631d29b2c44Sab196087 * each ELFCLASS. Define a generic name for this function, based on 632d29b2c44Sab196087 * the class being supported by the including module. 633d29b2c44Sab196087 */ 634d29b2c44Sab196087 #ifdef _ELF64 635d29b2c44Sab196087 #define elfedit_init elfedit64_init 636d29b2c44Sab196087 #else 637d29b2c44Sab196087 #define elfedit_init elfedit32_init 638d29b2c44Sab196087 #endif 639d29b2c44Sab196087 640d29b2c44Sab196087 641d29b2c44Sab196087 642d29b2c44Sab196087 /* 643d29b2c44Sab196087 * It is common to search the dynamic section for specific elements. 644d29b2c44Sab196087 * Structures of this type are used to represent the contents of such 645d29b2c44Sab196087 * elements in a systematic way. The elfedit_dyn_elt_init() function 646d29b2c44Sab196087 * is used to prepare these strucutres for use. 647d29b2c44Sab196087 */ 648d29b2c44Sab196087 typedef struct { 649d29b2c44Sab196087 int dn_seen; /* True if this item has been seen */ 650d29b2c44Sab196087 Elf32_Word dn_ndx; /* Index of item in dynamic array */ 651d29b2c44Sab196087 Elf32_Dyn dn_dyn; /* Contents of dynamic item */ 652d29b2c44Sab196087 } elfedit32_dyn_elt_t; 653d29b2c44Sab196087 654d29b2c44Sab196087 typedef struct { 655d29b2c44Sab196087 int dn_seen; 656d29b2c44Sab196087 Elf64_Word dn_ndx; 657d29b2c44Sab196087 Elf64_Dyn dn_dyn; 658d29b2c44Sab196087 } elfedit64_dyn_elt_t; 659d29b2c44Sab196087 660d29b2c44Sab196087 #ifdef _ELF64 661d29b2c44Sab196087 #define elfedit_dyn_elt_t elfedit64_dyn_elt_t 662d29b2c44Sab196087 #else 663d29b2c44Sab196087 #define elfedit_dyn_elt_t elfedit32_dyn_elt_t 664d29b2c44Sab196087 #endif 665d29b2c44Sab196087 666d29b2c44Sab196087 /* 667d29b2c44Sab196087 * The elfedit_atoi() and elfedit_atoui() functions can optionally 668d29b2c44Sab196087 * accept an array of these structures, giving symbolic names that 669d29b2c44Sab196087 * will be accepted instead of numeric codes. If such an array is 670d29b2c44Sab196087 * present, the supplied string has it's leading and trailing whitespace 671d29b2c44Sab196087 * removed and is then compared to the list, and if there is a match, 672d29b2c44Sab196087 * the corresponding integer value is returned. 673d29b2c44Sab196087 * 674d29b2c44Sab196087 * The final array element must have its name field set to NULL. 675d29b2c44Sab196087 */ 676d29b2c44Sab196087 typedef u_longlong_t elfedit_atoui_t; 677d29b2c44Sab196087 typedef struct { 678d29b2c44Sab196087 const char *sym_name; 679d29b2c44Sab196087 elfedit_atoui_t sym_value; 680d29b2c44Sab196087 } elfedit_atoui_sym_t; 681d29b2c44Sab196087 typedef longlong_t elfedit_atoi_t; 682d29b2c44Sab196087 typedef struct { 683d29b2c44Sab196087 const char *sym_name; 684d29b2c44Sab196087 elfedit_atoi_t sym_value; 685d29b2c44Sab196087 } elfedit_atoi_sym_t; 686d29b2c44Sab196087 687d29b2c44Sab196087 688d29b2c44Sab196087 /* 689d29b2c44Sab196087 * The elfedit_atoconst*() functions are built on top of the atoui routines. 690d29b2c44Sab196087 * These routines accept an elfedit_const_t code instead of a 691d29b2c44Sab196087 * pointer to an elfedit_atoui_sym_t array, and use internally 692d29b2c44Sab196087 * predefined tables of elfedit_atoui_sym_t in order to do the desired 693d29b2c44Sab196087 * mappings. elfedit modules are encouraged to use these standard 694d29b2c44Sab196087 * tables instead of defining their own elfedit_atoui_sym_t arrays. 695d29b2c44Sab196087 * 696d29b2c44Sab196087 * note: 697d29b2c44Sab196087 * - The values assigned here must be in agreement with the 698d29b2c44Sab196087 * sym_table[] array defined in elfconst.c. 699d29b2c44Sab196087 * - Once defined, these values must not change. Reordering the 700d29b2c44Sab196087 * list will require all modules to be rebuilt, and will 701d29b2c44Sab196087 * break backward compatability. New items should be 702d29b2c44Sab196087 * added to the end. 703d29b2c44Sab196087 */ 704d29b2c44Sab196087 typedef enum { 705d29b2c44Sab196087 ELFEDIT_CONST_OUTSTYLE = 0, /* elfedit output styles */ 706d29b2c44Sab196087 ELFEDIT_CONST_OUTSTYLE_MO = 1, /* ostyles with -o prefix */ 707d29b2c44Sab196087 ELFEDIT_CONST_BOOL = 2, /* boolean names */ 708d29b2c44Sab196087 ELFEDIT_CONST_SHN = 3, /* ELF SHN_ section indexes */ 709d29b2c44Sab196087 ELFEDIT_CONST_SHT = 4, /* ELF SHT_ section types */ 710d29b2c44Sab196087 ELFEDIT_CONST_SHT_STRTAB = 5, /* ELF SHT_STRTAB */ 711d29b2c44Sab196087 ELFEDIT_CONST_SHT_ALLSYMTAB = 6, /* ELF SHT_ symbol table */ 712d29b2c44Sab196087 /* section types */ 713d29b2c44Sab196087 ELFEDIT_CONST_SHT_SYMTAB = 7, /* ELF SHT_SYMTAB */ 714d29b2c44Sab196087 ELFEDIT_CONST_SHT_DYNSYM = 8, /* ELF SHT_DYNSYM */ 715d29b2c44Sab196087 ELFEDIT_CONST_SHT_LDYNSYM = 9, /* ELF SHT_SUNW_LDYNSYM */ 716d29b2c44Sab196087 ELFEDIT_CONST_DT = 10, /* Dynamic tags: DT_ */ 717d29b2c44Sab196087 ELFEDIT_CONST_DF = 11, /* DT_FLAGS bits */ 718d29b2c44Sab196087 ELFEDIT_CONST_DF_P1 = 12, /* DF_POSFLAG_1 bits */ 719d29b2c44Sab196087 ELFEDIT_CONST_DF_1 = 13, /* DT_FLAGS_1 bits */ 720d29b2c44Sab196087 ELFEDIT_CONST_DTF_1 = 14, /* DT_FEATURE_1 bits */ 721d29b2c44Sab196087 ELFEDIT_CONST_EI = 15, /* ELF header e_ident indexes */ 722d29b2c44Sab196087 ELFEDIT_CONST_ET = 16, /* Ehdr obj type */ 723d29b2c44Sab196087 ELFEDIT_CONST_ELFCLASS = 17, /* Ehdr wordsize (32,64) */ 724d29b2c44Sab196087 ELFEDIT_CONST_ELFDATA = 18, /* Ehdr endian */ 725d29b2c44Sab196087 ELFEDIT_CONST_EF = 19, /* Ehdr flags */ 726d29b2c44Sab196087 ELFEDIT_CONST_EV = 20, /* Ehdr version */ 727d29b2c44Sab196087 ELFEDIT_CONST_EM = 21, /* Ehdr machine */ 728d29b2c44Sab196087 ELFEDIT_CONST_ELFOSABI = 22, /* Ehdr ABI */ 729d29b2c44Sab196087 ELFEDIT_CONST_PT = 23, /* Phdr type */ 730d29b2c44Sab196087 ELFEDIT_CONST_PF = 24, /* Phdr flags */ 731d29b2c44Sab196087 ELFEDIT_CONST_SHF = 25, /* Shdr flags */ 732d29b2c44Sab196087 ELFEDIT_CONST_STB = 26, /* Sym binding */ 733d29b2c44Sab196087 ELFEDIT_CONST_STT = 27, /* Sym type */ 734d29b2c44Sab196087 ELFEDIT_CONST_STV = 28, /* Sym visibility */ 735d29b2c44Sab196087 ELFEDIT_CONST_SYMINFO_BT = 29, /* Syminfo boundto */ 736d29b2c44Sab196087 ELFEDIT_CONST_SYMINFO_FLG = 30, /* Syminfo flags */ 737d29b2c44Sab196087 ELFEDIT_CONST_CA = 31, /* Capabilities tags: CA_ */ 738d29b2c44Sab196087 ELFEDIT_CONST_AV_386 = 32, /* X86 hardware caps */ 739d29b2c44Sab196087 ELFEDIT_CONST_AV_SPARC = 33, /* sparc hardware caps */ 740d29b2c44Sab196087 ELFEDIT_CONST_SF1_SUNW = 34, /* software capabilities */ 741d29b2c44Sab196087 } elfedit_const_t; 742d29b2c44Sab196087 743d29b2c44Sab196087 /* 744d29b2c44Sab196087 * Given an elfedit_const_t, return the array of elfedit_atoui_sym_t 745d29b2c44Sab196087 * entries that it represents. 746d29b2c44Sab196087 */ 747d29b2c44Sab196087 extern elfedit_atoui_sym_t *elfedit_const_to_atoui(elfedit_const_t const_type); 748d29b2c44Sab196087 749d29b2c44Sab196087 /* 750d29b2c44Sab196087 * Return the elfedit_atoui_t array that corresponds to the 751d29b2c44Sab196087 * CA_SUNW_HW_1 hardware capabiliies field for a given 752d29b2c44Sab196087 * machine type. 753d29b2c44Sab196087 */ 754d29b2c44Sab196087 extern elfedit_atoui_sym_t *elfedit_mach_sunw_hw1_to_atoui(int mach); 755d29b2c44Sab196087 756d29b2c44Sab196087 /* 757d29b2c44Sab196087 * ato[u]i and const routines, used to turn strings into numeric values, 758d29b2c44Sab196087 * with support for mapping symbol names to numbers, and range checking. 759d29b2c44Sab196087 */ 760d29b2c44Sab196087 extern elfedit_atoi_t elfedit_atoi(const char *str, 761d29b2c44Sab196087 const elfedit_atoi_sym_t *sym); 762d29b2c44Sab196087 extern elfedit_atoui_t elfedit_atoui(const char *str, 763d29b2c44Sab196087 const elfedit_atoui_sym_t *sym); 764d29b2c44Sab196087 extern elfedit_atoui_t elfedit_atoconst(const char *str, 765d29b2c44Sab196087 elfedit_const_t const_type); 766d29b2c44Sab196087 767d29b2c44Sab196087 extern int elfedit_atoi2(const char *str, const elfedit_atoi_sym_t *sym, 768d29b2c44Sab196087 elfedit_atoi_t *v); 769d29b2c44Sab196087 extern int elfedit_atoui2(const char *str, const elfedit_atoui_sym_t *sym, 770d29b2c44Sab196087 elfedit_atoui_t *); 771d29b2c44Sab196087 extern int elfedit_atoconst2(const char *str, elfedit_const_t const_type, 772d29b2c44Sab196087 elfedit_atoui_t *); 773d29b2c44Sab196087 774d29b2c44Sab196087 extern elfedit_atoi_t elfedit_atoi_range(const char *str, 775d29b2c44Sab196087 const char *item_name, elfedit_atoi_t min, elfedit_atoi_t max, 776d29b2c44Sab196087 const elfedit_atoi_sym_t *sym); 777d29b2c44Sab196087 extern elfedit_atoui_t elfedit_atoui_range(const char *str, 778d29b2c44Sab196087 const char *item_name, elfedit_atoui_t min, elfedit_atoui_t max, 779d29b2c44Sab196087 const elfedit_atoui_sym_t *sym); 780d29b2c44Sab196087 extern elfedit_atoui_t elfedit_atoconst_range(const char *str, 781d29b2c44Sab196087 const char *item_name, elfedit_atoui_t min, elfedit_atoui_t max, 782d29b2c44Sab196087 elfedit_const_t const_type); 783d29b2c44Sab196087 784d29b2c44Sab196087 extern int elfedit_atoi_range2(const char *str, elfedit_atoi_t min, 785d29b2c44Sab196087 elfedit_atoi_t max, const elfedit_atoi_sym_t *sym, elfedit_atoi_t *v); 786d29b2c44Sab196087 extern int elfedit_atoui_range2(const char *str, elfedit_atoui_t min, 787d29b2c44Sab196087 elfedit_atoui_t max, const elfedit_atoui_sym_t *sym, elfedit_atoui_t *v); 788d29b2c44Sab196087 extern int elfedit_atoconst_range2(const char *str, elfedit_atoui_t min, 789d29b2c44Sab196087 elfedit_atoui_t max, elfedit_const_t const_type, elfedit_atoui_t *v); 790d29b2c44Sab196087 791d29b2c44Sab196087 extern const char *elfedit_atoi_value_to_str(const elfedit_atoi_sym_t *sym, 792d29b2c44Sab196087 elfedit_atoi_t value, int required); 793d29b2c44Sab196087 extern const char *elfedit_atoui_value_to_str(const elfedit_atoui_sym_t *sym, 794d29b2c44Sab196087 elfedit_atoui_t value, int required); 795d29b2c44Sab196087 extern const char *elfedit_atoconst_value_to_str(elfedit_const_t const_type, 796d29b2c44Sab196087 elfedit_atoui_t value, int required); 797d29b2c44Sab196087 798d29b2c44Sab196087 extern void elfedit_cpl_atoi(void *cpldata, const elfedit_atoi_sym_t *sym); 799d29b2c44Sab196087 extern void elfedit_cpl_atoui(void *cpldata, const elfedit_atoui_sym_t *sym); 800d29b2c44Sab196087 extern void elfedit_cpl_atoconst(void *cpldata, elfedit_const_t const_type); 801d29b2c44Sab196087 802d29b2c44Sab196087 803d29b2c44Sab196087 /* 804d29b2c44Sab196087 * Convenience functions built on top of the ato[u]i routines. 805d29b2c44Sab196087 */ 806d29b2c44Sab196087 extern int elfedit_atobool(const char *str, const char *item_name); 807d29b2c44Sab196087 extern elfedit_atoui_t elfedit_atoshndx(const char *str, size_t shnum); 808d29b2c44Sab196087 809d29b2c44Sab196087 810d29b2c44Sab196087 /* 811d29b2c44Sab196087 * elfedit provides a getopt utility for use by the module commands. 812d29b2c44Sab196087 * elfedit_getopt_state_t is the state block used by elfedit_getopt(). 813d29b2c44Sab196087 * elfedit_getopt_ret_t is the definition of the values returned to 814d29b2c44Sab196087 * the user by elfedit_getopt() when an option is matched. Elfedit 815d29b2c44Sab196087 * getopt processing is done as follows: 816d29b2c44Sab196087 * 817d29b2c44Sab196087 * 1) The caller initializes an elfedit_getopt_state_t struct via 818d29b2c44Sab196087 * a call to elfedit_getopt_init(). The contents of this structure 819d29b2c44Sab196087 * must not be accessed by the caller, as they are all private and 820d29b2c44Sab196087 * subject to change. 821d29b2c44Sab196087 * 2) Repeated calls are made to elfedit_getopt(), as long as it returns 822d29b2c44Sab196087 * a non-NULL pointer to an elfedit_getopt_ret_t structure. If the 823d29b2c44Sab196087 * matched option has a value (ELFEDIT_CMDOA_F_VALUE), then the gor_value 824d29b2c44Sab196087 * field contains the pointer to the string. Otherwise, gor_value is NULL. 825d29b2c44Sab196087 * 3) As elfedit_getopt() consumes optional arguments from the argc/argv 826d29b2c44Sab196087 * passed to elfedit_getopt_init(), it adjusts argc/argc to skip over 827d29b2c44Sab196087 * them. Once elfedit_getopt() returns NULL to indicate that there are no 828d29b2c44Sab196087 * more options to match, argc/argv have been adjusted so that they 829d29b2c44Sab196087 * reference the plain arguments. 830d29b2c44Sab196087 */ 831d29b2c44Sab196087 typedef struct { 832d29b2c44Sab196087 elfedit_cmd_oa_mask_t gor_idmask; /* oa_idmask from matching */ 833d29b2c44Sab196087 /* elfedit_cmd_optarg_t. Can be */ 834d29b2c44Sab196087 /* used to quickly identify opt */ 835d29b2c44Sab196087 const char *gor_value; /* Opt value if ELFEDIT_CMDOA_F_VALUE */ 836d29b2c44Sab196087 /* Otherwise, NULL */ 837d29b2c44Sab196087 } elfedit_getopt_ret_t; 838d29b2c44Sab196087 typedef struct { 839d29b2c44Sab196087 int *go_argc; /* Pointer to # of options */ 840d29b2c44Sab196087 const char ***go_argv; /* Ptr to array of opt strs */ 841d29b2c44Sab196087 elfedit_cmd_optarg_t *go_optarg; /* Array of allowed options */ 842d29b2c44Sab196087 elfedit_cmd_oa_mask_t go_idmask; /* Combined id masks of all */ 843d29b2c44Sab196087 /* seen options */ 844d29b2c44Sab196087 int go_done; /* True if last option seen */ 845d29b2c44Sab196087 const char *go_sglgrp; /* Group of 1-letter opts */ 846d29b2c44Sab196087 elfedit_getopt_ret_t go_ret; /* Data returned to user */ 847d29b2c44Sab196087 } elfedit_getopt_state_t; 848d29b2c44Sab196087 849d29b2c44Sab196087 850d29b2c44Sab196087 851d29b2c44Sab196087 /* 852d29b2c44Sab196087 * getopt related routines 853d29b2c44Sab196087 */ 854d29b2c44Sab196087 extern void elfedit_getopt_init(elfedit_getopt_state_t *, 855d29b2c44Sab196087 int *, const char ***); 856d29b2c44Sab196087 extern elfedit_getopt_ret_t *elfedit_getopt(elfedit_getopt_state_t *); 857d29b2c44Sab196087 858d29b2c44Sab196087 859d29b2c44Sab196087 860d29b2c44Sab196087 /* 861d29b2c44Sab196087 * Additional utility functions exported for use by modules 862d29b2c44Sab196087 */ 863d29b2c44Sab196087 extern void elfedit_array_elts_delete(const char *name_str, void *data_start, 864d29b2c44Sab196087 size_t entsize, size_t num_ent, size_t start_ndx, size_t cnt); 865d29b2c44Sab196087 866d29b2c44Sab196087 extern void elfedit_array_elts_move(const char *name_str, void *data_start, 867d29b2c44Sab196087 size_t entsize, size_t num_ent, size_t srcndx, 868d29b2c44Sab196087 size_t dstndx, size_t cnt, void *scr_item); 869d29b2c44Sab196087 870d29b2c44Sab196087 extern int elfedit_bits_set(u_longlong_t v, int sizeof_orig_v); 871d29b2c44Sab196087 872d29b2c44Sab196087 extern void elfedit32_dyn_elt_init(elfedit32_dyn_elt_t *dyn_elt); 873d29b2c44Sab196087 extern void elfedit64_dyn_elt_init(elfedit64_dyn_elt_t *dyn_elt); 874d29b2c44Sab196087 875d29b2c44Sab196087 extern void elfedit32_dyn_elt_save(elfedit32_dyn_elt_t *elt, Elf32_Word ndx, 876d29b2c44Sab196087 Elf32_Dyn *dyn); 877d29b2c44Sab196087 extern void elfedit64_dyn_elt_save(elfedit64_dyn_elt_t *elt, Elf64_Word ndx, 878d29b2c44Sab196087 Elf64_Dyn *dyn); 879d29b2c44Sab196087 880d29b2c44Sab196087 const char *elfedit32_dyn_offset_to_str(elfedit32_section_t *strsec, 881d29b2c44Sab196087 elfedit32_dyn_elt_t *dynelt); 882d29b2c44Sab196087 const char *elfedit64_dyn_offset_to_str(elfedit64_section_t *strsec, 883d29b2c44Sab196087 elfedit64_dyn_elt_t *dynelt); 884d29b2c44Sab196087 885d29b2c44Sab196087 extern int elfedit32_dynstr_getpad(elfedit32_section_t *dynsec, 886d29b2c44Sab196087 elfedit32_dyn_elt_t *dyn_strpad); 887d29b2c44Sab196087 extern int elfedit64_dynstr_getpad(elfedit64_section_t *dynsec, 888d29b2c44Sab196087 elfedit64_dyn_elt_t *dyn_strpad); 889d29b2c44Sab196087 890d29b2c44Sab196087 extern Elf32_Word elfedit32_dynstr_insert(elfedit32_section_t *dynsec, 891d29b2c44Sab196087 elfedit32_section_t *strsec, elfedit32_dyn_elt_t *dyn_strpad, 892d29b2c44Sab196087 const char *str); 893d29b2c44Sab196087 extern Elf64_Word elfedit64_dynstr_insert(elfedit64_section_t *dynsec, 894d29b2c44Sab196087 elfedit64_section_t *strsec, elfedit64_dyn_elt_t *dyn_strpad, 895d29b2c44Sab196087 const char *str); 896d29b2c44Sab196087 897d29b2c44Sab196087 extern void elfedit32_modified_data(elfedit32_section_t *s); 898d29b2c44Sab196087 extern void elfedit64_modified_data(elfedit64_section_t *s); 899d29b2c44Sab196087 900d29b2c44Sab196087 extern void elfedit32_modified_ehdr(elfedit32_obj_state_t *obj_state); 901d29b2c44Sab196087 extern void elfedit64_modified_ehdr(elfedit64_obj_state_t *obj_state); 902d29b2c44Sab196087 903d29b2c44Sab196087 extern void elfedit32_modified_phdr(elfedit32_obj_state_t *obj_state); 904d29b2c44Sab196087 extern void elfedit64_modified_phdr(elfedit64_obj_state_t *obj_state); 905d29b2c44Sab196087 906d29b2c44Sab196087 extern void elfedit32_modified_shdr(elfedit32_section_t *s); 907d29b2c44Sab196087 extern void elfedit64_modified_shdr(elfedit64_section_t *s); 908d29b2c44Sab196087 909d29b2c44Sab196087 extern Elf32_Word elfedit32_name_to_shndx(elfedit32_obj_state_t *obj_state, 910d29b2c44Sab196087 const char *shnam); 911d29b2c44Sab196087 extern Elf64_Word elfedit64_name_to_shndx(elfedit64_obj_state_t *obj_state, 912d29b2c44Sab196087 const char *shnam); 913d29b2c44Sab196087 914d29b2c44Sab196087 extern Elf32_Word elfedit32_type_to_shndx(elfedit32_obj_state_t *obj_state, 915d29b2c44Sab196087 Elf32_Word shtype); 916d29b2c44Sab196087 extern Elf64_Word elfedit64_type_to_shndx(elfedit64_obj_state_t *obj_state, 917d29b2c44Sab196087 Elf64_Word shtype); 918d29b2c44Sab196087 919d29b2c44Sab196087 extern int elfedit32_name_to_symndx(elfedit32_section_t *symsec, 920d29b2c44Sab196087 elfedit32_section_t *strsec, const char *name, elfedit_msg_t msg_type, 921d29b2c44Sab196087 Elf32_Word *ret_symndx); 922d29b2c44Sab196087 extern int elfedit64_name_to_symndx(elfedit64_section_t *symsec, 923d29b2c44Sab196087 elfedit64_section_t *strsec, const char *name, elfedit_msg_t msg_type, 924d29b2c44Sab196087 Elf64_Word *ret_symndx); 925d29b2c44Sab196087 926d29b2c44Sab196087 extern const char *elfedit32_offset_to_str(elfedit32_section_t *strsec, 927d29b2c44Sab196087 Elf32_Word offset, elfedit_msg_t msg_type, int debug_msg); 928d29b2c44Sab196087 extern const char *elfedit64_offset_to_str(elfedit64_section_t *strsec, 929d29b2c44Sab196087 Elf64_Word offset, elfedit_msg_t msg_type, int debug_msg); 930d29b2c44Sab196087 931d29b2c44Sab196087 extern int elfedit32_sec_findstr(elfedit32_section_t *sec, Elf32_Word tail_ign, 932d29b2c44Sab196087 const char *str, Elf32_Word *ret_offset); 933d29b2c44Sab196087 extern int elfedit64_sec_findstr(elfedit64_section_t *sec, Elf64_Word tail_ign, 934d29b2c44Sab196087 const char *str, Elf64_Word *ret_offset); 935d29b2c44Sab196087 936cce0e03bSab196087 extern elfedit32_section_t *elfedit32_sec_get( 937cce0e03bSab196087 elfedit32_obj_state_t *obj_state, Elf32_Word shndx); 938cce0e03bSab196087 extern elfedit64_section_t *elfedit64_sec_get( 939cce0e03bSab196087 elfedit64_obj_state_t *obj_state, Elf64_Word shndx); 940cce0e03bSab196087 941d29b2c44Sab196087 extern elfedit32_section_t *elfedit32_sec_getcap( 942d29b2c44Sab196087 elfedit32_obj_state_t *obj_state, Elf32_Cap **cap, Elf32_Word *num); 943d29b2c44Sab196087 extern elfedit64_section_t *elfedit64_sec_getcap( 944d29b2c44Sab196087 elfedit64_obj_state_t *obj_state, Elf64_Cap **cap, Elf64_Word *num); 945d29b2c44Sab196087 946d29b2c44Sab196087 extern elfedit32_section_t *elfedit32_sec_getdyn( 947d29b2c44Sab196087 elfedit32_obj_state_t *obj_state, Elf32_Dyn **dyn, Elf32_Word *num); 948d29b2c44Sab196087 extern elfedit64_section_t *elfedit64_sec_getdyn( 949d29b2c44Sab196087 elfedit64_obj_state_t *obj_state, Elf64_Dyn **dyn, Elf64_Word *num); 950d29b2c44Sab196087 951d29b2c44Sab196087 extern elfedit32_section_t *elfedit32_sec_getstr( 952*55ef6355Sab196087 elfedit32_obj_state_t *obj_state, Elf32_Word shndx, int); 953d29b2c44Sab196087 extern elfedit64_section_t *elfedit64_sec_getstr( 954*55ef6355Sab196087 elfedit64_obj_state_t *obj_state, Elf64_Word shndx, int); 955d29b2c44Sab196087 956d29b2c44Sab196087 extern elfedit32_section_t *elfedit32_sec_getsyminfo( 957d29b2c44Sab196087 elfedit32_obj_state_t *obj_state, Elf32_Syminfo **syminfo, Elf32_Word *num); 958d29b2c44Sab196087 extern elfedit64_section_t *elfedit64_sec_getsyminfo( 959d29b2c44Sab196087 elfedit64_obj_state_t *obj_state, Elf64_Syminfo **syminfo, Elf64_Word *num); 960d29b2c44Sab196087 961d29b2c44Sab196087 extern elfedit32_section_t *elfedit32_sec_getsymtab( 962d29b2c44Sab196087 elfedit32_obj_state_t *obj_state, int by_index, Elf32_Word index, 963d29b2c44Sab196087 const char *name, Elf32_Sym **sym, Elf32_Word *num, 964d29b2c44Sab196087 elfedit32_symtab_t **aux_info); 965d29b2c44Sab196087 extern elfedit64_section_t *elfedit64_sec_getsymtab( 966d29b2c44Sab196087 elfedit64_obj_state_t *obj_state, int by_index, Elf64_Word index, 967d29b2c44Sab196087 const char *name, Elf64_Sym **sym, Elf64_Word *num, 968d29b2c44Sab196087 elfedit64_symtab_t **aux_info); 969d29b2c44Sab196087 970d29b2c44Sab196087 extern elfedit32_section_t *elfedit32_sec_getversym( 971d29b2c44Sab196087 elfedit32_obj_state_t *obj_state, elfedit32_section_t *symsec, 972d29b2c44Sab196087 Elf32_Versym **versym, Elf32_Word *num); 973d29b2c44Sab196087 extern elfedit64_section_t *elfedit64_sec_getversym( 974d29b2c44Sab196087 elfedit64_obj_state_t *obj_state, elfedit64_section_t *symsec, 975d29b2c44Sab196087 Elf64_Versym **versym, Elf64_Word *num); 976d29b2c44Sab196087 977d29b2c44Sab196087 extern elfedit32_section_t *elfedit32_sec_getxshndx( 978d29b2c44Sab196087 elfedit32_obj_state_t *obj_state, elfedit32_section_t *symsec, 979d29b2c44Sab196087 Elf32_Word **xshndx, Elf32_Word *num); 980d29b2c44Sab196087 extern elfedit64_section_t *elfedit64_sec_getxshndx( 981d29b2c44Sab196087 elfedit64_obj_state_t *obj_state, elfedit64_section_t *symsec, 982d29b2c44Sab196087 Elf64_Word **xshndx, Elf64_Word *num); 983d29b2c44Sab196087 984d29b2c44Sab196087 extern int elfedit32_sec_issymtab(elfedit32_section_t *sec, int issue_err, 985d29b2c44Sab196087 elfedit_atoui_sym_t **atoui_list); 986d29b2c44Sab196087 extern int elfedit64_sec_issymtab(elfedit64_section_t *sec, int issue_err, 987d29b2c44Sab196087 elfedit_atoui_sym_t **atoui_list); 988d29b2c44Sab196087 989d29b2c44Sab196087 extern const char *elfedit32_sec_msgprefix(elfedit32_section_t *sec); 990d29b2c44Sab196087 extern const char *elfedit64_sec_msgprefix(elfedit64_section_t *sec); 991d29b2c44Sab196087 992d29b2c44Sab196087 extern const char *elfedit32_shndx_to_name(elfedit32_obj_state_t *obj_state, 993d29b2c44Sab196087 Elf32_Word shndx); 994d29b2c44Sab196087 extern const char *elfedit64_shndx_to_name(elfedit64_obj_state_t *obj_state, 995d29b2c44Sab196087 Elf64_Word shndx); 996d29b2c44Sab196087 997d29b2c44Sab196087 extern Elf32_Word elfedit32_strtab_insert(elfedit32_obj_state_t *obj_state, 998d29b2c44Sab196087 elfedit32_section_t *strsec, elfedit32_section_t *dynsec, const char *str); 999d29b2c44Sab196087 extern Elf64_Word elfedit64_strtab_insert(elfedit64_obj_state_t *obj_state, 1000d29b2c44Sab196087 elfedit64_section_t *strsec, elfedit64_section_t *dynsec, const char *str); 1001d29b2c44Sab196087 1002d29b2c44Sab196087 extern void elfedit32_strtab_insert_test(elfedit32_obj_state_t *obj_state, 1003d29b2c44Sab196087 elfedit32_section_t *strsec, elfedit32_section_t *dynsec, const char *str); 1004d29b2c44Sab196087 extern void elfedit64_strtab_insert_test(elfedit64_obj_state_t *obj_state, 1005d29b2c44Sab196087 elfedit64_section_t *strsec, elfedit64_section_t *dynsec, const char *str); 1006d29b2c44Sab196087 1007d29b2c44Sab196087 extern Elf32_Word elfedit32_type_to_shndx(elfedit32_obj_state_t *obj_state, 1008d29b2c44Sab196087 Elf32_Word shtype); 1009d29b2c44Sab196087 extern Elf64_Word elfedit64_type_to_shndx(elfedit64_obj_state_t *obj_state, 1010d29b2c44Sab196087 Elf64_Word shtype); 1011d29b2c44Sab196087 1012d29b2c44Sab196087 1013d29b2c44Sab196087 1014d29b2c44Sab196087 /* 1015d29b2c44Sab196087 * Map the generic names for each of the ELFCLASS specific routines 1016d29b2c44Sab196087 * above to reference the proper routine for the current compilation. 1017d29b2c44Sab196087 */ 1018d29b2c44Sab196087 #ifdef _ELF64 1019d29b2c44Sab196087 #define elfedit_dyn_elt_init elfedit64_dyn_elt_init 1020d29b2c44Sab196087 #define elfedit_dyn_elt_save elfedit64_dyn_elt_save 1021d29b2c44Sab196087 #define elfedit_dyn_offset_to_str elfedit64_dyn_offset_to_str 1022d29b2c44Sab196087 #define elfedit_dynstr_getpad elfedit64_dynstr_getpad 1023d29b2c44Sab196087 #define elfedit_dynstr_insert elfedit64_dynstr_insert 1024d29b2c44Sab196087 #define elfedit_modified_data elfedit64_modified_data 1025d29b2c44Sab196087 #define elfedit_modified_ehdr elfedit64_modified_ehdr 1026d29b2c44Sab196087 #define elfedit_modified_phdr elfedit64_modified_phdr 1027d29b2c44Sab196087 #define elfedit_modified_shdr elfedit64_modified_shdr 1028d29b2c44Sab196087 #define elfedit_name_to_shndx elfedit64_name_to_shndx 1029d29b2c44Sab196087 #define elfedit_name_to_symndx elfedit64_name_to_symndx 1030d29b2c44Sab196087 #define elfedit_offset_to_str elfedit64_offset_to_str 1031d29b2c44Sab196087 #define elfedit_sec_findstr elfedit64_sec_findstr 1032cce0e03bSab196087 #define elfedit_sec_get elfedit64_sec_get 1033d29b2c44Sab196087 #define elfedit_sec_getcap elfedit64_sec_getcap 1034d29b2c44Sab196087 #define elfedit_sec_getdyn elfedit64_sec_getdyn 1035d29b2c44Sab196087 #define elfedit_sec_getstr elfedit64_sec_getstr 1036d29b2c44Sab196087 #define elfedit_sec_getsyminfo elfedit64_sec_getsyminfo 1037d29b2c44Sab196087 #define elfedit_sec_getsymtab elfedit64_sec_getsymtab 1038d29b2c44Sab196087 #define elfedit_sec_getversym elfedit64_sec_getversym 1039d29b2c44Sab196087 #define elfedit_sec_getxshndx elfedit64_sec_getxshndx 1040d29b2c44Sab196087 #define elfedit_sec_issymtab elfedit64_sec_issymtab 1041d29b2c44Sab196087 #define elfedit_shndx_to_name elfedit64_shndx_to_name 1042d29b2c44Sab196087 #define elfedit_sec_msgprefix elfedit64_sec_msgprefix 1043d29b2c44Sab196087 #define elfedit_strtab_insert elfedit64_strtab_insert 1044d29b2c44Sab196087 #define elfedit_strtab_insert_test elfedit64_strtab_insert_test 1045d29b2c44Sab196087 #define elfedit_type_to_shndx elfedit64_type_to_shndx 1046d29b2c44Sab196087 #else 1047d29b2c44Sab196087 #define elfedit_dyn_elt_init elfedit32_dyn_elt_init 1048d29b2c44Sab196087 #define elfedit_dyn_elt_save elfedit32_dyn_elt_save 1049d29b2c44Sab196087 #define elfedit_dyn_offset_to_str elfedit32_dyn_offset_to_str 1050d29b2c44Sab196087 #define elfedit_dynstr_getpad elfedit32_dynstr_getpad 1051d29b2c44Sab196087 #define elfedit_dynstr_insert elfedit32_dynstr_insert 1052d29b2c44Sab196087 #define elfedit_modified_data elfedit32_modified_data 1053d29b2c44Sab196087 #define elfedit_modified_ehdr elfedit32_modified_ehdr 1054d29b2c44Sab196087 #define elfedit_modified_phdr elfedit32_modified_phdr 1055d29b2c44Sab196087 #define elfedit_modified_shdr elfedit32_modified_shdr 1056d29b2c44Sab196087 #define elfedit_name_to_shndx elfedit32_name_to_shndx 1057d29b2c44Sab196087 #define elfedit_name_to_symndx elfedit32_name_to_symndx 1058d29b2c44Sab196087 #define elfedit_offset_to_str elfedit32_offset_to_str 1059d29b2c44Sab196087 #define elfedit_sec_findstr elfedit32_sec_findstr 1060cce0e03bSab196087 #define elfedit_sec_get elfedit32_sec_get 1061d29b2c44Sab196087 #define elfedit_sec_getcap elfedit32_sec_getcap 1062d29b2c44Sab196087 #define elfedit_sec_getdyn elfedit32_sec_getdyn 1063d29b2c44Sab196087 #define elfedit_sec_getstr elfedit32_sec_getstr 1064d29b2c44Sab196087 #define elfedit_sec_getsyminfo elfedit32_sec_getsyminfo 1065d29b2c44Sab196087 #define elfedit_sec_getsymtab elfedit32_sec_getsymtab 1066d29b2c44Sab196087 #define elfedit_sec_getversym elfedit32_sec_getversym 1067d29b2c44Sab196087 #define elfedit_sec_getxshndx elfedit32_sec_getxshndx 1068d29b2c44Sab196087 #define elfedit_sec_issymtab elfedit32_sec_issymtab 1069d29b2c44Sab196087 #define elfedit_shndx_to_name elfedit32_shndx_to_name 1070d29b2c44Sab196087 #define elfedit_sec_msgprefix elfedit32_sec_msgprefix 1071d29b2c44Sab196087 #define elfedit_strtab_insert elfedit32_strtab_insert 1072d29b2c44Sab196087 #define elfedit_strtab_insert_test elfedit32_strtab_insert_test 1073d29b2c44Sab196087 #define elfedit_type_to_shndx elfedit32_type_to_shndx 1074d29b2c44Sab196087 #endif 1075d29b2c44Sab196087 1076d29b2c44Sab196087 1077d29b2c44Sab196087 #ifdef __cplusplus 1078d29b2c44Sab196087 } 1079d29b2c44Sab196087 #endif 1080d29b2c44Sab196087 1081d29b2c44Sab196087 #endif /* _ELFEDIT_H */ 1082