MikeRohsoft

Untitled

Oct 24th, 2017
336
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Delphi 5.25 KB | None | 0 0
  1. unit Unit1;
  2.  
  3. {$mode objfpc}{$H+}
  4.  
  5. interface
  6.  
  7. uses
  8.   Classes, SysUtils, FileUtil, Forms, Controls, Graphics, Dialogs, StdCtrls, Windows, JwaPsApi, Process;
  9. type
  10.  
  11.   { TForm1 }
  12.  
  13.   TForm1 = class(TForm)
  14.     Memo: TMemo;
  15.     procedure FormShow(Sender: TObject);
  16.     procedure Inject(pid: cardinal; const DllPath: string);
  17.   private
  18.     { private declarations }
  19.   public
  20.     { public declarations }
  21.   end;
  22.  
  23. var
  24.   Form1: TForm1;
  25.  
  26. implementation
  27.  
  28. {$R *.lfm}
  29.  
  30. { TForm1 }
  31.  
  32. function GetPathFromPID(const PID: cardinal): string;
  33. var
  34.   hProcess: THandle;
  35.   path: array[0..MAX_PATH - 1] of char;
  36. begin
  37.   hProcess := OpenProcess(PROCESS_QUERY_INFORMATION or PROCESS_VM_READ, false, PID);
  38.   if hProcess <> 0 then
  39.     try
  40.       if GetModuleFileNameEx(hProcess, 0, path, MAX_PATH) = 0 then
  41.         RaiseLastOSError;
  42.       result := path;
  43.     finally
  44.       CloseHandle(hProcess)
  45.     end
  46.   else
  47.     RaiseLastOSError;
  48. end;
  49.  
  50. procedure RunShellExecute(const prog: string; params: array of string);
  51. var
  52.   AProcess: TProcess;
  53.   i: integer;
  54. begin
  55.   AProcess := TProcess.Create(nil);
  56.   AProcess.Executable:= prog;
  57.   for i := 0 to Length(params) - 1 do
  58.     AProcess.Parameters.Add(params[i]);
  59.   AProcess.Options := AProcess.Options + [poWaitOnExit];
  60.   AProcess.Execute;
  61.   AProcess.Free;
  62. end;
  63.  
  64. procedure TForm1.Inject(pid: cardinal; const DllPath: string);
  65.   label INVALID_PROCESS_HANDLE;
  66.   label FIILE_NOT_FOUND;
  67.   label CANT_ALLOCATE_MEMORY;
  68.   label CANT_WRITE_IN_PROCESS;
  69.   label CANT_CREATE_REMOTE_THREAD;
  70.   label PROCEDURE_END;
  71. var
  72.   ProccessHandle: THandle;
  73.   pDLLPath: Pointer;
  74.   BytesWritten: SIZE_T;
  75.   ThreadID: cardinal;
  76. begin
  77.   ProccessHandle := OpenProcess(PROCESS_ALL_ACCESS, false, pid);
  78.   if ProccessHandle = 0 then
  79.     goto INVALID_PROCESS_HANDLE;
  80.  
  81.   if not FileExists(DllPath) then
  82.     goto FIILE_NOT_FOUND;
  83.  
  84.   pDLLPath := VirtualAllocEx(ProccessHandle, nil, Length(DLLPath), MEM_COMMIT, PAGE_EXECUTE_READWRITE);
  85.   if not Assigned(pDLLPath) then
  86.     goto CANT_ALLOCATE_MEMORY;
  87.  
  88.   if not WriteProcessMemory(ProccessHandle, pDLLPath, PChar(DLLPath), Length(DLLPath), BytesWritten) then
  89.     goto CANT_WRITE_IN_PROCESS;
  90.  
  91.   if CreateRemoteThread(ProccessHandle, nil, 0, GetProcAddress(GetModuleHandle('kernel32.dll'), 'LoadLibraryA'), pDLLPath, 0, ThreadID) = 0 then
  92.     goto CANT_CREATE_REMOTE_THREAD;
  93.  
  94.    Memo.Lines.Add('Process Successfully Injected');
  95.      goto PROCEDURE_END;
  96.  
  97.   INVALID_PROCESS_HANDLE:
  98.     Memo.Lines.Add('Invalid Process Handle');
  99.     goto PROCEDURE_END;
  100.  
  101.   FIILE_NOT_FOUND:
  102.     Memo.Lines.Add(DllPath + ' not found');
  103.     goto PROCEDURE_END;
  104.  
  105.   CANT_ALLOCATE_MEMORY:
  106.     Memo.Lines.Add('Can''t Allocate Memory');
  107.     goto PROCEDURE_END;
  108.  
  109.   CANT_WRITE_IN_PROCESS:
  110.     Memo.Lines.Add('Can''t write into Process');
  111.     goto PROCEDURE_END;
  112.  
  113.   CANT_CREATE_REMOTE_THREAD:
  114.     Memo.Lines.Add('Can''t create Thread in Process');
  115.     goto PROCEDURE_END;
  116.   PROCEDURE_END:
  117.     exit();
  118. end;
  119.  
  120. procedure TForm1.FormShow(Sender: TObject);
  121.   label PROCESS_NOT_FOUND;
  122.   label PROCESS_PATH_NOT_FOUND;
  123.   label CANT_COPY_FILE;
  124.   label CANT_OBFUSCATE_FILE;
  125.   label CANT_DELETE_FILE;
  126.   label ROUTINE_END;
  127.   label ROUTINE_EXIT;
  128. const
  129.   DESKING_DLL = 'official.menu';
  130.   BUFFER_DLL = 'toInject.dll';
  131. var
  132.   cpid: cardinal;
  133.   wHandle: cardinal;
  134.   sProcessPath: string;
  135.   sDeskingDllPath: PChar;
  136.   sL: TStringList;
  137.   i: integer;
  138. begin
  139.   cpid := 0;
  140.   Memo.Lines.Add('Official Injector  v1.33.7');
  141.   wHandle := FindWindow('grcWindow', nil);
  142.   if wHandle = 0 then
  143.     goto PROCESS_NOT_FOUND;
  144.  
  145.   GetWindowThreadProcessID(wHandle, @cpid);
  146.   if cpid = 0 then
  147.     goto PROCESS_NOT_FOUND;
  148.  
  149.   Memo.Lines.Add('GTA 5 found.');
  150.  
  151.   sProcessPath := ExtractFilePath(GetPathFromPID(cpid));
  152.   if sProcessPath = '' then
  153.     goto PROCESS_PATH_NOT_FOUND;
  154.  
  155.   Memo.Lines.Add('Process Path: ' + sProcessPath);
  156.  
  157.   if FileExists(BUFFER_DLL) and not DeleteFile(BUFFER_DLL) then
  158.     goto CANT_DELETE_FILE;
  159.  
  160.   sDeskingDllPath := PChar(sProcessPath + DESKING_DLL);
  161.  
  162.   if FileExists(sDeskingDllPath) and not DeleteFile(sDeskingDllPath) then
  163.     goto CANT_DELETE_FILE;
  164.  
  165.   if not CopyFile(DESKING_DLL, BUFFER_DLL, false) then
  166.     goto CANT_COPY_FILE;
  167.  
  168.   //RunShellExecute('upx.exe', ['-' + IntToStr(random(9) + 1), BUFFER_DLL]);
  169.  
  170.   if not CopyFile(BUFFER_DLL, PChar(sDeskingDllPath), false) then
  171.     goto CANT_COPY_FILE;
  172.  
  173.   Inject(cpid, sDeskingDllPath);
  174.   goto ROUTINE_EXIT;
  175.  
  176.   PROCESS_NOT_FOUND:
  177.     Memo.Lines.Add('GTA not found, pls Start GTA before you start the Injector');
  178.     goto ROUTINE_END;
  179.  
  180.   PROCESS_PATH_NOT_FOUND:
  181.     Memo.Lines.Add('GTA Process Path not found');
  182.     goto ROUTINE_END;
  183.  
  184.   CANT_COPY_FILE:
  185.     Memo.Lines.Add('Copy Operation failed');
  186.     goto ROUTINE_END;
  187.  
  188.   CANT_OBFUSCATE_FILE:
  189.     Memo.Lines.Add('made by Mike Rohsoft');
  190.     goto ROUTINE_END;
  191.  
  192.   CANT_DELETE_FILE:
  193.     Memo.Lines.Add('Delete Operation failed');
  194.     goto ROUTINE_END;
  195.  
  196.   ROUTINE_END:
  197.     Memo.Lines.Add('Please fix the Issues and restart this App');
  198.     goto ROUTINE_EXIT;
  199.  
  200.   ROUTINE_EXIT:
  201.     Memo.Lines.Add('Please close this Application');
  202.     sL := TStringList.Create();
  203.  
  204.     for i := 0 to Memo.Lines.Count -1 do
  205.       sL.Add(Memo.Lines[i]);
  206.  
  207.    sL.SaveToFile('log.txt');
  208.  
  209.    sL.Free;
  210.  
  211.    exit();
  212. end;
  213.  
  214. end.
Advertisement
Add Comment
Please, Sign In to add comment