⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ramdisk.bat

📁 汇编语言开发驱动程序的开发包
💻 BAT
📖 第 1 页 / 共 2 页
字号:
		mov eax, TRUE
	.else
		and eax, FALSE
	.endif

	ret

BroadcastDeviceMessage endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                    MountRamdisk                                                   
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

MountRamdisk proc

	invoke LoadDriver
	.if eax == TRUE
		invoke BroadcastDeviceMessage, g_CreateParams.dwDriveLetter, DBT_DEVICEARRIVAL
	.endif

	ret

MountRamdisk endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                   UnmountRamdisk                                                  
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

UnmountRamdisk proc

local dwBytesReturned:DWORD
local fOk:BOOL
local hDevice:HANDLE
local buffer[256]:CHAR

	and fOk, FALSE

	; RamDisk is no longer available for use. Applications should prepare for the removal of the device
	invoke BroadcastDeviceMessage, g_CreateParams.dwDriveLetter, DBT_DEVICEREMOVEPENDING

	invoke wsprintf, addr buffer, $CTA0("\\\\.\\%c:"), g_CreateParams.dwDriveLetter
	invoke CreateFile, addr buffer, GENERIC_READ + GENERIC_WRITE, FILE_SHARE_READ + FILE_SHARE_WRITE, NULL, OPEN_EXISTING, 0, NULL
	.if eax != INVALID_HANDLE_VALUE

		mov hDevice, eax

		; Lock volume to prepare for unmount
		invoke DeviceIoControl, hDevice, FSCTL_LOCK_VOLUME, NULL,0, NULL, 0, addr dwBytesReturned, NULL
		.if eax != 0

			; Unmount volumes
			invoke DeviceIoControl, hDevice, FSCTL_DISMOUNT_VOLUME, NULL, 0, NULL, 0, addr dwBytesReturned, NULL
			.if eax != 0

				; Delete drive letter
				invoke DeviceIoControl, hDevice, IOCTL_REMOVE, NULL,0, NULL, 0, addr dwBytesReturned, NULL
				.if eax != 0
					; Link to RamDisk has been removed
					invoke BroadcastDeviceMessage, g_CreateParams.dwDriveLetter, DBT_DEVICEREMOVECOMPLETE
					mov fOk, TRUE
				.else
					invoke MessageBox, g_hDlg, $CTA0("Couldn't remove drive letter"), NULL, MB_ICONEXCLAMATION
				.endif

			.else
				invoke MessageBox, g_hDlg, $CTA0("Couldn't unmount ram disk"), NULL, MB_ICONEXCLAMATION
			.endif
			; Unlock volume
			invoke DeviceIoControl, hDevice, FSCTL_UNLOCK_VOLUME, NULL, 0, NULL, 0, addr dwBytesReturned, NULL

		.else

			CTA "Couldn't lock drive %c: in preperation for unmount.\n", g_szLockDriveError
			CTA0 "Ensure that there are no open files on the drive."

			invoke wsprintf, addr buffer, addr g_szLockDriveError, g_CreateParams.dwDriveLetter
			invoke MessageBox, g_hDlg, addr buffer, NULL, MB_ICONEXCLAMATION
		.endif
		invoke CloseHandle, hDevice

	.else
		invoke wsprintf, addr buffer, $CTA0("Couldn't open drive %c: for unmount"), g_CreateParams.dwDriveLetter
		invoke MessageBox, g_hDlg, addr buffer, NULL, MB_ICONEXCLAMATION
	.endif

	mov eax, fOk
	.if eax == TRUE
		; Delete RamDisk device and unload driver
		invoke UnloadDriver
		invoke BroadcastSystemMessage, BSF_NOHANG + BSF_QUERY, NULL, WM_DEVICECHANGE, DBT_QUERYCHANGECONFIG, 0
		invoke BroadcastSystemMessage, BSF_NOHANG + BSF_POSTMESSAGE, NULL, WM_DEVICECHANGE, DBT_CONFIGCHANGED, 0
		invoke BroadcastSystemMessage, BSF_NOHANG + BSF_POSTMESSAGE, NULL, WM_DEVICECHANGE, DBT_DEVNODES_CHANGED, 0

	.endif

	ret

UnmountRamdisk endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                               D I A L O G     P R O C E D U R E                                   
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

DlgProc proc uses esi edi hDlg:HWND, uMsg:UINT, wParam:WPARAM, lParam:LPARAM

local buffer[16]:CHAR
local fOk:BOOL

	mov eax, uMsg
	.if eax == WM_INITDIALOG

		push hDlg
		pop g_hDlg

		invoke LoadIcon, g_hInstance, IDI_ICON
		invoke SendMessage, hDlg, WM_SETICON, ICON_BIG, eax


		invoke GetDlgItem, hDlg, IDC_DRIVE_LETTER
		mov g_hwndDriveLetters, eax
		invoke GetDlgItem, hDlg, IDC_DISK_SIZE
		mov g_hwndDiskSize, eax
		invoke GetDlgItem, hDlg, IDC_ROOT_DIRECTORY_ENTRIES
		mov g_hwndRootDerectoryEntries, eax
		invoke GetDlgItem, hDlg, IDC_SECTORS_PER_CLUSTER
		mov g_hwndSectorsPerCluster, eax
		invoke GetDlgItem, hDlg, IDC_CREATE
		mov g_hwndCreate, eax
		invoke GetDlgItem, hDlg, IDC_REMOVE
		mov g_hwndRemove, eax


		; Fill combo with available drive letters
		invoke GetLogicalDrives
		mov edi, eax
		shr edi, 3			; skip 'A', 'B', 'C'
		mov esi, 'D'
		.while esi <= 'Z'
			shr edi, 1
			.if !CARRY?
				invoke wsprintf, addr buffer, $CTA0("%c:"), esi
				invoke SendMessage, g_hwndDriveLetters, CB_ADDSTRING, 0, addr buffer
			.endif
			inc esi
		.endw
		invoke SendMessage, g_hwndDriveLetters, CB_SETCURSEL, 0, 0

		invoke SetDlgItemInt, hDlg, IDC_DISK_SIZE, 1024, FALSE
		invoke SetDlgItemInt, hDlg, IDC_ROOT_DIRECTORY_ENTRIES, 512, FALSE
		invoke SetDlgItemInt, hDlg, IDC_SECTORS_PER_CLUSTER, 1, FALSE

	.elseif eax == WM_COMMAND

		mov eax, wParam
		and eax, 0FFFFh
