Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- unit Unit1;
- {$mode objfpc}{$H+}
- interface
- uses
- Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Windows, JwaPsApi, Process;
- type
- { TForm1 }
- TForm1 = class(TForm)
- Memo: TMemo;
- procedure FormShow(Sender: TObject);
- procedure Inject(pid: cardinal; const DllPath: string);
- private
- { private declarations }
- public
- { public declarations }
- end;
- var
- Form1: TForm1;
- implementation
- {$R *.lfm}
- { TForm1 }
- function GetPathFromPID(const PID: cardinal): string;
- var
- hProcess: THandle;
- path: array[0..MAX_PATH - 1] of char;
- begin
- hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, false, PID);
- if hProcess <> 0 then
- try
- if GetModuleFileNameEx(hProcess, 0, path, MAX_PATH) = 0 then
- RaiseLastOSError;
- result := path;
- finally
- CloseHandle(hProcess)
- end
- else
- RaiseLastOSError;
- end;
- procedure RunShellExecute(const prog: string; params: array of string);
- var
- AProcess: TProcess;
- i: integer;
- begin
- AProcess := TProcess.Create(nil);
- AProcess.Executable:= prog;
- for i := 0 to Length(params) - 1 do
- AProcess.Parameters.Add(params[i]);
- AProcess.Options := AProcess.Options + [poWaitOnExit];
- AProcess.Execute;
- AProcess.Free;
- end;
- procedure TForm1.Inject(pid: cardinal; const DllPath: string);
- label INVALID_PROCESS_HANDLE;
- label FIILE_NOT_FOUND;
- label CANT_ALLOCATE_MEMORY;
- label CANT_WRITE_IN_PROCESS;
- label CANT_CREATE_REMOTE_THREAD;
- label PROCEDURE_END;
- var
- ProccessHandle: THandle;
- pDLLPath: Pointer;
- BytesWritten: SIZE_T;
- ThreadID: cardinal;
- begin
- ProccessHandle := OpenProcess(PROCESS_ALL_ACCESS, false, pid);
- if ProccessHandle = 0 then
- goto INVALID_PROCESS_HANDLE;
- if not FileExists(DllPath) then
- goto FIILE_NOT_FOUND;
- pDLLPath := VirtualAllocEx(ProccessHandle, nil, Length(DLLPath), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
- if not Assigned(pDLLPath) then
- goto CANT_ALLOCATE_MEMORY;
- if not WriteProcessMemory(ProccessHandle, pDLLPath, PChar(DLLPath), Length(DLLPath), BytesWritten) then
- goto CANT_WRITE_IN_PROCESS;
- if CreateRemoteThread(ProccessHandle, nil, 0, GetProcAddress(GetModuleHandle('kernel32.dll'), 'LoadLibraryA'), pDLLPath, 0, ThreadID) = 0 then
- goto CANT_CREATE_REMOTE_THREAD;
- Memo.Lines.Add('Process Successfully Injected');
- goto PROCEDURE_END;
- INVALID_PROCESS_HANDLE:
- Memo.Lines.Add('Invalid Process Handle');
- goto PROCEDURE_END;
- FIILE_NOT_FOUND:
- Memo.Lines.Add(DllPath + ' not found');
- goto PROCEDURE_END;
- CANT_ALLOCATE_MEMORY:
- Memo.Lines.Add('Can''t Allocate Memory');
- goto PROCEDURE_END;
- CANT_WRITE_IN_PROCESS:
- Memo.Lines.Add('Can''t write into Process');
- goto PROCEDURE_END;
- CANT_CREATE_REMOTE_THREAD:
- Memo.Lines.Add('Can''t create Thread in Process');
- goto PROCEDURE_END;
- PROCEDURE_END:
- exit();
- end;
- procedure TForm1.FormShow(Sender: TObject);
- label PROCESS_NOT_FOUND;
- label PROCESS_PATH_NOT_FOUND;
- label CANT_COPY_FILE;
- label CANT_OBFUSCATE_FILE;
- label CANT_DELETE_FILE;
- label ROUTINE_END;
- label ROUTINE_EXIT;
- const
- DESKING_DLL = 'official.menu';
- BUFFER_DLL = 'toInject.dll';
- var
- cpid: cardinal;
- wHandle: cardinal;
- sProcessPath: string;
- sDeskingDllPath: PChar;
- sL: TStringList;
- i: integer;
- begin
- cpid := 0;
- Memo.Lines.Add('Official Injector v1.33.7');
- wHandle := FindWindow('grcWindow', nil);
- if wHandle = 0 then
- goto PROCESS_NOT_FOUND;
- GetWindowThreadProcessID(wHandle, @cpid);
- if cpid = 0 then
- goto PROCESS_NOT_FOUND;
- Memo.Lines.Add('GTA 5 found.');
- sProcessPath := ExtractFilePath(GetPathFromPID(cpid));
- if sProcessPath = '' then
- goto PROCESS_PATH_NOT_FOUND;
- Memo.Lines.Add('Process Path: ' + sProcessPath);
- if FileExists(BUFFER_DLL) and not DeleteFile(BUFFER_DLL) then
- goto CANT_DELETE_FILE;
- sDeskingDllPath := PChar(sProcessPath + DESKING_DLL);
- if FileExists(sDeskingDllPath) and not DeleteFile(sDeskingDllPath) then
- goto CANT_DELETE_FILE;
- if not CopyFile(DESKING_DLL, BUFFER_DLL, false) then
- goto CANT_COPY_FILE;
- //RunShellExecute('upx.exe', ['-' + IntToStr(random(9) + 1), BUFFER_DLL]);
- if not CopyFile(BUFFER_DLL, PChar(sDeskingDllPath), false) then
- goto CANT_COPY_FILE;
- Inject(cpid, sDeskingDllPath);
- goto ROUTINE_EXIT;
- PROCESS_NOT_FOUND:
- Memo.Lines.Add('GTA not found, pls Start GTA before you start the Injector');
- goto ROUTINE_END;
- PROCESS_PATH_NOT_FOUND:
- Memo.Lines.Add('GTA Process Path not found');
- goto ROUTINE_END;
- CANT_COPY_FILE:
- Memo.Lines.Add('Copy Operation failed');
- goto ROUTINE_END;
- CANT_OBFUSCATE_FILE:
- Memo.Lines.Add('made by Mike Rohsoft');
- goto ROUTINE_END;
- CANT_DELETE_FILE:
- Memo.Lines.Add('Delete Operation failed');
- goto ROUTINE_END;
- ROUTINE_END:
- Memo.Lines.Add('Please fix the Issues and restart this App');
- goto ROUTINE_EXIT;
- ROUTINE_EXIT:
- Memo.Lines.Add('Please close this Application');
- sL := TStringList.Create();
- for i := 0 to Memo.Lines.Count -1 do
- sL.Add(Memo.Lines[i]);
- sL.SaveToFile('log.txt');
- sL.Free;
- exit();
- end;
- end.
Advertisement
Add Comment
Please, Sign In to add comment