Kod: Tümünü seç
function TForm1.FindProcessByName(exeFileName: string): PPROCESSENTRY32;
var
ContinueLoop: BOOL;
FSnapshotHandle: THandle;
FProcessEntry32: TProcessEntry32;
begin
Result := nil;
FSnapshotHandle := CreateToolhelp32Snapshot(TH32CS_SNAPPROCESS, 0);
FProcessEntry32.dwSize := SizeOf(FProcessEntry32);
ContinueLoop := Process32First(FSnapshotHandle, FProcessEntry32);
while Integer(ContinueLoop) <> 0 do
begin
if ((UpperCase(ExtractFileName(FProcessEntry32.szExeFile)) =
UpperCase(ExeFileName)) or (UpperCase(FProcessEntry32.szExeFile) =
UpperCase(ExeFileName))) then
begin
New(Result);
Result^ := FProcessEntry32;
end;
ContinueLoop := Process32Next(FSnapshotHandle, FProcessEntry32);
end;
CloseHandle(FSnapshotHandle);
end;
Kod: Tümünü seç
function TForm1.InjectDLL(dwPID: DWORD; DLLPath: PWideChar): integer;
var
dwThreadID: Cardinal;
hProc, hThread, hKernel: THandle;
BytesToWrite, BytesWritten: SIZE_T;
pRemoteBuffer, pLoadLibrary: Pointer;
hExitCode:Cardinal;
begin
hProc := OpenProcess(PROCESS_ALL_ACCESS, False, dwPID);
if hProc = 0 then Exit;
try
BytesToWrite := SizeOf(WideChar) * (Length(DLLPath) + 0);
pRemoteBuffer := VirtualAllocEx(hProc, nil, BytesToWrite, MEM_COMMIT, PAGE_READWRITE);
if pRemoteBuffer = nil then
exit(0);
try
if not WriteProcessMemory(hProc, pRemoteBuffer, DLLPath, BytesToWrite, BytesWritten) then
Exit;
hKernel := GetModuleHandle('kernel32.dll');
pLoadLibrary := GetProcAddress(hKernel, 'LoadLibraryW');
hThread := CreateRemoteThread(hProc, nil, 0, pLoadLibrary, pRemoteBuffer, 0, dwThreadID);
try
WaitForSingleObject(hThread, INFINITE);
finally
CloseHandle(hThread);
end;
finally
VirtualFreeEx(hProc, pRemoteBuffer, 0, MEM_RELEASE);
end;
finally
CloseHandle(hProc);
end;
end;
Burada ise bulduğum Process'e DLL imi inject ediyorum
DLL imde CallMsg isminde StdCall mekanizmasına sahip Export edilmiş bir Prosedürüm var.
Benim yapmak istediğim şu örneğin ben "notepad.exe" ye DLL i Inject ettim ve daha sonra "notepad.exe" içinde bulunan DLL in yine o proses de çalışcak sekilde CallMsg methodumu çağırmak istiyorum. Eğer parametreli yapabilirsem yapmak istediğim tam olacak 2 gün dür uğraşıyorum internette aramadığım yer kalmadı ama çalışan bir örnek bulamadım yardımlarınızı bekliyorum.
Saygılar