home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / magazine / progjour / 1991 / 04 / spy.asm < prev    next >
Assembly Source File  |  1991-04-19  |  3KB  |  145 lines

  1.     title    netbios datagram spy
  2.     include    asm.inc
  3.     include    netbios.inc
  4.  
  5.     public    main
  6.  
  7.     .stack
  8.  
  9.     .const
  10. broadcast_text    db  'Broadcast',0
  11. callname_text    db  ' - Call Name:',0
  12. datagram_text    db  'Datagram ',0
  13. driver_text    db  'No NetBIOS driver found',0
  14. help_text    db  'NetBIOS Spy - displays network datagrams',13,10
  15.         db  'Press ESC to exit',0
  16. length_text    db  ' - Length:',0
  17. retcode_text    db  ' - RetCode:',0
  18. spy_text    db  'Spy',0
  19.  
  20.  
  21.     .data?
  22. ncb_broadcast    ncb <>            ; control blk for broadcast datagrams
  23. ncb_datagram    ncb <>            ; control blk for other datagrams
  24.  
  25. buf_broadcast    db  DATAGRAM_MAX dup(?)    ; buffer for broadcast datagrams
  26. buf_datagram    db  DATAGRAM_MAX dup(?)    ; buffer for other datagrams
  27.  
  28. add_name    db    ?
  29.  
  30.  
  31.     .code
  32.  extn exit_program,get_input_state,clear_ncb,netbios_call,netbios_cancel
  33.  extn putchar_newline,puts,put_hex_byte,put_hex_word,put_multiple_bytes
  34.  extn put_netbios_name,put_string,startup,netbios_check
  35.  extn netbios_add_name,netbios_delete_name
  36.  
  37. ;;    main
  38. ;
  39. main    proc
  40.     lea    si,help_text
  41.     call    puts
  42.  
  43.     call    netbios_check
  44.     jc    mai4            ;  if no netbios driver
  45.  
  46.     lea    si,spy_text
  47.     call    netbios_add_name
  48.     mov    add_name[bp],al
  49.  
  50. mai1:    lea    si,ncb_broadcast    ; check receive broadcast datagram
  51.     cmp    Ncb_Cmd_Cplt[si],0FFh
  52.     je    mai2            ;  if receive pending
  53.  
  54.     call    clear_ncb        ;  else post receive broadcast
  55.     mov    Ncb_Command[si],NB_RECEIVE_BROADCAST
  56.     mov    Ncb_Num[si],0FFh    ;  (FF means any datagram)
  57.     mov    Ncb_BufferOff[si],offset buf_broadcast
  58.     mov    Ncb_BufferSeg[si],ds
  59.     mov    Ncb_Length[si],size buf_broadcast
  60.     call    netbios_call
  61.  
  62. mai2:    lea    si,ncb_datagram        ; check receive datagram
  63.     cmp    Ncb_Cmd_Cplt[si],0FFh
  64.     je    mai3            ;  if receive pending
  65.  
  66.     call    clear_ncb        ;  else post receive broadcast
  67.     mov    Ncb_Command[si],NB_RECEIVE_DATAGRAM
  68.     mov    al,0FFh            ;  (FF means any datagram)
  69. ;    mov    al,add_name[bp]
  70.     mov    Ncb_Num[si],al
  71.     mov    Ncb_BufferOff[si],offset buf_datagram
  72.     mov    Ncb_BufferSeg[si],ds
  73.     mov    Ncb_Length[si],size buf_datagram
  74.     call    netbios_call
  75.  
  76. mai3:    call    get_input_state
  77.     jnz    mai5            ;  if key waiting
  78.  
  79.     lea    si,ncb_broadcast
  80.     call    process_control_block
  81.  
  82.     lea    si,ncb_datagram
  83.     call    process_control_block
  84.     jmp    mai1
  85.  
  86. mai4:    lea    si,driver_text        ; *No NetBIOS driver found*
  87.     call    puts
  88.     jmp    exit_program
  89.  
  90. mai5:    lea    si,ncb_broadcast
  91.     call    netbios_cancel
  92.     lea    si,ncb_datagram
  93.     call    netbios_cancel
  94.     lea    si,spy_text
  95.     call    netbios_delete_name
  96.     jmp    exit_program
  97. main    endp
  98.  
  99.  
  100. ;;    process control block
  101. ;
  102. ;    entry    DS:SI    datagram control block
  103. ;    uses    AX,BX,CX,SI
  104. ;
  105. process_control_block proc
  106.     mov    bx,si
  107.     cmp    Ncb_Cmd_Cplt[bx],0FFh
  108.     je    pcb3            ;  if receive still pending
  109.  
  110.     lea    si,datagram_text    ; *Datagram *
  111.     cmp    Ncb_Command[bx],NB_RECEIVE_DATAGRAM
  112.     je    pcb1
  113.     lea    si,broadcast_text    ; *Broadcast*
  114. pcb1:    call    put_string
  115.  
  116.     cmp    Ncb_RetCode[bx],0    ; display non-zero return code
  117.     je    pcb2
  118.  
  119.     lea    si,retcode_text        ; * - RetCode:*
  120.     call    put_string
  121.     mov    al,Ncb_RetCode[bx]
  122.     call    put_hex_byte
  123.  
  124. pcb2:    lea    si,length_text        ; * - Length:*
  125.     call    put_string
  126.     mov    ax,Ncb_Length[bx]
  127.     call    put_hex_word
  128.  
  129.     lea    si,callname_text    ; * - Call Name:*
  130.     call    put_string
  131.  
  132.     lea    si,Ncb_CallName[bx]    ; display call name
  133.     call    put_netbios_name
  134.     call    putchar_newline
  135.  
  136.     push    ds            ; display datagram
  137.     mov    cx,Ncb_Length[bx]
  138.     lds    si,dword ptr Ncb_BufferOff[bx]
  139.     call    put_multiple_bytes
  140.     pop    ds
  141. pcb3:    ret
  142. process_control_block endp
  143.  
  144.     end
  145.