천객만래 [千客萬來] (It has an interminable succession of visitors)

델파이로 dll injection 하는 예

procedure TForm1.Button1Click(Sender: TObject);
var
aHandle, hProcess , ThreadHandle : THandle;
PID : Integer;
DllName : String;
DllNamePos : Pointer;
BytesWritten , TheadID : DWORD;
begin
DllName := ExtractFilePath(ParamStr(0)) + 'Inject.dll';

PID := 0;
aHandle := FindWindow('notepad', Nil);
if aHandle <> 0 then
GetWindowThreadProcessId(aHandle, @PID);

if PID <> 0 then
begin
hProcess := OpenProcess(PROCESS_ALL_ACCESS, FALSE, PID);
if (hProcess = 0) then exit;

DllNamePos := VirtualAllocEx(hProcess, Nil, 1000, MEM_COMMIT, PAGE_READWRITE);
WriteProcessMemory(hProcess, DllNamePos, Pointer(DllName), Length(DllName), BytesWritten);
ThreadHandle := CreateRemoteThread(hProcess, nil, 0, GetProcAddress(LoadLibrary('kernel32.dll'), 'LoadLibraryA'), DllNamePos, 0, TheadID);
WaitForSingleObject(ThreadHandle ,INFINITE);
VirtualFreeEx(hProcess ,DllNamePos ,0 ,MEM_RELEASE);
CloseHandle(ThreadHandle);
CloseHandle(hProcess);
end;
end;
Posted by SB패밀리