diff options
author | Jussi Pakkanen <jpakkane@gmail.com> | 2013-02-03 14:33:14 +0200 |
---|---|---|
committer | Jussi Pakkanen <jpakkane@gmail.com> | 2013-02-03 14:33:14 +0200 |
commit | 682e5620f8e4bca83c4c178efe907ec96d6bf782 (patch) | |
tree | 2e302753d3b634361120075deee83563fc2ac0f3 | |
parent | 60905c96631163d5f493b7dbef8e5eb191e2cf75 (diff) | |
download | meson-682e5620f8e4bca83c4c178efe907ec96d6bf782.zip meson-682e5620f8e4bca83c4c178efe907ec96d6bf782.tar.gz meson-682e5620f8e4bca83c4c178efe907ec96d6bf782.tar.bz2 |
Parse section names.
-rwxr-xr-x | rpathtool.py | 25 |
1 files changed, 19 insertions, 6 deletions
diff --git a/rpathtool.py b/rpathtool.py index 8995419..b5bfcf9 100755 --- a/rpathtool.py +++ b/rpathtool.py @@ -16,6 +16,8 @@ import sys, struct +SHT_STRTAB = 3 + class SectionHeader(): def __init__(self, ifile): #Elf64_Word @@ -35,7 +37,7 @@ class SectionHeader(): #Elf64_Word self.sh_info = struct.unpack('I', ifile.read(4))[0]; #Elf64_Xword - self.sh_addralign = struct.unpack('Q', ifile.read(4))[0]; + self.sh_addralign = struct.unpack('Q', ifile.read(8))[0]; #Elf64_Xword self.sh_entsize = struct.unpack('Q', ifile.read(8))[0]; @@ -69,15 +71,26 @@ class Elf(): self.bf.seek(self.e_shoff) self.sections = [] for i in range(self.e_shnum): - self.sections.append(self.bf) + self.sections.append(SectionHeader(self.bf)) -def remove_rpath(bfile): - elf = Elf(bfile) + def read_str(self): + arr = [] + x = self.bf.read(1) + while x != b'\0': + arr.append(x) + x = self.bf.read(1) + return b''.join(arr) + def print_section_names(self): + section_names = self.sections[self.e_shstrndx] + for i in self.sections: + self.bf.seek(section_names.sh_offset + i.sh_name) + name = self.read_str() + print(name.decode()) if __name__ == '__main__': if len(sys.argv) != 2: print('%s: <binary file>' % sys.argv[0]) exit(1) - bfile = sys.argv[1] - remove_rpath(bfile) + e = Elf(sys.argv[1]) + e.print_section_names() |