Call initialization routine Injection context Target module Context thread of execution Error code
| 744 | /// <param name="pThread">Context thread of execution</param> |
| 745 | /// <returns>Error code</returns> |
| 746 | NTSTATUS InjectionCore::CallInitRoutine( |
| 747 | InjectContext& context, |
| 748 | const blackbone::pe::PEImage& img, |
| 749 | blackbone::ModuleDataPtr mod, |
| 750 | uint64_t exportRVA, |
| 751 | blackbone::ThreadPtr pThread /*= nullptr*/ |
| 752 | ) |
| 753 | { |
| 754 | // Call init for native image |
| 755 | if (!context.cfg.initRoutine.empty() && !img.pureIL() && context.cfg.injectMode < Kernel_Thread) |
| 756 | { |
| 757 | auto fnPtr = mod->baseAddress + exportRVA; |
| 758 | |
| 759 | xlog::Normal( "Calling initialization routine for image '%ls'", img.path().c_str() ); |
| 760 | |
| 761 | // Create new thread |
| 762 | if (pThread == nullptr) |
| 763 | { |
| 764 | auto argMem = _process.memory().Allocate( 0x1000, PAGE_READWRITE ); |
| 765 | if (!argMem) |
| 766 | return argMem.status; |
| 767 | |
| 768 | argMem->Write( 0, context.cfg.initArgs.length() * sizeof( wchar_t ) + 2, context.cfg.initArgs.c_str() ); |
| 769 | auto status = _process.remote().ExecDirect( fnPtr, argMem->ptr() ); |
| 770 | |
| 771 | xlog::Normal( "Initialization routine returned 0x%X", status ); |
| 772 | } |
| 773 | // Execute in existing thread |
| 774 | else |
| 775 | { |
| 776 | blackbone::RemoteFunction<fnInitRoutine> pfn( _process, fnPtr ); |
| 777 | auto status = pfn.Call( context.cfg.initArgs.c_str(), pThread ); |
| 778 | |
| 779 | xlog::Normal( "Initialization routine returned 0x%X", status ); |
| 780 | } |
| 781 | } |
| 782 | |
| 783 | return STATUS_SUCCESS; |
| 784 | } |
| 785 |