Generate invalid shared library with size of section headers as zero
This change will generate a shared library that contains an
invalid executable header. The executable header will
set the size of the section headers as zero.
elf64Binary.ehdr.e_shentsize = 0;
Bug: 347728628
Test: $ m geninvalelf64
$ adb push out/target/product/vsoc_x86_64_pgagnostic/system/bin/geninvalelf64 /data
$ vsoc_x86_64_pgagnostic:/data # ./geninvalelf64 ./test_x86_64/libtest_empty.so ./test_x86_64
Writing ELF64 binary to file ./test_x86_64/libtest_invalid-zero_shentsize.so
$ vsoc_x86_64_pgagnostic:/data # ldd $PWD/test_x86_64/libtest_invalid-zero_shentsize.so
"/data/test_x86_64/libtest_invalid-zero_shentsize.so" has unsupported e_shentsize: 0x0 (expected 0x40)
error: "/data/test_x86_64/libtest_invalid-zero_shentsize.so" has unsupported e_shentsize: 0x0 (expected 0x40)
$ vsoc_x86_64_pgagnostic:/data # readelf -h ./test_x86_64/libtest_invalid-zero_shentsize.so
readelf: ./test_x86_64/libtest_invalid-zero_shentsize.so: bad shstrndx
ELF Header:
Magic: 7f 45 4c 46 02 01 01 00 00 00 00 00 00 00 00 00
Class: ELF64
Data: 2's complement, little endian
Version: 1 (current)
OS/ABI: UNIX - System V
ABI Version: 0
Type: DYN (Shared object file)
Machine: x86-64
Version: 0x1
Entry point address: 0x0
Start of program headers: 64 (bytes into file)
Start of section headers: 3216 (bytes into file)
Flags: 0x0
Size of this header: 64 (bytes)
Size of program headers: 56 (bytes)
Number of program headers: 9
Size of section headers: 0 (bytes)
Number of section headers: 22
Section header string table index: 20$
$ vsoc_x86_64_pgagnostic:/data # readelf -l ./test_x86_64/libtest_invalid-zero_shentsize.so
readelf: ./test_x86_64/libtest_invalid-zero_shentsize.so: bad shstrndx
Change-Id: Ib5b0d0c92f04f53052c6b42c7c33135cf95352bb
1 file changed