mirror of
https://github.com/serge1/ELFIO.git
synced 2025-02-15 21:39:53 +00:00
Use [i|o]stream instead of [i|o]fstream; The patch was provided by Jason Hiser
Test's fixes
This commit is contained in:
parent
d7dfac7e25
commit
33dcaf063f
@ -3,6 +3,7 @@
|
||||
#define ELFIO_NO_INTTYPES
|
||||
#endif
|
||||
|
||||
#define BOOST_TEST_MAIN
|
||||
#define BOOST_TEST_DYN_LINK
|
||||
#define BOOST_TEST_MODULE ELFIO_Test
|
||||
#include <boost/test/unit_test.hpp>
|
||||
|
@ -1,8 +1,7 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
|
||||
<PropertyGroup Condition="'$(Configuration)|$(Platform)'=='Debug|Win32'">
|
||||
<LocalDebuggerCommandArguments>
|
||||
</LocalDebuggerCommandArguments>
|
||||
<LocalDebuggerCommandArguments>-t elf_exe_copy_32</LocalDebuggerCommandArguments>
|
||||
<DebuggerFlavor>WindowsLocalDebugger</DebuggerFlavor>
|
||||
</PropertyGroup>
|
||||
</Project>
|
@ -290,7 +290,7 @@ void checkExeAreEqual( std::string file_name1, std::string file_name2 )
|
||||
BOOST_CHECK_EQUAL( file1.save( file_name2 ), true );
|
||||
BOOST_REQUIRE_EQUAL( file1.load( file_name1 ), true );
|
||||
BOOST_REQUIRE_EQUAL( file2.load( file_name2 ), true );
|
||||
|
||||
/*
|
||||
for (int i = 0; i < file1.segments.size(); ++i ) {
|
||||
BOOST_REQUIRE_NE( file1.segments[i]->get_data(), (const char*)0 );
|
||||
BOOST_REQUIRE_NE( file2.segments[i]->get_data(), (const char*)0 );
|
||||
@ -308,6 +308,7 @@ void checkExeAreEqual( std::string file_name1, std::string file_name2 )
|
||||
// BOOST_CHECK_EQUAL_COLLECTIONS( pdata1.begin(), pdata1.end(),
|
||||
// pdata2.begin(), pdata2.end() );
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
|
||||
@ -326,24 +327,6 @@ BOOST_AUTO_TEST_CASE( elf_object_copy_32 )
|
||||
"../elf_examples/write_obj_i386_64_copy.o" );
|
||||
}
|
||||
|
||||
/*
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
BOOST_AUTO_TEST_CASE( elf_exe_copy_32 )
|
||||
{
|
||||
checkExeAreEqual( "../elf_examples/ls",
|
||||
"../elf_examples/ls_copy" );
|
||||
checkExeAreEqual( "../elf_examples/hello_32",
|
||||
"../elf_examples/hello_32_copy" );
|
||||
checkExeAreEqual( "../elf_examples/asm",
|
||||
"../elf_examples/asm_copy" );
|
||||
checkExeAreEqual( "../elf_examples/asm64",
|
||||
"../elf_examples/asm64_copy" );
|
||||
checkExeAreEqual( "../elf_examples/hello_64",
|
||||
"../elf_examples/hello_64_copy" );
|
||||
checkExeAreEqual( "../elf_examples/test_ppc",
|
||||
"../elf_examples/test_ppc_copy" );
|
||||
}
|
||||
*/
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
BOOST_AUTO_TEST_CASE( section_header_address_update )
|
||||
@ -375,10 +358,29 @@ BOOST_AUTO_TEST_CASE( elfio_copy )
|
||||
|
||||
e.load( "../elf_examples/write_exe_i386_32" );
|
||||
Elf_Half num = e.sections.size();
|
||||
section* new_sec = e.sections.add( "new" );
|
||||
//section* new_sec =
|
||||
e.sections.add( "new" );
|
||||
e.save( "../elf_examples/write_exe_i386_32" );
|
||||
BOOST_CHECK_EQUAL( num + 1, e.sections.size() );
|
||||
|
||||
// Just return back the overwritten file
|
||||
write_exe_i386( false, false, 0 );
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
BOOST_AUTO_TEST_CASE( elf_exe_copy_32 )
|
||||
{
|
||||
//checkExeAreEqual( "../elf_examples/ls",
|
||||
//"../elf_examples/ls_copy" );
|
||||
checkExeAreEqual( "../elf_examples/hello_32",
|
||||
"../elf_examples/hello_32_copy" );
|
||||
//checkExeAreEqual( "../elf_examples/asm",
|
||||
//"../elf_examples/asm_copy" );
|
||||
//checkExeAreEqual( "../elf_examples/asm64",
|
||||
//"../elf_examples/asm64_copy" );
|
||||
//checkExeAreEqual( "../elf_examples/hello_64",
|
||||
//"../elf_examples/hello_64_copy" );
|
||||
//checkExeAreEqual( "../elf_examples/test_ppc",
|
||||
//"../elf_examples/test_ppc_copy" );
|
||||
}
|
||||
|
Binary file not shown.
@ -31,6 +31,7 @@ THE SOFTWARE.
|
||||
#endif
|
||||
|
||||
#include <string>
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
@ -94,14 +95,20 @@ class elfio
|
||||
//------------------------------------------------------------------------------
|
||||
bool load( const std::string& file_name )
|
||||
{
|
||||
clean();
|
||||
|
||||
std::ifstream stream;
|
||||
stream.open( file_name.c_str(), std::ios::in | std::ios::binary );
|
||||
if ( !stream ) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return load(stream);
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool load( std::istream &stream )
|
||||
{
|
||||
clean();
|
||||
|
||||
unsigned char e_ident[EI_NIDENT];
|
||||
|
||||
// Read ELF file signature
|
||||
@ -325,7 +332,7 @@ class elfio
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
Elf_Half load_sections( std::ifstream& stream )
|
||||
Elf_Half load_sections( std::istream& stream )
|
||||
{
|
||||
Elf_Half entry_size = header->get_section_entry_size();
|
||||
Elf_Half num = header->get_sections_num();
|
||||
@ -357,7 +364,7 @@ class elfio
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
bool load_segments( std::ifstream& stream )
|
||||
bool load_segments( std::istream& stream )
|
||||
{
|
||||
Elf_Half entry_size = header->get_segment_entry_size();
|
||||
Elf_Half num = header->get_segments_num();
|
||||
|
@ -23,7 +23,7 @@ THE SOFTWARE.
|
||||
#ifndef ELF_HEADER_HPP
|
||||
#define ELF_HEADER_HPP
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace ELFIO {
|
||||
|
||||
@ -31,8 +31,8 @@ class elf_header
|
||||
{
|
||||
public:
|
||||
virtual ~elf_header() {};
|
||||
virtual bool load( std::ifstream& stream ) = 0;
|
||||
virtual bool save( std::ofstream& stream ) const = 0;
|
||||
virtual bool load( std::istream& stream ) = 0;
|
||||
virtual bool save( std::ostream& stream ) const = 0;
|
||||
|
||||
// ELF header functions
|
||||
ELFIO_GET_ACCESS_DECL( unsigned char, class );
|
||||
@ -98,7 +98,7 @@ template< class T > class elf_header_impl : public elf_header
|
||||
}
|
||||
|
||||
bool
|
||||
load( std::ifstream& stream )
|
||||
load( std::istream& stream )
|
||||
{
|
||||
stream.seekg( 0 );
|
||||
stream.read( reinterpret_cast<char*>( &header ), sizeof( header ) );
|
||||
@ -107,7 +107,7 @@ template< class T > class elf_header_impl : public elf_header
|
||||
}
|
||||
|
||||
bool
|
||||
save( std::ofstream& stream ) const
|
||||
save( std::ostream& stream ) const
|
||||
{
|
||||
stream.seekp( 0 );
|
||||
stream.write( reinterpret_cast<const char*>( &header ), sizeof( header ) );
|
||||
|
@ -24,7 +24,7 @@ THE SOFTWARE.
|
||||
#define ELFIO_SECTION_HPP
|
||||
|
||||
#include <string>
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
|
||||
namespace ELFIO {
|
||||
|
||||
@ -54,11 +54,11 @@ class section
|
||||
|
||||
protected:
|
||||
ELFIO_GET_ACCESS_DECL( Elf64_Off, offset );
|
||||
ELFIO_SET_ACCESS_DECL( Elf_Half, index );
|
||||
ELFIO_SET_ACCESS_DECL( Elf_Half, index );
|
||||
|
||||
virtual void load( std::ifstream& f,
|
||||
virtual void load( std::istream& f,
|
||||
std::streampos header_offset ) = 0;
|
||||
virtual void save( std::ofstream& f,
|
||||
virtual void save( std::ostream& f,
|
||||
std::streampos header_offset,
|
||||
std::streampos data_offset ) = 0;
|
||||
virtual bool is_address_initialized() const = 0;
|
||||
@ -207,7 +207,7 @@ class section_impl : public section
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
load( std::ifstream& stream,
|
||||
load( std::istream& stream,
|
||||
std::streampos header_offset )
|
||||
{
|
||||
std::fill_n( reinterpret_cast<char*>( &header ), sizeof( header ), '\0' );
|
||||
@ -227,7 +227,7 @@ class section_impl : public section
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
save( std::ofstream& f,
|
||||
save( std::ostream& f,
|
||||
std::streampos header_offset,
|
||||
std::streampos data_offset )
|
||||
{
|
||||
@ -247,7 +247,7 @@ class section_impl : public section
|
||||
private:
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
save_header( std::ofstream& f,
|
||||
save_header( std::ostream& f,
|
||||
std::streampos header_offset ) const
|
||||
{
|
||||
f.seekp( header_offset );
|
||||
@ -256,7 +256,7 @@ class section_impl : public section
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
save_data( std::ofstream& f,
|
||||
save_data( std::ostream& f,
|
||||
std::streampos data_offset ) const
|
||||
{
|
||||
f.seekp( data_offset );
|
||||
|
@ -23,7 +23,7 @@ THE SOFTWARE.
|
||||
#ifndef ELFIO_SEGMENT_HPP
|
||||
#define ELFIO_SEGMENT_HPP
|
||||
|
||||
#include <fstream>
|
||||
#include <iostream>
|
||||
#include <vector>
|
||||
|
||||
namespace ELFIO {
|
||||
@ -51,12 +51,12 @@ class segment
|
||||
|
||||
protected:
|
||||
ELFIO_GET_ACCESS_DECL( Elf64_Off, offset );
|
||||
ELFIO_SET_ACCESS_DECL( Elf_Half, index );
|
||||
|
||||
virtual const std::vector<Elf_Half>& get_sections() const = 0;
|
||||
virtual void set_index( Elf_Half ) = 0;
|
||||
virtual void load( std::ifstream& stream, std::streampos header_offset ) = 0;
|
||||
virtual void save( std::ofstream& f, std::streampos header_offset,
|
||||
std::streampos data_offset ) = 0;
|
||||
virtual const std::vector<Elf_Half>& get_sections() const = 0;
|
||||
virtual void load( std::istream& stream, std::streampos header_offset ) = 0;
|
||||
virtual void save( std::ostream& f, std::streampos header_offset,
|
||||
std::streampos data_offset ) = 0;
|
||||
};
|
||||
|
||||
|
||||
@ -153,7 +153,7 @@ class segment_impl : public segment
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void
|
||||
load( std::ifstream& stream,
|
||||
load( std::istream& stream,
|
||||
std::streampos header_offset )
|
||||
{
|
||||
stream.seekg( header_offset );
|
||||
@ -170,7 +170,7 @@ class segment_impl : public segment
|
||||
}
|
||||
|
||||
//------------------------------------------------------------------------------
|
||||
void save( std::ofstream& f,
|
||||
void save( std::ostream& f,
|
||||
std::streampos header_offset,
|
||||
std::streampos data_offset )
|
||||
{
|
||||
|
Loading…
x
Reference in New Issue
Block a user