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

📄 dnsr.asm

📁 Application sources:A084.ZIP
💻 ASM
📖 第 1 页 / 共 2 页
字号:
   
    mov     eax, 53
    mov     ebx, 2
    mov     ecx, [socketNum]
    int     0x40                ; any more data?
    
    cmp     eax, 0
    jne     ctr002              ; yes, so get it

    ; close socket
    mov     eax, 53
    mov     ebx, 1
    mov     ecx, [socketNum]
    int     0x40
   
    mov     [socketNum], dword 0xFFFF

    ; Now parse the message to get the host IP
    ; Man, this is complicated. It's described in
    ; RFC 1035
    
    ; 1) Validate that we have an answer with > 0 responses
    ; 2) Find the answer record with TYPE 0001 ( host IP )
    ; 3) Finally, copy the IP address to the display
    ; Note: The response is in dnsMsg
    ;       The end of the buffer is pointed to by [dnsMsgLen]
    
    ; Clear the IP address text
    mov     [hostIP], dword 0
    
    mov     esi, dnsMsg
    
    ; Is this a response to my question?
    mov     al, [esi+2]
    and     al, 0x80
    cmp     al, 0x80
    jne     ctr002a
    
    ; Were there any errors?
    mov     al, [esi+3]
    and     al, 0x0F
    cmp     al, 0x00
    jne     ctr002a
    
    ; Is there ( at least 1 ) answer?
    mov     ax, [esi+6]
    cmp     ax, 0x00
    je      ctr002a
        
    ; Header validated. Scan through and get my answer
    
    add     esi, 12             ; Skip to the question field
    
    ; Skip through the question field
    call    skipName
    add     esi, 4              ; skip past the questions qtype, qclass
    
ctr002z:
    ; Now at the answer. There may be several answers, 
    ; find the right one ( TYPE = 0x0001 )
    call    skipName
    mov     ax, [esi]
    cmp     ax, 0x0100          ; Is this the IP address answer?
    jne     ctr002c
    
    ; Yes! Point esi to the first byte of the IP address
    add     esi, 10
    
    mov     eax, [esi]
    mov     [hostIP], eax
    jmp     ctr002a             ; And exit...
    
    
ctr002c:                        ; Skip through the answer, move to the next
    add     esi, 8              
    movzx   eax, byte [esi+1]
    mov     ah, [esi]
    add     esi, eax
    add     esi, 2
    
    ; Have we reached the end of the msg?
    ; This is an error condition, should not happen
    cmp     esi, [dnsMsgLen]
    jl      ctr002z             ; Check next answer
    jmp     ctr002a             ; abort
    
    
ctr002a:
    mov     dword [prompt], p4  ; Display IP address
    mov     dword [promptlen], p4len - p4
    call    draw_window  

    jmp     ctr001
   
ctr003:                         ; redraw
    call    draw_window
    jmp     ctr001
   
ctr004:                         ; key
    mov     eax,2               ; just read it and ignore
    int     0x40
    jmp     ctr001
   
ctr005:                         ; button
    mov     eax,17              ; get id
    int     0x40
   
    ; close socket
    mov     eax, 53
    mov     ebx, 1
    mov     ecx, [socketNum]
    int     0x40
    
    mov     [socketNum], dword 0xFFFF
    mov     [hostIP], dword 0
    
    mov     dword [prompt], p1
    mov     dword [promptlen], p1len - p1   ; 'waiting for command'
            
    call    draw_window                     ; at first, draw the window

    ret   
    
    
    
;***************************************************************************
;   Function
;      skipName
;
;   Description
;       Increment esi to the first byte past the name field  
;       Names may use compressed labels. Normally do.
;       RFC 1035 page 30 gives details
;
;***************************************************************************
skipName:
    mov     al, [esi]
    cmp     al, 0
    je      sn_exit
    and     al, 0xc0
    cmp     al, 0xc0
    je      sn001
    
    movzx   eax, byte [esi]
    inc     eax
    add     esi, eax
    jmp     skipName
    
sn001:
    add     esi, 2                          ; A pointer is always at the end
    ret

sn_exit:
    inc     esi
    ret
       
   
;   *********************************************
;   *******  WINDOW DEFINITIONS AND DRAW ********
;   *********************************************
   
   
draw_window:
    mov     eax,12                    ; function 12:tell os about windowdraw
    mov     ebx,1                     ; 1, start of draw
    int     0x40
                                      ; DRAW WINDOW
    mov     eax,0                     ; function 0 : define and draw window
    mov     ebx,100*65536+300         ; [x start] *65536 + [x size]
    mov     ecx,100*65536+140         ; [y start] *65536 + [y size]
    mov     edx,0x04224466            ; color of work area RRGGBB
    mov     esi,window_label          ; color of grab bar  RRGGBB,8->color gl
    mov     edi,0                     ; color of frames    RRGGBB
    int     0x40
      
    mov     eax,8                     ; Resolve
    mov     ebx,20*65536+190
    mov     ecx,79*65536+15
    mov     edx,3
    mov     esi,0x557799
    int     0x40
   
    mov     eax,8
    mov     ebx,270*65536+10
    mov     ecx,34*65536+10
    mov     edx,4
    mov     esi,0x557799
    int     0x40
   
    mov     eax,8
    mov     ebx,270*65536+10
    mov     ecx,50*65536+10
    mov     edx,5
    mov     esi,0x557799
    int     0x40
      
    ; Copy the file name to the screen buffer
    ; file name is same length as IP address, to
    ; make the math easier later.
    cld
    mov     esi,query
    mov     edi,text+13
    mov     ecx,26
    rep     movsb
   
   
    ; copy the IP address to the screen buffer
    mov     esi,dnsServer
    mov     edi,text+40+13
    mov     ecx,26
    rep     movsb
   
    ; copy the prompt to the screen buffer
    mov     esi,[prompt]
    mov     edi,text+200
    mov     ecx,[promptlen]
    rep     movsb
    
    ; Re-draw the screen text
    cld
    mov     ebx,25*65536+35           ; draw info text with function 4
    mov     ecx,0xffffff
    mov     edx,text
    mov     esi,40

newline:
    mov     eax,4
    int     0x40
    add     ebx,16
    add     edx,40
    cmp     [edx],byte 'x'
    jnz     newline


    ; Write the host IP, if we have one
    mov     eax, [hostIP]
    cmp     eax, 0
    je      dw001
    
    ; We have an IP address... display it
    mov     edi,hostIP            
    mov     edx,97*65536+115
    mov     esi,0x00ffffff
    mov     ebx,3*65536
    
ipdisplay:
    mov     eax,47
    movzx   ecx,byte [edi]
    int     0x40
    add     edx,6*4*65536
    inc     edi
    cmp     edi,hostIP+4
    jb      ipdisplay
        
dw001:   
    mov     eax,12                    ; function 12:tell os about windowdraw
    mov     ebx,2                     ; 2, end of draw
    int     0x40
   
    ret

   
if DEBUGGING_STATE = DEBUGGING_ENABLED
;****************************************************************************
;    Function   
;       debug_print_string
;
;   Description
;       prints a string to the debug board       
;          
;       esi holds ptr to msg to display
;
;       Nothing preserved; I'm assuming a pusha/popa is done before calling
;
;****************************************************************************
debug_print_string:
    mov     cl, [esi]
    cmp     cl, 0
    jnz     dps_001
    ret
	
dps_001:
    mov     eax,63
    mov     ebx, 1
    push    esi
    int 0x40

    inc   word [ind]
    mov  ax, [ind]
    and ax, 0x1f
    cmp  ax, 0
    jne  ds1
    
    mov   cl, 13
    mov     eax,63
    mov     ebx, 1
    int 0x40
    mov   cl, 10
    mov     eax,63
    mov     ebx, 1
    int 0x40
    
    
ds1:
    pop     esi
    inc     esi
    jmp     debug_print_string
 

ind: dw 0
; This is used for translating hex to ASCII for display or output
hexchars db '0','1','2','3','4','5','6','7','8','9','A','B','C','D','E','F'
IP_STR              db  'xx',0


debug_print_rx_ip:
    pusha
    mov     edi, IP_STR
    
    xor     eax, eax
    mov     al, bl
    shr     al, 4
    mov     ah, [eax + hexchars]
    mov     [edi], ah
    inc     edi
    
    xor     eax, eax
    mov     al, bl
    and     al, 0x0f
    mov     ah, [eax + hexchars]
    mov     [edi], ah
    mov     esi, IP_STR

    call    debug_print_string
    popa
    ret
end if

   
; DATA AREA
   
addr            dd  0x0
ya              dd  0x0
   
text:
    db 'Host name  : xxxxxxxxxxxxxxx            '
    db 'DNS server : xxx.xxx.xxx.xxx            '
    db '                                        '
    db '     RESOLVE ADDRESS                    '
    db '                                        '
    db '                                        '
    db 'x <- END MARKER, DONT DELETE            '
   
   

window_label:

    db   'DNS CLIENT',0
   
prompt: dd 0
promptlen: dd 0
   
   
p1:             db 'Waiting for Command        '
p1len:
   
p4:             db 'IP Address:    .   .   .   '
p4len:
   
p5:             db 'Resolving...               '
p5len:
      
   
dnsServer       db  '194.145.128.1              ' ; iolfree.ie DNS
query           db  'WWW.MENUETOS.ORG           '
   
hostIP:         dd 0   
dnsIP:          dd 0
dnsMsgLen:      dd 0
socketNum:      dd 0xFFFF
dnsMsg:
I_END:
   
   
   
   
   

⌨️ 快捷键说明

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