diff options
author | Nicolas Dechesne <nicolas.dechesne@linaro.org> | 2018-05-27 00:09:48 +0200 |
---|---|---|
committer | Nicolas Dechesne <nicolas.dechesne@linaro.org> | 2018-05-27 01:29:20 +0200 |
commit | 1f61c03322c3728f35b3f0cd4ff04f73522f1e67 (patch) | |
tree | b2fee80d9ee40a1e61976b3331e144c167e1ab31 | |
parent | 059f3f2768a8bc460fe814e2bb4bc8cc3078c8ba (diff) |
Add support for ELF64
ELF32 was assumed so far, and a few hard coded constants were used. In this
patch, we avoid hardcoding and header size which are different for ELF32 and
ELF64.
Use elfio.get_class() to set the output file ELF class so that it matches the
input file ELF class.
signlk needs the section size header to compute the offset where the data needs
to be inserted, so a new file is created which contains the section size which
is different on ELF32 and ELF64.
Signed-off-by: Nicolas Dechesne <nicolas.dechesne@linaro.org>
-rw-r--r-- | signer/signlk.cpp | 22 | ||||
-rwxr-xr-x | signlk.sh | 2 |
2 files changed, 14 insertions, 10 deletions
diff --git a/signer/signlk.cpp b/signer/signlk.cpp index 466185f..615775a 100644 --- a/signer/signlk.cpp +++ b/signer/signlk.cpp @@ -125,14 +125,7 @@ int main( int argc, char** argv ) char elfHeader[0x1000]; Elf_Half seg_num=0; char Si[8] ={0x36,0x36,0x36,0x36,0x36,0x36,0x36,0x3F}; - char So[8] ={0x5C,0x5C,0x5C,0x5C,0x5C,0x5C,0x5C,0x5C}; - - /* create a write configuration */ - writer.create( ELFCLASS32, ELFDATA2LSB ); - writer.set_os_abi( ELFOSABI_NONE ); - writer.set_type( ET_EXEC ); - writer.set_machine( EM_ARM ); - writer.set_flags(0x5000002); + char So[8] ={0x5C,0x5C,0x5C,0x5C,0x5C,0x5C,0x5C,0x5C}; /* Load ELF data */ if ( !reader.load( argv[1] ) ) { @@ -140,6 +133,13 @@ int main( int argc, char** argv ) return 2; } + /* create a write configuration */ + writer.create( reader.get_class(), reader.get_encoding() ); + writer.set_os_abi( reader.get_os_abi() ); + writer.set_type( reader.get_type() ); + writer.set_machine( reader.get_machine() ); + writer.set_flags(reader.get_flags()); + seg_num = reader.segments.size(); /* Create hash data section*/ @@ -232,7 +232,7 @@ int main( int argc, char** argv ) } } - Elf_Half headerSize = writer.get_header_size() +(writer.segments.size() )*32; + Elf_Half headerSize = writer.get_header_size() + writer.segments.size() * writer.get_segment_entry_size(); /* Create data section */ data_sec = writer.sections.add( "" ); data_sec->set_type( SHT_NOBITS ); @@ -282,5 +282,9 @@ int main( int argc, char** argv ) std::string tmpSoFileName = tmp_path+"/So"; saveDataToFile(tmpSoFileName, So, sizeof(So)); + std::string sectionSize = std::to_string(writer.get_section_entry_size()); + std::string tmpSectionSizeFileName = tmp_path+"/sectionSize"; + saveDataToFile(tmpSectionSizeFileName, sectionSize.c_str(), sizeof(sectionSize.c_str())); + return 0; } @@ -167,7 +167,7 @@ atte_file_size=$(du -b $ATT | tr '[:blank:]' ' ' | cut -d ' ' -f 1) root_file_size=$(du -b $ROOT | tr '[:blank:]' ' ' | cut -d ' ' -f 1) hash_seg_file_size=$(du -b $tmpdir/hashSeg | tr '[:blank:]' ' ' | cut -d ' ' -f 1) hash_seg_offset=4096 -mi_hdr_size=40 +mi_hdr_size=$(tr -d '\0' < $tmpdir/sectionSize) dd if=$TMPOUTFILE of=$OUTFILE 2>/dev/null dd if=$DATA of=$OUTFILE bs=1 count=$data_file_size seek=$((hash_seg_offset+$mi_hdr_size)) 2>/dev/null |