ASM CGI With Apache & Nginx

Apach & Nginx 下的汇编CGI 程序
This is a comprehensive program ,and it shows another power of ASM, writing Web programs, which you might think is ridiculous, but ASM is so powerful. Compiled CGI program size is only 3KB, the operation can be precise to each step instructions. ASM under the operating system it is same as high-level language to call to the unified API interface, so that assembly than high-level language is more powerful !

IDE: MASMPlus
Environment : Apach & Nginx
Lang: ASM x86 CGI

Using ASM:

.386
.model flat,stdcall 
option casemap:none 
 
include windows.inc 
include user32.inc
include kernel32.inc 
include masm32.inc 
includelib user32.lib
includelib kernel32.lib 
includelib masm32.lib 
includelib msvcrt.lib 
include macro.asm
 
printf proto c:DWORD ,:vararg
scanf proto c:DWORD ,:vararg
gets proto c:DWORD
getchar proto c:DWORD
getenv proto c:DWORD 
fopen proto c:DWORD ,:DWORD
fseek proto c:DWORD ,:DWORD ,:DWORD 
fread proto c:DWORD ,:DWORD ,:DWORD,:DWORD
fclose proto c:DWORD
ftell proto c:DWORD
strcpy proto c:DWORD ,:DWORD 
 
.data 
n DWORD ?
i   DWORD ?
j   DWORD ?
NV DWORD ?
NEX DWORD ?
 
PGraph DWORD ?
 
str2 BYTE 100 dup(0)
len DWORD ?
fSize DWORD ?
buffer  db 100 dup(?)
BufStream DWORD ?
fp DWORD ?
EnvData DWORD ?
 
 
.code
Malloc proc nSize:DWORD 
    invoke GetProcessHeap
    invoke HeapAlloc,eax,0,nSize
    ret
Malloc endp
 
getFileSizeB   proc pf:DWORD
                    local fiSize:DWORD
                    mov fiSize,-1
                    .if pf
                        invoke fseek,pf,0,SEEK_END
                        invoke ftell,fp
                        mov fiSize,eax
                    .endif
                    mov eax,fiSize
                    ret
getFileSizeB   endp
 
                     
start: 
invoke printf,CTXT("Content-type:text/html",0ah,0dh,0ah,0dh)
invoke getenv,CTXT("QUERY_STRING")
mov EnvData,eax
 
.if EnvData!=NULL
    invoke StrLen,EnvData
.endif
 
.if eax<2
    mov EnvData,CTXT("index.html")
.endif
 
invoke printf,CTXT("%s"),EnvData
 
invoke fopen,EnvData,CTXT("r")
mov fp,eax
invoke getFileSizeB,fp
mov fSize,eax
invoke Malloc,fSize
mov BufStream,eax
invoke fseek,fp,0,SEEK_SET
invoke fread,BufStream,fSize,1,fp
invoke fclose,fp
invoke printf,CTXT("%s"),BufStream
 
Done:
;invoke gets,addr string
invoke StdIn,addr buffer,sizeof buffer
invoke ExitProcess, 0 
end start

HTML部分

<!doctype html>    
<html>    
<head>    
    <meta charset="utf-8">    
    <title>Fuck You</title>    
</head>    
<body>    
    <h1>FUCK IS OK</h1>    
    <h2>FUCK IS OK</h2>    
    <p>Fuck Fuck Fuck</p>    
</body>    
</html>