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*4f680cc6SAli Bahrami * Copyright 2009 Sun Microsystems, Inc. All rights reserved.
24d29b2c44Sab196087 * Use is subject to license terms.
25d29b2c44Sab196087 */
26d29b2c44Sab196087
27d29b2c44Sab196087 #include <stdio.h>
28d29b2c44Sab196087 #include <ctype.h>
29d29b2c44Sab196087 #include <elfedit.h>
30d29b2c44Sab196087 #include <sys/elf_SPARC.h>
31d29b2c44Sab196087 #include <sys/elf_amd64.h>
32d29b2c44Sab196087 #include <strings.h>
33d29b2c44Sab196087 #include <conv.h>
34d29b2c44Sab196087 #include <debug.h>
35d29b2c44Sab196087 #include <ehdr_msg.h>
36d29b2c44Sab196087
37d29b2c44Sab196087
38d29b2c44Sab196087
39d29b2c44Sab196087
40d29b2c44Sab196087 /*
41d29b2c44Sab196087 * This module handles changes to the ELF header
42d29b2c44Sab196087 */
43d29b2c44Sab196087
44d29b2c44Sab196087
45d29b2c44Sab196087
46d29b2c44Sab196087 /*
47d29b2c44Sab196087 * This module uses shared code for several of the commands.
48d29b2c44Sab196087 * It is sometimes necessary to know which specific command
49d29b2c44Sab196087 * is active.
50d29b2c44Sab196087 */
51d29b2c44Sab196087 typedef enum {
52d29b2c44Sab196087 /* Dump command, used as module default to display ELF header */
53d29b2c44Sab196087 EHDR_CMD_T_DUMP = 0, /* ehdr:dump */
54d29b2c44Sab196087
55d29b2c44Sab196087 /* Commands that correspond directly to ELF header fields */
56d29b2c44Sab196087 EHDR_CMD_T_E_IDENT = 1, /* ehdr:e_ident */
57d29b2c44Sab196087 EHDR_CMD_T_E_TYPE = 2, /* ehdr:e_type */
58d29b2c44Sab196087 EHDR_CMD_T_E_MACHINE = 3, /* ehdr:e_machine */
59d29b2c44Sab196087 EHDR_CMD_T_E_VERSION = 4, /* ehdr:e_version */
60d29b2c44Sab196087 EHDR_CMD_T_E_ENTRY = 5, /* ehdr:e_entry */
61d29b2c44Sab196087 EHDR_CMD_T_E_PHOFF = 6, /* ehdr:e_phoff */
62d29b2c44Sab196087 EHDR_CMD_T_E_SHOFF = 7, /* ehdr:e_shoff */
63d29b2c44Sab196087 EHDR_CMD_T_E_FLAGS = 8, /* ehdr:e_flags */
64d29b2c44Sab196087 EHDR_CMD_T_E_EHSIZE = 9, /* ehdr:e_ehsize */
65d29b2c44Sab196087 EHDR_CMD_T_E_PHENTSIZE = 10, /* ehdr:e_phentsize */
66d29b2c44Sab196087 EHDR_CMD_T_E_PHNUM = 11, /* ehdr:e_phnum */
67d29b2c44Sab196087 EHDR_CMD_T_E_SHENTSIZE = 12, /* ehdr:e_shentsize */
68d29b2c44Sab196087 EHDR_CMD_T_E_SHNUM = 13, /* ehdr:e_shnum */
69d29b2c44Sab196087 EHDR_CMD_T_E_SHSTRNDX = 14, /* ehdr:e_shstrndx */
70d29b2c44Sab196087
71d29b2c44Sab196087 /* Commands that correspond to the e_ident[] array in ELF hdr */
72d29b2c44Sab196087 EHDR_CMD_T_EI_MAG0 = 15, /* ehdr:ei_mag0 */
73d29b2c44Sab196087 EHDR_CMD_T_EI_MAG1 = 16, /* ehdr:ei_mag1 */
74d29b2c44Sab196087 EHDR_CMD_T_EI_MAG2 = 17, /* ehdr:ei_mag2 */
75d29b2c44Sab196087 EHDR_CMD_T_EI_MAG3 = 18, /* ehdr:ei_mag3 */
76d29b2c44Sab196087 EHDR_CMD_T_EI_CLASS = 19, /* ehdr:ei_class */
77d29b2c44Sab196087 EHDR_CMD_T_EI_DATA = 20, /* ehdr:ei_data */
78d29b2c44Sab196087 EHDR_CMD_T_EI_VERSION = 21, /* ehdr:ei_version */
79d29b2c44Sab196087 EHDR_CMD_T_EI_OSABI = 22, /* ehdr:ei_osabi */
80d29b2c44Sab196087 EHDR_CMD_T_EI_ABIVERSION = 23 /* ehdr:ei_abiversion */
81d29b2c44Sab196087 } EHDR_CMD_T;
82d29b2c44Sab196087
83d29b2c44Sab196087
84d29b2c44Sab196087
85d29b2c44Sab196087
86d29b2c44Sab196087
87d29b2c44Sab196087
88d29b2c44Sab196087 #ifndef _ELF64
89d29b2c44Sab196087 /*
90d29b2c44Sab196087 * We supply this function for the msg module
91d29b2c44Sab196087 */
92d29b2c44Sab196087 const char *
_ehdr_msg(Msg mid)93d29b2c44Sab196087 _ehdr_msg(Msg mid)
94d29b2c44Sab196087 {
95d29b2c44Sab196087 return (gettext(MSG_ORIG(mid)));
96d29b2c44Sab196087 }
97d29b2c44Sab196087 #endif
98d29b2c44Sab196087
99d29b2c44Sab196087
100d29b2c44Sab196087 /*
101d29b2c44Sab196087 * This function is supplied to elfedit through our elfedit_module_t
102d29b2c44Sab196087 * definition. It translates the opaque elfedit_i18nhdl_t handles
103d29b2c44Sab196087 * in our module interface into the actual strings for elfedit to
104d29b2c44Sab196087 * use.
105d29b2c44Sab196087 *
106d29b2c44Sab196087 * note:
107d29b2c44Sab196087 * This module uses Msg codes for its i18n handle type.
108d29b2c44Sab196087 * So the translation is simply to use MSG_INTL() to turn
109d29b2c44Sab196087 * it into a string and return it.
110d29b2c44Sab196087 */
111d29b2c44Sab196087 static const char *
mod_i18nhdl_to_str(elfedit_i18nhdl_t hdl)112d29b2c44Sab196087 mod_i18nhdl_to_str(elfedit_i18nhdl_t hdl)
113d29b2c44Sab196087 {
114d29b2c44Sab196087 Msg msg = (Msg)hdl;
115d29b2c44Sab196087
116d29b2c44Sab196087 return (MSG_INTL(msg));
117d29b2c44Sab196087 }
118d29b2c44Sab196087
119d29b2c44Sab196087
120d29b2c44Sab196087
121d29b2c44Sab196087 /*
122d29b2c44Sab196087 * The ehdr_opt_t enum specifies a bit value for every optional
123d29b2c44Sab196087 * argument allowed by a command in this module.
124d29b2c44Sab196087 */
125d29b2c44Sab196087 typedef enum {
126d29b2c44Sab196087 EHDR_OPT_F_AND = 1, /* -and: AND (&) values to dest */
127d29b2c44Sab196087 EHDR_OPT_F_CMP = 2, /* -cmp: Complement (~) values */
128d29b2c44Sab196087 EHDR_OPT_F_OR = 4, /* -or: OR (|) values to dest */
129d29b2c44Sab196087 EHDR_OPT_F_SHNDX = 8, /* -shndx: sec argument is index of */
130d29b2c44Sab196087 /* section, not name */
131d29b2c44Sab196087 EHDR_OPT_F_SHTYP = 16 /* -shtyp: sec argument is type of */
132d29b2c44Sab196087 /* section, not name */
133d29b2c44Sab196087 } ehdr_opt_t;
134d29b2c44Sab196087
135d29b2c44Sab196087
136d29b2c44Sab196087 /*
137d29b2c44Sab196087 * A variable of type ARGSTATE is used by each command to maintain
138d29b2c44Sab196087 * information about the arguments and related things. It is
139d29b2c44Sab196087 * initialized by process_args(), and used by the other routines.
140d29b2c44Sab196087 */
141d29b2c44Sab196087 typedef struct {
142d29b2c44Sab196087 elfedit_obj_state_t *obj_state;
143d29b2c44Sab196087 ehdr_opt_t optmask; /* Mask of options used */
144d29b2c44Sab196087 int argc; /* # of plain arguments */
145d29b2c44Sab196087 const char **argv; /* Plain arguments */
146d29b2c44Sab196087 } ARGSTATE;
147d29b2c44Sab196087
148d29b2c44Sab196087
149d29b2c44Sab196087
150d29b2c44Sab196087 /*
151d29b2c44Sab196087 * Standard argument processing for ehdr module
152d29b2c44Sab196087 *
153d29b2c44Sab196087 * entry
154d29b2c44Sab196087 * obj_state, argc, argv - Standard command arguments
155d29b2c44Sab196087 * argstate - Address of ARGSTATE block to be initialized
156d29b2c44Sab196087 *
157d29b2c44Sab196087 * exit:
158d29b2c44Sab196087 * On success, *argstate is initialized. On error,
159d29b2c44Sab196087 * an error is issued and this routine does not return.
160d29b2c44Sab196087 */
161d29b2c44Sab196087 static void
process_args(elfedit_obj_state_t * obj_state,int argc,const char * argv[],ARGSTATE * argstate)162d29b2c44Sab196087 process_args(elfedit_obj_state_t *obj_state, int argc, const char *argv[],
163d29b2c44Sab196087 ARGSTATE *argstate)
164d29b2c44Sab196087 {
165d29b2c44Sab196087 elfedit_getopt_state_t getopt_state;
166d29b2c44Sab196087 elfedit_getopt_ret_t *getopt_ret;
167d29b2c44Sab196087
168d29b2c44Sab196087 bzero(argstate, sizeof (*argstate));
169d29b2c44Sab196087 argstate->obj_state = obj_state;
170d29b2c44Sab196087
171d29b2c44Sab196087 elfedit_getopt_init(&getopt_state, &argc, &argv);
172d29b2c44Sab196087 /* Add each new option to the options mask */
173d29b2c44Sab196087 while ((getopt_ret = elfedit_getopt(&getopt_state)) != NULL)
174d29b2c44Sab196087 argstate->optmask |= getopt_ret->gor_idmask;
175d29b2c44Sab196087
176d29b2c44Sab196087 /* If there may be an arbitrary amount of output, use a pager */
177d29b2c44Sab196087 if (argc == 0)
178d29b2c44Sab196087 elfedit_pager_init();
179d29b2c44Sab196087
180d29b2c44Sab196087 /* Return the updated values of argc/argv */
181d29b2c44Sab196087 argstate->argc = argc;
182d29b2c44Sab196087 argstate->argv = argv;
183d29b2c44Sab196087 }
184d29b2c44Sab196087
185d29b2c44Sab196087
186d29b2c44Sab196087
187d29b2c44Sab196087
188d29b2c44Sab196087
189d29b2c44Sab196087
190d29b2c44Sab196087 /*
191d29b2c44Sab196087 * Format the given magic number byte into a buffer
192d29b2c44Sab196087 *
193d29b2c44Sab196087 * entry:
194d29b2c44Sab196087 * value - Value of the magic value byte given by
195d29b2c44Sab196087 * ehdr->ei_ident[EI_MAG?]
196d29b2c44Sab196087 */
197d29b2c44Sab196087 static const char *
conv_magic_value(int value)198d29b2c44Sab196087 conv_magic_value(int value)
199d29b2c44Sab196087 {
200d29b2c44Sab196087 /*
201d29b2c44Sab196087 * This routine can be called twice within a single C statement,
202d29b2c44Sab196087 * so we use alternating buffers on each call to allow this
203d29b2c44Sab196087 * without requiring the caller to supply a buffer (the size of
204d29b2c44Sab196087 * which they don't know).
205d29b2c44Sab196087 */
206d29b2c44Sab196087 static char buf1[20];
207d29b2c44Sab196087 static char buf2[20];
208d29b2c44Sab196087 static char *buf;
209d29b2c44Sab196087
210d29b2c44Sab196087 /* Switch buffers */
211d29b2c44Sab196087 buf = (buf == buf1) ? buf2 : buf1;
212d29b2c44Sab196087
213d29b2c44Sab196087 if (isprint(value))
214d29b2c44Sab196087 (void) snprintf(buf, sizeof (buf1),
215d29b2c44Sab196087 MSG_ORIG(MSG_FMT_HEXNUM_QCHR), value, value);
216d29b2c44Sab196087 else
217d29b2c44Sab196087 (void) snprintf(buf, sizeof (buf1),
218d29b2c44Sab196087 MSG_ORIG(MSG_FMT_HEXNUM), value);
219d29b2c44Sab196087 return (buf);
220d29b2c44Sab196087 }
221d29b2c44Sab196087
222d29b2c44Sab196087
223d29b2c44Sab196087
224d29b2c44Sab196087 /*
225d29b2c44Sab196087 * Print ELF header values, taking the calling command, and output style
226d29b2c44Sab196087 * into account.
227d29b2c44Sab196087 *
228d29b2c44Sab196087 * entry:
229d29b2c44Sab196087 * cmd - EHDR_CMD_T_* value giving identify of caller
230d29b2c44Sab196087 * e_ident_ndx - Ignored unless cmd is EHDR_CMD_T_E_IDENT. In IDENT
231d29b2c44Sab196087 * case, index of item in e_ident[] array to display, or
232d29b2c44Sab196087 * -1 to display the entire array.
233d29b2c44Sab196087 * autoprint - If True, output is only produced if the elfedit
234d29b2c44Sab196087 * autoprint flag is set. If False, output is always produced.
235d29b2c44Sab196087 * argstate - Argument state block
236d29b2c44Sab196087 */
237d29b2c44Sab196087 static void
print_ehdr(EHDR_CMD_T cmd,int e_ident_ndx,int autoprint,ARGSTATE * argstate)238d29b2c44Sab196087 print_ehdr(EHDR_CMD_T cmd, int e_ident_ndx, int autoprint,
239d29b2c44Sab196087 ARGSTATE *argstate)
240d29b2c44Sab196087 {
241d29b2c44Sab196087 elfedit_outstyle_t outstyle;
242d29b2c44Sab196087 Conv_fmt_flags_t flags_fmt_flags = 0;
243d29b2c44Sab196087 Ehdr *ehdr;
244d29b2c44Sab196087 int c;
245d29b2c44Sab196087 Conv_inv_buf_t inv_buf;
246d29b2c44Sab196087
247d29b2c44Sab196087 if (autoprint && ((elfedit_flags() & ELFEDIT_F_AUTOPRINT) == 0))
248d29b2c44Sab196087 return;
249d29b2c44Sab196087
250d29b2c44Sab196087 /*
251d29b2c44Sab196087 * Pick an output style. ehdr:dump is required to use the default
252d29b2c44Sab196087 * style. The other commands use the current output style.
253d29b2c44Sab196087 */
254d29b2c44Sab196087 if (cmd == EHDR_CMD_T_DUMP) {
255d29b2c44Sab196087 outstyle = ELFEDIT_OUTSTYLE_DEFAULT;
256d29b2c44Sab196087 } else {
257d29b2c44Sab196087 outstyle = elfedit_outstyle();
258d29b2c44Sab196087
259d29b2c44Sab196087 /*
260d29b2c44Sab196087 * When the caller specifies the simple output style,
261d29b2c44Sab196087 * omit the brackets from around the values.
262d29b2c44Sab196087 */
263d29b2c44Sab196087 if (outstyle == ELFEDIT_OUTSTYLE_SIMPLE)
264d29b2c44Sab196087 flags_fmt_flags = CONV_FMT_NOBKT;
265d29b2c44Sab196087
266d29b2c44Sab196087 /*
267d29b2c44Sab196087 * For things that show a single header item, switch
268d29b2c44Sab196087 * from default to simple mode.
269d29b2c44Sab196087 */
270d29b2c44Sab196087 if ((outstyle == ELFEDIT_OUTSTYLE_DEFAULT) &&
271d29b2c44Sab196087 ((cmd != EHDR_CMD_T_E_IDENT) || (e_ident_ndx != -1)))
272d29b2c44Sab196087 outstyle = ELFEDIT_OUTSTYLE_SIMPLE;
273d29b2c44Sab196087 }
274d29b2c44Sab196087
275d29b2c44Sab196087 ehdr = argstate->obj_state->os_ehdr;
276d29b2c44Sab196087
277d29b2c44Sab196087 /*
278d29b2c44Sab196087 * If doing default output, use elfdump style where we
279d29b2c44Sab196087 * show the full ELF header. In this case, the command
280d29b2c44Sab196087 * that called us doesn't matter. This can only happen
281d29b2c44Sab196087 * from ehdr:dump or ehdr:e_ident/
282d29b2c44Sab196087 */
283d29b2c44Sab196087 if (outstyle == ELFEDIT_OUTSTYLE_DEFAULT) {
284d29b2c44Sab196087 const char *ndx, *value;
285d29b2c44Sab196087 char ndx_buf[64], value_buf[20];
286d29b2c44Sab196087 int i;
287d29b2c44Sab196087
288d29b2c44Sab196087 if (cmd == EHDR_CMD_T_DUMP) {
289d29b2c44Sab196087 Elf_ehdr(NULL, ehdr,
290d29b2c44Sab196087 argstate->obj_state->os_secarr[0].sec_shdr);
291d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_STR_NL));
292d29b2c44Sab196087 }
293d29b2c44Sab196087
294d29b2c44Sab196087 /*
295d29b2c44Sab196087 * Elf_ehdr() does not display all of e_ident[], so we
296d29b2c44Sab196087 * augment by displaying the entire array separately.
297d29b2c44Sab196087 */
298d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_STR_EIDENT_HDR));
299d29b2c44Sab196087
300d29b2c44Sab196087 for (i = 0; i < EI_NIDENT; i++) {
301d29b2c44Sab196087 ndx = value = NULL;
302d29b2c44Sab196087
303d29b2c44Sab196087 switch (i) {
304d29b2c44Sab196087 case EI_MAG0:
305d29b2c44Sab196087 case EI_MAG1:
306d29b2c44Sab196087 case EI_MAG2:
307d29b2c44Sab196087 case EI_MAG3:
308d29b2c44Sab196087 ndx = elfedit_atoconst_value_to_str(
309d29b2c44Sab196087 ELFEDIT_CONST_EI, i, 1);
310d29b2c44Sab196087 value = conv_magic_value(ehdr->e_ident[i]);
311d29b2c44Sab196087 break;
312d29b2c44Sab196087 case EI_CLASS:
313d29b2c44Sab196087 ndx = elfedit_atoconst_value_to_str(
314d29b2c44Sab196087 ELFEDIT_CONST_EI, EI_CLASS, 1);
315d29b2c44Sab196087 value = conv_ehdr_class(ehdr->e_ident[EI_CLASS],
316d29b2c44Sab196087 0, &inv_buf);
317d29b2c44Sab196087 break;
318d29b2c44Sab196087 case EI_DATA:
319d29b2c44Sab196087 ndx = elfedit_atoconst_value_to_str(
320d29b2c44Sab196087 ELFEDIT_CONST_EI, EI_DATA, 1);
321d29b2c44Sab196087 value = conv_ehdr_data(ehdr->e_ident[EI_DATA],
322d29b2c44Sab196087 0, &inv_buf);
323d29b2c44Sab196087 break;
324d29b2c44Sab196087 case EI_VERSION:
325d29b2c44Sab196087 ndx = elfedit_atoconst_value_to_str(
326d29b2c44Sab196087 ELFEDIT_CONST_EI, EI_VERSION, 1);
327d29b2c44Sab196087 value = conv_ehdr_vers(
328d29b2c44Sab196087 ehdr->e_ident[EI_VERSION], 0, &inv_buf);
329d29b2c44Sab196087 break;
330d29b2c44Sab196087 case EI_OSABI:
331d29b2c44Sab196087 ndx = elfedit_atoconst_value_to_str(
332d29b2c44Sab196087 ELFEDIT_CONST_EI, EI_OSABI, 1);
333d29b2c44Sab196087 value = conv_ehdr_osabi(ehdr->e_ident[EI_OSABI],
334d29b2c44Sab196087 0, &inv_buf);
335d29b2c44Sab196087 break;
336d29b2c44Sab196087 case EI_ABIVERSION:
337d29b2c44Sab196087 ndx = elfedit_atoconst_value_to_str(
338d29b2c44Sab196087 ELFEDIT_CONST_EI, EI_ABIVERSION, 1);
339*4f680cc6SAli Bahrami value = conv_ehdr_abivers(
340*4f680cc6SAli Bahrami ehdr->e_ident[EI_OSABI],
341*4f680cc6SAli Bahrami ehdr->e_ident[EI_ABIVERSION],
342*4f680cc6SAli Bahrami CONV_FMT_DECIMAL, &inv_buf);
343d29b2c44Sab196087 break;
344d29b2c44Sab196087 default:
345d29b2c44Sab196087 value = value_buf;
346d29b2c44Sab196087 (void) snprintf(value_buf, sizeof (value_buf),
347d29b2c44Sab196087 MSG_ORIG(MSG_FMT_HEXNUM), ehdr->e_ident[i]);
348d29b2c44Sab196087 break;
349d29b2c44Sab196087 }
350d29b2c44Sab196087
351d29b2c44Sab196087 if (ndx == NULL)
352d29b2c44Sab196087 (void) snprintf(ndx_buf, sizeof (ndx_buf),
353d29b2c44Sab196087 MSG_ORIG(MSG_FMT_BKTINT), i);
354d29b2c44Sab196087 else
355d29b2c44Sab196087 (void) snprintf(ndx_buf, sizeof (ndx_buf),
356d29b2c44Sab196087 MSG_ORIG(MSG_FMT_BKTSTR), ndx);
357d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_EI_ELT),
358d29b2c44Sab196087 ndx_buf, value);
359d29b2c44Sab196087 }
360d29b2c44Sab196087 return;
361d29b2c44Sab196087 }
362d29b2c44Sab196087
363d29b2c44Sab196087
364d29b2c44Sab196087 switch (cmd) {
365d29b2c44Sab196087 case EHDR_CMD_T_E_IDENT:
366d29b2c44Sab196087 {
367d29b2c44Sab196087 int i, cnt;
368d29b2c44Sab196087
369d29b2c44Sab196087 /* Show one element, or the entire thing? */
370d29b2c44Sab196087 if (e_ident_ndx == -1) {
371d29b2c44Sab196087 i = 0;
372d29b2c44Sab196087 cnt = EI_NIDENT;
373d29b2c44Sab196087 } else {
374d29b2c44Sab196087 i = e_ident_ndx;
375d29b2c44Sab196087 cnt = 1;
376d29b2c44Sab196087 }
377d29b2c44Sab196087
378d29b2c44Sab196087 for (; cnt-- > 0; i++) {
379d29b2c44Sab196087 /*
380d29b2c44Sab196087 * If using numeric style, or there is
381d29b2c44Sab196087 * no conversion routine for this item,
382d29b2c44Sab196087 * print a simple hex value.
383d29b2c44Sab196087 */
384d29b2c44Sab196087 if ((outstyle == ELFEDIT_OUTSTYLE_NUM) ||
385*4f680cc6SAli Bahrami (i > EI_ABIVERSION)) {
386d29b2c44Sab196087 elfedit_printf(
387d29b2c44Sab196087 MSG_ORIG(MSG_FMT_HEXNUMNL),
388d29b2c44Sab196087 ehdr->e_ident[i]);
389d29b2c44Sab196087 continue;
390d29b2c44Sab196087 }
391d29b2c44Sab196087
392d29b2c44Sab196087 /* Handle special cases in simple mode */
393d29b2c44Sab196087 switch (i) {
394d29b2c44Sab196087 case EI_MAG0:
395d29b2c44Sab196087 case EI_MAG1:
396d29b2c44Sab196087 case EI_MAG2:
397d29b2c44Sab196087 case EI_MAG3:
398d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
399d29b2c44Sab196087 conv_magic_value(ehdr->e_ident[i]));
400d29b2c44Sab196087 continue;
401d29b2c44Sab196087 case EI_CLASS:
402d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
403d29b2c44Sab196087 conv_ehdr_class(
404d29b2c44Sab196087 ehdr->e_ident[EI_CLASS], 0,
405d29b2c44Sab196087 &inv_buf));
406d29b2c44Sab196087 continue;
407d29b2c44Sab196087 case EI_DATA:
408d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
409d29b2c44Sab196087 conv_ehdr_data(
410d29b2c44Sab196087 ehdr->e_ident[EI_DATA], 0,
411d29b2c44Sab196087 &inv_buf));
412d29b2c44Sab196087 continue;
413d29b2c44Sab196087 case EI_VERSION:
414d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
415d29b2c44Sab196087 conv_ehdr_vers(
416d29b2c44Sab196087 ehdr->e_ident[EI_VERSION], 0,
417d29b2c44Sab196087 &inv_buf));
418d29b2c44Sab196087 continue;
419d29b2c44Sab196087 case EI_OSABI:
420d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
421d29b2c44Sab196087 conv_ehdr_osabi(
422d29b2c44Sab196087 ehdr->e_ident[EI_OSABI], 0,
423d29b2c44Sab196087 &inv_buf));
424d29b2c44Sab196087 continue;
425*4f680cc6SAli Bahrami case EI_ABIVERSION:
426*4f680cc6SAli Bahrami elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
427*4f680cc6SAli Bahrami conv_ehdr_abivers(
428*4f680cc6SAli Bahrami ehdr->e_ident[EI_OSABI],
429*4f680cc6SAli Bahrami ehdr->e_ident[EI_ABIVERSION],
430*4f680cc6SAli Bahrami CONV_FMT_DECIMAL, &inv_buf));
431*4f680cc6SAli Bahrami continue;
432d29b2c44Sab196087 }
433d29b2c44Sab196087 }
434d29b2c44Sab196087 }
435d29b2c44Sab196087 return;
436d29b2c44Sab196087
437d29b2c44Sab196087 case EHDR_CMD_T_E_TYPE:
438d29b2c44Sab196087 if (outstyle == ELFEDIT_OUTSTYLE_SIMPLE)
439d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
440*4f680cc6SAli Bahrami conv_ehdr_type(ehdr->e_ident[EI_OSABI],
441*4f680cc6SAli Bahrami ehdr->e_type, 0, &inv_buf));
442d29b2c44Sab196087 else
443d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_DECNUMNL),
444d29b2c44Sab196087 ehdr->e_type);
445d29b2c44Sab196087 return;
446d29b2c44Sab196087
447d29b2c44Sab196087 case EHDR_CMD_T_E_MACHINE:
448d29b2c44Sab196087 if (outstyle == ELFEDIT_OUTSTYLE_SIMPLE) {
449d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
450d29b2c44Sab196087 conv_ehdr_mach(ehdr->e_machine, 0, &inv_buf));
451d29b2c44Sab196087 } else {
452d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_DECNUMNL),
453d29b2c44Sab196087 EC_WORD(ehdr->e_machine));
454d29b2c44Sab196087 }
455d29b2c44Sab196087 return;
456d29b2c44Sab196087
457d29b2c44Sab196087 case EHDR_CMD_T_E_VERSION:
458d29b2c44Sab196087 if (outstyle == ELFEDIT_OUTSTYLE_SIMPLE)
459d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
460d29b2c44Sab196087 conv_ehdr_vers(ehdr->e_version, 0, &inv_buf));
461d29b2c44Sab196087 else
462d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_DECNUMNL),
463d29b2c44Sab196087 ehdr->e_version);
464d29b2c44Sab196087 return;
465d29b2c44Sab196087
466d29b2c44Sab196087 case EHDR_CMD_T_E_ENTRY:
467d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_HEXNUMNL),
468d29b2c44Sab196087 EC_WORD(ehdr->e_entry));
469d29b2c44Sab196087 return;
470d29b2c44Sab196087
471d29b2c44Sab196087 case EHDR_CMD_T_E_PHOFF:
472d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_HEXNUMNL),
473d29b2c44Sab196087 EC_WORD(ehdr->e_phoff));
474d29b2c44Sab196087 return;
475d29b2c44Sab196087
476d29b2c44Sab196087 case EHDR_CMD_T_E_SHOFF:
477d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_HEXNUMNL),
478d29b2c44Sab196087 EC_WORD(ehdr->e_shoff));
479d29b2c44Sab196087 return;
480d29b2c44Sab196087
481d29b2c44Sab196087 case EHDR_CMD_T_E_FLAGS:
482d29b2c44Sab196087 if (outstyle == ELFEDIT_OUTSTYLE_SIMPLE) {
483d29b2c44Sab196087 Conv_ehdr_flags_buf_t flags_buf;
484d29b2c44Sab196087
485d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
486d29b2c44Sab196087 conv_ehdr_flags(ehdr->e_machine, ehdr->e_flags,
487d29b2c44Sab196087 flags_fmt_flags, &flags_buf));
488d29b2c44Sab196087 } else {
489d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_HEXNUMNL),
490d29b2c44Sab196087 ehdr->e_flags);
491d29b2c44Sab196087 }
492d29b2c44Sab196087 return;
493d29b2c44Sab196087
494d29b2c44Sab196087 case EHDR_CMD_T_E_EHSIZE:
495d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_DECNUMNL),
496d29b2c44Sab196087 EC_WORD(ehdr->e_ehsize));
497d29b2c44Sab196087 return;
498d29b2c44Sab196087
499d29b2c44Sab196087 case EHDR_CMD_T_E_PHENTSIZE:
500d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_DECNUMNL),
501d29b2c44Sab196087 EC_WORD(ehdr->e_phentsize));
502d29b2c44Sab196087 return;
503d29b2c44Sab196087
504d29b2c44Sab196087 case EHDR_CMD_T_E_PHNUM:
505d29b2c44Sab196087 {
506d29b2c44Sab196087 Word num = ehdr->e_phnum;
507d29b2c44Sab196087
508d29b2c44Sab196087 /*
509d29b2c44Sab196087 * If using extended indexes, fetch the real
510d29b2c44Sab196087 * value from shdr[0].sh_info
511d29b2c44Sab196087 */
512d29b2c44Sab196087 if (num == PN_XNUM)
513d29b2c44Sab196087 num = argstate->obj_state->
514d29b2c44Sab196087 os_secarr[0].sec_shdr->sh_info;
515d29b2c44Sab196087
516d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_DECNUMNL),
517d29b2c44Sab196087 EC_WORD(num));
518d29b2c44Sab196087 }
519d29b2c44Sab196087 return;
520d29b2c44Sab196087
521d29b2c44Sab196087 case EHDR_CMD_T_E_SHENTSIZE:
522d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_DECNUMNL),
523d29b2c44Sab196087 EC_WORD(ehdr->e_shentsize));
524d29b2c44Sab196087 return;
525d29b2c44Sab196087
526d29b2c44Sab196087 case EHDR_CMD_T_E_SHNUM:
527d29b2c44Sab196087 {
528d29b2c44Sab196087 Word num = ehdr->e_shnum;
529d29b2c44Sab196087
530d29b2c44Sab196087 /*
531d29b2c44Sab196087 * If using extended indexes, fetch the real
532d29b2c44Sab196087 * value from shdr[0].sh_size
533d29b2c44Sab196087 */
534d29b2c44Sab196087 if (num == 0)
535d29b2c44Sab196087 num = argstate->obj_state->
536d29b2c44Sab196087 os_secarr[0].sec_shdr->sh_size;
537d29b2c44Sab196087
538d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_DECNUMNL),
539d29b2c44Sab196087 EC_WORD(num));
540d29b2c44Sab196087 }
541d29b2c44Sab196087 return;
542d29b2c44Sab196087
543d29b2c44Sab196087 case EHDR_CMD_T_E_SHSTRNDX:
544d29b2c44Sab196087 {
545d29b2c44Sab196087 Word num = ehdr->e_shstrndx;
546d29b2c44Sab196087
547d29b2c44Sab196087 /*
548d29b2c44Sab196087 * If using extended indexes, fetch the real
549d29b2c44Sab196087 * value from shdr[0].sh_link
550d29b2c44Sab196087 */
551d29b2c44Sab196087 if (num == SHN_XINDEX)
552d29b2c44Sab196087 num = argstate->obj_state->
553d29b2c44Sab196087 os_secarr[0].sec_shdr->sh_link;
554d29b2c44Sab196087
555d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_DECNUMNL),
556d29b2c44Sab196087 EC_WORD(num));
557d29b2c44Sab196087 }
558d29b2c44Sab196087 return;
559d29b2c44Sab196087
560d29b2c44Sab196087 case EHDR_CMD_T_EI_MAG0:
561d29b2c44Sab196087 case EHDR_CMD_T_EI_MAG1:
562d29b2c44Sab196087 case EHDR_CMD_T_EI_MAG2:
563d29b2c44Sab196087 case EHDR_CMD_T_EI_MAG3:
564d29b2c44Sab196087 /* This depends on EHDR_CMD_T_EI_MAG[0-3] being contiguous */
565d29b2c44Sab196087 c = ehdr->e_ident[cmd - EHDR_CMD_T_EI_MAG0];
566d29b2c44Sab196087 if (outstyle == ELFEDIT_OUTSTYLE_SIMPLE)
567d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
568d29b2c44Sab196087 conv_magic_value(c));
569d29b2c44Sab196087 else
570d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_HEXNUMNL), c);
571d29b2c44Sab196087 return;
572d29b2c44Sab196087
573d29b2c44Sab196087 case EHDR_CMD_T_EI_CLASS:
574d29b2c44Sab196087 c = ehdr->e_ident[EI_CLASS];
575d29b2c44Sab196087 if (outstyle == ELFEDIT_OUTSTYLE_SIMPLE)
576d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
577d29b2c44Sab196087 conv_ehdr_class(c, 0, &inv_buf));
578d29b2c44Sab196087 else
579d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_HEXNUMNL), c);
580d29b2c44Sab196087 return;
581d29b2c44Sab196087
582d29b2c44Sab196087 case EHDR_CMD_T_EI_DATA:
583d29b2c44Sab196087 c = ehdr->e_ident[EI_DATA];
584d29b2c44Sab196087 if (outstyle == ELFEDIT_OUTSTYLE_SIMPLE)
585d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
586d29b2c44Sab196087 conv_ehdr_data(c, 0, &inv_buf));
587d29b2c44Sab196087 else
588d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_HEXNUMNL), c);
589d29b2c44Sab196087 return;
590d29b2c44Sab196087
591d29b2c44Sab196087 case EHDR_CMD_T_EI_VERSION:
592d29b2c44Sab196087 c = ehdr->e_ident[EI_VERSION];
593d29b2c44Sab196087 if (outstyle == ELFEDIT_OUTSTYLE_SIMPLE)
594d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
595d29b2c44Sab196087 conv_ehdr_vers(c, 0, &inv_buf));
596d29b2c44Sab196087 else
597d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_HEXNUMNL), c);
598d29b2c44Sab196087 return;
599d29b2c44Sab196087
600d29b2c44Sab196087 case EHDR_CMD_T_EI_OSABI:
601d29b2c44Sab196087 c = ehdr->e_ident[EI_OSABI];
602d29b2c44Sab196087 if (outstyle == ELFEDIT_OUTSTYLE_SIMPLE) {
603d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
604d29b2c44Sab196087 conv_ehdr_osabi(c, 0, &inv_buf));
605d29b2c44Sab196087 } else {
606d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_HEXNUMNL),
607d29b2c44Sab196087 EC_WORD(c));
608d29b2c44Sab196087 }
609d29b2c44Sab196087 return;
610d29b2c44Sab196087
611d29b2c44Sab196087 case EHDR_CMD_T_EI_ABIVERSION:
612*4f680cc6SAli Bahrami c = ehdr->e_ident[EI_ABIVERSION];
613*4f680cc6SAli Bahrami if (outstyle == ELFEDIT_OUTSTYLE_SIMPLE) {
614*4f680cc6SAli Bahrami elfedit_printf(MSG_ORIG(MSG_FMT_STRNL),
615*4f680cc6SAli Bahrami conv_ehdr_abivers(ehdr->e_ident[EI_OSABI],
616*4f680cc6SAli Bahrami c, CONV_FMT_DECIMAL, &inv_buf));
617*4f680cc6SAli Bahrami } else {
618d29b2c44Sab196087 elfedit_printf(MSG_ORIG(MSG_FMT_HEXNUMNL),
619*4f680cc6SAli Bahrami EC_WORD(c));
620*4f680cc6SAli Bahrami }
621d29b2c44Sab196087 return;
622d29b2c44Sab196087 }
623d29b2c44Sab196087 }
624d29b2c44Sab196087
625d29b2c44Sab196087
626d29b2c44Sab196087 /*
627d29b2c44Sab196087 * Common body for the ehdr: module commands. These commands
628d29b2c44Sab196087 * share a large amount of common behavior, so it is convenient
629d29b2c44Sab196087 * to centralize things and use the cmd argument to handle the
630d29b2c44Sab196087 * small differences.
631d29b2c44Sab196087 *
632d29b2c44Sab196087 * entry:
633d29b2c44Sab196087 * cmd - One of the EHDR_CMD_T_* constants listed above, specifying
634d29b2c44Sab196087 * which command to implement.
635d29b2c44Sab196087 * obj_state, argc, argv - Standard command arguments
636d29b2c44Sab196087 */
637d29b2c44Sab196087 static elfedit_cmdret_t
cmd_body(EHDR_CMD_T cmd,elfedit_obj_state_t * obj_state,int argc,const char * argv[])638d29b2c44Sab196087 cmd_body(EHDR_CMD_T cmd, elfedit_obj_state_t *obj_state,
639d29b2c44Sab196087 int argc, const char *argv[])
640d29b2c44Sab196087 {
641d29b2c44Sab196087 /*
642d29b2c44Sab196087 * When a call comes in for ehdr:e_ident[ndx], and the
643d29b2c44Sab196087 * specified element is one that we have a special command
644d29b2c44Sab196087 * for, then we revector to that special command instead
645d29b2c44Sab196087 * of using the generic ehdr:e_ident processing. This array,
646d29b2c44Sab196087 * which is indexed by the e_ident[] index value is used
647d29b2c44Sab196087 * to decide if that is the case. If the resulting value
648d29b2c44Sab196087 * is EHDR_CMD_T_E_IDENT, then the generic processing is
649d29b2c44Sab196087 * used. Otherwise, we revector to the specified command.
650d29b2c44Sab196087 */
651d29b2c44Sab196087 static const int e_ident_revector[16] = {
652d29b2c44Sab196087 EHDR_CMD_T_EI_MAG0, /* 0: EI_MAG0 */
653d29b2c44Sab196087 EHDR_CMD_T_EI_MAG1, /* 1: EI_MAG1 */
654d29b2c44Sab196087 EHDR_CMD_T_EI_MAG2, /* 2: EI_MAG2 */
655d29b2c44Sab196087 EHDR_CMD_T_EI_MAG3, /* 3: EI_MAG3 */
656d29b2c44Sab196087 EHDR_CMD_T_EI_CLASS, /* 4: EI_CLASS */
657d29b2c44Sab196087 EHDR_CMD_T_EI_DATA, /* 5: EI_DATA */
658d29b2c44Sab196087 EHDR_CMD_T_EI_VERSION, /* 6: EI_VERSION */
659d29b2c44Sab196087 EHDR_CMD_T_EI_OSABI, /* 7: EI_OSABI */
660d29b2c44Sab196087 EHDR_CMD_T_EI_ABIVERSION, /* 8: EI_ABIVERSION */
661d29b2c44Sab196087 EHDR_CMD_T_E_IDENT, /* 9: generic */
662d29b2c44Sab196087 EHDR_CMD_T_E_IDENT, /* 10: generic */
663d29b2c44Sab196087 EHDR_CMD_T_E_IDENT, /* 11: generic */
664d29b2c44Sab196087 EHDR_CMD_T_E_IDENT, /* 12: generic */
665d29b2c44Sab196087 EHDR_CMD_T_E_IDENT, /* 13: generic */
666d29b2c44Sab196087 EHDR_CMD_T_E_IDENT, /* 14: generic */
667d29b2c44Sab196087 EHDR_CMD_T_E_IDENT, /* 15: generic */
668d29b2c44Sab196087 };
669d29b2c44Sab196087
670d29b2c44Sab196087
671d29b2c44Sab196087 ARGSTATE argstate;
672d29b2c44Sab196087 Ehdr *ehdr;
673d29b2c44Sab196087 elfedit_cmdret_t ret = ELFEDIT_CMDRET_NONE;
674d29b2c44Sab196087 int e_ident_ndx = -1;
675d29b2c44Sab196087 Conv_inv_buf_t inv_buf1, inv_buf2;
676d29b2c44Sab196087
677d29b2c44Sab196087 /* Process the optional arguments */
678d29b2c44Sab196087 process_args(obj_state, argc, argv, &argstate);
679d29b2c44Sab196087
680d29b2c44Sab196087 /* Check number of arguments */
681d29b2c44Sab196087 switch (cmd) {
682d29b2c44Sab196087 case EHDR_CMD_T_DUMP:
683d29b2c44Sab196087 /* ehdr:dump does not accept arguments */
684d29b2c44Sab196087 if (argstate.argc > 0)
685d29b2c44Sab196087 elfedit_command_usage();
686d29b2c44Sab196087 break;
687d29b2c44Sab196087 case EHDR_CMD_T_E_IDENT:
688d29b2c44Sab196087 /*
689d29b2c44Sab196087 * ehdr:e_ident accepts 1 or 2 arguments, the first
690d29b2c44Sab196087 * being the index into the array, and the second being
691d29b2c44Sab196087 * the value. If there are arguments, then process the
692d29b2c44Sab196087 * index, and remove it from the argument list.
693d29b2c44Sab196087 */
694d29b2c44Sab196087 if (argstate.argc > 0) {
695d29b2c44Sab196087 if (argstate.argc > 2)
696d29b2c44Sab196087 elfedit_command_usage();
697d29b2c44Sab196087 e_ident_ndx = (int)
698d29b2c44Sab196087 elfedit_atoconst_range(argstate.argv[0],
699d29b2c44Sab196087 MSG_ORIG(MSG_STR_INDEX), 0, EI_NIDENT - 1,
700d29b2c44Sab196087 ELFEDIT_CONST_EI);
701d29b2c44Sab196087 argstate.argc--;
702d29b2c44Sab196087 argstate.argv++;
703d29b2c44Sab196087
704d29b2c44Sab196087 /*
705d29b2c44Sab196087 * If the index is for one of the e_ident elements
706d29b2c44Sab196087 * that we have a special command for, then switch
707d29b2c44Sab196087 * to that command. e_ident_revector[] returns
708d29b2c44Sab196087 * EHDR_CMD_T_E_IDENT in the cases where such a command
709d29b2c44Sab196087 * does not exist, in which case we'll continue with the
710d29b2c44Sab196087 * generic code.
711d29b2c44Sab196087 */
712d29b2c44Sab196087 cmd = e_ident_revector[e_ident_ndx];
713d29b2c44Sab196087 }
714d29b2c44Sab196087 break;
715d29b2c44Sab196087 case EHDR_CMD_T_E_FLAGS:
716d29b2c44Sab196087 /* ehdr:e_flags accepts an arbitrary number of arguments */
717d29b2c44Sab196087 break;
718d29b2c44Sab196087 default:
719d29b2c44Sab196087 /* The remaining commands accept a single optional argument */
720d29b2c44Sab196087 if (argstate.argc > 1)
721d29b2c44Sab196087 elfedit_command_usage();
722d29b2c44Sab196087 break;
723d29b2c44Sab196087 }
724d29b2c44Sab196087
725d29b2c44Sab196087 /* If there are no arguments, dump the ELF header and return */
726d29b2c44Sab196087 if (argstate.argc == 0) {
727d29b2c44Sab196087 print_ehdr(cmd, e_ident_ndx, 0, &argstate);
728d29b2c44Sab196087 return (ELFEDIT_CMDRET_NONE);
729d29b2c44Sab196087 }
730d29b2c44Sab196087
731d29b2c44Sab196087 ehdr = obj_state->os_ehdr;
732d29b2c44Sab196087 switch (cmd) {
733d29b2c44Sab196087 /*
734d29b2c44Sab196087 * EHDR_CMD_T_DUMP can't get here: It never has an
735d29b2c44Sab196087 * argument, and is handled above.
736d29b2c44Sab196087 */
737d29b2c44Sab196087
738d29b2c44Sab196087 case EHDR_CMD_T_E_IDENT:
739d29b2c44Sab196087 {
740d29b2c44Sab196087 /*
741d29b2c44Sab196087 * Only those e_ident[] elements for which we
742d29b2c44Sab196087 * don't have a specialized command come here.
743d29b2c44Sab196087 * The argument is a value to be set in
744d29b2c44Sab196087 * e_ident[e_ident_ndx].
745d29b2c44Sab196087 */
746d29b2c44Sab196087 uchar_t value = (uchar_t)
747d29b2c44Sab196087 elfedit_atoui_range(argstate.argv[0],
748d29b2c44Sab196087 MSG_ORIG(MSG_STR_VALUE), 0, 255, NULL);
749d29b2c44Sab196087
750d29b2c44Sab196087 if (ehdr->e_ident[e_ident_ndx] == value) {
751d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
752d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_EI_D_X_OK),
753d29b2c44Sab196087 e_ident_ndx, EC_WORD(value));
754d29b2c44Sab196087 } else {
755d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
756d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_EI_D_X_CHG),
757d29b2c44Sab196087 e_ident_ndx, ehdr->e_ident[e_ident_ndx],
758d29b2c44Sab196087 value);
759d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
760d29b2c44Sab196087 ehdr->e_ident[e_ident_ndx] = value;
761d29b2c44Sab196087 }
762d29b2c44Sab196087 }
763d29b2c44Sab196087 break;
764d29b2c44Sab196087
765d29b2c44Sab196087 case EHDR_CMD_T_E_TYPE:
766d29b2c44Sab196087 {
767d29b2c44Sab196087 /* The argument gives the object type */
768d29b2c44Sab196087 Half type = (Half) elfedit_atoconst(argstate.argv[0],
769d29b2c44Sab196087 ELFEDIT_CONST_ET);
770d29b2c44Sab196087 const char *name = MSG_ORIG(MSG_CMD_E_TYPE);
771d29b2c44Sab196087
772d29b2c44Sab196087 if (ehdr->e_type == type) {
773d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
774d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_S_OK), name,
775*4f680cc6SAli Bahrami conv_ehdr_type(ehdr->e_ident[EI_OSABI],
776*4f680cc6SAli Bahrami ehdr->e_type, 0, &inv_buf1));
777d29b2c44Sab196087 } else {
778d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
779d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_S_CHG), name,
780*4f680cc6SAli Bahrami conv_ehdr_type(ehdr->e_ident[EI_OSABI],
781*4f680cc6SAli Bahrami ehdr->e_type, 0, &inv_buf1),
782*4f680cc6SAli Bahrami conv_ehdr_type(ehdr->e_ident[EI_OSABI],
783*4f680cc6SAli Bahrami type, 0, &inv_buf2));
784d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
785d29b2c44Sab196087 ehdr->e_type = type;
786d29b2c44Sab196087 }
787d29b2c44Sab196087 }
788d29b2c44Sab196087 break;
789d29b2c44Sab196087
790d29b2c44Sab196087 case EHDR_CMD_T_E_MACHINE:
791d29b2c44Sab196087 {
792d29b2c44Sab196087 /* The argument gives the machine code */
793d29b2c44Sab196087 Half mach = (Half) elfedit_atoconst(argstate.argv[0],
794d29b2c44Sab196087 ELFEDIT_CONST_EM);
795d29b2c44Sab196087 const char *name = MSG_ORIG(MSG_CMD_E_MACHINE);
796d29b2c44Sab196087
797d29b2c44Sab196087 if (ehdr->e_machine == mach) {
798d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
799d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_S_OK), name,
800d29b2c44Sab196087 conv_ehdr_mach(ehdr->e_machine, 0,
801d29b2c44Sab196087 &inv_buf1));
802d29b2c44Sab196087 } else {
803d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
804d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_S_CHG), name,
805d29b2c44Sab196087 conv_ehdr_mach(ehdr->e_machine, 0,
806d29b2c44Sab196087 &inv_buf1),
807d29b2c44Sab196087 conv_ehdr_mach(mach, 0, &inv_buf2));
808*4f680cc6SAli Bahrami ret = ELFEDIT_CMDRET_MOD_OS_MACH;
809d29b2c44Sab196087 ehdr->e_machine = mach;
810*4f680cc6SAli Bahrami
811d29b2c44Sab196087 }
812d29b2c44Sab196087 }
813d29b2c44Sab196087 break;
814d29b2c44Sab196087
815d29b2c44Sab196087 case EHDR_CMD_T_E_VERSION:
816d29b2c44Sab196087 {
817d29b2c44Sab196087 /* The argument gives the version */
818d29b2c44Sab196087 Word ver = (Word) elfedit_atoconst(argstate.argv[0],
819d29b2c44Sab196087 ELFEDIT_CONST_EV);
820d29b2c44Sab196087 const char *name = MSG_ORIG(MSG_CMD_E_VERSION);
821d29b2c44Sab196087
822d29b2c44Sab196087 if (ehdr->e_version == ver) {
823d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
824d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_S_OK), name,
825d29b2c44Sab196087 conv_ehdr_vers(ehdr->e_version, 0,
826d29b2c44Sab196087 &inv_buf1));
827d29b2c44Sab196087 } else {
828d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
829d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_S_CHG), name,
830d29b2c44Sab196087 conv_ehdr_vers(ehdr->e_version, 0,
831d29b2c44Sab196087 &inv_buf1),
832d29b2c44Sab196087 conv_ehdr_vers(ver, 0, &inv_buf2));
833d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
834d29b2c44Sab196087 ehdr->e_version = ver;
835d29b2c44Sab196087 }
836d29b2c44Sab196087 }
837d29b2c44Sab196087 break;
838d29b2c44Sab196087
839d29b2c44Sab196087 case EHDR_CMD_T_E_ENTRY:
840d29b2c44Sab196087 {
841d29b2c44Sab196087 /* The argument gives the entry address */
842d29b2c44Sab196087 Addr entry = (Addr)
843d29b2c44Sab196087 elfedit_atoui(argstate.argv[0], NULL);
844d29b2c44Sab196087 const char *name = MSG_ORIG(MSG_CMD_E_ENTRY);
845d29b2c44Sab196087
846d29b2c44Sab196087 if (ehdr->e_entry == entry) {
847d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
848d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_LLX_OK), name,
849d29b2c44Sab196087 EC_ADDR(ehdr->e_entry));
850d29b2c44Sab196087 } else {
851d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
852d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_LLX_CHG), name,
853d29b2c44Sab196087 EC_ADDR(ehdr->e_entry), EC_ADDR(entry));
854d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
855d29b2c44Sab196087 ehdr->e_entry = entry;
856d29b2c44Sab196087 }
857d29b2c44Sab196087 }
858d29b2c44Sab196087 break;
859d29b2c44Sab196087
860d29b2c44Sab196087 case EHDR_CMD_T_E_PHOFF:
861d29b2c44Sab196087 {
862d29b2c44Sab196087 /* The argument gives the program header offset */
863d29b2c44Sab196087 Off off = (Off) elfedit_atoui(argstate.argv[0],
864d29b2c44Sab196087 NULL);
865d29b2c44Sab196087 const char *name = MSG_ORIG(MSG_CMD_E_PHOFF);
866d29b2c44Sab196087
867d29b2c44Sab196087 if (ehdr->e_phoff == off) {
868d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
869d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_LLX_OK), name,
870d29b2c44Sab196087 EC_OFF(ehdr->e_phoff));
871d29b2c44Sab196087 } else {
872d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
873d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_LLX_CHG), name,
874d29b2c44Sab196087 EC_OFF(ehdr->e_phoff), EC_OFF(off));
875d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
876d29b2c44Sab196087 ehdr->e_phoff = off;
877d29b2c44Sab196087 }
878d29b2c44Sab196087 }
879d29b2c44Sab196087 break;
880d29b2c44Sab196087
881d29b2c44Sab196087 case EHDR_CMD_T_E_SHOFF:
882d29b2c44Sab196087 {
883d29b2c44Sab196087 /* The argument gives the section header offset */
884d29b2c44Sab196087 Off off = (Off) elfedit_atoui(argstate.argv[0],
885d29b2c44Sab196087 NULL);
886d29b2c44Sab196087 const char *name = MSG_ORIG(MSG_CMD_E_SHOFF);
887d29b2c44Sab196087
888d29b2c44Sab196087 if (ehdr->e_shoff == off) {
889d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
890d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_LLX_OK), name,
891d29b2c44Sab196087 EC_OFF(ehdr->e_shoff));
892d29b2c44Sab196087 } else {
893d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
894d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_LLX_CHG), name,
895d29b2c44Sab196087 EC_OFF(ehdr->e_shoff), EC_OFF(off));
896d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
897d29b2c44Sab196087 ehdr->e_shoff = off;
898d29b2c44Sab196087 }
899d29b2c44Sab196087 }
900d29b2c44Sab196087 break;
901d29b2c44Sab196087
902d29b2c44Sab196087 case EHDR_CMD_T_E_FLAGS:
903d29b2c44Sab196087 {
904d29b2c44Sab196087 Conv_ehdr_flags_buf_t flags_buf1, flags_buf2;
905d29b2c44Sab196087 const char *name = MSG_ORIG(MSG_CMD_E_FLAGS);
906d29b2c44Sab196087 Word flags = 0;
907d29b2c44Sab196087 int i;
908d29b2c44Sab196087
909d29b2c44Sab196087 /* Collect the arguments */
910d29b2c44Sab196087 for (i = 0; i < argstate.argc; i++)
911d29b2c44Sab196087 flags |= (Word)
912d29b2c44Sab196087 elfedit_atoconst(argstate.argv[i],
913d29b2c44Sab196087 ELFEDIT_CONST_EF);
914d29b2c44Sab196087
915d29b2c44Sab196087 /* Complement the value? */
916d29b2c44Sab196087 if (argstate.optmask & EHDR_OPT_F_CMP)
917d29b2c44Sab196087 flags = ~flags;
918d29b2c44Sab196087
919d29b2c44Sab196087 /* Perform any requested bit operations */
920d29b2c44Sab196087 if (argstate.optmask & EHDR_OPT_F_AND)
921d29b2c44Sab196087 flags &= ehdr->e_flags;
922d29b2c44Sab196087 else if (argstate.optmask & EHDR_OPT_F_OR)
923d29b2c44Sab196087 flags |= ehdr->e_flags;
924d29b2c44Sab196087
925d29b2c44Sab196087 /* Set the value */
926d29b2c44Sab196087 if (ehdr->e_flags == flags) {
927d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
928d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_S_OK), name,
929d29b2c44Sab196087 conv_ehdr_flags(ehdr->e_machine,
930d29b2c44Sab196087 ehdr->e_flags, 0, &flags_buf1));
931d29b2c44Sab196087 } else {
932d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
933d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_S_CHG), name,
934d29b2c44Sab196087 conv_ehdr_flags(ehdr->e_machine,
935d29b2c44Sab196087 ehdr->e_flags, 0, &flags_buf1),
936d29b2c44Sab196087 conv_ehdr_flags(ehdr->e_machine,
937d29b2c44Sab196087 flags, 0, &flags_buf2));
938d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
939d29b2c44Sab196087 ehdr->e_flags = flags;
940d29b2c44Sab196087 }
941d29b2c44Sab196087 }
942d29b2c44Sab196087 break;
943d29b2c44Sab196087
944d29b2c44Sab196087 case EHDR_CMD_T_E_EHSIZE:
945d29b2c44Sab196087 {
946d29b2c44Sab196087 /* The argument gives the ELF header size */
947d29b2c44Sab196087 Half ehsize = (Half) elfedit_atoui(argstate.argv[0],
948d29b2c44Sab196087 NULL);
949d29b2c44Sab196087 const char *name = MSG_ORIG(MSG_CMD_E_EHSIZE);
950d29b2c44Sab196087
951d29b2c44Sab196087 if (ehdr->e_ehsize == ehsize) {
952d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
953d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_D_OK), name,
954d29b2c44Sab196087 EC_WORD(ehdr->e_ehsize));
955d29b2c44Sab196087 } else {
956d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
957d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_D_CHG), name,
958d29b2c44Sab196087 EC_WORD(ehdr->e_ehsize), EC_WORD(ehsize));
959d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
960d29b2c44Sab196087 ehdr->e_ehsize = ehsize;
961d29b2c44Sab196087 }
962d29b2c44Sab196087 }
963d29b2c44Sab196087 break;
964d29b2c44Sab196087
965d29b2c44Sab196087 case EHDR_CMD_T_E_PHENTSIZE:
966d29b2c44Sab196087 {
967d29b2c44Sab196087 /*
968d29b2c44Sab196087 * The argument gives the size of a program
969d29b2c44Sab196087 * header element.
970d29b2c44Sab196087 */
971d29b2c44Sab196087 Half phentsize = (Half) elfedit_atoui(argstate.argv[0],
972d29b2c44Sab196087 NULL);
973d29b2c44Sab196087 const char *name = MSG_ORIG(MSG_CMD_E_PHENTSIZE);
974d29b2c44Sab196087
975d29b2c44Sab196087 if (ehdr->e_phentsize == phentsize) {
976d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
977d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_D_OK), name,
978d29b2c44Sab196087 EC_WORD(ehdr->e_phentsize));
979d29b2c44Sab196087 } else {
980d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
981d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_D_CHG), name,
982d29b2c44Sab196087 EC_WORD(ehdr->e_phentsize),
983d29b2c44Sab196087 EC_WORD(phentsize));
984d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
985d29b2c44Sab196087 ehdr->e_phentsize = phentsize;
986d29b2c44Sab196087 }
987d29b2c44Sab196087 }
988d29b2c44Sab196087 break;
989d29b2c44Sab196087
990d29b2c44Sab196087 case EHDR_CMD_T_E_PHNUM:
991d29b2c44Sab196087 {
992d29b2c44Sab196087 /* The argument gives the number of program headers */
993d29b2c44Sab196087 Word phnum = (Word) elfedit_atoui(argstate.argv[0],
994d29b2c44Sab196087 NULL);
995d29b2c44Sab196087 const char *name = MSG_ORIG(MSG_CMD_E_PHNUM);
996d29b2c44Sab196087 elfedit_section_t *sec0 = &obj_state->os_secarr[0];
997d29b2c44Sab196087 Shdr *shdr0 = sec0->sec_shdr;
998d29b2c44Sab196087 Half e_phnum;
999d29b2c44Sab196087 Word sh_info;
1000d29b2c44Sab196087
1001d29b2c44Sab196087 if (phnum >= PN_XNUM) {
1002d29b2c44Sab196087 e_phnum = PN_XNUM;
1003d29b2c44Sab196087 sh_info = phnum;
1004d29b2c44Sab196087 } else {
1005d29b2c44Sab196087 e_phnum = phnum;
1006d29b2c44Sab196087 sh_info = 0;
1007d29b2c44Sab196087 }
1008d29b2c44Sab196087
1009d29b2c44Sab196087 if (ehdr->e_phnum == e_phnum) {
1010d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1011d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_D_OK), name,
1012d29b2c44Sab196087 EC_WORD(ehdr->e_phnum));
1013d29b2c44Sab196087 } else {
1014d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1015d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_D_CHG), name,
1016d29b2c44Sab196087 EC_WORD(ehdr->e_phnum), e_phnum);
1017d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
1018d29b2c44Sab196087 ehdr->e_phnum = e_phnum;
1019d29b2c44Sab196087 }
1020d29b2c44Sab196087 if (shdr0->sh_info == sh_info) {
1021d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1022d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_SHDR0_D_OK),
1023d29b2c44Sab196087 MSG_ORIG(MSG_STR_SH_INFO),
1024d29b2c44Sab196087 EC_WORD(shdr0->sh_info));
1025d29b2c44Sab196087 } else {
1026d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1027d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_SHDR0_D_CHG),
1028d29b2c44Sab196087 MSG_ORIG(MSG_STR_SH_INFO),
1029d29b2c44Sab196087 EC_WORD(shdr0->sh_info), sh_info);
1030d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
1031d29b2c44Sab196087 shdr0->sh_info = sh_info;
1032d29b2c44Sab196087 elfedit_modified_shdr(sec0);
1033d29b2c44Sab196087 }
1034d29b2c44Sab196087 }
1035d29b2c44Sab196087 break;
1036d29b2c44Sab196087
1037d29b2c44Sab196087 case EHDR_CMD_T_E_SHENTSIZE:
1038d29b2c44Sab196087 {
1039d29b2c44Sab196087 /*
1040d29b2c44Sab196087 * The argument gives the size of a program
1041d29b2c44Sab196087 * header element.
1042d29b2c44Sab196087 */
1043d29b2c44Sab196087 Half shentsize = (Half) elfedit_atoui(argstate.argv[0],
1044d29b2c44Sab196087 NULL);
1045d29b2c44Sab196087 const char *name = MSG_ORIG(MSG_CMD_E_SHENTSIZE);
1046d29b2c44Sab196087
1047d29b2c44Sab196087 if (ehdr->e_shentsize == shentsize) {
1048d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1049d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_D_OK), name,
1050d29b2c44Sab196087 EC_WORD(ehdr->e_shentsize));
1051d29b2c44Sab196087 } else {
1052d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1053d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_D_CHG), name,
1054d29b2c44Sab196087 EC_WORD(ehdr->e_shentsize),
1055d29b2c44Sab196087 EC_WORD(shentsize));
1056d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
1057d29b2c44Sab196087 ehdr->e_shentsize = shentsize;
1058d29b2c44Sab196087 }
1059d29b2c44Sab196087 }
1060d29b2c44Sab196087 break;
1061d29b2c44Sab196087
1062d29b2c44Sab196087 case EHDR_CMD_T_E_SHNUM:
1063d29b2c44Sab196087 {
1064d29b2c44Sab196087 /* The argument gives the number of section headers */
1065d29b2c44Sab196087 Word shnum = (Word) elfedit_atoui(argstate.argv[0],
1066d29b2c44Sab196087 NULL);
1067d29b2c44Sab196087 const char *name = MSG_ORIG(MSG_CMD_E_SHNUM);
1068d29b2c44Sab196087 elfedit_section_t *sec0 = &obj_state->os_secarr[0];
1069d29b2c44Sab196087 Shdr *shdr0 = sec0->sec_shdr;
1070d29b2c44Sab196087 Half e_shnum;
1071d29b2c44Sab196087 Word sh_size;
1072d29b2c44Sab196087
1073d29b2c44Sab196087 if (shnum >= SHN_LORESERVE) {
1074d29b2c44Sab196087 e_shnum = 0;
1075d29b2c44Sab196087 sh_size = shnum;
1076d29b2c44Sab196087 } else {
1077d29b2c44Sab196087 e_shnum = shnum;
1078d29b2c44Sab196087 sh_size = 0;
1079d29b2c44Sab196087 }
1080d29b2c44Sab196087
1081d29b2c44Sab196087 if (ehdr->e_shnum == e_shnum) {
1082d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1083d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_D_OK), name,
1084d29b2c44Sab196087 EC_WORD(ehdr->e_shnum));
1085d29b2c44Sab196087 } else {
1086d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1087d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_D_CHG), name,
1088d29b2c44Sab196087 EC_WORD(ehdr->e_shnum), e_shnum);
1089d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
1090d29b2c44Sab196087 ehdr->e_shnum = e_shnum;
1091d29b2c44Sab196087 }
1092d29b2c44Sab196087 if (shdr0->sh_size == sh_size) {
1093d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1094d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_SHDR0_D_OK),
1095d29b2c44Sab196087 MSG_ORIG(MSG_STR_SH_SIZE),
1096d29b2c44Sab196087 EC_WORD(shdr0->sh_size));
1097d29b2c44Sab196087 } else {
1098d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1099d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_SHDR0_D_CHG),
1100d29b2c44Sab196087 MSG_ORIG(MSG_STR_SH_SIZE),
1101d29b2c44Sab196087 EC_WORD(shdr0->sh_size), sh_size);
1102d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
1103d29b2c44Sab196087 shdr0->sh_size = sh_size;
1104d29b2c44Sab196087 elfedit_modified_shdr(sec0);
1105d29b2c44Sab196087 }
1106d29b2c44Sab196087 }
1107d29b2c44Sab196087 break;
1108d29b2c44Sab196087
1109d29b2c44Sab196087 case EHDR_CMD_T_E_SHSTRNDX:
1110d29b2c44Sab196087 {
1111d29b2c44Sab196087 const char *name = MSG_ORIG(MSG_CMD_E_SHSTRNDX);
1112d29b2c44Sab196087 Word shstrndx;
1113d29b2c44Sab196087 elfedit_section_t *sec0 = &obj_state->os_secarr[0];
1114d29b2c44Sab196087 Shdr *shdr0 = sec0->sec_shdr;
1115d29b2c44Sab196087 Half e_shstrndx;
1116d29b2c44Sab196087 Word sh_link;
1117d29b2c44Sab196087
1118d29b2c44Sab196087 /*
1119d29b2c44Sab196087 * By default, sec argument is name of section.
1120d29b2c44Sab196087 * If -shndx is used, it is a numeric index, and
1121d29b2c44Sab196087 * if -shtyp is used, it is a section type.
1122d29b2c44Sab196087 */
1123d29b2c44Sab196087 if (argstate.optmask & EHDR_OPT_F_SHNDX)
1124d29b2c44Sab196087 shstrndx = elfedit_atoshndx(argstate.argv[0],
1125d29b2c44Sab196087 obj_state->os_shnum);
1126d29b2c44Sab196087 else if (argstate.optmask & EHDR_OPT_F_SHTYP)
1127d29b2c44Sab196087 shstrndx = elfedit_type_to_shndx(obj_state,
1128d29b2c44Sab196087 elfedit_atoconst(argstate.argv[0],
1129d29b2c44Sab196087 ELFEDIT_CONST_SHT));
1130d29b2c44Sab196087 else
1131d29b2c44Sab196087 shstrndx = elfedit_name_to_shndx(obj_state,
1132d29b2c44Sab196087 argstate.argv[0]);
1133d29b2c44Sab196087
1134d29b2c44Sab196087 /* Warn if the section isn't a string table */
1135d29b2c44Sab196087 if ((shstrndx >= obj_state->os_shnum) ||
1136d29b2c44Sab196087 ((shstrndx >= SHN_LORESERVE) &&
1137d29b2c44Sab196087 (shstrndx <= SHN_HIRESERVE)) ||
1138d29b2c44Sab196087 (obj_state->os_secarr[shstrndx].sec_shdr->sh_type !=
1139d29b2c44Sab196087 SHT_STRTAB))
1140d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1141d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_NOTSTRTAB), name,
1142d29b2c44Sab196087 EC_WORD(shstrndx));
1143d29b2c44Sab196087
1144d29b2c44Sab196087 if (shstrndx >= SHN_LORESERVE) {
1145d29b2c44Sab196087 e_shstrndx = SHN_XINDEX;
1146d29b2c44Sab196087 sh_link = shstrndx;
1147d29b2c44Sab196087 } else {
1148d29b2c44Sab196087 e_shstrndx = shstrndx;
1149d29b2c44Sab196087 sh_link = 0;
1150d29b2c44Sab196087 }
1151d29b2c44Sab196087
1152d29b2c44Sab196087 if (ehdr->e_shstrndx == e_shstrndx) {
1153d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1154d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_D_OK), name,
1155d29b2c44Sab196087 EC_WORD(ehdr->e_shstrndx));
1156d29b2c44Sab196087 } else {
1157d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1158d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_E_D_CHG), name,
1159d29b2c44Sab196087 EC_WORD(ehdr->e_shstrndx), e_shstrndx);
1160d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
1161d29b2c44Sab196087 ehdr->e_shstrndx = e_shstrndx;
1162d29b2c44Sab196087 }
1163d29b2c44Sab196087 if (shdr0->sh_link == sh_link) {
1164d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1165d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_SHDR0_D_OK),
1166d29b2c44Sab196087 MSG_ORIG(MSG_STR_SH_LINK),
1167d29b2c44Sab196087 EC_WORD(shdr0->sh_link));
1168d29b2c44Sab196087 } else {
1169d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1170d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_SHDR0_D_CHG),
1171d29b2c44Sab196087 MSG_ORIG(MSG_STR_SH_LINK),
1172d29b2c44Sab196087 EC_WORD(shdr0->sh_link), sh_link);
1173d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
1174d29b2c44Sab196087 shdr0->sh_link = sh_link;
1175d29b2c44Sab196087 elfedit_modified_shdr(sec0);
1176d29b2c44Sab196087 }
1177d29b2c44Sab196087 }
1178d29b2c44Sab196087 break;
1179d29b2c44Sab196087
1180d29b2c44Sab196087 case EHDR_CMD_T_EI_MAG0:
1181d29b2c44Sab196087 case EHDR_CMD_T_EI_MAG1:
1182d29b2c44Sab196087 case EHDR_CMD_T_EI_MAG2:
1183d29b2c44Sab196087 case EHDR_CMD_T_EI_MAG3:
1184d29b2c44Sab196087 {
1185d29b2c44Sab196087 /*
1186d29b2c44Sab196087 * This depends on EHDR_CMD_T_EI_MAG[0-3]
1187d29b2c44Sab196087 * being contiguous
1188d29b2c44Sab196087 */
1189d29b2c44Sab196087 int ei_ndx = (cmd - EHDR_CMD_T_EI_MAG0) + EI_MAG0;
1190d29b2c44Sab196087
1191d29b2c44Sab196087 /* The argument gives the magic number byte */
1192d29b2c44Sab196087 int mag = (int)elfedit_atoui_range(argstate.argv[0],
1193d29b2c44Sab196087 MSG_ORIG(MSG_STR_VALUE), 0, 255, NULL);
1194d29b2c44Sab196087
1195d29b2c44Sab196087 if (ehdr->e_ident[ei_ndx] == mag) {
1196d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1197d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_EI_S_S_OK),
1198d29b2c44Sab196087 elfedit_atoconst_value_to_str(
1199d29b2c44Sab196087 ELFEDIT_CONST_EI, ei_ndx, 1),
1200d29b2c44Sab196087 conv_magic_value(ehdr->e_ident[ei_ndx]));
1201d29b2c44Sab196087 } else {
1202d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1203d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_EI_S_S_CHG),
1204d29b2c44Sab196087 elfedit_atoconst_value_to_str(
1205d29b2c44Sab196087 ELFEDIT_CONST_EI, ei_ndx, 1),
1206d29b2c44Sab196087 conv_magic_value(ehdr->e_ident[ei_ndx]),
1207d29b2c44Sab196087 conv_magic_value(mag));
1208d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
1209d29b2c44Sab196087 ehdr->e_ident[ei_ndx] = mag;
1210d29b2c44Sab196087 }
1211d29b2c44Sab196087 }
1212d29b2c44Sab196087 break;
1213d29b2c44Sab196087
1214d29b2c44Sab196087 case EHDR_CMD_T_EI_CLASS:
1215d29b2c44Sab196087 {
1216d29b2c44Sab196087 /* The argument gives the ELFCLASS value */
1217d29b2c44Sab196087 int class = (int)elfedit_atoconst_range(
1218d29b2c44Sab196087 argstate.argv[0], MSG_ORIG(MSG_STR_VALUE), 0, 255,
1219d29b2c44Sab196087 ELFEDIT_CONST_ELFCLASS);
1220d29b2c44Sab196087 const char *name = elfedit_atoconst_value_to_str(
1221d29b2c44Sab196087 ELFEDIT_CONST_EI, EI_CLASS, 1);
1222d29b2c44Sab196087
1223d29b2c44Sab196087 if (ehdr->e_ident[EI_CLASS] == class) {
1224d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1225d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_EI_S_S_OK), name,
1226d29b2c44Sab196087 conv_ehdr_class(class, 0, &inv_buf1));
1227d29b2c44Sab196087 } else {
1228d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1229d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_EI_S_S_CHG), name,
1230d29b2c44Sab196087 conv_ehdr_class(ehdr->e_ident[EI_CLASS],
1231d29b2c44Sab196087 0, &inv_buf1),
1232d29b2c44Sab196087 conv_ehdr_class(class, 0, &inv_buf2));
1233d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
1234d29b2c44Sab196087 ehdr->e_ident[EI_CLASS] = class;
1235d29b2c44Sab196087 }
1236d29b2c44Sab196087 }
1237d29b2c44Sab196087 break;
1238d29b2c44Sab196087
1239d29b2c44Sab196087 case EHDR_CMD_T_EI_DATA:
1240d29b2c44Sab196087 {
1241d29b2c44Sab196087 /* The argument gives the ELFDATA value */
1242d29b2c44Sab196087 int data = (int)elfedit_atoconst_range(argstate.argv[0],
1243d29b2c44Sab196087 MSG_ORIG(MSG_STR_VALUE), 0, 255,
1244d29b2c44Sab196087 ELFEDIT_CONST_ELFDATA);
1245d29b2c44Sab196087 const char *name = elfedit_atoconst_value_to_str(
1246d29b2c44Sab196087 ELFEDIT_CONST_EI, EI_DATA, 1);
1247d29b2c44Sab196087
1248d29b2c44Sab196087 if (ehdr->e_ident[EI_DATA] == data) {
1249d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1250d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_EI_S_S_OK), name,
1251d29b2c44Sab196087 conv_ehdr_data(data, 0, &inv_buf1));
1252d29b2c44Sab196087 } else {
1253d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1254d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_EI_S_S_CHG), name,
1255d29b2c44Sab196087 conv_ehdr_data(ehdr->e_ident[EI_DATA],
1256d29b2c44Sab196087 0, &inv_buf1),
1257d29b2c44Sab196087 conv_ehdr_data(data, 0, &inv_buf2));
1258d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
1259d29b2c44Sab196087 ehdr->e_ident[EI_DATA] = data;
1260d29b2c44Sab196087 }
1261d29b2c44Sab196087 }
1262d29b2c44Sab196087 break;
1263d29b2c44Sab196087
1264d29b2c44Sab196087 case EHDR_CMD_T_EI_VERSION:
1265d29b2c44Sab196087 {
1266d29b2c44Sab196087 /* The argument gives the version */
1267d29b2c44Sab196087 int ver = (int)elfedit_atoconst_range(argstate.argv[0],
1268d29b2c44Sab196087 MSG_ORIG(MSG_STR_VALUE), 0, 255, ELFEDIT_CONST_EV);
1269d29b2c44Sab196087 const char *name = elfedit_atoconst_value_to_str(
1270d29b2c44Sab196087 ELFEDIT_CONST_EI, EI_VERSION, 1);
1271d29b2c44Sab196087
1272d29b2c44Sab196087 if (ehdr->e_ident[EI_VERSION] == ver) {
1273d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1274d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_EI_S_S_OK), name,
1275d29b2c44Sab196087 conv_ehdr_vers(ver, 0, &inv_buf1));
1276d29b2c44Sab196087 } else {
1277d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1278d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_EI_S_S_CHG), name,
1279d29b2c44Sab196087 conv_ehdr_vers(ehdr->e_ident[EI_VERSION],
1280d29b2c44Sab196087 0, &inv_buf1),
1281d29b2c44Sab196087 conv_ehdr_vers(ver, 0, &inv_buf2));
1282d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
1283d29b2c44Sab196087 ehdr->e_ident[EI_VERSION] = ver;
1284d29b2c44Sab196087 }
1285d29b2c44Sab196087 }
1286d29b2c44Sab196087 break;
1287d29b2c44Sab196087
1288d29b2c44Sab196087 case EHDR_CMD_T_EI_OSABI:
1289d29b2c44Sab196087 {
1290d29b2c44Sab196087 /* The argument gives the ABI code */
1291d29b2c44Sab196087 int osabi = (int)elfedit_atoconst_range(
1292d29b2c44Sab196087 argstate.argv[0], MSG_ORIG(MSG_STR_VALUE), 0, 255,
1293d29b2c44Sab196087 ELFEDIT_CONST_ELFOSABI);
1294d29b2c44Sab196087 const char *name = elfedit_atoconst_value_to_str(
1295d29b2c44Sab196087 ELFEDIT_CONST_EI, EI_OSABI, 1);
1296d29b2c44Sab196087
1297d29b2c44Sab196087 if (ehdr->e_ident[EI_OSABI] == osabi) {
1298d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1299d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_EI_S_S_OK), name,
1300d29b2c44Sab196087 conv_ehdr_osabi(osabi, 0, &inv_buf1));
1301d29b2c44Sab196087 } else {
1302d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1303d29b2c44Sab196087 MSG_INTL(MSG_DEBUG_EI_S_S_CHG), name,
1304d29b2c44Sab196087 conv_ehdr_osabi(ehdr->e_ident[EI_OSABI],
1305d29b2c44Sab196087 0, &inv_buf1),
1306d29b2c44Sab196087 conv_ehdr_osabi(osabi, 0, &inv_buf2));
1307*4f680cc6SAli Bahrami ret = ELFEDIT_CMDRET_MOD_OS_MACH;
1308d29b2c44Sab196087 ehdr->e_ident[EI_OSABI] = osabi;
1309d29b2c44Sab196087 }
1310d29b2c44Sab196087 }
1311d29b2c44Sab196087 break;
1312d29b2c44Sab196087
1313d29b2c44Sab196087 case EHDR_CMD_T_EI_ABIVERSION:
1314d29b2c44Sab196087 {
1315d29b2c44Sab196087 /* The argument gives the ABI version */
1316*4f680cc6SAli Bahrami int abiver = (int)elfedit_atoconst_range(
1317*4f680cc6SAli Bahrami argstate.argv[0], MSG_ORIG(MSG_STR_VALUE), 0, 255,
1318*4f680cc6SAli Bahrami ELFEDIT_CONST_EAV);
1319d29b2c44Sab196087 const char *name = elfedit_atoconst_value_to_str(
1320d29b2c44Sab196087 ELFEDIT_CONST_EI, EI_ABIVERSION, 1);
1321d29b2c44Sab196087
1322d29b2c44Sab196087 if (ehdr->e_ident[EI_ABIVERSION] == abiver) {
1323d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1324*4f680cc6SAli Bahrami MSG_INTL(MSG_DEBUG_EI_S_S_OK), name,
1325*4f680cc6SAli Bahrami conv_ehdr_abivers(ehdr->e_ident[EI_OSABI],
1326*4f680cc6SAli Bahrami abiver, CONV_FMT_DECIMAL, &inv_buf1));
1327d29b2c44Sab196087 } else {
1328d29b2c44Sab196087 elfedit_msg(ELFEDIT_MSG_DEBUG,
1329*4f680cc6SAli Bahrami MSG_INTL(MSG_DEBUG_EI_S_S_CHG), name,
1330*4f680cc6SAli Bahrami conv_ehdr_abivers(ehdr->e_ident[EI_OSABI],
1331*4f680cc6SAli Bahrami ehdr->e_ident[EI_ABIVERSION],
1332*4f680cc6SAli Bahrami CONV_FMT_DECIMAL, &inv_buf1),
1333*4f680cc6SAli Bahrami conv_ehdr_abivers(ehdr->e_ident[EI_OSABI],
1334*4f680cc6SAli Bahrami abiver, CONV_FMT_DECIMAL, &inv_buf2));
1335d29b2c44Sab196087 ret = ELFEDIT_CMDRET_MOD;
1336d29b2c44Sab196087 ehdr->e_ident[EI_ABIVERSION] = abiver;
1337d29b2c44Sab196087 }
1338d29b2c44Sab196087 }
1339d29b2c44Sab196087 break;
1340d29b2c44Sab196087 }
1341d29b2c44Sab196087
1342d29b2c44Sab196087 /*
1343d29b2c44Sab196087 * If we modified the ELF header, tell libelf.
1344d29b2c44Sab196087 */
1345d29b2c44Sab196087 if (ret == ELFEDIT_CMDRET_MOD)
1346d29b2c44Sab196087 elfedit_modified_ehdr(obj_state);
1347d29b2c44Sab196087
1348d29b2c44Sab196087 /* Do autoprint */
1349d29b2c44Sab196087 print_ehdr(cmd, e_ident_ndx, 1, &argstate);
1350d29b2c44Sab196087
1351d29b2c44Sab196087 return (ret);
1352d29b2c44Sab196087 }
1353d29b2c44Sab196087
1354d29b2c44Sab196087
1355d29b2c44Sab196087
1356d29b2c44Sab196087
1357d29b2c44Sab196087 /*
1358d29b2c44Sab196087 * Command completion functions for the various commands
1359d29b2c44Sab196087 */
1360d29b2c44Sab196087
1361d29b2c44Sab196087 /*ARGSUSED*/
1362d29b2c44Sab196087 static void
cpl_e_ident(elfedit_obj_state_t * obj_state,void * cpldata,int argc,const char * argv[],int num_opt)1363d29b2c44Sab196087 cpl_e_ident(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
1364d29b2c44Sab196087 const char *argv[], int num_opt)
1365d29b2c44Sab196087 {
1366d29b2c44Sab196087 elfedit_atoui_t ndx;
1367d29b2c44Sab196087
1368d29b2c44Sab196087 /*
1369d29b2c44Sab196087 * This command doesn't accept options, so num_opt should be
1370d29b2c44Sab196087 * 0. This is a defensive measure, in case that should change.
1371d29b2c44Sab196087 */
1372d29b2c44Sab196087 argc -= num_opt;
1373d29b2c44Sab196087 argv += num_opt;
1374d29b2c44Sab196087
1375d29b2c44Sab196087 if (argc == 1) {
1376d29b2c44Sab196087 elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_EI);
1377d29b2c44Sab196087 return;
1378d29b2c44Sab196087 }
1379d29b2c44Sab196087
1380d29b2c44Sab196087 if (argc != 2)
1381d29b2c44Sab196087 return;
1382d29b2c44Sab196087
1383d29b2c44Sab196087 /*
1384d29b2c44Sab196087 * In order to offer up the right completion strings for
1385d29b2c44Sab196087 * the value, we need to know what index was given for
1386d29b2c44Sab196087 * the first argument. If we don't recognize the index,
1387d29b2c44Sab196087 * we want to return quietly without issuing an error,
1388d29b2c44Sab196087 * so we use elfedit_atoui_range2(), which returns
1389d29b2c44Sab196087 * a success/failure result and does not throw any errors.
1390d29b2c44Sab196087 */
1391d29b2c44Sab196087 if (elfedit_atoconst_range2(argv[0], 0, EI_NIDENT - 1,
1392d29b2c44Sab196087 ELFEDIT_CONST_EI, &ndx) == 0)
1393d29b2c44Sab196087 return;
1394d29b2c44Sab196087 switch (ndx) {
1395d29b2c44Sab196087 case EI_CLASS:
1396d29b2c44Sab196087 elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_ELFCLASS);
1397d29b2c44Sab196087 break;
1398d29b2c44Sab196087 case EI_DATA:
1399d29b2c44Sab196087 elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_ELFDATA);
1400d29b2c44Sab196087 break;
1401d29b2c44Sab196087 case EI_VERSION:
1402d29b2c44Sab196087 elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_EV);
1403d29b2c44Sab196087 break;
1404d29b2c44Sab196087 case EI_OSABI:
1405d29b2c44Sab196087 elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_ELFOSABI);
1406d29b2c44Sab196087 break;
1407d29b2c44Sab196087 }
1408d29b2c44Sab196087 }
1409d29b2c44Sab196087
1410d29b2c44Sab196087 /*ARGSUSED*/
1411d29b2c44Sab196087 static void
cpl_e_type(elfedit_obj_state_t * obj_state,void * cpldata,int argc,const char * argv[],int num_opt)1412d29b2c44Sab196087 cpl_e_type(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
1413d29b2c44Sab196087 const char *argv[], int num_opt)
1414d29b2c44Sab196087 {
1415d29b2c44Sab196087 /*
1416d29b2c44Sab196087 * This command doesn't accept options, so num_opt should be
1417d29b2c44Sab196087 * 0. This is a defensive measure, in case that should change.
1418d29b2c44Sab196087 */
1419d29b2c44Sab196087 argc -= num_opt;
1420d29b2c44Sab196087 argv += num_opt;
1421d29b2c44Sab196087
1422d29b2c44Sab196087 if (argc == 1)
1423d29b2c44Sab196087 elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_ET);
1424d29b2c44Sab196087 }
1425d29b2c44Sab196087
1426d29b2c44Sab196087 /*ARGSUSED*/
1427d29b2c44Sab196087 static void
cpl_e_machine(elfedit_obj_state_t * obj_state,void * cpldata,int argc,const char * argv[],int num_opt)1428d29b2c44Sab196087 cpl_e_machine(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
1429d29b2c44Sab196087 const char *argv[], int num_opt)
1430d29b2c44Sab196087 {
1431d29b2c44Sab196087 /*
1432d29b2c44Sab196087 * This command doesn't accept options, so num_opt should be
1433d29b2c44Sab196087 * 0. This is a defensive measure, in case that should change.
1434d29b2c44Sab196087 */
1435d29b2c44Sab196087 argc -= num_opt;
1436d29b2c44Sab196087 argv += num_opt;
1437d29b2c44Sab196087
1438d29b2c44Sab196087 if (argc == 1)
1439d29b2c44Sab196087 elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_EM);
1440d29b2c44Sab196087 }
1441d29b2c44Sab196087
1442d29b2c44Sab196087 /*ARGSUSED*/
1443d29b2c44Sab196087 static void
cpl_e_version(elfedit_obj_state_t * obj_state,void * cpldata,int argc,const char * argv[],int num_opt)1444d29b2c44Sab196087 cpl_e_version(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
1445d29b2c44Sab196087 const char *argv[], int num_opt)
1446d29b2c44Sab196087 {
1447d29b2c44Sab196087 /*
1448d29b2c44Sab196087 * This command doesn't accept options, so num_opt should be
1449d29b2c44Sab196087 * 0. This is a defensive measure, in case that should change.
1450d29b2c44Sab196087 */
1451d29b2c44Sab196087 argc -= num_opt;
1452d29b2c44Sab196087 argv += num_opt;
1453d29b2c44Sab196087
1454d29b2c44Sab196087 if (argc == 1)
1455d29b2c44Sab196087 elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_EV);
1456d29b2c44Sab196087 }
1457d29b2c44Sab196087
1458d29b2c44Sab196087 /*ARGSUSED*/
1459d29b2c44Sab196087 static void
cpl_e_flags(elfedit_obj_state_t * obj_state,void * cpldata,int argc,const char * argv[],int num_opt)1460d29b2c44Sab196087 cpl_e_flags(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
1461d29b2c44Sab196087 const char *argv[], int num_opt)
1462d29b2c44Sab196087 {
1463d29b2c44Sab196087 /* This routine allows multiple flags to be specified */
1464d29b2c44Sab196087 elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_EF);
1465d29b2c44Sab196087 }
1466d29b2c44Sab196087
1467d29b2c44Sab196087 /*ARGSUSED*/
1468d29b2c44Sab196087 static void
cpl_e_shstrndx(elfedit_obj_state_t * obj_state,void * cpldata,int argc,const char * argv[],int num_opt)1469d29b2c44Sab196087 cpl_e_shstrndx(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
1470d29b2c44Sab196087 const char *argv[], int num_opt)
1471d29b2c44Sab196087 {
1472d29b2c44Sab196087 enum { NAME, INDEX, TYPE } op;
1473d29b2c44Sab196087 Word ndx;
1474d29b2c44Sab196087
1475d29b2c44Sab196087 /*
1476d29b2c44Sab196087 * The plainargument can be a section name, index, or
1477d29b2c44Sab196087 * type, based on the options used. All have completions.
1478d29b2c44Sab196087 */
1479d29b2c44Sab196087 if (argc != (num_opt + 1))
1480d29b2c44Sab196087 return;
1481d29b2c44Sab196087
1482d29b2c44Sab196087 op = NAME;
1483d29b2c44Sab196087 for (ndx = 0; ndx < num_opt; ndx++) {
1484d29b2c44Sab196087 if (strcmp(argv[ndx], MSG_ORIG(MSG_STR_MINUS_SHNDX)) == 0)
1485d29b2c44Sab196087 op = INDEX;
1486d29b2c44Sab196087 else if (strcmp(argv[ndx], MSG_ORIG(MSG_STR_MINUS_SHTYP)) == 0)
1487d29b2c44Sab196087 op = TYPE;
1488d29b2c44Sab196087 }
1489d29b2c44Sab196087
1490d29b2c44Sab196087 if (obj_state == NULL) { /* No object available */
1491d29b2c44Sab196087 if (op == TYPE)
1492d29b2c44Sab196087 elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_SHT);
1493d29b2c44Sab196087 return;
1494d29b2c44Sab196087 }
1495d29b2c44Sab196087
1496d29b2c44Sab196087 /*
1497d29b2c44Sab196087 * Loop over the sections and supply command completion
1498d29b2c44Sab196087 * for the string tables in the file.
1499d29b2c44Sab196087 */
1500d29b2c44Sab196087 for (ndx = 0; ndx < obj_state->os_shnum; ndx++) {
1501d29b2c44Sab196087 elfedit_section_t *sec = &obj_state->os_secarr[ndx];
1502d29b2c44Sab196087
1503d29b2c44Sab196087 if (sec->sec_shdr->sh_type != SHT_STRTAB)
1504d29b2c44Sab196087 continue;
1505d29b2c44Sab196087
1506d29b2c44Sab196087 switch (op) {
1507d29b2c44Sab196087 case NAME:
1508d29b2c44Sab196087 elfedit_cpl_match(cpldata, sec->sec_name, 0);
1509d29b2c44Sab196087 break;
1510d29b2c44Sab196087 case INDEX:
151155ef6355Sab196087 elfedit_cpl_ndx(cpldata, ndx);
1512d29b2c44Sab196087 break;
1513d29b2c44Sab196087 case TYPE:
1514d29b2c44Sab196087 elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_SHT_STRTAB);
1515d29b2c44Sab196087 break;
1516d29b2c44Sab196087 }
1517d29b2c44Sab196087 }
1518d29b2c44Sab196087 }
1519d29b2c44Sab196087
1520d29b2c44Sab196087 /*ARGSUSED*/
1521d29b2c44Sab196087 static void
cpl_ei_class(elfedit_obj_state_t * obj_state,void * cpldata,int argc,const char * argv[],int num_opt)1522d29b2c44Sab196087 cpl_ei_class(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
1523d29b2c44Sab196087 const char *argv[], int num_opt)
1524d29b2c44Sab196087 {
1525d29b2c44Sab196087 /*
1526d29b2c44Sab196087 * This command doesn't accept options, so num_opt should be
1527d29b2c44Sab196087 * 0. This is a defensive measure, in case that should change.
1528d29b2c44Sab196087 */
1529d29b2c44Sab196087 argc -= num_opt;
1530d29b2c44Sab196087 argv += num_opt;
1531d29b2c44Sab196087
1532d29b2c44Sab196087 if (argc == 1)
1533d29b2c44Sab196087 elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_ELFCLASS);
1534d29b2c44Sab196087 }
1535d29b2c44Sab196087
1536d29b2c44Sab196087 /*ARGSUSED*/
1537d29b2c44Sab196087 static void
cpl_ei_data(elfedit_obj_state_t * obj_state,void * cpldata,int argc,const char * argv[],int num_opt)1538d29b2c44Sab196087 cpl_ei_data(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
1539d29b2c44Sab196087 const char *argv[], int num_opt)
1540d29b2c44Sab196087 {
1541d29b2c44Sab196087 /*
1542d29b2c44Sab196087 * This command doesn't accept options, so num_opt should be
1543d29b2c44Sab196087 * 0. This is a defensive measure, in case that should change.
1544d29b2c44Sab196087 */
1545d29b2c44Sab196087 argc -= num_opt;
1546d29b2c44Sab196087 argv += num_opt;
1547d29b2c44Sab196087
1548d29b2c44Sab196087 if (argc == 1)
1549d29b2c44Sab196087 elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_ELFDATA);
1550d29b2c44Sab196087 }
1551d29b2c44Sab196087
1552d29b2c44Sab196087 /*ARGSUSED*/
1553d29b2c44Sab196087 static void
cpl_ei_osabi(elfedit_obj_state_t * obj_state,void * cpldata,int argc,const char * argv[],int num_opt)1554d29b2c44Sab196087 cpl_ei_osabi(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
1555d29b2c44Sab196087 const char *argv[], int num_opt)
1556d29b2c44Sab196087 {
1557d29b2c44Sab196087 /*
1558d29b2c44Sab196087 * This command doesn't accept options, so num_opt should be
1559d29b2c44Sab196087 * 0. This is a defensive measure, in case that should change.
1560d29b2c44Sab196087 */
1561d29b2c44Sab196087 argc -= num_opt;
1562d29b2c44Sab196087 argv += num_opt;
1563d29b2c44Sab196087
1564d29b2c44Sab196087 if (argc == 1)
1565d29b2c44Sab196087 elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_ELFOSABI);
1566d29b2c44Sab196087 }
1567d29b2c44Sab196087
1568*4f680cc6SAli Bahrami /*ARGSUSED*/
1569*4f680cc6SAli Bahrami static void
cpl_ei_abiversion(elfedit_obj_state_t * obj_state,void * cpldata,int argc,const char * argv[],int num_opt)1570*4f680cc6SAli Bahrami cpl_ei_abiversion(elfedit_obj_state_t *obj_state, void *cpldata, int argc,
1571*4f680cc6SAli Bahrami const char *argv[], int num_opt)
1572*4f680cc6SAli Bahrami {
1573*4f680cc6SAli Bahrami /*
1574*4f680cc6SAli Bahrami * This command doesn't accept options, so num_opt should be
1575*4f680cc6SAli Bahrami * 0. This is a defensive measure, in case that should change.
1576*4f680cc6SAli Bahrami */
1577*4f680cc6SAli Bahrami argc -= num_opt;
1578*4f680cc6SAli Bahrami argv += num_opt;
1579*4f680cc6SAli Bahrami
1580*4f680cc6SAli Bahrami if (argc == 1)
1581*4f680cc6SAli Bahrami elfedit_cpl_atoconst(cpldata, ELFEDIT_CONST_EAV);
1582*4f680cc6SAli Bahrami }
1583*4f680cc6SAli Bahrami
1584d29b2c44Sab196087
1585d29b2c44Sab196087
1586d29b2c44Sab196087
1587d29b2c44Sab196087 /*
1588d29b2c44Sab196087 * Implementation functions for the commands
1589d29b2c44Sab196087 */
1590d29b2c44Sab196087 static elfedit_cmdret_t
cmd_dump(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1591d29b2c44Sab196087 cmd_dump(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1592d29b2c44Sab196087 {
1593d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_DUMP, obj_state, argc, argv));
1594d29b2c44Sab196087 }
1595d29b2c44Sab196087
1596d29b2c44Sab196087
1597d29b2c44Sab196087 static elfedit_cmdret_t
cmd_e_ident(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1598d29b2c44Sab196087 cmd_e_ident(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1599d29b2c44Sab196087 {
1600d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_E_IDENT, obj_state, argc, argv));
1601d29b2c44Sab196087 }
1602d29b2c44Sab196087
1603d29b2c44Sab196087
1604d29b2c44Sab196087 static elfedit_cmdret_t
cmd_e_type(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1605d29b2c44Sab196087 cmd_e_type(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1606d29b2c44Sab196087 {
1607d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_E_TYPE, obj_state, argc, argv));
1608d29b2c44Sab196087 }
1609d29b2c44Sab196087
1610d29b2c44Sab196087
1611d29b2c44Sab196087 static elfedit_cmdret_t
cmd_e_machine(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1612d29b2c44Sab196087 cmd_e_machine(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1613d29b2c44Sab196087 {
1614d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_E_MACHINE, obj_state, argc, argv));
1615d29b2c44Sab196087 }
1616d29b2c44Sab196087
1617d29b2c44Sab196087
1618d29b2c44Sab196087 static elfedit_cmdret_t
cmd_e_version(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1619d29b2c44Sab196087 cmd_e_version(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1620d29b2c44Sab196087 {
1621d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_E_VERSION, obj_state, argc, argv));
1622d29b2c44Sab196087 }
1623d29b2c44Sab196087
1624d29b2c44Sab196087
1625d29b2c44Sab196087 static elfedit_cmdret_t
cmd_e_entry(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1626d29b2c44Sab196087 cmd_e_entry(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1627d29b2c44Sab196087 {
1628d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_E_ENTRY, obj_state, argc, argv));
1629d29b2c44Sab196087 }
1630d29b2c44Sab196087
1631d29b2c44Sab196087
1632d29b2c44Sab196087 static elfedit_cmdret_t
cmd_e_phoff(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1633d29b2c44Sab196087 cmd_e_phoff(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1634d29b2c44Sab196087 {
1635d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_E_PHOFF, obj_state, argc, argv));
1636d29b2c44Sab196087 }
1637d29b2c44Sab196087
1638d29b2c44Sab196087
1639d29b2c44Sab196087 static elfedit_cmdret_t
cmd_e_shoff(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1640d29b2c44Sab196087 cmd_e_shoff(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1641d29b2c44Sab196087 {
1642d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_E_SHOFF, obj_state, argc, argv));
1643d29b2c44Sab196087 }
1644d29b2c44Sab196087
1645d29b2c44Sab196087
1646d29b2c44Sab196087 static elfedit_cmdret_t
cmd_e_flags(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1647d29b2c44Sab196087 cmd_e_flags(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1648d29b2c44Sab196087 {
1649d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_E_FLAGS, obj_state, argc, argv));
1650d29b2c44Sab196087 }
1651d29b2c44Sab196087
1652d29b2c44Sab196087
1653d29b2c44Sab196087 static elfedit_cmdret_t
cmd_e_ehsize(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1654d29b2c44Sab196087 cmd_e_ehsize(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1655d29b2c44Sab196087 {
1656d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_E_EHSIZE, obj_state, argc, argv));
1657d29b2c44Sab196087 }
1658d29b2c44Sab196087
1659d29b2c44Sab196087
1660d29b2c44Sab196087 static elfedit_cmdret_t
cmd_e_phentsize(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1661d29b2c44Sab196087 cmd_e_phentsize(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1662d29b2c44Sab196087 {
1663d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_E_PHENTSIZE, obj_state, argc, argv));
1664d29b2c44Sab196087 }
1665d29b2c44Sab196087
1666d29b2c44Sab196087
1667d29b2c44Sab196087 static elfedit_cmdret_t
cmd_e_phnum(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1668d29b2c44Sab196087 cmd_e_phnum(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1669d29b2c44Sab196087 {
1670d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_E_PHNUM, obj_state, argc, argv));
1671d29b2c44Sab196087 }
1672d29b2c44Sab196087
1673d29b2c44Sab196087
1674d29b2c44Sab196087 static elfedit_cmdret_t
cmd_e_shentsize(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1675d29b2c44Sab196087 cmd_e_shentsize(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1676d29b2c44Sab196087 {
1677d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_E_SHENTSIZE, obj_state, argc, argv));
1678d29b2c44Sab196087 }
1679d29b2c44Sab196087
1680d29b2c44Sab196087
1681d29b2c44Sab196087 static elfedit_cmdret_t
cmd_e_shnum(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1682d29b2c44Sab196087 cmd_e_shnum(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1683d29b2c44Sab196087 {
1684d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_E_SHNUM, obj_state, argc, argv));
1685d29b2c44Sab196087 }
1686d29b2c44Sab196087
1687d29b2c44Sab196087
1688d29b2c44Sab196087 static elfedit_cmdret_t
cmd_e_shstrndx(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1689d29b2c44Sab196087 cmd_e_shstrndx(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1690d29b2c44Sab196087 {
1691d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_E_SHSTRNDX, obj_state, argc, argv));
1692d29b2c44Sab196087 }
1693d29b2c44Sab196087
1694d29b2c44Sab196087
1695d29b2c44Sab196087 static elfedit_cmdret_t
cmd_ei_mag0(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1696d29b2c44Sab196087 cmd_ei_mag0(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1697d29b2c44Sab196087 {
1698d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_EI_MAG0, obj_state, argc, argv));
1699d29b2c44Sab196087 }
1700d29b2c44Sab196087
1701d29b2c44Sab196087
1702d29b2c44Sab196087 static elfedit_cmdret_t
cmd_ei_mag1(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1703d29b2c44Sab196087 cmd_ei_mag1(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1704d29b2c44Sab196087 {
1705d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_EI_MAG1, obj_state, argc, argv));
1706d29b2c44Sab196087 }
1707d29b2c44Sab196087
1708d29b2c44Sab196087
1709d29b2c44Sab196087 static elfedit_cmdret_t
cmd_ei_mag2(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1710d29b2c44Sab196087 cmd_ei_mag2(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1711d29b2c44Sab196087 {
1712d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_EI_MAG2, obj_state, argc, argv));
1713d29b2c44Sab196087 }
1714d29b2c44Sab196087
1715d29b2c44Sab196087
1716d29b2c44Sab196087 static elfedit_cmdret_t
cmd_ei_mag3(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1717d29b2c44Sab196087 cmd_ei_mag3(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1718d29b2c44Sab196087 {
1719d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_EI_MAG3, obj_state, argc, argv));
1720d29b2c44Sab196087 }
1721d29b2c44Sab196087
1722d29b2c44Sab196087
1723d29b2c44Sab196087 static elfedit_cmdret_t
cmd_ei_class(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1724d29b2c44Sab196087 cmd_ei_class(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1725d29b2c44Sab196087 {
1726d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_EI_CLASS, obj_state, argc, argv));
1727d29b2c44Sab196087 }
1728d29b2c44Sab196087
1729d29b2c44Sab196087
1730d29b2c44Sab196087 static elfedit_cmdret_t
cmd_ei_data(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1731d29b2c44Sab196087 cmd_ei_data(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1732d29b2c44Sab196087 {
1733d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_EI_DATA, obj_state, argc, argv));
1734d29b2c44Sab196087 }
1735d29b2c44Sab196087
1736d29b2c44Sab196087
1737d29b2c44Sab196087 static elfedit_cmdret_t
cmd_ei_version(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1738d29b2c44Sab196087 cmd_ei_version(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1739d29b2c44Sab196087 {
1740d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_EI_VERSION, obj_state, argc, argv));
1741d29b2c44Sab196087 }
1742d29b2c44Sab196087
1743d29b2c44Sab196087
1744d29b2c44Sab196087 static elfedit_cmdret_t
cmd_ei_osabi(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1745d29b2c44Sab196087 cmd_ei_osabi(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1746d29b2c44Sab196087 {
1747d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_EI_OSABI, obj_state, argc, argv));
1748d29b2c44Sab196087 }
1749d29b2c44Sab196087
1750d29b2c44Sab196087
1751d29b2c44Sab196087 static elfedit_cmdret_t
cmd_ei_abiversion(elfedit_obj_state_t * obj_state,int argc,const char * argv[])1752d29b2c44Sab196087 cmd_ei_abiversion(elfedit_obj_state_t *obj_state, int argc, const char *argv[])
1753d29b2c44Sab196087 {
1754d29b2c44Sab196087 return (cmd_body(EHDR_CMD_T_EI_ABIVERSION, obj_state, argc, argv));
1755d29b2c44Sab196087 }
1756d29b2c44Sab196087
1757d29b2c44Sab196087
1758d29b2c44Sab196087
1759d29b2c44Sab196087
1760d29b2c44Sab196087 /*ARGSUSED*/
1761d29b2c44Sab196087 elfedit_module_t *
elfedit_init(elfedit_module_version_t version)1762d29b2c44Sab196087 elfedit_init(elfedit_module_version_t version)
1763d29b2c44Sab196087 {
1764d29b2c44Sab196087 /* Many of the commands only accept -o */
1765d29b2c44Sab196087 static elfedit_cmd_optarg_t opt_std[] = {
1766d29b2c44Sab196087 { ELFEDIT_STDOA_OPT_O, NULL,
1767d29b2c44Sab196087 ELFEDIT_CMDOA_F_INHERIT, 0, 0 },
1768d29b2c44Sab196087 { NULL }
1769d29b2c44Sab196087 };
1770d29b2c44Sab196087
1771d29b2c44Sab196087
1772d29b2c44Sab196087 /* ehdr:dump */
1773d29b2c44Sab196087 static const char *name_dump[] = {
1774d29b2c44Sab196087 MSG_ORIG(MSG_CMD_DUMP),
1775d29b2c44Sab196087 MSG_ORIG(MSG_STR_EMPTY), /* "" makes this the default command */
1776d29b2c44Sab196087 NULL
1777d29b2c44Sab196087 };
1778d29b2c44Sab196087
1779d29b2c44Sab196087 /* ehdr:e_ident */
1780d29b2c44Sab196087 static const char *name_e_ident[] = {
1781d29b2c44Sab196087 MSG_ORIG(MSG_CMD_E_IDENT), NULL };
1782d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_e_ident[] = {
1783d29b2c44Sab196087 { MSG_ORIG(MSG_STR_INDEX),
1784d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_IDENT_NDX) */
1785d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_IDENT_NDX),
1786d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1787d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
1788d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_IDENT_VALUE) */
1789d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_IDENT_VALUE),
1790d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1791d29b2c44Sab196087 { NULL }
1792d29b2c44Sab196087 };
1793d29b2c44Sab196087
1794d29b2c44Sab196087 /* ehdr:e_type */
1795d29b2c44Sab196087 static const char *name_e_type[] = {
1796d29b2c44Sab196087 MSG_ORIG(MSG_CMD_E_TYPE), NULL };
1797d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_e_type[] = {
1798d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
1799d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_TYPE_VALUE) */
1800d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_TYPE_VALUE),
1801d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1802d29b2c44Sab196087 { NULL }
1803d29b2c44Sab196087 };
1804d29b2c44Sab196087
1805d29b2c44Sab196087 /* ehdr:e_machine */
1806d29b2c44Sab196087 static const char *name_e_machine[] = {
1807d29b2c44Sab196087 MSG_ORIG(MSG_CMD_E_MACHINE), NULL };
1808d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_e_machine[] = {
1809d29b2c44Sab196087 { MSG_ORIG(MSG_STR_TYPE),
1810d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_MACHINE_VALUE) */
1811d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_MACHINE_VALUE),
1812d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1813d29b2c44Sab196087 { NULL }
1814d29b2c44Sab196087 };
1815d29b2c44Sab196087
1816d29b2c44Sab196087 /* ehdr:e_version */
1817d29b2c44Sab196087 static const char *name_e_version[] = {
1818d29b2c44Sab196087 MSG_ORIG(MSG_CMD_E_VERSION), NULL };
1819d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_e_version[] = {
1820d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VERSION),
1821d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_VERSION_VALUE) */
1822d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_VERSION_VALUE),
1823d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1824d29b2c44Sab196087 { NULL }
1825d29b2c44Sab196087 };
1826d29b2c44Sab196087
1827d29b2c44Sab196087 /* ehdr:e_entry */
1828d29b2c44Sab196087 static const char *name_e_entry[] = {
1829d29b2c44Sab196087 MSG_ORIG(MSG_CMD_E_ENTRY), NULL };
1830d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_e_entry[] = {
1831d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
1832d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_ENTRY_VALUE) */
1833d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_ENTRY_VALUE),
1834d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1835d29b2c44Sab196087 { NULL }
1836d29b2c44Sab196087 };
1837d29b2c44Sab196087
1838d29b2c44Sab196087 /* ehdr:e_phoff */
1839d29b2c44Sab196087 static const char *name_e_phoff[] = {
1840d29b2c44Sab196087 MSG_ORIG(MSG_CMD_E_PHOFF), NULL };
1841d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_e_phoff[] = {
1842d29b2c44Sab196087 { MSG_ORIG(MSG_STR_OFFSET),
1843d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_PHOFF_VALUE) */
1844d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_PHOFF_VALUE),
1845d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1846d29b2c44Sab196087 { NULL }
1847d29b2c44Sab196087 };
1848d29b2c44Sab196087
1849d29b2c44Sab196087 /* ehdr:e_shoff */
1850d29b2c44Sab196087 static const char *name_e_shoff[] = {
1851d29b2c44Sab196087 MSG_ORIG(MSG_CMD_E_SHOFF), NULL };
1852d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_e_shoff[] = {
1853d29b2c44Sab196087 { MSG_ORIG(MSG_STR_OFFSET),
1854d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_SHOFF_VALUE) */
1855d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_SHOFF_VALUE),
1856d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1857d29b2c44Sab196087 { NULL }
1858d29b2c44Sab196087 };
1859d29b2c44Sab196087
1860d29b2c44Sab196087 /* ehdr:e_flags */
1861d29b2c44Sab196087 static const char *name_e_flags[] = {
1862d29b2c44Sab196087 MSG_ORIG(MSG_CMD_E_FLAGS), NULL };
1863d29b2c44Sab196087 static elfedit_cmd_optarg_t opt_e_flags[] = {
1864d29b2c44Sab196087 { ELFEDIT_STDOA_OPT_AND, NULL,
1865d29b2c44Sab196087 ELFEDIT_CMDOA_F_INHERIT, EHDR_OPT_F_AND, EHDR_OPT_F_OR },
1866d29b2c44Sab196087 { ELFEDIT_STDOA_OPT_CMP, NULL,
1867d29b2c44Sab196087 ELFEDIT_CMDOA_F_INHERIT, EHDR_OPT_F_CMP, 0 },
1868d29b2c44Sab196087 { ELFEDIT_STDOA_OPT_O, NULL,
1869d29b2c44Sab196087 ELFEDIT_CMDOA_F_INHERIT, 0, 0 },
1870d29b2c44Sab196087 { ELFEDIT_STDOA_OPT_OR, NULL,
1871d29b2c44Sab196087 ELFEDIT_CMDOA_F_INHERIT, EHDR_OPT_F_OR, EHDR_OPT_F_AND },
1872d29b2c44Sab196087 { NULL }
1873d29b2c44Sab196087 };
1874d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_e_flags[] = {
1875d29b2c44Sab196087 { MSG_ORIG(MSG_STR_FLAGVALUE),
1876d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_FLAGS_VALUE) */
1877d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_FLAGS_VALUE),
1878d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT | ELFEDIT_CMDOA_F_MULT, 0 },
1879d29b2c44Sab196087 { NULL }
1880d29b2c44Sab196087 };
1881d29b2c44Sab196087
1882d29b2c44Sab196087 /* ehdr:e_ehsize */
1883d29b2c44Sab196087 static const char *name_e_ehsize[] = {
1884d29b2c44Sab196087 MSG_ORIG(MSG_CMD_E_EHSIZE), NULL };
1885d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_e_ehsize[] = {
1886d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
1887d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_EHSIZE_VALUE) */
1888d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_EHSIZE_VALUE),
1889d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1890d29b2c44Sab196087 { NULL }
1891d29b2c44Sab196087 };
1892d29b2c44Sab196087
1893d29b2c44Sab196087 /* ehdr:e_phentsize */
1894d29b2c44Sab196087 static const char *name_e_phentsize[] = {
1895d29b2c44Sab196087 MSG_ORIG(MSG_CMD_E_PHENTSIZE), NULL };
1896d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_e_phentsize[] = {
1897d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
1898d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_PHENTSIZE_VALUE) */
1899d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_PHENTSIZE_VALUE),
1900d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1901d29b2c44Sab196087 { NULL }
1902d29b2c44Sab196087 };
1903d29b2c44Sab196087
1904d29b2c44Sab196087 /* ehdr:e_phnum */
1905d29b2c44Sab196087 static const char *name_e_phnum[] = {
1906d29b2c44Sab196087 MSG_ORIG(MSG_CMD_E_PHNUM), NULL };
1907d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_e_phnum[] = {
1908d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
1909d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_PHNUM_VALUE) */
1910d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_PHNUM_VALUE),
1911d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1912d29b2c44Sab196087 { NULL }
1913d29b2c44Sab196087 };
1914d29b2c44Sab196087
1915d29b2c44Sab196087 /* ehdr:e_shentsize */
1916d29b2c44Sab196087 static const char *name_e_shentsize[] = {
1917d29b2c44Sab196087 MSG_ORIG(MSG_CMD_E_SHENTSIZE), NULL };
1918d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_e_shentsize[] = {
1919d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
1920d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_SHENTSIZE_VALUE) */
1921d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_SHENTSIZE_VALUE),
1922d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1923d29b2c44Sab196087 { NULL }
1924d29b2c44Sab196087 };
1925d29b2c44Sab196087
1926d29b2c44Sab196087 /* ehdr:e_shnum */
1927d29b2c44Sab196087 static const char *name_e_shnum[] = {
1928d29b2c44Sab196087 MSG_ORIG(MSG_CMD_E_SHNUM), NULL };
1929d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_e_shnum[] = {
1930d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
1931d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_SHNUM_VALUE) */
1932d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_SHNUM_VALUE),
1933d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1934d29b2c44Sab196087 { NULL }
1935d29b2c44Sab196087 };
1936d29b2c44Sab196087
1937d29b2c44Sab196087 /* ehdr:e_shstrndx */
1938d29b2c44Sab196087 static const char *name_e_shstrndx[] = {
1939d29b2c44Sab196087 MSG_ORIG(MSG_CMD_E_SHSTRNDX), NULL };
1940d29b2c44Sab196087 static elfedit_cmd_optarg_t opt_e_shstrndx[] = {
1941d29b2c44Sab196087 { ELFEDIT_STDOA_OPT_O, NULL,
1942d29b2c44Sab196087 ELFEDIT_CMDOA_F_INHERIT, 0, 0 },
1943d29b2c44Sab196087 { MSG_ORIG(MSG_STR_MINUS_SHNDX),
1944d29b2c44Sab196087 /* MSG_INTL(MSG_OPTDESC_SHNDX) */
1945d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_OPTDESC_SHNDX), 0,
1946d29b2c44Sab196087 EHDR_OPT_F_SHNDX, EHDR_OPT_F_SHTYP },
1947d29b2c44Sab196087 { MSG_ORIG(MSG_STR_MINUS_SHTYP),
1948d29b2c44Sab196087 /* MSG_INTL(MSG_OPTDESC_SHTYP) */
1949d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_OPTDESC_SHTYP), 0,
1950d29b2c44Sab196087 EHDR_OPT_F_SHTYP, EHDR_OPT_F_SHNDX, },
1951d29b2c44Sab196087 { NULL }
1952d29b2c44Sab196087 };
1953d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_e_shstrndx[] = {
1954d29b2c44Sab196087 { MSG_ORIG(MSG_STR_SEC),
1955d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_E_SHSTRNDX_SEC) */
1956d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_E_SHSTRNDX_SEC),
1957d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1958d29b2c44Sab196087 { NULL }
1959d29b2c44Sab196087 };
1960d29b2c44Sab196087
1961d29b2c44Sab196087 /* ehdr:ei_mag0 */
1962d29b2c44Sab196087 static const char *name_ei_mag0[] = {
1963d29b2c44Sab196087 MSG_ORIG(MSG_CMD_EI_MAG0), NULL };
1964d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_ei_mag0[] = {
1965d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
1966d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_EI_MAG0_VALUE) */
1967d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_EI_MAG0_VALUE),
1968d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1969d29b2c44Sab196087 { NULL }
1970d29b2c44Sab196087 };
1971d29b2c44Sab196087
1972d29b2c44Sab196087 /* ehdr:ei_mag1 */
1973d29b2c44Sab196087 static const char *name_ei_mag1[] = {
1974d29b2c44Sab196087 MSG_ORIG(MSG_CMD_EI_MAG1), NULL };
1975d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_ei_mag1[] = {
1976d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
1977d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_EI_MAG1_VALUE) */
1978d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_EI_MAG1_VALUE),
1979d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1980d29b2c44Sab196087 { NULL }
1981d29b2c44Sab196087 };
1982d29b2c44Sab196087
1983d29b2c44Sab196087 /* ehdr:ei_mag2 */
1984d29b2c44Sab196087 static const char *name_ei_mag2[] = {
1985d29b2c44Sab196087 MSG_ORIG(MSG_CMD_EI_MAG2), NULL };
1986d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_ei_mag2[] = {
1987d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
1988d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_EI_MAG2_VALUE) */
1989d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_EI_MAG2_VALUE),
1990d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
1991d29b2c44Sab196087 { NULL }
1992d29b2c44Sab196087 };
1993d29b2c44Sab196087
1994d29b2c44Sab196087 /* ehdr:ei_mag3 */
1995d29b2c44Sab196087 static const char *name_ei_mag3[] = {
1996d29b2c44Sab196087 MSG_ORIG(MSG_CMD_EI_MAG3), NULL };
1997d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_ei_mag3[] = {
1998d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
1999d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_EI_MAG3_VALUE) */
2000d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_EI_MAG3_VALUE),
2001d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
2002d29b2c44Sab196087 { NULL }
2003d29b2c44Sab196087 };
2004d29b2c44Sab196087
2005d29b2c44Sab196087 /* ehdr:ei_class */
2006d29b2c44Sab196087 static const char *name_ei_class[] = {
2007d29b2c44Sab196087 MSG_ORIG(MSG_CMD_EI_CLASS), NULL };
2008d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_ei_class[] = {
2009d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
2010d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_EI_CLASS_VALUE) */
2011d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_EI_CLASS_VALUE),
2012d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
2013d29b2c44Sab196087 { NULL }
2014d29b2c44Sab196087 };
2015d29b2c44Sab196087
2016d29b2c44Sab196087 /* ehdr:ei_data */
2017d29b2c44Sab196087 static const char *name_ei_data[] = {
2018d29b2c44Sab196087 MSG_ORIG(MSG_CMD_EI_DATA), NULL };
2019d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_ei_data[] = {
2020d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
2021d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_EI_DATA_VALUE) */
2022d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_EI_DATA_VALUE),
2023d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
2024d29b2c44Sab196087 { NULL }
2025d29b2c44Sab196087 };
2026d29b2c44Sab196087
2027d29b2c44Sab196087 /* ehdr:ei_version */
2028d29b2c44Sab196087 static const char *name_ei_version[] = {
2029d29b2c44Sab196087 MSG_ORIG(MSG_CMD_EI_VERSION), NULL };
2030d29b2c44Sab196087 /* Note: arg_e_version is also used for this command */
2031d29b2c44Sab196087
2032d29b2c44Sab196087 /* ehdr:ei_osabi */
2033d29b2c44Sab196087 static const char *name_ei_osabi[] = {
2034d29b2c44Sab196087 MSG_ORIG(MSG_CMD_EI_OSABI), NULL };
2035d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_ei_osabi[] = {
2036d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
2037d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_EI_OSABI_VALUE) */
2038d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_EI_OSABI_VALUE),
2039d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
2040d29b2c44Sab196087 { NULL }
2041d29b2c44Sab196087 };
2042d29b2c44Sab196087
2043d29b2c44Sab196087 /* ehdr:ei_abiversion */
2044d29b2c44Sab196087 static const char *name_ei_abiversion[] = {
2045d29b2c44Sab196087 MSG_ORIG(MSG_CMD_EI_ABIVERSION), NULL };
2046d29b2c44Sab196087 static elfedit_cmd_optarg_t arg_ei_abiversion[] = {
2047d29b2c44Sab196087 { MSG_ORIG(MSG_STR_VALUE),
2048d29b2c44Sab196087 /* MSG_INTL(MSG_ARGDESC_EI_ABIVERSION_VALUE) */
2049d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_ARGDESC_EI_ABIVERSION_VALUE),
2050d29b2c44Sab196087 ELFEDIT_CMDOA_F_OPT, 0 },
2051d29b2c44Sab196087 { NULL }
2052d29b2c44Sab196087 };
2053d29b2c44Sab196087
2054d29b2c44Sab196087
2055d29b2c44Sab196087
2056d29b2c44Sab196087
2057d29b2c44Sab196087 static elfedit_cmd_t cmds[] = {
2058d29b2c44Sab196087 /* ehdr:dump */
2059d29b2c44Sab196087 { cmd_dump, NULL, name_dump,
2060d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_DUMP) */
2061d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_DUMP),
2062d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_DUMP) */
2063d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_DUMP),
2064d29b2c44Sab196087 NULL, NULL },
2065d29b2c44Sab196087
2066d29b2c44Sab196087 /* ehdr:e_ident */
2067d29b2c44Sab196087 { cmd_e_ident, cpl_e_ident, name_e_ident,
2068d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_E_IDENT) */
2069d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_E_IDENT),
2070d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_E_IDENT) */
2071d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_E_IDENT),
2072d29b2c44Sab196087 opt_std, arg_e_ident },
2073d29b2c44Sab196087
2074d29b2c44Sab196087 /* ehdr:e_type */
2075d29b2c44Sab196087 { cmd_e_type, cpl_e_type, name_e_type,
2076d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_E_TYPE) */
2077d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_E_TYPE),
2078d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_E_TYPE) */
2079d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_E_TYPE),
2080d29b2c44Sab196087 opt_std, arg_e_type },
2081d29b2c44Sab196087
2082d29b2c44Sab196087 /* ehdr:e_machine */
2083d29b2c44Sab196087 { cmd_e_machine, cpl_e_machine, name_e_machine,
2084d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_E_MACHINE) */
2085d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_E_MACHINE),
2086d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_E_MACHINE) */
2087d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_E_MACHINE),
2088d29b2c44Sab196087 opt_std, arg_e_machine },
2089d29b2c44Sab196087
2090d29b2c44Sab196087 /* ehdr:e_version */
2091d29b2c44Sab196087 { cmd_e_version, cpl_e_version, name_e_version,
2092d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_E_VERSION) */
2093d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_E_VERSION),
2094d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_E_VERSION) */
2095d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_E_VERSION),
2096d29b2c44Sab196087 opt_std, arg_e_version },
2097d29b2c44Sab196087
2098d29b2c44Sab196087 /* ehdr:e_entry */
2099d29b2c44Sab196087 { cmd_e_entry, NULL, name_e_entry,
2100d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_E_ENTRY) */
2101d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_E_ENTRY),
2102d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_E_ENTRY) */
2103d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_E_ENTRY),
2104d29b2c44Sab196087 opt_std, arg_e_entry },
2105d29b2c44Sab196087
2106d29b2c44Sab196087 /* ehdr:e_phoff */
2107d29b2c44Sab196087 { cmd_e_phoff, NULL, name_e_phoff,
2108d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_E_PHOFF) */
2109d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_E_PHOFF),
2110d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_E_PHOFF) */
2111d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_E_PHOFF),
2112d29b2c44Sab196087 opt_std, arg_e_phoff },
2113d29b2c44Sab196087
2114d29b2c44Sab196087 /* ehdr:e_shoff */
2115d29b2c44Sab196087 { cmd_e_shoff, NULL, name_e_shoff,
2116d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_E_SHOFF) */
2117d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_E_SHOFF),
2118d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_E_SHOFF) */
2119d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_E_SHOFF),
2120d29b2c44Sab196087 opt_std, arg_e_shoff },
2121d29b2c44Sab196087
2122d29b2c44Sab196087 /* ehdr:e_flags */
2123d29b2c44Sab196087 { cmd_e_flags, cpl_e_flags, name_e_flags,
2124d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_E_FLAGS) */
2125d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_E_FLAGS),
2126d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_E_FLAGS) */
2127d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_E_FLAGS),
2128d29b2c44Sab196087 opt_e_flags, arg_e_flags },
2129d29b2c44Sab196087
2130d29b2c44Sab196087 /* ehdr:e_ehsize */
2131d29b2c44Sab196087 { cmd_e_ehsize, NULL, name_e_ehsize,
2132d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_E_EHSIZE) */
2133d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_E_EHSIZE),
2134d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_E_EHSIZE) */
2135d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_E_EHSIZE),
2136d29b2c44Sab196087 opt_std, arg_e_ehsize },
2137d29b2c44Sab196087
2138d29b2c44Sab196087 /* ehdr:e_phentsize */
2139d29b2c44Sab196087 { cmd_e_phentsize, NULL, name_e_phentsize,
2140d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_E_PHENTSIZE) */
2141d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_E_PHENTSIZE),
2142d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_E_PHENTSIZE) */
2143d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_E_PHENTSIZE),
2144d29b2c44Sab196087 opt_std, arg_e_phentsize },
2145d29b2c44Sab196087
2146d29b2c44Sab196087 /* ehdr:e_phnum */
2147d29b2c44Sab196087 { cmd_e_phnum, NULL, name_e_phnum,
2148d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_E_PHNUM) */
2149d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_E_PHNUM),
2150d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_E_PHNUM) */
2151d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_E_PHNUM),
2152d29b2c44Sab196087 opt_std, arg_e_phnum },
2153d29b2c44Sab196087
2154d29b2c44Sab196087 /* ehdr:e_shentsize */
2155d29b2c44Sab196087 { cmd_e_shentsize, NULL, name_e_shentsize,
2156d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_E_SHENTSIZE) */
2157d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_E_SHENTSIZE),
2158d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_E_SHENTSIZE) */
2159d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_E_SHENTSIZE),
2160d29b2c44Sab196087 opt_std, arg_e_shentsize },
2161d29b2c44Sab196087
2162d29b2c44Sab196087 /* ehdr:e_shnum */
2163d29b2c44Sab196087 { cmd_e_shnum, NULL, name_e_shnum,
2164d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_E_SHNUM) */
2165d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_E_SHNUM),
2166d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_E_SHNUM) */
2167d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_E_SHNUM),
2168d29b2c44Sab196087 opt_std, arg_e_shnum },
2169d29b2c44Sab196087
2170d29b2c44Sab196087 /* ehdr:e_shstrndx */
2171d29b2c44Sab196087 { cmd_e_shstrndx, cpl_e_shstrndx, name_e_shstrndx,
2172d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_E_SHSTRNDX) */
2173d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_E_SHSTRNDX),
2174d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_E_SHSTRNDX) */
2175d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_E_SHSTRNDX),
2176d29b2c44Sab196087 opt_e_shstrndx, arg_e_shstrndx },
2177d29b2c44Sab196087
2178d29b2c44Sab196087 /* ehdr:ei_mag0 */
2179d29b2c44Sab196087 { cmd_ei_mag0, NULL, name_ei_mag0,
2180d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_EI_MAG0) */
2181d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_EI_MAG0),
2182d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_EI_MAG0) */
2183d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_EI_MAG0),
2184d29b2c44Sab196087 opt_std, arg_ei_mag0 },
2185d29b2c44Sab196087
2186d29b2c44Sab196087 /* ehdr:ei_mag1 */
2187d29b2c44Sab196087 { cmd_ei_mag1, NULL, name_ei_mag1,
2188d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_EI_MAG1) */
2189d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_EI_MAG1),
2190d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_EI_MAG1) */
2191d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_EI_MAG1),
2192d29b2c44Sab196087 opt_std, arg_ei_mag1 },
2193d29b2c44Sab196087
2194d29b2c44Sab196087 /* ehdr:ei_mag2 */
2195d29b2c44Sab196087 { cmd_ei_mag2, NULL, name_ei_mag2,
2196d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_EI_MAG2) */
2197d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_EI_MAG2),
2198d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_EI_MAG2) */
2199d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_EI_MAG2),
2200d29b2c44Sab196087 opt_std, arg_ei_mag2 },
2201d29b2c44Sab196087
2202d29b2c44Sab196087 /* ehdr:ei_mag3 */
2203d29b2c44Sab196087 { cmd_ei_mag3, NULL, name_ei_mag3,
2204d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_EI_MAG3) */
2205d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_EI_MAG3),
2206d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_EI_MAG3) */
2207d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_EI_MAG3),
2208d29b2c44Sab196087 opt_std, arg_ei_mag3 },
2209d29b2c44Sab196087
2210d29b2c44Sab196087 /* ehdr:ei_class */
2211d29b2c44Sab196087 { cmd_ei_class, cpl_ei_class, name_ei_class,
2212d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_EI_CLASS) */
2213d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_EI_CLASS),
2214d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_EI_CLASS) */
2215d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_EI_CLASS),
2216d29b2c44Sab196087 opt_std, arg_ei_class },
2217d29b2c44Sab196087
2218d29b2c44Sab196087 /* ehdr:ei_data */
2219d29b2c44Sab196087 { cmd_ei_data, cpl_ei_data, name_ei_data,
2220d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_EI_DATA) */
2221d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_EI_DATA),
2222d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_EI_DATA) */
2223d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_EI_DATA),
2224d29b2c44Sab196087 opt_std, arg_ei_data },
2225d29b2c44Sab196087
2226d29b2c44Sab196087 /* ehdr:ei_version */
2227d29b2c44Sab196087 { cmd_ei_version, cpl_e_version, name_ei_version,
2228d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_EI_VERSION) */
2229d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_EI_VERSION),
2230d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_EI_VERSION) */
2231d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_EI_VERSION),
2232d29b2c44Sab196087 opt_std, arg_e_version },
2233d29b2c44Sab196087
2234d29b2c44Sab196087 /* ehdr:ei_osabi */
2235d29b2c44Sab196087 { cmd_ei_osabi, cpl_ei_osabi, name_ei_osabi,
2236d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_EI_OSABI) */
2237d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_EI_OSABI),
2238d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_EI_OSABI) */
2239d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_EI_OSABI),
2240d29b2c44Sab196087 opt_std, arg_ei_osabi },
2241d29b2c44Sab196087
2242d29b2c44Sab196087 /* ehdr:ei_abiversion */
2243*4f680cc6SAli Bahrami { cmd_ei_abiversion, cpl_ei_abiversion, name_ei_abiversion,
2244d29b2c44Sab196087 /* MSG_INTL(MSG_DESC_EI_ABIVERSION) */
2245d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_DESC_EI_ABIVERSION),
2246d29b2c44Sab196087 /* MSG_INTL(MSG_HELP_EI_ABIVERSION) */
2247d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_HELP_EI_ABIVERSION),
2248d29b2c44Sab196087 opt_std, arg_ei_abiversion },
2249d29b2c44Sab196087
2250d29b2c44Sab196087 { NULL }
2251d29b2c44Sab196087 };
2252d29b2c44Sab196087
2253d29b2c44Sab196087 static elfedit_module_t module = {
2254d29b2c44Sab196087 ELFEDIT_VER_CURRENT, MSG_ORIG(MSG_MOD_NAME),
2255d29b2c44Sab196087 /* MSG_INTL(MSG_MOD_DESC) */
2256d29b2c44Sab196087 ELFEDIT_I18NHDL(MSG_MOD_DESC),
2257d29b2c44Sab196087 cmds, mod_i18nhdl_to_str };
2258d29b2c44Sab196087
2259d29b2c44Sab196087 return (&module);
2260d29b2c44Sab196087 }
2261