📄 kmdmanager.asm
字号:
InsertReportListColumns endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; MakeFilePathOnly
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
MakeFilePathOnly proc lpPathName:LPVOID
invoke fstrlen, lpPathName
mov ecx, lpPathName
lea ecx, [ecx][eax-6]
@@:
mov al, [ecx]
dec ecx
cmp al, '\'
jne @B
mov byte ptr [ecx+2], 0
ret
MakeFilePathOnly endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
ListViewProc proc hWnd:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
mov eax, uMsg
.if eax == WM_CONTEXTMENU
; Don't pop up menu if list is empty
ListView_GetItemCount g_hwndReportListView
.if eax != 0
mov eax, lParam
mov ecx, eax
and eax, 0FFFFh
shr ecx, 16
invoke TrackPopupMenu, g_hListViewPopupMenu, TPM_LEFTALIGN, eax, ecx, NULL, hWnd, NULL
.endif
.elseif eax == WM_COMMAND
mov eax, $LOWORD(wParam)
.if eax == IDM_CLEAR_LOG
ListView_DeleteAllItems g_hwndReportListView
.endif
.endif
invoke CallWindowProc, g_pfnListViewProcPrev, hWnd, uMsg, wParam, lParam
ret
ListViewProc endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Dlg_OnInitDialog
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Dlg_OnInitDialog proc hDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
local rect:RECT
; Set Dialog Icon
invoke LoadIcon, g_hInstance, IDI_ICON
invoke SendMessage, hDlg, WM_SETICON, ICON_BIG, eax
mov g_hwndEditDriverPath, $invoke(GetDlgItem, hDlg, IDE_PATH)
mov g_hwndEditControlCode, $invoke(GetDlgItem, hDlg, IDE_CONTROL_CODE)
; Thnx to James Brown for idea
invoke MaskEditControl, g_hwndEditControlCode, $CTA0("0123456789abcdefABCDEF"), TRUE
invoke SendMessage, g_hwndEditControlCode, EM_LIMITTEXT, 8, 0
mov g_hwndButtonRegister, $invoke(GetDlgItem, hDlg, IDB_REGISTER)
mov g_hwndButtonRun, $invoke(GetDlgItem, hDlg, IDB_RUN)
mov g_hwndButtonControl, $invoke(GetDlgItem, hDlg, IDB_IOCONTROL)
mov g_hwndButtonStop, $invoke(GetDlgItem, hDlg, IDB_STOP)
mov g_hwndButtonUnregister, $invoke(GetDlgItem, hDlg, IDB_UNREGISTER)
mov g_hwndCheckRegToRun, $invoke(GetDlgItem, hDlg, IDCHK_REGTORUNLINK)
mov g_hwndCheckUnregToStop, $invoke(GetDlgItem, hDlg, IDCHK_UNREGTOSTOPLINK)
mov g_hwndCheckLinkAll, $invoke(GetDlgItem, hDlg, IDCHK_IOCONTROLLINK)
mov g_hwndReportListView, $invoke(GetDlgItem, hDlg, IDC_REPORT_LIST)
invoke InsertReportListColumns, g_hwndReportListView
mov g_pfnListViewProcPrev, $invoke(SetWindowLong, g_hwndReportListView, GWL_WNDPROC, offset ListViewProc)
; Create popup menu
invoke CreatePopupMenu
mov g_hListViewPopupMenu,eax
invoke AppendMenu, g_hListViewPopupMenu, MF_STRING, IDM_CLEAR_LOG, $CTA0("Clear log")
invoke GetDlgItem, hDlg, IDB_OPTIONS
invoke EnableWindow, eax, FALSE
; for tracking size
invoke GetWindowRect, hDlg, addr rect
lea edx, rect
mov eax, (RECT PTR [edx]).right
sub eax, (RECT PTR [edx]).left
mov g_dwDlgWidth, eax
mov eax, (RECT PTR [edx]).bottom
sub eax, (RECT PTR [edx]).top
mov g_dwDlgMinHeight, eax
add eax, 195
mov g_dwDlgMaxHeight, eax
; If we XP themed, remove WS_EX_STATICEDGE. Looks better.
invoke AdjustGuiIfThemed, hDlg
ret
Dlg_OnInitDialog endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Dlg_OnCommand
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Dlg_OnCommand proc hDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
LOCAL ofn:OPENFILENAME
LOCAL acBufferPath[MAX_PATH]:CHAR
LOCAL acBufferName[MAX_PATH]:CHAR
LOCAL acIoCode[16]:CHAR
LOCAL dwIoCode:DWORD
mov eax, $LOWORD(wParam)
.if eax == IDCANCEL
; ask only if user hit Esc key
invoke MessageBox, hDlg, $CTA0("Sure want to exit?"), \
$CTA0("Exit Confirmation"), MB_YESNO + MB_ICONQUESTION + MB_DEFBUTTON1
.if eax == IDYES
invoke EndDialog, hDlg, 0
.endif
.elseif eax == IDB_EXIT
invoke EndDialog, hDlg, 0
.elseif eax == IDB_BROWSE
; Get driver's path to load
invoke RtlZeroMemory, addr ofn, sizeof ofn
mov ofn.lStructSize, sizeof ofn
m2m ofn.hwndOwner, hDlg
m2m ofn.hInstance, g_hInstance
mov ofn.lpstrFilter, offset g_szFilterString
invoke RtlZeroMemory, addr acBufferPath, sizeof acBufferPath
lea eax, acBufferPath
mov ofn.lpstrFile, eax
mov ofn.nMaxFile, sizeof acBufferPath
invoke GetCurrentDirectory, sizeof acBufferName, addr acBufferName
lea eax, acBufferName
mov ofn.lpstrInitialDir, eax
mov ofn.lpstrTitle, offset g_szOpenDriverTitle
mov ofn.Flags, OFN_FILEMUSTEXIST + OFN_PATHMUSTEXIST + OFN_LONGNAMES + OFN_EXPLORER
invoke GetOpenFileName, addr ofn
.if eax != 0
; Show it in edit control
invoke SetWindowText, g_hwndEditDriverPath, ofn.lpstrFile
.endif
.elseif eax == IDB_REGISTER
invoke RtlZeroMemory, addr acBufferPath, sizeof acBufferPath
invoke GetWindowText, g_hwndEditDriverPath, addr acBufferPath, sizeof acBufferPath
.if eax != 0
invoke GetDriverNameFromPath, addr acBufferPath, addr acBufferName
.if eax == TRUE
invoke RegisterDriver, addr acBufferName, addr acBufferPath
invoke SendMessage, g_hwndCheckRegToRun, BM_GETCHECK, 0, 0
.if eax == BST_CHECKED
;invoke IsWindowEnabled, g_hwndButtonRun
;.if eax == 0
; linked
invoke RunDriver, addr acBufferName
.endif
.endif
.else
invoke MessageBox, hDlg, addr g_szEnterFullDriverPath, NULL, MB_OK + MB_ICONSTOP
.endif
.elseif eax == IDB_UNREGISTER
invoke RtlZeroMemory, addr acBufferPath, sizeof acBufferPath
invoke GetWindowText, g_hwndEditDriverPath, addr acBufferPath, sizeof acBufferPath
.if eax != 0
invoke GetDriverNameFromPath, addr acBufferPath, addr acBufferName
.if eax == TRUE
invoke SendMessage, g_hwndCheckUnregToStop, BM_GETCHECK, 0, 0
.if eax == BST_CHECKED
;invoke IsWindowEnabled, g_hwndButtonStop
;.if eax == 0
; linked
invoke StopDriver, addr acBufferName
.endif
invoke UnregisterDriver, addr acBufferName
.endif
.else
invoke MessageBox, hDlg, addr g_szEnterFullDriverPath, NULL, MB_OK + MB_ICONSTOP
.endif
.elseif eax == IDB_RUN
invoke RtlZeroMemory, addr acBufferPath, sizeof acBufferPath
invoke GetWindowText, g_hwndEditDriverPath, addr acBufferPath, sizeof acBufferPath
.if eax != 0
invoke GetDriverNameFromPath, addr acBufferPath, addr acBufferName
.if eax == TRUE
invoke RunDriver, addr acBufferName
.endif
.else
invoke MessageBox, hDlg, addr g_szEnterFullDriverPath, NULL, MB_OK + MB_ICONSTOP
.endif
.elseif eax == IDB_STOP
invoke RtlZeroMemory, addr acBufferPath, sizeof acBufferPath
invoke GetWindowText, g_hwndEditDriverPath, addr acBufferPath, sizeof acBufferPath
.if eax != 0
invoke GetDriverNameFromPath, addr acBufferPath, addr acBufferName
.if eax == TRUE
invoke StopDriver, addr acBufferName
.endif
.else
invoke MessageBox, hDlg, addr g_szEnterFullDriverPath, NULL, MB_OK + MB_ICONSTOP
.endif
.elseif eax == IDB_IOCONTROL
invoke RtlZeroMemory, addr acBufferPath, sizeof acBufferPath
invoke GetWindowText, g_hwndEditDriverPath, addr acBufferPath, sizeof acBufferPath
.if eax != 0
invoke GetDriverNameFromPath, addr acBufferPath, addr acBufferName
.if eax == TRUE
invoke GetWindowText, g_hwndEditControlCode, addr acIoCode, sizeof acIoCode
.if eax != 0
invoke htodw, addr acIoCode
mov dwIoCode, eax
invoke SendMessage, g_hwndCheckLinkAll, BM_GETCHECK, 0, 0
.if eax == BST_CHECKED
; linked
.while TRUE
; he-he
invoke RegisterDriver, addr acBufferName, addr acBufferPath
.break .if eax == FALSE
invoke RunDriver, addr acBufferName
.break .if eax == FALSE
invoke ControlDriver, addr acBufferName, dwIoCode
.break .if eax == FALSE
invoke StopDriver, addr acBufferName
.break .if eax == FALSE
invoke UnregisterDriver, addr acBufferName
.break
.endw
.else
invoke ControlDriver, addr acBufferName, dwIoCode
.endif
.else
invoke MessageBox, hDlg, $CTA0("Enter control code first."), NULL, MB_OK + MB_ICONSTOP
.endif
.endif
.else
invoke MessageBox, hDlg, addr g_szEnterFullDriverPath, NULL, MB_OK + MB_ICONSTOP
.endif
.elseif eax == IDB_ABOUT
invoke MessageBox, hDlg, $CTA0("Kernel-Mode Driver Manager\n\tv 1.3\n\nWritten by Four-F\nfour-f@mail.ru"), \
$CTA0("About"), MB_OK + MB_ICONINFORMATION
.elseif eax == IDCHK_REGTORUNLINK
invoke SendDlgItemMessage, hDlg, IDCHK_REGTORUNLINK, BM_GETCHECK, 0, 0
.if eax == BST_CHECKED
invoke EnableWindow, g_hwndButtonRun, FALSE
invoke SetWindowText, g_hwndButtonRegister, $CTA0("&Reg'n'Run")
.else
invoke EnableWindow, g_hwndButtonRun, TRUE
invoke SetWindowText, g_hwndButtonRegister, $CTA0("Re&gister")
.endif
.elseif eax == IDCHK_UNREGTOSTOPLINK
invoke SendDlgItemMessage, hDlg, IDCHK_UNREGTOSTOPLINK, BM_GETCHECK, 0, 0
.if eax == BST_CHECKED
invoke EnableWindow, g_hwndButtonStop, FALSE
invoke SetWindowText, g_hwndButtonUnregister, $CTA0("&Stop'n'Unreg")
.else
invoke EnableWindow, g_hwndButtonStop, TRUE
invoke SetWindowText, g_hwndButtonUnregister, $CTA0("&Unregister")
.endif
.elseif eax == IDCHK_IOCONTROLLINK
invoke SendDlgItemMessage, hDlg, IDCHK_IOCONTROLLINK, BM_GETCHECK, 0, 0
.if eax == BST_CHECKED
invoke EnableWindow, g_hwndButtonRegister, FALSE
invoke EnableWindow, g_hwndCheckRegToRun, FALSE
invoke EnableWindow, g_hwndButtonRun, FALSE
invoke EnableWindow, g_hwndButtonStop, FALSE
invoke EnableWindow, g_hwndCheckUnregToStop, FALSE
invoke EnableWindow, g_hwndButtonUnregister, FALSE
invoke SetWindowText, g_hwndButtonControl, $CTA0("All A&ctions")
.else
invoke EnableWindow, g_hwndButtonRegister, TRUE
invoke EnableWindow, g_hwndCheckRegToRun, TRUE
invoke SendMessage, g_hwndCheckRegToRun, BM_GETCHECK, 0, 0
.if eax == BST_UNCHECKED
invoke EnableWindow, g_hwndButtonRun, TRUE
.endif
invoke SendMessage, g_hwndCheckUnregToStop, BM_GETCHECK, 0, 0
.if eax == BST_UNCHECKED
invoke EnableWindow, g_hwndButtonStop, TRUE
.endif
invoke EnableWindow, g_hwndCheckUnregToStop, TRUE
invoke EnableWindow, g_hwndButtonUnregister, TRUE
invoke SetWindowText, g_hwndButtonControl, $CTA0("I/O &Control")
.endif
.endif
ret
Dlg_OnCommand endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Dlg_OnSize
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Dlg_OnSize proc uses esi esi ebx hDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
local rcDlg:RECT
local rcList:RECT
local sz:_SIZE
local pos:POINT
invoke GetWindowRect, hDlg, addr rcDlg
invoke GetWindowRect, g_hwndReportListView, addr rcList
mov eax, rcList.bottom
sub eax, rcList.top
mov ecx, rcDlg.bottom
sub ecx, rcList.bottom
sub ecx, 6
add eax, ecx
mov sz.y, eax
mov eax, rcList.right
sub eax, rcList.left
mov sz.x, eax
mrm pos.x, rcList.left
mrm pos.y, rcList.top
invoke ScreenToClient, hDlg, addr pos
invoke MoveWindow, g_hwndReportListView, pos.x, pos.y, sz.x, sz.y, TRUE
ret
Dlg_OnSize endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Dlg_OnGetMinMaxInfo
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Dlg_OnGetMinMaxInfo proc uses esi esi ebx hDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
mov ecx, lParam
assume ecx:ptr MINMAXINFO
mov eax, g_dwDlgWidth
mov [ecx].ptMinTrackSize.x, eax
mov [ecx].ptMaxTrackSize.x, eax
mrm [ecx].ptMinTrackSize.y, g_dwDlgMinHeight
mrm [ecx].ptMaxTrackSize.y, g_dwDlgMaxHeight
assume ecx:nothing
ret
Dlg_OnGetMinMaxInfo endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; Dlg_OnDropFiles
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
Dlg_OnDropFiles proc uses esi esi ebx hDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
local acDroppedFilePath[MAX_PATH]:CHAR
local acDriverName[MAX_MODULE_NAME32]:CHAR
invoke DragQueryFile, wParam, 0, addr acDroppedFilePath, sizeof acDroppedFilePath
; Show it in edit control
invoke SetWindowText, g_hwndEditDriverPath, addr acDroppedFilePath
invoke MakeFilePathOnly, addr acDroppedFilePath
invoke SetCurrentDirectory, addr acDroppedFilePath
ret
Dlg_OnDropFiles endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
; D I A L O G P R O C E D U R E
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
DlgProc proc hDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM
mov eax, uMsg
.if eax == WM_COMMAND
invoke Dlg_OnCommand, hDlg, uMsg, wParam, lParam
.elseif eax == WM_INITDIALOG
invoke Dlg_OnInitDialog, hDlg, uMsg, wParam, lParam
.elseif eax == WM_GETMINMAXINFO
invoke Dlg_OnGetMinMaxInfo, hDlg, uMsg, wParam, lParam
.elseif eax == WM_SIZE
invoke Dlg_OnSize, hDlg, uMsg, wParam, lParam
.elseif eax == WM_DROPFILES
invoke Dlg_OnDropFiles, hDlg, uMsg, wParam, lParam
.elseif eax == WM_CLOSE
invoke EndDialog, hDlg, 0
.else
return FALSE
.endif
return TRUE
DlgProc endp
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
start:
mov g_hInstance, $invoke(GetModuleHandle, NULL)
invoke DialogBoxParam, g_hInstance, IDD_DIALOG, NULL, addr DlgProc, 0
invoke ExitProcess, eax
ret
end start
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -