diff --git a/bionic/prebuilt-elf-files/edit.py b/bionic/prebuilt-elf-files/edit.py new file mode 100644 index 0000000000000000000000000000000000000000..3eeaceb47155d0e7d478b5655a021233a2dbffc4 --- /dev/null +++ b/bionic/prebuilt-elf-files/edit.py @@ -0,0 +1,47 @@ +from __future__ import print_function +import sys + +# If pyelftools is not installed, the example can also run from the root or +# examples/ dir of the source distribution. +sys.path[0:0] = ['.', '..'] + +from elftools.elf.elffile import ELFFile +from elftools.elf.sections import SymbolTableSection + + +def process_file(filename): + + #use map as "switch case" to decide which file is being edited + files = { + "libtest_invalid-zero_shdr_table_content.so": invalid_zero_shdr_table_content_FileEdit + } + + print('Processing file:', filename) + method = files.get(filename) + with open(filename, 'rb+') as f: + if method: + method(f) + +def invalid_zero_shdr_table_content_FileEdit(stream): + elfFile = ELFFile(stream) + elfSection = elfFile.get_section_by_name('.dynamic') + + if not elfSection: + print('.dynamic') + return + + section_type = elfSection['sh_type'] + if section_type != 'SHT_DYNAMIC': + print('wrong type') + return + + #section header's offset is 0xb04 + #sh_size in the section header is the size of section area instead of that of section header's + stream.seek(0xb04) + stream.write(b'\x00') + +if __name__ == '__main__': + if sys.argv[1] == '--test': + for filename in sys.argv[2:]: + process_file(filename) +