home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / APR94_2.ZIP / LISTDVCB / LISTDVCB.ASM < prev    next >
Assembly Source File  |  1994-03-01  |  6KB  |  221 lines

  1. ;ListDVCB.ASM  
  2. ;from Dr. Dobbs Journal, April 1994
  3. ;Copyright (c) 1994 Klaus Mueller.  All rights reserved.
  4.  
  5. OPTION M510
  6.  
  7. .386p
  8.  
  9. INCLUDE VMM.INC
  10. INCLUDE ListDVCB.inc
  11.  
  12. ;*****************************************************************************
  13. ;        V I R T U A L   D E V I C E   D E C L A R A T I O N
  14. ;*****************************************************************************
  15.  
  16. Declare_Virtual_Device  ListDVCB, 1, 0, ListDVCB_VxD_Control, \
  17.                         ListDVCB_Device_ID,ListDVCB_Init_Order, \
  18.                         ListDVCB_V86_API
  19.     
  20.  
  21. ;*****************************************************************************
  22. ;           R E A L   M O D E   I N I T I A L I Z A T I O N
  23. ;*****************************************************************************
  24.  
  25. VXD_REAL_INIT_SEG
  26.  
  27. real_init proc near
  28.     mov ah, 9
  29.     mov dx, offset copyright
  30.     int 21h
  31.     xor ax, ax           
  32.     xor bx, bx          
  33.     xor si, si
  34.     xor edx, edx
  35.     ret
  36. real_init endp
  37.  
  38. copyright   db  'ListDVCB.386 -- provides a map of VxD areas in the '
  39.             db  'Virtual Machine Control Block' ,0dh 
  40.             db  'Copyright (c) 1994 Klaus Mueller. All Rights Reserved.'
  41.             db  0dh,0ah,'$'
  42.  
  43. VXD_REAL_INIT_ENDS
  44.  
  45. VxD_ICODE_SEG
  46.  
  47.  
  48. ;** ListDVCB_Sys_Crit_Init
  49. BeginProc ListDVCB_Sys_Critical_Init
  50.  
  51.         mov Data_Buf_Size,1000h
  52.         VMMcall _PageAllocate <1, PG_SYS, 0, 0, 0, 0, 0, PAGEFIXED+PAGEZEROINIT>
  53.         cmp eax,0
  54.         je allocerr
  55.         mov Data_Buf,edx
  56.         mov eax,_Allocate_Device_CB_Area
  57.         mov esi,offset32 cbhook
  58.         VMMcall Hook_Device_Service
  59.         mov [oldservice],esi
  60.         ;int 3
  61.         clc                     ; no error
  62.         ret                     
  63. allocerr:
  64.         stc
  65.         ret
  66. EndProc ListDVCB_Sys_Critical_Init
  67.  
  68.  
  69.  
  70. VxD_ICODE_ENDS
  71.  
  72. ;*****************************************************************************
  73. ;           L O C K E D   C O D E   S E G M E N T
  74. ;*****************************************************************************
  75.  
  76. VxD_LOCKED_CODE_SEG
  77.  
  78. BeginProc ListDVCB_VxD_Control
  79.  
  80.     Control_Dispatch Sys_Critical_Init, ListDVCB_Sys_Critical_Init
  81.     clc
  82.     ret
  83.  
  84. EndProc ListDVCB_VxD_Control
  85.  
  86. VxD_LOCKED_CODE_ENDS
  87.  
  88. ;*****************************************************************************
  89. ;               O N L Y   D A T A   S E G M E N T
  90. ;*****************************************************************************
  91.  
  92. VxD_DATA_SEG
  93.  
  94. oldservice      dd  0           ;original handler for _Allocate_Device_CB_Area
  95. hook_count      dd  0           ;# of intercepted calls
  96. string_buf      dd  0           ;buffer for VMCB_Hook_Strucs
  97. privcblen       dd  0
  98. calladr         dd  0           
  99. Data_Buf        dd  0           ;buffer for Hook_Strucs
  100. Data_Buf_Size   dd  0           
  101.  
  102. VxD_DATA_ENDS
  103.  
  104. VxD_CODE_SEG
  105.  
  106. BeginProc   Hooked_Allocate_Device_CB_Area
  107.  
  108. cbhook: ;int 3                  ;uncomment this for debug
  109.         push ebp
  110.         mov ebp,esp
  111.         push [ebp+0ch]          ;Flags
  112.         push [ebp+8]            ;nbytes
  113.         push [ebp+8]
  114.         pop privcblen
  115.         push [ebp+4]            ;Callers returnaddress
  116.         pop calladr
  117.         call [oldservice]
  118.         add esp,8
  119.         pop ebp
  120.         cmp eax,0               ;error in Allocate_Device_CB_Area ?
  121.         je short exit
  122.         push edi
  123.         push ecx
  124.         push eax
  125.         mov edi,Data_Buf
  126.         mov ecx,hook_count
  127.         imul ecx,sizeof Hook_Struc 
  128.         add edi,ecx
  129.         mov eax,calladr
  130.         stosd                   ;store data in our Hook_Struc
  131.         pop eax                 ;offset in VM_CB_Area
  132.         push eax
  133.         stosd
  134.         mov eax,privcblen
  135.         stosd                   ;Because of the few calls to _Allocate_CB_Area  
  136.         inc hook_count          ;a test of Data_Buf overflow is not nessesary  
  137.         pop eax
  138.         pop ecx
  139.         pop edi
  140. exit:   ;int 3
  141.         ret
  142.         
  143. EndProc   Hooked_Allocate_Device_CB_Area
  144.  
  145.  
  146. BeginProc ListDVCB_V86_API
  147.  
  148.         cmp [ebp.Client_AX],Hook_Buf_Size
  149.         je bufsz
  150.         cmp [ebp.Client_AX],Copy_Hook_Data
  151.         jne v86err
  152.         cmp string_buf,0
  153.         je buildcb
  154.         jmp cbcpy
  155. v86err: or [ebp.Client_Flags],1
  156.         ret
  157. bufsz:  mov eax,hook_count
  158.         imul eax,sizeof VMCB_Hook_Struc
  159.         Client_Ptr_Flat edi,DS,BX       ;get offset of long int                 
  160.         stosd
  161.         ret
  162. buildcb:mov eax,hook_count              ;allocate space for VMCB_Hook_Struc buffer
  163.         imul eax,sizeof VMCB_Hook_Struc
  164.         cmp eax,1000h
  165.         ja cb1
  166.         mov eax,1
  167.         jmp cb2
  168. cb1:    add eax,1000h
  169.         and eax,0fffh
  170.         shr eax,0ch                     
  171. cb2:    VMMcall _PageAllocate <eax, PG_SYS, 0, 0, 0, 0, 0, PAGEFIXED+PAGEZEROINIT>
  172.         cmp eax,0
  173.         je cberr1
  174.         mov string_buf,edx
  175.         mov ecx,hook_count
  176.         mov esi,Data_Buf                ;buffer of Hook_Strucs
  177.         mov edi,string_buf
  178. cbloop: push ecx
  179.         push esi
  180.         push edi
  181.         mov edi,[esi.Hook_Struc.VMCB_Caller_Address]
  182.         VxDcall VxDQuery_Address_to_VxDName
  183.         jc vmcberr
  184.         mov esi,edi                     ;pointer to VxDName
  185.         pop edi                         ;current VMCB_Hook_Struc
  186.         mov ecx,string_len/4
  187.         rep movsd                       ;save VxDName in string_buf 
  188.         pop esi                         ;current Hook_Struc
  189.         mov ecx,(sizeof Hook_Struc)/4
  190.         rep movsd                       ;copy Hook_Struc to VMCB_Hook_Struc
  191.         pop ecx
  192.         loop cbloop                 
  193. cbcpy:  Client_Ptr_Flat edi,DS,DX       ;address of callers ptr to buffer
  194.         mov edi,[edi]                   ;get buffer address
  195.         call v862lin
  196.         mov esi,string_buf
  197.         mov ecx,hook_count              ;# of VMCB_Hook_Strucs
  198.         imul ecx,(sizeof VMCB_Hook_Struc)/4
  199.         rep movsd                       ;copy data into callers V86 buffer
  200.         ret
  201. vmcberr:add esp,8
  202. cberr1: or [ebp.Client_Flags],1
  203.         ret
  204.  
  205. ;v862lin - converts v86 address to linear address
  206. ;INPUT  edi = Seg:Offs V86
  207. ;OUTPUT edi = linadr
  208. v862lin:push edx
  209.         movzx edx,di
  210.         shr edi,10h
  211.         shl edi,4
  212.         add edi,edx
  213.         pop edx
  214.         ret
  215.  
  216. EndProc   ListDVCB_V86_API
  217.  
  218. VxD_CODE_ENDS
  219.  
  220.     END
  221.