Driver Compilation and connection

Source: Internet
Author: User

The method recommended by Kmdkit is to write the assembly source program as a batch bat file, taking the Ring0.sys of heaven as an example
Save the following code as a Ring0.bat

; @echo off
; Goto make
;>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>
.586P; Protection mode
. Model Flat,stdcall
Option Casemap:none
;>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>
Include \masm32\include\w2k\ntddk.inc
; Interrupt related data structures
Idt_reg STRUCT
Limit WORD?
Base DWORD?
Idt_reg ENDS

; Interrupt Descriptor
Int_descriptor STRUCT
Offs0_15 WORD?
Sel WORD?
Paramcnt BYTE?
Attrs BYTE?
Offs16_31 WORD?
Int_descriptor ENDS

;>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>
; Code Snippets
;>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>
. Code
Szbuffer db DUP (0)
;>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>
MYINTFUNC proc
Push edx
Call EAX
Iretd
Myintfunc ENDP

;====================================================================
addmyint proc uses EDI
Local @IDT

sidt   szbuffer
            mov       EDI, (Idt_reg ptr [szbuffer]). Base
             add      edi,21h*8

;   uses Int21 interrupts, which are not used under Win2K
     ;      CLI
            mov   eax,offset myintfunc
            mov   [Edi],ax
             shr   eax,16
             mov   [edi+6],ax     ;   Set entry address
            mov   [edi+2],cs      ;   Set segment address
        ;   Set Ring3 can access
            mov   WORD ptr [edi+4] , 0ee00h
     ;      sti

Ret
      addmyint   ENDP
      =========== =========================================================
      wdmunload    proc   Driverobject:dword
            local   @IDT

sidt   szbuffer
            mov       EDI, (Idt_reg ptr [szbuffer]). Base
             add      edi,21h*8
             xor   eax,eax
             mov   [Edi],ax
            mov    [edi+6],ax     ;   Set entry address
             mov   [edi+2],ax     ;   set segment address
            mov   WORD ptr [Edi+4],ax

Ret
Wdmunload ENDP
;====================================================================
driverentry proc Driverobj:dword,registrypath:dword


MOV eax,driverobj
Assume Eax:ptr Driver_object
mov [EAX]. Driverunload,offset Wdmunload
Assume eax:nothing
Invoke Addmyint

XOR Eax,eax
Ret
DriverEntry ENDP
;>>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>>>>>>>>>>>>>>>>>> >>>>>>>>>>
End DriverEntry

: Make

Set DRV=RING0

\MASM32\BIN\ML/NOLOGO/C/coff%drv%.bat
\masm32\bin\link/nologo/driver/base:0x10000/align:32/out:%drv%.sys
/subsystem:native

%drv%.obj

Del%drv%.obj

Echo.
Pause
REM ===== is the content of Ring0.bat =============


Double-click Ring0.bat, completes the compilation connection work, generated Ring0.sys how? Easy, huh?

Kmdkit skillfully combines batch processing with ASM files to make the compilation more goofy.
When you need to modify the code, click the right mouse button on the Ring0.bat and click Edit.
You need to double-click it directly when compiling.
It is important to note that \masm32 and Ring0.bat must be on a disk, such as Masm32 installed on the C: disk, Ring0.bat must also be in C: Disk

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.