diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2013-02-03 13:49:12 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2013-02-03 13:49:12 +0200 |
commit | 732a1b0000d2cf1aedd40f3929cbe433ee69b7fe (patch) | |
tree | 0fa04ad93738c6a3e21f0745918562eb15657833 /rpathtool.py | |
parent | 47f8602f1b808e1e62129b7ffe22c459d466b1b1 (diff) | |
download | meson-732a1b0000d2cf1aedd40f3929cbe433ee69b7fe.zip meson-732a1b0000d2cf1aedd40f3929cbe433ee69b7fe.tar.gz meson-732a1b0000d2cf1aedd40f3929cbe433ee69b7fe.tar.bz2 |
Parse ELF header.
Diffstat (limited to 'rpathtool.py')
-rwxr-xr-x | rpathtool.py | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/rpathtool.py b/rpathtool.py index 0e5edad..e5920c4 100755 --- a/rpathtool.py +++ b/rpathtool.py @@ -14,10 +14,32 @@ # See the License for the specific language governing permissions and # limitations under the License. -import sys +import sys, struct + +class Elf(): + + def __init__(self, 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.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] + self.e_entry = struct.unpack('Q', self.bf.read(8))[0] + self.e_phoff = struct.unpack('Q', self.bf.read(8))[0] + self.e_shoff = struct.unpack('Q', self.bf.read(8))[0] + self.e_flags = struct.unpack('i', self.bf.read(4))[0] + self.e_ehsize = struct.unpack('h', self.bf.read(2))[0] + self.e_phentsize = struct.unpack('h', self.bf.read(2))[0] + self.e_phnum = struct.unpack('h', self.bf.read(2))[0] + self.e_shentsize = struct.unpack('h', self.bf.read(2))[0] + self.e_shnum = struct.unpack('h', self.bf.read(2))[0] + self.e_shstrndx = struct.unpack('h', self.bf.read(2))[0] def remove_rpath(bfile): - bf = open(bfile, 'rb') + elf = Elf(bfile) + if __name__ == '__main__': if len(sys.argv) != 2: |