본문 바로가기
IT-개발,DB

[개발] 델파이 DLL injection

by SB리치퍼슨 2010. 11. 2.

델파이로 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;
반응형

댓글