MCPcopy Create free account
hub / github.com/DarthTon/Xenos / LoadImageFile

Method LoadImageFile

src/Routines.cpp:281–330  ·  view source on GitHub ↗

Load selected image and do some validation Full qualified image path Error code

Source from the content-addressed store, hash-verified

279/// <param name="path">Full qualified image path</param>
280/// <returns>Error code </returns>
281DWORD MainDlg::LoadImageFile( const std::wstring& path )
282{
283 std::shared_ptr<blackbone::pe::PEImage> img( new blackbone::pe::PEImage );
284 blackbone::pe::vecExports exports;
285
286 // Check if image is already in the list
287 if (std::find_if( _images.begin(), _images.end(),
288 [&path]( std::shared_ptr<blackbone::pe::PEImage>& img ) { return path == img->path(); } ) != _images.end())
289 {
290 Message::ShowInfo( _hwnd, L"Image '" + path + L"' is already in the list" );
291 return ERROR_ALREADY_EXISTS;
292 }
293
294 // Check if image is a PE file
295 if (!NT_SUCCESS( img->Load( path ) ))
296 {
297 std::wstring errstr = std::wstring( L"File \"" ) + path + L"\" is not a valid PE image";
298 Message::ShowError( _hwnd, errstr.c_str() );
299
300 img->Release();
301 return ERROR_INVALID_IMAGE_HASH;
302 }
303
304 // In case of pure IL, list all methods
305 if (img->pureIL() && img->net().Init( path ))
306 {
307 blackbone::ImageNET::mapMethodRVA methods;
308 img->net().Parse( &methods );
309
310 for (auto& entry : methods)
311 {
312 std::wstring name = entry.first.first + L"." + entry.first.second;
313 exports.push_back( blackbone::pe::ExportData( blackbone::Utils::WstringToAnsi( name ), 0 ) );
314 }
315 }
316 // Simple exports otherwise
317 else
318 img->GetExports( exports );
319
320
321 // Add to internal lists
322 AddToModuleList( img );
323 _exports.emplace_back( exports );
324
325 if (_procList.selection() != -1)
326 _inject.enable();
327
328 img->Release( true );
329 return ERROR_SUCCESS;
330}
331
332/// <summary>
333/// Add module to module list

Callers

nothing calls this directly

Calls 5

beginMethod · 0.80
endMethod · 0.80
LoadMethod · 0.80
enableMethod · 0.80
selectionMethod · 0.45

Tested by

no test coverage detected