⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dnsr.asm

📁 Application sources:A084.ZIP
💻 ASM
📖 第 1 页 / 共 2 页
字号:
;
;    DNS Domain name -> IP lookup
;
;    Compile with FASM for Menuet
;
   

; If you like, you camd change the DNS server default by changing the
; IP address in the dnsServer string.


; Enabling debugging puts the received response to the
; debug board
DEBUGGING_ENABLED           equ     1
DEBUGGING_DISABLED          equ     0
DEBUGGING_STATE             equ     DEBUGGING_DISABLED
      
   
use32
   
                org     0x0
   
                db      'MENUET00'              ; 8 byte id
                dd      38                      ; required os
                dd      START                   ; program start
                dd      I_END                   ; program image size
                dd      0x100000                ; required amount of memory
                dd      0x00000000              ; reserved=no extended header
   
   
START:                                      ; start of execution
    mov     eax,40                          ; Report events
    mov     ebx,10000111b                   ; Stack 8 + defaults
    int     0x40
               
    mov     dword [prompt], p1
    mov     dword [promptlen], p1len - p1   ; 'waiting for command'
            
    call    draw_window                     ; at first, draw the window
   
still:
    mov     eax,10                          ; wait here for event
    int     0x40
   
    cmp     eax,1                           ; redraw request ?
    jz      red
    cmp     eax,2                           ; key in buffer ?
    jz      key
    cmp     eax,3                           ; button in buffer ?
    jz      button
   
    jmp     still
   
red:                            ; redraw
    call    draw_window
    jmp     still
   
key:                            ; Keys are not valid at this part of the
    mov     eax,2               ; loop. Just read it and ignore
    int     0x40
    jmp     still
   
button:                         ; button
    mov     eax,17              ; get id
    int     0x40
   
    cmp     ah,1                ; button id=1 ?
    jnz     noclose
   
    ; close socket before exiting
    mov     eax, 53
    mov     ebx, 1
    mov     ecx, [socketNum]
    int     0x40
   
    mov     eax,0xffffffff      ; close this program
    int     0x40
   
noclose:
    cmp     ah,3                ; Resolve address?
    jnz     noresolve
   
    mov     dword [prompt], p5
    mov     dword [promptlen], p5len - p5   ; display 'Resolving'
    call    draw_window
   
    call    translateData       ; Convert domain & DNS IP address
    
    call    resolveDomain
   
    jmp     still
   
   
noresolve:
    cmp     ah,4
    jz      f1                  ; Enter domain name                   
    cmp     ah,5
    jz      f2                  ; enter DNS Server IP
    jmp     still
   
   
f1:
    mov     [addr],dword query
    mov     [ya],dword 35
    jmp     rk
   
f2:
    mov     [addr],dword dnsServer
    mov     [ya],dword 35+16
   
rk:
    mov     ecx,26
    mov     edi,[addr]
    mov     al,' '
    rep     stosb
   
    call    print_text
   
    mov     edi,[addr]
   
f11:
    mov     eax,10
    int     0x40
    cmp     eax,2
    jz      fbu
    jmp     still
    
fbu:
    mov     eax,2
    int     0x40  ; get key
    shr     eax,8
    cmp     eax,8
    jnz     nobs
    cmp     edi,[addr]
    jz      f11
    sub     edi,1
    mov     [edi],byte ' '
    call    print_text
    jmp     f11

nobs:
    cmp     eax,dword 31
    jbe     f11
    cmp     eax,dword 95
    jb      keyok
    sub     eax,32
  
keyok:
    mov     [edi],al
   
    call    print_text
   
    add     edi,1
    mov     esi,[addr]
    add     esi,26
    cmp     esi,edi
    jnz     f11
   
    jmp  still
 
 
   
print_text:  
    mov     eax,13
    mov     ebx,103*65536+26*6
    mov     ecx,[ya]
    shl     ecx,16
    mov     cx,8
    mov     edx,0x224466
    int     0x40
   
    mov     eax,4
    mov     ebx,103*65536
    add     ebx,[ya]
    mov     ecx,0xffffff
    mov     edx,[addr]
    mov     esi,26
    int     0x40
   
    ret
   
   
   
