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 


Get CLI Program Output

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> Cheat Engine Lua Scripting
View previous topic :: View next topic  
Author Message
Game Hacking Dojo
Master Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 250

PostPosted: Sun Dec 29, 2024 10:33 am    Post subject: Get CLI Program Output Reply with quote

I'm trying to find a way to capture the output of a program using Lua.
I've used this to return the output, and it worked for something like "Pause, Echo" but if I use a CLI program, it fails to return anything at the variable output.
Link to SigCheck (SysInternals): https://download.sysinternals.com/files/Sigcheck.zip

Code:
-- this works
local command = "pause"
local handle = assert(io.popen(command , 'r'))
local output = assert(handle:read('*a'))
handle:close()

print("Command = "..command)
print("Output = "..output)


Code:
-- this outputs nil
local file_path = [["C:\Program Files\WindowsApps\Microsoft.WindowsCalculator_11.2411.1.0_x64__8wekyb3d8bbwe\CalculatorApp.exe"]]
local sigcheck_path = [["C:\Program Files\SysInternals\sigcheck64.exe"]]
local command = sigcheck_path.." -nobanner -a "..file_path
local handle = assert(io.popen(command , 'r'))
local output = assert(handle:read('*a'))
handle:close()

print("Command = "..command)
print("Output = "..output)


Obviously, I am trying to collect version information of a PE file. I have tried using pe-parser.lua but that doesn't parse the resources section. If you have a better approach let me know. Thank you in advance
Back to top
View user's profile Send private message Visit poster's website
atom0s
Moderator
Reputation: 205

Joined: 25 Jan 2006
Posts: 8587
Location: 127.0.0.1

PostPosted: Sun Dec 29, 2024 7:18 pm    Post subject: Reply with quote

The issue you are having is due to your file paths having spaces in them and not properly building the command being passed to popen due to it. Windows' command line is insanely anal and dumb about how it processes paths forwarded to it and must be properly quoted for the whole command and additional paths within the command that have spaces.

So you would need to do something like this:

Code:

local file_path = 'C:\\Tools\\path with a space\\sigcheck.exe';
local tool_path = 'C:\\Tools\\path with a space\\sigcheck.exe';

local command = string.format([==[""%s" -nobanner -a "%s""]==], tool_path, file_path);

local handle = io.popen(command);
if (handle == nil) then
    error('failed to open');
else
    print(handle:read('*a'));
    handle:close();
end

_________________
- Retired.
Back to top
View user's profile Send private message Visit poster's website
Game Hacking Dojo
Master Cheater
Reputation: 1

Joined: 17 Sep 2023
Posts: 250

PostPosted: Sun Dec 29, 2024 8:16 pm    Post subject: Reply with quote

Thank you, that worked! But are you too used to C? Using semicolons in 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