public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Anthony G. Basile" <blueness@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/elfix:elfix-0.8.x commit in: misc/
Date: Mon, 20 May 2013 20:02:41 +0000 (UTC)	[thread overview]
Message-ID: <1369079635.7fcf66c9ab50111f5574dbce8cd52d6fd77ad699.blueness@gentoo> (raw)

commit:     7fcf66c9ab50111f5574dbce8cd52d6fd77ad699
Author:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
AuthorDate: Sat Feb  9 21:49:46 2013 +0000
Commit:     Anthony G. Basile <blueness <AT> gentoo <DOT> org>
CommitDate: Mon May 20 19:53:55 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/elfix.git;a=commit;h=7fcf66c9

misc/remove-ptpax.c: code to convert PT_PAX_FLAGS to PT_NULL phdr

---
 misc/remove-ptpax.c |  103 +++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 103 insertions(+), 0 deletions(-)

diff --git a/misc/remove-ptpax.c b/misc/remove-ptpax.c
new file mode 100644
index 0000000..ba441a5
--- /dev/null
+++ b/misc/remove-ptpax.c
@@ -0,0 +1,103 @@
+/*
+	remove-ptpax.c: this file is part of the elfix package
+	Copyright (C) 2013  Anthony G. Basile
+
+	This program is free software: you can redistribute it and/or modify
+	it under the terms of the GNU General Public License as published by
+	the Free Software Foundation, either version 3 of the License, or
+	(at your option) any later version.
+
+	This program is distributed in the hope that it will be useful,
+	but WITHOUT ANY WARRANTY; without even the implied warranty of
+	MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+	GNU General Public License for more details.
+
+	You should have received a copy of the GNU General Public License
+	along with this program.  If not, see <http://www.gnu.org/licenses/>.
+*/
+
+#include <stdio.h>
+#include <stdlib.h>
+#include <sys/types.h>
+#include <sys/stat.h>
+#include <fcntl.h>
+#include <gelf.h>
+
+#ifndef PT_PAX_FLAGS
+ #define PT_PAX_FLAGS 0x65041580
+#endif
+
+int
+remove_ptpax(int fd)
+{
+	Elf *elf;
+	GElf_Phdr phdr;
+	size_t i, phnum;
+
+	if(elf_version(EV_CURRENT) == EV_NONE)
+	{
+		printf("\tELF ERROR: Library out of date.\n");
+		return EXIT_FAILURE;
+	}
+
+	if((elf = elf_begin(fd, ELF_C_RDWR_MMAP, NULL)) == NULL)
+	{
+		printf("\tELF ERROR: elf_begin() fail: %s\n", elf_errmsg(elf_errno()));
+		return EXIT_FAILURE;
+	}
+
+	if(elf_kind(elf) != ELF_K_ELF)
+	{
+		elf_end(elf);
+		printf("\tELF ERROR: elf_kind() fail: this is not an elf file.\n");
+		return EXIT_FAILURE;
+	}
+
+	elf_getphdrnum(elf, &phnum);
+
+	for(i=0; i<phnum; i++)
+	{
+		if(gelf_getphdr(elf, i, &phdr) != &phdr)
+		{
+			elf_end(elf);
+			printf("\tELF ERROR: gelf_getphdr(): %s\n", elf_errmsg(elf_errno()));
+			return EXIT_FAILURE;
+		}
+
+		if(phdr.p_type == PT_PAX_FLAGS)
+		{
+			phdr.p_type = PT_NULL;
+			if(!gelf_update_phdr(elf, i, &phdr))
+			{
+				elf_end(elf);
+				printf("\tELF ERROR: gelf_update_phdr(): %s", elf_errmsg(elf_errno()));
+				return EXIT_FAILURE;
+			}
+		}
+	}
+
+	elf_end(elf);
+	return EXIT_SUCCESS;
+}
+
+
+int
+main( int argc, char *argv[])
+{
+	int fd;
+
+	if(argc != 2)
+	{
+		fprintf(stderr, "Usage: %s <filename>\n", argv[0]) ;
+		exit(EXIT_SUCCESS);
+	}
+
+	if((fd = open(argv[1], O_RDWR)) < 0)
+	{
+		printf("\topen(O_RDWR) failed: cannot change PT_PAX flags\n");
+		exit(EXIT_FAILURE);
+	}
+	else
+		exit(remove_ptpax(fd));
+
+}


             reply	other threads:[~2013-05-20 20:02 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-05-20 20:02 Anthony G. Basile [this message]
  -- strict thread matches above, loose matches on Subject: below --
2013-05-21 15:23 [gentoo-commits] proj/elfix:elfix-0.8.x commit in: misc/ Anthony G. Basile

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1369079635.7fcf66c9ab50111f5574dbce8cd52d6fd77ad699.blueness@gentoo \
    --to=blueness@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox