def strip(self, stripped_filename):
with mmapper(self.filename) as mapped:
fd, file = mapped
ehdr = self.elf.Ehdr.read(file)
stripped_ehdr = ehdr._replace(e_shoff=0, e_shnum=0, e_shstrndx=0)
stripped_size = max(phdr.p_offset + phdr.p_filesz
for phdr in gen_phdrs(file, self.elf, ehdr)
if phdr.p_type == PT_LOAD)
assert ehdr.e_phoff + (ehdr.e_phnum *
ehdr.e_phentsize) <= stripped_size
# Create the new file with the same mode as the original.
with os.fdopen(os.open(stripped_filename,
os.O_WRONLY | os.O_CREAT | os.O_TRUNC,
os.fstat(fd).st_mode & 0777),
'wb') as stripped_file:
stripped_file.write(self.elf.Ehdr.pack(stripped_ehdr))
stripped_file.write(file[self.elf.Ehdr.size:stripped_size])
评论列表
文章目录