home *** CD-ROM | disk | FTP | other *** search
/ Media Share 13 / mediashare_13.zip / mediashare_13 / ZIPPED / PROGRAM / APR94_1.ZIP / UC494.ASC < prev    next >
Text File  |  1994-02-27  |  5KB  |  134 lines

  1. _UNDOCUMENTED CORNER COLUMN_
  2. edited by Andrew Schulman
  3. written by Klaus Muller
  4.  
  5. Listing One
  6.  
  7. ;;; _AddInstanceItem hook from LISTINST.386
  8.  
  9. ;;; from DDK VMM.INC 
  10. InstDataStruc struc
  11. InstLinkF         dd          0   ; linked list forward ptr
  12. InstLinkB         dd          0   ; linked list back ptr
  13. InstLinAddr       dd          ?   ; Linear address of start of block
  14. InstSize          dd          ?   ; Size of block in bytes
  15. InstType          dd          ?   ; INDOS_Field or ALWAYS_Field -- ignored?
  16. InstDataStruc ends
  17.  
  18. ;;; from LISTINST.INC -- my InstData struct includes caller address
  19. KM_InstData struc
  20. AddInst_Caller          dd      ?
  21. InstDataStruc           { }       ; from VMM.INC
  22. KM_InstData ends
  23.  
  24. ;;; from LISTINST.ASM
  25. oldservice      dd  0       ; return value from Hook_Device_Service
  26. Inst_Struc_Ptr  dd  0       ; InstLinkF from InstDataStruc
  27. calladr         dd  0       ; address of _AddInstanceItem caller
  28. Data_Buf_Addr   dd  0       ; created with _PageAllocate PG_SYS
  29. Data_Buf_Size   dd  0
  30. Data_Buf_Handle dd  0
  31. Inst_Data_Count dd  0       ; number of instance items seen so far
  32.  
  33. ;;; from LISTINST.AM Sys_Critical_Init handler
  34.  
  35. ;Instancing of the first byte in the 1st MB in order to get all calls to 
  36. ;_AddInstanceItem befor ListInst_Sys_Critical_Init. The _AddInstanceItem
  37. ;service chains the InstDataStrucs together to a sorted double linked list
  38. ;via InstLinkF and instLinkB.
  39. ;If the LinkF field is -1, no other calls were made.
  40. ;If LinkF <> -1, then it represents a call to _AddInstanceItem caused by a
  41. ;system.ini - entry "LOCALTSRS= tsr_name". The VMM instances the whole TSR,
  42. ;the first 16 Byte represents the MCB of the PSP. So we can determine the name
  43. ;of the fully instanced TSR. 
  44.         ;;; ...
  45.         mov KM_Instance.InstLinAddr,0
  46.         mov KM_Instance.InstSize,1
  47.         mov KM_Instance.InstType,ALWAYS_FIELD
  48.         mov esi,offset32 KM_Instance
  49.         VMMcall _AddInstanceItem <esi,0>       
  50.         cmp KM_Instance.InstLinkF,-1            ;any LOCALTSRS ?
  51.         je nolocal
  52.         mov esi,KM_Instance.InstLinkF           ;yes, get it
  53. loclp:  mov Inst_Struc_Ptr,esi
  54.         mov calladr,'LTSR'
  55.         call addinst                            ;add instance item to our list
  56.         mov esi,[esi.InstDataStruc.InstLinkF]   ;get next InstDataStruc
  57.         cmp esi,-1                              ;no more strucs?
  58.         jne loclp
  59.  
  60. nolocal:mov eax,_AddInstanceItem
  61.         mov esi,offset32 myhook
  62.         VMMcall Hook_Device_Service
  63.         mov [oldservice],esi
  64.         ;;; ...
  65. BeginProc   Hooked_AddInstanceItem
  66. ; The AddInstanceItem Hook stores the callers address 
  67. ; and the instance data pointer in the Inst_Data_Buf buffer.
  68. myhook: 
  69.         push ebp
  70.         mov ebp,esp
  71.         push [ebp+0ch]              ; Flags
  72.         push [ebp+8]                ; Instance Structure Pointer
  73.         push [ebp+8]
  74.         pop Inst_Struc_Ptr
  75.         push [ebp+4]                ; get caller's return address!
  76.         pop calladr
  77.         call [oldservice]           ; call original _AddInstanceItem
  78.         add esp,8
  79.         pop ebp
  80.         cmp eax,0                   ; error in _AddInstanceItem ?
  81.         je exit
  82.         call addinst                ; add Instance Item to our list
  83. exit:   ret
  84. ;*****************************************************************************
  85. ;addinst - adds an instance item to our list.
  86. ;INPUT:     calladr - address of caller of _AddInstanceItem
  87. ;           Inst_Struc_Ptr - address of InstDataStruc
  88. ;OUTPUT:    hookerr = -1 - error growing Data_Buf
  89. ;           hookerr = 0 - all O.K.
  90. ;*****************************************************************************
  91. addinst:push edi
  92.         push esi
  93.         push ecx
  94.         push eax
  95. hook2:  mov edi,Data_Buf_Addr
  96.         mov ecx,Inst_Data_Count
  97.         imul ecx,sizeof KM_InstData
  98.         add edi,ecx
  99.         push edi
  100.         add edi,sizeof KM_InstData
  101.         mov ecx,Data_Buf_Addr
  102.         add ecx,Data_Buf_Size
  103.         cmp edi,ecx
  104.         pop edi
  105.         jl hook1
  106.         mov ecx,Data_Buf_Size
  107.         add ecx,1000h
  108.         shr ecx,0ch
  109.         mov edx,Data_Buf_Handle
  110.         VMMcall _PageReAllocate <EDX, ECX, PAGEZEROINIT>          
  111.         cmp eax,0
  112.         je hookerr
  113.         add Data_Buf_Size,1000h
  114.         mov Data_Buf_Handle,eax
  115.         mov Data_Buf_Addr,edx
  116.         jmp hook2
  117. hook1:  mov eax,calladr                 ;save caller's address in buffer
  118.         stosd
  119.         mov esi,Inst_Struc_Ptr
  120.         mov ecx,(sizeof InstDataStruc)/4
  121.         rep movsd                       ;save instance data struc
  122.         inc Inst_Data_Count
  123. hookret:pop eax                         ;next offset pair
  124.         pop ecx
  125.         pop esi
  126.         pop edi
  127.         ret
  128. hookerr:mov hook_err,-1
  129.         jmp hookret
  130.  
  131. EndProc   Hooked_AddInstanceItem
  132.  
  133.  
  134.