Exemple #1
0
/* main() loops over the cmdline arguments, leaving all the real work
 * to the other functions.
 */
int main(int argc, char *argv[]) {

    int			fd;
    Elf_Ehdr		ehdr;
    Elf_Phdr	       *phdrs;
    unsigned long	newsize;
    char	      **arg;
    int			failures = 0;

    if (argc < 2 || argv[1][0] == '-') {
	printf("Usage: sstrip FILE...\n"
	       "sstrip discards all nonessential bytes from an executable.\n\n"
	       "Version 2.0 Copyright (C) 2000,2001 Brian Raiter.\n"
	       "This program is free software, licensed under the GNU\n"
	       "General Public License. There is absolutely no warranty.\n");
	return EXIT_SUCCESS;
    }

    progname = argv[0];

    for (arg = argv + 1 ; *arg != NULL ; ++arg) {

	filename = *arg;

	fd = open(*arg, O_RDWR);
	if (fd < 0) {
	    ferr("can't open");
	    ++failures;
	    continue;
	}

	if (!(readelfheader(fd, &ehdr)			&&
	      readphdrtable(fd, &ehdr, &phdrs)		&&
	      getmemorysize(&ehdr, phdrs, &newsize)	&&
	      truncatezeros(fd, &newsize)		&&
	      modifyheaders(&ehdr, phdrs, newsize)	&&
	      commitchanges(fd, &ehdr, phdrs, newsize)))
	    ++failures;

	close(fd);
    }

    return failures ? EXIT_FAILURE : EXIT_SUCCESS;
}
Exemple #2
0
/* main() loops over the cmdline arguments, leaving all the real work
 * to the other functions.
 */
int main(int argc, char *argv[])
{
	int				fd;
	union {
		Elf32_Ehdr	ehdr32;
		Elf64_Ehdr	ehdr64;
	} e;
	union {
		Elf32_Phdr	*phdrs32;
		Elf64_Phdr	*phdrs64;
	} p;
	unsigned long	newsize;
	char			**arg;
	int				failures = 0;

	if (argc < 2 || argv[1][0] == '-') {
		printf("Usage: sstrip FILE...\n"
			   "sstrip discards all nonessential bytes from an executable.\n\n"
			   "Version 2.0-X Copyright (C) 2000,2001 Brian Raiter.\n"
			   "Cross-devel hacks Copyright (C) 2004 Manuel Novoa III.\n"
			   "This program is free software, licensed under the GNU\n"
			   "General Public License. There is absolutely no warranty.\n");
		return EXIT_SUCCESS;
	}

	progname = argv[0];

	for (arg = argv + 1 ; *arg != NULL ; ++arg) {
		filename = *arg;

		fd = open(*arg, O_RDWR);
		if (fd < 0) {
			ferr("can't open");
			++failures;
			continue;
		}

		switch (readelfheaderident(fd, &e.ehdr32)) {
			case ELFCLASS32:
				if (!(readelfheader32(fd, &e.ehdr32)					&&
					  readphdrtable32(fd, &e.ehdr32, &p.phdrs32)		&&
					  getmemorysize32(&e.ehdr32, p.phdrs32, &newsize)	&&
					  truncatezeros(fd, &newsize)						&&
					  modifyheaders32(&e.ehdr32, p.phdrs32, newsize)	&&
					  commitchanges32(fd, &e.ehdr32, p.phdrs32, newsize)))
					++failures;
				break;
			case ELFCLASS64:
				if (!(readelfheader64(fd, &e.ehdr64)					&&
					  readphdrtable64(fd, &e.ehdr64, &p.phdrs64)		&&
					  getmemorysize64(&e.ehdr64, p.phdrs64, &newsize)	&&
					  truncatezeros(fd, &newsize)						&&
					  modifyheaders64(&e.ehdr64, p.phdrs64, newsize)	&&
					  commitchanges64(fd, &e.ehdr64, p.phdrs64, newsize)))
					++failures;
				break;
			default:
				++failures;
				break;
		}
		close(fd);
	}

	return failures ? EXIT_FAILURE : EXIT_SUCCESS;
}