Subversion Repositories Kolibri OS

Rev

Go to most recent revision | Blame | Last modification | View Log | Download | RSS feed

  1.         .386p
  2. WIN40COMPAT = 1
  3.         include vmm.inc
  4.         include v86mmgr.inc
  5.         DECLARE_VIRTUAL_DEVICE LDKLBR,1,0,LDKLBR_Control,UNDEFINED_DEVICE_ID,1
  6.        
  7. ;Begin_control_dispatch LDKLBR
  8. ;Control_Dispatch w32_DeviceIoControl, OnDeviceIoControl
  9. ;Control_Dispatch Sys_Dynamic_Device_Exit, OnExit
  10. ;End_control_dispatch LDKLBR
  11.  
  12. VxD_LOCKED_DATA_SEG
  13. VkdControlProc  dd      0
  14. vkdddb          dd      0
  15. diskinfobuf:
  16.         db      10h,0,0,0FFh
  17.         db      0Ch dup (0)
  18.  
  19. oldidt label fword
  20.         dw      03FFh
  21.         dd      0
  22.  
  23.         include mtldr.inc
  24.  
  25. imgname dd      0
  26.  
  27. VxD_LOCKED_DATA_ENDS
  28.  
  29. VxD_LOCKED_CODE_SEG
  30.  
  31. BeginProc NewControlProc
  32.         cmp     eax, Reboot_Processor
  33.         jz      short MyReboot
  34.         jmp     [VkdControlProc]
  35. EndProc NewControlProc
  36.  
  37. BeginProc MyReboot
  38.         VMMCall _MapPhysToLinear,<0D000h,2000h,0>
  39.         push    eax
  40.         VMMCall _MapPhysToLinear,<0,1000h,0>
  41.         xchg    eax, ebx
  42.         cli
  43.         lea     esi, [ebx+53Ch]
  44.         lodsd
  45.         mov     [ebx+413h], ax
  46.         shr     eax, 10h
  47.         mov     [ebx+40Eh], ax
  48. ; restore BIOS IDT - vectors 00..1F
  49.         mov     edi, ebx
  50.         mov     ecx, 20h
  51.         rep     movsd
  52. ; int 19
  53.         mov     eax, [ebx+810h]
  54.         mov     [ebx+64h], eax
  55. ; vectors 40,41,42,43,46,4B,4F
  56.         lea     edi, [ebx+40h*4]
  57.         movsd
  58.         movsd
  59.         movsd
  60.         movsd
  61.         scasd
  62.         scasd
  63.         movsd
  64.         add     edi, 10h
  65.         movsd
  66.         add     edi, 0Ch
  67.         movsd
  68. ; vectors 70..77
  69. ;       lea     esi, [ebx+5DCh]
  70.         lea     edi, [ebx+70h*4]
  71.         mov     ecx, 8
  72.         rep     movsd
  73.  
  74. ; reboot to mtldr
  75.         mov     dword ptr [ebx+467h], 0D000007h ; 0D00:0007
  76.         mov     al, 0Fh
  77.         out     70h, al
  78.         jecxz   $+2
  79.         jecxz   $+2
  80.         mov     al, 5
  81.         out     71h, al
  82. ; copy mtldr code
  83.         mov     esi, offset mtldr
  84. ;       mov     edi, 0D000h
  85.         pop     edi
  86.         push    edi
  87.         mov     ecx, mtldr_size
  88.         rep     movsb
  89. ; copy mtldr parameters
  90.         mov     esi, [imgname]
  91.         mov     edi, esi
  92.         mov     al, 0
  93.         xor     ecx, ecx
  94.         dec     ecx
  95.         repnz   scasb
  96.         pop     edi
  97.         not     ecx
  98.         movzx   eax, word ptr [edi+5]
  99.         add     edi, eax
  100.         rep     movsb
  101. ; load old IDT
  102.         lidt    [oldidt]
  103. ; reboot
  104.         mov     al, 0FEh
  105.         out     64h, al
  106.         hlt
  107. EndProc MyReboot
  108.  
  109. BeginProc LDKLBR_Control
  110.         cmp     eax, w32_DeviceIoControl
  111.         jz      short OnDeviceIoControl
  112.         cmp     eax, Sys_Dynamic_Device_Exit
  113.         jz      short OnExit
  114.         cmp     eax, Reboot_Processor
  115.         jz      MyReboot
  116.         clc
  117.         ret
  118.  
  119. OnExit:
  120. ; allow unload if and only if we are not hooking
  121.         cmp     [VkdControlProc], 1
  122.         cmc
  123.         ret
  124.  
  125. OnDeviceIoControl:
  126.         cmp     dword ptr [esi+12], DIOC_Open
  127.         jz      @@open
  128.         cmp     dword ptr [esi+12], 0Fh
  129.         jnz     _exit
  130. ; request to set path of image
  131.         mov     ecx, [esi+20]   ; cbInBuffer
  132.         cmp     ecx, 300
  133.         ja      short @@paramerr
  134.         test    ecx, ecx
  135.         jnz     short @@param1ok
  136. @@paramerr:
  137.         xor     eax, eax
  138.         inc     eax
  139. @@errret:
  140.         mov     ecx, [vkdddb]
  141.         mov     edx, [VkdControlProc]
  142.         mov     [ecx + VxD_Desc_Block.DDB_Control_Proc], edx
  143.         mov     [VkdControlProc], 0
  144.         ret
  145. @@param1ok:
  146.         mov     eax, [esi+16]   ; lpvInBuffer
  147. ; set drive
  148.         mov     dl, [eax]
  149.         or      dl, 20h
  150.         sub     dl, 60h
  151.         jz      short @@paramerr
  152.         cmp     dl, 'z'-60h
  153.         ja      short @@paramerr
  154.         push    esi
  155.         Push_Client_State Uses_edi
  156.         mov     ecx, 10h
  157.         stc
  158.         push    ds
  159.         pop     fs
  160.         mov     esi, offset diskinfobuf
  161.         VMMCall Get_Cur_VM_Handle
  162.         VxDCall V86MMGR_Allocate_Buffer
  163.         VMMCall Begin_Nest_V86_Exec
  164.         assume ebp:ptr Client_Reg_Struc
  165.         mov     [ebp.Client_AX], 440Dh
  166.         mov     [ebp.Client_BL], dl
  167.         mov     [ebp.Client_CX], 086Fh
  168.         mov     [ebp.Client_DX], di
  169.         mov     eax, edi
  170.         shr     eax, 10h
  171.         mov     [ebp.Client_DS], ax
  172.         mov     eax, 21h
  173.         VMMCall Exec_Int
  174.         VMMCall End_Nest_Exec
  175.         mov     ecx, 10h
  176.         stc
  177.         push    ds
  178.         pop     fs
  179.         VxDCall V86MMGR_Free_Buffer
  180.         Pop_Client_State Uses_esi
  181.         pop     esi
  182.         mov     al, byte ptr [diskinfobuf+3]
  183.         cmp     al, 0FFh
  184.         jz      @@errret
  185.         cmp     al, 80h
  186.         jb      @@paramerr
  187.         mov     byte ptr [mtldr+4], al
  188.         mov     eax, dword ptr [diskinfobuf+8]
  189.         mov     dword ptr [mtldr], eax
  190. ; set path
  191.         mov     ecx, [imgname]
  192.         jecxz   @f
  193.         VMMCall _HeapFree, <ecx,0>
  194. @@:
  195.         mov     ecx, [esi+20]
  196.         dec     ecx
  197.         push    ecx
  198.         VMMCall _HeapAllocate, <ecx,0>
  199.         pop     ecx
  200.         mov     [imgname], eax
  201.         xchg    edi, eax
  202.         mov     esi, [esi+16]
  203.         inc     esi
  204. @@1:
  205.         lodsb
  206.         cmp     al, 'A'
  207.         jb      short @f
  208.         cmp     al, 'Z'
  209.         ja      short @f
  210.         or      al, 20h
  211. @@:
  212.         stosb
  213.         loop    @@1
  214.         xor     eax, eax
  215.         ret
  216. @@open:
  217. ; don't hook if already hooked
  218.         cmp     [VkdControlProc], 0
  219.         jnz     short @f
  220.         mov     eax, 0Dh
  221.         VMMCall Get_DDB
  222.         mov     [vkdddb], ecx
  223.         mov     eax, [ecx + VxD_Desc_Block.DDB_Control_Proc]
  224.         mov     [VkdControlProc], eax
  225.         mov     [ecx + VxD_Desc_Block.DDB_Control_Proc], NewControlProc
  226. @@:
  227.         xor     eax, eax
  228. _exit:
  229.         ret
  230. EndProc LDKLBR_Control
  231.  
  232. VxD_LOCKED_CODE_ENDS
  233.  
  234.         end
  235.