summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-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;
}