# encoding: utf-8'''@author: xingjun.xyf@contact: deathmemory@163.com@file: bb.py@time: 2021年8月6日 8:46 下午@desc:'''import jsonimport sysimport lieffrom lief import ELFfrom lief.ELF import SEGMENT_TYPESclass FixDumpSo:def __init__(self):passdef fix_dump_so(self, sopath, savepath):pobj = lief.parse(sopath)if isinstance(pobj, ELF.Binary) is not True:returnheader = pobj.headerheader.section_header_offset = 0header.section_header_offset = 0header.numberof_sections = 0header.section_name_table_idx = 0segments = pobj.segments# fix segmentfor segment in segments:if isinstance(segment, ELF.Segment):segment.file_offset = segment.virtual_addressprint(f'segment: {segment}')if segment.type == SEGMENT_TYPES.DYNAMIC:print(f'found {segment.type}')pobj.write(savepath)passdef remove_section_table(self, filename, output):binary = lief.parse(filename) # Build an ELF binaryheader = binary.headerheader.section_header_offset = 0header.numberof_sections = 0binary.write(output)def print_elf(self, sopath):binary = lief.parse(sopath)json_data = json.loads(lief.to_json(binary))print(json.dumps(json_data, sort_keys=True, indent=4))if __name__ == '__main__':if 2 != len(sys.argv):print('修复内存 Dump 出的so')print(f'Usage:\n\t{sys.argv[0]} /so/path/libxxx.so')else:fdso = FixDumpSo()sopath = sys.argv[1]savepath = sopath + "_saved"print(f'input so: {sopath}')print(f'saved so: {savepath}')print('working ...')# fdso.print_elf(savepath)fdso.fix_dump_so(sopath=sopath, savepath=savepath)# bjbus.remove_section_table(sopath, savepath)print('done .')pass
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。