--- debugedit-4.4.6/debugedit.c 2006-06-09 14:17:06.000000000 +0000 +++ debugedit-4.4.6-r2/debugedit.c 2008-05-03 01:41:58.054845092 +0000 @@ -43,6 +43,8 @@ char *base_dir = NULL; char *dest_dir = NULL; char *list_file = NULL; +int print_files; +int read_only; int list_file_fd = -1; typedef unsigned int uint_32; @@ -567,13 +569,13 @@ char *p; size_t size; ssize_t ret; - if (base_dir) - p = s + strlen (base_dir); - else - p = s; if (list_file_fd != -1) { + if (base_dir) + p = s + strlen (base_dir); + else + p = s; size = strlen (p) + 1; while (size > 0) { @@ -584,6 +586,23 @@ p += ret; } } + if (print_files) + { + if (base_dir) + p = s + strlen (base_dir); + else + p = s; + size = strlen (p) + 1; + while (size > 0) + { + ret = write (STDOUT_FILENO, p, size); + if (ret == -1) + break; + write (STDOUT_FILENO, "\n", 1); + size -= ret; + p += ret; + } + } } free (s); @@ -1193,6 +1212,10 @@ "directory to rewrite base-dir into", NULL }, { "list-file", 'l', POPT_ARG_STRING, &list_file, 0, "file where to put list of source and header file names", NULL }, + { "print", 'p', POPT_ARG_NONE, &print_files, 0, + "print newline delimited list of file names to stdout", NULL }, + { "read-only", 'r', POPT_ARG_NONE, &read_only, 0, + "open read-only", NULL }, POPT_AUTOHELP { NULL, 0, 0, NULL, 0, NULL, NULL } }; @@ -1205,7 +1228,7 @@ int i; DSO *dso = NULL; - elf = elf_begin (fd, ELF_C_RDWR_MMAP, NULL); + elf = elf_begin (fd, read_only ? ELF_C_READ : ELF_C_RDWR_MMAP, NULL); if (elf == NULL) { error (0, 0, "cannot open ELF file: %s", elf_errmsg (-1)); @@ -1357,10 +1380,12 @@ exit (1); } - /* Make sure we can read and write */ - chmod (file, stat_buf.st_mode | S_IRUSR | S_IWUSR); + if (!read_only) { + /* Make sure we can read and write */ + chmod (file, stat_buf.st_mode | S_IRUSR | S_IWUSR); + } - fd = open (file, O_RDWR); + fd = open (file, read_only ? O_RDONLY : O_RDWR); if (fd < 0) { fprintf (stderr, "Failed to open input file '%s': %s\n", file, strerror(errno)); @@ -1393,7 +1418,7 @@ } } - if (elf_update (dso->elf, ELF_C_WRITE) < 0) + if (!read_only && elf_update (dso->elf, ELF_C_WRITE) < 0) { fprintf (stderr, "Failed to write file: %s\n", elf_errmsg (elf_errno())); exit (1); @@ -1405,8 +1430,10 @@ } close (fd); - /* Restore old access rights */ - chmod (file, stat_buf.st_mode); + if (!read_only) { + /* Restore old access rights */ + chmod (file, stat_buf.st_mode); + } poptFreeContext (optCon);