Hi I just made this cgiHere it is

http://www.busybeesolutions.com/cgi-bin/intro/htm.exe

and here's the source, it was made in MASM32

http://www.busybeesolutions.com/sourcefiles/htm.asm

Now I wish I could , be able to pass information to it
like you can in a C cgi with getenv()
I noticed I can type
invoke GetEnvironmentStrings
In my masm32 without errrror, i got
GetEnvironmentStrings from the Kernal32.inc
But I have know idea how to make the code I need


Andy
Posted on 2001-11-14 21:55:44 by andy981
What exaclty do you want? Do you want the windows environment variables or reading what variables where sent to the webserver (file.exe?param=data&param2=datatoo or POST) ?

Thomas

edit: that weird string should be:


file.exe?param=data & param2=datatoo
(without spaces)

The board did some strange things with it.
Posted on 2001-11-15 01:47:02 by Thomas
This worked for me, maybe it's not very optimized, I'm new to x86 asm:

(Nasm syntax; sc macro used -equal to Masm's invoke-; variable declarations -all resd-, EQUs and Externs omitted)



StdIn:
sc GetStdHandle,STD_INPUT_HANDLE
mov dword [hInput], eax
sc SetConsoleMode,[hInput],ENABLE_LINE_INPUT|ENABLE_ECHO_INPUT|ENABLE_PROCESSED_INPUT
mov dword [bLen], 1024
xor edx, edx
mov eax, [esp+4] ; the return string will go in [esp+4]
.read:
add eax, edx
mov dword [bLenAc], edx
sc ReadFile,[hInput],eax,[bLen],bRead,0
mov dword edx, [bLenAc]
add edx, [bRead]
cmp dword [bRead], 0
jne .read
mov eax, [esp+4]
ret

StdOut:
mov dword [lpszText], eax ; string pointer in eax
sc GetStdHandle,STD_OUTPUT_HANDLE
mov dword [hOutput], eax
mov dword eax, [lpszText]
dec eax
mov dword edx, -1
.loop:
inc eax
inc edx
cmp byte [eax], 0
jne .loop
sc WriteFile,[hOutput],[lpszText],edx,bWritten,0
mov dword eax, [bWritten] ; return bytes sent in eax, or anything you like
ret


Hope it helps. Regards,

Wavemaker
Posted on 2001-11-15 03:42:25 by Wavemaker
Lacking a CGI example of this, I whipped one up for FAsm.

It takes the query string and (in PERL):
print join "<BR>\n", split /\&/, $ENV{QUERY_STRING}
Posted on 2001-11-15 05:48:44 by eet_1024
funny i just posted what you want in hutch's demos for masm
sticky thread... the zip contains win_cgi, should be what you
are looking for...

good luck
Posted on 2001-11-15 19:26:29 by mob
Thanks Mob

I tried it, but I couldn't get it to work, I use an IIS 5 server,
Got CGI-ERROR in IIS5
I just wish I could figure out how to pass a query string or
post, into a variable.
I have'nt had any sucess, can't even get a whole
query string like ?field=soandso
I did fool around with it though, like sandwiching the code
between one of my prevoius asm cgi's code.
but nothing happened
But soon or later the pieces will fall together.
Espesially here, you guys are geniuses
But Tonights effort were not at all loss, I found how to print
numbers using wsprintf

Thanks
Andy
Posted on 2001-11-15 22:35:49 by andy981
Like you said here

reading what variables where sent to the webserver (file.exe?param=data?m2=datatoo or POST) ?


Do you know how , using MASM32?
Masm32 the only assembler I've been able to use





:)
Posted on 2001-11-16 14:19:46 by andy981
It depends on how IIS treats your exe... Does it forward the HTTP request to your standard input? Try to read some input and directly ouput it again...
I wouldn't know if IIS sets the QUERY_STRING environment variable but if it inserts the full HTTP request into the stdinput, you can extract it from that. A http request looks like this:



