Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def is_dynelf(path):
- if os.path.getsize(path) <= 0:
- return False
- with open(path, 'rb') as f:
- if f.read(4) != '\x7fELF':
- return False
- #ELFCLASS32 = 1, ELFCLASS64 = 2
- wordsize = fun('B',f.read(1))*4
- wordfmt = 'Q' if wordsize == 8 else 'L'
- end = fun('B',f.read(1))
- #ELFDATA2LSB = 1, ELFDATA2MSB = 2
- end = '<' if end == 1 else '>'
- f.seek(16)
- elftype = fun(end+'H',f.read(2))
- #ET_REL = 1, ET_EXEC = 2, ET_DYN = 3
- if elftype not in range(1,4):
- return False
- # read section hdr offset
- f.seek(24+wordsize*2)
- shoff = fun(end+wordfmt,f.read(wordsize))
- # read section hdr entry size + nr. of entries
- f.seek(10, 1)
- shentsize = fun(end+'H',f.read(2))
- shnum = fun(end+'H',f.read(2))
- if shentsize < 1:
- return False
- # seek to section hdr and read entry by entry
- for i in xrange(0,shnum):
- f.seek(shoff+(i*shentsize)+4) # 4 = sh_type off
- shenttype = fun(end+'L',f.read(4))
- # SHT_DYNAMIC = 6
- if shenttype == 6:
- return True
- return False
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement