1/* 2Copyright (C) 2001-present by Serge Lamikhov-Center 3 4Permission is hereby granted, free of charge, to any person obtaining a copy 5of this software and associated documentation files (the "Software"), to deal 6in the Software without restriction, including without limitation the rights 7to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 8copies of the Software, and to permit persons to whom the Software is 9furnished to do so, subject to the following conditions: 10 11The above copyright notice and this permission notice shall be included in 12all copies or substantial portions of the Software. 13 14THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 17AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 18LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 19OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 20THE SOFTWARE. 21*/ 22 23#include <iostream> 24#include <elfio/elfio.hpp> 25 26using namespace ELFIO; 27 28int main( int argc, char** argv ) 29{ 30 if ( argc != 2 ) { 31 std::cout << "Usage: add_section <elf_file>" << std::endl; 32 return 1; 33 } 34 35 // Create an elfio reader 36 elfio reader; 37 38 // Load ELF data 39 if ( !reader.load( argv[1] ) ) { 40 std::cout << "Can't find or process ELF file " << argv[1] << std::endl; 41 return 2; 42 } 43 44 // Create additional section at the end of the file 45 section* note_sec = reader.sections.add( ".note.ELFIO" ); 46 note_sec->set_type( SHT_NOTE ); 47 note_section_accessor note_writer( reader, note_sec ); 48 note_writer.add_note( 0x01, "Created by ELFIO", "My data", 8 ); 49 50 reader.save( "./result.elf" ); 51 52 return 0; 53} 54