From 111c97cf888df0ebf9d30125fe2456b9e638cd12 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 29 Sep 2005 14:20:45 +0000 Subject: * Added a flag `--print-interpreter' that prints the path of the executable's ELF interpreter on standard output and exits. --- src/patchelf.c | 19 ++++++++++++++++--- 1 file 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; } -- cgit v0.12