GET /somefolder/yourfile.exe?something=this&somethingelse=that HTTP/1.1
Host: [url]www.yourhost.com[/url]
Accept: */*, blah blah
More: headers that you won't need



Notice that there's a blank line at the end which indicates the end of the request. If the request is a POST request, data is sent after that line but for GET requests this is all.
You can extract the passed parameters from the first line (after the question mark)..
I'll play with IIS and see what it does with an executable, I never tried..

Thomas
Posted on 2001-11-16 14:53:03 by Thomas
I tried some things and I don't think IIS passes any data to your standard input, except for POST data.
However you can get the query string from the environment variables like this:



.data
queryString db "QUERY_STRING",0
.code
invoke GetEnvironmentVariable, addr queryString, addr Buffer, sizeofyourbuffer


This will copy the part after the question mark in the request to Buffer.
Now you'll need to write some functions to split the parameters, eet_1024 has already posted such a function.
And also remember that you don't *have* to use the default something=this&other=that format, you can use any format you like such as yourexe.exe?something,anotherthing,evenmorethings.
As long as your program can parse it.

Thomas
Posted on 2001-11-16 15:33:16 by Thomas
That helped alot, Now I'll have to figure how to parse the data,
But what is troublesome is that you often get garbage instead of

field=Andy you'll get garbage like this ??3?

and of course you'll get garbage if there is no query string

I'd like to try stdin so I can post data,

but the only stdin I know is


invoke StdIn,ADDR Buffer,LENGTHOF Buffer

And that stops the server, got to get rid of the getchar
well you know the curser _ that blinks in a dos screen
A cgi just has to just zip in and out to work

But Thank You
Thomas

I've made real gains in my assembly CGI program this week
Posted on 2001-11-16 18:04:49 by andy981
StdIn did work!, I had'nt tried using the post, (get so use to failure), but it did work, I guess the thing to do is figure
a way to have it bypass, if StdIn is empty
In C CGI you test for a NULL
But I'm working on it.
Anyway my great interst in CGI Assembly is that you get this great kick out of it, Or any CGI , like C CGI


:alright:

Thanks Thomas for your Help

Andy
Posted on 2001-11-16 19:01:50 by andy981
Glad to help.. But I don't know why you are getting garbage when retrieving the querystring.. If I do this before the GetEnvironmentVariable:


.data
htmlContent db "Content-type: text/html",0dh,0ah,0dh,0ah
hc_len equ $-htmlContent ; nr of bytes in string above
.code
invoke WriteFile, hStdOut, addr htmlContent, hc_len, addr BytesWritten, 0


...this after GetEnvironmentVariable:


WriteFile, hStdOut, addr Buffer, eax, addr BytesWritten, 0
.

And then request the file like this:
http://localhost/testwww/file.exe?something=this
I get a html page (well text actually) that just displays:


something=this


No garbage at all.. Maybe you have missed a pointer somewhere?

The stdinput is only used when posting data, and there are other environment variables that can be used to determine whether it was a post or a get request. Then there's another environment variable that contains the number of bytes posted... Use this one to retrieve the right number of bytes..
But GET is easier to process, so try to get it work right without garbage..

I've included a list of environment variables you can use below, most have an obvious meaning, if you don't know one just search the web.

Thomas



AUTH_TYPE
ComSpec
GATEWAY_INTERFACE
All HTTP_* variables
CONTENT_LENGTH ; This is the length of POST data
CONTENT_TYPE
PATH
PATH_INFO
PATH_TRANSLATED
QUERY_STRING
REMOTE_ADDR
REMOTE_HOST
REMOTE_USER
REQUEST_METHOD ; "GET", "POST", "HEAD" etc (iirc)
SCRIPT_NAME
SERVER_NAME
SERVER_PROTOCOL
SERVER_PORT
SERVER_SOFTWARE
SystemRoot
windir
Posted on 2001-11-17 03:45:34 by Thomas