|
Cheat Engine The Official Site of Cheat Engine
|
View previous topic :: View next topic |
Author |
Message |
tanjiajun_34 Grandmaster Cheater Reputation: 0
Joined: 16 Feb 2006 Posts: 786 Location: Singapore
|
Posted: Tue Jun 30, 2009 8:42 am Post subject: Injecting dll error |
|
|
I am coding a external application to inject a dll into other process.
Here is my Injectdll code.
Code: |
procedure InjectDLL(DLLLocation:string);
var
Process:THandle;
TempHandle:THandle;
AllocatedRegion:pointer;
Empty:DWORD;
NumberOfBytesWritten:Cardinal;
WName:string;
PName:string;
pid:LongWord;
begin
Pid:=GetProcessID2('MS.exe');
Process:=OpenProcess(PROCESS_ALL_ACCESS,False,Pid);
AllocatedRegion:=VirtualAllocEx(Process,NIL,length(DLLLocation),MEM_COMMIT,PAGE_EXECUTE_READWRITE);
WriteProcessMemory(Process,AllocatedRegion,pchar(DLLLocation),length(DLLLocation),NumberOfBytesWritten);
//if WName='' then
// sleep(750)
//else
while FindWindow('MSClass', nil)=0 do
sleep(10);
TempHandle:=CreateRemoteThread(Process,nil,0,GetProcAddress(GetModuleHandle('kernel32.dll'),'LoadLibraryA'),AllocatedRegion,0,Empty);
WaitForSingleObject(TempHandle,INFINITE);
CloseHandle(TempHandle);
CloseHandle(Process);
end;
|
GetProcessID2 code
Code: |
function GetProcessID2(ProcessName:string):LongWord; //This function gotten from http://www.delphipages.com/threads/thread.cfm?ID=185732&G=185722
var
Handle:THandle;
Process:TProcessEntry32;
GotProcess:Boolean;
begin
Handle:= CreateToolHelp32SnapShot(TH32CS_SNAPALL,0);
Process.dwSize:=SizeOf(Process);
GotProcess := Process32First (Handle,Process);
{$B-}
if GotProcess and (Process.szExeFile<>ProcessName) then
repeat
GotProcess := Process32Next(Handle,Process);
until (not GotProcess) or (Process.szExeFile=ProcessName);
{$B+}
if GotProcess then Result := Process.th32ProcessID
else Result := 0;
CloseHandle(Handle);
end;
|
My button code
Code: |
procedure TForm1.Button1Click(Sender: TObject);
var
path:string;
begin
Path := ExtractFilePath(Application.ExeName)+'abcd.dll';
InjectDll(Path);
end;
|
When I compiled it and press the button to inject, it is not working. Like not injected at all.
|
|
Back to top |
|
|
Kerelmans Advanced Cheater Reputation: 0
Joined: 29 Oct 2007 Posts: 57
|
|
Back to top |
|
|
Stylo Grandmaster Cheater Supreme Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Tue Jun 30, 2009 9:37 am Post subject: |
|
|
you shouldn't open process using PROCESS_ALL_ACCESS Privilege
you should specified the current privileges
PROCESS_VM_WRITE
PROCESS_CREATE_THREAD
PROCESS_VM_READ
i'm not sure about PROCESS_QUERY_INFORMATION and PROCESS_VM_OPERATION but check it out
|
|
Back to top |
|
|
tanjiajun_34 Grandmaster Cheater Reputation: 0
Joined: 16 Feb 2006 Posts: 786 Location: Singapore
|
Posted: Tue Jun 30, 2009 11:22 am Post subject: |
|
|
I tried all at a time...
Code: |
procedure InjectDLL(DLLLocation:string);
var
Process:THandle;
TempHandle:THandle;
AllocatedRegion:pointer;
Empty:DWORD;
NumberOfBytesWritten:Cardinal;
WName:string;
PName:string;
pid:LongWord;
begin
Pid:=GetProcessId('MS.exe');
Process:=OpenProcess(PROCESS_VM_WRITE ,False,Pid);
Process:=OpenProcess(PROCESS_CREATE_THREAD,False,Pid);
Process:=OpenProcess(PROCESS_VM_READ,False,Pid);
Process:=OpenProcess(PROCESS_QUERY_INFORMATION,False,Pid);
Process:=OpenProcess(PROCESS_VM_OPERATION,False,Pid);
AllocatedRegion:=VirtualAllocEx(Process,NIL,length(DLLLocation),MEM_COMMIT,PAGE_EXECUTE_READWRITE);
WriteProcessMemory(Process,AllocatedRegion,pchar(DLLLocation),length(DLLLocation),NumberOfBytesWritten);
//if WName='' then
// sleep(750)
//else
while FindWindow('MSClass', nil)=0 do
sleep(10);
TempHandle:=CreateRemoteThread(Process,nil,0,GetProcAddress(GetModuleHandle('kernel32.dll'),'LoadLibraryA'),AllocatedRegion,0,Empty);
WaitForSingleObject(TempHandle,INFINITE);
CloseHandle(TempHandle);
CloseHandle(Process);
end;
|
Not working. Still no effect.
My program does use read and write process memory. It is worked for other things.
Does that means it is not open process error?
|
|
Back to top |
|
|
Stylo Grandmaster Cheater Supreme Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Tue Jun 30, 2009 12:35 pm Post subject: |
|
|
omg what the hell dude :O
you called openprocess like 5 times and every time you called it replaced the previous handle
you should call it like that:
Code: |
Process := OpenProcess(PROCESS_VM_READ or PROCESS_VM_WRITE or PROCESS_VM_OPERATION or PROCESS_QUERY_INFORMATION or PROCESS_CREATE_THREAD,false,PID);
|
|
|
Back to top |
|
|
dnsi0 I post too much Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Tue Jun 30, 2009 1:14 pm Post subject: |
|
|
Lol. Just do PROCESS_ALL_ACCESS.
Isn't this doomsday's source for his dll injector? Cause the variables match perfectly to his sourcecode that he released a long time ago.
|
|
Back to top |
|
|
Stylo Grandmaster Cheater Supreme Reputation: 3
Joined: 16 May 2007 Posts: 1073 Location: Israel
|
Posted: Tue Jun 30, 2009 1:49 pm Post subject: |
|
|
yea but
Code: |
Windows Server 2003 and Windows XP/2000: The size of the PROCESS_ALL_ACCESS flag increased on Windows Server 2008 and Windows Vista. If an application compiled for Windows Server 2008 and Windows Vista is run on Windows Server 2003 or Windows XP/2000, the PROCESS_ALL_ACCESS flag is too large and the function specifying this flag fails with ERROR_ACCESS_DENIED. To avoid this problem, specify the minimum set of access rights required for the operation. If PROCESS_ALL_ACCESS must be used, set _WIN32_WINNT to the minimum operating system targeted by your application (for example,
|
and he's probably run windows xp on his machine
|
|
Back to top |
|
|
dnsi0 I post too much Reputation: 0
Joined: 04 Jan 2007 Posts: 2674
|
Posted: Tue Jun 30, 2009 2:29 pm Post subject: |
|
|
1qaz wrote: | yea but
Code: |
Windows Server 2003 and Windows XP/2000: The size of the PROCESS_ALL_ACCESS flag increased on Windows Server 2008 and Windows Vista. If an application compiled for Windows Server 2008 and Windows Vista is run on Windows Server 2003 or Windows XP/2000, the PROCESS_ALL_ACCESS flag is too large and the function specifying this flag fails with ERROR_ACCESS_DENIED. To avoid this problem, specify the minimum set of access rights required for the operation. If PROCESS_ALL_ACCESS must be used, set _WIN32_WINNT to the minimum operating system targeted by your application (for example,
|
and he's probably run windows xp on his machine |
Make a code that checks what os you are on.
|
|
Back to top |
|
|
tanjiajun_34 Grandmaster Cheater Reputation: 0
Joined: 16 Feb 2006 Posts: 786 Location: Singapore
|
Posted: Tue Jun 30, 2009 6:08 pm Post subject: |
|
|
I am compiling on a Windows Vista but it does not work on my Vista. Will this be a problem for me?
Code: |
Windows Server 2003 and Windows XP/2000: The size of the PROCESS_ALL_ACCESS flag increased on Windows Server 2008 and Windows Vista. If an application compiled for Windows Server 2008 and Windows Vista is run on Windows Server 2003 or Windows XP/2000, the PROCESS_ALL_ACCESS flag is too large and the function specifying this flag fails with ERROR_ACCESS_DENIED. To avoid this problem, specify the minimum set of access rights required for the operation. If PROCESS_ALL_ACCESS must be used, set _WIN32_WINNT to the minimum operating system targeted by your application (for example, |
|
|
Back to top |
|
|
Anden100 Grandmaster Cheater Reputation: 0
Joined: 20 Apr 2007 Posts: 668
|
Posted: Wed Jul 01, 2009 12:55 am Post subject: |
|
|
Make sure you are running your compiler as adminstrator when you debug, or just launch the injector as admin, not sure if it will work, but worth a try
|
|
Back to top |
|
|
tanjiajun_34 Grandmaster Cheater Reputation: 0
Joined: 16 Feb 2006 Posts: 786 Location: Singapore
|
Posted: Wed Jul 01, 2009 8:49 am Post subject: |
|
|
I am... Still don't works.
|
|
Back to top |
|
|
|
|
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum You cannot attach files in this forum You can download files in this forum
|
|