;		.if eax == IDCANCEL
;			invoke EndDialog, hDlg, 0
;			invoke PostMessage, hDlg, WM_CLOSE, 0, 0

		.if eax == IDC_CREATE

			invoke SendMessage, g_hwndDriveLetters, CB_GETCURSEL, 0, 0
			.if eax != CB_ERR
				lea ecx, buffer
				invoke SendMessage, g_hwndDriveLetters, CB_GETLBTEXT, eax, ecx
				xor eax, eax
				mov al, buffer
				.if ( al >= 'D' ) && ( al <= 'Z' )
					mov g_CreateParams.dwDriveLetter, eax

					xor edi, edi
					inc edi						; TRUE
					invoke GetDlgItemInt, hDlg, IDC_DISK_SIZE, addr fOk, FALSE
					shl eax, 0Ah					; * Kb
					mov g_CreateParams.nDiskSize, eax
					and edi, fOk

					invoke GetDlgItemInt, hDlg, IDC_ROOT_DIRECTORY_ENTRIES, addr fOk, FALSE
					mov g_CreateParams.nRootDirectoryEntries, eax
					and edi, fOk

					invoke GetDlgItemInt, hDlg, IDC_SECTORS_PER_CLUSTER, addr fOk, FALSE
					mov g_CreateParams.nSectorsPerCluster, eax
					and edi, fOk

					.if ( edi == TRUE ) && ( g_fRamdiskMounted == FALSE )

						invoke MountRamdisk
						.if eax == TRUE
							mov g_fRamdiskMounted, TRUE

							invoke EnableWindow, g_hwndDriveLetters, FALSE
							invoke EnableWindow, g_hwndDiskSize, FALSE
							invoke EnableWindow, g_hwndRootDerectoryEntries, FALSE
							invoke EnableWindow, g_hwndSectorsPerCluster, FALSE
							invoke EnableWindow, g_hwndCreate, FALSE
							invoke EnableWindow, g_hwndRemove, TRUE
						.else
							invoke MessageBox, hDlg, $CTA0("Could't mount RamDisk."), NULL, MB_ICONERROR
						.endif

					.else
						invoke MessageBox, hDlg, $CTA0("Invalid parameter value."), NULL, MB_ICONERROR
					.endif
				.else
					invoke MessageBox, hDlg, $CTA0("Invalid drive letter."), NULL, MB_ICONERROR
				.endif
			.endif

		.elseif eax == IDC_REMOVE

			.if g_fRamdiskMounted == TRUE
				invoke UnmountRamdisk
				.if eax == TRUE
					and g_fRamdiskMounted, FALSE

					invoke EnableWindow, g_hwndDriveLetters, TRUE
					invoke EnableWindow, g_hwndDiskSize, TRUE
					invoke EnableWindow, g_hwndRootDerectoryEntries, TRUE
					invoke EnableWindow, g_hwndSectorsPerCluster, TRUE
					invoke EnableWindow, g_hwndCreate, TRUE
					invoke EnableWindow, g_hwndRemove, FALSE
				.else
					invoke MessageBox, hDlg, $CTA0("Could't unmount RamDisk."), NULL, MB_ICONERROR
				.endif
			.endif
		.endif



	.elseif eax == WM_CLOSE

		.if g_fRamdiskMounted
			invoke MessageBox, hDlg, $CTA0("Unmount RamDisk first\:"), NULL, MB_ICONASTERISK
		.else
			invoke EndDialog, hDlg, 0
		.endif


	.else

		xor eax, eax
		ret
	
	.endif

	xor eax, eax
	inc eax
	ret
    
DlgProc endp


;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                       start                                                       
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

start proc uses esi edi

	invoke GetModuleHandle, NULL
	mov g_hInstance, eax
	invoke DialogBoxParam, g_hInstance, IDD_MAIN, NULL, addr DlgProc, 0
	invoke ExitProcess, 0

start endp

;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::
;                                                                                                   
;:::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::::

end start

:make

set exe=RamDisk

if exist ..\%scp%.exe del ..\%scp%.exe

if exist rsrc.obj goto final
	\masm32\bin\rc /v rsrc.rc
	\masm32\bin\cvtres /machine:ix86 rsrc.res
	if errorlevel 0 goto final
		pause
		exit

:final
if exist rsrc.res del rsrc.res

\masm32\bin\ml /nologo /c /coff %exe%.bat
\masm32\bin\link /nologo /subsystem:windows %exe%.obj rsrc.obj

del %exe%.obj
move %exe%.exe ..
if exist %exe%.exe del %exe%.exe

echo.
pause

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -