I been Working on this as i got the source code
wanted to make a dll injector in console format,
i been able to debug until i got 4 errors , couldnt go further from there , as i been having some very little issues with this one, and since i dont have anyone to teach me, i decided to brin it on here for your assistance
Kindly help
where the errors are , i marked them, kindly help
program tryinject;
{$mode objfpc}{$H+}
uses
{$IFDEF UNIX}{$IFDEF UseCThreads}
cthreads,
{$ENDIF}{$ENDIF}
Classes , JwaTlHelp32, Windows
{ you can add units after this };
function InjectDLL (const DLLPath: string; const PID: DWORD): Boolean;
var
hProcess: THandle;
hThread: THandle;
BaseAddress: Pointer;
Size: Cardinal;
ThreadID: DWORD;
begin
Result := False;
OpenProcess(PROCESS_QUERY_INFORMATION or
PROCESS_CREATE_THREAD or
PROCESS_VM_OPERATION or
PROCESS_VM_WRITE,
false, PID);
if (hProcess <> 0) then
begin
BaseAddress := VirtualAllocEx(hProcess, nil, Length(DllPath) + 1, MEM_COMMIT, PAGE_READWRITE );
if BaseAddress <> nil then
begin
WriteProcessMemory(hProcess, BaseAddress, PChar(DllPath), Length(DllPath) + 1, Size);
if Length(DLLPath) + 1 = Size then
begin
hThread := CreateRemoteThread(hProcess, nil, 0, GetProcAddress(LoadLibrary('kernel32.dll'), 'LoadLibraryA' ), BaseAddress, 0, ThreadID);
Result := hThread <> 0;
WaitForSingleObject(hThread, INFINITE);
end;
end;
VirtualFreeEx(hProcess, BaseAddress, 0, MEM_RELEASE);
CloseHandle(hProcess);
end;
end;
function GetProcessIdByName(s : String) : Cardinal;
var
Proc: TPROCESSENTRY32;
hSnap: HWND;
Looper: BOOL;
PID : DWORD;
begin
Proc.dwSize := SizeOf(Proc);
hSnap := CreateToolhelp32Snapshot(TH32CS_SNAPALL, 0);
Looper := Process32First(hSnap, Proc);
while Integer(Looper) <> 0 do
begin
Caption := Proc.szExeFile; //error here
SubItems.Add(IntToStr(Proc.th32ProcessID)); //error here
end;
Looper := Process32Next(hSnap,proc);
CloseHandle(hSnap);
end;
begin
GetProcessIdbyName('Odesk.exe');
if InjectDLL('flash.dll',PID) then //error here, says No PID
WriteLn('Injection SuccessFul!')
else
Writeln('Injection Failed!');
end.