驅動程式 - Windows NT Driver (Legacy) - 使用範例 - Assembly (ARM64) - Hello, world!



參考資訊:
https://wasm.in/
http://four-f.narod.ru/
https://github.com/steward-fu/ddk

main.asm

    export DriverEntry
    extern DbgPrint

    area .data, data, arm64
Msg dcb "Hello, world!", 0

    area .text, code, arm64, align = 3
Unload
    ret

DriverEntry
    stp fp, lr, [sp, #-0x20]!
    mov fp, sp

    str x0, [sp, #0x10]
    str x1, [sp, #0x18]

    adrp x0, Msg
    bl DbgPrint

    ldr x1, [sp, #0x10]
    add x1, x1, #0x68
    adrp x0, Unload
    str x0, [x1]

    mov x0, #0
    ldp fp, lr, [sp], #0x20
    ret
    end

Create a new project


Empty WDM Driver


hello


Add New Item



在hello.asm上按下滑鼠右鍵,選擇Properties,將檔案改成Microsoft Macro Assembler


移除hello.inf,只要留下hello.asm即可


選擇ARM64


Build => Rebuild Solution


在開始安裝驅動程式之前,我們需要先下載除錯工具,讓驅動程式的Debug訊息可以顯示在除錯工具上面,目前在Kernel Mode以及User Mode上,最佳的Debug輸出訊息工具是DbgView,該公司目前已經被Microsoft併購,所以可以從Microsoft網站下載,下載完後執行DbgView並將Capture => Capture Kernel選項打勾,接著重啟DbgView


Legacy(NT-Style)驅動程式的安裝很方便,它是使用Service的方式安裝,因此,複製hello.sys到c:\windows\system32\drivers資料夾下並輸入如下命令進行安裝

c:\> sc create MyDriver binpath= c:\windows\system32\drivers\hello.sys type= kernel start= demand error= normal displayname= MyDriver
c:\> sc start MyDriver

P.S. 要記得在"="前面都需要一個空格

輸入完上列指令後,就可以看到輸出的Hello, world!字串


如果要更方便測試,建議使用Four-F撰寫的KmdManager