Notice: This forum has been recovered from an old backup, so some content, links, and dates may be outdated. The forum is currently read-only while we restore sign-in and registration functionality. Details
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
If you find this forum valuable and would like to help keep it online, donations to help cover hosting and domain costs are greatly appreciated, but never expected. You can support the forum through Buy Me a Coffee or Ko-fi. Thank you for helping preserve the EventGhost community.
Command line payloads
Command line payloads
Hi.
I am having trouble creating a shortcut with more than one payload. I'm not sure if what I'm experiencing is a bug, or intended behaviour though.
Here's what I'm trying to do. I have a short cut, thus:
"...EventGhost.exe" -e EventName PayloadOne PayloadTwo
I would expect the event to show as:
Main.EventName u"PayloadOne" u"PayloadTwo"
However the event is appearing as:
Payload2.Eventname u"PayloadOne"
If that is indeed intended behaviour, how can I get something similar to what I'm expecting?
Thanks!
I am having trouble creating a shortcut with more than one payload. I'm not sure if what I'm experiencing is a bug, or intended behaviour though.
Here's what I'm trying to do. I have a short cut, thus:
"...EventGhost.exe" -e EventName PayloadOne PayloadTwo
I would expect the event to show as:
Main.EventName u"PayloadOne" u"PayloadTwo"
However the event is appearing as:
Payload2.Eventname u"PayloadOne"
If that is indeed intended behaviour, how can I get something similar to what I'm expecting?
Thanks!
Re: Command line payloads
Just guessing: you are using EG 0.5? Seems the CLI option is broken.
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Command line payloads
wrap the payload values in double quotes.
eventghost -event Some.Event.Name "Payload1 Payload2"
events that are sent in from the cli have always had a payload that is a string. so if you want to make it easy to split the payload values you would format the CLI options like so
eventghost -event Some.Event.Name "['payload string 1', 'payload string 2']"
you would then add a script to the top of you macro to convert the payload and each payload item can be access vy specifying it's index after it.
eventghost -event Some.Event.Name "Payload1 Payload2"
events that are sent in from the cli have always had a payload that is a string. so if you want to make it easy to split the payload values you would format the CLI options like so
eventghost -event Some.Event.Name "['payload string 1', 'payload string 2']"
you would then add a script to the top of you macro to convert the payload and each payload item can be access vy specifying it's index after it.
Code: Select all
eg.event.payload = eval(eg.event.payload)
Re: Command line payloads
A fix for the payload problem will be in the next pre-/release. If you want to try: WIP-2017.12.26-15.40.37_Setup
Re: Command line payloads
Hi,kgschlosser wrote: Mon Dec 11, 2017 12:07 am wrap the payload values in double quotes.
eventghost -event Some.Event.Name "Payload1 Payload2"
events that are sent in from the cli have always had a payload that is a string. so if you want to make it easy to split the payload values you would format the CLI options like so
eventghost -event Some.Event.Name "['payload string 1', 'payload string 2']"
I think there is a character that is not handled in the event or payload, the equal sign ' = ' just try this to reproduce the error :
eventghost -event Some.Event.Name "a=b"
or
eventghost -event Some.Event.a=b
Code: Select all
16:23:23 Traceback (most recent call last):
16:23:23 File "C:\Program Files (x86)\EventGhost\eg\NamedPipe.py", line 291, in run
16:23:23 data
16:23:23 NamedPipeDataError: Pipe 89: Data not allowed: (u'Some.Event.Name', [u'a=b'])- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Command line payloads
There are a couple of possible ways to get it to work. What happens is anything that is passed through the named pipe gets evaluated. when you use any of the command line switches when EG is already running it creates a second running copy of EG. and this second copy connects to the pipe and sends data through it. the only thing that can be sent through the pipe is text. so in order to make the named pipe in a manner that would expose EventGhosts API without allowing malicious code is to not allow the setting of variables. which would be
the = is how you define a variable.
Now. you could try this and see if it works.
In your Autostart create a python script action.
in that action put this code
you can either restart EG or simply run the script
you will want to use one of the 2 command line statements below. I cannot remember how i set the pipe up
and if that does not work. you can give this one a run.
python script
command line
the reason why this is done this way is because in order for things to get set inside of EG you have to have put in helper functions before they will work. so things cannot get done without you knowing about it. You have to make it so that it is allowed. EG has a huge amount of power. And someone could grab passwords or destroy data using it. so we do not want to allow anything to inject malicious code.
Code: Select all
a = b
Now. you could try this and see if it works.
In your Autostart create a python script action.
in that action put this code
Code: Select all
def cli_trigger_event():
return 'a=b'
eg.globals.cli_trigger_event = cli_trigger_event
you will want to use one of the 2 command line statements below. I cannot remember how i set the pipe up
Code: Select all
eventghost -event Some.Event "eg.globals.cli_trigger_event()"
Code: Select all
eventghost -event Some.Event "eg.globals.cli_trigger_event"
python script
Code: Select all
class CLITriggerEvent:
@property
def event(self):
return 'a=b'
eg.globals.cli_trigger_event = CLITriggerEvent()
Code: Select all
eventghost -event Some.Event "eg.globals.cli_trigger_event.event"
the reason why this is done this way is because in order for things to get set inside of EG you have to have put in helper functions before they will work. so things cannot get done without you knowing about it. You have to make it so that it is allowed. EG has a huge amount of power. And someone could grab passwords or destroy data using it. so we do not want to allow anything to inject malicious code.
Re: Command line payloads
ok, thanks for your help. I've tried both ways and could get anything out of it, or maybe I didn't understand what it was supposed to do.
Anyway, as you may have understood the example "a = b" was just... an example to help you reproduce the error
, I don't need to pass or set any variables through the command line, all I'm trying to do is pass plain text that unfortunately contains the equal sign. Here's an example of the type of data that needs to be passed as payload :
This data comes from another program and is called with a variable, I can't control it nor modify it, I just want it to appear in EG as is, without any interpretation of the equal sign, is there a way to pass data in plain text without parsing it or doing any actions with it ?
this is how I call it :
eventghost -e SomeEvent "{my_program_variable}"
and it is interpreted as (as you can see it contains the = sign) :
eventghost -e SomeEvent "ath0: STA 00:00:e7:0d:4b:00 DRIVER: Sead AUTH addr=00:00:5e:66:bd:00"
and it should give me this in EG (but it doesn't because of the equal sign) :
Main.SomeEvent [u'ath0: STA 00:00:e7:0d:4b:00 DRIVER: Sead AUTH addr=00:00:5e:66:bd:00']
I understand the security matter that is involved with the equal sign, maybe if we wrap the payload with some special characters we would be able to tell EG to consider this data as plain text and not interpret anything of its content ? I'm sure there's something to do to come to it.
Anyway, as you may have understood the example "a = b" was just... an example to help you reproduce the error
Code: Select all
ath0: STA 00:00:e7:0d:4b:00 DRIVER: Sead AUTH addr=00:00:5e:66:bd:00this is how I call it :
eventghost -e SomeEvent "{my_program_variable}"
and it is interpreted as (as you can see it contains the = sign) :
eventghost -e SomeEvent "ath0: STA 00:00:e7:0d:4b:00 DRIVER: Sead AUTH addr=00:00:5e:66:bd:00"
and it should give me this in EG (but it doesn't because of the equal sign) :
Main.SomeEvent [u'ath0: STA 00:00:e7:0d:4b:00 DRIVER: Sead AUTH addr=00:00:5e:66:bd:00']
I understand the security matter that is involved with the equal sign, maybe if we wrap the payload with some special characters we would be able to tell EG to consider this data as plain text and not interpret anything of its content ? I'm sure there's something to do to come to it.
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Command line payloads
OK this works 100%
I know you are going to love me for this.
make a batch file and put the code below into it.
and simply change the program you are using to call eventghost have it cal the batch file instead like so..
trigger_event.bat "Some.Event" "Payload=Payload"
with or without quotes tho if the passed parameter has a space in it you will want the double quotes.
This is going to replace the = with a :
drop the batch file into you eventghost directory. if you do not want it there then you will have to add a full path to the call eventghost line.
you do not need to use the -event cli switch it is built into this code.
I know you are going to love me for this.
make a batch file and put the code below into it.
and simply change the program you are using to call eventghost have it cal the batch file instead like so..
trigger_event.bat "Some.Event" "Payload=Payload"
with or without quotes tho if the passed parameter has a space in it you will want the double quotes.
This is going to replace the = with a :
drop the batch file into you eventghost directory. if you do not want it there then you will have to add a full path to the call eventghost line.
you do not need to use the -event cli switch it is built into this code.
Code: Select all
@echo off&setlocal enabledelayedexpansion
set event=%1
set payload=%2
for /f "useback tokens=*" %%a in ('%event%') do set event=%%~a
for /f "useback tokens=*" %%a in ('%payload%') do set payload=%%~a
call :l_replace "%payload%" "=" ":"
call "eventghost.exe" -event "%event%" "%payload%"
goto end
:l_replace
set "payload=x%~1x"
:l_replaceloop
for /f "delims=%~2 tokens=1*" %%x in ("!payload!") do (
if "%%y"=="" set "payload=!payload:~1,-1!"&exit/b
set "payload=%%x%~3%%y"
)
goto l_replaceloop
:end
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Command line payloads
you can replace any character with another. I am sure you can figure out how to change it if you wanted to
Re: Command line payloads
thanks, although this method works perfectly, it doesn't work with my program, I can't pass the variable as the payload, it's not being interpreted for some reason, plus I don't like to have many cmd shell opened/closed (one per event), it's not very "clean" if I may say.
Anyway, if there is no workaround with EG itself then I think I will have to do it differently, it's ok.
Since we're at it, I noticed that there are still some flaws with the namedpipe despite your improvements made a few months ago (with the information I gave you back then), I still get some errors from time to time when the events are generated quickly... I think I'm going to completely abandon the use of the -e switch, since it's not very reliable and it makes EG unstable and sometimes unresponssive. I'm going to use the good old "udpsender.exe" to send events locally, it never failed me.
Thanks again for the tremendous help on this
very appreciated, as always 
Since we're at it, I noticed that there are still some flaws with the namedpipe despite your improvements made a few months ago (with the information I gave you back then), I still get some errors from time to time when the events are generated quickly... I think I'm going to completely abandon the use of the -e switch, since it's not very reliable and it makes EG unstable and sometimes unresponssive. I'm going to use the good old "udpsender.exe" to send events locally, it never failed me.
Thanks again for the tremendous help on this
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Command line payloads
if you are having errors then i need to see the errors. This way i will be able to improve upon it.
The last fix i did to the named pipe i ran something like 1000000 events at varying speeds and never got a single error. tho... Maybe if more then one event is being triggered at the same time. hmmmm... going to have to test that.
The last fix i did to the named pipe i ran something like 1000000 events at varying speeds and never got a single error. tho... Maybe if more then one event is being triggered at the same time. hmmmm... going to have to test that.
- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Command line payloads
I am not sure if you saw topix post with a fix.
Re: Command line payloads
I'm using the latest WIP of EG, his changes are in it ?
here's the error I get when 3 events are generated at almost the same time, I think approximately 100ms separates them :
here's the error I get when 3 events are generated at almost the same time, I think approximately 100ms separates them :
Code: Select all
Traceback (most recent call last):
File "EventGhost.pyw", line 53, in <module>
File "C:\Program Files (x86)\EventGhost\eg\__init__.py", line 31, in <module>
import Cli
File "C:\Program Files (x86)\EventGhost\eg\Cli.py", line 30, in <module>
import NamedPipe
File "C:\Program Files (x86)\EventGhost\eg\NamedPipe.py", line 107, in <module>
is_eg_running = _is_eg_running()
File "C:\Program Files (x86)\EventGhost\eg\NamedPipe.py", line 104, in _is_eg_running
raise NamedPipeConnectionError(err)
NameError: global name 'NamedPipeConnectionError' is not defined- kgschlosser
- Site Admin
- Posts: 5190
- Joined: Fri Jun 05, 2015 5:43 am
- Location: Rocky Mountains, Colorado USA
Re: Command line payloads
I am going to do some reading up on how to make the named pipe allow for multiple connections.
Re: Command line payloads
@snowbird: please try EventGhost_WIP-2018.04.10-17.57.02_Setup.exe
