NtCreateProcess
От: kevga  
Дата: 21.11.03 07:33
Оценка:
Столкнулся с проблемой. Вот код:

function test(ProcessNAme:pwidechar):boolean;
var
iosb:IO_STATUS_BLOCK;
oa:OBJECT_ATTRIBUTES;
hFile:THandle;
hProcess:THandle;
hSection:THandle;
NtOpenFile:TNtOpenFile;
NtCreateProcess:TNtCreateProcess;
NtCreateSection:TNtCreateSection;
NtQuerySection:TNtQuerySection;
NtCreateThread:TNtCreateThread;
RtlInitializeContext:TRtlInitializeContext;
NtQueryVirtualMemory:TNtQueryVirtualMemory;
NtQueryInformationProcess:TNtQueryInformationProcess;
sii:SECTION_IMAGE_INFORMATION;
objname:TUNICODE_STRING;
thHandle:THandle;
ClientID:CLIENT_ID;
thContext:_Context;
InitialTeb:INITIAL_TEB;
CONST
FILE_EXECUTE =$0020;
FILE_SYNCHRONOUS_IO_NONALERT =$00000020;
var
hModule:thandle;
RealRead:dword;
pi:TProcessInformation;
begin
result:=false;
ModuleHandle:=GetModuleHandle('ntdll.dll');
if ModuleHandle=0 then exit;
@NtOpenFile:=GetProcAddress(ModuleHandle, 'NtOpenFile');
@NtCreateProcess:=GetProcAddress(ModuleHandle,'NtCreateProcess');
@NtCreateSection:=GetProcAddress(ModuleHandle,'NtCreateSection');
@NtQuerySection:=GetProcAddress(ModuleHandle,'NtQuerySection');
@NtCreateThread:=GetProcAddress(ModuleHandle,'NtCreateThread');
@RtlInitializeContext:=GetProcAddress(ModuleHandle,'RtlInitializeContext');
@NtQueryInformationProcess:=GetProcAddress(ModuleHandle,'NtQueryInformationProcess');
if (@NtOpenFile=nil) or (@NtCreateProcess=nil) or
(@NtCreateSection=nil) or (@NtQuerySection=nil) or (@NtCreateThread=nil) or
(@NtQueryInformationProcess=nil) then exit;
fillchar(oa,SizeOf(oa),#0);
with oa do begin
Length:=sizeof(oa);
ObjectName:=@ObjName;
ObjectName.Length:=lstrlenw(ProcessName) * sizeof (widechar);
ObjectName.MaximumLength:=ObjectName.Length+sizeof (widechar);
ObjectName.Buffer:=ProcessName;
Attributes:=OBJ_CASE_INSENSITIVE;
end;
hFile:=0;
if NtOpenFile(hFile,FILE_EXECUTE or SYNCHRONIZE,@oa,@iosb,FILE_SHARE_READ,FILE_SYNCHRONOUS_IO_NONALERT)<>0 then exit;
oa.ObjectName:=nil;

NtCreateSection(@hSection,SECTION_ALL_ACCESS,@oa,0,PAGE_EXECUTE,$01000000,hFile);
CloseHandle(hFile);
NtQuerySection(hSection, SectionImageInformation,@sii,sizeof(sii),nil);

NtCreateProcess(@hProcess,PROCESS_ALL_ACCESS,@oa,GetCurrentProcess,TRUE,hSection,0,0);

CloseHandle(hSection);
fillchar(thContext,SizeOF(thContext),#0);
fillchar(InitialTEB,SizeOF(InitialTEB),#0);
RtlInitializeContext(hProcess,@thContext,0,sii.EntryPoint,@InitialTEB);
NtCreateThread(@thHandle,THREAD_ALL_ACCESS,@oa,hProcess,@ClientID,@thContext,@InitialTEB,true);
//CsrClientCallServer(&Message, 0, $10000, $28 );
//NtResumeThread( thHandle, 0 );


CloseHandle(hProcess);
end;

1. Только функция RtlInitializeContext возвращает ошибку — я ей передаю незаполненный InitialTEB, как его заполнять — непонятно, думаю что заполнять нужно как-то из структуры SECTION_IMAGE_INFORMATION.
2. Что за Message в CrsClientthread — его расшифровку я тоже не нашел.
 
Подождите ...
Wait...
Пока на собственное сообщение не было ответов, его можно удалить.