;***************************************************************************
;   Function
;      translateData
;
;   Description
;      Coverts the domain name and DNS IP address typed in by the user into
;      a format suitable for the IP layer.
;
;    The ename, in query, is converted and stored in dnsMsg
;      The DNS ip, in dnsServer, is converted and stored in dnsIP
;
;***************************************************************************
translateData:
   
    ; first, get the IP address of the DNS server
    ; Then, build up the request string. 
  
    xor     eax, eax
    mov     dh, 10
    mov     dl, al
    mov     [dnsIP], eax
   
    mov     esi, dnsServer
    mov     edi, dnsIP
   
    mov     ecx, 4
   
td003:
    lodsb
    sub     al, '0'
    add     dl, al
    lodsb
    cmp     al, '.'
    je      ipNext
    cmp     al, ' '
    je      ipNext
    mov     dh, al
    sub     dh, '0'
    mov     al, 10
    mul     dl
    add     al, dh
    mov     dl, al
    lodsb
    cmp     al, '.'
    je      ipNext
    cmp     al, ' '
    je      ipNext
    mov     dh, al
    sub     dh, '0'
    mov     al, 10
    mul     dl
    add     al, dh
    mov     dl, al
    lodsb

ipNext:
    mov     [edi], dl
    inc     edi
    mov     dl, 0
    loop    td003
    
    ; Build the request string
    

    mov     eax, 0x00010100
    mov     [dnsMsg], eax
    mov     eax, 0x00000100
    mov     [dnsMsg+4], eax
    mov     eax, 0x00000000
    mov     [dnsMsg+8], eax
    
    ; domain name goes in at dnsMsg+12
    mov     esi, dnsMsg + 12        ; location of label length
    mov     edi, dnsMsg + 13        ; label start
    mov     edx, query
    mov     ecx, 12                  ; total string length so far
    
td002:
    mov     [esi], byte 0
    inc     ecx
    
td0021:
    mov     al, [edx]
    cmp     al, ' '
    je      td001                   ; we have finished the string translation
    cmp     al, '.'                 ; we have finished the label
    je      td004
    
    inc     byte [esi]
    inc     ecx
    mov     [edi], al
    inc     edi
    inc     edx
    jmp     td0021
    
td004:
    mov     esi, edi
    inc     edi
    inc     edx
    jmp     td002
    
    
    
    ; write label len + label text

td001:
    mov     [edi], byte 0
    inc     ecx
    inc     edi
    mov     [edi], dword 0x01000100
    add     ecx, 4

    mov     [dnsMsgLen], ecx
        
    ret
   
   
   
  
   
;***************************************************************************
;   Function
;      resolveDomain
;
;   Description
;       Sends a question to the dns server
;       works out the IP address from the response from the DNS server
;
;***************************************************************************
resolveDomain:
    ; Get a free port number    
	mov	    ecx, 1000		; local port starting at 1000	
getlp:
	inc	    ecx             
	push	ecx
	mov	    eax, 53
	mov	    ebx, 9
	int     0x40
	pop	    ecx
	cmp	    eax, 0			; is this local port in use?
	jz		getlp		    ; yes - so try next
   
    ; First, open socket
    mov     eax, 53
    mov     ebx, 0
    mov     edx, 53    ; remote port - dns
    mov     esi, [dnsIP]
    int     0x40
   
    mov     [socketNum], eax
   
    ; write to socket ( request DNS lookup )
    mov     eax, 53
    mov     ebx, 4
    mov     ecx, [socketNum]
    mov     edx, [dnsMsgLen]
    mov     esi, dnsMsg
    int     0x40
    
    ; Setup the DNS response buffer
    
    mov     eax, dnsMsg
    mov     [dnsMsgLen], eax
   
    ; now, we wait for
    ; UI redraw
    ; UI close
    ; or data from remote
   
ctr001:
    mov     eax,10                 ; wait here for event
    int     0x40
       
    cmp     eax,1                  ; redraw request ?
    je      ctr003
    cmp     eax,2                  ; key in buffer ?
    je      ctr004
    cmp     eax,3                  ; button in buffer ?
    je      ctr005
   
   
    ; Any data in the UDP receive buffer?
    mov     eax, 53
    mov     ebx, 2
    mov     ecx, [socketNum]
    int     0x40
   
    cmp     eax, 0
    je      ctr001
   
    ; we have data - this will be the response
ctr002:
    mov     eax, 53
    mov     ebx, 3
    mov     ecx, [socketNum]
    int     0x40                ; read byte - block (high byte)

    ; Store the data in the response buffer   
    mov     eax, [dnsMsgLen]
    mov     [eax], bl
    inc     dword [dnsMsgLen]


if DEBUGGING_STATE = DEBUGGING_ENABLED
    call debug_print_rx_ip
end if

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -