View previous topic :: View next topic |
Author |
Message |
Game Hacking Dojo Master Cheater
Reputation: 1
Joined: 17 Sep 2023 Posts: 250
|
Posted: Sun Dec 29, 2024 10:33 am Post subject: Get CLI Program Output |
|
|
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 |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8587 Location: 127.0.0.1
|
Posted: Sun Dec 29, 2024 7:18 pm Post subject: |
|
|
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 |
|
 |
Game Hacking Dojo Master Cheater
Reputation: 1
Joined: 17 Sep 2023 Posts: 250
|
Posted: Sun Dec 29, 2024 8:16 pm Post subject: |
|
|
Thank you, that worked! But are you too used to C? Using semicolons in Lua
|
|
Back to top |
|
 |
|