| View previous topic :: View next topic |
| Author |
Message |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Sat Jun 07, 2014 7:45 pm Post subject: How to get own trainer process id? |
|
|
Hey,
If you make a trainer, and for some reason user decides to change it's name, how to obtain it's process id or process name?
_________________
I'm rusty and getting older, help me re-learn lua. |
|
| Back to top |
|
 |
justa_dude Grandmaster Cheater
Reputation: 23
Joined: 29 Jun 2010 Posts: 893
|
Posted: Sat Jun 07, 2014 9:14 pm Post subject: Re: How to get own trainer process id? |
|
|
| DaSpamer wrote: | Hey,
If you make a trainer, and for some reason user decides to change it's name, how to obtain it's process id or process name? |
There's a WinAPI call, GetCurrentProcessId, that would work. Since it's in the kernel, it should always be present.
_________________
A nagy kapu mellett, mindig van egy kis kapu.
----------------------
Come on... |
|
| Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Sat Jun 07, 2014 10:30 pm Post subject: |
|
|
Thanks.
This works great.
| Code: | alloc(data, 16)
label(pid)
registersymbol(data)
registersymbol(pid)
data:
call GetCurrentProcessId
mov [pid],eax
ret
pid:
dd 0
createthread(data) |
But I prefer via LUA.
_________________
I'm rusty and getting older, help me re-learn lua. |
|
| Back to top |
|
 |
justa_dude Grandmaster Cheater
Reputation: 23
Joined: 29 Jun 2010 Posts: 893
|
Posted: Sat Jun 07, 2014 11:23 pm Post subject: |
|
|
I believe that CE exports a TrainerOrigin variable to Lua that contains argv0. You can probably call getProcessIDFromProcessName with the result after possibly trimming the path (I find the original solution to be much more elegant, though).
_________________
A nagy kapu mellett, mindig van egy kis kapu.
----------------------
Come on... |
|
| Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Sat Jun 07, 2014 11:31 pm Post subject: |
|
|
| justa_dude wrote: | | I believe that CE exports a TrainerOrigin variable to Lua that contains argv0. You can probably call getProcessIDFromProcessName with the result after possibly trimming the path (I find the original solution to be much more elegant, though). |
I'm using older version of C.E,
The above script works only after attaching to a process.
TrainerOrigin returns only path.
I could find the trainer with lua string class, but if there's any other binaries (in the same DIR) it'll be a problem.
Came up with some solution..
but will have to 'force' some delays, because it takes about few ms for self_pid to update and be readable.
| Code: | openProcess(getForegroundProcess()); -- Gets us temporary valid process, if you're using C.E 6.2, if not this is not required.
reinitializeSymbolhandler();
autoAssemble("alloc(data, 24)\nlabel(self_pid)\nregistersymbol(data)\nregistersymbol(self_pid)\n\ndata:\ncall GetCurrentProcessId\nmov [self_pid],eax\nret\n\nself_pid:\ndd 0\n\ncreatethread(data)",true);
local timer = createTimer(getMainForm(), false);
local trainer_pid
timer.onTimer = function (sender) trainer_pid = readIntegerLocal("self_pid"); if (trainer_pid and trainer_pid > 0) then print('Trainer PID is ' .. trainer_pid); sender.destroy(); end; end;
timer.Interval = 100;
timer.Enabled = true; |
_________________
I'm rusty and getting older, help me re-learn lua. |
|
| Back to top |
|
 |
justa_dude Grandmaster Cheater
Reputation: 23
Joined: 29 Jun 2010 Posts: 893
|
Posted: Sun Jun 08, 2014 1:39 am Post subject: |
|
|
Just out of curiosity, what does this give you?
| Code: |
a = readStringLocal(readIntegerLocal(readIntegerLocal("KERNELBASE.GetCommandLineW+1")),666,true) --x86
if not a then
a = readStringLocal(readIntegerLocal(string.format("KERNELBASE.GetCommandLineW+7+%X",readIntegerLocal("KERNELBASE.GetCommandLineW+3"))),666,true) --x64
end
ShowMessage(string.format("%s (pid:%d)",a,getProcessIDFromProcessName(string.match(string.lower(a), ".*\\(.*exe)"))))
|
_________________
A nagy kapu mellett, mindig van egy kis kapu.
----------------------
Come on... |
|
| Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Sun Jun 08, 2014 7:26 am Post subject: |
|
|
| justa_dude wrote: | Just out of curiosity, what does this give you?
| Code: |
a = readStringLocal(readIntegerLocal(readIntegerLocal("KERNELBASE.GetCommandLineW+1")),666,true) --x86
if not a then
a = readStringLocal(readIntegerLocal(string.format("KERNELBASE.GetCommandLineW+7+%X",readIntegerLocal("KERNELBASE.GetCommandLineW+3"))),666,true) --x64
end
ShowMessage(string.format("%s (pid:%d)",a,getProcessIDFromProcessName(string.match(string.lower(a), ".*\\(.*exe)"))))
|
|
Works perfectly.
Thanks.
p.s
you had typo (showMessage not ShowMessage);
_________________
I'm rusty and getting older, help me re-learn lua. |
|
| Back to top |
|
 |
justa_dude Grandmaster Cheater
Reputation: 23
Joined: 29 Jun 2010 Posts: 893
|
Posted: Sun Jun 08, 2014 2:31 pm Post subject: |
|
|
| DaSpamer wrote: |
p.s
you had typo (showMessage not ShowMessage); |
That's no typo.
_________________
A nagy kapu mellett, mindig van egy kis kapu.
----------------------
Come on... |
|
| Back to top |
|
 |
mgr.inz.Player I post too much
Reputation: 222
Joined: 07 Nov 2008 Posts: 4438 Location: W kraju nad Wisla. UTC+01:00
|
|
| Back to top |
|
 |
daspamer Grandmaster Cheater Supreme
Reputation: 54
Joined: 13 Sep 2011 Posts: 1588
|
Posted: Mon Jun 09, 2014 7:23 am Post subject: |
|
|
Great news.
_________________
I'm rusty and getting older, help me re-learn lua. |
|
| Back to top |
|
 |
|