Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


How to get own trainer process id?

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Sat Jun 07, 2014 7:45 pm    Post subject: How to get own trainer process id? Reply with quote

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
View user's profile Send private message Visit poster's website
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 893

PostPosted: Sat Jun 07, 2014 9:14 pm    Post subject: Re: How to get own trainer process id? Reply with quote

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
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Sat Jun 07, 2014 10:30 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 893

PostPosted: Sat Jun 07, 2014 11:23 pm    Post subject: Reply with quote

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
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Sat Jun 07, 2014 11:31 pm    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 893

PostPosted: Sun Jun 08, 2014 1:39 am    Post subject: Reply with quote

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
View user's profile Send private message
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Sun Jun 08, 2014 7:26 am    Post subject: Reply with quote

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
View user's profile Send private message Visit poster's website
justa_dude
Grandmaster Cheater
Reputation: 23

Joined: 29 Jun 2010
Posts: 893

PostPosted: Sun Jun 08, 2014 2:31 pm    Post subject: Reply with quote

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
View user's profile Send private message
mgr.inz.Player
I post too much
Reputation: 222

Joined: 07 Nov 2008
Posts: 4438
Location: W kraju nad Wisla. UTC+01:00

PostPosted: Sun Jun 08, 2014 4:17 pm    Post subject: Reply with quote

DaSpamer wrote:
you had typo (showMessage not ShowMessage)


In CE6.3 all class methods and CE registered native functions start with lowercase letter. All class properties starts with capital letter.


In future CE6.4 first letter can be whatever you want, lower case or upper case.


https://code.google.com/p/cheat-engine/source/browse/trunk/Cheat+Engine/LuaClass.pas?spec=svn2406&%72=2406#328

https://code.google.com/p/cheat-engine/source/browse/trunk/Cheat+Engine/LuaClass.pas?spec=svn2406&%72=2406#346

https://code.google.com/p/cheat-engine/source/browse/trunk/Cheat+Engine/LuaHandler.pas?spec=svn2549&%72=2549#123


 

_________________
Back to top
View user's profile Send private message MSN Messenger
daspamer
Grandmaster Cheater Supreme
Reputation: 54

Joined: 13 Sep 2011
Posts: 1588

PostPosted: Mon Jun 09, 2014 7:23 am    Post subject: Reply with quote

Great news.
_________________
I'm rusty and getting older, help me re-learn lua.
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
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


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites