aboutsummaryrefslogtreecommitdiff
path: root/rpathtool.py
diff options
context:
space:
mode:
authorJussi Pakkanen <jpakkane@gmail.com>2013-02-03 14:11:04 +0200
committerJussi Pakkanen <jpakkane@gmail.com>2013-02-03 14:11:04 +0200
commit60905c96631163d5f493b7dbef8e5eb191e2cf75 (patch)
tree010cb6cf73d056f7b42f8cf6b0fc6caed0b76da3 /rpathtool.py
parent732a1b0000d2cf1aedd40f3929cbe433ee69b7fe (diff)
downloadmeson-60905c96631163d5f493b7dbef8e5eb191e2cf75.zip
meson-60905c96631163d5f493b7dbef8e5eb191e2cf75.tar.gz
meson-60905c96631163d5f493b7dbef8e5eb191e2cf75.tar.bz2
Parse section header.
Diffstat (limited to 'rpathtool.py')
-rwxr-xr-xrpathtool.py40
1 files changed, 37 insertions, 3 deletions
diff --git a/rpathtool.py b/rpathtool.py
index e5920c4..8995419 100755
--- a/rpathtool.py
+++ b/rpathtool.py
@@ -16,13 +16,41 @@
import sys, struct
+class SectionHeader():
+ def __init__(self, ifile):
+#Elf64_Word
+ self.sh_name = struct.unpack('I', ifile.read(4))[0];
+#Elf64_Word
+ self.sh_type = struct.unpack('I', ifile.read(4))[0]
+#Elf64_Xword
+ self.sh_flags = struct.unpack('Q', ifile.read(8))[0];
+#Elf64_Addr
+ self.sh_addr = struct.unpack('Q', ifile.read(8))[0];
+#Elf64_Off
+ self.sh_offset = struct.unpack('Q', ifile.read(8))[0]
+#Elf64_Xword
+ self.sh_size = struct.unpack('Q', ifile.read(8))[0];
+#Elf64_Word
+ self.sh_link = struct.unpack('I', ifile.read(4))[0];
+#Elf64_Word
+ self.sh_info = struct.unpack('I', ifile.read(4))[0];
+#Elf64_Xword
+ self.sh_addralign = struct.unpack('Q', ifile.read(4))[0];
+#Elf64_Xword
+ self.sh_entsize = struct.unpack('Q', ifile.read(8))[0];
+
class Elf():
def __init__(self, bfile):
+ self.bfile = bfile
self.bf = open(bfile, 'rb')
- self.ident = struct.unpack('16s', self.bf.read(16))[0]
- if self.ident[1:4] != b'ELF':
- raise RuntimeError('File "%s" is not an ELF file.' % bfile)
+ self.parse_header()
+ self.parse_sections()
+
+ def parse_header(self):
+ self.e_ident = struct.unpack('16s', self.bf.read(16))[0]
+ if self.e_ident[1:4] != b'ELF':
+ raise RuntimeError('File "%s" is not an ELF file.' % self.bfile)
self.e_type = struct.unpack('h', self.bf.read(2))[0]
self.e_machine = struct.unpack('h', self.bf.read(2))[0]
self.e_version = struct.unpack('i', self.bf.read(4))[0]
@@ -37,6 +65,12 @@ class Elf():
self.e_shnum = struct.unpack('h', self.bf.read(2))[0]
self.e_shstrndx = struct.unpack('h', self.bf.read(2))[0]
+ def parse_sections(self):
+ self.bf.seek(self.e_shoff)
+ self.sections = []
+ for i in range(self.e_shnum):
+ self.sections.append(self.bf)
+
def remove_rpath(bfile):
elf = Elf(bfile)