165042b18Sopenharmony_ci/*
265042b18Sopenharmony_ciCopyright (C) 2001-present by Serge Lamikhov-Center
365042b18Sopenharmony_ci
465042b18Sopenharmony_ciPermission is hereby granted, free of charge, to any person obtaining a copy
565042b18Sopenharmony_ciof this software and associated documentation files (the "Software"), to deal
665042b18Sopenharmony_ciin the Software without restriction, including without limitation the rights
765042b18Sopenharmony_cito use, copy, modify, merge, publish, distribute, sublicense, and/or sell
865042b18Sopenharmony_cicopies of the Software, and to permit persons to whom the Software is
965042b18Sopenharmony_cifurnished to do so, subject to the following conditions:
1065042b18Sopenharmony_ci
1165042b18Sopenharmony_ciThe above copyright notice and this permission notice shall be included in
1265042b18Sopenharmony_ciall copies or substantial portions of the Software.
1365042b18Sopenharmony_ci
1465042b18Sopenharmony_ciTHE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1565042b18Sopenharmony_ciIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1665042b18Sopenharmony_ciFITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
1765042b18Sopenharmony_ciAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
1865042b18Sopenharmony_ciLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
1965042b18Sopenharmony_ciOUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
2065042b18Sopenharmony_ciTHE SOFTWARE.
2165042b18Sopenharmony_ci*/
2265042b18Sopenharmony_ci
2365042b18Sopenharmony_ci#ifdef _MSC_VER
2465042b18Sopenharmony_ci#define _CRT_SECURE_NO_WARNINGS
2565042b18Sopenharmony_ci#endif
2665042b18Sopenharmony_ci
2765042b18Sopenharmony_ci#include <elfio/elfio.hpp>
2865042b18Sopenharmony_ci#include <cstring>
2965042b18Sopenharmony_ci
3065042b18Sopenharmony_ciusing namespace ELFIO;
3165042b18Sopenharmony_ci
3265042b18Sopenharmony_ci#include "elfio_c_wrapper.h"
3365042b18Sopenharmony_ci
3465042b18Sopenharmony_ci//-----------------------------------------------------------------------------
3565042b18Sopenharmony_ci// elfio
3665042b18Sopenharmony_ci//-----------------------------------------------------------------------------
3765042b18Sopenharmony_cipelfio_t elfio_new() { return new ( std::nothrow ) elfio; }
3865042b18Sopenharmony_ci
3965042b18Sopenharmony_civoid elfio_delete( pelfio_t pelfio ) { delete (elfio*)pelfio; }
4065042b18Sopenharmony_ci
4165042b18Sopenharmony_civoid elfio_create( pelfio_t      pelfio,
4265042b18Sopenharmony_ci                   unsigned char file_class,
4365042b18Sopenharmony_ci                   unsigned char encoding )
4465042b18Sopenharmony_ci{
4565042b18Sopenharmony_ci    pelfio->create( file_class, encoding );
4665042b18Sopenharmony_ci}
4765042b18Sopenharmony_ci
4865042b18Sopenharmony_cibool elfio_load( pelfio_t pelfio, const char* file_name )
4965042b18Sopenharmony_ci{
5065042b18Sopenharmony_ci    return pelfio->load( file_name );
5165042b18Sopenharmony_ci}
5265042b18Sopenharmony_ci
5365042b18Sopenharmony_cibool elfio_save( pelfio_t pelfio, const char* file_name )
5465042b18Sopenharmony_ci{
5565042b18Sopenharmony_ci    return pelfio->save( file_name );
5665042b18Sopenharmony_ci}
5765042b18Sopenharmony_ci
5865042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_IMPL( unsigned char, class );
5965042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_IMPL( unsigned char, elf_version );
6065042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_IMPL( unsigned char, encoding );
6165042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_IMPL( Elf_Word, version );
6265042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_IMPL( Elf_Half, header_size );
6365042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_IMPL( Elf_Half, section_entry_size );
6465042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_IMPL( Elf_Half, segment_entry_size );
6565042b18Sopenharmony_ci
6665042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_SET_IMPL( unsigned char, os_abi );
6765042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_SET_IMPL( unsigned char, abi_version );
6865042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_SET_IMPL( Elf_Half, type );
6965042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_SET_IMPL( Elf_Half, machine );
7065042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_SET_IMPL( Elf_Word, flags );
7165042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_SET_IMPL( Elf64_Addr, entry );
7265042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_SET_IMPL( Elf64_Off, sections_offset );
7365042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_SET_IMPL( Elf64_Off, segments_offset );
7465042b18Sopenharmony_ciELFIO_C_HEADER_ACCESS_GET_SET_IMPL( Elf_Half, section_name_str_index );
7565042b18Sopenharmony_ci
7665042b18Sopenharmony_ciElf_Half elfio_get_sections_num( pelfio_t pelfio )
7765042b18Sopenharmony_ci{
7865042b18Sopenharmony_ci    return pelfio->sections.size();
7965042b18Sopenharmony_ci}
8065042b18Sopenharmony_ci
8165042b18Sopenharmony_cipsection_t elfio_get_section_by_index( pelfio_t pelfio, int index )
8265042b18Sopenharmony_ci{
8365042b18Sopenharmony_ci    return pelfio->sections[index];
8465042b18Sopenharmony_ci}
8565042b18Sopenharmony_ci
8665042b18Sopenharmony_cipsection_t elfio_get_section_by_name( pelfio_t pelfio, char* name )
8765042b18Sopenharmony_ci{
8865042b18Sopenharmony_ci    return pelfio->sections[name];
8965042b18Sopenharmony_ci}
9065042b18Sopenharmony_ci
9165042b18Sopenharmony_cipsection_t elfio_add_section( pelfio_t pelfio, char* name )
9265042b18Sopenharmony_ci{
9365042b18Sopenharmony_ci    return pelfio->sections.add( name );
9465042b18Sopenharmony_ci}
9565042b18Sopenharmony_ci
9665042b18Sopenharmony_ciElf_Half elfio_get_segments_num( pelfio_t pelfio )
9765042b18Sopenharmony_ci{
9865042b18Sopenharmony_ci    return pelfio->segments.size();
9965042b18Sopenharmony_ci}
10065042b18Sopenharmony_ci
10165042b18Sopenharmony_cipsegment_t elfio_get_segment_by_index( pelfio_t pelfio, int index )
10265042b18Sopenharmony_ci{
10365042b18Sopenharmony_ci    return pelfio->segments[index];
10465042b18Sopenharmony_ci}
10565042b18Sopenharmony_ci
10665042b18Sopenharmony_cipsegment_t elfio_add_segment( pelfio_t pelfio )
10765042b18Sopenharmony_ci{
10865042b18Sopenharmony_ci    return pelfio->segments.add();
10965042b18Sopenharmony_ci}
11065042b18Sopenharmony_ci
11165042b18Sopenharmony_cibool elfio_validate( pelfio_t pelfio, char* msg, int msg_len )
11265042b18Sopenharmony_ci{
11365042b18Sopenharmony_ci    std::string error = pelfio->validate();
11465042b18Sopenharmony_ci
11565042b18Sopenharmony_ci    if ( msg != nullptr && msg_len > 0 ) {
11665042b18Sopenharmony_ci        strncpy( msg, error.c_str(), (size_t)msg_len - 1 );
11765042b18Sopenharmony_ci    }
11865042b18Sopenharmony_ci
11965042b18Sopenharmony_ci    return error.empty();
12065042b18Sopenharmony_ci}
12165042b18Sopenharmony_ci
12265042b18Sopenharmony_ci//-----------------------------------------------------------------------------
12365042b18Sopenharmony_ci// section
12465042b18Sopenharmony_ci//-----------------------------------------------------------------------------
12565042b18Sopenharmony_ciELFIO_C_GET_ACCESS_IMPL( section, Elf_Half, index );
12665042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( section, Elf_Word, type );
12765042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( section, Elf_Xword, flags );
12865042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( section, Elf_Word, info );
12965042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( section, Elf_Word, link );
13065042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( section, Elf_Xword, addr_align );
13165042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( section, Elf_Xword, entry_size );
13265042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( section, Elf64_Addr, address );
13365042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( section, Elf_Xword, size );
13465042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( section, Elf_Word, name_string_offset );
13565042b18Sopenharmony_ciELFIO_C_GET_ACCESS_IMPL( section, Elf64_Off, offset );
13665042b18Sopenharmony_ci
13765042b18Sopenharmony_civoid elfio_section_get_name( psection_t psection, char* buffer, int len )
13865042b18Sopenharmony_ci{
13965042b18Sopenharmony_ci    strncpy( buffer, psection->get_name().c_str(), (size_t)len - 1 );
14065042b18Sopenharmony_ci}
14165042b18Sopenharmony_ci
14265042b18Sopenharmony_civoid elfio_section_set_name( psection_t psection, char* buffer )
14365042b18Sopenharmony_ci{
14465042b18Sopenharmony_ci    psection->set_name( buffer );
14565042b18Sopenharmony_ci}
14665042b18Sopenharmony_ci
14765042b18Sopenharmony_cichar* elfio_section_get_data( psection_t psection )
14865042b18Sopenharmony_ci{
14965042b18Sopenharmony_ci    return (char*)psection->get_data();
15065042b18Sopenharmony_ci}
15165042b18Sopenharmony_ci
15265042b18Sopenharmony_civoid elfio_section_set_data( psection_t  psection,
15365042b18Sopenharmony_ci                             const char* pData,
15465042b18Sopenharmony_ci                             Elf_Word    size )
15565042b18Sopenharmony_ci{
15665042b18Sopenharmony_ci    psection->set_data( pData, size );
15765042b18Sopenharmony_ci}
15865042b18Sopenharmony_ci
15965042b18Sopenharmony_civoid elfio_section_append_data( psection_t  psection,
16065042b18Sopenharmony_ci                                const char* pData,
16165042b18Sopenharmony_ci                                Elf_Word    size )
16265042b18Sopenharmony_ci{
16365042b18Sopenharmony_ci    psection->append_data( pData, size );
16465042b18Sopenharmony_ci}
16565042b18Sopenharmony_ci
16665042b18Sopenharmony_ci//-----------------------------------------------------------------------------
16765042b18Sopenharmony_ci// segment
16865042b18Sopenharmony_ci//-----------------------------------------------------------------------------
16965042b18Sopenharmony_ciELFIO_C_GET_ACCESS_IMPL( segment, Elf_Half, index );
17065042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( segment, Elf_Word, type );
17165042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( segment, Elf_Word, flags );
17265042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( segment, Elf_Xword, align );
17365042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( segment, Elf_Xword, memory_size );
17465042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( segment, Elf64_Addr, virtual_address );
17565042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( segment, Elf64_Addr, physical_address );
17665042b18Sopenharmony_ciELFIO_C_GET_SET_ACCESS_IMPL( segment, Elf_Xword, file_size );
17765042b18Sopenharmony_ciELFIO_C_GET_ACCESS_IMPL( segment, Elf64_Off, offset );
17865042b18Sopenharmony_ci
17965042b18Sopenharmony_cichar* elfio_segment_get_data( psegment_t psegment )
18065042b18Sopenharmony_ci{
18165042b18Sopenharmony_ci    return (char*)psegment->get_data();
18265042b18Sopenharmony_ci}
18365042b18Sopenharmony_ci
18465042b18Sopenharmony_ciElf_Half elfio_segment_add_section_index( psegment_t psegment,
18565042b18Sopenharmony_ci                                          Elf_Half   index,
18665042b18Sopenharmony_ci                                          Elf_Xword  addr_align )
18765042b18Sopenharmony_ci{
18865042b18Sopenharmony_ci    return psegment->add_section_index( index, addr_align );
18965042b18Sopenharmony_ci}
19065042b18Sopenharmony_ci
19165042b18Sopenharmony_ciElf_Half elfio_segment_get_sections_num( psegment_t psegment )
19265042b18Sopenharmony_ci{
19365042b18Sopenharmony_ci    return psegment->get_sections_num();
19465042b18Sopenharmony_ci}
19565042b18Sopenharmony_ci
19665042b18Sopenharmony_ciElf_Half elfio_segment_get_section_index_at( psegment_t psegment, Elf_Half num )
19765042b18Sopenharmony_ci{
19865042b18Sopenharmony_ci    return psegment->get_section_index_at( num );
19965042b18Sopenharmony_ci}
20065042b18Sopenharmony_ci
20165042b18Sopenharmony_cibool elfio_segment_is_offset_initialized( psegment_t psegment )
20265042b18Sopenharmony_ci{
20365042b18Sopenharmony_ci    return psegment->is_offset_initialized();
20465042b18Sopenharmony_ci}
20565042b18Sopenharmony_ci
20665042b18Sopenharmony_ci//-----------------------------------------------------------------------------
20765042b18Sopenharmony_ci// symbol
20865042b18Sopenharmony_ci//-----------------------------------------------------------------------------
20965042b18Sopenharmony_cipsymbol_t elfio_symbol_section_accessor_new( pelfio_t   pelfio,
21065042b18Sopenharmony_ci                                             psection_t psection )
21165042b18Sopenharmony_ci{
21265042b18Sopenharmony_ci    return new ( std::nothrow ) symbol_section_accessor( *pelfio, psection );
21365042b18Sopenharmony_ci}
21465042b18Sopenharmony_ci
21565042b18Sopenharmony_civoid elfio_symbol_section_accessor_delete( psymbol_t psymbol )
21665042b18Sopenharmony_ci{
21765042b18Sopenharmony_ci    delete psymbol;
21865042b18Sopenharmony_ci}
21965042b18Sopenharmony_ci
22065042b18Sopenharmony_ciElf_Xword elfio_symbol_get_symbols_num( psymbol_t psymbol )
22165042b18Sopenharmony_ci{
22265042b18Sopenharmony_ci    return psymbol->get_symbols_num();
22365042b18Sopenharmony_ci}
22465042b18Sopenharmony_ci
22565042b18Sopenharmony_cibool elfio_symbol_get_symbol( psymbol_t      psymbol,
22665042b18Sopenharmony_ci                              Elf_Xword      index,
22765042b18Sopenharmony_ci                              char*          name,
22865042b18Sopenharmony_ci                              int            name_len,
22965042b18Sopenharmony_ci                              Elf64_Addr*    value,
23065042b18Sopenharmony_ci                              Elf_Xword*     size,
23165042b18Sopenharmony_ci                              unsigned char* bind,
23265042b18Sopenharmony_ci                              unsigned char* type,
23365042b18Sopenharmony_ci                              Elf_Half*      section_index,
23465042b18Sopenharmony_ci                              unsigned char* other )
23565042b18Sopenharmony_ci{
23665042b18Sopenharmony_ci    std::string name_param;
23765042b18Sopenharmony_ci    bool ret = psymbol->get_symbol( index, name_param, *value, *size, *bind,
23865042b18Sopenharmony_ci                                    *type, *section_index, *other );
23965042b18Sopenharmony_ci    strncpy( name, name_param.c_str(), (size_t)name_len - 1 );
24065042b18Sopenharmony_ci
24165042b18Sopenharmony_ci    return ret;
24265042b18Sopenharmony_ci}
24365042b18Sopenharmony_ci
24465042b18Sopenharmony_ciElf_Word elfio_symbol_add_symbol( psymbol_t     psymbol,
24565042b18Sopenharmony_ci                                  Elf_Word      name,
24665042b18Sopenharmony_ci                                  Elf64_Addr    value,
24765042b18Sopenharmony_ci                                  Elf_Xword     size,
24865042b18Sopenharmony_ci                                  unsigned char info,
24965042b18Sopenharmony_ci                                  unsigned char other,
25065042b18Sopenharmony_ci                                  Elf_Half      shndx )
25165042b18Sopenharmony_ci{
25265042b18Sopenharmony_ci    return psymbol->add_symbol( name, value, size, info, other, shndx );
25365042b18Sopenharmony_ci}
25465042b18Sopenharmony_ci
25565042b18Sopenharmony_ciElf_Xword elfio_symbol_arrange_local_symbols(
25665042b18Sopenharmony_ci    psymbol_t psymbol, void ( *func )( Elf_Xword first, Elf_Xword second ) )
25765042b18Sopenharmony_ci{
25865042b18Sopenharmony_ci    return psymbol->arrange_local_symbols( func );
25965042b18Sopenharmony_ci}
26065042b18Sopenharmony_ci
26165042b18Sopenharmony_ci//-----------------------------------------------------------------------------
26265042b18Sopenharmony_ci// relocation
26365042b18Sopenharmony_ci//-----------------------------------------------------------------------------
26465042b18Sopenharmony_ciprelocation_t elfio_relocation_section_accessor_new( pelfio_t   pelfio,
26565042b18Sopenharmony_ci                                                     psection_t psection )
26665042b18Sopenharmony_ci{
26765042b18Sopenharmony_ci    return new ( std::nothrow )
26865042b18Sopenharmony_ci        relocation_section_accessor( *pelfio, psection );
26965042b18Sopenharmony_ci}
27065042b18Sopenharmony_ci
27165042b18Sopenharmony_civoid elfio_relocation_section_accessor_delete( prelocation_t prelocation )
27265042b18Sopenharmony_ci{
27365042b18Sopenharmony_ci    delete prelocation;
27465042b18Sopenharmony_ci}
27565042b18Sopenharmony_ci
27665042b18Sopenharmony_ciElf_Xword elfio_relocation_get_entries_num( prelocation_t prelocation )
27765042b18Sopenharmony_ci{
27865042b18Sopenharmony_ci    return prelocation->get_entries_num();
27965042b18Sopenharmony_ci}
28065042b18Sopenharmony_ci
28165042b18Sopenharmony_cibool elfio_relocation_get_entry( prelocation_t prelocation,
28265042b18Sopenharmony_ci                                 Elf_Xword     index,
28365042b18Sopenharmony_ci                                 Elf64_Addr*   offset,
28465042b18Sopenharmony_ci                                 Elf_Word*     symbol,
28565042b18Sopenharmony_ci                                 Elf_Word*     type,
28665042b18Sopenharmony_ci                                 Elf_Sxword*   addend )
28765042b18Sopenharmony_ci{
28865042b18Sopenharmony_ci    return prelocation->get_entry( index, *offset, *symbol, *type, *addend );
28965042b18Sopenharmony_ci}
29065042b18Sopenharmony_ci
29165042b18Sopenharmony_cibool elfio_relocation_set_entry( prelocation_t prelocation,
29265042b18Sopenharmony_ci                                 Elf_Xword     index,
29365042b18Sopenharmony_ci                                 Elf64_Addr    offset,
29465042b18Sopenharmony_ci                                 Elf_Word      symbol,
29565042b18Sopenharmony_ci                                 Elf_Word      type,
29665042b18Sopenharmony_ci                                 Elf_Sxword    addend )
29765042b18Sopenharmony_ci{
29865042b18Sopenharmony_ci    return prelocation->set_entry( index, offset, symbol, type, addend );
29965042b18Sopenharmony_ci}
30065042b18Sopenharmony_ci
30165042b18Sopenharmony_civoid elfio_relocation_add_entry( prelocation_t prelocation,
30265042b18Sopenharmony_ci                                 Elf64_Addr    offset,
30365042b18Sopenharmony_ci                                 Elf_Word      symbol,
30465042b18Sopenharmony_ci                                 unsigned char type,
30565042b18Sopenharmony_ci                                 Elf_Sxword    addend )
30665042b18Sopenharmony_ci{
30765042b18Sopenharmony_ci    return prelocation->add_entry( offset, symbol, type, addend );
30865042b18Sopenharmony_ci}
30965042b18Sopenharmony_ci
31065042b18Sopenharmony_civoid elfio_relocation_swap_symbols( prelocation_t prelocation,
31165042b18Sopenharmony_ci                                    Elf_Xword     first,
31265042b18Sopenharmony_ci                                    Elf_Xword     second )
31365042b18Sopenharmony_ci{
31465042b18Sopenharmony_ci    prelocation->swap_symbols( first, second );
31565042b18Sopenharmony_ci}
31665042b18Sopenharmony_ci
31765042b18Sopenharmony_ci//-----------------------------------------------------------------------------
31865042b18Sopenharmony_ci// string
31965042b18Sopenharmony_ci//-----------------------------------------------------------------------------
32065042b18Sopenharmony_cipstring_t elfio_string_section_accessor_new( psection_t psection )
32165042b18Sopenharmony_ci{
32265042b18Sopenharmony_ci    return new ( std::nothrow ) string_section_accessor( psection );
32365042b18Sopenharmony_ci}
32465042b18Sopenharmony_ci
32565042b18Sopenharmony_civoid elfio_string_section_accessor_delete( pstring_t pstring )
32665042b18Sopenharmony_ci{
32765042b18Sopenharmony_ci    delete pstring;
32865042b18Sopenharmony_ci}
32965042b18Sopenharmony_ci
33065042b18Sopenharmony_ciconst char* elfio_string_get_string( pstring_t pstring, Elf_Word index )
33165042b18Sopenharmony_ci{
33265042b18Sopenharmony_ci    return pstring->get_string( index );
33365042b18Sopenharmony_ci}
33465042b18Sopenharmony_ci
33565042b18Sopenharmony_ciElf_Word elfio_string_add_string( pstring_t pstring, char* str )
33665042b18Sopenharmony_ci{
33765042b18Sopenharmony_ci    return pstring->add_string( str );
33865042b18Sopenharmony_ci}
33965042b18Sopenharmony_ci
34065042b18Sopenharmony_ci//-----------------------------------------------------------------------------
34165042b18Sopenharmony_ci// note
34265042b18Sopenharmony_ci//-----------------------------------------------------------------------------
34365042b18Sopenharmony_cipnote_t elfio_note_section_accessor_new( pelfio_t pelfio, psection_t psection )
34465042b18Sopenharmony_ci{
34565042b18Sopenharmony_ci    return new ( std::nothrow ) note_section_accessor( *pelfio, psection );
34665042b18Sopenharmony_ci}
34765042b18Sopenharmony_ci
34865042b18Sopenharmony_civoid elfio_note_section_accessor_delete( pnote_t pnote ) { delete pnote; }
34965042b18Sopenharmony_ci
35065042b18Sopenharmony_ciElf_Word elfio_note_get_notes_num( pnote_t pnote )
35165042b18Sopenharmony_ci{
35265042b18Sopenharmony_ci    return pnote->get_notes_num();
35365042b18Sopenharmony_ci}
35465042b18Sopenharmony_ci
35565042b18Sopenharmony_cibool elfio_note_get_note( pnote_t   pnote,
35665042b18Sopenharmony_ci                          Elf_Word  index,
35765042b18Sopenharmony_ci                          Elf_Word* type,
35865042b18Sopenharmony_ci                          char*     name,
35965042b18Sopenharmony_ci                          int       name_len,
36065042b18Sopenharmony_ci                          void**    desc,
36165042b18Sopenharmony_ci                          Elf_Word* descSize )
36265042b18Sopenharmony_ci{
36365042b18Sopenharmony_ci    std::string name_str;
36465042b18Sopenharmony_ci    bool ret = pnote->get_note( index, *type, name_str, *desc, *descSize );
36565042b18Sopenharmony_ci    strncpy( name, name_str.c_str(), (size_t)name_len - 1 );
36665042b18Sopenharmony_ci
36765042b18Sopenharmony_ci    return ret;
36865042b18Sopenharmony_ci}
36965042b18Sopenharmony_ci
37065042b18Sopenharmony_civoid elfio_note_add_note( pnote_t     pnote,
37165042b18Sopenharmony_ci                          Elf_Word    type,
37265042b18Sopenharmony_ci                          const char* name,
37365042b18Sopenharmony_ci                          const void* desc,
37465042b18Sopenharmony_ci                          Elf_Word    descSize )
37565042b18Sopenharmony_ci{
37665042b18Sopenharmony_ci    pnote->add_note( type, name, desc, descSize );
37765042b18Sopenharmony_ci}
37865042b18Sopenharmony_ci
37965042b18Sopenharmony_ci//-----------------------------------------------------------------------------
38065042b18Sopenharmony_ci// modinfo
38165042b18Sopenharmony_ci//-----------------------------------------------------------------------------
38265042b18Sopenharmony_cipmodinfo_t elfio_modinfo_section_accessor_new( psection_t psection )
38365042b18Sopenharmony_ci{
38465042b18Sopenharmony_ci    return new ( std::nothrow ) modinfo_section_accessor( psection );
38565042b18Sopenharmony_ci}
38665042b18Sopenharmony_ci
38765042b18Sopenharmony_civoid elfio_modinfo_section_accessor_delete( pmodinfo_t pmodinfo )
38865042b18Sopenharmony_ci{
38965042b18Sopenharmony_ci    delete pmodinfo;
39065042b18Sopenharmony_ci}
39165042b18Sopenharmony_ci
39265042b18Sopenharmony_ciElf_Word elfio_modinfo_get_attribute_num( pmodinfo_t pmodinfo )
39365042b18Sopenharmony_ci{
39465042b18Sopenharmony_ci    return pmodinfo->get_attribute_num();
39565042b18Sopenharmony_ci}
39665042b18Sopenharmony_ci
39765042b18Sopenharmony_cibool elfio_modinfo_get_attribute( pmodinfo_t pmodinfo,
39865042b18Sopenharmony_ci                                  Elf_Word   no,
39965042b18Sopenharmony_ci                                  char*      field,
40065042b18Sopenharmony_ci                                  int        field_len,
40165042b18Sopenharmony_ci                                  char*      value,
40265042b18Sopenharmony_ci                                  int        value_len )
40365042b18Sopenharmony_ci{
40465042b18Sopenharmony_ci    std::string field_str;
40565042b18Sopenharmony_ci    std::string value_str;
40665042b18Sopenharmony_ci    bool        ret = pmodinfo->get_attribute( no, field_str, value_str );
40765042b18Sopenharmony_ci    strncpy( field, field_str.c_str(), (size_t)field_len - 1 );
40865042b18Sopenharmony_ci    strncpy( value, value_str.c_str(), (size_t)value_len - 1 );
40965042b18Sopenharmony_ci
41065042b18Sopenharmony_ci    return ret;
41165042b18Sopenharmony_ci}
41265042b18Sopenharmony_ci
41365042b18Sopenharmony_cibool elfio_modinfo_get_attribute_by_name( pmodinfo_t pmodinfo,
41465042b18Sopenharmony_ci                                          char*      field_name,
41565042b18Sopenharmony_ci                                          char*      value,
41665042b18Sopenharmony_ci                                          int        value_len )
41765042b18Sopenharmony_ci{
41865042b18Sopenharmony_ci    std::string value_str;
41965042b18Sopenharmony_ci    bool        ret = pmodinfo->get_attribute( value_str, value_str );
42065042b18Sopenharmony_ci    strncpy( value, value_str.c_str(), (size_t)value_len - 1 );
42165042b18Sopenharmony_ci
42265042b18Sopenharmony_ci    return ret;
42365042b18Sopenharmony_ci}
42465042b18Sopenharmony_ci
42565042b18Sopenharmony_ciElf_Word
42665042b18Sopenharmony_cielfio_modinfo_add_attribute( pmodinfo_t pmodinfo, char* field, char* value )
42765042b18Sopenharmony_ci{
42865042b18Sopenharmony_ci    return pmodinfo->add_attribute( field, value );
42965042b18Sopenharmony_ci}
43065042b18Sopenharmony_ci
43165042b18Sopenharmony_ci//-----------------------------------------------------------------------------
43265042b18Sopenharmony_ci// dynamic
43365042b18Sopenharmony_ci//-----------------------------------------------------------------------------
43465042b18Sopenharmony_cipdynamic_t elfio_dynamic_section_accessor_new( pelfio_t   pelfio,
43565042b18Sopenharmony_ci                                               psection_t psection )
43665042b18Sopenharmony_ci{
43765042b18Sopenharmony_ci    return new ( std::nothrow ) dynamic_section_accessor( *pelfio, psection );
43865042b18Sopenharmony_ci}
43965042b18Sopenharmony_ci
44065042b18Sopenharmony_civoid elfio_dynamic_section_accessor_delete( pdynamic_t pdynamic )
44165042b18Sopenharmony_ci{
44265042b18Sopenharmony_ci    delete pdynamic;
44365042b18Sopenharmony_ci}
44465042b18Sopenharmony_ci
44565042b18Sopenharmony_ciElf_Xword elfio_dynamic_get_entries_num( pdynamic_t pdynamic )
44665042b18Sopenharmony_ci{
44765042b18Sopenharmony_ci    return pdynamic->get_entries_num();
44865042b18Sopenharmony_ci}
44965042b18Sopenharmony_ci
45065042b18Sopenharmony_cibool elfio_dynamic_get_entry( pdynamic_t pdynamic,
45165042b18Sopenharmony_ci                              Elf_Xword  index,
45265042b18Sopenharmony_ci                              Elf_Xword* tag,
45365042b18Sopenharmony_ci                              Elf_Xword* value,
45465042b18Sopenharmony_ci                              char*      str,
45565042b18Sopenharmony_ci                              int        str_len )
45665042b18Sopenharmony_ci{
45765042b18Sopenharmony_ci    std::string str_str;
45865042b18Sopenharmony_ci    bool        ret = pdynamic->get_entry( index, *tag, *value, str_str );
45965042b18Sopenharmony_ci    strncpy( str, str_str.c_str(), (size_t)str_len - 1 );
46065042b18Sopenharmony_ci
46165042b18Sopenharmony_ci    return ret;
46265042b18Sopenharmony_ci}
46365042b18Sopenharmony_ci
46465042b18Sopenharmony_civoid elfio_dynamic_add_entry( pdynamic_t pdynamic,
46565042b18Sopenharmony_ci                              Elf_Xword  tag,
46665042b18Sopenharmony_ci                              Elf_Xword  value )
46765042b18Sopenharmony_ci{
46865042b18Sopenharmony_ci    pdynamic->add_entry( tag, value );
46965042b18Sopenharmony_ci}
47065042b18Sopenharmony_ci
47165042b18Sopenharmony_ci//-----------------------------------------------------------------------------
47265042b18Sopenharmony_ci// array
47365042b18Sopenharmony_ci//-----------------------------------------------------------------------------
47465042b18Sopenharmony_ciparray_t elfio_array_section_accessor_new( pelfio_t   pelfio,
47565042b18Sopenharmony_ci                                           psection_t psection )
47665042b18Sopenharmony_ci{
47765042b18Sopenharmony_ci    return new ( std::nothrow )
47865042b18Sopenharmony_ci        array_section_accessor<Elf64_Word>( *pelfio, psection );
47965042b18Sopenharmony_ci}
48065042b18Sopenharmony_ci
48165042b18Sopenharmony_civoid elfio_array_section_accessor_delete( parray_t parray ) { delete parray; }
48265042b18Sopenharmony_ci
48365042b18Sopenharmony_ciElf_Xword elfio_array_get_entries_num( parray_t parray )
48465042b18Sopenharmony_ci{
48565042b18Sopenharmony_ci    return parray->get_entries_num();
48665042b18Sopenharmony_ci}
48765042b18Sopenharmony_ci
48865042b18Sopenharmony_cibool elfio_array_get_entry( parray_t    parray,
48965042b18Sopenharmony_ci                            Elf_Xword   index,
49065042b18Sopenharmony_ci                            Elf64_Addr* paddress )
49165042b18Sopenharmony_ci{
49265042b18Sopenharmony_ci    bool ret = parray->get_entry( index, *paddress );
49365042b18Sopenharmony_ci
49465042b18Sopenharmony_ci    return ret;
49565042b18Sopenharmony_ci}
49665042b18Sopenharmony_ci
49765042b18Sopenharmony_civoid elfio_array_add_entry( parray_t parray, Elf64_Addr address )
49865042b18Sopenharmony_ci{
49965042b18Sopenharmony_ci    parray->add_entry( address );
50065042b18Sopenharmony_ci}
501