summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2005-09-29 14:20:45 (GMT)
committerEelco Dolstra <e.dolstra@tudelft.nl>2005-09-29 14:20:45 (GMT)
commit111c97cf888df0ebf9d30125fe2456b9e638cd12 (patch)
treec711cd5ced4451a82d11c999eaae36795e4c41eb /src
parent868553426143d7bc5dc8d05f838a6326f53cf466 (diff)
downloadpatchelf-111c97cf888df0ebf9d30125fe2456b9e638cd12.zip
patchelf-111c97cf888df0ebf9d30125fe2456b9e638cd12.tar.gz
patchelf-111c97cf888df0ebf9d30125fe2456b9e638cd12.tar.bz2
* Added a flag `--print-interpreter' that prints the path of the
executable's ELF interpreter on standard output and exits.
Diffstat (limited to 'src')
-rw-r--r--src/patchelf.c19
1 files changed, 16 insertions, 3 deletions
diff --git a/src/patchelf.c b/src/patchelf.c
index ae6e7b2..adf1c8f 100644
--- a/src/patchelf.c
+++ b/src/patchelf.c
@@ -16,6 +16,7 @@
static char * fileName = 0;
static char * newInterpreter = 0;
static int doShrinkRPath = 0;
+static int printInterpreter = 0;
#define MAX_PHEADERS 128
@@ -148,12 +149,16 @@ static void setInterpreter(void)
{
/* Find the PT_INTERP segment and replace it by a new one that
contains the new interpreter name. */
- if (newInterpreter && hdr->e_type == ET_EXEC) {
+ if ((newInterpreter || printInterpreter) && hdr->e_type == ET_EXEC) {
shiftFile();
int i;
for (i = 0; i < hdr->e_phnum; ++i) {
Elf32_Phdr * phdr = phdrs + i;
if (phdr->p_type == PT_INTERP) {
+ if (printInterpreter) {
+ printf("%s\n", (char *) (contents + phdr->p_offset));
+ exit(0);
+ }
fprintf(stderr, "changing interpreter from `%s' to `%s'\n",
(char *) (contents + phdr->p_offset), newInterpreter);
unsigned int interpOffset = freeOffset;
@@ -306,7 +311,8 @@ static void shrinkRPath(void)
static void patchElf(void)
{
- fprintf(stderr, "patching ELF file `%s'\n", fileName);
+ if (!printInterpreter)
+ fprintf(stderr, "patching ELF file `%s'\n", fileName);
mode_t fileMode;
@@ -385,7 +391,11 @@ static void patchElf(void)
int main(int argc, char * * argv)
{
if (argc <= 1) {
- fprintf(stderr, "syntax: %s [--interpreter FILENAME] [--shrink-rpath] FILENAME\n", argv[0]);
+ fprintf(stderr, "syntax: %s\n\
+ [--interpreter FILENAME]\n\
+ [--print-interpreter]\n\
+ [--shrink-rpath]\n\
+ FILENAME\n", argv[0]);
return 1;
}
@@ -395,6 +405,9 @@ int main(int argc, char * * argv)
if (++i == argc) error("missing argument");
newInterpreter = argv[i];
}
+ else if (strcmp(argv[i], "--print-interpreter") == 0) {
+ printInterpreter = 1;
+ }
else if (strcmp(argv[i], "--shrink-rpath") == 0) {
doShrinkRPath = 1;
}