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 


Help getting standalone exe trainer to open correct process.

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Tustart123
How do I cheat?
Reputation: 0

Joined: 21 Mar 2012
Posts: 5

PostPosted: Wed Mar 21, 2012 9:53 am    Post subject: Help getting standalone exe trainer to open correct process. Reply with quote

Hey,

I have my basic standalone exe trainer written. I have done some debugging and am fairly sure the issue is it attaches to the wrong version of a duplicate process.

The process is always in sequential order in the list.
abc.exe
abc.exe

It is always the one on top. However, autoattach and openprocess both open the bottom version of the process.

I want the program to run as a standalone and I believe it has to attach or open that process.

Does anybody have any suggestions on how I can accomplish getting the lua script to select the appropriate process or even giving the user a list displaying the PIDs and have them select the PID or type in the correct PID and submit it for the trainer.exe for attachment?
Back to top
View user's profile Send private message
Dark Byte
Site Admin
Reputation: 457

Joined: 09 May 2003
Posts: 25262
Location: The netherlands

PostPosted: Wed Mar 21, 2012 11:57 am    Post subject: Reply with quote

there is currently no processlist, it always picks the newest process when using processname based opening

I do have on suggestion, but it's not an easy one:
in lua execute the "tasklist" program and read the output. Then get the processid and use that to open the process

_________________
Do not ask me about online cheats. I don't know any and wont help finding them.

Like my help? Join me on Patreon so i can keep helping
Back to top
View user's profile Send private message MSN Messenger
atom0s
Moderator
Reputation: 198

Joined: 25 Jan 2006
Posts: 8516
Location: 127.0.0.1

PostPosted: Fri Mar 23, 2012 8:11 pm    Post subject: Reply with quote

Using what DB said, you can parse TASKLIST results in CSV format pretty easily in Lua. You can invoke the process using:

Code:
local target = "abc.exe";
local f = io.popen( string.format( "TASKLIST /FI \"IMAGENAME eq %s\" /FO csv", target ) );
assert( f, "Failed to obtain results from TASKLIST.exe!" );

-- Do work here..

f:close();


You can then parse each line returned like this:

Code:

    for x in f:lines() do
        -- Strip the header line so we don't try to read it as a process..
        local input = string.gsub( x, "(.*),\"Mem Usage\"", '' );
        if string.len( input ) > 0 then
            local parts = input:split( "[^,]+" );
            print( #parts );
            print( parts[1] ); -- prints the process name
            print( parts[2] ); -- prints the process id
        end
    end


Using the string:split function from:
http://lua-users.org/wiki/SplitJoin

Code:

string.split = function(str, pattern)
  pattern = pattern or "[^%s]+"
  if pattern:len() == 0 then pattern = "[^%s]+" end
  local parts = {__index = table.insert}
  setmetatable(parts, parts)
  str:gsub(pattern, parts)
  setmetatable(parts, nil)
  parts.__index = nil
  return parts
end

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Tustart123
How do I cheat?
Reputation: 0

Joined: 21 Mar 2012
Posts: 5

PostPosted: Fri Mar 30, 2012 12:32 am    Post subject: Reply with quote

Wiccaan wrote:
Using what DB said, you can parse TASKLIST results in CSV format pretty easily in Lua. You can invoke the process using:

Code:
local target = "abc.exe";
local f = io.popen( string.format( "TASKLIST /FI \"IMAGENAME eq %s\" /FO csv", target ) );
assert( f, "Failed to obtain results from TASKLIST.exe!" );

-- Do work here..

f:close();


You can then parse each line returned like this:

Code:

    for x in f:lines() do
        -- Strip the header line so we don't try to read it as a process..
        local input = string.gsub( x, "(.*),\"Mem Usage\"", '' );
        if string.len( input ) > 0 then
            local parts = input:split( "[^,]+" );
            print( #parts );
            print( parts[1] ); -- prints the process name
            print( parts[2] ); -- prints the process id
        end
    end


Using the string:split function from:

Code:

string.split = function(str, pattern)
  pattern = pattern or "[^%s]+"
  if pattern:len() == 0 then pattern = "[^%s]+" end
  local parts = {__index = table.insert}
  setmetatable(parts, parts)
  str:gsub(pattern, parts)
  setmetatable(parts, nil)
  parts.__index = nil
  return parts
end


Thanks so much both of you.

I got it working perfectly.

It did take me awhile to figure out why your script copied exactly was not working and it's because your split function is at the bottom.

Simply move the string.split function to the top of the code so it is executed before the other two pieces of code and it works perfectly. Probably not an issue for the vast majority of you out there but it did take me a little time to figure out.

Thank you so much, again.
Back to top
View user's profile Send private message
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