fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER START
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The contents of this file are subject to the terms of the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Common Development and Distribution License (the "License").
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You may not use this file except in compliance with the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * See the License for the specific language governing permissions
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * and limitations under the License.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * When distributing Covered Code, include this CDDL HEADER in each
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * If applicable, add the following below this CDDL HEADER, with the
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * fields enclosed by brackets "[]" replaced with your own identifying
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information: Portions Copyright [yyyy] [name of copyright owner]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * CDDL HEADER END
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Use is subject to license terms.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This module handles changes to the ELF header
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This module uses shared code for several of the commands.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * It is sometimes necessary to know which specific command
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * is active.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef enum {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Dump command, used as module default to display ELF header */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Commands that correspond directly to ELF header fields */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte EHDR_CMD_T_E_PHENTSIZE = 10, /* ehdr:e_phentsize */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte EHDR_CMD_T_E_SHENTSIZE = 12, /* ehdr:e_shentsize */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte EHDR_CMD_T_E_SHSTRNDX = 14, /* ehdr:e_shstrndx */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Commands that correspond to the e_ident[] array in ELF hdr */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte EHDR_CMD_T_EI_VERSION = 21, /* ehdr:ei_version */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte EHDR_CMD_T_EI_ABIVERSION = 23 /* ehdr:ei_abiversion */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * We supply this function for the msg module
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This function is supplied to elfedit through our elfedit_module_t
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * definition. It translates the opaque elfedit_i18nhdl_t handles
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * in our module interface into the actual strings for elfedit to
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This module uses Msg codes for its i18n handle type.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * So the translation is simply to use MSG_INTL() to turn
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * it into a string and return it.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic const char *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * The ehdr_opt_t enum specifies a bit value for every optional
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * argument allowed by a command in this module.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef enum {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte EHDR_OPT_F_AND = 1, /* -and: AND (&) values to dest */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte EHDR_OPT_F_CMP = 2, /* -cmp: Complement (~) values */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte EHDR_OPT_F_OR = 4, /* -or: OR (|) values to dest */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte EHDR_OPT_F_SHNDX = 8, /* -shndx: sec argument is index of */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* section, not name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte EHDR_OPT_F_SHTYP = 16 /* -shtyp: sec argument is type of */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* section, not name */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * A variable of type ARGSTATE is used by each command to maintain
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * information about the arguments and related things. It is
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * initialized by process_args(), and used by the other routines.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortetypedef struct {
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Standard argument processing for ehdr module
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * obj_state, argc, argv - Standard command arguments
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * argstate - Address of ARGSTATE block to be initialized
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * On success, *argstate is initialized. On error,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * an error is issued and this routine does not return.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteprocess_args(elfedit_obj_state_t *obj_state, int argc, const char *argv[],
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte elfedit_getopt_init(&getopt_state, &argc, &argv);
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Add each new option to the options mask */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte while ((getopt_ret = elfedit_getopt(&getopt_state)) != NULL)
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* If there may be an arbitrary amount of output, use a pager */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Return the updated values of argc/argv */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Format the given magic number byte into a buffer
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * value - Value of the magic value byte given by
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * ehdr->ei_ident[EI_MAG?]
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Fortestatic const char *
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * This routine can be called twice within a single C statement,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * so we use alternating buffers on each call to allow this
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * without requiring the caller to supply a buffer (the size of
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * which they don't know).
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte /* Switch buffers */
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Print ELF header values, taking the calling command, and output style
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * into account.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * cmd - EHDR_CMD_T_* value giving identify of caller
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * e_ident_ndx - Ignored unless cmd is EHDR_CMD_T_E_IDENT. In IDENT
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * case, index of item in e_ident[] array to display, or
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * -1 to display the entire array.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * autoprint - If True, output is only produced if the elfedit
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * autoprint flag is set. If False, output is always produced.
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * argstate - Argument state block
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forteprint_ehdr(EHDR_CMD_T cmd, int e_ident_ndx, int autoprint,
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte if (autoprint && ((elfedit_flags() & ELFEDIT_F_AUTOPRINT) == 0))
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * Pick an output style. ehdr:dump is required to use the default
fcf3ce441efd61da9bb2884968af01cb7c1452ccJohn Forte * style. The other commands use the current output style.
for (i = 0; i < EI_NIDENT; i++) {
case EI_MAG0:
case EI_MAG1:
case EI_MAG2:
case EI_MAG3:
case EI_CLASS:
0, &inv_buf);
case EI_DATA:
0, &inv_buf);
case EI_VERSION:
case EI_OSABI:
0, &inv_buf);
case EI_ABIVERSION:
switch (cmd) {
case EHDR_CMD_T_E_IDENT:
i = e_ident_ndx;
for (; cnt-- > 0; i++) {
(i > EI_ABIVERSION)) {
case EI_MAG0:
case EI_MAG1:
case EI_MAG2:
case EI_MAG3:
case EI_CLASS:
&inv_buf));
case EI_DATA:
&inv_buf));
case EI_VERSION:
&inv_buf));
case EI_OSABI:
&inv_buf));
case EI_ABIVERSION:
case EHDR_CMD_T_E_TYPE:
case EHDR_CMD_T_E_MACHINE:
case EHDR_CMD_T_E_VERSION:
case EHDR_CMD_T_E_ENTRY:
case EHDR_CMD_T_E_PHOFF:
case EHDR_CMD_T_E_SHOFF:
case EHDR_CMD_T_E_FLAGS:
case EHDR_CMD_T_E_EHSIZE:
case EHDR_CMD_T_E_PHENTSIZE:
case EHDR_CMD_T_E_PHNUM:
case EHDR_CMD_T_E_SHENTSIZE:
case EHDR_CMD_T_E_SHNUM:
if (num == 0)
case EHDR_CMD_T_E_SHSTRNDX:
case EHDR_CMD_T_EI_MAG0:
case EHDR_CMD_T_EI_MAG1:
case EHDR_CMD_T_EI_MAG2:
case EHDR_CMD_T_EI_MAG3:
conv_magic_value(c));
case EHDR_CMD_T_EI_CLASS:
case EHDR_CMD_T_EI_DATA:
case EHDR_CMD_T_EI_VERSION:
case EHDR_CMD_T_EI_OSABI:
EC_WORD(c));
case EHDR_CMD_T_EI_ABIVERSION:
EC_WORD(c));
static elfedit_cmdret_t
switch (cmd) {
case EHDR_CMD_T_DUMP:
case EHDR_CMD_T_E_IDENT:
e_ident_ndx = (int)
case EHDR_CMD_T_E_FLAGS:
return (ELFEDIT_CMDRET_NONE);
switch (cmd) {
case EHDR_CMD_T_E_IDENT:
value);
case EHDR_CMD_T_E_TYPE:
case EHDR_CMD_T_E_MACHINE:
&inv_buf1));
&inv_buf1),
case EHDR_CMD_T_E_VERSION:
&inv_buf1));
&inv_buf1),
case EHDR_CMD_T_E_ENTRY:
case EHDR_CMD_T_E_PHOFF:
NULL);
case EHDR_CMD_T_E_SHOFF:
NULL);
case EHDR_CMD_T_E_FLAGS:
case EHDR_CMD_T_E_EHSIZE:
NULL);
case EHDR_CMD_T_E_PHENTSIZE:
NULL);
case EHDR_CMD_T_E_PHNUM:
NULL);
sh_info = 0;
case EHDR_CMD_T_E_SHENTSIZE:
NULL);
case EHDR_CMD_T_E_SHNUM:
NULL);
e_shnum = 0;
sh_size = 0;
case EHDR_CMD_T_E_SHSTRNDX:
sh_link = 0;
case EHDR_CMD_T_EI_MAG0:
case EHDR_CMD_T_EI_MAG1:
case EHDR_CMD_T_EI_MAG2:
case EHDR_CMD_T_EI_MAG3:
case EHDR_CMD_T_EI_CLASS:
0, &inv_buf1),
case EHDR_CMD_T_EI_DATA:
0, &inv_buf1),
case EHDR_CMD_T_EI_VERSION:
0, &inv_buf1),
case EHDR_CMD_T_EI_OSABI:
0, &inv_buf1),
case EHDR_CMD_T_EI_ABIVERSION:
return (ret);
switch (ndx) {
case EI_CLASS:
case EI_DATA:
case EI_VERSION:
case EI_OSABI:
switch (op) {
case NAME:
case INDEX:
case TYPE:
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
static elfedit_cmdret_t
ELFEDIT_CMDOA_F_INHERIT, 0, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_INHERIT, 0, 0 },
{ NULL }
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_INHERIT, 0, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
ELFEDIT_CMDOA_F_OPT, 0 },
{ NULL }
{ NULL }
return (&module);