/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
*/
/*
* acom: Append Comment
*
* This program demonstrates the use of the libelf interface to
* modify a ELF file. This program will open an ELF file and
* a new .comment section to an existing ELF file.
*/
#include <stdio.h>
#include <libelf.h>
#include <gelf.h>
#include <fcntl.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
static void
{
file, elf_errmsg(0));
return;
}
/*
* Do a string compare to examine each section header
* to see if it is a ".comment" section. If it is then
* this is the section we want to process.
*/
file, elf_errmsg(0));
return;
}
break;
}
int ndx;
(void) printf("%s has no .comment section. "
"Creating one...\n", file);
/*
* First add the ".comment" string to the string table
*/
file, elf_errmsg(0));
return;
}
file, elf_errmsg(0));
return;
}
file, elf_errmsg(0));
return;
}
/*
* Add the ".comment" section to the end of the file.
* Initialize the fields in the Section Header that
* libelf will not fill in.
*/
file, elf_errmsg(0));
return;
}
file, elf_errmsg(0));
return;
}
/*
* Flush the changes to the underlying elf32 or elf64
* section header.
*/
}
(void) printf("%s: .comment section is part of a "
"loadable segment, it cannot be changed.\n", file);
return;
}
file, elf_errmsg(0));
return;
}
elf_errmsg(0));
}
int
{
int i;
char *new_comment;
if (argc < 3) {
(void) printf("usage: %s <new comment> elf_file ...\n",
argv[0]);
return (1);
}
/*
* Initialize the elf library, must be called before elf_begin()
* can be called.
*/
elf_errmsg(0));
return (1);
}
/*
* The new comment is passed in through the command line.
* This string will be used to update the .comment section of
* the specified ELF files.
*/
for (i = 2; i < argc; i++) {
int fd;
char *elf_fname;
perror("open");
continue;
}
/*
* for each file.
*/
elf_errmsg(0));
continue;
}
/*
* Determine what kind of elf file this is:
*/
else
(void) printf("%s not of type ELF_K_ELF. "
}
return (0);
}