|
|
|
@ -4,6 +4,7 @@
|
|
|
|
|
|
|
|
|
|
#include <algorithm>
|
|
|
|
|
#include <cstdint>
|
|
|
|
|
#include <filesystem>
|
|
|
|
|
#include <fstream>
|
|
|
|
|
#include <functional>
|
|
|
|
|
#include <map>
|
|
|
|
@ -69,20 +70,20 @@ namespace xtils
|
|
|
|
|
|
|
|
|
|
auto open_binary_file( const std::string &file, std::vector< uint8_t > &data ) -> bool
|
|
|
|
|
{
|
|
|
|
|
std::ifstream fstr( file, std::ios::binary );
|
|
|
|
|
auto file_size = std::filesystem::file_size( std::filesystem::path( file ) );
|
|
|
|
|
|
|
|
|
|
if ( !fstr.is_open() )
|
|
|
|
|
if ( !file_size )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
fstr.unsetf( std::ios::skipws );
|
|
|
|
|
fstr.seekg( 0, std::ios::end );
|
|
|
|
|
OFSTRUCT of;
|
|
|
|
|
auto hfile = OpenFile( file.c_str(), &of, NULL );
|
|
|
|
|
|
|
|
|
|
const auto file_size = fstr.tellg();
|
|
|
|
|
if ( ( HANDLE )hfile == INVALID_HANDLE_VALUE )
|
|
|
|
|
return false;
|
|
|
|
|
|
|
|
|
|
fstr.seekg( NULL, std::ios::beg );
|
|
|
|
|
data.reserve( static_cast< uint32_t >( file_size ) );
|
|
|
|
|
data.insert( data.begin(), std::istream_iterator< uint8_t >( fstr ), std::istream_iterator< uint8_t >() );
|
|
|
|
|
return true;
|
|
|
|
|
DWORD bytes_read;
|
|
|
|
|
data.resize( file_size );
|
|
|
|
|
return ReadFile( ( HANDLE )hfile, data.data(), file_size, &bytes_read, nullptr );
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
auto image_base( const char *image_path ) -> std::uintptr_t
|
|
|
|
|